#include "logger.h"
#include "oic_malloc.h"
#include "cathreadpool.h" /* for thread pool */
-#include "camutex.h"
+#include "octhread.h"
#include "uarraylist.h"
#include "caadapterutils.h"
#include "org_iotivity_ca_CaEdrInterface.h"
/**
* Mutex to synchronize receive server.
*/
-static ca_mutex g_mutexReceiveServer = NULL;
+static oc_mutex g_mutexReceiveServer = NULL;
/**
* Flag to control the Receive Unicast Data Thread.
/**
* Mutex to synchronize accept server.
*/
-static ca_mutex g_mutexAcceptServer = NULL;
+static oc_mutex g_mutexAcceptServer = NULL;
/**
* Flag to control the Accept Thread.
/**
* Mutex to synchronize server socket.
*/
-static ca_mutex g_mutexServerSocket = NULL;
+static oc_mutex g_mutexServerSocket = NULL;
/**
* Flag to control the server socket.
/**
* Mutex to synchronize device state list.
*/
-static ca_mutex g_mutexStateList = NULL;
+static oc_mutex g_mutexStateList = NULL;
/**
* Mutex to synchronize device object list.
*/
-static ca_mutex g_mutexObjectList = NULL;
+static oc_mutex g_mutexObjectList = NULL;
/**
* Mutex to synchronize start server state.
*/
-static ca_mutex g_mutexStartServerState = NULL;
+static oc_mutex g_mutexStartServerState = NULL;
/**
* Thread context information for unicast, multicast and secured unicast server.
return;
}
- ca_mutex_lock(g_mutexServerSocket);
+ oc_mutex_lock(g_mutexServerSocket);
g_serverSocket = (*env)->NewGlobalRef(env, jni_obj_BTServerSocket);
- ca_mutex_unlock(g_mutexServerSocket);
+ oc_mutex_unlock(g_mutexServerSocket);
CAAdapterAcceptThreadContext_t *ctx = (CAAdapterAcceptThreadContext_t *) data;
// it should be initialized for restart accept thread
- ca_mutex_lock(g_mutexAcceptServer);
+ oc_mutex_lock(g_mutexAcceptServer);
g_stopAccept = false;
- ca_mutex_unlock(g_mutexAcceptServer);
+ oc_mutex_unlock(g_mutexAcceptServer);
while (true != *(ctx->stopFlag))
{
if (!CAEDRNativeIsEnableBTAdapter(env))
{
OIC_LOG(INFO, TAG, "BT adapter is not enabled");
- ca_mutex_lock(g_mutexAcceptServer);
+ oc_mutex_lock(g_mutexAcceptServer);
g_stopAccept = true;
- ca_mutex_unlock(g_mutexAcceptServer);
- ca_mutex_lock(g_mutexServerSocket);
+ oc_mutex_unlock(g_mutexAcceptServer);
+ oc_mutex_lock(g_mutexServerSocket);
g_serverSocket = NULL;
- ca_mutex_unlock(g_mutexServerSocket);
+ oc_mutex_unlock(g_mutexServerSocket);
}
else
{
return CA_STATUS_NOT_INITIALIZED;
}
- ca_mutex_lock(g_mutexStartServerState);
+ oc_mutex_lock(g_mutexStartServerState);
if (g_isStartServer)
{
OIC_LOG(DEBUG, TAG, "server already started");
- ca_mutex_unlock(g_mutexStartServerState);
+ oc_mutex_unlock(g_mutexStartServerState);
return CA_STATUS_OK;
}
- ca_mutex_unlock(g_mutexStartServerState);
+ oc_mutex_unlock(g_mutexStartServerState);
CAResult_t res = CAEDRServerStartAcceptThread();
if (CA_STATUS_OK == res)
CAEDRServerStop();
return CA_STATUS_FAILED;
}
- ca_mutex_lock(g_mutexStartServerState);
+ oc_mutex_lock(g_mutexStartServerState);
g_isStartServer = true;
- ca_mutex_unlock(g_mutexStartServerState);
+ oc_mutex_unlock(g_mutexStartServerState);
}
return res;
{
CAEDRStopReceiveThread();
- ca_mutex_lock(g_mutexAcceptServer);
+ oc_mutex_lock(g_mutexAcceptServer);
g_stopAccept = true;
- ca_mutex_unlock(g_mutexAcceptServer);
+ oc_mutex_unlock(g_mutexAcceptServer);
if (!g_jvm)
{
}
CAEDRNatvieCloseServerTask(env);
- ca_mutex_lock(g_mutexStartServerState);
+ oc_mutex_lock(g_mutexStartServerState);
g_isStartServer = false;
- ca_mutex_unlock(g_mutexStartServerState);
+ oc_mutex_unlock(g_mutexStartServerState);
if (isAttached)
{
{
if (g_mutexReceiveServer)
{
- ca_mutex_free(g_mutexReceiveServer);
+ oc_mutex_free(g_mutexReceiveServer);
g_mutexReceiveServer = NULL;
}
if (g_mutexAcceptServer)
{
- ca_mutex_free(g_mutexAcceptServer);
+ oc_mutex_free(g_mutexAcceptServer);
g_mutexAcceptServer = NULL;
}
if (g_mutexServerSocket)
{
- ca_mutex_free(g_mutexServerSocket);
+ oc_mutex_free(g_mutexServerSocket);
g_mutexServerSocket = NULL;
}
if (g_mutexStateList)
{
- ca_mutex_free(g_mutexStateList);
+ oc_mutex_free(g_mutexStateList);
g_mutexStateList = NULL;
}
if (g_mutexObjectList)
{
- ca_mutex_free(g_mutexObjectList);
+ oc_mutex_free(g_mutexObjectList);
g_mutexObjectList = NULL;
}
if (g_mutexStartServerState)
{
- ca_mutex_free(g_mutexStartServerState);
+ oc_mutex_free(g_mutexStartServerState);
g_mutexStartServerState = NULL;
}
}
static CAResult_t CAEDRServerCreateMutex()
{
- g_mutexReceiveServer = ca_mutex_new();
+ g_mutexReceiveServer = oc_mutex_new();
if (!g_mutexReceiveServer)
{
OIC_LOG(ERROR, TAG, "Failed to created mutex!");
return CA_STATUS_FAILED;
}
- g_mutexAcceptServer = ca_mutex_new();
+ g_mutexAcceptServer = oc_mutex_new();
if (!g_mutexAcceptServer)
{
OIC_LOG(ERROR, TAG, "Failed to created mutex!");
return CA_STATUS_FAILED;
}
- g_mutexServerSocket = ca_mutex_new();
+ g_mutexServerSocket = oc_mutex_new();
if (!g_mutexServerSocket)
{
OIC_LOG(ERROR, TAG, "Failed to created mutex!");
return CA_STATUS_FAILED;
}
- g_mutexStateList = ca_mutex_new();
+ g_mutexStateList = oc_mutex_new();
if (!g_mutexStateList)
{
OIC_LOG(ERROR, TAG, "Failed to created mutex!");
return CA_STATUS_FAILED;
}
- g_mutexObjectList = ca_mutex_new();
+ g_mutexObjectList = oc_mutex_new();
if (!g_mutexObjectList)
{
OIC_LOG(ERROR, TAG, "Failed to created mutex!");
return CA_STATUS_FAILED;
}
- g_mutexStartServerState = ca_mutex_new();
+ g_mutexStartServerState = oc_mutex_new();
if (!g_mutexStartServerState)
{
OIC_LOG(ERROR, TAG, "Failed to created mutex!");
(*env)->ReleaseStringUTFChars(env, jni_address, localAddress);
}
- ca_mutex_lock(g_mutexStateList);
+ oc_mutex_lock(g_mutexStateList);
CAEDRNativeCreateDeviceStateList();
- ca_mutex_unlock(g_mutexStateList);
+ oc_mutex_unlock(g_mutexStateList);
- ca_mutex_lock(g_mutexObjectList);
+ oc_mutex_lock(g_mutexObjectList);
CAEDRNativeCreateDeviceSocketList();
- ca_mutex_unlock(g_mutexObjectList);
+ oc_mutex_unlock(g_mutexObjectList);
if (isAttached)
{
}
ctx->stopFlag = &g_stopAccept;
- if (CA_STATUS_OK != ca_thread_pool_add_task(g_threadPoolHandle, CAAcceptHandler, (void *) ctx))
+ if (CA_STATUS_OK != ca_thread_pool_add_task(g_threadPoolHandle, CAAcceptHandler,
+ (void *) ctx, NULL))
{
OIC_LOG(ERROR, TAG, "Failed to create read thread!");
OICFree((void *) ctx);
{
OIC_LOG(DEBUG, TAG, "CAEDRStartReceiveThread");
- ca_mutex_lock(g_mutexReceiveServer);
+ oc_mutex_lock(g_mutexReceiveServer);
/**
* The task to listen for data from unicast is added to the thread pool.
if (!ctx)
{
OIC_LOG(ERROR, TAG, "Out of memory!");
- ca_mutex_unlock(g_mutexReceiveServer);
+ oc_mutex_unlock(g_mutexReceiveServer);
return CA_MEMORY_ALLOC_FAILED;
}
g_stopUnicast = false;
ctx->stopFlag = &g_stopUnicast;
ctx->type = isSecured ? CA_SECURED_UNICAST_SERVER : CA_UNICAST_SERVER;
- if (CA_STATUS_OK != ca_thread_pool_add_task(g_threadPoolHandle, CAReceiveHandler, (void *) ctx))
+ if (CA_STATUS_OK != ca_thread_pool_add_task(g_threadPoolHandle, CAReceiveHandler,
+ (void *) ctx, NULL))
{
OIC_LOG(ERROR, TAG, "Failed to create read thread!");
- ca_mutex_unlock(g_mutexReceiveServer);
+ oc_mutex_unlock(g_mutexReceiveServer);
OICFree((void *) ctx);
return CA_STATUS_FAILED;
}
- ca_mutex_unlock(g_mutexReceiveServer);
+ oc_mutex_unlock(g_mutexReceiveServer);
OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
{
OIC_LOG(DEBUG, TAG, "CAEDRStopReceiveThread");
- ca_mutex_lock(g_mutexReceiveServer);
+ oc_mutex_lock(g_mutexReceiveServer);
g_stopUnicast = true;
- ca_mutex_unlock(g_mutexReceiveServer);
+ oc_mutex_unlock(g_mutexReceiveServer);
return CA_STATUS_OK;
}
(*env)->ReleaseByteArrayElements(env, jbuf, buf, 0);
(*env)->DeleteLocalRef(env, jbuf);
- if (!deviceInfo->totalDataLen)
+ if (!deviceInfo->totalDataLen && deviceInfo->recvData)
{
coap_transport_t transport = coap_get_tcp_header_type_from_initbyte(
((unsigned char *) deviceInfo->recvData)[0] >> 4);
size_t headerLen = coap_get_tcp_header_length_for_transport(transport);
- if (deviceInfo->recvData && deviceInfo->recvDataLen >= headerLen)
+ if (deviceInfo->recvDataLen >= headerLen)
{
deviceInfo->totalDataLen = coap_get_total_message_length(deviceInfo->recvData,
deviceInfo->recvDataLen);
// update state to disconnect
// the socket will be close next read thread routine
- ca_mutex_lock(g_mutexStateList);
+ oc_mutex_lock(g_mutexStateList);
CAEDRUpdateDeviceState(STATE_DISCONNECTED, address);
- ca_mutex_unlock(g_mutexStateList);
+ oc_mutex_unlock(g_mutexStateList);
(*env)->ReleaseStringUTFChars(env, jni_str_address, address);
(*env)->DeleteLocalRef(env, jni_str_address);
return;
}
- ca_mutex_lock(g_mutexServerSocket);
+ oc_mutex_lock(g_mutexServerSocket);
g_serverSocket = (*env)->NewGlobalRef(env, jni_obj_BTServerSocket);
- ca_mutex_unlock(g_mutexServerSocket);
+ oc_mutex_unlock(g_mutexServerSocket);
}
jobject CAEDRNativeListen(JNIEnv *env)
OIC_LOG_V(INFO, TAG, "accept a new connection from [%s]", address);
// update state
- ca_mutex_lock(g_mutexStateList);
+ oc_mutex_lock(g_mutexStateList);
CAEDRUpdateDeviceState(STATE_CONNECTED, address);
- ca_mutex_unlock(g_mutexStateList);
+ oc_mutex_unlock(g_mutexStateList);
(*env)->ReleaseStringUTFChars(env, j_str_address, address);
(*env)->DeleteLocalRef(env, j_str_address);
return;
}
- ca_mutex_lock(g_mutexObjectList);
+ oc_mutex_lock(g_mutexObjectList);
CAEDRNativeAddDeviceSocketToList(env, jni_socket);
- ca_mutex_unlock(g_mutexObjectList);
+ oc_mutex_unlock(g_mutexObjectList);
(*env)->DeleteGlobalRef(env, jni_socket);
(*env)->DeleteLocalRef(env, jni_obj_BTSocket);