var serviceUuid_ = data.serviceUuid;
//address_ is needed to control if device is still connected
var address_ = address || data.address;
+
function servicesGetter() {
var services = [];
var result = native.callSync('BluetoothGATTClientServiceGetServices', {
return ++CurrentGATTServerEntityId;
}
+function IsUuidValid(uuid) {
+ return (
+ BluetoothManager_UUIDIsValid16Bit(uuid) ||
+ BluetoothManager_UUIDIsValid32Bit(uuid) ||
+ BluetoothManager_UUIDIsValid128Bit(uuid)
+ );
+}
+
+var ValidateBluetoothGATTServerServiceInit = function(initData) {
+ initData = AV.validateArgs(
+ [
+ initData['serviceUuid'],
+ initData['isPrimary'] || true,
+ initData['includedServices'] || [],
+ initData['characteristics'] || []
+ ],
+ [
+ {
+ name: 'serviceUuid',
+ type: AV.Types.STRING,
+ validator: IsUuidValid
+ },
+ {
+ name: 'isPrimary',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'includedServices',
+ type: AV.Types.ARRAY
+ },
+ {
+ name: 'characteristics',
+ type: AV.Types.ARRAY
+ }
+ ]
+ );
+
+ // "uuid" field is used to construct BluetoothGATTService, but it's not a part
+ // of BluetoothGATTServerServiceInit dictionary.
+ // In case of BluetoothGATTServerServices, its value is always the same as
+ // serviceUuid's.
+ initData.uuid = initData.serviceUuid;
+ return initData;
+};
+
//class BluetoothGATTServerService ///////////////////////////
var BluetoothGATTServerService = function(data) {
- // TODO: validate data and set default values
+ data = ValidateBluetoothGATTServerServiceInit(data);
BluetoothGATTService.call(this, data, null);
};
};
+var ValidateBluetoothGATTServerCharacteristicInit = function(initData) {
+ return AV.validateArgs(
+ [
+ initData['uuid'],
+ initData['descriptors'] || [],
+ initData['isBroadcast'] || false,
+ initData['hasExtendedProperties'] || false,
+ initData['isNotify'] || false,
+ initData['isIndication'] || false,
+ initData['isReadable'] || false,
+ initData['isSignedWrite'] || false,
+ initData['isWritable'] || false,
+ initData['isWriteNoResponse'] || false,
+ initData['readPermission'] || false,
+ initData['writePermission'] || false,
+ initData['encryptedReadPermission'] || false,
+ initData['encryptedWritePermission'] || false,
+ initData['encryptedSignedReadPermission'] || false,
+ initData['encryptedSignedWritePermission'] || false,
+ initData['readValueRequestCallback'] || null,
+ initData['writeValueRequestCallback'] || null
+ ],
+ [
+ {
+ name: 'uuid',
+ type: AV.Types.STRING,
+ validator: IsUuidValid
+ },
+ {
+ name: 'descriptors',
+ type: AV.Types.ARRAY
+ },
+ {
+ name: 'isBroadcast',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'hasExtendedProperties',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'isNotify',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'isIndication',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'isReadable',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'isSignedWrite',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'isWritable',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'isWriteNoResponse',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'readPermission',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'writePermission',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'encryptedReadPermission',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'encryptedWritePermission',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'encryptedSignedReadPermission',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'encryptedSignedWritePermission',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'readValueRequestCallback',
+ type: AV.Types.FUNCTION,
+ nullable: true
+ },
+ {
+ name: 'writeValueRequestCallback',
+ type: AV.Types.FUNCTION,
+ nullable: true
+ }
+ ]
+ );
+};
+
//class BluetoothGATTServerCharacteristic ///////////////////////////
var BluetoothGATTServerCharacteristic = function(data) {
- // TODO: validate data and set default values
+ data = ValidateBluetoothGATTServerCharacteristicInit(data);
BluetoothGATTCharacteristic.call(this, data, null);
uuid: {
enumerable: true,
get: function() {
- return uuid_;
+ return uuid_;
},
- set: function() {},
+ set: function() {}
}
});
};
+var ValidateBluetoothGATTServerDescriptorInit = function(initData) {
+ return AV.validateArgs(
+ [
+ initData['uuid'],
+ initData['readPermission'] || false,
+ initData['writePermission'] || false,
+ initData['encryptedReadPermission'] || false,
+ initData['encryptedWritePermission'] || false,
+ initData['encryptedSignedReadPermission'] || false,
+ initData['encryptedSignedWritePermission'] || false,
+ initData['readValueRequestCallback'] || null,
+ initData['writeValueRequestCallback'] || null
+ ],
+ [
+ {
+ name: 'uuid',
+ type: AV.Types.STRING,
+ validator: IsUuidValid
+ },
+ {
+ name: 'readPermission',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'writePermission',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'encryptedReadPermission',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'encryptedWritePermission',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'encryptedSignedReadPermission',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'encryptedSignedWritePermission',
+ type: AV.Types.BOOLEAN
+ },
+ {
+ name: 'readValueRequestCallback',
+ type: AV.Types.FUNCTION,
+ nullable: true
+ },
+ {
+ name: 'writeValueRequestCallback',
+ type: AV.Types.FUNCTION,
+ nullable: true
+ }
+ ]
+ );
+};
+
var BluetoothGATTServerDescriptor = function(data, address) {
- // TODO: validate data and set default values
+ data = ValidateBluetoothGATTServerDescriptorInit(data);
BluetoothGATTDescriptor.call(this, data, null);