--- /dev/null
+/* ****************************************************************
+ *
+ * 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_
+
+
+
--- /dev/null
+/* ****************************************************************
+ *
+ * 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;
+ }
+}
'../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':
'OCRepresentation.cpp',
'InProcServerWrapper.cpp',
'InProcClientWrapper.cpp',
- 'OCResourceRequest.cpp'
+ 'OCResourceRequest.cpp',
+ 'CAManager.cpp'
]
oclib = oclib_env.SharedLibrary('oc', oclib_src)
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')