added network monitoring logic in CAUtil 91/7791/14
authorhyuna0213.jo <hyuna0213.jo@samsung.com>
Fri, 15 Apr 2016 04:31:17 +0000 (13:31 +0900)
committerJon A. Cruz <jon@joncruz.org>
Sun, 1 May 2016 16:55:41 +0000 (16:55 +0000)
I added the function to monitoring the status of the transport adapter
and connection.

- added connection status monitoring callback.
- modified adapter status monitoring callback parameter.
- modified network interface monitoring logic in ipa adapter.

Change-Id: I1d04e018f7cd54ea069b6257a1c2188bbf266232
Signed-off-by: hyuna0213.jo <hyuna0213.jo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/7791
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jon@joncruz.org>
44 files changed:
android/android_api/base/src/main/java/org/iotivity/ca/CaIpInterface.java
resource/csdk/connectivity/api/cainterface.h
resource/csdk/connectivity/inc/caadapterinterface.h
resource/csdk/connectivity/inc/caedradapter.h
resource/csdk/connectivity/inc/caedradapter_singlethread.h
resource/csdk/connectivity/inc/cainterfacecontroller.h
resource/csdk/connectivity/inc/cainterfacecontroller_singlethread.h
resource/csdk/connectivity/inc/caipadapter.h
resource/csdk/connectivity/inc/caipinterface.h
resource/csdk/connectivity/inc/caleadapter.h
resource/csdk/connectivity/inc/canfcadapter.h
resource/csdk/connectivity/inc/caraadapter.h
resource/csdk/connectivity/inc/catcpadapter.h
resource/csdk/connectivity/inc/catcpinterface.h
resource/csdk/connectivity/src/bt_edr_adapter/caedradapter.c
resource/csdk/connectivity/src/bt_edr_adapter/linux/SConscript [deleted file]
resource/csdk/connectivity/src/bt_edr_adapter/linux/caedradapter.c [deleted file]
resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c
resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.c
resource/csdk/connectivity/src/caconnectivitymanager.c
resource/csdk/connectivity/src/cainterfacecontroller.c
resource/csdk/connectivity/src/camessagehandler.c
resource/csdk/connectivity/src/ip_adapter/android/caipnwmonitor.c
resource/csdk/connectivity/src/ip_adapter/caipadapter.c
resource/csdk/connectivity/src/ip_adapter/caipserver.c
resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c
resource/csdk/connectivity/src/ip_adapter/tizen/caipnwmonitor.c
resource/csdk/connectivity/src/nfc_adapter/canfcadapter.c
resource/csdk/connectivity/src/ra_adapter/caraadapter.c
resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c
resource/csdk/connectivity/src/tcp_adapter/catcpserver.c
resource/csdk/connectivity/util/SConscript
resource/csdk/connectivity/util/inc/camanagerleinterface.h
resource/csdk/connectivity/util/src/camanager/android/caleconnectionmanager.c
resource/csdk/connectivity/util/src/camanager/arduino/caleconnectionmanager.c [deleted file]
resource/csdk/connectivity/util/src/camanager/linux/caleconnectionmanager.c [deleted file]
resource/csdk/connectivity/util/src/camanager/tizen/caleconnectionmanager.c [deleted file]
resource/csdk/connectivity/util/src/cautilinterface.c
resource/csdk/stack/include/internal/oickeepalive.h
resource/csdk/stack/src/ocstack.c
resource/csdk/stack/src/oickeepalive.c
service/easy-setup/mediator/richsdk/unittests/SConscript
service/resource-container/examples/BMISensorBundle/src/inputSensors/HeightSensorApp/SConscript
service/things-manager/unittests/SConscript

index 81ab7d5..2314df9 100644 (file)
@@ -73,16 +73,16 @@ public class CaIpInterface {
     private static BroadcastReceiver mReceiver = new BroadcastReceiver() {\r
         @Override\r
         public void onReceive(Context context, Intent intent) {\r
-            if (intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,\r
-                WifiManager.WIFI_STATE_UNKNOWN) == WifiManager.WIFI_STATE_DISABLED) {\r
-                caIpStateDisabled();\r
-            } else if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {\r
+            if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {\r
                 ConnectivityManager manager = (ConnectivityManager)\r
                         mContext.getSystemService(Context.CONNECTIVITY_SERVICE);\r
-                NetworkInfo nwInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);\r
+                NetworkInfo wifiInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);\r
+                NetworkInfo mobileInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);\r
 \r
-                if(nwInfo.isConnected()) {\r
+                if (mobileInfo != null && mobileInfo.isConnected() || wifiInfo.isConnected()) {\r
                     caIpStateEnabled();\r
+                } else {\r
+                    caIpStateDisabled();\r
                 }\r
             }\r
 \r
index a253846..5d50d8d 100644 (file)
@@ -69,22 +69,14 @@ typedef struct
  * Callback function to pass the connection information from CA to RI.
  * @param[out]   object           remote device information.
  */
-typedef void (*CAKeepAliveConnectedCallback)(const CAEndpoint_t *object);
+typedef void (*CAKeepAliveConnectionCallback)(const CAEndpoint_t *object, bool isConnected);
 
 /**
- * Callback function to pass the disconnection information from CA to RI.
- * @param[out]   object           remote device information.
- */
-typedef void (*CAKeepAliveDisconnectedCallback)(const CAEndpoint_t *object);
-
-/**
- * Register connected callback and disconnected callback to process KeepAlive.
+ * Register connection status changes callback to process KeepAlive.
  * connection informations are delivered these callbacks.
- * @param[in]   ConnHandler     Connected callback.
- * @param[in]   DisconnHandler  Disconnected Callback.
+ * @param[in]   ConnHandler     Connection status changes callback.
  */
-void CARegisterKeepAliveHandler(CAKeepAliveConnectedCallback ConnHandler,
-                                CAKeepAliveDisconnectedCallback DisconnHandler);
+void CARegisterKeepAliveHandler(CAKeepAliveConnectionCallback ConnHandler);
 #endif
 /**
  * Initialize the connectivity abstraction module.
index 8e029ad..144f383 100644 (file)
@@ -188,9 +188,13 @@ typedef void (*CANetworkPacketReceivedCallback)(const CASecureEndpoint_t *sep,
 
 /**
  * This will be used to notify network changes to the connectivity common logic layer.
- * @see SendUnicastData(), SendMulticastData()
  */
-typedef void (*CANetworkChangeCallback)(const CAEndpoint_t *info, CANetworkStatus_t status);
+typedef void (*CAAdapterChangeCallback)(CATransportAdapter_t adapter, CANetworkStatus_t status);
+
+/**
+ * This will be used to notify connection changes to the connectivity common logic layer.
+ */
+typedef void (*CAConnectionChangeCallback)(const CAEndpoint_t *info, bool isConnected);
 
 /**
  * This will be used to notify error result to the connectivity common logic layer.
index 88794e3..bec17b7 100644 (file)
@@ -44,7 +44,9 @@ extern "C"
  *                                 Abstraction Layer.
  * @param[in]   reqRespCallback    Callback to notify request and response messages from
  *                                 server(s) started at Connectivity Abstraction Layer.
- * @param[in]   netCallback        Callback to notify the network additions to Connectivity
+ * @param[in]   netCallback        Callback to notify the adapter changes to Connectivity
+ *                                 Abstraction Layer.
+ * @param[in]   connCallback       Callback to notify the connection changes to Connectivity
  *                                 Abstraction Layer.
  * @param[in]   errorCallback      errorCallback to notify error to connectivity common logic
  *                                 layer from adapter.
@@ -52,8 +54,9 @@ extern "C"
  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
 CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
-                           CANetworkPacketReceivedCallback reqRespCallback,
-                           CANetworkChangeCallback netCallback,
+                           CANetworkPacketReceivedCallback packetReceivedCallback,
+                           CAAdapterChangeCallback netCallback,
+                           CAConnectionChangeCallback connCallback,
                            CAErrorHandleCallback errorCallback, ca_thread_pool_t handle);
 
 /**
index f2422ae..f1cba26 100644 (file)
@@ -55,7 +55,7 @@ extern "C"
  */
 CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
                            CANetworkPacketReceivedCallback reqRespCallback,
-                           CANetworkChangeCallback netCallback);
+                           CAAdapterChangeCallback netCallback);
 
 /**
  * @brief  Starting EDR connectivity adapters. As its peer to peer it doesnot require to start
index 477674f..edf060f 100644 (file)
@@ -67,11 +67,12 @@ void CASetPacketReceivedCallback(CANetworkPacketReceivedCallback callback);
 void CASetErrorHandleCallback(CAErrorHandleCallback errorCallback);
 
 /**
- * Set the network status changed callback for message handler.
- * @param[in]   callback         message handler network status callback
- *                               to receive network changes.
+ * Set the network status changed callback for CAUtil.
+ * @param[in]   adapterCB       CAUtil callback to receive adapter status changes.
+ * @param[in]   connCB          CAUtil callback to receive connection status changes.
  */
-void CASetNetworkChangeCallback(CANetworkChangeCallback callback);
+void CASetNetworkMonitorCallbacks(CAAdapterChangeCallback adapterCB,
+                                  CAConnectionChangeCallback connCB);
 
 /**
  * Starting different connectivity adapters based on the network selection.
index b8234f9..6ab085e 100644 (file)
@@ -51,12 +51,12 @@ void CAInitializeAdapters();
 void CASetPacketReceivedCallback(CANetworkPacketReceivedCallback callback);
 
 /**
- * @brief   Set the network status changed callback for message handler
+ * @brief   Set the adapter status changed callback for message handler
  * @param   callback        [IN]    message handler network status callback to receive network
  *                                  changes.
  * @return   none
  */
-void CASetNetworkChangeCallback(CANetworkChangeCallback callback);
+void CASetNetworkChangeCallback(CAAdapterChangeCallback callback);
 
 /**
  * @brief   Set the error handler callback for message handler
index e7fa8c0..d4ec30a 100644 (file)
@@ -50,7 +50,7 @@ extern "C"
  */
 CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
                           CANetworkPacketReceivedCallback networkPacketCallback,
-                          CANetworkChangeCallback netCallback,
+                          CAAdapterChangeCallback netCallback,
                           CAErrorHandleCallback errorCallback, ca_thread_pool_t handle);
 
 /**
index 2caf5b1..1dc028f 100644 (file)
@@ -187,6 +187,30 @@ typedef struct
     uint32_t ipv4addr;        /**< used for IPv4 only. */
 } CAInterface_t;
 
+
+/**
+ * Callback to be notified when IP adapter connection state changes.
+ *
+ * @param[in]  adapter      Transport adapter.
+ * @param[in]  status       Connection status either ::CA_INTERFACE_UP or ::CA_INTERFACE_DOWN.
+ * @see CAIPSetConnectionStateChangeCallback() for registration.
+ */
+typedef void (*CAIPConnectionStateChangeCallback)(CATransportAdapter_t adapter, CANetworkStatus_t status);
+
+/**
+ * Set callback for receiving local IP adapter connection status.
+ *
+ * @param[in]  adapter      Callback to be notified when IP adapter connection state changes.
+ */
+void CAIPSetConnectionStateChangeCallback(CAIPConnectionStateChangeCallback callback);
+
+/**
+ * Set callback for receiving local IP adapter connection status.
+ *
+ * @param[in]  callback     Callback to be notified when IP adapter connection state changes.
+ */
+void CAIPSetNetworkMonitorCallback(CAIPConnectionStateChangeCallback callback);
+
 /**
  * Get a list of CAInterface_t items.
  *
@@ -195,14 +219,14 @@ typedef struct
 u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex);
 
 /**
- * @brief   Find a new network interface.
+ * Find a new network interface.
  *
  * @return  Description of interface (or NULL if no change)
  */
 CAInterface_t *CAFindInterfaceChange();
 
 /**
- * @brief   Let the network monitor update the polling interval.
+ * Let the network monitor update the polling interval.
  * @param   [in] current polling interval
  *
  * @return  desired polling interval
@@ -210,7 +234,7 @@ CAInterface_t *CAFindInterfaceChange();
 int CAGetPollingInterval(int interval);
 
 /**
- * @brief   Tell the IP server an interface has been added.
+ * Tell the IP server an interface has been added.
  */
 void CAWakeUpForChange();
 
