B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService

From MozillaWiki
< B2G‎ | Bluetooth‎ | WebBluetooth-v2
Revision as of 06:46, 20 November 2014 by Btian (talk | contribs) (→‎Methods)
Jump to navigation Jump to search

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

BluetoothGattService

[CheckPermissions="bluetooth"]
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, Throws] Promise<BluetoothGattCharacteristic> addCharacteristic(DOMString uuid, Permission permissions, Properties properties);
  [NewObject, Throws] Promise<void> addIncludedService(BluetoothGattService service);
};

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, Permissions permissions, Properties properties)

Description
The method adds a characteristic to this service.
Parameter
uuid
UUID of the characteristic to add.
permissions
Permissions of the characteristic to add.
properties
Properties of the characteristic to add
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.
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.