X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fconnectivity%2Fsrc%2Fbt_le_adapter%2Fandroid%2Fcaleclient.h;h=e05a0d4af956caddcc23715726c73ff8dc7ee729;hb=8229635f6d207516ccbbdf23b13be164e0fc1787;hp=613138554cddd8131446f463ae793439254ce66c;hpb=b8bdfc0eec0c7797792203e357cdc73eb84c76fc;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.h b/resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.h index 6131385..e05a0d4 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.h +++ b/resource/csdk/connectivity/src/bt_le_adapter/android/caleclient.h @@ -25,6 +25,7 @@ #ifndef CA_LECLIENT_H_ #define CA_LECLIENT_H_ +#include "calestate.h" #include "cacommon.h" #include "cathreadpool.h" #include "uarraylist.h" @@ -35,24 +36,15 @@ extern "C" { #endif -static const uint16_t STATE_CHARACTER_SET = 2; -static const uint16_t STATE_CHARACTER_UNSET = 1; -static const uint16_t STATE_CHARACTER_NO_CHANGE = 0; - -static const uint16_t STATE_SEND_NONE = 0; -static const uint16_t STATE_SEND_SUCCESS = 1; -static const uint16_t STATE_SEND_FAILED = 2; - -static const jint STATE_CONNECTED = 2; -static const jint STATE_DISCONNECTED = 0; - -typedef struct le_state_info +/** + * BLE Scanning State. + */ +typedef enum { - char address[CA_MACADDR_SIZE]; - jint connectedState; - uint16_t notificationState; - uint16_t sendState; -} CALEState_t; + BLE_SCAN_ENABLE = 0, /**< BLE scan is working */ + BLE_SCAN_DISABLE, /**< BLE scan is not working */ + BLE_SCAN_NONE /**< Initialize State */ +} CALEScanState_t; /** * Callback to be notified on reception of any data from remote devices. @@ -80,10 +72,9 @@ CAResult_t CALEClientCreateJniInterfaceObject(); /** * initialize client for BLE. - * @param[in] handle thread pool handle object. * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). */ -CAResult_t CALEClientInitialize(ca_thread_pool_t handle); +CAResult_t CALEClientInitialize(); /** * terminate client for BLE. @@ -104,6 +95,13 @@ CAResult_t CALEClientDestroyJniInterface(); void CALEClientSendFinish(JNIEnv *env, jobject gatt); /** + * send negotiation message after gatt connection is done. + * @param[in] address remote address. + * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). + */ +CAResult_t CALEClientSendNegotiationMessage(const char* address); + +/** * send data for unicast (interface). * @param[in] address remote address. * @param[in] data data for transmission. @@ -152,6 +150,15 @@ void CALEClientStopMulticastServer(); void CALEClientSetCallback(CAPacketReceiveCallback callback); /** + * waiting to get scanned device from BT Platform. + * if there is no scanned device in the list. + * @param[in] env JNI interface pointer. + * @param[in] address LE address. + * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). + */ +CAResult_t CALEClientIsThereScannedDevices(JNIEnv *env, const char* address); + +/** * send data for unicast (implement). * @param[in] address remote address. * @param[in] data data for transmission. @@ -172,13 +179,6 @@ CAResult_t CALEClientSendMulticastMessageImpl(JNIEnv *env, const uint8_t *data, const uint32_t dataLen); /** - * check whether it is connected or not with remote address. - * @param[in] address remote address. - * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). - */ -CAResult_t CALECheckSendState(const char* address); - -/** * send data to remote device. * if it isn't connected yet. connect LE before try to send data. * @param[in] env JNI interface pointer. @@ -226,6 +226,14 @@ CAResult_t CALEClientStartScan(); CAResult_t CALEClientStartScanImpl(JNIEnv *env, jobject callback); /** + * start to scan whole bluetooth devices for android API level 21 (implement). + * @param[in] env JNI interface pointer. + * @param[in] callback callback to receive device object by scanning. + * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). + */ +CAResult_t CALEClientStartScanImplForV21(JNIEnv *env, jobject callback); + +/** * start to scan target bluetooth devices for service uuid (implement). * @param[in] env JNI interface pointer. * @param[in] uuids target UUID. @@ -236,6 +244,16 @@ CAResult_t CALEClientStartScanWithUUIDImpl(JNIEnv *env, jobjectArray uuids, jobject callback); /** + * start to scan target bluetooth devices for service uuid for android API level 21 (implement). + * @param[in] env JNI interface pointer. + * @param[in] uuids target UUID. + * @param[in] callback callback to receive device object by scanning. + * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). + */ +CAResult_t CALEClientStartScanWithUUIDImplForV21(JNIEnv *env, jobjectArray uuids, + jobject callback); + +/** * get uuid object. * @param[in] env JNI interface pointer. * @param[in] uuid uuid. @@ -250,18 +268,20 @@ jobject CALEClientGetUUIDObject(JNIEnv *env, const char *uuid); CAResult_t CALEClientStopScan(); /** - * set ble scanning flag. - * @param[in] flag scan flag. + * stop scan (implement). + * @param[in] env JNI interface pointer. + * @param[in] callback callback to receive device object by scanning. + * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). */ -void CALEClientSetScanFlag(bool flag); +CAResult_t CALEClientStopScanImpl(JNIEnv *env, jobject callback); /** - * stop scan (implement). + * stop scan for android API level 21(implement). * @param[in] env JNI interface pointer. * @param[in] callback callback to receive device object by scanning. * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). */ -CAResult_t CALEClientStopScanImpl(JNIEnv *env, jobject callback); +CAResult_t CALEClientStopScanImplForV21(JNIEnv *env, jobject callback); /** * connect to gatt server hosted. @@ -270,11 +290,9 @@ CAResult_t CALEClientStopScanImpl(JNIEnv *env, jobject callback); * @param[in] autoconnect whether to directly connect to the remote device(false) or * to automatically connect as soon as the remote device * becomes available. - * @param[in] callback callback for connection state change. - * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). + * @return gatt object */ -CAResult_t CALEClientConnect(JNIEnv *env, jobject bluetoothDevice, jboolean autoconnect, - jobject callback); +jobject CALEClientConnect(JNIEnv *env, jobject bluetoothDevice, jboolean autoconnect); /** * disconnect to gatt server by a target device. @@ -292,6 +310,22 @@ CAResult_t CALEClientDisconnect(JNIEnv *env, jobject bluetoothGatt); CAResult_t CALEClientDisconnectAll(JNIEnv *env); /** + * disconnect to gatt server by selected address. + * @param[in] env JNI interface pointer. + * @param[in] remoteAddress remote address. + * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). + */ +CAResult_t CALEClientDisconnectforAddress(JNIEnv *env, jstring remoteAddress); + +/** + * request MTU size negotiation to server. + * @param[in] env JNI interface pointer. + * @param[in] bluetoothGatt gatt object. + * @param[in] size MTU size. + * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). + */ +CAResult_t CALEClientRequestMTU(JNIEnv *env, jobject bluetoothGatt, jint size); +/** * start discovery server. * @param[in] env JNI interface pointer. * @param[in] bluetoothGatt Gatt profile object. @@ -300,13 +334,21 @@ CAResult_t CALEClientDisconnectAll(JNIEnv *env); CAResult_t CALEClientDiscoverServices(JNIEnv *env, jobject bluetoothGatt); /** + * call CALESetValueAndWriteCharacteristic when connection is successful. + * @param[in] env JNI interface pointer. + * @param[in] gatt Gatt profile object. + * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). + */ +CAResult_t CALEClientWriteCharacteristic(JNIEnv *env, jobject gatt); + +/** * create GattCharacteristic and call CALEClientWriteCharacteristicImpl * for request to write gatt characteristic. * @param[in] env JNI interface pointer. * @param[in] gatt Gatt profile object. * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). */ -CAResult_t CALEClientWriteCharacteristic(JNIEnv *env, jobject gatt); +CAResult_t CALESetValueAndWriteCharacteristic(JNIEnv *env, jobject gatt); /** * request to write gatt characteristic. @@ -457,63 +499,58 @@ CAResult_t CALEClientRemoveGattObj(JNIEnv *env, jobject gatt); CAResult_t CALEClientRemoveGattObjForAddr(JNIEnv *env, jstring addr); /** - * update new state information. - * @param[in] address remote address. - * @param[in] connectedState connection state. - * @param[in] notificationState whether characteristic notification already set or not. - * @param[in] sendState whether sending was success or not. - * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). - */ -CAResult_t CALEClientUpdateDeviceState(const char* address, uint32_t connectedState, - uint16_t notificationState, uint16_t sendState); - -/** - * add new state to state list. - * @param[in] state new state. - * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). - */ -CAResult_t CALEClientAddDeviceStateToList(CALEState_t* state); - -/** - * check whether the remote address is existed or not. - * @param[in] address remote address. - * @return true or false. + * get ble address from Bluetooth device. + * @param[in] env JNI interface pointer. + * @param[in] bluetoothDevice Bluetooth device. + * @return ble address. */ -bool CALEClientIsDeviceInList(const char *remoteAddress); +jstring CALEClientGetLEAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice); /** - * remove all device states. + * update new state information by Bluetooth device object. + * @param[in] env JNI interface pointer. + * @param[in] device Bluetooth device. + * @param[in] state_type state type. + * @param[in] target_state state index to update. * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). */ -CAResult_t CALEClientRemoveAllDeviceState(); +CAResult_t CALEClientUpdateDeviceStateWithBtDevice(JNIEnv *env, + jobject device, + uint16_t state_type, + uint16_t target_state); /** - * remove the device state for a remote device. - * @param[in] remoteAddress remote address. - * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). + * set flag into State List. + * @param[in] env JNI interface pointer. + * @param[in] jni_address remote address. + * @param[in] state_idx state index. + * @param[in] flag auto connect flag. */ -CAResult_t CALEClientRemoveDeviceState(const char* remoteAddress); +CAResult_t CALEClientSetFlagToState(JNIEnv *env, jstring jni_address, + jint state_idx, jboolean flag); /** - * get state information for a remote device. - * @param[in] remoteAddress remote address. - * @return CALEState_t. + * get flag from State List. + * @param[in] env JNI interface pointer. + * @param[in] jni_address remote address. + * @param[in] state_idx state index. + * @return current flag; */ -CALEState_t* CALEClientGetStateInfo(const char* remoteAddress); +jboolean CALEClientGetFlagFromState(JNIEnv *env, jstring jni_address, jint state_idx); /** - * check whether the remote address is connected or not. - * @param[in] remoteAddress remote address. - * @return true or false. + * get MTU size. + * @param[in] address the address of the remote device. + * @return mtu size negotiated from remote device. */ -bool CALEClientIsConnectedDevice(const char* remoteAddress); +uint16_t CALEClientGetMtuSize(const char* address); /** - * check whether the remote address set CharacteristicNotification or not. - * @param[in] remoteAddress remote address. - * @return true or false. + * Reset values of device state for all of devices. + * this method has to be invoked when BT adapter is disabled. + * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). */ -bool CALEClientIsSetCharacteristic(const char* remoteAddress); +CAResult_t CALEClientResetDeviceStateForAll(); /** * create scan device list. @@ -543,6 +580,68 @@ void CALEClientTerminateGattMutexVariables(); */ void CALEClientSetSendFinishFlag(bool flag); +/** + * close the connection of the profile proxy to the Service. + * @param[in] env JNI interface pointer. + * @param[in] gatt gatt profile object. + * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). + */ +CAResult_t CALEClientCloseProfileProxy(JNIEnv *env, jobject gatt); + +/** + * connect to GATT Server hosted by this device. + * @param[in] env JNI interface pointer. + * @param[in] bluetoothDevice bluetooth device object. + * @param[in] autoconnect connect as soon as the device becomes avaiable(true). + * @return gatt profile object + */ +jobject CALEClientGattConnect(JNIEnv *env, jobject bluetoothDevice, jboolean autoconnect); + +/** + * connect to GATT Server hosted by this device directly. + * @param[in] env JNI interface pointer. + * @param[in] bluetoothDevice bluetooth device object. + * @param[in] autoconnect connect as soon as the device becomes avaiable(true). + * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). + */ +CAResult_t CALEClientDirectConnect(JNIEnv *env, jobject bluetoothDevice, jboolean autoconnect); + +/** + * check connection status. + * @param[in] address the address of the remote device. + * @return true or false. + */ +bool CALEClientIsConnected(const char* address); + +/** + * set new interval time and working count. + * @param[in] intervalTime interval time(Seconds). + * @param[in] workingCount working count for selected interval time. + * @param[in] nextScanningStep set next scanning state. + */ +void CALEClientSetScanInterval(int32_t intervalTime, int32_t workingCount, + CALEScanState_t nextScanningStep); + +/** + * restart scanning with new interval time and working count. + * @param[in] intervalTime interval time(Seconds). + * @param[in] workingCount working count for selected interval time. + * @param[in] nextScanningStep set next scanning state. + */ +void CALERestartScanWithInterval(int32_t intervalTime, int32_t workingCount, + CALEScanState_t nextScanningStep); + +/** + * start LE scanning logic with interval time and working count. + * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). + */ +CAResult_t CALEClientStartScanWithInterval(); + +/** + * stop LE scanning logic with interval time and cycle. + */ +void CALEClientStopScanWithInterval(); + #ifdef __cplusplus } /* extern "C" */ #endif