added the cpp interface to monitoring network status.
authorhyuna0213.jo <hyuna0213.jo@samsung.com>
Fri, 19 Feb 2016 00:27:25 +0000 (09:27 +0900)
committerJon A. Cruz <jonc@osg.samsung.com>
Thu, 25 Feb 2016 02:38:19 +0000 (02:38 +0000)
add new cpp interface to pass the changed network status
to application layer from CA.

Change-Id: Ib2867d22c7e65b223a0f39ce170bf259defa2719
Signed-off-by: hyuna0213.jo <hyuna0213.jo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5051
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
resource/include/CAManager.h [new file with mode: 0644]
resource/src/CAManager.cpp [new file with mode: 0644]
resource/src/SConscript

diff --git a/resource/include/CAManager.h b/resource/include/CAManager.h
new file mode 100644 (file)
index 0000000..0a69743
--- /dev/null
@@ -0,0 +1,58 @@
+/* ****************************************************************
+ *
+ * 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_H_
+#define CA_MANAGER_H_
+
+#include <OCApi.h>
+
+namespace OC
+{
+    /**
+    * This namespace contains the main entrance/functionality to monitoring network changes.
+    * It may be used with OC::CAManager::functionName. To set a custom callback function,
+    * the implementer must make a call to CAManager::setNetworkMonitorHandler.
+    */
+    namespace CAManager
+    {
+        // typedef to get adapter status changes from CA.
+        typedef std::function<void(OCTransportAdapter,
+                                   const std::string&, bool)> ConnectionChangedCallback;
+
+        // typedef to get connection status changes from CA.
+        typedef std::function<void(OCTransportAdapter, bool)> AdapterChangedCallback;
+
+        /**
+        * Set network monitoring handler.
+        * @param adapterHandler adapter state change handler to handle changes for
+        *                       any transport types.
+        * @param connectionHandler connection state change handler to handle changes for
+        *                          connection with remote devices.
+        * @return Returns ::OC_STACK_OK if success.
+        */
+        OCStackResult setNetworkMonitorHandler(AdapterChangedCallback adapterHandler,
+                                               ConnectionChangedCallback connectionHandler);
+    }
+}
+
+#endif // CA_MANAGER_H_
+
+
+
diff --git a/resource/src/CAManager.cpp b/resource/src/CAManager.cpp
new file mode 100644 (file)
index 0000000..cafcfa9
--- /dev/null
@@ -0,0 +1,75 @@
+/* ****************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+/**
+ * @file
+ *
+ * This file contains the implementation of classes and its members related
+ * to CAManager. Network changes status will be passed from CA to application.
+ */
+
+#include "OCApi.h"
+#include "CAManager.h"
+#include "cautilinterface.h"
+
+using namespace OC;
+
+namespace
+{
+        CAManager::AdapterChangedCallback g_adapterHandler = NULL;
+        CAManager::ConnectionChangedCallback g_connectionHandler = NULL;
+}
+
+void DefaultAdapterStateChangedHandler(CATransportAdapter_t adapter, bool enabled)
+{
+    if (g_adapterHandler)
+    {
+        g_adapterHandler((OCTransportAdapter) adapter, enabled);
+    }
+}
+
+void DefaultConnectionStateChangedHandler(CATransportAdapter_t adapter,
+                                          const char *remote_address, bool connected)
+{
+    if (g_connectionHandler)
+    {
+        g_connectionHandler((OCTransportAdapter) adapter, remote_address, connected);
+    }
+}
+
+OCStackResult CAManager::setNetworkMonitorHandler(AdapterChangedCallback adapterHandler,
+                                                  ConnectionChangedCallback connectionHandler)
+{
+    g_adapterHandler = adapterHandler;
+    g_connectionHandler = connectionHandler;
+
+    CAResult_t ret = CARegisterNetworkMonitorHandler(DefaultAdapterStateChangedHandler,
+                                                     DefaultConnectionStateChangedHandler);
+
+    switch (ret)
+    {
+        case CA_STATUS_OK:
+            return OC_STACK_OK;
+        case CA_NOT_SUPPORTED:
+            return OC_STACK_NOTIMPL;
+        default:
+            return OC_STACK_ERROR;
+    }
+}
index 7cdde7b..187341e 100644 (file)
@@ -37,12 +37,14 @@ oclib_env.AppendUnique(CPPPATH = [
                '../c_common/ocrandom/include',
                '../csdk/logger/include',
                '../oc_logger/include',
-               '../csdk/connectivity/lib/libcoap-4.1.1'
+               '../csdk/connectivity/lib/libcoap-4.1.1',
+               '../csdk/connectivity/api'
                ])
 
 oclib_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
 
 oclib_env.AppendUnique(LIBS = ['octbstack', 'oc_logger'])
+oclib_env.AppendUnique(LIBS = ['connectivity_abstraction'])
 
 target_os = env.get('TARGET_OS')
 if target_os == 'linux':
@@ -73,7 +75,8 @@ oclib_src = [
                'OCRepresentation.cpp',
                'InProcServerWrapper.cpp',
                'InProcClientWrapper.cpp',
-               'OCResourceRequest.cpp'
+               'OCResourceRequest.cpp',
+               'CAManager.cpp'
        ]
 
 oclib = oclib_env.SharedLibrary('oc', oclib_src)
@@ -106,6 +109,8 @@ oclib_env.UserInstallTargetHeader(header_dir + 'OCResource.h', 'resource', 'OCRe
 oclib_env.UserInstallTargetHeader(header_dir + 'OCResourceRequest.h', 'resource', 'OCResourceRequest.h')
 oclib_env.UserInstallTargetHeader(header_dir + 'OCResourceResponse.h', 'resource', 'OCResourceResponse.h')
 
+oclib_env.UserInstallTargetHeader(header_dir + 'CAManager.h', 'resource', 'CAManager.h')
+
 # Add Provisioning library
 if target_os in ['linux', 'android'] and env.get('SECURED') == '1':
         SConscript('../provisioning/SConscript')