bluetooth: Implement getDevice() for Adapter
authorVinicius Costa Gomes <vcgomes@gmail.com>
Mon, 12 Aug 2013 20:10:48 +0000 (17:10 -0300)
committerVinicius Costa Gomes <vcgomes@gmail.com>
Thu, 15 Aug 2013 18:20:13 +0000 (15:20 -0300)
This method returns an BluetoothDevice from the list of known devices.

bluetooth/bluetooth_api.js

index a105511..8cc65f3 100644 (file)
@@ -474,7 +474,28 @@ BluetoothAdapter.prototype.getKnownDevices = function(deviceArraySuccessCallback
   deviceArraySuccessCallback(adapter.known_devices);
 };
 
-BluetoothAdapter.prototype.getDevice = function(address, deviceSuccessCallback, errorCallback) {};
+BluetoothAdapter.prototype.getDevice = function(address, deviceSuccessCallback, errorCallback) {
+  if (adapter.serviceNotAvailable(errorCallback))
+    return;
+
+  if ((deviceSuccessCallback && typeof deviceSuccessCallback !== 'function') ||
+      (errorCallback && typeof errorCallback !== 'function')) {
+    throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
+  }
+
+  if (typeof address !== 'string') {
+    throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
+  }
+
+  var index = adapter.indexOfDevice(adapter.known_devices, address)
+  if (index == -1) {
+    var error = new tizen.WebAPIError(tizen.WebAPIException.NOT_FOUND_ERR)
+    errorCallback(error)
+    return;
+  }
+
+  deviceSuccessCallback(adapter.known_devices[index])
+};
 
 BluetoothAdapter.prototype.createBonding = function(address, successCallback, errorCallback) {
   if (adapter.serviceNotAvailable(errorCallback))