#ifndef CA_LECLIENT_H_
#define CA_LECLIENT_H_
+#include "calestate.h"
#include "cacommon.h"
#include "cathreadpool.h"
#include "uarraylist.h"
{
#endif
-static const uint16_t GATT_ERROR = 133;
-
-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.
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.
/**
* 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();
+CAResult_t CALEClientIsThereScannedDevices(JNIEnv *env, const char* address);
/**
* send data for unicast (implement).
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.
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.
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.
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.
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.
jstring CALEClientGetLEAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice);
/**
- * 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.
+ * 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 CALEClientUpdateDeviceState(const char* address, uint32_t connectedState,
- uint16_t notificationState, uint16_t sendState);
+CAResult_t CALEClientUpdateDeviceStateWithBtDevice(JNIEnv *env,
+ jobject device,
+ uint16_t state_type,
+ uint16_t target_state);
/**
- * 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).
+ * 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 CALEClientAddDeviceStateToList(CALEState_t* state);
+CAResult_t CALEClientSetFlagToState(JNIEnv *env, jstring jni_address,
+ jint state_idx, jboolean flag);
/**
- * check whether the remote address is existed or not.
- * @param[in] address remote address.
- * @return true or false.
+ * 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;
*/
-bool CALEClientIsDeviceInList(const char *remoteAddress);
+jboolean CALEClientGetFlagFromState(JNIEnv *env, jstring jni_address, jint state_idx);
/**
- * remove all device states.
- * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ * get MTU size.
+ * @param[in] address the address of the remote device.
+ * @return mtu size negotiated from remote device.
*/
-CAResult_t CALEClientRemoveAllDeviceState();
+uint16_t CALEClientGetMtuSize(const char* address);
/**
- * remove the device state for a remote device.
- * @param[in] remoteAddress remote address.
+ * 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).
*/
-CAResult_t CALEClientRemoveDeviceState(const char* remoteAddress);
-
-/**
- * get state information for a remote device.
- * @param[in] remoteAddress remote address.
- * @return CALEState_t.
- */
-CALEState_t* CALEClientGetStateInfo(const char* remoteAddress);
-
-/**
- * check whether the remote address is connected or not.
- * @param[in] remoteAddress remote address.
- * @return true or false.
- */
-bool CALEClientIsConnectedDevice(const char* remoteAddress);
-
-/**
- * check whether the remote address set CharacteristicNotification or not.
- * @param[in] remoteAddress remote address.
- * @return true or false.
- */
-bool CALEClientIsSetCharacteristic(const char* remoteAddress);
+CAResult_t CALEClientResetDeviceStateForAll();
/**
* create scan device list.
*/
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