@@ -229,7 +253,7 @@ CAResult_t CAIPStartNetworkMonitor();
 CAResult_t CAIPStopNetworkMonitor();
 
 /**
- * @brief  Set callback for error handling.
+ * Set callback for error handling.
  *
  * @param[in]  ipErrorCallback  callback to notify error to the ipadapter.
  */
index bf85d27..11a0b79 100644 (file)
@@ -40,7 +40,9 @@ extern "C"
  * @param[in]  reqRespCallback  Callback to notify request and response
  *                              messages from server(s) started at
  *                              Connectivity Abstraction Layer.
- * @param[in]  netCallback      Callback to notify the network additions
+ * @param[in]  netCallback      Callback to notify the adapter changes
+ *                              to Connectivity Abstraction Layer.
+ * @param[in]  connCallback     Callback to notify the connection changes
  *                              to Connectivity Abstraction Layer.
  * @param[in]  errorCallback    errorCallback to notify error to
  *                              connectivity common logic layer from adapter.
@@ -50,7 +52,8 @@ extern "C"
  */
 CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
                           CANetworkPacketReceivedCallback reqRespCallback,
-                          CANetworkChangeCallback netCallback,
+                          CAAdapterChangeCallback netCallback,
+                          CAConnectionChangeCallback connCallback,
                           CAErrorHandleCallback errorCallback,
                           ca_thread_pool_t handle);
 
index 3e8fb48..3083ab3 100644 (file)
@@ -49,7 +49,7 @@ extern "C"
  */\r
 CAResult_t CAInitializeNFC(CARegisterConnectivityCallback registerCallback,\r
                           CANetworkPacketReceivedCallback networkPacketCallback,\r
-                          CANetworkChangeCallback netCallback,\r
+                          CAAdapterChangeCallback netCallback,\r
                           CAErrorHandleCallback errorCallback, ca_thread_pool_t handle);\r
 \r
 /**\r
index 7dd0940..ed730f0 100644 (file)
@@ -51,7 +51,7 @@ extern "C"
  */
 CAResult_t CAInitializeRA(CARegisterConnectivityCallback registerCallback,
                           CANetworkPacketReceivedCallback networkPacketCallback,
-                          CANetworkChangeCallback netCallback,
+                          CAAdapterChangeCallback netCallback,
                           ca_thread_pool_t handle);
 
 
index 2528df1..e3da369 100644 (file)
@@ -54,7 +54,9 @@ typedef struct
  * @param[in] networkPacketCallback Callback to notify request and
  *                                  response messages from server(s)
  *                                  started at Connectivity Abstraction Layer.
- * @param[in] netCallback           Callback to notify the network additions
+ * @param[in] netCallback           Callback to notify the adapter changes
+ *                                  to Connectivity Abstraction Layer.
+ * @param[in] connCallback          Callback to notify the connection changes
  *                                  to Connectivity Abstraction Layer.
  * @param[in] errorCallback         Callback to notify the network errors to
  *                                  Connectivity Abstraction Layer.
@@ -63,7 +65,8 @@ typedef struct
  */
 CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback,
                            CANetworkPacketReceivedCallback networkPacketCallback,
-                           CANetworkChangeCallback netCallback,
+                           CAAdapterChangeCallback netCallback,
+                           CAConnectionChangeCallback connCallback,
                            CAErrorHandleCallback errorCallback, ca_thread_pool_t handle);
 
 /**
@@ -152,13 +155,11 @@ CAResult_t CAStopTCP();
 void CATerminateTCP();
 
 /**
- * Set connected callback and disconnected callback to process KeepAlive.
+ * Set connection status changes callback to process KeepAlive.
  * connection informations are delivered these callbacks.
- * @param[in]   ConnHandler     Connected callback.
- * @param[in]   DisconnHandler  Disconnected Callback.
+ * @param[in]   ConnHandler     Connection status changes callback.
  */
-void CATCPSetKeepAliveCallbacks(CAKeepAliveConnectedCallback ConnHandler,
-                                CAKeepAliveDisconnectedCallback DisconnHandler);
+void CATCPSetKeepAliveCallbacks(CAKeepAliveConnectionCallback ConnHandler);
 
 #ifdef __cplusplus
 } /* extern "C" */
