[Bluetooth] Implement BluetoothGATTServer::getConnectionMtu() 31/237931/6
authorPawel Wasowski <p.wasowski2@samsung.com>
Mon, 6 Jul 2020 14:24:35 +0000 (16:24 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Wed, 26 Aug 2020 06:13:10 +0000 (06:13 +0000)
Related ACR: TWDAPI-263

[Verification] The function was tested in Chrome Dev Tool and worked
               fine.

Change-Id: I2fd9c719e8871cb5db86e2bc65f8fbbc853fa47d
Signed-off-by: Pawel Wasowski <p.wasowski2@samsung.com>
src/bluetooth/bluetooth_api.js
src/bluetooth/bluetooth_gatt_server.cc
src/bluetooth/bluetooth_gatt_server.h
src/bluetooth/bluetooth_instance.cc
src/bluetooth/bluetooth_instance.h

index 7c58de23aefaf5699fb7ae3f44447c5c02cef3e5..b2dd582c63f011c7013e0057bea23afbda97b493 100755 (executable)
@@ -2840,6 +2840,45 @@ BluetoothGATTServer.prototype.stop = function() {
     }
 }
 
+var BluetoothGATTServer_valid_getConnectionMtu_errors = ['InvalidStateError', 'NotSupportedError', 'UnknownError'];
+var BluetoothGATTServer_valid_getConnectionMtu_exceptions = ['TypeMismatchError', 'SecurityError'];
+
+BluetoothGATTServer.prototype.getConnectionMtu = function() {
+    privUtils_.log('Entered BluetoothGATTServer.getConnectionMtu()');
+    var args = AV.validateArgs(arguments, [
+        {
+            name: 'clientAddress',
+            type: AV.Types.STRING
+        },
+        {
+            name: 'successCallback',
+            type: AV.Types.FUNCTION
+        },
+        {
+            name: 'errorCallback',
+            type: AV.Types.FUNCTION,
+            optional: true
+        }
+    ]);
+
+    var callback = function(result) {
+        if (native.isFailure(result)) {
+            native.callIfPossible(args.errorCallback,
+                                  native.getErrorObjectAndValidate(result,
+                                    BluetoothGATTServer_valid_getConnectionMtu_errors, UnknownError));
+        } else {
+            args.successCallback(native.getResultObject(result));
+        }
+    };
+
+    var result = native.call('BluetoothGATTServerGetConnectionMtu',
+                             {clientAddress: args.clientAddress}, callback);
+    if (native.isFailure(result)) {
+        throw native.getErrorObjectAndValidate(result, BluetoothGATTServer_valid_getConnectionMtu_exceptions,
+                                               UnknownError);
+    }
+}
+
 var GATTServer = new BluetoothGATTServer();
 
 // class BluetoothManager ///////////////////////////
index 255433e4ed0785ff2ded777e06fcba1a134ff922..b2273112256dd88a87b3b83955154503ee1c5fd7 100644 (file)
@@ -112,6 +112,23 @@ void BluetoothGATTServer::Stop(picojson::object& out) {
   }
 }
 
+void BluetoothGATTServer::GetConnectionMtu(const picojson::value& args,
+                                           picojson::object& out) {
+  ScopeLogger();
+
+  const auto client_address = args.get("clientAddress").get<std::string>();
+
+  unsigned int mtu = 0;
+  auto ret = bt_gatt_server_get_device_mtu(client_address.c_str(), &mtu);
+  if (BT_ERROR_NONE != ret) {
+    LoggerE("bt_gatt_server_get_device_mtu(): %d (%s)", ret, get_error_message(ret));
+    ReportError(BluetoothErrorToPlatformResult(ret), &out);
+  }
+  LoggerD("bt_gatt_server_get_device_mtu(): success, MTU: %u", mtu);
+
+  ReportSuccess(picojson::value{static_cast<double>(mtu)}, out);
+}
+
 PlatformResult BluetoothGATTServer::Initialize() {
   ScopeLogger();
 
index 6c5d83d2605d3b91fc7ee6ba09340eb8c2029929..e28789c865a61fd1c63bacc93a52c6efdbfb7701 100644 (file)
@@ -36,6 +36,7 @@ class BluetoothGATTServer {
 
   void Start(picojson::object& out);
   void Stop(picojson::object& out);
+  void GetConnectionMtu(const picojson::value& args, picojson::object& out);
 
   static bool DestroyService(int total, int index, bt_gatt_h handle, void* user_data);
   static bool DestroyCharacteristic(int total, int index, bt_gatt_h handle, void* user_data);
index 2ff079ea9f322b7e194f96883988632e565b8b53..ccad4e76b3d8ae0b4e1107d1d54da1beb649cf53 100644 (file)
@@ -102,6 +102,7 @@ BluetoothInstance::BluetoothInstance()
 
   REGISTER_METHOD(BluetoothGATTServerStart);
   REGISTER_METHOD(BluetoothGATTServerStop);
+  REGISTER_METHOD(BluetoothGATTServerGetConnectionMtu);
 
 #undef REGISTER_METHOD
 }
@@ -480,5 +481,24 @@ void BluetoothInstance::BluetoothGATTServerStop(const picojson::value& args,
   ReportSuccess(out);
 }
 
+void BluetoothInstance::BluetoothGATTServerGetConnectionMtu(const picojson::value& args,
+                                                            picojson::object& out) {
+  ScopeLogger();
+
+  CHECK_PRIVILEGE_ACCESS(kPrivilegeBluetooth, &out);
+
+  double callback_id = args.get(JSON_CALLBACK_ID).get<double>();
+  worker.add_job([this, callback_id, args] {
+    ScopeLogger("Async call: BluetoothGATTServerGetConnectionMtu");
+    picojson::value response = picojson::value(picojson::object());
+    picojson::object& async_out = response.get<picojson::object>();
+    async_out[JSON_CALLBACK_ID] = picojson::value(callback_id);
+    this->bluetooth_gatt_server_.GetConnectionMtu(args, async_out);
+    this->PostMessage(response.serialize().c_str());
+  });
+
+  ReportSuccess(out);
+}
+
 }  // namespace bluetooth
 }  // namespace extension
index 0ee235dfad65934b532d37785acf8701afbf2673..880949d14915ff17b40d03f881d76d2e8d2cb593 100644 (file)
@@ -110,6 +110,7 @@ class BluetoothInstance : public common::ParsedInstance {
                                                      picojson::object& out);
   void BluetoothGATTServerStart(const picojson::value& args, picojson::object& out);
   void BluetoothGATTServerStop(const picojson::value& args, picojson::object& out);
+  void BluetoothGATTServerGetConnectionMtu(const picojson::value& args, picojson::object& out);
 
   BluetoothAdapter bluetooth_adapter_;
   BluetoothDevice bluetooth_device_;