[Bluetooth] Implement BluetoothGATTServerDescriptor::setReadValueRequestCallback() 86/244186/3
authorPawel Wasowski <p.wasowski2@samsung.com>
Tue, 15 Sep 2020 14:37:55 +0000 (16:37 +0200)
committerPawel Wasowski <p.wasowski2@samsung.com>
Tue, 15 Sep 2020 22:09:48 +0000 (00:09 +0200)
This commit isolates the implementation of setReadValueRequestCallback,
which is common for GATT characteristic and descriptor and adds it to
both these interfaces.

[Verification] Tested manually in Chrome DevTools. It works fine

Change-Id: I721db57deb597634dedad3b947590ad7a6e116b7
Signed-off-by: Pawel Wasowski <p.wasowski2@samsung.com>
src/bluetooth/bluetooth_api.js

index 5608e2e..6bfcbec 100755 (executable)
@@ -2512,7 +2512,6 @@ function _createReadValueRequestCallback(
         function(event, readValueRequestCallback, unusedErrorCallback) {
             var clientAddress = event.clientAddress;
             var offset = event.offset;
-            privUtils_.warn('event: ' + JSON.stringify(event));
 
             if (readValueRequestCallback) {
                 var requestReply = readValueRequestCallback(clientAddress, offset);
@@ -2524,7 +2523,6 @@ function _createReadValueRequestCallback(
                     statusCode: requestReply.statusCode,
                     data: requestReply.data
                 };
-                privUtils_.warn('event: ' + JSON.stringify(response));
                 var callback = function(result) {
                     if (native.isFailure(result)) {
                         native.callIfPossible(
@@ -2548,7 +2546,7 @@ function _createReadValueRequestCallback(
 
 var _BluetoothGATTServerReadWriteValueRequestCallbacks = {};
 
-BluetoothGATTServerCharacteristic.prototype.setReadValueRequestCallback = function() {
+var _setReadValueRequestCallbackCommon = function() {
     var args = AV.validateArgs(arguments, [
         {
             name: 'readValueRequestCallback',
@@ -2580,14 +2578,14 @@ BluetoothGATTServerCharacteristic.prototype.setReadValueRequestCallback = functi
         }
     ]);
 
-    var characteristicId = this._id;
+    var entityId = this._id;
 
     var callback = function(result) {
         if (native.isFailure(result)) {
             native.callIfPossible(args.errorCallback, native.getErrorObject(result));
         } else {
             var readValueRequestCallback = _createReadValueRequestCallback(
-                characteristicId,
+                entityId,
                 args.sendResponseSuccessCallback,
                 args.sendResponseErrorCallback
             );
@@ -2598,7 +2596,7 @@ BluetoothGATTServerCharacteristic.prototype.setReadValueRequestCallback = functi
                 }
             );
             _BluetoothGATTServerReadWriteValueRequestCallbacks[
-                'ReadValueCallback' + characteristicId
+                "ReadValueCallback" + entityId
             ] = readValueRequestCallback;
             native.callIfPossible(args.successCallback, native.getErrorObject(result));
         }
@@ -2616,6 +2614,8 @@ BluetoothGATTServerCharacteristic.prototype.setReadValueRequestCallback = functi
     }
 };
 
+BluetoothGATTServerCharacteristic.prototype.setReadValueRequestCallback = _setReadValueRequestCallbackCommon;
+
 /**
  * Creates a manager for specified listener event. Manager handles multiple
  * registered listeners
@@ -2981,6 +2981,8 @@ Object.defineProperty(BluetoothGATTServerDescriptor.prototype, 'constructor', {
     writable: true
 });
 
+BluetoothGATTServerDescriptor.prototype.setReadValueRequestCallback = _setReadValueRequestCallbackCommon;
+
 // class BluetoothAdapter ///////////////////////////
 var BluetoothAdapter = function() {
     function nameGetter() {