index 38efb00..10dd685 100644 (file)
@@ -70,7 +70,7 @@ typedef void (*CATCPErrorHandleCallback)(const CAEndpoint_t *endpoint, const voi
   * @param[in]  isConnected    Whether keepalive message needs to be sent.
   * @see  Callback must be registered using CATCPSetKeepAliveCallback().
  */
-typedef void (*CATCPKeepAliveHandleCallback)(const char *addr, uint16_t port, bool isConnected);
+typedef void (*CATCPConnectionHandleCallback)(const char *addr, uint16_t port, bool isConnected);
 
 /**
  * set error callback to notify error in TCP adapter.
@@ -86,7 +86,7 @@ void CATCPSetErrorHandler(CATCPErrorHandleCallback errorHandleCallback);
  * @param[in]  keepaliveHandler Callback function to notify the connection information.
  * in the TCP adapter.
  */
-void CATCPSetKeepAliveCallback(CATCPKeepAliveHandleCallback keepaliveHandler);
+void CATCPSetKeepAliveCallback(CAKeepAliveConnectionCallback keepaliveHandler);
 
 /**
  * Start TCP server.
index 9a1c018..fb036ed 100644 (file)
 #include "pdu.h"
 
 /**
- * @var EDR_ADAPTER_TAG
- * @brief Logging tag for module name.
+ * Logging tag for module name.
  */
 #define EDR_ADAPTER_TAG "OIC_CA_EDR_ADAP"
 
 /**
- * @var g_edrThreadPool
- * @brief Reference to threadpool.
+ * Reference to threadpool.
  */
 static ca_thread_pool_t g_edrThreadPool = NULL;
 
 /**
- * @var g_sendQueueHandle
- * @brief Queue handle for Send Data
+ * Queue handle for Send Data
  */
 static CAQueueingThread_t *g_sendQueueHandle = NULL;
 
 /**
- * @var g_recvQueueHandle
- * @brief Queue handle for Receive Data
+ * Queue handle for Receive Data
  */
 static CAQueueingThread_t *g_recvQueueHandle = NULL;
 
 /**
- * @var g_adapterState
- * @brief Storing Adapter state information
+ * Storing Adapter state information
  */
 static bool g_adapterState = true;
 
 /**
- * @var g_networkPacketReceivedCallback
- * @brief Maintains the callback to be notified on receival of network packets from other
- *          Bluetooth devices.
+ * Maintains the callback to be notified on receival of network packets from other
+ * Bluetooth devices.
  */
 static CANetworkPacketReceivedCallback g_networkPacketReceivedCallback = NULL;
 
 /**
- * @var g_networkChangeCallback
- * @brief Maintains the callback to be notified on local bluetooth adapter status change.
+ * Maintains the callback to be notified on local bluetooth adapter status change.
  */
-static CANetworkChangeCallback g_networkChangeCallback = NULL;
+static CAAdapterChangeCallback g_adapterChangeCallback = NULL;
 
 /**
- * @var g_errorCallback
- * @brief error Callback to CA adapter
+ * error Callback to CA adapter
  */
 static CAErrorHandleCallback g_errorCallback = NULL;
 
 /**
- * @var g_localConnectivity
- * @brief Information of local Bluetooth adapter.
+ * Information of local Bluetooth adapter.
  */
 static CAEndpoint_t *g_localConnectivity = NULL;
 
 /**
- * @var g_serverState
- * @brief Storing Rfcommserver state information
+ * Storing Rfcommserver state information
  */
 static bool g_serverState = false;
 
@@ -139,21 +129,21 @@ static void CAEDRErrorHandler(const char *remoteAddress, const uint8_t *data,
 
 CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
                            CANetworkPacketReceivedCallback packetReceivedCallback,
-                           CANetworkChangeCallback networkStateChangeCallback,
+                           CAAdapterChangeCallback netCallback,
+                           CAConnectionChangeCallback connCallback,
                            CAErrorHandleCallback errorCallback, ca_thread_pool_t handle)
 {
     // Input validation
     VERIFY_NON_NULL(registerCallback, EDR_ADAPTER_TAG, "register callback is NULL");
     VERIFY_NON_NULL(packetReceivedCallback, EDR_ADAPTER_TAG, "data receive callback is NULL");
-    VERIFY_NON_NULL(networkStateChangeCallback, EDR_ADAPTER_TAG,
-                    "network state change callback is NULL");
+    VERIFY_NON_NULL(netCallback, EDR_ADAPTER_TAG, "adapter state change callback is NULL");
+    VERIFY_NON_NULL(connCallback, EDR_ADAPTER_TAG, "connection state change callback is NULL");
     VERIFY_NON_NULL(handle, EDR_ADAPTER_TAG, "Thread pool handle is NULL");
 
     // Register the callbacks
-
     g_edrThreadPool = handle;
     g_networkPacketReceivedCallback = packetReceivedCallback;
-    g_networkChangeCallback = networkStateChangeCallback;
+    g_adapterChangeCallback = netCallback;
     g_errorCallback = errorCallback;
 
     // Initialize EDR Network Monitor
@@ -385,7 +375,7 @@ void CATerminateEDR()
     CAAdapterTerminateQueues();
 
     g_networkPacketReceivedCallback = NULL;
-    g_networkChangeCallback = NULL;
+    g_adapterChangeCallback = NULL;
 
     // Terminate thread pool
     g_edrThreadPool = NULL;
@@ -778,7 +768,7 @@ void CAEDRNotifyNetworkStatus(CANetworkStatus_t status)
     }
 
     // Notify to upper layer
-    if (g_networkChangeCallback && g_localConnectivity && g_edrThreadPool)
+    if (g_adapterChangeCallback && g_localConnectivity && g_edrThreadPool)
     {
         // Add notification task to thread pool
         CAEDRNetworkEvent *event = CAEDRCreateNetworkEvent(g_localConnectivity, status);
@@ -805,9 +795,9 @@ void CAEDROnNetworkStatusChanged(void *context)
     CAEDRNetworkEvent *networkEvent = (CAEDRNetworkEvent *) context;
 
     // Notify to upper layer
-    if (g_networkChangeCallback)
+    if (g_adapterChangeCallback)
     {
-        g_networkChangeCallback(networkEvent->info, networkEvent->status);
+        g_adapterChangeCallback(networkEvent->info->adapter, networkEvent->status);
     }
 
     // Free the created Network event
diff --git a/resource/csdk/connectivity/src/bt_edr_adapter/linux/SConscript b/resource/csdk/connectivity/src/bt_edr_adapter/linux/SConscript
deleted file mode 100644 (file)
index 0e09967..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-##########################################
-#       Build BT EDR adapter for Linux
-##########################################
-
-Import('env')
-
-src_files = [ 'caedradapter.c']
-
-Return('src_files')
diff --git a/resource/csdk/connectivity/src/bt_edr_adapter/linux/caedradapter.c b/resource/csdk/connectivity/src/bt_edr_adapter/linux/caedradapter.c
deleted file mode 100644 (file)
index 4863861..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-/******************************************************************
- *
- * Copyright 2014 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "caedradapter.h"
-#include "logger.h"
-
-#define TAG PCF("OIC_CA")
-
-static CANetworkPacketReceivedCallback g_edrReceivedCallback = NULL;
-static ca_thread_pool_t g_threadPoolHandle = NULL;
-
-CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
-                           CANetworkPacketReceivedCallback reqRespCallback,
-                           CANetworkChangeCallback networkStateChangeCallback,
-                           CAErrorHandleCallback errorCallback, ca_thread_pool_t handle)
-{
-    (void)networkStateChangeCallback;
-    (void)errorCallback;
-    OIC_LOG(DEBUG, TAG, "CAInitializeEDR");
-
-    g_edrReceivedCallback = reqRespCallback;
-    g_threadPoolHandle = handle;
-
-    // register handlers
-    CAConnectivityHandler_t handler = {
-        .startAdapter = CAStartEDR,
-        .startListenServer = CAStartEDRListeningServer,
-        .stopListenServer = CAStopEDRListeningServer,
-        .startDiscoveryServer = CAStartEDRDiscoveryServer,
-        .sendData = CASendEDRUnicastData,
-        .sendDataToAll = CASendEDRMulticastData,
-        .GetnetInfo = CAGetEDRInterfaceInformation,
-        .readData = CAReadEDRData,
-        .stopAdapter = CAStopEDR,
-        .terminate = CATerminateEDR,
-        .cType = CA_ADAPTER_RFCOMM_BTEDR
-    };
-
-    registerCallback(handler);
-
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAStartEDR()
-{
-    OIC_LOG(DEBUG, TAG, "CAStartEDR");
-
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAStartEDRListeningServer()
-{
-    OIC_LOG(DEBUG, TAG, "CAStartEDRListeningServer");
-
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAStopEDRListeningServer()
-{
-    OIC_LOG(DEBUG, TAG, "CAStopEDRListeningServer");
-
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAStartEDRDiscoveryServer()
-{
-    OIC_LOG(DEBUG, TAG, "CAStartEDRDiscoveryServer");
-
-    return CA_STATUS_OK;
-}
-
-int32_t CASendEDRUnicastData(const CAEndpoint_t *endpoint, const void *data,
-    uint32_t dataLen)
-{
-    (void)endpoint;
-    (void)data;
-    (void)dataLen;
-    OIC_LOG(DEBUG, TAG, "CASendEDRUnicastData");
-
-    return -1;
-}
-
-int32_t CASendEDRMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen)
-{
-    (void)endpoint;
-    (void)data;
-    (void)dataLen;
-    OIC_LOG(DEBUG, TAG, "CASendEDRMulticastData");
-
-    return -1;
-}
-
-CAResult_t CAGetEDRInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
-{
-    (void)info;
-    (void)size;
-    OIC_LOG(DEBUG, TAG, "CAGetEDRInterfaceInformation");
-
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAReadEDRData()
-{
-    OIC_LOG(DEBUG, TAG, "Read EDR Data");
-
-    return CA_STATUS_OK;
-}
-
-CAResult_t CAStopEDR()
-{
-    OIC_LOG(DEBUG, TAG, "CAStopEDR");
-
-    return CA_STATUS_OK;
-}
-
-void CATerminateEDR()
-{
-    OIC_LOG(DEBUG, TAG, "CATerminateEDR");
-}
-
index f181dd9..ca42cb4 100644 (file)
@@ -69,7 +69,12 @@ typedef enum
 /**
  * Callback to provide the status of the network change to CA layer.
  */
-static CANetworkChangeCallback g_networkCallback = NULL;
+static CAAdapterChangeCallback g_networkCallback = NULL;
+
+/**
+ * Callback to provide the status of the connection change to CA layer.
+ */
+static CAConnectionChangeCallback g_connectionCallback = NULL;
 
 /**
  * bleAddress of the local adapter. Value will be initialized to zero,
@@ -145,8 +150,10 @@ static CAErrorHandleCallback g_errorHandler = NULL;
 /**
  * Register network change notification callback.
  *
- * @param[in]  netCallback CANetworkChangeCallback callback which will
- *                         be set for the change in network.
+ * @param[in]  netCallback  CAAdapterChangeCallback callback which will
+ *                          be set for the change in adapter.
+ * @param[in]  connCallback CAConnectionChangeCallback callback which will
+ *                          be set for the change in connection.
  *
  * @return  0 on success otherwise a positive error value.
  * @retval  ::CA_STATUS_OK  Successful.
@@ -154,7 +161,8 @@ static CAErrorHandleCallback g_errorHandler = NULL;
  * @retval  ::CA_STATUS_FAILED Operation failed.
  *
  */
-static CAResult_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCallback);
+static CAResult_t CALERegisterNetworkNotifications(CAAdapterChangeCallback netCallback,
+                                                   CAConnectionChangeCallback connCallback);
 
 /**
  * Set the thread pool handle which is required for spawning new
@@ -1717,7 +1725,8 @@ static CAResult_t CALEAdapterGattClientStop()
 
 CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
                           CANetworkPacketReceivedCallback reqRespCallback,
-                          CANetworkChangeCallback netCallback,
+                          CAAdapterChangeCallback netCallback,
+                          CAConnectionChangeCallback connCallback,
                           CAErrorHandleCallback errorCallback,
                           ca_thread_pool_t handle)
 {
@@ -1727,6 +1736,7 @@ CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
     VERIFY_NON_NULL(registerCallback, CALEADAPTER_TAG, "RegisterConnectivity callback is null");
     VERIFY_NON_NULL(reqRespCallback, CALEADAPTER_TAG, "PacketReceived Callback is null");
     VERIFY_NON_NULL(netCallback, CALEADAPTER_TAG, "NetworkChange Callback is null");
+    VERIFY_NON_NULL(connCallback, CALEADAPTER_TAG, "ConnectionChange Callback is null");
 
     CAResult_t result = CA_STATUS_OK;
     result = CAInitLEAdapterMutex();
@@ -1768,7 +1778,7 @@ CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
 
     CASetBLEClientErrorHandleCallback(CALEErrorHandler);
     CASetBLEServerErrorHandleCallback(CALEErrorHandler);
-    CALERegisterNetworkNotifications(netCallback);
+    CALERegisterNetworkNotifications(netCallback, connCallback);
 
     g_errorHandler = errorCallback;
 
@@ -1837,7 +1847,7 @@ static void CATerminateLE()
 
     CASetLEReqRespServerCallback(NULL);
     CASetLEReqRespClientCallback(NULL);
-    CALERegisterNetworkNotifications(NULL);
+    CALERegisterNetworkNotifications(NULL, NULL);
     CASetLEReqRespAdapterCallback(NULL);
     CATerminateLENetworkMonitor();
 
@@ -2153,12 +2163,14 @@ static CAResult_t CAGetLEInterfaceInformation(CAEndpoint_t **info, uint32_t *siz
     return CA_STATUS_OK;
 }
 
-static CAResult_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCallback)
+static CAResult_t CALERegisterNetworkNotifications(CAAdapterChangeCallback netCallback,
+                                                   CAConnectionChangeCallback connCallback)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
 
     ca_mutex_lock(g_bleNetworkCbMutex);
     g_networkCallback = netCallback;
+    g_connectionCallback = connCallback;
     ca_mutex_unlock(g_bleNetworkCbMutex);
     CAResult_t res = CA_STATUS_OK;
     if (netCallback)
@@ -2168,12 +2180,6 @@ static CAResult_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCa
         {
             OIC_LOG(ERROR, CALEADAPTER_TAG, "CASetLEAdapterStateChangedCb failed!");
         }
-
-        res = CASetLENWConnectionStateChangedCb(CALEConnectionStateChangedCb);
-        if (CA_STATUS_OK != res)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "CALEConnectionStateChangedCb failed!");
-        }
     }
     else
     {
@@ -2184,6 +2190,15 @@ static CAResult_t CALERegisterNetworkNotifications(CANetworkChangeCallback netCa
         }
     }
 
+    if (g_connectionCallback)
+    {
+        res = CASetLENWConnectionStateChangedCb(CALEConnectionStateChangedCb);
+        if (CA_STATUS_OK != res)
+        {
+            OIC_LOG(ERROR, CALEADAPTER_TAG, "CASetLENWConnectionStateChangedCb failed!");
+        }
+    }
+
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
     return res;
 }
@@ -2246,6 +2261,16 @@ static void CALEConnectionStateChangedCb(CATransportAdapter_t adapter, const cha
 #endif
     }
 
+    CAEndpoint_t localEndpoint = { .adapter = CA_ADAPTER_GATT_BTLE };
+    OICStrcpy(localEndpoint.addr, sizeof(localEndpoint.addr), address);
+
+    ca_mutex_lock(g_bleNetworkCbMutex);
+    if (g_connectionCallback)
+    {
+        g_connectionCallback(&localEndpoint, isConnected);
+    }
+    ca_mutex_unlock(g_bleNetworkCbMutex);
+
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
 }
 
@@ -2253,15 +2278,6 @@ static void CALEDeviceStateChangedCb(CAAdapterState_t adapter_state)
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN - CALEDeviceStateChangedCb");
 
-    VERIFY_NON_NULL_VOID(g_localBLEAddress, CALEADAPTER_TAG, "g_localBLEAddress is null");
-    CAEndpoint_t localEndpoint = { .adapter = CA_ADAPTER_GATT_BTLE };
-
-    ca_mutex_lock(g_bleLocalAddressMutex);
-    OICStrcpy(localEndpoint.addr,
-              sizeof(localEndpoint.addr),
-              g_localBLEAddress);
-    ca_mutex_unlock(g_bleLocalAddressMutex);
-
     if (CA_ADAPTER_ENABLED == adapter_state)
     {
         ca_mutex_lock(g_bleIsServerMutex);
@@ -2306,7 +2322,7 @@ static void CALEDeviceStateChangedCb(CAAdapterState_t adapter_state)
     ca_mutex_lock(g_bleNetworkCbMutex);
     if (NULL != g_networkCallback)
     {
-        g_networkCallback(&localEndpoint, adapter_state);
+        g_networkCallback(CA_ADAPTER_GATT_BTLE, adapter_state);
     }
     else
     {
index f21b637..0b234d7 100644 (file)
@@ -114,13 +114,6 @@ 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 CALEGattServerConnectionStateChanged(bool connected, const char *remoteAddress)
 {
     VERIFY_NON_NULL_VOID(remoteAddress, TAG, "remote address");
@@ -128,18 +121,10 @@ void CALEGattServerConnectionStateChanged(bool connected, const char *remoteAddr
     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);
-        }
     }
 }
 
index 691e2bc..82919b7 100644 (file)
@@ -553,9 +553,8 @@ CAResult_t CACloseDtlsSession(const CAEndpoint_t *endpoint)
 #endif /* __WITH_DTLS__ */
 
 #ifdef TCP_ADAPTER
-void CARegisterKeepAliveHandler(CAKeepAliveConnectedCallback ConnHandler,
-                                CAKeepAliveDisconnectedCallback DisconnHandler)
+void CARegisterKeepAliveHandler(CAKeepAliveConnectionCallback ConnHandler)
 {
-    CATCPSetKeepAliveCallbacks(ConnHandler, DisconnHandler);
+    CATCPSetKeepAliveCallbacks(ConnHandler);
 }
 #endif
index 562a7b5..64b3f68 100644 (file)
 #define CA_MEMORY_ALLOC_CHECK(arg) {if (arg == NULL) \
     {OIC_LOG(ERROR, TAG, "memory error");goto memory_error_exit;} }
 
-
-
 static CAConnectivityHandler_t *g_adapterHandler = NULL;
 
 static uint32_t g_numberOfAdapters = 0;
 
 static CANetworkPacketReceivedCallback g_networkPacketReceivedCallback = NULL;
 
-static CANetworkChangeCallback g_networkChangeCallback = NULL;
+static CAAdapterChangeCallback g_adapterChangeCallback = NULL;
+
+static CAConnectionChangeCallback g_connChangeCallback = NULL;
 
 static CAErrorHandleCallback g_errorHandleCallback = NULL;
 
@@ -124,13 +124,24 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep,
     }
 }
 
