Initial commit for Bluetooth plugin for HTML5 UI
[profile/ivi/wrt-plugins-ivi-bt.git] / src / BluetoothCallbackUtil.h
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 #ifndef __TIZEN_BLUETOOTH_CALLBACK_UTIL_H__
19 #define __TIZEN_BLUETOOTH_CALLBACK_UTIL_H__
20
21 #include <string>
22 #include <JavaScriptCore/JavaScript.h>
23 #include <MultiCallbackUserData.h>
24 #include <PlatformException.h>
25
26
27 namespace DeviceAPI {
28 namespace Bluetooth {
29
30
31 class BluetoothCallbackUserData
32 {
33 public:
34     typedef enum {
35         BT_CB_SUCCESS,
36         BT_CB_ERROR,
37         BT_CB_DEVICE,
38         BT_CB_DEVICES,
39         BT_CB_SERVICE
40     } callbackTypeE;
41
42
43     BluetoothCallbackUserData(DeviceAPI::Common::MultiCallbackUserDataPtr userData, callbackTypeE type)
44     {
45         mUserData = userData;
46         mCBType = type;
47     };
48
49     BluetoothCallbackUserData(DeviceAPI::Common::MultiCallbackUserDataPtr userData, Common::BasePlatformException *error)
50     {
51         mUserData = userData;
52         mError = error;
53         mCBType = BT_CB_ERROR;
54     };
55
56     BluetoothCallbackUserData(DeviceAPI::Common::MultiCallbackUserDataPtr userData, std::string &uuid, std::string &name)
57     {
58         mUserData = userData;
59         mCBType = BT_CB_SERVICE;
60         mUUID = uuid;
61         mName = name;
62     };
63
64     BluetoothCallbackUserData(DeviceAPI::Common::MultiCallbackUserDataPtr userData, std::string &address)
65     {
66         mUserData = userData;
67         mCBType = BT_CB_DEVICE;
68         mAddress = address;
69     };
70
71     virtual ~BluetoothCallbackUserData()
72     {
73         if(mCBType == BT_CB_ERROR)
74             delete mError;
75     };
76
77
78     callbackTypeE mCBType;
79     DeviceAPI::Common::MultiCallbackUserDataPtr mUserData;
80     Common::BasePlatformException *mError;
81     std::string mUUID;
82     std::string mName;
83     std::string mAddress;
84 };
85
86 typedef BluetoothCallbackUserData* BluetoothCallbackUserDataPtr;
87
88
89 class BluetoothCallbackUtil
90 {
91 public:
92     static void syncToAsyncSuccessCallback(DeviceAPI::Common::MultiCallbackUserDataPtr userData);
93     static void syncToAsyncErrorCallback(DeviceAPI::Common::MultiCallbackUserDataPtr userData, Common::BasePlatformException *error);
94     static void syncToAsyncDeviceCallback(DeviceAPI::Common::MultiCallbackUserDataPtr userData, std::string &address);
95     static void syncToAsyncDeviceArrayCallback(DeviceAPI::Common::MultiCallbackUserDataPtr userData);
96     static void syncToAsyncServiceCallback(DeviceAPI::Common::MultiCallbackUserDataPtr userData, std::string &uuid, std::string &name);
97 };
98
99
100 } // Bluetooth
101 } // DeviceAPI
102
103
104
105 #endif // __TIZEN_BLUETOOTH_CALLBACK_UTIL_H__