From a924ed12750ac2b04fec5b82af8fca69625f3cce Mon Sep 17 00:00:00 2001 From: "hyuna0213.jo" Date: Mon, 22 Feb 2016 17:42:55 +0900 Subject: [PATCH] To add connection manager for Tizen BLE Server Implemented connection manager for Tizen 2.4 BLE Server Change-Id: I4237288aadb16036b848589687ddf50f428f9b74 Signed-off-by: hyuna0213.jo Reviewed-on: https://gerrit.iotivity.org/gerrit/5111 Tested-by: jenkins-iotivity Reviewed-by: Jon A. Cruz --- .../build/tizen/packaging/com.oic.ca.spec | 2 + .../src/bt_le_adapter/tizen/caleserver.c | 22 +++++- .../src/bt_le_adapter/tizen/caleserver.h | 15 ++++ .../src/camanager/tizen/caleconnectionmanager.c | 87 ++++++++++++++++++++-- 4 files changed, 117 insertions(+), 9 deletions(-) diff --git a/resource/csdk/connectivity/build/tizen/packaging/com.oic.ca.spec b/resource/csdk/connectivity/build/tizen/packaging/com.oic.ca.spec index 8c3a25b..1346ff9 100644 --- a/resource/csdk/connectivity/build/tizen/packaging/com.oic.ca.spec +++ b/resource/csdk/connectivity/build/tizen/packaging/com.oic.ca.spec @@ -49,11 +49,13 @@ fi cp -rf %{ROOTDIR}/con/api/cacommon.h* %{DEST_INC_DIR}/ cp -rf %{ROOTDIR}/con/inc/caadapterinterface.h* %{DEST_INC_DIR}/ cp -rf %{ROOTDIR}/con/common/inc/cathreadpool.h* %{DEST_INC_DIR}/ +cp -rf %{ROOTDIR}/con/util/inc/camanagerleinterface.h* %{DEST_INC_DIR}/ cp -rf %{ROOTDIR}/con/inc/caipadapter.h* %{DEST_INC_DIR}/ cp -rf %{ROOTDIR}/con/inc/caedradapter.h* %{DEST_INC_DIR}/ cp -rf %{ROOTDIR}/con/inc/caleadapter.h* %{DEST_INC_DIR}/ cp -rf %{ROOTDIR}/con/api/cainterface.h* %{DEST_INC_DIR}/ cp -rf %{ROOTDIR}/con/api/casecurityinterface.h* %{DEST_INC_DIR}/ +cp -rf %{ROOTDIR}/con/api/cautilinterface.h* %{DEST_INC_DIR}/ cp -rf %{ROOTDIR}/com.oic.ca.pc %{DEST_LIB_DIR}/pkgconfig/ diff --git a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.c b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.c index f38284f..5e73070 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.c @@ -118,11 +118,16 @@ static ca_thread_pool_t g_leServerThreadPool = NULL; */ static GMainLoop *g_eventLoop = NULL; +static CALEConnectionStateChangedCallback g_connStateCb = NULL; + +void CASetLEConnectionStateChangedCallback(CALEConnectionStateChangedCallback connStateCb) +{ + g_connStateCb = connStateCb; +} + void CALEGattServerConnectionStateChangedCb(int result, bool connected, const char *remoteAddress, void *userData) { - OIC_LOG(DEBUG, TAG, "IN"); - VERIFY_NON_NULL_VOID(remoteAddress, TAG, "remote address"); OIC_LOG_V(DEBUG, TAG, "CABleGattConnectionStateChangedCb result[%d]", result); @@ -130,8 +135,19 @@ void CALEGattServerConnectionStateChangedCb(int result, bool connected, if (connected) { OIC_LOG_V(DEBUG, TAG, "Connected to [%s]", remoteAddress); + if (g_connStateCb) + { + g_connStateCb(CA_ADAPTER_GATT_BTLE, remoteAddress, true); + } + } + else + { + OIC_LOG_V(DEBUG, TAG, "Disconnected from [%s]", remoteAddress); + if (g_connStateCb) + { + g_connStateCb(CA_ADAPTER_GATT_BTLE, remoteAddress, false); + } } - OIC_LOG(DEBUG, TAG, "OUT"); } void CALEServerNotificationSentCB(int result, char *remote_address, bt_gatt_server_h server, diff --git a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.h b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.h index 4760d4e..c638531 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.h +++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.h @@ -166,5 +166,20 @@ void CALEGattRemoteCharacteristicWriteCb(char *remoteAddress, bt_gatt_server_h s void CALEGattServerConnectionStateChangedCb(int result, bool connected, const char *remoteAddress, void *userData); +/** + * Callback function type for network status changes delivery from CA common logic. + * @param[in] adapter Transport type information. + * @param[in] remoteAddress Endpoint object from which the connection status is changed. + * @param[in] connected State of connection. + */ +typedef void (*CALEConnectionStateChangedCallback)(CATransportAdapter_t adapter, + const char *remoteAddress, bool connected); + +/** + * Setting the connection state changed callback. + * @param[in] connStateCb callback for receiving the changed network info. + */ +void CASetLEConnectionStateChangedCallback(CALEConnectionStateChangedCallback connStateCb); + #endif /* TZ_BLE_SERVER_H_ */ diff --git a/resource/csdk/connectivity/util/src/camanager/tizen/caleconnectionmanager.c b/resource/csdk/connectivity/util/src/camanager/tizen/caleconnectionmanager.c index 5e09342..d2097ed 100644 --- a/resource/csdk/connectivity/util/src/camanager/tizen/caleconnectionmanager.c +++ b/resource/csdk/connectivity/util/src/camanager/tizen/caleconnectionmanager.c @@ -18,8 +18,14 @@ * ******************************************************************/ +#include +#include +#include + #include "camanagerleinterface.h" #include "cacommon.h" +#include "caleserver.h" +#include "cagattservice.h" #include "logger.h" #define TAG "OIC_CA_MANAGER_TZ_LE" @@ -27,35 +33,104 @@ static CAAdapterStateChangedCB g_adapterStateCB = NULL; static CAConnectionStateChangedCB g_connStateCB = NULL; +static void CAManagerAdapterMonitorHandler(const CAEndpoint_t *info, CANetworkStatus_t status); +static void CAManagerConnectionMonitorHandler(CATransportAdapter_t adapter, + const char *remoteAddress, bool connected); + void CASetLENetworkMonitorCallbacks(CAAdapterStateChangedCB adapterStateCB, CAConnectionStateChangedCB connStateCB) { OIC_LOG(DEBUG, TAG, "CASetLENetworkMonitorCallbacks"); g_adapterStateCB = adapterStateCB; + CASetNetworkMonitorCallback(CAManagerAdapterMonitorHandler); + g_connStateCB = connStateCB; + CASetLEConnectionStateChangedCallback(CAManagerConnectionMonitorHandler); +} + +void CAStartServerLEAdvertising() +{ + OIC_LOG(DEBUG, TAG, "CAStartServerLEAdvertising"); + + CAResult_t res = CALEStartAdvertise(CA_GATT_SERVICE_UUID); + if (CA_STATUS_OK != res) + { + OIC_LOG_V(ERROR, TAG, "Failed to start le advertising [%d]", res); + return; + } +} + +void CAStopServerLEAdvertising() +{ + OIC_LOG(DEBUG, TAG, "CAStopServerLEAdvertising"); + + CAResult_t res = CALEStopAdvertise(); + if (CA_STATUS_OK != res) + { + OIC_LOG_V(ERROR, TAG, "Failed to stop le advertising [%d]", res); + return; + } } CAResult_t CASetLEClientAutoConnectionDeviceInfo(const char * address) { OIC_LOG(DEBUG, TAG, "CASetLEClientAutoConnectionDeviceInfo"); - return CA_NOT_SUPPORTED; } CAResult_t CAUnsetLEClientAutoConnectionDeviceInfo(const char * address) { OIC_LOG(DEBUG, TAG, "CAUnsetLEClientAutoConnectionDeviceInfo"); - return CA_NOT_SUPPORTED; } -void CAStartServerLEAdvertising() +static void CAManagerAdapterMonitorHandler(const CAEndpoint_t *info, CANetworkStatus_t status) { - OIC_LOG(DEBUG, TAG, "CAStartServerLEAdvertising"); + (void)info; + (void)status; + + if (CA_INTERFACE_DOWN == status) + { + g_adapterStateCB(info->adapter, false); + OIC_LOG(DEBUG, TAG, "Pass the disabled adapter state to upper layer"); + } + else if (CA_INTERFACE_UP == status) + { + g_adapterStateCB(info->adapter, true); + OIC_LOG(DEBUG, TAG, "Pass the enabled adapter state to upper layer"); + } } -void CAStopServerLEAdvertising() +static void CAManagerConnectionMonitorHandler(CATransportAdapter_t adapter, + const char *remoteAddress, bool connected) { - OIC_LOG(DEBUG, TAG, "CAStopServerLEAdvertising"); + if (!remoteAddress) + { + OIC_LOG(ERROR, TAG, "remoteAddress is NULL"); + return; + } + + if (connected) + { + if (g_connStateCB) + { + g_connStateCB(CA_ADAPTER_GATT_BTLE, remoteAddress, true); + OIC_LOG(DEBUG, TAG, "Pass the connected device info to upper layer"); + + // stop le advertising + CAStopServerLEAdvertising(); + } + } + else + { + if (g_connStateCB) + { + g_connStateCB(CA_ADAPTER_GATT_BTLE, remoteAddress, false); + OIC_LOG(DEBUG, TAG, "Pass the disconnected device info to upper layer"); + + // start le advertising to receive new connection request. + CAStartServerLEAdvertising(); + } + } } -- 2.7.4