Bug 1140952 - Implement read/write value of a descriptor for GATT client API (webapi part). f=jocelyn, r=btian, r=mrbkap

This commit is contained in:
Bruce Sun 2015-04-16 16:44:58 +08:00
parent 7635978729
commit f50af0f15c
3 changed files with 48 additions and 0 deletions

View File

@ -52,3 +52,29 @@ BluetoothGattDescriptor::WrapObject(JSContext* aContext,
{
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;
}

View File

@ -10,6 +10,8 @@
#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"
@ -40,6 +42,15 @@ public:
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
***************************************************************************/
@ -81,6 +92,11 @@ private:
* UUID string of this GATT descriptor.
*/
nsString mUuidStr;
/**
* Value of this GATT descriptor.
*/
nsTArray<uint8_t> mValue;
};
END_BLUETOOTH_NAMESPACE

View File

@ -9,4 +9,10 @@ interface BluetoothGattDescriptor
{
readonly attribute BluetoothGattCharacteristic characteristic;
readonly attribute DOMString uuid;
readonly attribute ArrayBuffer? value;
[NewObject]
Promise<ArrayBuffer> readValue();
[NewObject]
Promise<void> writeValue(ArrayBuffer value);
};