Renamed submodule of Consumer. 13/8413/3
authorKIM JungYong <jyong2.kim@samsung.com>
Wed, 1 Jun 2016 08:02:00 +0000 (17:02 +0900)
committerUze Choi <uzchoi@samsung.com>
Fri, 3 Jun 2016 05:04:33 +0000 (05:04 +0000)
Listener, Notification, Subscription module is renamed.
(to NetworkEventListener, Communication, InternalTaskController)
wrapper of listening for response is removed.
some of variables, functions, structures is renamed.
fixed bug about mutex lock and unlock at creation of thread.
waitting time is added in the thread function at queue scheduler.

Change-Id: Id76d5b0d23c67ec8b31d7cd51aad9d544ea516c9
Signed-off-by: KIM JungYong <jyong2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8413
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
15 files changed:
service/notification/src/consumer/NSConsumerCommon.c
service/notification/src/consumer/NSConsumerCommon.h
service/notification/src/consumer/NSConsumerCommunication.c [moved from service/notification/src/consumer/NSConsumerNotification.c with 82% similarity]
service/notification/src/consumer/NSConsumerCommunication.h [moved from service/notification/src/consumer/NSConsumerNotification.h with 87% similarity]
service/notification/src/consumer/NSConsumerDiscovery.c
service/notification/src/consumer/NSConsumerDiscovery.h
service/notification/src/consumer/NSConsumerInterface.c
service/notification/src/consumer/NSConsumerInternalTaskController.c [moved from service/notification/src/consumer/NSConsumerSubsription.c with 98% similarity]
service/notification/src/consumer/NSConsumerInternalTaskController.h [moved from service/notification/src/consumer/NSConsumerSubsription.h with 93% similarity]
service/notification/src/consumer/NSConsumerNetworkEventListener.c [moved from service/notification/src/consumer/NSConsumerListener.c with 73% similarity]
service/notification/src/consumer/NSConsumerNetworkEventListener.h [moved from service/notification/src/consumer/NSConsumerListener.h with 100% similarity]
service/notification/src/consumer/NSConsumerQueueScheduler.c [moved from service/notification/src/consumer/NSConsumerMessageHandler.c with 87% similarity]
service/notification/src/consumer/NSConsumerQueueScheduler.h [moved from service/notification/src/consumer/NSConsumerMessageHandler.h with 100% similarity]
service/notification/src/consumer/NSThread.c
service/notification/src/consumer/NSThread.h

index e5ed593..7ad36f7 100644 (file)
@@ -58,7 +58,7 @@ NSProviderDiscoveredCallback NSGetDiscoverCb()
     return * NSGetBoneDiscoverCb();
 }
 