-static void CANetworkChangedCallback(const CAEndpoint_t *info, CANetworkStatus_t status)
+static void CAAdapterChangedCallback(CATransportAdapter_t adapter, CANetworkStatus_t status)
+{
+    // Call the callback.
+    if (g_adapterChangeCallback != NULL)
+    {
+        g_adapterChangeCallback(adapter, status);
+    }
+    OIC_LOG_V(DEBUG, TAG, "[%d]adapter status is changed to [%d]", adapter, status);
+}
+
+static void CAConnectionChangedCallback(const CAEndpoint_t *info, bool isConnected)
 {
     // Call the callback.
-    if (g_networkChangeCallback != NULL)
+    if (g_connChangeCallback != NULL)
     {
-        g_networkChangeCallback(info, status);
+        g_connChangeCallback(info, isConnected);
     }
+    OIC_LOG_V(DEBUG, TAG, "[%s] connection status is changed to [%d]", info->addr, isConnected);
 }
 
 static void CAAdapterErrorHandleCallback(const CAEndpoint_t *endpoint,
@@ -152,32 +163,32 @@ void CAInitializeAdapters(ca_thread_pool_t handle)
 
     // Initialize adapters and register callback.
 #ifdef IP_ADAPTER
-    CAInitializeIP(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback,
+    CAInitializeIP(CARegisterCallback, CAReceivedPacketCallback, CAAdapterChangedCallback,
                    CAAdapterErrorHandleCallback, handle);
 #endif /* IP_ADAPTER */
 
 #ifdef EDR_ADAPTER
-    CAInitializeEDR(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback,
-                    CAAdapterErrorHandleCallback, handle);
+    CAInitializeEDR(CARegisterCallback, CAReceivedPacketCallback, CAAdapterChangedCallback,
+                    CAConnectionChangedCallback, CAAdapterErrorHandleCallback, handle);
 #endif /* EDR_ADAPTER */
 
 #ifdef LE_ADAPTER
-    CAInitializeLE(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback,
-                   CAAdapterErrorHandleCallback, handle);
+    CAInitializeLE(CARegisterCallback, CAReceivedPacketCallback, CAAdapterChangedCallback,
+                   CAConnectionChangedCallback, CAAdapterErrorHandleCallback, handle);
 #endif /* LE_ADAPTER */
 
 #ifdef RA_ADAPTER
-    CAInitializeRA(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback,
+    CAInitializeRA(CARegisterCallback, CAReceivedPacketCallback, CAAdapterChangedCallback,
                    handle);
 #endif /* RA_ADAPTER */
 
 #ifdef TCP_ADAPTER
-    CAInitializeTCP(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback,
-                    CAAdapterErrorHandleCallback, handle);
+    CAInitializeTCP(CARegisterCallback, CAReceivedPacketCallback, CAAdapterChangedCallback,
+                    CAConnectionChangedCallback, CAAdapterErrorHandleCallback, handle);
 #endif /* TCP_ADAPTER */
 
 #ifdef NFC_ADAPTER
-    CAInitializeNFC(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback,
+    CAInitializeNFC(CARegisterCallback, CAReceivedPacketCallback, CAAdapterChangedCallback,
                     CAAdapterErrorHandleCallback, handle);
 #endif /* NFC_ADAPTER */
 }
@@ -189,11 +200,13 @@ void CASetPacketReceivedCallback(CANetworkPacketReceivedCallback callback)
     g_networkPacketReceivedCallback = callback;
 }
 
-void CASetNetworkChangeCallback(CANetworkChangeCallback callback)
+void CASetNetworkMonitorCallbacks(CAAdapterChangeCallback adapterCB,
+                                  CAConnectionChangeCallback connCB)
 {
-    OIC_LOG(DEBUG, TAG, "Set network handle callback");
+    OIC_LOG(DEBUG, TAG, "Set network monitoring callback");
 
-    g_networkChangeCallback = callback;
+    g_adapterChangeCallback = adapterCB;
+    g_connChangeCallback = connCB;
 }
 
 void CASetErrorHandleCallback(CAErrorHandleCallback errorCallback)
index e637642..5d5ed73 100644 (file)
@@ -842,17 +842,6 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep,
     coap_delete_pdu(pdu);
 }
 
-static void CANetworkChangedCallback(const CAEndpoint_t *info, CANetworkStatus_t status)
-{
-    (void)info;
-    (void)status;
-
-    if (g_nwMonitorHandler)
-    {
-        g_nwMonitorHandler(info, status);
-    }
-}
-
 void CAHandleRequestResponseCallbacks()
 {
 #ifdef SINGLE_THREAD
@@ -1045,8 +1034,6 @@ void CASetNetworkMonitorCallback(CANetworkMonitorCallback nwMonitorHandler)
 CAResult_t CAInitializeMessageHandler()
 {
     CASetPacketReceivedCallback(CAReceivedPacketCallback);
-
-    CASetNetworkChangeCallback(CANetworkChangedCallback);
     CASetErrorHandleCallback(CAErrorHandler);
 
 #ifndef SINGLE_THREAD
index 2685880..ff70009 100644 (file)
@@ -38,6 +38,8 @@
 
 #define TAG "OIC_CA_IP_MONITOR"
 
+static CAIPConnectionStateChangeCallback g_networkChangeCallback;
+
 static CAInterface_t *CANewInterfaceItem(int index, const char *name, int family,
                                          uint32_t addr, int flags);
 
@@ -69,6 +71,11 @@ int CAGetPollingInterval(int interval)
     return interval;
 }
 
+void CAIPSetNetworkMonitorCallback(CAIPConnectionStateChangeCallback callback)
+{
+    g_networkChangeCallback = callback;
+}
+
 CAInterface_t *CAFindInterfaceChange()
 {
     char buf[MAX_INTERFACE_INFO_LENGTH] = { 0 };
@@ -438,9 +445,9 @@ Java_org_iotivity_ca_CaIpInterface_caIpStateEnabled(JNIEnv *env, jclass class)
 {
     (void)env;
     (void)class;
-    OIC_LOG(DEBUG, TAG, "caIpStateEnabled");
 
-    CAWakeUpForChange();
+    OIC_LOG(DEBUG, TAG, "Wifi is in Activated State");
+    g_networkChangeCallback(CA_ADAPTER_IP, CA_INTERFACE_UP);
 }
 
 JNIEXPORT void JNICALL
@@ -448,13 +455,7 @@ Java_org_iotivity_ca_CaIpInterface_caIpStateDisabled(JNIEnv *env, jclass class)
 {
     (void)env;
     (void)class;
-    OIC_LOG(DEBUG, TAG, "caIpStateDisabled");
 
-    u_arraylist_t *iflist = CAIPGetInterfaceInformation(0);
-    if (!iflist)
-    {
-        OIC_LOG_V(ERROR, TAG, "get interface info failed");
-        return;
-    }
-    u_arraylist_destroy(iflist);
+    OIC_LOG(DEBUG, TAG, "Wifi is in Deactivated State");
+    g_networkChangeCallback(CA_ADAPTER_IP, CA_INTERFACE_DOWN);
 }
index 308ec6d..4c4c9fb 100644 (file)
@@ -68,7 +68,7 @@ static CANetworkPacketReceivedCallback g_networkPacketCallback = NULL;
 /**
  * Network Changed Callback to CA.
  */
-static CANetworkChangeCallback g_networkChangeCallback = NULL;
+static CAAdapterChangeCallback g_networkChangeCallback = NULL;
 
 /**
  * error Callback to CA adapter.
@@ -137,10 +137,16 @@ void CAIPDeinitializeQueueHandles()
 
 #endif // SINGLE_THREAD
 
-void CAIPConnectionStateCB(const char *ipAddress, CANetworkStatus_t status)
+void CAIPConnectionStateCB(CATransportAdapter_t adapter, CANetworkStatus_t status)
 {
-    (void)ipAddress;
-    (void)status;
+    if (g_networkChangeCallback)
+    {
+        g_networkChangeCallback(adapter, status);
+    }
+    else
+    {
+        OIC_LOG(ERROR, TAG, "g_networkChangeCallback is NULL");
+    }
 }
 
 #ifdef __WITH_DTLS__
@@ -215,7 +221,7 @@ static void CAInitializeIPGlobals()
 
 CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
                           CANetworkPacketReceivedCallback networkPacketCallback,
-                          CANetworkChangeCallback netCallback,
+                          CAAdapterChangeCallback netCallback,
                           CAErrorHandleCallback errorCallback, ca_thread_pool_t handle)
 {
     OIC_LOG(DEBUG, TAG, "IN");
@@ -234,6 +240,9 @@ CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
     caglobals.ip.threadpool = handle;
 
     CAIPSetPacketReceiveCallback(CAIPPacketReceivedCB);
+#ifndef SINGLE_THREAD
+    CAIPSetConnectionStateChangeCallback(CAIPConnectionStateCB);
+#endif
 #ifdef __WITH_DTLS__
     CAAdapterNetDtlsInit();
 
index 83433d8..da0375f 100644 (file)
@@ -250,7 +250,12 @@ static void CASelectReturned(fd_set *readFds, int ret)
         else ISSET(m4s, readFds, CA_MULTICAST | CA_IPV4 | CA_SECURE)
         else if (FD_ISSET(caglobals.ip.netlinkFd, readFds))
         {
-            CAHandleNetlink();
+            CAInterface_t *ifchanged = CAFindInterfaceChange();
+            if (ifchanged)
+            {
+                CAProcessNewInterface(ifchanged);
+                OICFree(ifchanged);
+            }
             break;
         }
         else if (FD_ISSET(caglobals.ip.shutdownFds[0], readFds))
@@ -261,13 +266,6 @@ static void CASelectReturned(fd_set *readFds, int ret)
             {
                 continue;
             }
-
-            CAInterface_t *ifchanged = CAFindInterfaceChange();
-            if (ifchanged)
-            {
-                CAProcessNewInterface(ifchanged);
-                OICFree(ifchanged);
-            }
             break;
         }
         else
@@ -836,64 +834,18 @@ static void CAProcessNewInterface(CAInterface_t *ifitem)
         OIC_LOG(DEBUG, TAG, "ifitem is null");
         return;
     }
-
-    applyMulticastToInterface6(ifitem->index);
-    struct in_addr inaddr = { .s_addr = ifitem->ipv4addr };
-    applyMulticastToInterface4(inaddr);
+    if (ifitem->family == AF_INET6)
+    {
+        applyMulticastToInterface6(ifitem->index);
+    }
+    if (ifitem->family == AF_INET)
+    {
+        struct in_addr inaddr = { .s_addr = ifitem->ipv4addr };
+        applyMulticastToInterface4(inaddr);
+    }
 }
 static void CAHandleNetlink()
 {
-#ifdef __linux__
-    char buf[4096];
-    struct nlmsghdr *nh;
-    struct sockaddr_nl sa;
-    struct iovec iov = { buf, sizeof (buf) };
-    struct msghdr msg = { (void *)&sa, sizeof (sa), &iov, 1, NULL, 0, 0 };
-
-    size_t len = recvmsg(caglobals.ip.netlinkFd, &msg, 0);
-
-    for (nh = (struct nlmsghdr *)buf; NLMSG_OK(nh, len); nh = NLMSG_NEXT(nh, len))
-    {
-        if (nh != NULL && nh->nlmsg_type != RTM_NEWLINK)
-        {
-            continue;
-        }
-
-        struct ifinfomsg *ifi = (struct ifinfomsg *)NLMSG_DATA(nh);
-        if (!ifi || (ifi->ifi_flags & IFF_LOOPBACK) || !(ifi->ifi_flags & IFF_RUNNING))
-        {
-            continue;
-        }
-
-        int newIndex = ifi->ifi_index;
-
-        u_arraylist_t *iflist = CAIPGetInterfaceInformation(newIndex);
-        if (!iflist)
-        {
-            OIC_LOG_V(ERROR, TAG, "get interface info failed: %s", strerror(errno));
-            return;
-        }
-
-        uint32_t listLength = u_arraylist_length(iflist);
-        for (uint32_t i = 0; i < listLength; i++)
-        {
-            CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
-            if (!ifitem)
-            {
-                continue;
-            }
-
-            if ((int)ifitem->index != newIndex)
-            {
-                continue;
-            }
-
-            CAProcessNewInterface(ifitem);
-            break; // we found the one we were looking for
-        }
-        u_arraylist_destroy(iflist);
-    }
-#endif // __linux__
 }
 
 void CAIPSetPacketReceiveCallback(CAIPPacketReceivedCallback callback)
@@ -906,6 +858,11 @@ void CAIPSetExceptionCallback(CAIPExceptionCallback callback)
     g_exceptionCallback = callback;
 }
 
+void CAIPSetConnectionStateChangeCallback(CAIPConnectionStateChangeCallback callback)
+{
+    CAIPSetNetworkMonitorCallback(callback);
+}
+
 static void sendData(int fd, const CAEndpoint_t *endpoint,
                      const void *data, uint32_t dlen,
                      const char *cast, const char *fam)
index f1d5211..a2f2e4f 100644 (file)
 
 #include "caipinterface.h"
 
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
 #include <sys/types.h>
+#include <sys/select.h>
 #include <ifaddrs.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
 #include <net/if.h>
-#include <sys/socket.h>
 #include <netdb.h>
-#include <string.h>
 #include <errno.h>
-#include <unistd.h>
 
+#ifdef __linux__
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#endif
+
+#include "camutex.h"
 #include "caadapterutils.h"
 #include "logger.h"
 #include "oic_malloc.h"
 
 #define TAG "OIC_CA_IP_MONITOR"
 
-CAResult_t CAIPStartNetworkMonitor()
+/**
+ * Mutex for synchronizing access to cached interface and IP address information.
+ */
+static ca_mutex g_networkMonitorContextMutex = NULL;
+
+/**
+ * Used to storing network interface.
+ */
+static u_arraylist_t *g_netInterfaceList = NULL;
+
+static CAIPConnectionStateChangeCallback g_networkChangeCallback = NULL;
+
+static CAResult_t CAIPInitializeNetworkMonitorList();
+static void CAIPDestroyNetworkMonitorList();
+static CAInterface_t *CANewInterfaceItem(int index, const char *name, int family,
+                                         uint32_t addr, int flags);
+
+static CAResult_t CAIPInitializeNetworkMonitorList()
+{
+    if (!g_networkMonitorContextMutex)
+    {
+        g_networkMonitorContextMutex = ca_mutex_new();
+        if (!g_networkMonitorContextMutex)
+        {
+            OIC_LOG(ERROR, TAG, "ca_mutex_new has failed");
+            return CA_STATUS_FAILED;
+        }
+    }
+
+    if (!g_netInterfaceList)
+    {
+        g_netInterfaceList = u_arraylist_create();
+        if (!g_netInterfaceList)
+        {
+            OIC_LOG(ERROR, TAG, "u_arraylist_create has failed");
+            CAIPDestroyNetworkMonitorList();
+            return CA_STATUS_FAILED;
+        }
+    }
+}
+
+static void CAIPDestroyNetworkMonitorList()
+{
+    if (g_netInterfaceList)
+    {
+        u_arraylist_destroy(g_netInterfaceList);
+        g_netInterfaceList = NULL;
+    }
+
+    if (g_networkMonitorContextMutex)
+    {
+        ca_mutex_free(g_networkMonitorContextMutex);
+        g_networkMonitorContextMutex = NULL;
+    }
+}
+
+static bool CACmpNetworkList(uint32_t ifiindex)
+{
+    if (!g_netInterfaceList)
+    {
+        OIC_LOG(ERROR, TAG, "g_netInterfaceList is NULL");
+        return false;
+    }
+
+    ca_mutex_lock(g_networkMonitorContextMutex);
+
+    uint32_t list_length = u_arraylist_length(g_netInterfaceList);
+    for (uint32_t list_index = 0; list_index < list_length; list_index++)
+    {
+        CAInterface_t *currItem = (CAInterface_t *) u_arraylist_get(g_netInterfaceList, list_index);
+        if (currItem->index == ifiindex)
+        {
+            ca_mutex_unlock(g_networkMonitorContextMutex);
+            return true;
+        }
+    }
+    ca_mutex_unlock(g_networkMonitorContextMutex);
+    return false;
+}
+
+static CAResult_t CAAddNetworkMonitorList(CAInterface_t *ifitem)
 {
+    VERIFY_NON_NULL(g_netInterfaceList, TAG, "g_netInterfaceList is NULL");
+    VERIFY_NON_NULL(ifitem, TAG, "ifitem is NULL");
+
+    ca_mutex_lock(g_networkMonitorContextMutex);
+    bool result = u_arraylist_add(g_netInterfaceList, (void *) ifitem);
+    if (!result)
+    {
+        OIC_LOG(ERROR, TAG, "u_arraylist_add failed.");
+        ca_mutex_unlock(g_networkMonitorContextMutex);
+        return CA_STATUS_FAILED;
+    }
+    ca_mutex_unlock(g_networkMonitorContextMutex);
     return CA_STATUS_OK;
 }
 
+static void CARemoveNetworkMonitorList(int ifiindex)
+{
+    VERIFY_NON_NULL_VOID(g_netInterfaceList, TAG, "g_netInterfaceList is NULL");
+
+    ca_mutex_lock(g_networkMonitorContextMutex);
+
+    uint32_t list_length = u_arraylist_length(g_netInterfaceList);
+    for (uint32_t list_index = 0; list_index < list_length; list_index++)
+    {
+        CAInterface_t *removedifitem = (CAInterface_t *) u_arraylist_get(
+                g_netInterfaceList, list_index);
+        if (removedifitem && removedifitem->index == ifiindex)
+        {
+            if (u_arraylist_remove(g_netInterfaceList, list_index))
+            {
+                OICFree(removedifitem);
+                ca_mutex_unlock(g_networkMonitorContextMutex);
+                return;
+            }
+            continue;
+        }
+    }
+    ca_mutex_unlock(g_networkMonitorContextMutex);
+    return;
+}
+
+CAResult_t CAIPStartNetworkMonitor()
+{
+    return CAIPInitializeNetworkMonitorList();
+}
+
 CAResult_t CAIPStopNetworkMonitor()
 {
+    CAIPDestroyNetworkMonitorList();
     return CA_STATUS_OK;
 }
 
@@ -51,9 +189,96 @@ int CAGetPollingInterval(int interval)
     return interval;
 }
 
+void CAIPSetNetworkMonitorCallback(CAIPConnectionStateChangeCallback callback)
+{
+    g_networkChangeCallback = callback;
+}
+
+static CAInterface_t *CANewInterfaceItem(int index, const char *name, int family,
+                                         uint32_t addr, int flags)
+{
+    CAInterface_t *ifitem = (CAInterface_t *)OICCalloc(1, sizeof (CAInterface_t));
+    if (!ifitem)
+    {
+        OIC_LOG(ERROR, TAG, "Malloc failed");
+        return NULL;
+    }
+
+    OICStrcpy(ifitem->name, sizeof (ifitem->name), name);
+    ifitem->index = index;
+    ifitem->family = family;
+    ifitem->ipv4addr = addr;
+    ifitem->flags = flags;
+
+    return ifitem;
+}
+
 CAInterface_t *CAFindInterfaceChange()
 {
-    return NULL;
+    CAInterface_t *foundNewInterface = NULL;
+#ifdef __linux__
+    char buf[4096];
+    struct nlmsghdr *nh;
+    struct sockaddr_nl sa;
+    struct iovec iov = { buf, sizeof (buf) };
+    struct msghdr msg = { (void *)&sa, sizeof (sa), &iov, 1, NULL, 0, 0 };
+
+    size_t len = recvmsg(caglobals.ip.netlinkFd, &msg, 0);
+
+    for (nh = (struct nlmsghdr *)buf; NLMSG_OK(nh, len); nh = NLMSG_NEXT(nh, len))
+    {
+        if (nh != NULL && nh->nlmsg_type != RTM_NEWLINK)
+        {
+            continue;
+        }
+
+        struct ifinfomsg *ifi = (struct ifinfomsg *)NLMSG_DATA(nh);
+
+        int ifiIndex = ifi->ifi_index;
+        u_arraylist_t *iflist = CAIPGetInterfaceInformation(ifiIndex);
+
+        if ((!ifi || (ifi->ifi_flags & IFF_LOOPBACK) || !(ifi->ifi_flags & IFF_RUNNING)))
+        {
+            bool isFound = CACmpNetworkList(ifiIndex);
+            if (isFound)
+            {
+                CARemoveNetworkMonitorList(ifiIndex);
+                if (g_networkChangeCallback)
+                {
+                    g_networkChangeCallback(CA_ADAPTER_IP ,CA_INTERFACE_DOWN);
+                }
+            }
+            continue;
+        }
+
+        if (!iflist)
+        {
+            OIC_LOG_V(ERROR, TAG, "get interface info failed: %s", strerror(errno));
+            return NULL;
+        }
+
+        uint32_t listLength = u_arraylist_length(iflist);
+        for (uint32_t i = 0; i < listLength; i++)
+        {
+            CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
+            if (!ifitem)
+            {
+                continue;
+            }
+
+            if ((int)ifitem->index != ifiIndex)
+            {
+                continue;
+            }
+
+            foundNewInterface = CANewInterfaceItem(ifitem->index, ifitem->name, ifitem->family,
+                                                   ifitem->ipv4addr, ifitem->flags);
+            break;    // we found the one we were looking for
+        }
+        u_arraylist_destroy(iflist);
+    }
+#endif
+    return foundNewInterface;
 }
 
 u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex)
@@ -138,9 +363,24 @@ u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex)
             goto exit;
         }
 
