Changed to be used only once to create input stream.
[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  * EDR Socket Information for EDR transport
40  */
41 typedef struct
42 {
43     jobject deviceSocket;   /**< Bluetooth device socket info */
44     jobject inputStream;    /**< InputStream for read data */
45 } CAEDRSocketInfo_t;
46
47 /**
48  * Get address from device socket.
49  * @param[in]   env                 JNI interface pointer.
50  * @param[in]   bluetoothSocketObj  bluetooth socket object.
51  * @return  Bluetooth device address.
52  */
53 jstring CAEDRNativeGetAddressFromDeviceSocket(JNIEnv *env, jobject bluetoothSocketObj);
54
55 /**
56  * Get local device address.
57  * @param[in]   env                 JNI interface pointer.
58  * @return  Bluetooth device address.
59  */
60 jstring CAEDRNativeGetLocalDeviceAddress(JNIEnv *env);
61
62 /**
63  * Get bonded devices list.
64  * @param[in]   env                 JNI interface pointer.
65  * @return  Bonded devices list.
66  */
67 jobjectArray CAEDRNativeGetBondedDevices(JNIEnv *env);
68
69 /**
70  * Get Bluetooth device state.
71  * @param[in]   env                 JNI interface pointer.
72  * @return  Bluetooth device state.
73  */
74 jint CAEDRNativeGetBTStateOnInfo(JNIEnv *env);
75
76 /**
77  * Check the BT Adapter enable.
78  * @param[in]   env                 JNI interface pointer.
79  * @return  JNI_TRUE or JNI_FALSE.
80  */
81 jboolean CAEDRNativeIsEnableBTAdapter(JNIEnv *env);
82
83 /**
84  * Get address from BT device.
85  * @param[in]   env                 JNI interface pointer.
86  * @param[in]   bluetoothDevice     bluetooth socket object.
87  * @return  Bluetooth device address.
88  */
89 jstring CAEDRNativeGetAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice);
90
91 /**
92  * This function will create the device state list.
93  */
94 void CAEDRNativeCreateDeviceStateList();
95
96 /**
97  * Update connection state of device.
98  * @param[in]  state            connection state.
99  * @param[in]  address          remote address.
100  */
101 void CAEDRUpdateDeviceState(CAConnectedState_t state, const char *address);
102
103 /**
104  * Add device object to the list.
105  * @param[in]  state            connection state object.
106  */
107 void CAEDRNativeAddDeviceStateToList(CAConnectedDeviceInfo_t *state);
108
109 /**
110  * Check whether the device exist in the list or not.
111  * @param[in]  remoteAddress    remote address.
112  * @return true or false.
113  */
114 bool CAEDRNativeIsDeviceInList(const char *remoteAddress);
115
116 /**
117  * Close all socket.
118  * @param[in]   env       JNI interface pointer.
119  */
120 void CAEDRNativeSocketCloseToAll(JNIEnv *env);
121
122 /**
123  * Remove all device objects in the list.
124  */
125 void CAEDRNativeRemoveAllDeviceState();
126
127 /**
128  * Remove target device in the list.
129  * @param[in]   remoteAddress    remote address.
130  */
131 void CAEDRNativeRemoveDevice(const char *remoteAddress);
132
133 /**
134  * Get current device connection state.
135  * @param[in]   remoteAddress    remote address.
136  * @return  STATE_DISCONNECTED or STATE_CONNECTED.
137  */
138 CAConnectedState_t CAEDRIsConnectedDevice(const char *remoteAddress);
139
140 /**
141  * This function will create the device socket list.
142  */
143 void CAEDRNativeCreateDeviceSocketList();
144
145 /**
146  * Add device object to the list.
147  * @param[in]  env              JNI interface pointer.
148  * @param[in]  deviceSocket     device socket object.
149  */
150 void CAEDRNativeAddDeviceSocketToList(JNIEnv *env, jobject deviceSocket);
151
152 /**
153  * Add device object to the list.
154  * @param[in]  env              JNI interface pointer.
155  * @param[in]  remoteAddress    remote address.
156  * @return true or false.
157  */
158 bool CAEDRNativeIsDeviceSocketInList(JNIEnv *env, const char *remoteAddress);
159
160 /**
161  * Add device object to the list.
162  * @param[in]  env              JNI interface pointer.
163  */
164 void CAEDRNativeRemoveAllDeviceSocket(JNIEnv *env);
165
166 /**
167  * Add device object to the list.
168  * @param[in]  env              JNI interface pointer.
169  * @param[in]  deviceSocket     device socket object.
170  */
171 void CAEDRNativeRemoveDeviceSocket(JNIEnv *env, jobject deviceSocket);
172
173 /**
174  * Remove device socket.
175  * @param[in]   env             JNI interface pointer.
176  * @param[in]   address         remote address.
177  */
178 void CAEDRNativeRemoveDeviceSocketBaseAddr(JNIEnv *env, jstring address);
179
180 /**
181  * Get device socket object from the list.
182  * @param[in]  index            index of device list.
183  * @return Device socket object or NULL.
184  */
185 jobject CAEDRNativeGetDeviceSocket(uint32_t index);
186
187 /**
188  * Get device socket address.
189  * @param[in]   env             JNI interface pointer.
190  * @param[in]   remoteAddress   remote address.
191  * @return  Device socket object or NULL.
192  */
193 jobject CAEDRNativeGetDeviceSocketBaseAddr(JNIEnv *env, const char* remoteAddress);
194
195 /**
196  * Get input stream object from the list.
197  * @param[in]   index           index of device list.
198  * @return Input stream object or NULL.
199  */
200 jobject CAEDRNativeGetInputStream(uint32_t index);
201
202 /**
203  * Get length of device socket list.
204  * @return length of list.
205  */
206 uint32_t CAEDRGetSocketListLength();
207
208 /**
209  * Get device information from list.
210  * @param[in]   remoteAddress   remote address.
211  * @return  Device information object or NULL.
212  */
213 CAConnectedDeviceInfo_t *CAEDRGetDeviceInfoFromAddress(const char *remoteAddress);
214
215 #ifdef __cplusplus
216 } /* extern "C" */
217 #endif
218
219 #endif /* CA_EDR_UTILS_H_ */
220