-void * NSDiscoverdProviderFunc(void * provider)
+void * NSDiscoveredProviderFunc(void * provider)
 {
     NSGetDiscoverCb()((NSProvider *) provider);
 
@@ -67,7 +67,7 @@ void * NSDiscoverdProviderFunc(void * provider)
 
 void NSDiscoveredProvider(NSProvider * provider)
 {
-    if (!NSThreadInit(NSDiscoverdProviderFunc, (void *) provider))
+    if (!NSThreadInit(NSDiscoveredProviderFunc, (void *) provider))
     {
         NS_LOG(ERROR, "execute discovered provider callback fail");
         return;
@@ -163,23 +163,6 @@ void NSNotificationPost(NSProvider * provider, NSMessage * msg)
     }
 }
 
-onRIResponseListener * NSGetBoneResponseListener()
-{
-    static onRIResponseListener g_responseCb = NULL;
-
-    return & g_responseCb;
-}
-
-void NSSetResponseListener(onRIResponseListener cb)
-{
-    * NSGetBoneResponseListener() = cb;
-}
-
-onRIResponseListener NSGetResponseListener()
-{
-    return * NSGetBoneResponseListener();
-}
-
 NSTask * NSMakeTask(NSTaskType type, void * data)
 {
     NSTask * retTask = OICMalloc(sizeof(NSTask));
@@ -253,17 +236,17 @@ void NSRemoveMessage(NSMessage_consumer * msg)
     msg = NULL;
 }
 
-OCStackResult NSSendRequest(OCDoHandle * handle,
+OCStackResult NSInvokeRequest(OCDoHandle * handle,
         OCMethod method, const OCDevAddr * addr,
-        const char * queryUrl, OCPayload * payload, void * callback)
+        const char * queryUrl, OCPayload * payload,
+        void * callbackFunc, void * callbackData)
 {
     OCCallbackData cbdata;
 
-    cbdata.cb = NSGetResponseListener();
-    cbdata.context = callback;
+    cbdata.cb = callbackFunc;
+    cbdata.context = callbackData;
     cbdata.cd = NULL;
 
     return OCDoResource(handle, method, queryUrl, addr,
             payload, CT_DEFAULT, NS_QOS, &cbdata, NULL, 0);
 }
-
index ddc94a7..07ff1db 100644 (file)
@@ -41,8 +41,26 @@ extern "C" {
 
 #define NS_DISCOVER_QUERY "/oic/res?rt=oic.r.notification"
 
-typedef OCStackApplicationResult (*onRIResponseListener)(
-        void *, OCDoHandle, OCClientResponse *);
+#define NS_VERTIFY_NOT_NULL(obj, retVal) { if ((obj) == NULL) \
+    { \
+        NS_LOG_V(ERROR, "%s : obj is null", __func__); \
+        return (retVal); \
+    }}
+
+#define NS_VERTIFY_NOT_NULL_WITH_POST_CLEANING(obj, retVal, func) { \
+    if ((obj) == NULL) \
+    { \
+        NS_LOG_V(ERROR, "%s : obj is null", __func__); \
+        NS_LOG(ERROR, "execute deletion"); \
+        (func); \
+        return (retVal); \
+    }}
+
+#define NS_VERTIFY_STACK_OK(obj, retVal) { if ((obj) != OC_STACK_OK) \
+    { \
+        NS_LOG_V(ERROR, "%s : obj is not OC_STACK_OK", __func__); \
+        return (retVal); \
+    }}
 
 typedef enum
 {
@@ -78,9 +96,6 @@ void NSNotificationPost(NSProvider * provider, NSMessage * obj);
 void NSSetNotificationSyncCb(NSSyncCallback cb);
 void NSNotificationSync(NSProvider * provider, NSSync * sync);
 
-onRIResponseListener NSGetResponseListener();
-void NSSetResponseListener(onRIResponseListener cb);
-
 NSTask * NSMakeTask(NSTaskType, void *);
 
 NSResult NSConsumerPushEvent(NSTask *);
@@ -88,9 +103,10 @@ NSResult NSConsumerPushEvent(NSTask *);
 NSMessage_consumer * NSCopyMessage(NSMessage_consumer *);
 void NSRemoveMessage(NSMessage_consumer *);
 
-OCStackResult NSSendRequest(OCDoHandle * handle,
+OCStackResult NSInvokeRequest(OCDoHandle * handle,
         OCMethod method, const OCDevAddr * addr,
-        const char * queryUrl, OCPayload * payload, void * callback);
+        const char * queryUrl, OCPayload * payload,
+        void * callbackFunc, void * callbackData);
 
 #ifdef __cplusplus
 }
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
-#include "NSConsumerNotification.h"
-
 #include "NSConstants.h"
 #include "NSConsumerCommon.h"
+#include "NSConsumerCommunication.h"
 #include "oic_malloc.h"
 #include "oic_string.h"
 #include "ocpayload.h"
 
 const char NS_MESSAGE_ACCEPTANCE[] = "0000-0000-0000-0000";
 
-NSMessage_consumer * NSBuildOICNotification(OCClientResponse * clientResponse);
-NSSync * NSBuildOICNotificationSync(OCClientResponse * clientResponse);
+NSMessage_consumer * NSGetNSMessage(OCClientResponse * clientResponse);
+NSSync * NSGetNSSyncInfo(OCClientResponse * clientResponse);
 