-        OIC_LOG_V(DEBUG, TAG, "Added interface: %s (%d)", ifitem->name, family);
+        bool isFound = CACmpNetworkList(ifitem->index);
+        if (!isFound)
+        {
+            CAInterface_t *newifitem = CANewInterfaceItem(ifitem->index, ifitem->name, ifitem->family,
+                                                          ifitem->ipv4addr, ifitem->flags);
+            CAResult_t ret = CAAddNetworkMonitorList(newifitem);
+            if (CA_STATUS_OK != ret)
+            {
+                OICFree(newifitem);
+                goto exit;
+            }
+            if (g_networkChangeCallback)
+            {
+                g_networkChangeCallback(CA_ADAPTER_IP, CA_INTERFACE_UP);
+            }
+            OIC_LOG_V(DEBUG, TAG, "Added interface: %s (%d)", ifitem->name, ifitem->family);
+        }
     }
-
     freeifaddrs(ifp);
     return iflist;
 
index 437e535..aaa39d4 100644 (file)
@@ -39,6 +39,8 @@
 #define TAG "IP_MONITOR"
 #define MAX_INTERFACE_INFO_LENGTH (1024)
 
+static CAIPConnectionStateChangeCallback g_networkChangeCallback;
+
 static CAInterface_t *CANewInterfaceItem(int index, char *name, int family,
                                          uint32_t addr, int flags);
 
@@ -56,6 +58,11 @@ int CAGetPollingInterval(int interval)
     return interval;
 }
 
