ca_thread_pool_t threadPool;
CAIPPacketReceivedCallback packetReceivedCallback;
CAIPExceptionCallback exceptionCallback;
+ CAIPErrorHandleCallback IPErrorCallback;
} CAAdapterIPServerContext_t;
/**
static ca_mutex g_mutexServerInfoList = NULL;
/**
- * @var g_adapterEthServerContext
+ * @var g_adapterIPServerContext
* @brief Mutex to synchronize ethenet adapter context.
*/
-static CAAdapterIPServerContext_t *g_adapterEthServerContext = NULL;
+static CAAdapterIPServerContext_t *g_adapterIPServerContext = NULL;
/**
* @var g_mutexAdapterServerContext
OIC_LOG_V(ERROR, IP_SERVER_TAG, "Server socket shutdown sock fd[%d]", sd);
ca_mutex_lock(g_mutexAdapterServerContext);
// Notify upper layer this exception
- if (g_adapterEthServerContext->exceptionCallback)
+ if (g_adapterIPServerContext->exceptionCallback)
{
// need to make proper exception callback.
- //g_adapterEthServerContext->exceptionCallback(ctx->type);
+ //g_adapterIPServerContext->exceptionCallback(ctx->type);
}
ca_mutex_unlock(g_mutexAdapterServerContext);
}
{
ca_mutex_lock(g_mutexAdapterServerContext);
- if (g_adapterEthServerContext->packetReceivedCallback)
+ if (g_adapterIPServerContext->packetReceivedCallback)
{
- g_adapterEthServerContext->packetReceivedCallback(&ep,
+ g_adapterIPServerContext->packetReceivedCallback(&ep,
recvBuffer, recvLen);
}
ca_mutex_lock(g_mutexAdapterServerContext);
- if (!g_adapterEthServerContext)
+ if (!g_adapterIPServerContext)
{
- OIC_LOG(ERROR, IP_SERVER_TAG, "g_adapterEthServerContext NULL");
+ OIC_LOG(ERROR, IP_SERVER_TAG, "g_adapterIPServerContext NULL");
ca_mutex_unlock(g_mutexAdapterServerContext);
return CA_STATUS_FAILED;
}
if (1 == listLength) //Its first time.
{
g_packetHandlerStopFlag = false;
- if (CA_STATUS_OK != ca_thread_pool_add_task(g_adapterEthServerContext->threadPool,
+ if (CA_STATUS_OK != ca_thread_pool_add_task(g_adapterIPServerContext->threadPool,
CAReceiveHandler, NULL ))
{
OIC_LOG(ERROR, IP_SERVER_TAG, "thread_pool_add_task failed!");
}
ca_mutex_lock(g_mutexAdapterServerContext);
- g_adapterEthServerContext = (CAAdapterIPServerContext_t *) OICCalloc(1,
+ g_adapterIPServerContext = (CAAdapterIPServerContext_t *) OICCalloc(1,
sizeof(CAAdapterIPServerContext_t));
- if (!g_adapterEthServerContext)
+ if (!g_adapterIPServerContext)
{
OIC_LOG(ERROR, IP_SERVER_TAG, "Malloc failed");
ca_mutex_unlock(g_mutexAdapterServerContext);
return CA_MEMORY_ALLOC_FAILED;
}
- g_adapterEthServerContext->threadPool = threadPool;
+ g_adapterIPServerContext->threadPool = threadPool;
ca_mutex_unlock(g_mutexAdapterServerContext);
{
OIC_LOG(DEBUG, IP_SERVER_TAG, "IN");
ca_mutex_lock(g_mutexAdapterServerContext);
- if (!g_adapterEthServerContext)
+ if (!g_adapterIPServerContext)
{
- OIC_LOG(ERROR, IP_SERVER_TAG, "g_adapterEthServerContext NULL");
+ OIC_LOG(ERROR, IP_SERVER_TAG, "g_adapterIPServerContext NULL");
ca_mutex_unlock(g_mutexAdapterServerContext);
return;
}
- OICFree(g_adapterEthServerContext);
- g_adapterEthServerContext = NULL;
+ OICFree(g_adapterIPServerContext);
+ g_adapterIPServerContext = NULL;
ca_mutex_unlock(g_mutexAdapterServerContext);
VERIFY_NON_NULL(localAddress, IP_SERVER_TAG, "localAddress");
VERIFY_NON_NULL(port, IP_SERVER_TAG, "port");
- if (0 > *port)
- {
- OIC_LOG(ERROR, IP_SERVER_TAG, "Invalid input: port is invalid!");
- return CA_STATUS_INVALID_PARAM;
- }
-
ca_mutex_lock(g_mutexServerInfoList);
bool isUnicastServerStarted = CAIsUnicastServerStarted(g_serverInfoList, localAddress, *port);
if (!isUnicastServerStarted)
ca_mutex_lock(g_mutexAdapterServerContext);
- if (!g_adapterEthServerContext)
+ if (g_adapterIPServerContext)
{
- OIC_LOG(ERROR, IP_SERVER_TAG, "g_adapterEthServerContext NULL");
- ca_mutex_unlock(g_mutexAdapterServerContext);
- return;
+ g_adapterIPServerContext->packetReceivedCallback = callback;
+ }
+ else
+ {
+ OIC_LOG(ERROR, IP_SERVER_TAG, "g_adapterIPServerContext NULL");
+ }
+
+ ca_mutex_unlock(g_mutexAdapterServerContext);
+
+ OIC_LOG(DEBUG, IP_SERVER_TAG, "OUT");
+}
+
+void CAIPSetErrorHandleCallback(CAIPErrorHandleCallback ipErrorCallback)
+{
+ OIC_LOG(DEBUG, IP_SERVER_TAG, "IN");
+
+ ca_mutex_lock(g_mutexAdapterServerContext);
+
+ if (g_adapterIPServerContext)
+ {
+ g_adapterIPServerContext->IPErrorCallback = ipErrorCallback;
}
- g_adapterEthServerContext->packetReceivedCallback = callback;
ca_mutex_unlock(g_mutexAdapterServerContext);
OIC_LOG(DEBUG, IP_SERVER_TAG, "IN");
ca_mutex_lock(g_mutexAdapterServerContext);
- if (!g_adapterEthServerContext)
+ if (g_adapterIPServerContext)
{
- OIC_LOG(ERROR, IP_SERVER_TAG, "g_adapterEthServerContext NULL");
- ca_mutex_unlock(g_mutexAdapterServerContext);
- return;
+ g_adapterIPServerContext->exceptionCallback = callback;
+ }
+ else
+ {
+ OIC_LOG(ERROR, IP_SERVER_TAG, "g_adapterIPServerContext NULL");
}
- g_adapterEthServerContext->exceptionCallback = callback;
ca_mutex_unlock(g_mutexAdapterServerContext);