Signed-off-by: Hongkuk, Son <hongkuk.son@samsung.com>
Change-Id: Ief7e3ae9c8c4e11ab1f7f82d05b3879fc5afc0ef
+http://suprem.sec.samsung.net/jira/browse/CONPRO-1131
+
+commit_info_2017-11-14.txt
+
+commit_id: f8b740a6b97c456423747719284085dc21c8066f
+----------------------------------------------------------------------------------------------------------------------------------
http://suprem.sec.samsung.net/jira/browse/CONPRO-1124
commit_info_2017-11-08.txt
http://suprem.sec.samsung.net/jira/browse/CONPRO-1124
commit_info_2017-11-08.txt
#include "cainterface.h"
#include "caipinterface.h"
#include <coap/utlist.h>
#include "cainterface.h"
#include "caipinterface.h"
#include <coap/utlist.h>
#ifdef RA_ADAPTER
#include "caraadapter.h"
#ifdef RA_ADAPTER
#include "caraadapter.h"
static struct CANetworkCallback_t * g_networkChangeCallbackList = NULL;
/**
static struct CANetworkCallback_t * g_networkChangeCallbackList = NULL;
/**
+ * Mutex to synchronize network change list.
+ */
+static oc_mutex g_mutexNetCallbackList = NULL;
+
+/**
* network callback structure is handling
* for adapter state changed and connection state changed event.
*/
* network callback structure is handling
* for adapter state changed and connection state changed event.
*/
return CA_STATUS_INVALID_PARAM;
}
return CA_STATUS_INVALID_PARAM;
}
+ oc_mutex_lock(g_mutexNetCallbackList);
CANetworkCallback_t* callback = NULL;
LL_FOREACH(g_networkChangeCallbackList, callback)
{
if (callback && adapterCB == callback->adapter && connCB == callback->conn)
{
OIC_LOG(DEBUG, TAG, "this callback is already added");
CANetworkCallback_t* callback = NULL;
LL_FOREACH(g_networkChangeCallbackList, callback)
{
if (callback && adapterCB == callback->adapter && connCB == callback->conn)
{
OIC_LOG(DEBUG, TAG, "this callback is already added");
+ oc_mutex_unlock(g_mutexNetCallbackList);
if (NULL == callback)
{
OIC_LOG(ERROR, TAG, "Memory allocation failed during registration");
if (NULL == callback)
{
OIC_LOG(ERROR, TAG, "Memory allocation failed during registration");
+ oc_mutex_unlock(g_mutexNetCallbackList);
return CA_MEMORY_ALLOC_FAILED;
}
callback->adapter = adapterCB;
callback->conn = connCB;
LL_APPEND(g_networkChangeCallbackList, callback);
return CA_MEMORY_ALLOC_FAILED;
}
callback->adapter = adapterCB;
callback->conn = connCB;
LL_APPEND(g_networkChangeCallbackList, callback);
+ oc_mutex_unlock(g_mutexNetCallbackList);
OIC_LOG_V(INFO, TAG, "Added NetworkStateChanged Callback [%p]", callback);
return CA_STATUS_OK;
OIC_LOG_V(INFO, TAG, "Added NetworkStateChanged Callback [%p]", callback);
return CA_STATUS_OK;
{
OIC_LOG(DEBUG, TAG, "Remove NetworkStateChanged Callback");
{
OIC_LOG(DEBUG, TAG, "Remove NetworkStateChanged Callback");
+ oc_mutex_lock(g_mutexNetCallbackList);
CANetworkCallback_t* callback = NULL;
LL_FOREACH(g_networkChangeCallbackList, callback)
{
CANetworkCallback_t* callback = NULL;
LL_FOREACH(g_networkChangeCallbackList, callback)
{
{
OIC_LOG(DEBUG, TAG, "remove specific callback");
LL_DELETE(g_networkChangeCallbackList, callback);
{
OIC_LOG(DEBUG, TAG, "remove specific callback");
LL_DELETE(g_networkChangeCallbackList, callback);
+ oc_mutex_unlock(g_mutexNetCallbackList);
OICFree(callback);
return CA_STATUS_OK;
}
}
OICFree(callback);
return CA_STATUS_OK;
}
}
+ oc_mutex_unlock(g_mutexNetCallbackList);
+
static void CAAdapterChangedCallback(CATransportAdapter_t adapter, CANetworkStatus_t status)
{
static void CAAdapterChangedCallback(CATransportAdapter_t adapter, CANetworkStatus_t status)
{
+
+ oc_mutex_lock(g_mutexNetCallbackList);
// Call the callback.
CANetworkCallback_t* callback = NULL;
LL_FOREACH(g_networkChangeCallbackList, callback)
// Call the callback.
CANetworkCallback_t* callback = NULL;
LL_FOREACH(g_networkChangeCallbackList, callback)
OIC_LOG_V(INFO, TAG, "OUT application adapter changed callback [%p]", callback);
}
}
OIC_LOG_V(INFO, TAG, "OUT application adapter changed callback [%p]", callback);
}
}
+ oc_mutex_unlock(g_mutexNetCallbackList);
OIC_LOG_V(DEBUG, TAG, "[%d] adapter status is changed to [%d]", adapter, status);
}
#if defined(TCP_ADAPTER) || defined(EDR_ADAPTER) || defined(LE_ADAPTER)
static void CAConnectionChangedCallback(const CAEndpoint_t *info, bool isConnected)
{
OIC_LOG_V(DEBUG, TAG, "[%d] adapter status is changed to [%d]", adapter, status);
}
#if defined(TCP_ADAPTER) || defined(EDR_ADAPTER) || defined(LE_ADAPTER)
static void CAConnectionChangedCallback(const CAEndpoint_t *info, bool isConnected)
{
+ oc_mutex_lock(g_mutexNetCallbackList);
// Call the callback.
CANetworkCallback_t* callback = NULL;
LL_FOREACH(g_networkChangeCallbackList, callback)
// Call the callback.
CANetworkCallback_t* callback = NULL;
LL_FOREACH(g_networkChangeCallbackList, callback)
callback->conn(info, isConnected);
}
}
callback->conn(info, isConnected);
}
}
+ oc_mutex_unlock(g_mutexNetCallbackList);
OIC_LOG_V(DEBUG, TAG, "[%s] connection status is changed to [%d]", info->addr, isConnected);
}
#endif
OIC_LOG_V(DEBUG, TAG, "[%s] connection status is changed to [%d]", info->addr, isConnected);
}
#endif
+static void CADestroyMutex()
+{
+ if (g_mutexNetCallbackList)
+ {
+ oc_mutex_free(g_mutexNetCallbackList);
+ g_mutexNetCallbackList = NULL;
+ }
+}
+
+static CAResult_t CACreateMutex()
+{
+ if (!g_mutexNetCallbackList)
+ {
+ g_mutexNetCallbackList = oc_mutex_new();
+ if (!g_mutexNetCallbackList)
+ {
+ return CA_STATUS_FAILED;
+ }
+ }
+
+ return CA_STATUS_OK;
+}
+
void CAInitializeAdapters(ca_thread_pool_t handle, CATransportAdapter_t transportType)
{
OIC_LOG_V(DEBUG, TAG, "initialize adapters %d", transportType);
void CAInitializeAdapters(ca_thread_pool_t handle, CATransportAdapter_t transportType)
{
OIC_LOG_V(DEBUG, TAG, "initialize adapters %d", transportType);
+ if (CA_STATUS_OK != CACreateMutex())
+ {
+ OIC_LOG(ERROR, TAG, "Failed to create mutex!");
+ }
+
// Initialize ssl adapter.
#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
if (CA_STATUS_OK != CAinitSslAdapter())
// Initialize ssl adapter.
#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
if (CA_STATUS_OK != CAinitSslAdapter())
void CATerminateAdapters()
{
void CATerminateAdapters()
{
for (uint32_t index = 0; index < g_numberOfAdapters; index++)
{
if (g_adapterHandler[index].terminate != NULL)
for (uint32_t index = 0; index < g_numberOfAdapters; index++)
{
if (g_adapterHandler[index].terminate != NULL)
return len;
}
sendCounter++;
return len;
}
sendCounter++;
- OIC_LOG_V(WARNING, TAG, "send blocked. trying %n attempt from 100", sendCounter);
+ OIC_LOG_V(WARNING, TAG, "send blocked. trying %zu attempt from 100", sendCounter);
if(sendCounter >= 100)
{
return len;
if(sendCounter >= 100)
{
return len;