+void CAIPSetNetworkMonitorCallback(CAIPConnectionStateChangeCallback callback)
+{
+    g_networkChangeCallback = callback;
+}
+
 CAInterface_t *CAFindInterfaceChange()
 {
     char buf[MAX_INTERFACE_INFO_LENGTH] = { 0 };
@@ -357,17 +364,11 @@ void CAWIFIConnectionStateChangedCb(wifi_connection_state_e state, wifi_ap_h ap,
 
     if (WIFI_CONNECTION_STATE_CONNECTED == state)
     {
-        CAWakeUpForChange();
+        g_networkChangeCallback(CA_ADAPTER_IP, CA_INTERFACE_UP);
     }
     else
     {
-        u_arraylist_t *iflist = CAIPGetInterfaceInformation(0);
-        if (!iflist)
-        {
-            OIC_LOG_V(ERROR, TAG, "get interface info failed");
-            return;
-        }
-        u_arraylist_destroy(iflist);
+        g_networkChangeCallback(CA_ADAPTER_IP, CA_INTERFACE_DOWN);
     }
 
     OIC_LOG(DEBUG, TAG, "OUT");
index cc34caa..eddee4d 100644 (file)
@@ -58,9 +58,9 @@ static CAQueueingThread_t *g_sendQueueHandle = NULL;
 static CANetworkPacketReceivedCallback g_packetReceivedCallback = NULL;
 
 /**
- *  Network Changed Callback to CA
+ *  Adapter Changed Callback to CA
  */
-static CANetworkChangeCallback g_connectionStateCallback = NULL;
+static CAAdapterChangeCallback g_adapterStateCallback = NULL;
 
 /**
  * error Callback to CA adapter
@@ -177,16 +177,16 @@ void CANFCErrorHandler(const CAEndpoint_t *endpoint, const void *data, uint32_t
 
 CAResult_t CAInitializeNFC(CARegisterConnectivityCallback registerCallback,
                            CANetworkPacketReceivedCallback packetReceivedCallback,
-                           CANetworkChangeCallback connectionStateCallback,
+                           CAAdapterChangeCallback netCallback,
                            CAErrorHandleCallback errorCallback, ca_thread_pool_t handle)
 {
     OIC_LOG(DEBUG, TAG, "IN");
     VERIFY_NON_NULL(registerCallback, TAG, "registerCallback");
     VERIFY_NON_NULL(packetReceivedCallback, TAG, "packetReceivedCallback");
-    VERIFY_NON_NULL(connectionStateCallback, TAG, "connectionStateCallback");
+    VERIFY_NON_NULL(netCallback, TAG, "netCallback");
     VERIFY_NON_NULL(handle, TAG, "thread pool handle");
 
-    g_connectionStateCallback = connectionStateCallback;
+    g_adapterStateCallback = netCallback;
     g_packetReceivedCallback = packetReceivedCallback;
     g_errorCallback = errorCallback;
 
index b34cb83..fba4ca8 100644 (file)
@@ -59,7 +59,7 @@ static CANetworkPacketReceivedCallback g_networkPacketCallback = NULL;
 /**
  * Network Changed Callback to CA.
  */
-static CANetworkChangeCallback g_networkChangeCallback = NULL;
+static CAAdapterChangeCallback g_networkChangeCallback = NULL;
 
 /**
  * Holds XMPP data information.
@@ -91,26 +91,16 @@ void CARANotifyNetworkChange(const char *address, CANetworkStatus_t status)
 
     g_xmppData.connectionStatus = status;
 
-    CAEndpoint_t *localEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS,
-                                CA_ADAPTER_REMOTE_ACCESS,
-                                address, 0);
-    if (!localEndpoint)
-    {
-        OIC_LOG(ERROR, RA_ADAPTER_TAG, "localEndpoint creation failed!");
-        return;
-    }
-    CANetworkChangeCallback networkChangeCallback = g_networkChangeCallback;
+    CAAdapterChangeCallback networkChangeCallback = g_networkChangeCallback;
     if (networkChangeCallback)
     {
-        networkChangeCallback(localEndpoint, status);
+        networkChangeCallback(CA_ADAPTER_REMOTE_ACCESS, status);
     }
     else
     {
         OIC_LOG(ERROR, RA_ADAPTER_TAG, "g_networkChangeCallback is NULL");
     }
 
-    CAFreeEndpoint(localEndpoint);
-
     OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CARANotifyNetworkChange OUT");
 }
 
@@ -359,8 +349,8 @@ static int CARAConnHandler(xmpp_t *xmpp, xmppconn_info_t *conninfo, void *udata)
 }
 
 CAResult_t CAInitializeRA(CARegisterConnectivityCallback registerCallback,
-                                CANetworkPacketReceivedCallback networkPacketCallback,
-                                CANetworkChangeCallback netCallback, ca_thread_pool_t handle)
+                          CANetworkPacketReceivedCallback networkPacketCallback,
+                          CAAdapterChangeCallback netCallback, ca_thread_pool_t handle)
 {
     OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CAInitializeRA IN");
     if (!registerCallback || !networkPacketCallback || !netCallback || !handle)
@@ -615,7 +605,7 @@ static CANetworkPacketReceivedCallback g_networkPacketCallback = NULL;
 /**
  * Network Changed Callback to CA.
  */
-static CANetworkChangeCallback g_networkChangeCallback = NULL;
+static CAAdapterChangeCallback g_networkChangeCallback = NULL;
 
 /**
  * Holds XMPP data information.
@@ -657,26 +647,16 @@ void CARANotifyNetworkChange(const char *address, CANetworkStatus_t status)
 {
     OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CARANotifyNetworkChange IN");
 
-    CAEndpoint_t *localEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS,
-                                CA_ADAPTER_REMOTE_ACCESS,
-                                address, 0);
-    if (!localEndpoint)
-    {
-        OIC_LOG(ERROR, RA_ADAPTER_TAG, "localEndpoint creation failed!");
-        return;
-    }
-    CANetworkChangeCallback networkChangeCallback = g_networkChangeCallback;
+    CAAdapterChangeCallback networkChangeCallback = g_networkChangeCallback;
     if (networkChangeCallback)
     {
-        networkChangeCallback(localEndpoint, status);
+        networkChangeCallback(CA_ADAPTER_REMOTE_ACCESS, status);
     }
     else
     {
         OIC_LOG(ERROR, RA_ADAPTER_TAG, "g_networkChangeCallback is NULL");
     }
 
-    CAFreeEndpoint(localEndpoint);
-
     OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CARANotifyNetworkChange OUT");
 }
 
@@ -783,8 +763,8 @@ void CARAXmppMessageReceivedCB(void * const param, xmpp_error_code_t result,
 }
 
 CAResult_t CAInitializeRA(CARegisterConnectivityCallback registerCallback,
-                                CANetworkPacketReceivedCallback networkPacketCallback,
-                                CANetworkChangeCallback netCallback, ca_thread_pool_t handle)
+                          CANetworkPacketReceivedCallback networkPacketCallback,
+                          CAAdapterChangeCallback netCallback, ca_thread_pool_t handle)
 {
     OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CAInitializeRA IN");
     if (!registerCallback || !networkPacketCallback || !netCallback || !handle)
index 64aa5d7..6ea9c36 100644 (file)
@@ -71,9 +71,14 @@ static CAQueueingThread_t *g_sendQueueHandle = NULL;
 static CANetworkPacketReceivedCallback g_networkPacketCallback = NULL;
 
 /**
- * Network Changed Callback to CA.
+ * Adapter Changed Callback to CA.
  */
-static CANetworkChangeCallback g_networkChangeCallback = NULL;
+static CAAdapterChangeCallback g_networkChangeCallback = NULL;
+
+/**
+ * Connection Changed Callback to CA.
+ */
+static CAConnectionChangeCallback g_connectionChangeCallback = NULL;
 
 /**
  * error Callback to CA adapter.
@@ -84,14 +89,9 @@ static void CATCPPacketReceivedCB(const CASecureEndpoint_t *sep,
                                   const void *data, uint32_t dataLength);
 
 /**
- * KeepAlive Connected Callback to CA adapter.
+ * KeepAlive Connected or Disconnected Callback to CA adapter.
  */
-static CAKeepAliveConnectedCallback g_connCallback = NULL;
-
-/**
- * KeepAlive Disconnected Callback to CA adapter.
- */
-static CAKeepAliveDisconnectedCallback g_disconnCallback = NULL;
+static CAKeepAliveConnectionCallback g_connKeepAliveCallback = NULL;
 
 static CAResult_t CATCPInitializeQueueHandles();
 
@@ -175,29 +175,28 @@ void CATCPErrorHandler(const CAEndpoint_t *endpoint, const void *data,
     }
 }
 
-static void CATCPKeepAliveHandler(const char *addr, uint16_t port, bool isConnected)
+static void CATCPConnectionHandler(const char *addr, uint16_t port, bool isConnected)
 {
     CAEndpoint_t endpoint = { .adapter =  CA_ADAPTER_TCP,
                               .port = port };
     OICStrcpy(endpoint.addr, sizeof(endpoint.addr), addr);
 
-    if (isConnected)
+    // Pass the changed connection status to RI Layer for keepalive.
+    if (g_connKeepAliveCallback)
     {
-        g_connCallback(&endpoint);
+        g_connKeepAliveCallback(&endpoint, isConnected);
     }
-    else
+
+    // Pass the changed connection status to CAUtil.
+    if (g_connectionChangeCallback)
     {
-        g_disconnCallback(&endpoint);
+        g_connectionChangeCallback(&endpoint, isConnected);
     }
 }
 
-void CATCPSetKeepAliveCallbacks(CAKeepAliveConnectedCallback ConnHandler,
-                                CAKeepAliveDisconnectedCallback DisconnHandler)
+void CATCPSetKeepAliveCallbacks(CAKeepAliveConnectionCallback ConnHandler)
 {
-    g_connCallback = ConnHandler;
-    g_disconnCallback = DisconnHandler;
-
-    CATCPSetKeepAliveCallback(CATCPKeepAliveHandler);
+    g_connKeepAliveCallback = ConnHandler;
 }
 
 static void CAInitializeTCPGlobals()
@@ -226,7 +225,8 @@ static void CAInitializeTCPGlobals()
 
 CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback,
                            CANetworkPacketReceivedCallback networkPacketCallback,
-                           CANetworkChangeCallback netCallback,
+                           CAAdapterChangeCallback netCallback,
+                           CAConnectionChangeCallback connCallback,
                            CAErrorHandleCallback errorCallback, ca_thread_pool_t handle)
 {
     OIC_LOG(DEBUG, TAG, "IN");
@@ -236,12 +236,14 @@ CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback,
     VERIFY_NON_NULL(handle, TAG, "thread pool handle");
 
     g_networkChangeCallback = netCallback;
+    g_connectionChangeCallback = connCallback;
     g_networkPacketCallback = networkPacketCallback;
     g_errorCallback = errorCallback;
 
     CAInitializeTCPGlobals();
     caglobals.tcp.threadpool = handle;
 
+    CATCPSetConnectionChangedCallback(CATCPConnectionHandler);
     CATCPSetPacketReceiveCallback(CATCPPacketReceivedCB);
     CATCPSetErrorHandler(CATCPErrorHandler);
 
index b266815..3d9ef2f 100644 (file)
@@ -83,7 +83,7 @@ static CATCPErrorHandleCallback g_TCPErrorHandler = NULL;
 /**
  * Connected Callback to pass the connection information to RI.
  */
-static CATCPKeepAliveHandleCallback g_keepaliveCallback = NULL;
+static CATCPConnectionHandleCallback g_connectionCallback = NULL;
 
 static CAResult_t CATCPCreateMutex();
 static void CATCPDestroyMutex();
@@ -720,9 +720,9 @@ void CATCPSetPacketReceiveCallback(CATCPPacketReceivedCallback callback)
     g_packetReceivedCallback = callback;
 }
 
-void CATCPSetKeepAliveCallback(CATCPKeepAliveHandleCallback keepaliveHandler)
+void CATCPSetConnectionChangedCallback(CATCPConnectionHandleCallback connHandler)
 {
-    g_keepaliveCallback = keepaliveHandler;
+    g_connectionCallback = connHandler;
 }
 
 static size_t CACheckPayloadLength(const void *data, size_t dlen)
@@ -892,10 +892,10 @@ CATCPSessionInfo_t *CAConnectTCPSession(const CAEndpoint_t *endpoint)
 
     CHECKFD(fd);
 
-    // pass the connection information to RI for keepalive.
-    if (g_keepaliveCallback)
+    // pass the connection information to CA Common Layer.
+    if (g_connectionCallback)
     {
-        g_keepaliveCallback(svritem->sep.endpoint.addr, svritem->sep.endpoint.port, true);
+        g_connectionCallback(svritem->sep.endpoint.addr, svritem->sep.endpoint.port, true);
     }
 
     return svritem;
@@ -915,10 +915,10 @@ CAResult_t CADisconnectTCPSession(CATCPSessionInfo_t *svritem, size_t index)
     u_arraylist_remove(caglobals.tcp.svrlist, index);
     OICFree(svritem->recvData);
 
-    // pass the connection information to RI for keepalive.
-    if (g_keepaliveCallback)
+    // pass the connection information to CA Common Layer.
+    if (g_connectionCallback)
     {
-        g_keepaliveCallback(svritem->sep.endpoint.addr, svritem->sep.endpoint.port, false);
+        g_connectionCallback(svritem->sep.endpoint.addr, svritem->sep.endpoint.port, false);
     }
 
     OICFree(svritem);
