notificationCB,
errorCB
) {
- var args = AV.validateArgs(
- Array.prototype.slice.call(arguments, 1),
- [
- {
- name: 'clientAddress',
- type: AV.Types.STRING,
- optional: true,
- nullable: true
- },
- {
- name: 'notificationCB',
- type: AV.Types.LISTENER,
- values: [
- 'onnotificationsuccess',
- 'onnotificationfail',
- 'onnotificationfinish'
- ],
- optional: true,
- nullable: true
- },
- {
- name: 'errorCB',
- type: AV.Types.FUNCTION,
- optional: true,
- nullable: true
- }
- ]
- );
+ var args = AV.validateArgs(Array.prototype.slice.call(arguments, 1), [
+ {
+ name: 'clientAddress',
+ type: AV.Types.STRING,
+ optional: true,
+ nullable: true
+ },
+ {
+ name: 'notificationCB',
+ type: AV.Types.LISTENER,
+ values: [
+ 'onnotificationsuccess',
+ 'onnotificationfail',
+ 'onnotificationfinish'
+ ],
+ optional: true,
+ nullable: true
+ },
+ {
+ name: 'errorCB',
+ type: AV.Types.FUNCTION,
+ optional: true,
+ nullable: true
+ }
+ ]);
var callArgs = {
value: BluetoothManager_toByteArray(value),
}
};
+var BluetoothGATTServer_valid_unregisterAllServices_errors = [
+ 'InvalidStateError',
+ 'AbortError'
+];
+
+var BluetoothGATTServer_valid_unregisterAllServices_exceptions = [
+ 'TypeMismatchError',
+ 'SecurityError'
+];
+
+BluetoothGATTServer.prototype.unregisterAllServices = function() {
+ privUtils_.log('Entered BluetoothGATTServer.unregisterAllServices()');
+ var args = AV.validateArgs(arguments, [
+ {
+ name: 'successCallback',
+ type: AV.Types.FUNCTION,
+ optional: true,
+ nullable: true
+ },
+ {
+ name: 'errorCallback',
+ type: AV.Types.FUNCTION,
+ optional: true,
+ nullable: true
+ }
+ ]);
+
+ var servicesToUnregister = [];
+ for (var i = 0; i < _BluetoothGATTServerServices.length; ++i) {
+ if (!T.isNullOrUndefined(_BluetoothGATTServerServices[i]._id)) {
+ servicesToUnregister.push(_BluetoothGATTServerServices[i]);
+ }
+ }
+
+ if (servicesToUnregister.length) {
+ privUtils_.log(
+ 'Number of services to unregister: ' + servicesToUnregister.length
+ );
+ var unregisterServiceCallbacksAggregator = new ResultCallbacksAggregator(
+ servicesToUnregister.length,
+ function onAllSucceeded() {
+ _BluetoothGATTServerServices = [];
+ _BluetoothGATTServerServicesRegisteredInNativeLayer = [];
+ native.callIfPossible(args.successCallback);
+ },
+ function onFailure(error) {
+ native.callIfPossible(
+ args.errorCallback,
+ native.getErrorObjectAndValidate(
+ error,
+ BluetoothGATTServer_valid_unregisterAllServices_errors,
+ AbortError
+ )
+ );
+ }
+ );
+
+ for (var i = 0; i < servicesToUnregister.length; ++i) {
+ var serviceIndex = _BluetoothGATTServerServices.findIndex(function(service) {
+ return service._id === servicesToUnregister[i]._id;
+ });
+
+ var serviceId = servicesToUnregister[i]._id;
+
+ var unregisterServiceCallback = function(result) {
+ if (native.isFailure(result)) {
+ unregisterServiceCallbacksAggregator.errorCallback(
+ native.getErrorObjectAndValidate(
+ result,
+ BluetoothGATTServer_valid_unregisterAllServices_errors,
+ AbortError
+ )
+ );
+ } else {
+ delete _BluetoothGATTServerServicesRegisteredInNativeLayer[serviceId];
+ _BluetoothGATTServerServices.splice(serviceIndex, 1);
+ unregisterServiceCallbacksAggregator.successCallback();
+ }
+ };
+
+ var callArgs = {
+ _id: servicesToUnregister[i]._id,
+ idsToRemoveFromNativeLayer: _getIncludedServicesAndItsComponentsIdsRecursively(
+ servicesToUnregister[i]
+ )
+ };
+
+ var result = native.call(
+ 'BluetoothGATTServerUnregisterService',
+ callArgs,
+ unregisterServiceCallback
+ );
+
+ if (native.isFailure(result)) {
+ throw native.getErrorObjectAndValidate(
+ result,
+ BluetoothGATTServer_valid_unregisterAllServices_exceptions,
+ AbortError
+ );
+ }
+ }
+ } else {
+ privUtils_.log(
+ 'Nothing registered in native layer, calling BluetoothGATTServer.stop()'
+ );
+
+ var callback = function(result) {
+ if (native.isFailure(result)) {
+ native.callIfPossible(
+ args.errorCallback,
+ native.getErrorObjectAndValidate(
+ result,
+ BluetoothGATTServer_valid_unregisterAllServices_errors,
+ AbortError
+ )
+ );
+ } else {
+ _BluetoothGATTServerServices = [];
+ _BluetoothGATTServerServicesRegisteredInNativeLayer = {};
+ native.callIfPossible(args.successCallback);
+ }
+ };
+
+ var result = native.call('BluetoothGATTServerStop', {}, callback);
+ if (native.isFailure(result)) {
+ throw native.getErrorObjectAndValidate(
+ result,
+ BluetoothGATTServer_valid_unregisterAllServices_exceptions,
+ AbortError
+ );
+ }
+ }
+};
+
/*
* Objects of this class are used to wait for multiple callbacks results.
*