2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
21 #include <JSWebAPIError.h>
23 #include "BluetoothCallbackUtil.h"
24 #include "BluetoothAdapter.h"
28 using namespace DeviceAPI::Common;
33 static Eina_Bool jobCompleteCB(void *userData){
36 BluetoothCallbackUserDataPtr data = static_cast<BluetoothCallbackUserDataPtr>(userData);
39 LoggerW("BluetoothCallbackUserDataPtr is NULL");
43 if(!(data->mUserData)) {
44 LoggerW("MulticallbackUserData is NULL");
49 switch(data->mCBType) {
50 case BluetoothCallbackUserData::BT_CB_SUCCESS:
52 LoggerD("BT_CB_SUCCESS");
53 data->mUserData->invokeCallback("success");
56 case BluetoothCallbackUserData::BT_CB_ERROR:
58 LoggerD("BT_CB_ERROR");
59 data->mUserData->invokeCallback("error", JSWebAPIError::makeJSWebAPIError(data->mUserData->getContext(), *(data->mError)));
62 case BluetoothCallbackUserData::BT_CB_DEVICE:
64 LoggerD("BT_CB_DEVICE");
65 BluetoothAdapter::getInstance()->returnDevice(data->mAddress, data->mUserData);
68 case BluetoothCallbackUserData::BT_CB_DEVICES:
70 LoggerD("BT_CB_DEVICES");
71 BluetoothAdapter::getInstance()->returnKnownDevices(data->mUserData);
74 case BluetoothCallbackUserData::BT_CB_SERVICE:
76 LoggerD("BT_CB_SERVICE");
77 BluetoothAdapter::getInstance()->returnRegisteredService(data->mUUID, data->mName, data->mUserData);
82 LoggerW("Unknown callback type");
90 void BluetoothCallbackUtil::syncToAsyncSuccessCallback(Common::MultiCallbackUserDataPtr userData)
92 BluetoothCallbackUserDataPtr data = new BluetoothCallbackUserData(userData, BluetoothCallbackUserData::BT_CB_SUCCESS);
93 ecore_idler_add(jobCompleteCB, data);
96 void BluetoothCallbackUtil::syncToAsyncErrorCallback(DeviceAPI::Common::MultiCallbackUserDataPtr userData, Common::BasePlatformException *error)
98 BluetoothCallbackUserDataPtr data = new BluetoothCallbackUserData(userData, error);
99 ecore_idler_add(jobCompleteCB, data);
102 void BluetoothCallbackUtil::syncToAsyncDeviceCallback(Common::MultiCallbackUserDataPtr userData, std::string &address)
104 BluetoothCallbackUserDataPtr data = new BluetoothCallbackUserData(userData, address);
105 ecore_idler_add(jobCompleteCB, data);
108 void BluetoothCallbackUtil::syncToAsyncDeviceArrayCallback(Common::MultiCallbackUserDataPtr userData)
110 BluetoothCallbackUserDataPtr data = new BluetoothCallbackUserData(userData, BluetoothCallbackUserData::BT_CB_DEVICES);
111 ecore_idler_add(jobCompleteCB, data);
114 void BluetoothCallbackUtil::syncToAsyncServiceCallback(Common::MultiCallbackUserDataPtr userData, std::string &uuid, std::string &name)
116 BluetoothCallbackUserDataPtr data = new BluetoothCallbackUserData(userData, uuid, name);
117 ecore_idler_add(jobCompleteCB, data);