-NSProvider * NSGetProvider(OCClientResponse * clientResponse);
+NSProvider * NSGetNSProvider(OCClientResponse * clientResponse);
 NSResult NSPushToCache(OCClientResponse * clientResponse, NSTaskType type);
 
 NSResult NSConsumerSubscribeProvider(NSProvider * provider)
 {
-    if (OC_STACK_OK != NSSendRequest(&(provider->messageHandle),
+    if (OC_STACK_OK != NSInvokeRequest(&(provider->messageHandle),
             OC_REST_OBSERVE, (OCDevAddr *) provider->mUserData,
-            provider->messageUri, NULL, NSConsumerNotificationListener))
+            provider->messageUri, NULL, NSConsumerMessageListener, NULL))
     {
         return NS_ERROR;
     }
 
-    if (OC_STACK_OK != NSSendRequest(&(provider->syncHandle),
+    if (OC_STACK_OK != NSInvokeRequest(&(provider->syncHandle),
             OC_REST_OBSERVE, (OCDevAddr *) provider->mUserData,
-            provider->syncUri, NULL, NSConsumerSyncListener))
+            provider->syncUri, NULL, NSConsumerSyncInfoListener, NULL))
     {
         return NS_ERROR;
     }
@@ -55,9 +54,7 @@ NSResult NSConsumerSubscribeProvider(NSProvider * provider)
 
 NSResult NSConsumerPostProvider(OCDevAddr * addr, OCPayload * payload, const char * uri)
 {
-
-    if (OC_STACK_OK != NSSendRequest(NULL, OC_REST_POST, addr,
-            uri, payload, NULL))
+    if (OC_STACK_OK != NSInvokeRequest(NULL, OC_REST_POST, addr, uri, payload, NULL, NULL))
     {
         return NS_ERROR;
     }
@@ -65,20 +62,24 @@ NSResult NSConsumerPostProvider(OCDevAddr * addr, OCPayload * payload, const cha
     return NS_OK;
 }
 
-OCStackApplicationResult NSConsumerSyncListener(
-        OCDoHandle handle, OCClientResponse * clientResponse)
+OCStackApplicationResult NSConsumerSyncInfoListener(
+        void * ctx, OCDoHandle handle, OCClientResponse * clientResponse)
 {
+    (void) ctx;
     (void) handle;
 
+    NS_VERTIFY_NOT_NULL(clientResponse, OC_STACK_KEEP_TRANSACTION);
+    NS_VERTIFY_STACK_OK(clientResponse->result, OC_STACK_KEEP_TRANSACTION);
+
     NSSync * newNoti = NULL;
-    NSProvider * provider = NSGetProvider(clientResponse);
+    NSProvider * provider = NSGetNSProvider(clientResponse);
     if (!provider)
     {
         NS_LOG(ERROR, "getting provider is failed");
         return OC_STACK_KEEP_TRANSACTION;
     }
 
-    newNoti = NSBuildOICNotificationSync(clientResponse);
+    newNoti = NSGetNSSyncInfo(clientResponse);
     if (!newNoti)
     {
         return OC_STACK_KEEP_TRANSACTION;
@@ -106,19 +107,23 @@ OCStackApplicationResult NSConsumerSyncListener(
     return OC_STACK_KEEP_TRANSACTION;
 }
 
-OCStackApplicationResult NSConsumerNotificationListener(
-        OCDoHandle handle, OCClientResponse * clientResponse)
+OCStackApplicationResult NSConsumerMessageListener(
+        void * ctx, OCDoHandle handle, OCClientResponse * clientResponse)
 {
+    (void) ctx;
     (void) handle;
 
-    NSProvider * provider = NSGetProvider(clientResponse);
+    NS_VERTIFY_NOT_NULL(clientResponse, OC_STACK_KEEP_TRANSACTION);
+    NS_VERTIFY_STACK_OK(clientResponse->result, OC_STACK_KEEP_TRANSACTION);
+
+    NSProvider * provider = NSGetNSProvider(clientResponse);
     if (!provider)
     {
         NS_LOG(ERROR, "getting provider is failed");
         return OC_STACK_KEEP_TRANSACTION;
     }
 
-    NSMessage_consumer * newNoti = NSBuildOICNotification(clientResponse);
+    NSMessage_consumer * newNoti = NSGetNSMessage(clientResponse);
     if (!newNoti)
     {
         return OC_STACK_KEEP_TRANSACTION;
@@ -149,7 +154,7 @@ OCStackApplicationResult NSConsumerNotificationListener(
 
 NSResult NSPushToCache(OCClientResponse * clientResponse, NSTaskType type)
 {
-    NSMessage_consumer * cachedNoti = NSBuildOICNotification(clientResponse);
+    NSMessage_consumer * cachedNoti = NSGetNSMessage(clientResponse);
     if (!cachedNoti)
     {
         return NS_ERROR;
@@ -166,7 +171,7 @@ NSResult NSPushToCache(OCClientResponse * clientResponse, NSTaskType type)
     return NS_OK;
 }
 
-NSMessage_consumer * NSBuildOICNotification(OCClientResponse * clientResponse)
+NSMessage_consumer * NSGetNSMessage(OCClientResponse * clientResponse)
 {
     if(!clientResponse->payload)
     {
@@ -210,7 +215,7 @@ NSMessage_consumer * NSBuildOICNotification(OCClientResponse * clientResponse)
     return retNoti;
 }
 
-NSSync * NSBuildOICNotificationSync(OCClientResponse * clientResponse)
+NSSync * NSGetNSSyncInfo(OCClientResponse * clientResponse)
 {
     if(!clientResponse->payload)
     {
@@ -249,7 +254,7 @@ NSSync * NSBuildOICNotificationSync(OCClientResponse * clientResponse)
     return retSync;
 }
 
-NSProvider * NSGetProvider(OCClientResponse * clientResponse)
+NSProvider * NSGetNSProvider(OCClientResponse * clientResponse)
 {
     NSProvider * newProvider = (NSProvider *)OICMalloc(sizeof(NSProvider));
     if (!newProvider)
@@ -36,9 +36,9 @@ void NSConsumerNotificationTaskProcessing(NSTask *);
 NSResult NSConsumerSubscribeProvider(NSProvider *);
 NSResult NSConsumerPostProvider(OCDevAddr *, OCPayload *, const char *);
 
-OCStackApplicationResult NSConsumerNotificationListener(OCDoHandle, OCClientResponse *);
+OCStackApplicationResult NSConsumerMessageListener(void *, OCDoHandle, OCClientResponse *);
 
-OCStackApplicationResult NSConsumerSyncListener(OCDoHandle, OCClientResponse *);
+OCStackApplicationResult NSConsumerSyncInfoListener(void *, OCDoHandle, OCClientResponse *);
 
 #ifdef __cplusplus
 }
index 2e44986..ee90226 100644 (file)
@@ -40,9 +40,14 @@ OCDoHandle * getPresenceHandle()
 }
 
 OCStackApplicationResult NSConsumerPresenceListener(
-        OCDoHandle handle, OCClientResponse * clientResponse)
+        void * ctx, OCDoHandle handle, OCClientResponse * clientResponse)
 {
+    (void) ctx;
     (void) handle;
+
+    NS_VERTIFY_NOT_NULL(clientResponse, OC_STACK_KEEP_TRANSACTION);
+    NS_VERTIFY_STACK_OK(clientResponse->result, OC_STACK_KEEP_TRANSACTION);
+
     NS_LOG_V(DEBUG, "Presence income : %s:%d",
             clientResponse->devAddr.addr, clientResponse->devAddr.port);
     NS_LOG_V(DEBUG, "Presence result : %d",
@@ -66,17 +71,22 @@ OCStackApplicationResult NSConsumerPresenceListener(
 
     else if (payload->trigger == OC_PRESENCE_TRIGGER_CREATE)
     {
-    NSSendRequest(NULL, OC_REST_DISCOVER, clientResponse->addr,
-            NS_DISCOVER_QUERY, NULL, NSProviderDiscoverListener);
+        NSInvokeRequest(NULL, OC_REST_DISCOVER, clientResponse->addr,
+            NS_DISCOVER_QUERY, NULL, NSProviderDiscoverListener, NULL);
     }
 
     return OC_STACK_KEEP_TRANSACTION;
 }
 
 OCStackApplicationResult NSProviderDiscoverListener(
-        OCDoHandle handle, OCClientResponse * clientResponse)
+        void * ctx, OCDoHandle handle, OCClientResponse * clientResponse)
 {
+    (void) ctx;
     (void) handle;
+
+    NS_VERTIFY_NOT_NULL(clientResponse, OC_STACK_KEEP_TRANSACTION);
+    NS_VERTIFY_STACK_OK(clientResponse->result, OC_STACK_KEEP_TRANSACTION);
+
     NS_LOG_V(DEBUG, "Discover income : %s:%d",
             clientResponse->devAddr.addr, clientResponse->devAddr.port);
     NS_LOG_V(DEBUG, "Discover result : %d",
@@ -99,9 +109,8 @@ OCStackApplicationResult NSProviderDiscoverListener(
     {
         if (!strcmp(resource->uri, NS_RESOURCE_URI))
         {
-            NSSendRequest(
-                    NULL, OC_REST_GET, clientResponse->addr,
-                    NS_RESOURCE_URI, NULL, NSIntrospectProvider);
+            NSInvokeRequest(NULL, OC_REST_GET, clientResponse->addr,
+                    NS_RESOURCE_URI, NULL, NSIntrospectProvider, NULL);
         }
         resource = resource->next;
     }
@@ -110,9 +119,14 @@ OCStackApplicationResult NSProviderDiscoverListener(
 }
 
 OCStackApplicationResult NSIntrospectProvider(
-        OCDoHandle handle, OCClientResponse * clientResponse)
+        void * ctx, OCDoHandle handle, OCClientResponse * clientResponse)
 {
+    (void) ctx;
     (void) handle;
+
+    NS_VERTIFY_NOT_NULL(clientResponse, OC_STACK_KEEP_TRANSACTION);
+    NS_VERTIFY_STACK_OK(clientResponse->result, OC_STACK_KEEP_TRANSACTION);
+
     int64_t accepter = 0;
 
     NS_LOG_V(DEBUG, "GET response income : %s:%d",
@@ -222,8 +236,8 @@ void NSConsumerDiscoveryTaskProcessing(NSTask * task)
     NS_LOG_V(DEBUG, "Receive Event : %d", (int)task->taskType);
     if (task->taskType == TASK_EVENT_CONNECTED || task->taskType == TASK_CONSUMER_REQ_DISCOVER)
     {
-        NSSendRequest(NULL, OC_REST_DISCOVER, NULL, NS_DISCOVER_QUERY,
-                NULL, NSProviderDiscoverListener);
+        NSInvokeRequest(NULL, OC_REST_DISCOVER, NULL, NS_DISCOVER_QUERY,
+                NULL, NSProviderDiscoverListener, NULL);
     }
     else
     {
index 8c0d695..01b3a25 100644 (file)
@@ -32,13 +32,13 @@ extern "C" {
 
 void NSConsumerDiscoveryTaskProcessing(NSTask *);
 
-OCStackApplicationResult NSConsumerPresenceListener(OCDoHandle, OCClientResponse *);
+OCStackApplicationResult NSConsumerPresenceListener(void *, OCDoHandle, OCClientResponse *);
 
 // for discover result
-OCStackApplicationResult NSProviderDiscoverListener(OCDoHandle, OCClientResponse *);
+OCStackApplicationResult NSProviderDiscoverListener(void *, OCDoHandle, OCClientResponse *);
 
 // for checking Permission
-OCStackApplicationResult NSIntrospectProvider(OCDoHandle, OCClientResponse *);
+OCStackApplicationResult NSIntrospectProvider(void *, OCDoHandle, OCClientResponse *);
 
 #ifdef __cplusplus
 }
index f5ced3d..abac627 100644 (file)
@@ -26,7 +26,7 @@
 #include "NSCommon.h"
 #include "NSConsumerCommon.h"
 #include "NSConstants.h"
-#include "NSConsumerMessageHandler.h"
+#include "NSConsumerQueueScheduler.h"
 #include "oic_malloc.h"
 
 // Public APIs
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
-#include "NSConsumerSubsription.h"
-
 #include "NSConstants.h"
 #include "NSConsumerCommon.h"
+#include "NSConsumerInternalTaskController.h"
 #include "NSStructs.h"
 
 #include "oic_malloc.h"
@@ -26,8 +26,8 @@ extern "C" {
 #endif // __cplusplus
 
 #include "NSStructs.h"
-#include "../common/NSStorageAdapter.h"
-#include "NSConsumerNotification.h"
+#include "NSStorageAdapter.h"
+#include "NSConsumerCommunication.h"
 
 void NSDestroyCacheList();
 
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
-#include "NSConsumerListener.h"
-
 #include <memory.h>
 #include <string.h>
 
 #include "NSConstants.h"
 #include "NSConsumerCommon.h"
-#include "payload_logging.h"
 #include "cautilinterface.h"
 
 #include "NSConsumerDiscovery.h"
+#include "NSConsumerNetworkEventListener.h"
 
 #define NS_PRESENCE_SUBSCRIBE_QUERY "coap://224.0.1.187:5683/oic/ad?rt=oic.r.notification"
 
-typedef OCStackApplicationResult(*onRIResponse)(OCDoHandle, OCClientResponse *);
-
-OCStackApplicationResult NSRIResponseListener(
-        void * ctx, OCDoHandle handle, OCClientResponse * clientResponse);
-
 void NSConnectionStateListener(CATransportAdapter_t adapter,
         const char *remote_address, bool connected);
 
@@ -44,8 +37,6 @@ void NSAdapterStateListener(CATransportAdapter_t adapter, bool enabled);
 
 NSResult NSConsumerListenerInit()
 {
-    NSSetResponseListener(NSRIResponseListener);
-
     // TODO replace with comment lines when enable network monitor of IP Adapter
     CARegisterNetworkMonitorHandler(NSAdapterStateListener, NSConnectionStateListener);
 //    if (CARegisterNetworkMonitorHandler(NSAdapterStateListener, NSConnectionStateListener)
@@ -54,15 +45,15 @@ NSResult NSConsumerListenerInit()
 //        return NS_ERROR;
 //    }
 
-    if (OC_STACK_OK != NSSendRequest(NULL, OC_REST_PRESENCE, NULL,
-            NS_PRESENCE_SUBSCRIBE_QUERY, NULL, NSConsumerPresenceListener))
+    if (OC_STACK_OK != NSInvokeRequest(NULL, OC_REST_PRESENCE, NULL,
+            NS_PRESENCE_SUBSCRIBE_QUERY, NULL, NSConsumerPresenceListener, NULL))
     {
         NS_LOG(ERROR, "Presence request fail");
         return NS_ERROR;
     }
 
-    if (OC_STACK_OK != NSSendRequest(NULL, OC_REST_DISCOVER, NULL,
-            NS_DISCOVER_QUERY, NULL, NSProviderDiscoverListener))
+    if (OC_STACK_OK != NSInvokeRequest(NULL, OC_REST_DISCOVER, NULL,
+            NS_DISCOVER_QUERY, NULL, NSProviderDiscoverListener, NULL))
     {
         NS_LOG(ERROR, "Discover request fail");
         return NS_ERROR;
@@ -71,28 +62,6 @@ NSResult NSConsumerListenerInit()
     return NS_OK;
 }
 
-OCStackApplicationResult NSRIResponseListener(
-        void * ctx, OCDoHandle handle, OCClientResponse * clientResponse)
-{
-    if (ctx == NULL)
-    {
-        NS_LOG(ERROR, "Callback is null");
-        return OC_STACK_DELETE_TRANSACTION;
-    }
-
-    if (clientResponse->result == OC_STACK_OK && clientResponse != NULL)
-    {
-        OIC_LOG_PAYLOAD(INFO, clientResponse->payload);
-        ((onRIResponse)ctx)(handle, clientResponse);
-    }
-    else
-    {
-        NS_LOG_V(ERROR, "result is not ok : %d", clientResponse->result);
-    }
-
-    return OC_STACK_KEEP_TRANSACTION;
-}
-
 void NSConnectionStateListener(CATransportAdapter_t adapter,
         const char *remote_address, bool connected)
 {
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
-#include "NSConsumerMessageHandler.h"
-
 #include <stdlib.h>
 #include <stdbool.h>
+#include <unistd.h>
 
 #include "oic_malloc.h"
 
 #include "NSStructs.h"
 #include "NSConstants.h"
 #include "NSConsumerCommon.h"
+#include "NSConsumerCommunication.h"
 
 #include "NSThread.h"
 #include "NSConsumerQueue.h"
 
-#include "NSConsumerListener.h"
 #include "NSConsumerDiscovery.h"
+#include "NSConsumerInternalTaskController.h"
+#include "NSConsumerNetworkEventListener.h"
+#include "NSConsumerQueueScheduler.h"
 #include "NSConsumerSystem.h"
-#include "NSConsumerNotification.h"
-#include "NSConsumerSubsription.h"
 
 void * NSConsumerMsgHandleThreadFunc(void * handle);
 
@@ -44,13 +44,13 @@ void * NSConsumerMsgPushThreadFunc(void * data);
 
 void NSConsumerTaskProcessing(NSTask * task);
 
-NSThread ** NSGetMsgHandleThreadHandle()
+NSConsumerThread ** NSGetMsgHandleThreadHandle()
 {
-    static NSThread * handle = NULL;
+    static NSConsumerThread * handle = NULL;
     return & handle;
 }
 
-void NSSetMsgHandleThreadHandle(NSThread * handle)
+void NSSetMsgHandleThreadHandle(NSConsumerThread * handle)
 {
    *(NSGetMsgHandleThreadHandle()) = handle;
 }
@@ -68,7 +68,7 @@ void NSSetMsgHandleQueue(NSConsumerQueue * queue)
 
 NSResult NSConsumerMessageHandlerInit()
 {
-    NSThread * handle = NULL;
+    NSConsumerThread * handle = NULL;
     NSConsumerQueue * queue = NULL;
 
     if (NS_OK != NSConsumerListenerInit())
@@ -123,9 +123,9 @@ void * NSConsumerMsgHandleThreadFunc(void * threadHandle)
 {
     NSConsumerQueue * queue = NULL;
     NSConsumerQueueObject * obj = NULL;
-    NSThread * handle = (NSThread *) threadHandle;
+    NSConsumerThread * queueHandleThread = (NSConsumerThread *) threadHandle;
     NS_LOG(DEBUG, "created thread for consumer message handle");
-    if (!handle)
+    if (!queueHandleThread)
     {
         NS_LOG(ERROR, "thread handle is null");
         return NULL;
@@ -133,7 +133,7 @@ void * NSConsumerMsgHandleThreadFunc(void * threadHandle)
 
     while (true)
     {
-        if (!handle->isStarted)
+        if (!queueHandleThread->isStarted)
         {
             NS_LOG(ERROR, "msg handler thread will be terminated");
             break;
@@ -147,10 +147,11 @@ void * NSConsumerMsgHandleThreadFunc(void * threadHandle)
 
         if (NSIsQueueEmpty(queue))
         {
+            usleep(2000);
             continue;
         }
 
-        NSThreadLock(handle);
+        NSThreadLock(queueHandleThread);
         NS_LOG(DEBUG, "msg handler working");
         obj = NSPopQueue(queue);
 
@@ -159,7 +160,7 @@ void * NSConsumerMsgHandleThreadFunc(void * threadHandle)
             NSConsumerTaskProcessing((NSTask *)(obj->data));
         }
 
-        NSThreadUnlock(handle);
+        NSThreadUnlock(queueHandleThread);
 
     }
 
@@ -170,7 +171,7 @@ void * NSConsumerMsgPushThreadFunc(void * data)
 {
     NSConsumerQueueObject * obj = NULL;
     NSConsumerQueue * queue = NULL;
-    NSThread * msgHandleThread = *(NSGetMsgHandleThreadHandle());
+    NSConsumerThread * msgHandleThread = *(NSGetMsgHandleThreadHandle());
     if (!msgHandleThread)
     {
         NS_LOG(ERROR, "NSThreadHandle is null. can not insert to queue");
index aca5038..248bcb4 100644 (file)
 #include <memory.h>
 #include "oic_malloc.h"
 
-void NSDestroyThreadHandle(NSThread *);
+static pthread_mutex_t g_create_mutex;
 
-NSThread * NSThreadInit(NSThreadFunc func, void * data)
+void NSDestroyThreadHandle(NSConsumerThread *);
+
+NSConsumerThread * NSThreadInit(NSThreadFunc func, void * data)
 {
     if (!func)
     {
@@ -36,14 +38,16 @@ NSThread * NSThreadInit(NSThreadFunc func, void * data)
         return NULL;
     }
 
-    NSThread * handle = (NSThread *)OICMalloc(sizeof(NSThread));
+    pthread_mutex_init(&g_create_mutex, NULL);
+
+    NSConsumerThread * handle = (NSConsumerThread *)OICMalloc(sizeof(NSConsumerThread));
     if (!handle)
     {
         NS_LOG(ERROR, "thread allocation fail");
         return NULL;
     }
 
-    memset(handle, 0, sizeof(NSThread));
+    memset(handle, 0, sizeof(NSConsumerThread));
 
     pthread_mutexattr_init(&(handle->mutex_attr));
     if (pthread_mutexattr_settype(&(handle->mutex_attr), PTHREAD_MUTEX_RECURSIVE))
@@ -60,12 +64,7 @@ NSThread * NSThreadInit(NSThreadFunc func, void * data)
         return NULL;
     }
 
-    if (pthread_mutex_lock(&(handle->mutex)))
-    {
-        NS_LOG(ERROR, "thread mutex lock fail");
-        NSDestroyThreadHandle(handle);
-        return NULL;
-    }
+    pthread_mutex_lock(&g_create_mutex);
 
     handle->isStarted = true;
 
@@ -76,28 +75,27 @@ NSThread * NSThreadInit(NSThreadFunc func, void * data)
         NSDestroyThreadHandle(handle);
         return NULL;
     }
-
-    pthread_mutex_unlock(&(handle->mutex));
+    pthread_mutex_unlock(&g_create_mutex);
 
     return handle;
 }
 
-void NSThreadLock(NSThread * handle)
+void NSThreadLock(NSConsumerThread * handle)
 {
     pthread_mutex_lock(&(handle->mutex));
 }
 
-void NSThreadUnlock(NSThread * handle)
+void NSThreadUnlock(NSConsumerThread * handle)
 {
     pthread_mutex_unlock(&(handle->mutex));
 }
 
-void NSThreadStop(NSThread * handle)
+void NSThreadStop(NSConsumerThread * handle)
 {
     NSDestroyThreadHandle(handle);
 }
 
-void NSThreadJoin(NSThread * handle)
+void NSThreadJoin(NSConsumerThread * handle)
 {
        if (handle->thread_id)
        {
@@ -105,7 +103,7 @@ void NSThreadJoin(NSThread * handle)
        }
 }
 
-void NSDestroyThreadHandle(NSThread * handle)
+void NSDestroyThreadHandle(NSConsumerThread * handle)
 {
     handle->isStarted = false;
 
index e4d0bc3..1e1d7bb 100644 (file)
@@ -43,20 +43,21 @@ typedef struct
     pthread_t thread_id;
     pthread_mutex_t mutex;
     pthread_mutexattr_t mutex_attr;
-} NSThread;
+} NSConsumerThread;
+
 #endif
 
 typedef void *(*NSThreadFunc)(void *);
 
-NSThread * NSThreadInit(NSThreadFunc, void *);
+NSConsumerThread * NSThreadInit(NSThreadFunc, void *);
 
-void NSThreadLock(NSThread *);
+void NSThreadLock(NSConsumerThread *);
 
-void NSThreadUnlock(NSThread *);
+void NSThreadUnlock(NSConsumerThread *);
 
-void NSThreadJoin(NSThread *);
+void NSThreadJoin(NSConsumerThread *);
 
-void NSThreadStop(NSThread *);
+void NSThreadStop(NSConsumerThread *);
 
 #ifdef __cplusplus
 }