}
return characteristics;
}
+
+ /*
+ * If this function is called as a constructor of BluetoothGATTServerService's
+ * base class, some properties have to be left configurable, to enable redefinition.
+ * Otherwise, if this function is called to create BluetoothGATTService,
+ * they are left non-configurable.
+ *
+ * If BluetoothGATTService will be a base for any other class in the future,
+ * the line below may have to be updated to take into account the new class.
+ */
+ var isConfigurable = this instanceof BluetoothGATTServerService;
+
Object.defineProperties(this, {
uuid: { value: uuid_, writable: false, enumerable: true },
serviceUuid: { value: serviceUuid_, writable: false, enumerable: true },
- services: { enumerable: true, set: function() {}, get: servicesGetter },
+ services: {
+ enumerable: true,
+ configurable: isConfigurable,
+ set: function() {},
+ get: servicesGetter
+ },
characteristics: {
enumerable: true,
+ configurable: isConfigurable,
set: function() {},
get: characteristicsGetter
}
});
};
+var CurrentGATTServerEntityId = 0;
+function NextGattServerEntityID() {
+ return ++CurrentGATTServerEntityId;
+}
+
+//class BluetoothGATTServerService ///////////////////////////
+var BluetoothGATTServerService = function(data) {
+ // TODO: validate data and set default values
+
+ BluetoothGATTService.call(this, data, null);
+
+ var services_ = data.includedServices.map(function(serviceData) {
+ return new BluetoothGATTServerService(serviceData, null);
+ });
+ var characteristics_ = data.characteristics.map(function(characteristicData) {
+ return new BluetoothGATTServerCharacteristic(characteristicData, null);
+ });
+
+ Object.defineProperties(this, {
+ isPrimary: { value: data.isPrimary, writable: false, enumerable: true },
+ services: {
+ enumerable: true,
+ get: function() {
+ return services_.slice();
+ },
+ set: function() {}
+ },
+ characteristics: {
+ enumerable: true,
+ get: function() {
+ return characteristics_.slice();
+ },
+ set: function() {}
+ },
+ // This property is "private" and meant not to be used by users
+ _id: {
+ // It has to be enumerable, to be serialized with JSON.stringify()
+ enumerable: true,
+ value: NextGattServerEntityID()
+ }
+ });
+};
+
+BluetoothGATTServerService.prototype = Object.create(BluetoothGATTService.prototype);
+
+Object.defineProperty(BluetoothGATTServerService.prototype, 'constructor', {
+ value: BluetoothGATTServerService,
+ enumerable: false,
+ writable: true
+});
+
var numberArrayToByteArray = function(array) {
var d = [];
var isWriteNoResponse_ = data.isWriteNoResponse;
var uuid_ = data.uuid;
+ /*
+ * If this function is called as a constructor of BluetoothGATTServerCharacteristic's
+ * base class, some properties have to be left configurable, to enable redefinition.
+ * Otherwise, if this function is called to create BluetoothGATTCharacteristic,
+ * they are left non-configurable.
+ *
+ * If BluetoothGATTCharacteristic will be a base for any other class in the future,
+ * the line below may have to be updated to take into account the new class.
+ */
+ var isConfigurable = this instanceof BluetoothGATTServerCharacteristic;
+
Object.defineProperties(this, {
descriptors: {
enumerable: true,
+ configurable: isConfigurable,
get: function() {
return descriptors_.slice();
},
};
};
+//class BluetoothGATTServerCharacteristic ///////////////////////////
+var BluetoothGATTServerCharacteristic = function(data) {
+ // TODO: validate data and set default values
+
+ BluetoothGATTCharacteristic.call(this, data, null);
+
+ var descriptors_ = data.descriptors.map(function(descriptor_data) {
+ return new BluetoothGATTServerDescriptor(descriptor_data, null);
+ });
+
+ Object.defineProperties(this, {
+ descriptors: {
+ enumerable: true,
+ get: function() {
+ return descriptors_.slice();
+ },
+ set: function() {}
+ },
+ readPermission: {
+ enumerable: true,
+ get: function() {
+ return data.readPermission;
+ },
+ set: function() {}
+ },
+ writePermission: {
+ enumerable: true,
+ get: function() {
+ return data.writePermission;
+ },
+ set: function() {}
+ },
+ encryptedReadPermission: {
+ enumerable: true,
+ get: function() {
+ return data.encryptedReadPermission;
+ },
+ set: function() {}
+ },
+ encryptedWritePermission: {
+ enumerable: true,
+ get: function() {
+ return data.encryptedWritePermission;
+ },
+ set: function() {}
+ },
+ encryptedSignedReadPermission: {
+ enumerable: true,
+ get: function() {
+ return data.encryptedSignedReadPermission;
+ },
+ set: function() {}
+ },
+ encryptedSignedWritePermission: {
+ enumerable: true,
+ get: function() {
+ return data.encryptedSignedWritePermission;
+ },
+ set: function() {}
+ },
+ // This property is "private" and meant not to be used by users
+ _id: {
+ // It has to be enumerable, to be serialized with JSON.stringify()
+ enumerable: true,
+ value: NextGattServerEntityID()
+ }
+ });
+
+ this.readValue = function() {
+ throw new WebAPIException(
+ 'NotSupportedError',
+ 'This method cannot be called on BluetoothGATTServerCharacteristic'
+ );
+ };
+
+ this.writeValue = function() {
+ throw new WebAPIException(
+ 'NotSupportedError',
+ 'This method cannot be called on BluetoothGATTServerCharacteristic'
+ );
+ };
+
+ this.addValueChangeListener = function() {
+ throw new WebAPIException(
+ 'NotSupportedError',
+ 'This method cannot be called on BluetoothGATTServerCharacteristic'
+ );
+ };
+
+ this.removeValueChangeListener = function() { /* Intended no operation */ };
+};
+
+BluetoothGATTServerCharacteristic.prototype = Object.create(BluetoothGATTCharacteristic.prototype);
+
+Object.defineProperty(BluetoothGATTServerCharacteristic.prototype, 'constructor', {
+ value: BluetoothGATTServerCharacteristic,
+ enumerable: false,
+ writable: true
+});
+
/**
* Creates a manager for specified listener event. Manager handles multiple
* registered listeners
});
};
+var BluetoothGATTServerDescriptor = function(data, address) {
+ // TODO: validate data and set default values
+
+ BluetoothGATTDescriptor.call(this, data, null);
+
+ Object.defineProperties(this, {
+ readPermission: {
+ enumerable: true,
+ get: function() {
+ return data.readPermission;
+ },
+ set: function() {}
+ },
+ writePermission: {
+ enumerable: true,
+ get: function() {
+ return data.writePermission;
+ },
+ set: function() {}
+ },
+ encryptedReadPermission: {
+ enumerable: true,
+ get: function() {
+ return data.encryptedReadPermission;
+ },
+ set: function() {}
+ },
+ encryptedWritePermission: {
+ enumerable: true,
+ get: function() {
+ return data.encryptedWritePermission;
+ },
+ set: function() {}
+ },
+ encryptedSignedReadPermission: {
+ enumerable: true,
+ get: function() {
+ return data.encryptedSignedReadPermission;
+ },
+ set: function() {}
+ },
+ encryptedSignedWritePermission: {
+ enumerable: true,
+ get: function() {
+ return data.encryptedSignedWritePermission;
+ },
+ set: function() {}
+ },
+ // This property is "private" and meant not to be used by users
+ _id: {
+ // It has to be enumerable, to be serialized with JSON.stringify()
+ enumerable: true,
+ value: NextGattServerEntityID()
+ }
+ });
+
+ this.readValue = function() {
+ throw new WebAPIException(
+ 'NotSupportedError',
+ 'This method cannot be called on BluetoothGATTServerDescriptor'
+ );
+ };
+
+ this.writeValue = function() {
+ throw new WebAPIException(
+ 'NotSupportedError',
+ 'This method cannot be called on BluetoothGATTServerDescriptor'
+ );
+ };
+};
+
+BluetoothGATTServerDescriptor.prototype = Object.create(BluetoothGATTDescriptor.prototype);
+
+Object.defineProperty(BluetoothGATTServerDescriptor.prototype, 'constructor', {
+ value: BluetoothGATTServerDescriptor,
+ enumerable: false,
+ writable: true
+});
+
// class BluetoothAdapter ///////////////////////////
var BluetoothAdapter = function() {
function nameGetter() {