index 6305edb..c89cb4c 100644 (file)
@@ -9,36 +9,25 @@ print "Reading util folder script"
 
 ca_os = env.get('TARGET_OS')
 ca_transport = env.get('TARGET_TRANSPORT')
+target_os = env.get('TARGET_OS')
 project_root = env.get('SRC_DIR')
 root_dir = os.path.join(project_root, 'resource', 'csdk', 'connectivity')
 src_dir = os.path.join(root_dir, 'util', 'src')
 
-env.PrependUnique(CPPPATH = [ os.path.join(root_dir, 'api') ])
-env.AppendUnique(CPPPATH = [ os.path.join(root_dir, 'inc'),
-                             os.path.join(project_root, 'resource', 'csdk', 'logger', 'include'),
-                             os.path.join(root_dir, 'lib', 'libcoap-4.1.1'),
-                             os.path.join(root_dir, 'common', 'inc'),
-                             os.path.join(root_dir, 'util', 'inc') ])
-
 ######################################################################
 # Source files to build common for platforms
 ######################################################################
 
-env.AppendUnique(CA_SRC = [os.path.join('./../util/src','cautilinterface.c')])
-
-if (('BLE' in ca_transport) or ('ALL' in ca_transport)):
-    if ca_os in ['linux', 'tizen', 'arduino']:
-               env.AppendUnique(CA_SRC = [
-               os.path.join(src_dir, 'camanager', ca_os, 'caleconnectionmanager.c')])
+env.AppendUnique(CA_SRC = [os.path.join('./../util/src/cautilinterface.c')])
 
-    if ca_os == 'android':
-               env.AppendUnique(CA_SRC = [
-               os.path.join(src_dir, 'camanager', 'android', 'caleconnectionmanager.c'),
-               os.path.join(src_dir, 'camanager', 'android', 'caleautoconnector.c'),
-               os.path.join(src_dir, 'camanager', 'android', 'camanagerleutil.c'),
-               os.path.join(src_dir, 'camanager', 'android', 'camanagerdevice.c')])
+if target_os == 'android':
+       if (('BLE' in ca_transport) or ('ALL' in ca_transport)):
+                       env.AppendUnique(CA_SRC = [
+                       os.path.join(src_dir, 'camanager', 'android', 'caleconnectionmanager.c'),
+                       os.path.join(src_dir, 'camanager', 'android', 'caleautoconnector.c'),
+                       os.path.join(src_dir, 'camanager', 'android', 'camanagerleutil.c'),
+                       os.path.join(src_dir, 'camanager', 'android', 'camanagerdevice.c')])
 
-if (('BT' in ca_transport) or ('ALL' in ca_transport)):
-    if ca_os == 'android':
-               env.AppendUnique(CA_SRC = [
-               os.path.join(src_dir, 'btpairing' ,'android', 'cabtpairing.c')])
+       if (('BT' in ca_transport) or ('ALL' in ca_transport)):
+                       env.AppendUnique(CA_SRC = [
+                       os.path.join(src_dir, 'btpairing' ,'android', 'cabtpairing.c')])
\ No newline at end of file
index 9a175bf..fa3cb81 100644 (file)
@@ -48,18 +48,7 @@ CAResult_t CASetLEClientAutoConnectionDeviceInfo();
  */
 CAResult_t CAUnsetLEClientAutoConnectionDeviceInfo();
 
-/**
- * Start advertise to receive request for scanning or connecting.
- */
-void CAStartServerLEAdvertising();
-
-/**
- * Stop advertise to destroy advertiser.
- */
-void CAStopServerLEAdvertising();
-
-#ifdef __ANDROID__
-#ifdef LE_ADAPTER
+#if defined(__ANDROID__) && defined(LE_ADAPTER)
 /**
  * initialize client connection manager
  * @param[in]   env                   JNI interface pointer.
@@ -78,7 +67,6 @@ CAResult_t CAManagerLEClientInitialize(JNIEnv *env, JavaVM *jvm, jobject context
  */
 CAResult_t CAManagerLEClientTerminate(JNIEnv *env);
 #endif
-#endif
 
 #ifdef __cplusplus
 } /* extern "C" */
index 18ba248..fb5742b 100644 (file)
@@ -32,9 +32,6 @@
 
 #define TAG "OIC_CA_MANAGER_LE"
 
-static CAAdapterStateChangedCB g_adapterStateCB = NULL;
-static CAConnectionStateChangedCB g_connStateCB = NULL;
-
 static const jint SUPPORT_ADNROID_API_LEVEL = 18;
 static const jint AUTH_FAIL = 5;
 static const jint LINK_LOSS = 8;
@@ -46,14 +43,6 @@ static JavaVM *g_jvm = NULL;
 static jobject g_context = NULL;
 static jobject g_connectedDeviceSet = NULL;
 
