added the CA interface to monitoring network status.
authorjihwanseo <jihwan.seo@samsung.com>
Wed, 17 Feb 2016 10:29:44 +0000 (19:29 +0900)
committerJon A. Cruz <jonc@osg.samsung.com>
Wed, 24 Feb 2016 00:38:19 +0000 (00:38 +0000)
add new CA interface for network status changes delivery
to upper layer.

Change-Id: I2819b7dd0a31364554d6b90be4fe5b2dabf24d14
Signed-off-by: hyuna0213.jo <hyuna0213.jo@samsung.com>
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5019
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
resource/csdk/connectivity/api/cacommon.h
resource/csdk/connectivity/api/cautilinterface.h [new file with mode: 0644]
resource/csdk/connectivity/src/SConscript
resource/csdk/connectivity/src/camessagehandler.c
resource/csdk/connectivity/util/SConscript [new file with mode: 0644]
resource/csdk/connectivity/util/inc/camanagerleinterface.h [new file with mode: 0644]
resource/csdk/connectivity/util/src/camanager/android/caleconnectionmanager.c [new file with mode: 0644]
resource/csdk/connectivity/util/src/camanager/arduino/caleconnectionmanager.c [new file with mode: 0644]
resource/csdk/connectivity/util/src/camanager/linux/caleconnectionmanager.c [new file with mode: 0644]
resource/csdk/connectivity/util/src/camanager/tizen/caleconnectionmanager.c [new file with mode: 0644]
resource/csdk/connectivity/util/src/cautilinterface.c [new file with mode: 0644]

index ba1be2f..3ed6002 100644 (file)
@@ -552,6 +552,14 @@ typedef void (*CAResponseCallback)(const CAEndpoint_t *object,
 typedef void (*CAErrorCallback)(const CAEndpoint_t *object,
                                 const CAErrorInfo_t *errorInfo);
 
+/**
+ * Callback function type for network status changes delivery from CA common logic.
+ * @param[out]   info       Endpoint object from which the network status is changed.
+ *                          It contains endpoint address based on the connectivity type.
+ * @param[out]   status     Current network status info.
+ */
+typedef void (*CANetworkMonitorCallback)(const CAEndpoint_t *info, CANetworkStatus_t status);
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
diff --git a/resource/csdk/connectivity/api/cautilinterface.h b/resource/csdk/connectivity/api/cautilinterface.h
new file mode 100644 (file)
index 0000000..fb8c801
--- /dev/null
@@ -0,0 +1,64 @@
+/* ****************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#ifndef CA_UTILS_INTERFACE_H_
+#define CA_UTILS_INTERFACE_H_
+
+#include "cacommon.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * Callback function type for connection status changes delivery.
+ */
+typedef void (*CAConnectionStateChangedCB)(CATransportAdapter_t adapter,
+        const char *remote_address, bool connected);
+
+/**
+ * Callback function type for adapter status changes delivery.
+ * @param[out]   adapter    Transport type information.
+ * @param[out]   enabled    Current adapter status info.
+ */
+typedef void (*CAAdapterStateChangedCB)(CATransportAdapter_t adapter, bool enabled);
+
+/**
+ * Register network monitoring callback.
+ * Network status changes are delivered these callback.
+ * @param[in]   adapterStateCB  Adapter state monitoring callback.
+ * @param[in]   connStateCB     Connection state monitoring callback.
+ *
+ * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
+ */
+CAResult_t CARegisterNetworkMonitorHandler(CAAdapterStateChangedCB adapterStateCB,
+                                           CAConnectionStateChangedCB connStateCB);
+
+CAResult_t CASetAutoConnectionDeviceInfo(const char* address);
+
+CAResult_t CAUnsetAutoConnectionDeviceInfo(const char* address);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* CA_UTILS_INTERFACE_H_ */
+
index 6385cd7..f5f7f1b 100644 (file)
@@ -25,7 +25,8 @@ env.PrependUnique(CPPPATH = [ os.path.join(root_dir, 'api') ])
 env.AppendUnique(CPPPATH = [ os.path.join(root_dir, 'inc'),
                              os.path.join(root_dir, 'lib/libcoap-4.1.1'),
                              os.path.join(src_dir, '/resource/csdk/logger/include/'),
-                             os.path.join(root_dir, 'common/inc') ])
+                             os.path.join(root_dir, 'common/inc'),
+                             os.path.join(root_dir, 'util/inc') ])
 
 if ca_os not in ['arduino', 'windows', 'winrt']:
        env.AppendUnique(CPPDEFINES = ['WITH_POSIX'])
