#endif
/**
+ * this level depends on transmission time.
+ * unicast based UDP will be checked by caretransmission.
+ */
+typedef enum
+{
+ HIGH_SPEED = 0,
+ NORMAL_SPEED
+} CMSpeedLevel_t;
+
+typedef struct
+{
+ /** address for all **/
+ char addr[MAX_ADDR_STR_SIZE_CA];
+
+ /** adapter priority of all transmissions. **/
+ CATransportAdapter_t adapter;
+
+ /** level about speed of response. **/
+ CMSpeedLevel_t level;
+} CMConfigureInfo_t;
+
+/**
* Callback function type for connection status changes delivery.
* @param[out] info Remote endpoint information.
* @param[out] isConnected Current connection status info.
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
+ os.path.join(src_dir, 'btpairing' ,'android', 'cabtpairing.c')])
+
+env.AppendUnique(CA_SRC = [
+ os.path.join(src_dir, 'camanager', 'caconnectionmanager.c'),
+ os.path.join(src_dir, 'camanager', 'camanagerutil.c'),
+ os.path.join(src_dir, 'camanager', 'camessagearbiter.c'),
+ os.path.join(src_dir, 'camanager', 'capolicymanager.c')])
+
--- /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 common function for connection manager
+ */
+
+#ifndef CA_CONNECTIONMANAGER_H_
+#define CA_CONNECTIONMANAGER_H_
+
+#include <stdint.h>
+
+#include <coap/coap.h>
+#include "cathreadpool.h"
+#include "octhread.h"
+#include "uarraylist.h"
+#include "cacommon.h"
+#include "caprotocolmessage.h"
+#include "camessagehandler.h"
+#include "cautilinterface.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * Callback to send replaced data.
+ * @param[in] data send data.
+ */
+typedef void (*CASendThreadFunc)(CAData_t *data);
+
+/**
+ * Callback to notify received data from the remote endpoint.
+ * @param[in] data received data.
+ */
+typedef void (*CAReceiveThreadFunc)(CAData_t *data);
+
+/**
+ * Context of connection manager
+ */
+typedef struct
+{
+ /** send method for block data. **/
+ CASendThreadFunc sendThreadFunc;
+
+ /** callback function for received message. **/
+ CAReceiveThreadFunc receivedThreadFunc;
+
+ /** array list on which the thread is operating. **/
+ u_arraylist_t *dataList;
+
+ /** data list mutex for synchronization. **/
+ oc_mutex dataListMutex;
+
+ /** sender mutex for synchronization. **/
+ oc_mutex dataSenderMutex;
+} CAConnectionManagerContext_t;
+
+/**
+ * Initializes the connection manager context.
+ * @param[in] CASendThreadFunc function point to add data in send queue thread.
+ * @param[in] CAReceiveThreadFunc function point to add data in receive queue thread.
+ * @return ::CASTATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CAInitializeConnectionManager(CASendThreadFunc blockSendMethod,
+ CAReceiveThreadFunc receivedDataCallback);
+
+/**
+ * Terminate the connection manager context.
+ */
+void CATerminateConnectionManager();
+
+/**
+ * Initialize mutex.
+ * @return ::CASTATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CAInitConnectionManagerMutexVariables();
+
+/**
+ * Terminate mutex.
+ */
+void CATerminateConnectionManagerMutexVariables();
+
+/**
+ * Get request/response message to send.
+ */
+CAData_t* CAGetConnectionManagerMessageData(CAData_t *data);
+
+/**
+ * Start connection manager.
+ */
+void CAStartConnectionManagerService(CMConfigureInfo_t info);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif // CA_CONNECTIONMANAGER_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.
+ *
+ ******************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "caadapterutils.h"
+#include "cainterface.h"
+#include "camessagehandler.h"
+#include "caremotehandler.h"
+#include "oic_malloc.h"
+#include "oic_string.h"
+#include "octhread.h"
+#include "logger.h"
+#include "caadapterutils.h"
+
+#include "caconnectionmanager.h"
+#include "capolicymanager.h"
+
+#define TAG "OIC_CM"
+
+static oc_mutex g_threadCMConfigureMutex = NULL;
+
+// context for connection manager
+static CAConnectionManagerContext_t g_context = {.sendThreadFunc = NULL,
+ .receivedThreadFunc = NULL,
+ .dataList = NULL};
+
+void CAStartConnectionManagerService(CMConfigureInfo_t info)
+{
+ OIC_LOG(DEBUG, TAG, "CAStartConnectionManagerService");
+
+ oc_mutex_lock(g_threadCMConfigureMutex);
+ CMSetConfigure(info);
+ oc_mutex_unlock(g_threadCMConfigureMutex);
+}
+
+CAData_t* CAGetConnectionManagerMessageData(CAData_t *data)
+{
+ OIC_LOG(DEBUG, TAG, "CAGetConnectionManagerMessageData");
+
+ VERIFY_NON_NULL_RET(data, TAG, "data is null", NULL);
+
+ // TODO
+ // decide specific reqeust/response message
+
+ return data;
+}
+
+CAResult_t CAInitializeConnectionManager(CASendThreadFunc sendThreadFunc,
+ CAReceiveThreadFunc receivedThreadFunc)
+{
+ OIC_LOG(DEBUG, TAG, "CAInitializeConnectionManager");
+
+ if (!g_context.sendThreadFunc)
+ {
+ g_context.sendThreadFunc = sendThreadFunc;
+ }
+
+ if (!g_context.receivedThreadFunc)
+ {
+ g_context.receivedThreadFunc = receivedThreadFunc;
+ }
+
+ if (!g_context.dataList)
+ {
+ g_context.dataList = u_arraylist_create();
+ }
+
+ CAResult_t res = CAInitConnectionManagerMutexVariables();
+ if (CA_STATUS_OK != res)
+ {
+ u_arraylist_free(&g_context.dataList);
+ g_context.dataList = NULL;
+ OIC_LOG(ERROR, TAG, "init has failed");
+ }
+ return res;
+}
+
+void CATerminateConnectionManager()
+{
+ OIC_LOG(DEBUG, TAG, "CATerminateConnectionManager");
+
+ if (g_context.dataList)
+ {
+ // TODO
+ // Remove all of management data();
+ u_arraylist_free(&g_context.dataList);
+ }
+ CATerminateConnectionManagerMutexVariables();
+}
+
+CAResult_t CAInitConnectionManagerMutexVariables()
+{
+ if (!g_context.dataListMutex)
+ {
+ g_context.dataListMutex = oc_mutex_new();
+ if (!g_context.dataListMutex)
+ {
+ OIC_LOG(ERROR, TAG, "oc_mutex_new has failed");
+ return CA_STATUS_FAILED;
+ }
+ }
+
+ if (!g_context.dataSenderMutex)
+ {
+ g_context.dataSenderMutex = oc_mutex_new();
+ if (!g_context.dataSenderMutex)
+ {
+ OIC_LOG(ERROR, TAG, "oc_mutex_new has failed");
+ CATerminateConnectionManagerMutexVariables();
+ return CA_STATUS_FAILED;
+ }
+ }
+
+ if (NULL == g_threadCMConfigureMutex)
+ {
+ g_threadCMConfigureMutex = oc_mutex_new();
+ if (NULL == g_threadCMConfigureMutex)
+ {
+ OIC_LOG(ERROR, TAG, "oc_mutex_new has failed");
+ return CA_STATUS_FAILED;
+ }
+ }
+
+ return CA_STATUS_OK;
+}
+
+void CATerminateConnectionManagerMutexVariables()
+{
+ if (g_context.dataListMutex)
+ {
+ oc_mutex_free(g_context.dataListMutex);
+ g_context.dataListMutex = NULL;
+ }
+
+ if (g_context.dataSenderMutex)
+ {
+ oc_mutex_free(g_context.dataSenderMutex);
+ g_context.dataSenderMutex = NULL;
+ }
+
+ if (g_threadCMConfigureMutex)
+ {
+ oc_mutex_free(g_threadCMConfigureMutex);
+ g_threadCMConfigureMutex = NULL;
+ }
+}
--- /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.
+ *
+ ******************************************************************/
+
+#include "logger.h"
+#include "cathreadpool.h"
+#include "uarraylist.h"
+#include "octhread.h"
+
+#include "camanagerutil.h"
+
+#define TAG "OIC_CM_UTIL"
--- /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 common function for connection manager util
+ */
+
+#ifndef CA_MANAGER_UTIL_H_
+#define CA_MANAGER_UTIL_H_
+
+#include "logger.h"
+#include "cathreadpool.h"
+#include "uarraylist.h"
+#include "octhread.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif // CA_MANAGER_UTIL_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.
+ *
+ ******************************************************************/
+
+#include "logger.h"
+#include "cathreadpool.h"
+#include "octhread.h"
+
+#define TAG "OIC_CM_ARBITER"
--- /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 common function for connection manager arbiter
+ */
+
+#ifndef CA_CONNECTIONMANAGER_ARBITER_H_
+#define CA_CONNECTIONMANAGER_ARBITER_H_
+
+#include "logger.h"
+#include "cathreadpool.h"
+#include "octhread.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif // CA_CONNECTIONMANAGER_ARBITER_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.
+ *
+ ******************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "cathreadpool.h"
+#include "octhread.h"
+#include "uarraylist.h"
+#include "cacommon.h"
+#include "logger.h"
+
+#include "caconnectionmanager.h"
+#include "capolicymanager.h"
+
+#define TAG "OIC_CM_POLICY"
+
+static CMConfigureInfo_t g_configure = {.addr = NULL,
+ .adapter = CA_ADAPTER_IP,
+ .level = NORMAL_SPEED};
+
+void CMSetConfigure(CMConfigureInfo_t info)
+{
+ OIC_LOG(DEBUG, TAG, "CMSetConfigurePolicy");
+ OICStrcpy(g_configure.addr, sizeof(g_configure.addr), info.addr);
+ g_configure.adapter = info.adapter;
+ g_configure.level = info.level;
+}
+
+const char* CMGetTargetAddress()
+{
+ OIC_LOG(DEBUG, TAG, "CMGetTargetAddress");
+ return g_configure.addr;
+}
+
+CATransportAdapter_t CMGetAdapterType()
+{
+ OIC_LOG(DEBUG, TAG, "CMGetAdapterType");
+ return g_configure.adapter;
+}
+
+CMSpeedLevel_t CMGetSpeedOfResponseLevel()
+{
+ OIC_LOG(DEBUG, TAG, "CMGetSpeedOfResponseLevel");
+ return g_configure.level;
+}
--- /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 common function for policy manager
+ */
+
+#ifndef CA_POLICY_MANAGER_H_
+#define CA_POLICY_MANAGER_H_
+
+#include <stdint.h>
+
+#include "cathreadpool.h"
+#include "octhread.h"
+#include "uarraylist.h"
+#include "cacommon.h"
+#include "caconnectionmanager.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * Set connection manager configure.
+ * Target address and connectivity priority and speed level can be set in this method.
+ * @param[in] info configuration data for connection manager policy
+ */
+void CMSetConfigure(CMConfigureInfo_t info);
+
+/**
+ * get target address.
+ * @return address
+ */
+const char* CMGetTargetAddress();
+
+/**
+ * get Adapter Type of current priority.
+ * @return ::CATransportAdapter_t value.
+ */
+CATransportAdapter_t CMGetAdapterType();
+
+/**
+ * get speed of response level.
+ * @return ::CMSpeedLevel_t value.
+ */
+CMSpeedLevel_t CMGetSpeedOfResponseLevel();
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif // CA_POLICY_MANAGER_H_