7d1601e1182cff0d1c7a2bd3078b687aa2291a32
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_edr_adapter / android / caedrutils.h
1 /* ****************************************************************
2  *
3  * Copyright 2014 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************/
20
21 /**
22  * @file
23  * This file contains the APIs for BT communications.
24  */
25 #ifndef CA_EDR_UTILS_H_
26 #define CA_EDR_UTILS_H_
27
28 #include "cacommon.h"
29 #include "cathreadpool.h"
30 #include "caedrinterface.h"
31 #include "jni.h"
32
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #endif
37
38 /**
39  * Get address from device socket.
40  * @param[in]   env                 JNI interface pointer.
41  * @param[in]   bluetoothSocketObj  bluetooth socket object.
42  * @return  Bluetooth device address.
43  */
44 jstring CAEDRNativeGetAddressFromDeviceSocket(JNIEnv *env, jobject bluetoothSocketObj);
45
46 /**
47  * Get local device address.
48  * @param[in]   env                 JNI interface pointer.
49  * @return  Bluetooth device address.
50  */
51 jstring CAEDRNativeGetLocalDeviceAddress(JNIEnv *env);
52
53 /**
54  * Get bonded devices list.
55  * @param[in]   env                 JNI interface pointer.
56  * @return  Bonded devices list.
57  */
58 jobjectArray CAEDRNativeGetBondedDevices(JNIEnv *env);
59
60 /**
61  * Get Bluetooth device state.
62  * @param[in]   env                 JNI interface pointer.
63  * @return  Bluetooth device state.
64  */
65 jint CAEDRNativeGetBTStateOnInfo(JNIEnv *env);
66
67 /**
68  * Check the BT Adapter enable.
69  * @param[in]   env                 JNI interface pointer.
70  * @return  JNI_TRUE or JNI_FALSE.
71  */
72 jboolean CAEDRNativeIsEnableBTAdapter(JNIEnv *env);
73
74 /**
75  * Get address from BT device.
76  * @param[in]   env                 JNI interface pointer.
77  * @param[in]   bluetoothDevice     bluetooth socket object.
78  * @return  Bluetooth device address.
79  */
80 jstring CAEDRNativeGetAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice);
81
82 /**
83  * This function will create the device state list.
84  */
85 void CAEDRNativeCreateDeviceStateList();
86
87 /**
88  * Update connection state of device.
89  * @param[in]  state            connection state.
90  * @param[in]  address          remote address.
91  */
92 void CAEDRUpdateDeviceState(CAConnectedState_t state, const char *address);
93
94 /**
95  * Add device object to the list.
96  * @param[in]  state            connection state object.
97  */
98 void CAEDRNativeAddDeviceStateToList(CAConnectedDeviceInfo_t *state);
99
100 /**
101  * Check whether the device exist in the list or not.
102  * @param[in]  remoteAddress    remote address.
103  * @return true or false.
104  */
105 bool CAEDRNativeIsDeviceInList(const char *remoteAddress);
106
107 /**
108  * Close all socket.
109  * @param[in]   env       JNI interface pointer.
110  */
111 void CAEDRNativeSocketCloseToAll(JNIEnv *env);
112
113 /**
114  * Remove all device objects in the list.
115  */
116 void CAEDRNativeRemoveAllDeviceState();
117
118 /**
119  * Remove target device in the list.
120  * @param[in]   remoteAddress    remote address.
121  */
122 void CAEDRNativeRemoveDevice(const char *remoteAddress);
123
124 /**
125  * Get current device connection state.
126  * @param[in]   remoteAddress    remote address.
127  * @return  STATE_DISCONNECTED or STATE_CONNECTED.
128  */
129 CAConnectedState_t CAEDRIsConnectedDevice(const char *remoteAddress);
130
131 /**
132  * This function will create the device socket list.
133  */
134 void CAEDRNativeCreateDeviceSocketList();
135
136 /**
137  * Add device object to the list.
138  * @param[in]  env              JNI interface pointer.
139  * @param[in]  deviceSocket     device socket object.
140  */
141 void CAEDRNativeAddDeviceSocketToList(JNIEnv *env, jobject deviceSocket);
142
143 /**
144  * Add device object to the list.
145  * @param[in]  env              JNI interface pointer.
146  * @param[in]  remoteAddress    remote address.
147  * @return true or false.
148  */
149 bool CAEDRNativeIsDeviceSocketInList(JNIEnv *env, const char *remoteAddress);
150
151 /**
152  * Add device object to the list.
153  * @param[in]  env              JNI interface pointer.
154  */
155 void CAEDRNativeRemoveAllDeviceSocket(JNIEnv *env);
156
157 /**
158  * Add device object to the list.
159  * @param[in]  env              JNI interface pointer.
160  * @param[in]  deviceSocket     device socket object.
161  */
162 void CAEDRNativeRemoveDeviceSocket(JNIEnv *env, jobject deviceSocket);
163
164 /**
165  * Remove device socket.
166  * @param[in]   env             JNI interface pointer.
167  * @param[in]   address         remote address.
168  */
169 void CAEDRNativeRemoveDeviceSocketBaseAddr(JNIEnv *env, jstring address);
170
171 /**
172  * Get device socket object from the list.
173  * @param[in]  idx              index of device list.
174  * @return Device socket object or NULL.
175  */
176 jobject CAEDRNativeGetDeviceSocket(uint32_t idx);
177
178 /**
179  * Get device socket address.
180  * @param[in]   env             JNI interface pointer.
181  * @param[in]   remoteAddress   remote address.
182  * @return  Device socket object or NULL.
183  */
184 jobject CAEDRNativeGetDeviceSocketBaseAddr(JNIEnv *env, const char* remoteAddress);
185
186 /**
187  * Get length of device socket list.
188  * @return length of list.
189  */
190 uint32_t CAEDRGetSocketListLength();
191
192 /**
193  * Get device information from list.
194  * @param[in]   remoteAddress   remote address.
195  * @return  Device information object or NULL.
196  */
197 CAConnectedDeviceInfo_t *CAEDRGetDeviceInfoFromAddress(const char *remoteAddress);
198
199 #ifdef __cplusplus
200 } /* extern "C" */
201 #endif
202
203 #endif /* CA_EDR_UTILS_H_ */
204