@@ -39,6 +40,9 @@ if ca_os in ['darwin','ios']:
 # Getting common source files
 env.SConscript('./../common/SConscript')
 
+# Getting util source files
+env.SConscript(root_dir + '/util/SConscript')
+
 # The tinydtls library is found in '#extlibs/tinydtls', where the '#'
 # is interpreted by SCons as the top-level iotivity directory where
 # the SConscruct file is found.
index c55d429..76a9e28 100644 (file)
@@ -66,6 +66,7 @@ static CARetransmission_t g_retransmissionContext;
 static CARequestCallback g_requestHandler = NULL;
 static CAResponseCallback g_responseHandler = NULL;
 static CAErrorCallback g_errorHandler = NULL;
+static CANetworkMonitorCallback g_nwMonitorHandler = NULL;
 
 static void CAErrorHandler(const CAEndpoint_t *endpoint,
                            const void *data, uint32_t dataLen,
@@ -813,9 +814,11 @@ static void CANetworkChangedCallback(const CAEndpoint_t *info, CANetworkStatus_t
 {
     (void)info;
     (void)status;
-    OIC_LOG(DEBUG, TAG, "IN");
 
-    OIC_LOG(DEBUG, TAG, "OUT");
+    if (g_nwMonitorHandler)
+    {
+        g_nwMonitorHandler(info, status);
+    }
 }
 
 void CAHandleRequestResponseCallbacks()
@@ -1017,6 +1020,11 @@ void CASetInterfaceCallbacks(CARequestCallback ReqHandler, CAResponseCallback Re
     g_errorHandler = errorHandler;
 }
 
+void CASetNetworkMonitorCallback(CANetworkMonitorCallback nwMonitorHandler)
+{
+    g_nwMonitorHandler = nwMonitorHandler;
+}
+
 CAResult_t CAInitializeMessageHandler()
 {
     CASetPacketReceivedCallback(CAReceivedPacketCallback);
diff --git a/resource/csdk/connectivity/util/SConscript b/resource/csdk/connectivity/util/SConscript
new file mode 100644 (file)
index 0000000..dc8e341
--- /dev/null
@@ -0,0 +1,36 @@
+#######################################################
+#      Build Common Util
+#######################################################
+
+Import('env')
+import os.path
+
+print "Reading util folder script"
+
+ca_os = env.get('TARGET_OS')
+ca_transport = env.get('TARGET_TRANSPORT')
+src_dir = env.get('SRC_DIR')
+root_dir = './../'
+src_dir = './../util/src/'
+
+env.PrependUnique(CPPPATH = [ os.path.join(root_dir, 'api') ])
+env.AppendUnique(CPPPATH = [ os.path.join(root_dir, 'inc'),
+                             os.path.join(root_dir, 'lib/libcoap-4.1.1'),
+                             os.path.join(src_dir, '/resource/csdk/logger/include/'),
+                             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(src_dir,'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')])
+
+    if ca_os == 'android':
+               env.AppendUnique(CA_SRC = [
+               os.path.join(src_dir,'camanager/android/caleconnectionmanager.c')])
\ No newline at end of file
diff --git a/resource/csdk/connectivity/util/inc/camanagerleinterface.h b/resource/csdk/connectivity/util/inc/camanagerleinterface.h
new file mode 100644 (file)
index 0000000..c9e1257
--- /dev/null
@@ -0,0 +1,66 @@
+/* ****************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#ifndef CA_MANAGER_LE_INF_H_
+#define CA_MANAGER_LE_INF_H_
+
+#include "cacommon.h"
+#include "cautilinterface.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * Register network monitor callbacks.
+ * Adapter state changes and network state changes are delivered these callbacks.
+ * @param[in]   adapterStateCB  Adapter state changed callback.
+ * @param[in]   connStateCB     Connection state changed callback.
+ */
+void CASetLENetworkMonitorCallbacks(CAAdapterStateChangedCB adapterStateCB,
+                                    CAConnectionStateChangedCB connStateCB);
+
+/**
+ * Set device information for auto connection.
+ */
+CAResult_t CASetLEClientAutoConnectionDeviceInfo();
+
+/**
+ * Unset device information to stop auto connection.
+ */
+CAResult_t CAUnsetLEClientAutoConnectionDeviceInfo();
+
+/**
+ * Start advertise to receive request for scanning or connecting.
+ */
+void CAStartServerLEAdvertising();
+
+/**
+ * Stop advertise to destroy advertiser.
+ */
+void CAStopServerLEAdvertising();
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* CA_MANAGER_LE_INF_H_ */
+
diff --git a/resource/csdk/connectivity/util/src/camanager/android/caleconnectionmanager.c b/resource/csdk/connectivity/util/src/camanager/android/caleconnectionmanager.c
new file mode 100644 (file)
index 0000000..0660579
--- /dev/null
@@ -0,0 +1,61 @@
+/* ****************************************************************
+ *
+ * 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_AN_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");
+
+    return CA_NOT_SUPPORTED;
+}
+
+CAResult_t CAUnsetLEClientAutoConnectionDeviceInfo(const char* address)
+{
+    OIC_LOG(DEBUG, TAG, "CAUnsetLEClientAutoConnectionDeviceInfo");
+
+    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/arduino/caleconnectionmanager.c b/resource/csdk/connectivity/util/src/camanager/arduino/caleconnectionmanager.c
new file mode 100644 (file)
index 0000000..772c7e2
--- /dev/null
@@ -0,0 +1,61 @@
+/* ****************************************************************
+ *
+ * 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");
+
+    return CA_NOT_SUPPORTED;
+}
+
+CAResult_t CAUnsetLEClientAutoConnectionDeviceInfo(const char * address)
+{
+    OIC_LOG(DEBUG, TAG, "CAUnsetClientAutoConnectionDeviceInfo");
+
+    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
new file mode 100644 (file)
index 0000000..6056097
--- /dev/null
@@ -0,0 +1,61 @@
+/* ****************************************************************
+ *
+ * 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");
+
+    return CA_NOT_SUPPORTED;
+}
+
+CAResult_t CAUnsetLEClientAutoConnectionDeviceInfo(const char * address)
+{
+    OIC_LOG(DEBUG, TAG, "CAUnsetLEClientAutoConnectionDeviceInfo");
+
+    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
new file mode 100644 (file)
index 0000000..5e09342
--- /dev/null
@@ -0,0 +1,61 @@
+/* ****************************************************************
+ *
+ * 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_TZ_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");
+
+    return CA_NOT_SUPPORTED;
+}
+
+CAResult_t CAUnsetLEClientAutoConnectionDeviceInfo(const char * address)
+{
+    OIC_LOG(DEBUG, TAG, "CAUnsetLEClientAutoConnectionDeviceInfo");
+
+    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/cautilinterface.c b/resource/csdk/connectivity/util/src/cautilinterface.c
new file mode 100644 (file)
index 0000000..97da4f9
--- /dev/null
@@ -0,0 +1,63 @@
+/* ****************************************************************
+ *
+ * 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 "cautilinterface.h"
+
+#include "cacommon.h"
+#include "logger.h"
+
+#define TAG "OIC_CA_UTIL_INF"
+
+CAResult_t CARegisterNetworkMonitorHandler(CAAdapterStateChangedCB adapterStateCB,
+                                           CAConnectionStateChangedCB connStateCB)
+{
+    OIC_LOG(DEBUG, TAG, "CARegisterNetworkMonitorHandler");
+
+#ifdef LE_ADAPTER
+    CASetLENetworkMonitorCallbacks(adapterStateCB, connStateCB);
+    return CA_STATUS_OK;
+#else
+    return CA_NOT_SUPPORTED;
+#endif
+
+}
+
+CAResult_t CASetAutoConnectionDeviceInfo(const char *address)
+{
+    OIC_LOG(DEBUG, TAG, "CASetAutoConnectionDeviceInfo");
+
+#ifdef LE_ADAPTER
+    return CASetLEClientAutoConnectionDeviceInfo(address);
+#else
+    return CA_NOT_SUPPORTED;
+#endif
+}
+
+CAResult_t CAUnsetAutoConnectionDeviceInfo(const char *address)
+{
+    OIC_LOG(DEBUG, TAG, "CAUnsetAutoConnectionDeviceInfo");
+
+#ifdef LE_ADAPTER
+    return CAUnsetLEClientAutoConnectionDeviceInfo(address);
+#else
+    return CA_NOT_SUPPORTED;
+#endif
+}