-void CASetLENetworkMonitorCallbacks(CAAdapterStateChangedCB adapterStateCB,
-                                    CAConnectionStateChangedCB connStateCB)
-{
-    OIC_LOG(DEBUG, TAG, "CASetLENetworkMonitorCallbacks");
-
-    g_adapterStateCB = adapterStateCB;
-    g_connStateCB = connStateCB;
-}
 
 CAResult_t CASetLEClientAutoConnectionDeviceInfo(const char* address)
 {
@@ -306,10 +295,6 @@ Java_org_iotivity_ca_CaLeClientInterface_caManagerAdapterStateChangedCallback(
     if (state_on == state)
     {
         OIC_LOG(DEBUG, TAG, "AdapterStateChangedCallback : state_on");
-        if (g_adapterStateCB)
-        {
-            g_adapterStateCB(CA_ADAPTER_GATT_BTLE, true);
-        }
 
         // when BT state is on. recovery flag has to be reset.
         CAManagerSetBTRecovery(false);
@@ -334,10 +319,6 @@ Java_org_iotivity_ca_CaLeClientInterface_caManagerAdapterStateChangedCallback(
     else if (state_off == state)
     {
         OIC_LOG(DEBUG, TAG, "AdapterStateChangedCallback : state_off");
-        if (g_adapterStateCB)
-        {
-            g_adapterStateCB(CA_ADAPTER_GATT_BTLE, false);
-        }
 
         // reset isAutoConnecting flag for all target devices
         size_t length = CAManagerGetACDataLength();
@@ -458,13 +439,6 @@ Java_org_iotivity_ca_CaLeClientInterface_caManagerLeGattConnectionStateChangeCB(
     {
         OIC_LOG(DEBUG, TAG, "LE is disconnected");
 
-        if (g_connStateCB)
-        {
-            OIC_LOG_V(DEBUG, TAG, "LE Disconnected state is %d, %s", newState, address);
-            g_connStateCB(CA_ADAPTER_GATT_BTLE, address, false);
-            OIC_LOG(DEBUG, TAG, "LE Disconnected state callback is called");
-        }
-
         if (LINK_LOSS == status || REMOTE_DISCONNECT == status)
         {
             if (!CAManagerIsInACDataList(env, jni_address))
@@ -550,12 +524,6 @@ Java_org_iotivity_ca_CaLeClientInterface_caManagerLeServicesDiscoveredCallback(J
             OIC_LOG(DEBUG, TAG, "AC list - the address is not set to AutoConnect");
         }
 
-        if (g_connStateCB)
-        {
-            g_connStateCB(CA_ADAPTER_GATT_BTLE, address, true);
-            OIC_LOG(DEBUG, TAG, "LE Connected callback is called");
-        }
-
         (*env)->ReleaseStringUTFChars(env, jni_address, address);
         (*env)->DeleteLocalRef(env, jni_address);
 
diff --git a/resource/csdk/connectivity/util/src/camanager/arduino/caleconnectionmanager.c b/resource/csdk/connectivity/util/src/camanager/arduino/caleconnectionmanager.c
deleted file mode 100644 (file)
index 33f7648..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/* ****************************************************************
- *
- * Copyright 2016 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-#include "camanagerleinterface.h"
-#include "cacommon.h"
-#include "logger.h"
-
-#define TAG "OIC_CA_MANAGER_AR_LE"
-
-static CAAdapterStateChangedCB g_adapterStateCB = NULL;
-static CAConnectionStateChangedCB g_connStateCB = NULL;
-
-void CASetLENetworkMonitorCallbacks(CAAdapterStateChangedCB adapterStateCB,
-                                    CAConnectionStateChangedCB connStateCB)
-{
-    OIC_LOG(DEBUG, TAG, "CASetLENetworkMonitorCallbacks");
-
-    g_adapterStateCB = adapterStateCB;
-    g_connStateCB = connStateCB;
-}
-
-CAResult_t CASetLEClientAutoConnectionDeviceInfo(const char * address)
-{
-    OIC_LOG(DEBUG, TAG, "CASetClientAutoConnectionDeviceInfo");
-    (void)address;
-    return CA_NOT_SUPPORTED;
-}
-
-CAResult_t CAUnsetLEClientAutoConnectionDeviceInfo(const char * address)
-{
-    OIC_LOG(DEBUG, TAG, "CAUnsetClientAutoConnectionDeviceInfo");
-    (void)address;
-    return CA_NOT_SUPPORTED;
-}
-
-void CAStartServerLEAdvertising()
-{
-    OIC_LOG(DEBUG, TAG, "CAStartServerLEAdvertising");
-}
-
-void CAStopServerLEAdvertising()
-{
-    OIC_LOG(DEBUG, TAG, "CAStopServerLEAdvertising");
-}
diff --git a/resource/csdk/connectivity/util/src/camanager/linux/caleconnectionmanager.c b/resource/csdk/connectivity/util/src/camanager/linux/caleconnectionmanager.c
deleted file mode 100644 (file)
index 98f336e..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/* ****************************************************************
- *
- * Copyright 2016 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-#include "camanagerleinterface.h"
-#include "cacommon.h"
-#include "logger.h"
-
-#define TAG "OIC_CA_MANAGER_LI_LE"
-
-static CAAdapterStateChangedCB g_adapterStateCB = NULL;
-static CAConnectionStateChangedCB g_connStateCB = NULL;
-
-void CASetLENetworkMonitorCallbacks(CAAdapterStateChangedCB adapterStateCB,
-                                    CAConnectionStateChangedCB connStateCB)
-{
-    OIC_LOG(DEBUG, TAG, "CASetLENetworkMonitorCallbacks");
-
-    g_adapterStateCB = adapterStateCB;
-    g_connStateCB = connStateCB;
-}
-
-CAResult_t CASetLEClientAutoConnectionDeviceInfo(const char * address)
-{
-    OIC_LOG(DEBUG, TAG, "CASetLEClientAutoConnectionDeviceInfo");
-    (void)address;
-    return CA_NOT_SUPPORTED;
-}
-
-CAResult_t CAUnsetLEClientAutoConnectionDeviceInfo(const char * address)
-{
-    OIC_LOG(DEBUG, TAG, "CAUnsetLEClientAutoConnectionDeviceInfo");
-    (void)address;
-    return CA_NOT_SUPPORTED;
-}
-
-void CAStartServerLEAdvertising()
-{
-    OIC_LOG(DEBUG, TAG, "CAStartServerLEAdvertising");
-}
-
-void CAStopServerLEAdvertising()
-{
-    OIC_LOG(DEBUG, TAG, "CAStopServerLEAdvertising");
-}
diff --git a/resource/csdk/connectivity/util/src/camanager/tizen/caleconnectionmanager.c b/resource/csdk/connectivity/util/src/camanager/tizen/caleconnectionmanager.c
deleted file mode 100644 (file)
index cc196f2..0000000
+++ /dev/null
@@ -1,144 +0,0 @@
-/* ****************************************************************
- *
- * Copyright 2016 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-#include <bluetooth.h>
-#include <bluetooth_type.h>
-#include <bluetooth_internal.h>
-
-#include "camanagerleinterface.h"
-#include "cacommon.h"
-#include "camessagehandler.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");
-    (void)address;
-    return CA_NOT_SUPPORTED;
-}
-
-CAResult_t CAUnsetLEClientAutoConnectionDeviceInfo(const char * address)
-{
-    OIC_LOG(DEBUG, TAG, "CAUnsetLEClientAutoConnectionDeviceInfo");
-    (void)address;
-    return CA_NOT_SUPPORTED;
-}
-
-static void CAManagerAdapterMonitorHandler(const CAEndpoint_t *info, CANetworkStatus_t status)
-{
-    if (CA_INTERFACE_DOWN == status)
-    {
-        if (info && g_adapterStateCB)
-        {
-            g_adapterStateCB(info->adapter, false);
-            OIC_LOG(DEBUG, TAG, "Pass the disabled adapter state to upper layer");
-        }
-    }
-    else if (CA_INTERFACE_UP == status)
-    {
-        if (info && g_adapterStateCB)
-        {
-            g_adapterStateCB(info->adapter, true);
-            OIC_LOG(DEBUG, TAG, "Pass the enabled adapter state to upper layer");
-        }
-    }
-}
-
-static void CAManagerConnectionMonitorHandler(CATransportAdapter_t adapter,
-                                              const char *remoteAddress, bool connected)
-{
-    (void)adapter;
-
-    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();
-        }
-    }
-}
index 83513f7..046ace4 100644 (file)
 #include "camanagerleinterface.h"
 #include "cabtpairinginterface.h"
 #include "cautilinterface.h"
-
+#include "cainterfacecontroller.h"
 #include "cacommon.h"
 #include "logger.h"
 
 #define TAG "OIC_CA_COMMON_UTILS"
 
+static CAAdapterStateChangedCB g_adapterStateCB = NULL;
+static CAConnectionStateChangedCB g_connStateCB = NULL;
+
+static void CAManagerAdapterMonitorHandler(CATransportAdapter_t adapter,
+                                           CANetworkStatus_t status)
+{
+    if (CA_INTERFACE_DOWN == status)
+    {
+        if (g_adapterStateCB)
+        {
+            g_adapterStateCB(adapter, false);
+            OIC_LOG(DEBUG, TAG, "Pass the disabled adapter state to upper layer");
+        }
+    }
+    else if (CA_INTERFACE_UP == status)
+    {
+        if (g_adapterStateCB)
+        {
+            g_adapterStateCB(adapter, true);
+            OIC_LOG(DEBUG, TAG, "Pass the enabled adapter state to upper layer");
+        }
+    }
+}
+
+static void CAManagerConnectionMonitorHandler(const CAEndpoint_t *info, bool isConnected)
+{
+    if (!info || !info->addr)
+    {
+        OIC_LOG(ERROR, TAG, "remoteAddress is NULL");
+        return;
+    }
+
+    if (isConnected)
+    {
+        if (g_connStateCB)
+        {
+            g_connStateCB(info->adapter, info->addr, isConnected);
+            OIC_LOG(DEBUG, TAG, "Pass the connected device info to upper layer");
+        }
+    }
+    else
+    {
+        if (g_connStateCB)
+        {
+            g_connStateCB(info->adapter, info->addr, isConnected);
+            OIC_LOG(DEBUG, TAG, "Pass the disconnected device info to upper layer");
+        }
+    }
+}
+
 CAResult_t CARegisterNetworkMonitorHandler(CAAdapterStateChangedCB adapterStateCB,
                                            CAConnectionStateChangedCB connStateCB)
 {
     OIC_LOG(DEBUG, TAG, "CARegisterNetworkMonitorHandler");
 
-#ifdef LE_ADAPTER
-    CASetLENetworkMonitorCallbacks(adapterStateCB, connStateCB);
-    return CA_STATUS_OK;
-#else
-    (void)adapterStateCB;
-    (void)connStateCB;
-    return CA_NOT_SUPPORTED;
-#endif
+    g_adapterStateCB = adapterStateCB;
+    g_connStateCB = connStateCB;
 
+    CASetNetworkMonitorCallbacks(CAManagerAdapterMonitorHandler,
+                                 CAManagerConnectionMonitorHandler);
+    return CA_STATUS_OK;
 }
 
 CAResult_t CASetAutoConnectionDeviceInfo(const char *address)
 {
     OIC_LOG(DEBUG, TAG, "CASetAutoConnectionDeviceInfo");
 
-#ifdef LE_ADAPTER
+#if defined(__ANDROID__) && defined(LE_ADAPTER)
     return CASetLEClientAutoConnectionDeviceInfo(address);
 #else
     (void)address;
@@ -59,7 +106,7 @@ CAResult_t CAUnsetAutoConnectionDeviceInfo(const char *address)
 {
     OIC_LOG(DEBUG, TAG, "CAUnsetAutoConnectionDeviceInfo");
 
-#ifdef LE_ADAPTER
+#if defined(__ANDROID__) && defined(LE_ADAPTER)
     return CAUnsetLEClientAutoConnectionDeviceInfo(address);
 #else
     (void)address;
index c6a4d02..95f3cd0 100644 (file)
@@ -85,13 +85,7 @@ OCStackResult HandleKeepAliveRequest(const CAEndpoint_t* endPoint,
  * API to handle the connected device for KeepAlive.
  * @return  Current Time.
  */
-void HandleKeepAliveConnCB(const CAEndpoint_t *endpoint);
-
-/**
- * API to handle the disconnected device for KeepAlive.
- * @return  Current Time.
- */
-void HandleKeepAliveDisconnCB(const CAEndpoint_t *endpoint);
+void HandleKeepAliveConnCB(const CAEndpoint_t *endpoint, bool isConnected);
 
 #ifdef __cplusplus
 } // extern "C"
index e8ce987..4061893 100644 (file)
@@ -2041,7 +2041,7 @@ OCStackResult OCInit1(OCMode mode, OCTransportFlags serverFlags, OCTransportFlag
     VERIFY_SUCCESS(result, OC_STACK_OK);
 
 #ifdef TCP_ADAPTER
-    CARegisterKeepAliveHandler(HandleKeepAliveConnCB, HandleKeepAliveDisconnCB);
+    CARegisterKeepAliveHandler(HandleKeepAliveConnCB);
 #endif
 
 #ifdef WITH_PRESENCE
index 8063f2b..c94bb85 100644 (file)
@@ -716,31 +716,31 @@ OCStackResult RemoveKeepAliveEntry(const CAEndpoint_t *endpoint)
     return OC_STACK_OK;
 }
 
-void HandleKeepAliveConnCB(const CAEndpoint_t *endpoint)
+void HandleKeepAliveConnCB(const CAEndpoint_t *endpoint, bool isConnected)
 {
     VERIFY_NON_NULL_NR(endpoint, FATAL);
 
-    OIC_LOG(DEBUG, TAG, "Received the connected device information from CA");
-
-    // Send discover message to find ping resource
-    OCCallbackData pingData = { .cb = PingRequestCallback };
-    OCDevAddr devAddr = { .adapter = OC_ADAPTER_TCP };
-    CopyEndpointToDevAddr(endpoint, &devAddr);
-
-    OCDoResource(NULL, OC_REST_DISCOVER, KEEPALIVE_RESOURCE_URI, &devAddr, NULL,
-                 OC_ADAPTER_TCP, OC_HIGH_QOS, &pingData, NULL, 0);
-}
-
-void HandleKeepAliveDisconnCB(const CAEndpoint_t *endpoint)
-{
-    VERIFY_NON_NULL_NR(endpoint, FATAL);
+    if (isConnected)
+    {
+        OIC_LOG(DEBUG, TAG, "Received the connected device information from CA");
 
-    OIC_LOG(DEBUG, TAG, "Received the disconnected device information from CA");
+        // Send discover message to find ping resource
+        OCCallbackData pingData = { .cb = PingRequestCallback };
+        OCDevAddr devAddr = { .adapter = OC_ADAPTER_TCP };
+        CopyEndpointToDevAddr(endpoint, &devAddr);
 
-    OCStackResult result = RemoveKeepAliveEntry(endpoint);
-    if(result != OC_STACK_OK)
+        OCDoResource(NULL, OC_REST_DISCOVER, KEEPALIVE_RESOURCE_URI, &devAddr, NULL,
+                     OC_ADAPTER_TCP, OC_HIGH_QOS, &pingData, NULL, 0);
+    }
+    else
     {
-        OIC_LOG(ERROR, TAG, "Failed to remove entry");
-        return;
+        OIC_LOG(DEBUG, TAG, "Received the disconnected device information from CA");
+
+        OCStackResult result = RemoveKeepAliveEntry(endpoint);
+        if(result != OC_STACK_OK)
+        {
+            OIC_LOG(ERROR, TAG, "Failed to remove entry");
+            return;
+        }
     }
 }
index 480df19..0b27415 100644 (file)
@@ -80,12 +80,12 @@ if env.get('SECURED') == '1':
             mediator_rich_test_env.PrependUnique(LIBS = ['tinydtls','ocprovision', 'ocpmapi'])
 
 mediator_rich_test_env.PrependUnique(LIBS = [
-    'oc',
-    'octbstack',
+    'coap',
+    'connectivity_abstraction',
     'oc_logger',
     'oc_logger_core',
-    'connectivity_abstraction',
-    'coap',
+    'octbstack',
+    'oc',
     'ESMediatorRich',
     gtest,
     gtest_main])
@@ -105,4 +105,4 @@ if env.get('TEST') == '1':
     target_os = env.get('TARGET_OS')
     if target_os == 'linux':
         from tools.scons.RunTest import *
-        run_test(mediator_rich_test_env, '', 'service/easy-setup/mediator/richsdk/unittests/mediator_richsdk_test')
\ No newline at end of file
+        run_test(mediator_rich_test_env, '', 'service/easy-setup/mediator/richsdk/unittests/mediator_richsdk_test')
index 22bd821..20516e4 100644 (file)
@@ -16,11 +16,11 @@ linux_sample_env.AppendUnique(CPPPATH = ['include'])
 linux_sample_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
 linux_sample_env.AppendUnique(CPPDEFINES = ['LINUX'])
 linux_sample_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
-linux_sample_env.AppendUnique(LIBS = ['oc'])
-linux_sample_env.AppendUnique(LIBS = ['octbstack'])
-linux_sample_env.AppendUnique(LIBS = ['libconnectivity_abstraction'])
 linux_sample_env.AppendUnique(LIBS = ['libcoap'])
+linux_sample_env.AppendUnique(LIBS = ['libconnectivity_abstraction'])
 linux_sample_env.AppendUnique(LIBS = ['liboc_logger'])
+linux_sample_env.AppendUnique(LIBS = ['octbstack'])
+linux_sample_env.AppendUnique(LIBS = ['oc'])
 linux_sample_env.AppendUnique(LIBS = ['pthread'])
 
 if env.get('SECURED') == '1':
@@ -36,4 +36,4 @@ if 'rt' in linux_sample_env.get('LIBS'):
 ######################################################################
 heightsensorapp = linux_sample_env.Program('HeightSensorApp', 'src/HeightSensorApp.cpp')
 Alias("heightsensorapp_sample", heightsensorapp)
-env.AppendTarget('heightsensorapp')
\ No newline at end of file
+env.AppendTarget('heightsensorapp')
index e1bd784..461103a 100644 (file)
@@ -77,11 +77,12 @@ if target_os not in ['windows', 'winrt']:
 
 ThingsManager_gtest_env.PrependUnique(LIBS = [
     'libTGMSDKLibrary',
-    'oc',
-    'octbstack',
+    'coap',
+    'connectivity_abstraction',
     'oc_logger',
     'oc_logger_core',
-    'connectivity_abstraction',
+    'oc',
+    'octbstack',
     gtest,
     gtest_main])
 
@@ -101,4 +102,4 @@ if env.get('TEST') == '1':
     if target_os == 'linux':
         from tools.scons.RunTest import *
         run_test(ThingsManager_gtest_env, '',
-                'service/things-manager/unittests/ThingsManagerTest')
\ No newline at end of file
+                'service/things-manager/unittests/ThingsManagerTest')