a couple of variables and function is renamed.
in particular, processing function of queue task in each submodules renamed
to TaskProcessing and thread structure is renamed to NSThread from NSThreadHandle.
and thread join function is added.
Change-Id: Id1508e3f6422318f316ee388cf195217d0823ebd
Signed-off-by: KIM JungYong <jyong2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8379
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
msg = NULL;
}
-OCStackResult NSRequestToResourceIntrospection(OCDoHandle * handle,
+OCStackResult NSSendRequest(OCDoHandle * handle,
OCMethod method, const OCDevAddr * addr,
const char * queryUrl, OCPayload * payload, void * callback)
{
NSMessage_consumer * NSCopyMessage(NSMessage_consumer *);
void NSRemoveMessage(NSMessage_consumer *);
-OCStackResult NSRequestToResourceIntrospection(OCDoHandle * handle,
+OCStackResult NSSendRequest(OCDoHandle * handle,
OCMethod method, const OCDevAddr * addr,
const char * queryUrl, OCPayload * payload, void * callback);
else if (payload->trigger == OC_PRESENCE_TRIGGER_CREATE)
{
- NSRequestToResourceIntrospection(NULL, OC_REST_DISCOVER, clientResponse->addr,
+ NSSendRequest(NULL, OC_REST_DISCOVER, clientResponse->addr,
NS_DISCOVER_QUERY, NULL, NSProviderDiscoverListener);
}
{
if (!strcmp(resource->uri, NS_RESOURCE_URI))
{
- NSRequestToResourceIntrospection(
+ NSSendRequest(
NULL, OC_REST_GET, clientResponse->addr,
- NS_RESOURCE_URI, NULL, NSGetProviderInformation);
+ NS_RESOURCE_URI, NULL, NSIntrospectProvider);
}
resource = resource->next;
}
return OC_STACK_KEEP_TRANSACTION;
}
-OCStackApplicationResult NSGetProviderInformation(
+OCStackApplicationResult NSIntrospectProvider(
OCDoHandle handle, OCClientResponse * clientResponse)
{
(void) handle;
return OC_STACK_KEEP_TRANSACTION;
}
-void NSConsumerDiscoveryHandleMsg(NSTask * task)
+void NSConsumerDiscoveryTaskProcessing(NSTask * task)
{
if (!task)
{
NS_LOG_V(DEBUG, "Receive Event : %d", (int)task->taskType);
if (task->taskType == TASK_EVENT_CONNECTED || task->taskType == TASK_CONSUMER_REQ_DISCOVER)
{
- NSRequestToResourceIntrospection(NULL, OC_REST_DISCOVER, NULL, NS_DISCOVER_QUERY,
+ NSSendRequest(NULL, OC_REST_DISCOVER, NULL, NS_DISCOVER_QUERY,
NULL, NSProviderDiscoverListener);
}
else
#include "ocstack.h"
#include "NSStructs.h"
-void NSConsumerDiscoveryHandleMsg(NSTask *);
+void NSConsumerDiscoveryTaskProcessing(NSTask *);
OCStackApplicationResult NSConsumerPresenceListener(OCDoHandle, OCClientResponse *);
OCStackApplicationResult NSProviderDiscoverListener(OCDoHandle, OCClientResponse *);
// for checking Permission
-OCStackApplicationResult NSGetProviderInformation(OCDoHandle, OCClientResponse *);
+OCStackApplicationResult NSIntrospectProvider(OCDoHandle, OCClientResponse *);
#ifdef __cplusplus
}
// return NS_ERROR;
// }
- if (OC_STACK_OK != NSRequestToResourceIntrospection(NULL, OC_REST_PRESENCE, NULL,
+ if (OC_STACK_OK != NSSendRequest(NULL, OC_REST_PRESENCE, NULL,
NS_PRESENCE_SUBSCRIBE_QUERY, NULL, NSConsumerPresenceListener))
{
NS_LOG(ERROR, "Presence request fail");
return NS_ERROR;
}
- if (OC_STACK_OK != NSRequestToResourceIntrospection(NULL, OC_REST_DISCOVER, NULL,
+ if (OC_STACK_OK != NSSendRequest(NULL, OC_REST_DISCOVER, NULL,
NS_DISCOVER_QUERY, NULL, NSProviderDiscoverListener))
{
NS_LOG(ERROR, "Discover request fail");
void * NSConsumerMsgPushThreadFunc(void * data);
-void NSConsumerHandleMsg(NSTask * task);
+void NSConsumerTaskProcessing(NSTask * task);
-NSThreadHandle ** NSGetMsgHandleThreadHandle()
+NSThread ** NSGetMsgHandleThreadHandle()
{
- static NSThreadHandle * handle = NULL;
+ static NSThread * handle = NULL;
return & handle;
}
-void NSSetMsgHandleThreadHandle(NSThreadHandle * handle)
+void NSSetMsgHandleThreadHandle(NSThread * handle)
{
*(NSGetMsgHandleThreadHandle()) = handle;
}
NSResult NSConsumerMessageHandlerInit()
{
- NSThreadHandle * handle = NULL;
+ NSThread * handle = NULL;
NSConsumerQueue * queue = NULL;
if (NS_OK != NSConsumerListenerInit())
{
NSConsumerQueue * queue = NULL;
NSConsumerQueueObject * obj = NULL;
- NSThreadHandle * handle = (NSThreadHandle *) threadHandle;
+ NSThread * handle = (NSThread *) threadHandle;
NS_LOG(DEBUG, "created thread for consumer message handle");
if (!handle)
{
continue;
}
- if (NSIsEmptyQueue(queue))
+ if (NSIsQueueEmpty(queue))
{
continue;
}
if (obj)
{
- NSConsumerHandleMsg((NSTask *)(obj->data));
+ NSConsumerTaskProcessing((NSTask *)(obj->data));
}
NSThreadUnlock(handle);
{
NSConsumerQueueObject * obj = NULL;
NSConsumerQueue * queue = NULL;
- NSThreadHandle * handle = *(NSGetMsgHandleThreadHandle());
- if (!handle)
+ NSThread * msgHandleThread = *(NSGetMsgHandleThreadHandle());
+ if (!msgHandleThread)
{
NS_LOG(ERROR, "NSThreadHandle is null. can not insert to queue");
return NULL;
obj->data = data;
obj->next = NULL;
- NSThreadLock(handle);
+ NSThreadLock(msgHandleThread);
queue = *(NSGetMsgHandleQueue());
if (!queue)
NSPushQueue(queue, obj);
}
- NSThreadUnlock(handle);
+ NSThreadUnlock(msgHandleThread);
return NULL;
}
-void NSConsumerHandleMsg(NSTask * task)
+void NSConsumerTaskProcessing(NSTask * task)
{
switch (task->taskType)
{
case TASK_EVENT_CONNECTED:
case TASK_CONSUMER_REQ_DISCOVER:
{
- NSConsumerDiscoveryHandleMsg(task);
+ NSConsumerDiscoveryTaskProcessing(task);
break;
}
case TASK_CONSUMER_REQ_SUBSCRIBE:
case TASK_SEND_READ:
case TASK_SEND_DISMISS:
{
- NSConsumerNotificationHandleMsg(task);
+ NSConsumerNotificationTaskProcessing(task);
break;
}
case TASK_RECV_READ:
case TASK_RECV_DISMISS:
case TASK_CONSUMER_RECV_NOTIFICATION:
{
- NSConsumerSubscriptionHandleMsg(task);
+ NSConsumerSubscriptionTaskProcessing(task);
break;
}
default:
NSResult NSConsumerSubscribeProvider(NSProvider * provider)
{
- if (OC_STACK_OK != NSRequestToResourceIntrospection(&(provider->messageHandle),
+ if (OC_STACK_OK != NSSendRequest(&(provider->messageHandle),
OC_REST_OBSERVE, (OCDevAddr *) provider->mUserData,
provider->messageUri, NULL, NSConsumerNotificationListener))
{
return NS_ERROR;
}
- if (OC_STACK_OK != NSRequestToResourceIntrospection(&(provider->syncHandle),
+ if (OC_STACK_OK != NSSendRequest(&(provider->syncHandle),
OC_REST_OBSERVE, (OCDevAddr *) provider->mUserData,
provider->syncUri, NULL, NSConsumerSyncListener))
{
NSResult NSConsumerPostProvider(OCDevAddr * addr, OCPayload * payload, const char * uri)
{
- if (OC_STACK_OK != NSRequestToResourceIntrospection(NULL, OC_REST_POST, addr,
+ if (OC_STACK_OK != NSSendRequest(NULL, OC_REST_POST, addr,
uri, payload, NULL))
{
return NS_ERROR;
return newProvider;
}
-void NSConsumerNotificationHandleMsg(NSTask * task)
+void NSConsumerNotificationTaskProcessing(NSTask * task)
{
if (!task)
{
#include "NSStructs.h"
#include "ocstack.h"
-void NSConsumerNotificationHandleMsg(NSTask *);
+void NSConsumerNotificationTaskProcessing(NSTask *);
NSResult NSConsumerSubscribeProvider(NSProvider *);
NSResult NSConsumerPostProvider(OCDevAddr *, OCPayload *, const char *);
return queue->size;
}
-bool NSIsEmptyQueue(NSConsumerQueue * queue)
+bool NSIsQueueEmpty(NSConsumerQueue * queue)
{
return (queue->size <= 0);
}
int NSGetQueueSize(NSConsumerQueue *);
-bool NSIsEmptyQueue(NSConsumerQueue *);
+bool NSIsQueueEmpty(NSConsumerQueue *);
#ifdef __cplusplus
}
return NS_OK;
}
-void NSConsumerSubscriptionHandleMsg(NSTask * task)
+void NSConsumerSubscriptionTaskProcessing(NSTask * task)
{
if (!task)
{
void NSDestroyCacheList();
-void NSConsumerSubscriptionHandleMsg(NSTask *);
+void NSConsumerSubscriptionTaskProcessing(NSTask *);
#ifdef __cplusplus
}
#include <memory.h>
#include "oic_malloc.h"
-void NSDestroyThreadHandle(NSThreadHandle *);
+void NSDestroyThreadHandle(NSThread *);
-NSThreadHandle * NSThreadInit(NSThreadFunc func, void * data)
+NSThread * NSThreadInit(NSThreadFunc func, void * data)
{
if (!func)
{
return NULL;
}
- NSThreadHandle * handle = (NSThreadHandle *)OICMalloc(sizeof(NSThreadHandle));
+ NSThread * handle = (NSThread *)OICMalloc(sizeof(NSThread));
if (!handle)
{
NS_LOG(ERROR, "thread allocation fail");
return NULL;
}
- memset(handle, 0, sizeof(NSThreadHandle));
+ memset(handle, 0, sizeof(NSThread));
pthread_mutexattr_init(&(handle->mutex_attr));
if (pthread_mutexattr_settype(&(handle->mutex_attr), PTHREAD_MUTEX_RECURSIVE))
return handle;
}
-void NSThreadLock(NSThreadHandle * handle)
+void NSThreadLock(NSThread * handle)
{
pthread_mutex_lock(&(handle->mutex));
}
-void NSThreadUnlock(NSThreadHandle * handle)
+void NSThreadUnlock(NSThread * handle)
{
pthread_mutex_unlock(&(handle->mutex));
}
-void NSThreadStop(NSThreadHandle * handle)
+void NSThreadStop(NSThread * handle)
{
NSDestroyThreadHandle(handle);
}
-void NSDestroyThreadHandle(NSThreadHandle * handle)
+void NSThreadJoin(NSThread * handle)
+{
+ if (handle->thread_id)
+ {
+ pthread_join(handle->thread_id, NULL);
+ }
+}
+
+void NSDestroyThreadHandle(NSThread * handle)
{
handle->isStarted = false;
- if (handle->thread_id)
- {
- pthread_join(handle->thread_id, NULL);
- }
+ NSThreadJoin(handle);
pthread_mutex_destroy(&(handle->mutex));
pthread_mutexattr_destroy(&(handle->mutex_attr));
pthread_t thread_id;
pthread_mutex_t mutex;
pthread_mutexattr_t mutex_attr;
-} NSThreadHandle;
+} NSThread;
#endif
typedef void *(*NSThreadFunc)(void *);
-NSThreadHandle * NSThreadInit(NSThreadFunc, void *);
+NSThread * NSThreadInit(NSThreadFunc, void *);
-void NSThreadLock(NSThreadHandle *);
+void NSThreadLock(NSThread *);
-void NSThreadUnlock(NSThreadHandle *);
+void NSThreadUnlock(NSThread *);
-void NSThreadStop(NSThreadHandle *);
+void NSThreadJoin(NSThread *);
+
+void NSThreadStop(NSThread *);
#ifdef __cplusplus
}