Bug 1140952 - Implement read/write value of a descriptor for GATT client API (webapi part). f=jocelyn, r=btian, r=mrbkap
authorBruce Sun <brsun@mozilla.com>
Thu, 16 Apr 2015 16:44:58 +0800
changeset 239579 532dec7b6f8ca5c8e570880c4e6a7288003be8f2
parent 239578 f3181d2b6c66d3ce546aeff234fbdd48a447c6eb
child 239580 c8b28d0e161d3227ee19944d6c8671600e9e3838
push id12444
push userryanvm@gmail.com
push dateFri, 17 Apr 2015 20:04:42 +0000
treeherderfx-team@560a202db924 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbtian, mrbkap
bugs1140952
milestone40.0a1
Bug 1140952 - Implement read/write value of a descriptor for GATT client API (webapi part). f=jocelyn, r=btian, r=mrbkap
dom/bluetooth/bluetooth2/BluetoothGattDescriptor.cpp
dom/bluetooth/bluetooth2/BluetoothGattDescriptor.h
dom/webidl/BluetoothGattDescriptor.webidl
--- a/dom/bluetooth/bluetooth2/BluetoothGattDescriptor.cpp
+++ b/dom/bluetooth/bluetooth2/BluetoothGattDescriptor.cpp
@@ -47,8 +47,34 @@ BluetoothGattDescriptor::~BluetoothGattD
 }
 
 JSObject*
 BluetoothGattDescriptor::WrapObject(JSContext* aContext,
                                     JS::Handle<JSObject*> aGivenProto)
 {
   return BluetoothGattDescriptorBinding::Wrap(aContext, this, aGivenProto);
 }
+
+void
+BluetoothGattDescriptor::GetValue(JSContext* cx,
+                                  JS::MutableHandle<JSObject*> aValue) const
+{
+  MOZ_ASSERT(aValue);
+
+  aValue.set(mValue.IsEmpty()
+             ? nullptr
+             : ArrayBuffer::Create(cx, mValue.Length(), mValue.Elements()));
+}
+
+already_AddRefed<Promise>
+BluetoothGattDescriptor::ReadValue(ErrorResult& aRv)
+{
+  // TODO: This will be implemented by later patch set in the same bug.
+  return nullptr;
+}
+
+already_AddRefed<Promise>
+BluetoothGattDescriptor::WriteValue(
+  const RootedTypedArray<ArrayBuffer>& aValue, ErrorResult& aRv)
+{
+  // TODO: This will be implemented by later patch set in the same bug.
+  return nullptr;
+}
--- a/dom/bluetooth/bluetooth2/BluetoothGattDescriptor.h
+++ b/dom/bluetooth/bluetooth2/BluetoothGattDescriptor.h
@@ -5,16 +5,18 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_bluetooth_bluetoothgattdescriptor_h__
 #define mozilla_dom_bluetooth_bluetoothgattdescriptor_h__
 
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/BluetoothGattDescriptorBinding.h"
 #include "mozilla/dom/bluetooth/BluetoothCommon.h"
+#include "mozilla/dom/Promise.h"
+#include "mozilla/dom/TypedArray.h"
 #include "nsCOMPtr.h"
 #include "nsWrapperCache.h"
 #include "nsPIDOMWindow.h"
 
 BEGIN_BLUETOOTH_NAMESPACE
 
 class BluetoothGattCharacteristic;
 class BluetoothSignal;
@@ -35,16 +37,25 @@ public:
     return mCharacteristic;
   }
 
   void GetUuid(nsString& aUuidStr) const
   {
     aUuidStr = mUuidStr;
   }
 
+  void GetValue(JSContext* cx, JS::MutableHandle<JSObject*> aValue) const;
+
+  /****************************************************************************
+   * Methods (Web API Implementation)
+   ***************************************************************************/
+  already_AddRefed<Promise> ReadValue(ErrorResult& aRv);
+  already_AddRefed<Promise> WriteValue(
+    const RootedTypedArray<ArrayBuffer>& aValue, ErrorResult& aRv);
+
   /****************************************************************************
    * Others
    ***************************************************************************/
   void Notify(const BluetoothSignal& aData); // BluetoothSignalObserver
 
   nsPIDOMWindow* GetParentObject() const
   {
      return mOwner;
@@ -76,13 +87,18 @@ private:
    * 2) mInstanceId: Instance id of this descriptor.
    */
   BluetoothGattId mDescriptorId;
 
   /**
    * UUID string of this GATT descriptor.
    */
   nsString mUuidStr;
+
+  /**
+   * Value of this GATT descriptor.
+   */
+  nsTArray<uint8_t> mValue;
 };
 
 END_BLUETOOTH_NAMESPACE
 
 #endif
--- a/dom/webidl/BluetoothGattDescriptor.webidl
+++ b/dom/webidl/BluetoothGattDescriptor.webidl
@@ -4,9 +4,15 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 [CheckPermissions="bluetooth"]
 interface BluetoothGattDescriptor
 {
   readonly attribute BluetoothGattCharacteristic            characteristic;
   readonly attribute DOMString                              uuid;
+  readonly attribute ArrayBuffer?                           value;
+
+  [NewObject]
+  Promise<ArrayBuffer>  readValue();
+  [NewObject]
+  Promise<void>         writeValue(ArrayBuffer value);
 };