To add connection manager for Tizen BLE Server
authorhyuna0213.jo <hyuna0213.jo@samsung.com>
Mon, 22 Feb 2016 08:42:55 +0000 (17:42 +0900)
committerJon A. Cruz <jonc@osg.samsung.com>
Wed, 24 Feb 2016 23:29:07 +0000 (23:29 +0000)
Implemented connection manager for Tizen 2.4 BLE Server

Change-Id: I4237288aadb16036b848589687ddf50f428f9b74
Signed-off-by: hyuna0213.jo <hyuna0213.jo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5111
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
resource/csdk/connectivity/build/tizen/packaging/com.oic.ca.spec
resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.c
resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.h
resource/csdk/connectivity/util/src/camanager/tizen/caleconnectionmanager.c

index 8c3a25b..1346ff9 100644 (file)
@@ -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/
 
 
index f38284f..5e73070 100644 (file)
@@ -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,
index 4760d4e..c638531 100644 (file)
@@ -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_ */
 
index 5e09342..d2097ed 100644 (file)
  *
  ******************************************************************/
 
+#include <bluetooth.h>
+#include <bluetooth_type.h>
+#include <bluetooth_internal.h>
+
 #include "camanagerleinterface.h"
 #include "cacommon.h"
+#include "caleserver.h"
+#include "cagattservice.h"
 #include "logger.h"
 
 #define TAG "OIC_CA_MANAGER_TZ_LE"
 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();
+        }
+    }
 }