B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(→‎addIncludedService(BluetoothGattService service): Refine the description that the one would be rejected is the promise instead of the function itself.)
 
(33 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== Overview ==
== Overview ==
'''BluetoothGattService''' represents the service provided by GATT server. BluetoothGattService is consisted of its service definition, a list of included services which are referenced by this service, and a list of characteristics in this service.
'''BluetoothGattService''' represents the service provided by GATT server. BluetoothGattService consists of the service definition, a list of included services which this service references, and a list of characteristics in this service.


== Interfaces ==
== Interfaces ==
[[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#BluetoothGattService|BluetoothGattService]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#BluetoothGattService|BluetoothGattService]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#BluetoothGattServiceInit|BluetoothGattServiceInit]]


=== BluetoothGattService ===
=== BluetoothGattService ===
  [CheckPermissions="bluetooth"]
  [CheckPermissions="bluetooth",
  Constructor(BluetoothGattServiceInit init)]
  interface BluetoothGattService
  interface BluetoothGattService
  {
  {
   [Cached, Pure]
   [Cached, Pure] readonly attribute sequence<[[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#BluetoothGattCharacteristic|BluetoothGattCharacteristic]]> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#characteristics|characteristics]];
  readonly attribute sequence<[[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#BluetoothGattCharacteristic|BluetoothGattCharacteristic]]> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#characteristics|characteristics]];
   [Cached, Pure] readonly attribute sequence<[[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#BluetoothGattService|BluetoothGattService]]> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#includedServices|includedServices]];
   [Cached, Pure]
  readonly attribute sequence<[[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#BluetoothGattService|BluetoothGattService]]>       [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#includedServices|includedServices]];
  readonly attribute boolean                              [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#isPrimary|isPrimary]];
  readonly attribute DOMString                            [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#uuid|uuid]];
  readonly attribute int                                  [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#instanceId|instanceId]];
   
   
   [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic|BluetoothGattCharacteristic]]? [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#findCharacteristic.28DOMString uuid.29|findCharacteristic(DOMString uuid)]];
   readonly attribute boolean [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#isPrimary|isPrimary]];
  readonly attribute DOMString [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#uuid|uuid]];
  readonly attribute unsigned short [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#instanceId|instanceId]];
  [NewObject] Promise<[[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#BluetoothGattCharacteristic|BluetoothGattCharacteristic]]> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#addCharacteristic.28DOMString_uuid.2C_GattPermissions_permissions.2C_GattCharacteristicProperties_properties.2C_ArrayBuffer_value.29|addCharacteristic(DOMString uuid, GattPermissions permissions, GattCharacteristicProperties properties, ArrayBuffer value)]];
  [NewObject] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#addIncludedService.28BluetoothGattService_service.29|addIncludedService(BluetoothGattService service)]];
};
 
=== BluetoothGattServiceInit ===
dictionary BluetoothGattServiceInit
{
  boolean isPrimary = false;
  DOMString uuid = "";
  };
  };


== Properties ==
== Properties ==
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#characteristics|BluetoothGattService.characteristics]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#characteristics|BluetoothGattService.characteristics]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#includeServices|BluetoothGattService.includeServices]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#includedServices|BluetoothGattService.includedServices]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#isPrimary|BluetoothGattService.isPrimary]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#isPrimary|BluetoothGattService.isPrimary]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#uuid|BluetoothGattService.uuid]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#uuid|BluetoothGattService.uuid]]
Line 77: Line 86:


; Value Type
; Value Type
: integer
: unsigned short


; Default Value
; Default Value
Line 83: Line 92:


== Methods ==
== Methods ==
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#findCharacteristic.28DOMString uuid.29|BluetoothGattService.findCharacteristic(DOMString uuid)]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#addCharacteristic.28DOMString_uuid.2C_GattPermissions_permissions.2C_GattCharacteristicProperties_properties.29|BluetoothGattService.addCharacteristic(DOMString uuid, GattPermissions permissions, GattCharacteristicProperties properties, ArrayBuffer value)]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#addIncludedService.28BluetoothGattService_service.29|BluetoothGattService.addIncludedService(BluetoothGattService service)]]


=== findCharacteristic(DOMString uuid) ===
=== addCharacteristic(DOMString uuid, GattPermissions permissions, GattCharacteristicProperties properties, ArrayBuffer value) ===


; Description
; Description
: The method finds a characteristic in this service from the characteristics property by the given UUID.
: The method adds a characteristic to this service.
: When there are multiple characteristics with the same UUID existed in the service, the first one will be returned.


; Parameters
; Parameter
: ''uuid''
: ''uuid''
:: UUID DOMString of the characteristic to seek for.
:: UUID of the characteristic to add.
: ''permissions''
:: [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#GattPermissions|GattPermissions]] of the characteristic to add.
: ''properties''
:: [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#GattCharacteristicProperties|GattCharacteristicProperties]] of the characteristic to add
: ''value''
:: The initial value of this characteristic.


; Return
; Return
: The first characteristic with the given uuid in characteristics property.
: A Promise to indicate whether the operation is resolved or rejected. Once the Promise is resolved, the property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#characteristics|characteristics]] is also updated with the added characteristic.
: A null pointer is returned if no characteristic is found.
 
=== addIncludedService(BluetoothGattService service) ===
 
; Description
: The method adds an included service to this service. The included service to be added should be an existing service of the same GATT server, otherwise the promise will be rejected.


; Sample
; Parameter
const HEART_RATE_SERVICE = "0000180d-0000-1000-8000-00805f9b34fb";
: ''service''
const HEART_RATE_MEASUREMENT = "00002a37-0000-1000-8000-00805f9b34fb";
:: The [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#BluetoothGattService|BluetoothGattService]] object to add.


if (device.gatt && device.gatt.findService(HEART_RATE_SERVICE)) {
; Return
  heartRateMeasurement = heartRateService.findCharacteristic(HEART_RATE_MEASUREMENT);
: A Promise to indicate whether the operation is resolved or rejected. Once the Promise is resolved, it returns the added [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#BluetoothGattService|BluetoothGattService]] object, and property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#includedServices|includedServices]] is also updated with the added service.
}

Latest revision as of 03:59, 16 September 2015

Overview

BluetoothGattService represents the service provided by GATT server. BluetoothGattService consists of the service definition, a list of included services which this service references, and a list of characteristics in this service.

Interfaces

BluetoothGattService

[CheckPermissions="bluetooth",
 Constructor(BluetoothGattServiceInit init)]
interface BluetoothGattService
{
  [Cached, Pure] readonly attribute sequence<BluetoothGattCharacteristic> characteristics;
  [Cached, Pure] readonly attribute sequence<BluetoothGattService> includedServices;

  readonly attribute boolean isPrimary;
  readonly attribute DOMString uuid;
  readonly attribute unsigned short instanceId;

  [NewObject] Promise<BluetoothGattCharacteristic> addCharacteristic(DOMString uuid, GattPermissions permissions, GattCharacteristicProperties properties, ArrayBuffer value);
  [NewObject] Promise<void> addIncludedService(BluetoothGattService service);
};

BluetoothGattServiceInit

dictionary BluetoothGattServiceInit
{
  boolean isPrimary = false;
  DOMString uuid = "";
};

Properties

characteristics

Description
A cached array of charactertistics contained in this service.
Value Type
sequence<BluetoothGattCharacteristic>
Default Value
Empty array (array with length = 0)

includedServices

Description
A cached array of included services referenced by this service.
Value Type
sequence<BluetoothGattService>
Default Value
Empty array (array with length = 0)

isPrimary

Description
Indicate whether this is a primary or secondary service.
Value Type
boolean
Default Value
false

uuid

Description
This property stores the UUID of this service.
Value Type
DOMString
Default Value
Empty string ("")

instanceId

Description
This property stores the instance id of this service.
Value Type
unsigned short
Default Value
0

Methods

addCharacteristic(DOMString uuid, GattPermissions permissions, GattCharacteristicProperties properties, ArrayBuffer value)

Description
The method adds a characteristic to this service.
Parameter
uuid
UUID of the characteristic to add.
permissions
GattPermissions of the characteristic to add.
properties
GattCharacteristicProperties of the characteristic to add
value
The initial value of this characteristic.
Return
A Promise to indicate whether the operation is resolved or rejected. Once the Promise is resolved, the property characteristics is also updated with the added characteristic.

addIncludedService(BluetoothGattService service)

Description
The method adds an included service to this service. The included service to be added should be an existing service of the same GATT server, otherwise the promise will be rejected.
Parameter
service
The BluetoothGattService object to add.
Return
A Promise to indicate whether the operation is resolved or rejected. Once the Promise is resolved, it returns the added BluetoothGattService object, and property includedServices is also updated with the added service.