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.
19 #include <Commons/FunctionDefinition.h>
20 #include <Commons/FunctionDeclaration.h>
23 #include "plugin_config.h"
25 #define BLUETOOTH_FEATURE_API_ADMIN "http://tizen.org/privilege/bluetooth.admin"
26 #define BLUETOOTH_FEATURE_API_GAP "http://tizen.org/privilege/bluetooth.gap"
27 #define BLUETOOTH_FEATURE_API_SPP "http://tizen.org/privilege/bluetooth.spp"
28 #define BLUETOOTH_FEATURE_API_MANAGER "http://tizen.org/privilege/bluetoothmanager"
30 #define BLUETOOTH_DEVICE_CAP_ADMIN "bluetooth.admin"
31 #define BLUETOOTH_DEVICE_CAP_GAP "bluetooth.gap"
32 #define BLUETOOTH_DEVICE_CAP_SPP "bluetooth.spp"
33 #define BLUETOOTH_DEVICE_CAP_MANAGER "bluetoothmanager"
35 using namespace WrtDeviceApis::Commons;
40 static FunctionMapping createBluetoothFunctions();
41 static FunctionMapping BluetoothFunctions = createBluetoothFunctions();
43 #pragma GCC visibility push(default)
45 DEFINE_FUNCTION_GETTER(Bluetooth, BluetoothFunctions);
47 #pragma GCC visibility pop
49 static FunctionMapping createBluetoothFunctions()
54 ACE_CREATE_DEVICE_CAP(DEVICE_CAP_BLUETOOTH_ADMIN, BLUETOOTH_DEVICE_CAP_ADMIN);
55 ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_BLUETOOTH_ADMIN);
56 ACE_ADD_DEVICE_CAP(DEVICE_LIST_BLUETOOTH_ADMIN, DEVICE_CAP_BLUETOOTH_ADMIN);
58 ACE_CREATE_DEVICE_CAP(DEVICE_CAP_BLUETOOTH_GAP, BLUETOOTH_DEVICE_CAP_GAP);
59 ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_BLUETOOTH_GAP);
60 ACE_ADD_DEVICE_CAP(DEVICE_LIST_BLUETOOTH_GAP, DEVICE_CAP_BLUETOOTH_GAP);
62 ACE_CREATE_DEVICE_CAP(DEVICE_CAP_BLUETOOTH_SPP, BLUETOOTH_DEVICE_CAP_SPP);
63 ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_BLUETOOTH_SPP);
64 ACE_ADD_DEVICE_CAP(DEVICE_LIST_BLUETOOTH_SPP, DEVICE_CAP_BLUETOOTH_SPP);
66 ACE_CREATE_DEVICE_CAP(DEVICE_CAP_BLUETOOTH_MANAGER, BLUETOOTH_DEVICE_CAP_MANAGER);
67 ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_BLUETOOTH_MANAGER);
68 ACE_ADD_DEVICE_CAP(DEVICE_LIST_BLUETOOTH_MANAGER, DEVICE_CAP_BLUETOOTH_MANAGER);
74 ACE_CREATE_FEATURE(FEATURE_ADMIN, BLUETOOTH_FEATURE_API_ADMIN);
75 ACE_CREATE_FEATURE_LIST(BLUETOOTH_FEATURES_BLUETOOTH_ADMIN);
76 ACE_ADD_API_FEATURE(BLUETOOTH_FEATURES_BLUETOOTH_ADMIN, FEATURE_ADMIN);
78 ACE_CREATE_FEATURE(FEATURE_GAP, BLUETOOTH_FEATURE_API_GAP);
79 ACE_CREATE_FEATURE_LIST(BLUETOOTH_FEATURES_BLUETOOTH_GAP);
80 ACE_ADD_API_FEATURE(BLUETOOTH_FEATURES_BLUETOOTH_GAP, FEATURE_GAP);
82 ACE_CREATE_FEATURE(FEATURE_SPP, BLUETOOTH_FEATURE_API_SPP);
83 ACE_CREATE_FEATURE_LIST(BLUETOOTH_FEATURES_BLUETOOTH_SPP);
84 ACE_ADD_API_FEATURE(BLUETOOTH_FEATURES_BLUETOOTH_SPP, FEATURE_SPP);
86 ACE_CREATE_FEATURE(FEATURE_MANAGER, BLUETOOTH_FEATURE_API_MANAGER);
87 ACE_CREATE_FEATURE_LIST(BLUETOOTH_FEATURES_BLUETOOTH_MANAGER);
88 ACE_ADD_API_FEATURE(BLUETOOTH_FEATURES_BLUETOOTH_MANAGER, FEATURE_MANAGER);
89 ACE_ADD_API_FEATURE(BLUETOOTH_FEATURES_BLUETOOTH_MANAGER, FEATURE_ADMIN); // for backward compatibility
95 FunctionMapping BluetoothMapping;
97 // getDefaultAdapter()
98 AceFunction getDefaultAdapterFunc = ACE_CREATE_FUNCTION(
99 FUNCTION_BLUETOOTH_MANAGER_API_GET_DEFAULT_ADAPTER,
100 BLUETOOTH_MANAGER_API_GET_DEFAULT_ADAPTER,
101 BLUETOOTH_FEATURES_BLUETOOTH_GAP,
102 DEVICE_LIST_BLUETOOTH_GAP);
104 BluetoothMapping.insert(std::make_pair(
105 BLUETOOTH_MANAGER_API_GET_DEFAULT_ADAPTER,
106 getDefaultAdapterFunc));
109 AceFunction setNameFunc = ACE_CREATE_FUNCTION(
110 FUNCTION_BLUETOOTH_ADAPTER_API_SET_NAME,
111 BLUETOOTH_ADAPTER_API_SET_NAME,
112 BLUETOOTH_FEATURES_BLUETOOTH_ADMIN,
113 DEVICE_LIST_BLUETOOTH_ADMIN);
115 BluetoothMapping.insert(std::make_pair(
116 BLUETOOTH_ADAPTER_API_SET_NAME,
120 AceFunction setPoweredFunc = ACE_CREATE_FUNCTION(
121 FUNCTION_BLUETOOTH_ADAPTER_API_SET_POWERED,
122 BLUETOOTH_ADAPTER_API_SET_POWERED,
123 BLUETOOTH_FEATURES_BLUETOOTH_ADMIN,
124 DEVICE_LIST_BLUETOOTH_ADMIN);
126 BluetoothMapping.insert(std::make_pair(
127 BLUETOOTH_ADAPTER_API_SET_POWERED,
131 AceFunction setVisibleFunc = ACE_CREATE_FUNCTION(
132 FUNCTION_BLUETOOTH_ADAPTER_API_SET_VISIBLE,
133 BLUETOOTH_ADAPTER_API_SET_VISIBLE,
134 BLUETOOTH_FEATURES_BLUETOOTH_MANAGER,
135 DEVICE_LIST_BLUETOOTH_MANAGER);
137 BluetoothMapping.insert(std::make_pair(
138 BLUETOOTH_ADAPTER_API_SET_VISIBLE,
142 AceFunction discoverDevicesFunc = ACE_CREATE_FUNCTION(
143 FUNCTION_BLUETOOTH_ADAPTER_API_DISCOVER_DEVICES,
144 BLUETOOTH_ADAPTER_API_DISCOVER_DEVICES,
145 BLUETOOTH_FEATURES_BLUETOOTH_GAP,
146 DEVICE_LIST_BLUETOOTH_GAP);
148 BluetoothMapping.insert(std::make_pair(
149 BLUETOOTH_ADAPTER_API_DISCOVER_DEVICES,
150 discoverDevicesFunc));
153 AceFunction stopDiscoveryFunc = ACE_CREATE_FUNCTION(
154 FUNCTION_BLUETOOTH_ADAPTER_API_STOP_DISCOVERY,
155 BLUETOOTH_ADAPTER_API_STOP_DISCOVERY,
156 BLUETOOTH_FEATURES_BLUETOOTH_GAP,
157 DEVICE_LIST_BLUETOOTH_GAP);
159 BluetoothMapping.insert(std::make_pair(
160 BLUETOOTH_ADAPTER_API_STOP_DISCOVERY,
164 AceFunction getKnownDevicesFunc = ACE_CREATE_FUNCTION(
165 FUNCTION_BLUETOOTH_ADAPTER_API_GET_KNOWN_DEVICES,
166 BLUETOOTH_ADAPTER_API_GET_KNOWN_DEVICES,
167 BLUETOOTH_FEATURES_BLUETOOTH_GAP,
168 DEVICE_LIST_BLUETOOTH_GAP);
170 BluetoothMapping.insert(std::make_pair(
171 BLUETOOTH_ADAPTER_API_GET_KNOWN_DEVICES,
172 getKnownDevicesFunc));
175 AceFunction getDeviceFunc = ACE_CREATE_FUNCTION(
176 FUNCTION_BLUETOOTH_ADAPTER_API_GET_DEVICE,
177 BLUETOOTH_ADAPTER_API_GET_DEVICE,
178 BLUETOOTH_FEATURES_BLUETOOTH_GAP,
179 DEVICE_LIST_BLUETOOTH_GAP);
181 BluetoothMapping.insert(std::make_pair(
182 BLUETOOTH_ADAPTER_API_GET_DEVICE,
186 AceFunction createBondingFunc = ACE_CREATE_FUNCTION(
187 FUNCTION_BLUETOOTH_ADAPTER_API_CREATE_BONDING,
188 BLUETOOTH_ADAPTER_API_CREATE_BONDING,
189 BLUETOOTH_FEATURES_BLUETOOTH_GAP,
190 DEVICE_LIST_BLUETOOTH_GAP);
192 BluetoothMapping.insert(std::make_pair(
193 BLUETOOTH_ADAPTER_API_CREATE_BONDING,
197 AceFunction destroyBondingFunc = ACE_CREATE_FUNCTION(
198 FUNCTION_BLUETOOTH_ADAPTER_API_DESTROY_BONDING,
199 BLUETOOTH_ADAPTER_API_DESTROY_BONDING,
200 BLUETOOTH_FEATURES_BLUETOOTH_GAP,
201 DEVICE_LIST_BLUETOOTH_GAP);
203 BluetoothMapping.insert(std::make_pair(
204 BLUETOOTH_ADAPTER_API_DESTROY_BONDING,
205 destroyBondingFunc));
207 // registerRFCOMMServiceByUUID()
208 AceFunction registerRFCOMMServiceByUUIDFunc = ACE_CREATE_FUNCTION(
209 FUNCTION_BLUETOOTH_ADAPTER_API_REGISTER_RFCOMMSERVICE_BY_UUID,
210 BLUETOOTH_ADAPTER_API_REGISTER_RFCOMMSERVICE_BY_UUID,
211 BLUETOOTH_FEATURES_BLUETOOTH_SPP,
212 DEVICE_LIST_BLUETOOTH_SPP);
214 BluetoothMapping.insert(std::make_pair(
215 BLUETOOTH_ADAPTER_API_REGISTER_RFCOMMSERVICE_BY_UUID,
216 registerRFCOMMServiceByUUIDFunc));
218 // connectToServiceByUUID()
219 AceFunction connectToServiceByUUIDFunc = ACE_CREATE_FUNCTION(
220 FUNCTION_BLUETOOTH_DEVICE_API_CONNECT_TO_SERVICE_BY_UUID,
221 BLUETOOTH_DEVICE_API_CONNECT_TO_SERVICE_BY_UUID,
222 BLUETOOTH_FEATURES_BLUETOOTH_SPP,
223 DEVICE_LIST_BLUETOOTH_SPP);
225 BluetoothMapping.insert(std::make_pair(
226 BLUETOOTH_DEVICE_API_CONNECT_TO_SERVICE_BY_UUID,
227 connectToServiceByUUIDFunc));
230 AceFunction writeDataFunc = ACE_CREATE_FUNCTION(
231 FUNCTION_BLUETOOTH_SOCKET_API_WRITE_DATA,
232 BLUETOOTH_SOCKET_API_WRITE_DATA,
233 BLUETOOTH_FEATURES_BLUETOOTH_SPP,
234 DEVICE_LIST_BLUETOOTH_SPP);
236 BluetoothMapping.insert(std::make_pair(
237 BLUETOOTH_SOCKET_API_WRITE_DATA,
241 AceFunction readDataFunc = ACE_CREATE_FUNCTION(
242 FUNCTION_BLUETOOTH_SOCKET_API_READ_DATA,
243 BLUETOOTH_SOCKET_API_READ_DATA,
244 BLUETOOTH_FEATURES_BLUETOOTH_SPP,
245 DEVICE_LIST_BLUETOOTH_SPP);
247 BluetoothMapping.insert(std::make_pair(
248 BLUETOOTH_SOCKET_API_READ_DATA,
252 AceFunction closeFunc = ACE_CREATE_FUNCTION(
253 FUNCTION_BLUETOOTH_SOCKET_API_CLOSE,
254 BLUETOOTH_SOCKET_API_CLOSE,
255 BLUETOOTH_FEATURES_BLUETOOTH_SPP,
256 DEVICE_LIST_BLUETOOTH_SPP);
258 BluetoothMapping.insert(std::make_pair(
259 BLUETOOTH_SOCKET_API_CLOSE,
263 AceFunction hasServiceFunc = ACE_CREATE_FUNCTION(
264 FUNCTION_BLUETOOTH_CLASS_API_HAS_SERVICE,
265 BLUETOOTH_CLASS_API_HAS_SERVICE,
266 BLUETOOTH_FEATURES_BLUETOOTH_GAP,
267 DEVICE_LIST_BLUETOOTH_GAP);
269 BluetoothMapping.insert(std::make_pair(
270 BLUETOOTH_CLASS_API_HAS_SERVICE,
274 AceFunction unregisterFunc = ACE_CREATE_FUNCTION(
275 FUNCTION_BLUETOOTH_SERVICE_HANDLER_API_UNREGISTER,
276 BLUETOOTH_SERVICE_HANDLER_API_UNREGISTER,
277 BLUETOOTH_FEATURES_BLUETOOTH_SPP,
278 DEVICE_LIST_BLUETOOTH_SPP);
280 BluetoothMapping.insert(std::make_pair(
281 BLUETOOTH_SERVICE_HANDLER_API_UNREGISTER,
284 return BluetoothMapping;