NSDuplicateMessage copy logic not working(bug fixed).
authorjaesick.shin <jaesick.shin@samsung.com>
Thu, 26 May 2016 06:17:07 +0000 (15:17 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 26 May 2016 09:25:43 +0000 (09:25 +0000)
previosuly patch added NSMessage copy logic.
but, that is wrong condition. so copy is not working.

Change-Id: I68d1530d82dca36ec38863cb8b4c9ff14ef352fb
Signed-off-by: jaesick.shin <jaesick.shin@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8347
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/notification/examples/linux/notificationprovider.c
service/notification/src/common/NSUtil.c
service/notification/src/provider/NSProviderInterface.c
service/notification/src/provider/NSProviderNotification.c
service/notification/src/provider/NSProviderNotification.h
service/notification/src/provider/NSProviderResource.c
service/notification/src/provider/NSProviderResource.h
service/notification/src/provider/NSProviderScheduler.c
service/notification/src/provider/NSProviderScheduler.h

index 8dac9c0..481c04a 100644 (file)
@@ -122,7 +122,6 @@ int main()
                 char charID[100];\r
 \r
                 printf("id : %d\n", ++id);\r
-\r
                 printf("title : ");\r
 \r
                 gets(title);\r
index 7f074cf..a8443af 100755 (executable)
@@ -58,32 +58,34 @@ NSResult NSFreeMessage(NSMessage * obj)
 
 NSMessage * NSDuplicateMessage(NSMessage * copyMsg)
 {
+    NSMessage * newMsg = NULL;
+
     if(copyMsg == NULL)
     {
         NS_LOG(ERROR, "Copy Msg is NULL");
         return NULL;
     }
 
-    NSMessage * newMsg = (NSMessage *)OICMalloc(sizeof(NSMessage));
+    newMsg = (NSMessage *)OICMalloc(sizeof(NSMessage));
 
-    if (!copyMsg->mId)
+    if (copyMsg->mId)
     {
         newMsg->mId = OICStrdup(copyMsg->mId);
     }
 
-    if (!copyMsg->mTitle)
+    if (copyMsg->mTitle)
     {
         newMsg->mTitle = OICStrdup(copyMsg->mTitle);
     }
 
-    if (!copyMsg->mContentText)
+    if (copyMsg->mContentText)
     {
         newMsg->mContentText = OICStrdup(copyMsg->mContentText);
     }
 
-    if (!copyMsg->mSource)
+    if (copyMsg->mSource)
     {
-        newMsg->mSource = OICStrdup(copyMsg->mSource);
+       newMsg->mSource = OICStrdup(copyMsg->mSource);
     }
 
     return newMsg;
index 490e3dd..f875e2d 100644 (file)
 #include "NSProviderScheduler.h"\r
 #include "NSProviderListener.h"\r
 #include "NSCacheAdapter.h"\r
-#include "cautilinterface.h"\r
 #include "NSProviderSubscription.h"\r
 #include "NSProviderNotification.h"\r
+#include "NSProviderMemoryCache.h"\r
+#include "oic_malloc.h"\r
+#include "oic_string.h"\r
+#include "cautilinterface.h"\r
 \r
 bool initProvider = false;\r
 static NSSubscribeRequestCallback g_subscribeRequestCb = NULL;\r
 static NSSyncCallback g_syncCb = NULL;\r
-pthread_mutex_t NSCacheMutex;\r
+\r
+pthread_mutex_t nsInitMutex;\r
+\r
+void initializeMutex()\r
+{\r
+    static pthread_mutex_t initMutex = PTHREAD_MUTEX_INITIALIZER;\r
+    nsInitMutex = initMutex;\r
+}\r
 \r
 void NSRegisterSubscribeRequestCb(NSSubscribeRequestCallback subscribeRequestCb)\r
 {\r
@@ -64,26 +74,34 @@ NSResult NSStartProvider(NSAccessPolicy policy, NSSubscribeRequestCallback subsc
 {\r
     OIC_LOG(INFO, INTERFACE_TAG, "Notification Service Start Provider..");\r
     NS_LOG(DEBUG, "NSStartProvider - IN");\r
-    NSSetSubscriptionAcceptPolicy(policy);\r
+\r
+    initializeMutex();\r
+\r
+    pthread_mutex_lock(&nsInitMutex);\r
 \r
     if (!initProvider)\r
     {\r
         NS_LOG(DEBUG, "Init Provider");\r
         initProvider = true;\r
+        NSSetSubscriptionAcceptPolicy(policy);\r
+        NSRegisterSubscribeRequestCb(subscribeRequestCb);\r
+        NSRegisterSyncCb(syncCb);\r
+        CARegisterNetworkMonitorHandler(NSProviderAdapterStateListener,\r
+                NSProviderConnectionStateListener);\r
 \r
         NSSetList();\r
         NSInitScheduler();\r
         NSStartScheduler();\r
-    }\r
 \r
-    NSRegisterSubscribeRequestCb(subscribeRequestCb);\r
-    NSRegisterSyncCb(syncCb);\r
-\r
-    CARegisterNetworkMonitorHandler(NSProviderAdapterStateListener,\r
-            NSProviderConnectionStateListener);\r
+        NSPushQueue(DISCOVERY_SCHEDULER, TASK_START_PRESENCE, NULL);\r
+        NSPushQueue(DISCOVERY_SCHEDULER, TASK_REGISTER_RESOURCE, NULL);\r
+    }\r
+    else\r
+    {\r
+        NS_LOG(DEBUG, "Already started Notification Provider");\r
+    }\r
 \r
-    NSPushQueue(DISCOVERY_SCHEDULER, TASK_START_PRESENCE, NULL);\r
-    NSPushQueue(DISCOVERY_SCHEDULER, TASK_REGISTER_RESOURCE, NULL);\r
+    pthread_mutex_unlock(&nsInitMutex);\r
 \r
     NS_LOG(DEBUG, "NSStartProvider - OUT");\r
 \r
@@ -102,9 +120,14 @@ void NSSetList()
 NSResult NSStopProvider()\r
 {\r
     NS_LOG(DEBUG, "NSStopProvider - IN");\r
+\r
+    pthread_mutex_lock(&nsInitMutex);\r
+\r
     NSRegisterSubscribeRequestCb((NSSubscribeRequestCallback)NULL);\r
     NSRegisterSyncCb((NSSyncCallback)NULL);\r
     initProvider = false;\r
+\r
+    pthread_mutex_unlock(&nsInitMutex);\r
     NS_LOG(DEBUG, "NSStopProvider - OUT");\r
     return NS_OK;\r
 }\r
@@ -145,7 +168,6 @@ NSResult NSAccept(NSConsumer *consumer, bool accepted)
     {\r
         NS_LOG(DEBUG, "accepted is true - ALLOW");\r
         NSPushQueue(SUBSCRIPTION_SCHEDULER, TASK_SEND_ALLOW, consumer);\r
-\r
     }\r
     else\r
     {\r
@@ -183,7 +205,7 @@ void * NSResponseSchedule(void * ptr)
                     OCEntityHandlerRequest * request = (OCEntityHandlerRequest*)node->taskData;\r
                     NSConsumer consumer;\r
 \r
-                    consumer.mId = strdup(request->devAddr.addr);\r
+                    consumer.mId = OICStrdup(request->devAddr.addr);\r
                     int * obId = (int *) OICMalloc(sizeof(int));\r
                     *obId = request->obsInfo.obsId;\r
                     consumer.mUserData = obId;\r
@@ -203,12 +225,7 @@ void * NSResponseSchedule(void * ptr)
                 default:\r
                     OIC_LOG(INFO, INTERFACE_TAG, "Response to User");\r
 \r
-                    // TODO: NSSubscribeRequestCb\r
-\r
-                    // TODO: NSSyncCb\r
-\r
                     break;\r
-\r
             }\r
             OICFree(node);\r
         }\r
index f0a943f..46dcb81 100644 (file)
@@ -47,6 +47,7 @@ NSResult NSGetMessagePayload(NSMessage *msg, OCRepPayload** msgPayload)
     OCRepPayloadSetPropString(*msgPayload, NS_ATTRIBUTE_ID, msg->mId);
     OCRepPayloadSetPropString(*msgPayload, NS_ATTRIBUTE_TITLE, msg->mTitle);
     OCRepPayloadSetPropString(*msgPayload, NS_ATTRIBUTE_TEXT, msg->mContentText);
+    OCRepPayloadSetPropString(*msgPayload, NS_ATTRIBUTE_SOURCE, msg->mSource);
 
     NS_LOG(DEBUG, "NSGetMessagePayload - OUT");
     return NS_OK;
@@ -237,7 +238,7 @@ void * NSNotificationSchedule(void *ptr)
                 case TASK_SEND_NOTIFICATION:
                 {
                     NS_LOG(DEBUG, "CASE TASK_SEND_NOTIFICATION : ");
-                    NSMessage * nsMsg = node->taskData;
+                    NSMessage * nsMsg = (NSMessage *)node->taskData;
                     NSSendMessage(nsMsg);
                     break;
                 }
index f03516a..f9c0dac 100644 (file)
 #include "NSProviderSubscription.h"\r
 #include "oic_string.h"\r
 #include "oic_malloc.h"\r
+#include "NSUtil.h"\r
 \r
 NSCacheList * messageList;\r
 \r
 NSResult NSRegisterResource();\r
-\r
 NSResult NSInitMessageList();\r
-\r
 NSResult NSPutNotificationMessage(NSMessage *, OCResourceHandle *);\r
-\r
 NSResult NSSendNotificationMessage(NSMessage *);\r
 \r
-\r
 #endif /* _NS_PROVIDER_NOTIFICATION_H_ */\r
index a9a2111..85239a1 100644 (file)
@@ -180,10 +180,14 @@ NSResult NSPutMessageResource(NSMessage *msg, OCResourceHandle * handle)
 
     if(msg != NULL)
     {
-        NS_LOG(ERROR, "NSMessage is valid");
-        NotificationMessageResource.id = strdup(msg->mId);
-        NotificationMessageResource.title = strdup(msg->mTitle);
-        NotificationMessageResource.body = strdup(msg->mContentText);
+        NS_LOG(DEBUG, "NSMessage is valid");
+        NS_LOG_V(DEBUG, "msg -> mId : %s", msg->mId);
+        NS_LOG_V(DEBUG, "msg -> mTitle : %s", msg->mTitle);
+        NS_LOG_V(DEBUG, "msg -> mContentText : %s", msg->mContentText);
+
+        NotificationMessageResource.id = OICStrdup(msg->mId);
+        NotificationMessageResource.title = OICStrdup(msg->mTitle);
+        NotificationMessageResource.body = OICStrdup(msg->mContentText);
     }
     else
     {
index c2bf541..2f0d6ad 100644 (file)
@@ -25,6 +25,8 @@
 #include "logger.h"
 #include "NSCommon.h"
 #include "NSProviderListener.h"
+#include "oic_malloc.h"
+#include "oic_string.h"
 
 NSResult NSCreateResource(char *uri);
 
index 00b5968..8cac068 100755 (executable)
@@ -148,7 +148,7 @@ void NSPushQueue(NSSchedulerType schedulerType, NSTaskType taskType, void* data)
 \r
     if (NSHeadMsg[schedulerType] == NULL)\r
     {\r
-        NSHeadMsg[schedulerType] = (NSTask*) malloc(sizeof(NSTask));\r
+        NSHeadMsg[schedulerType] = (NSTask*) OICMalloc(sizeof(NSTask));\r
         memset(NSHeadMsg[schedulerType], 0, sizeof(NSTask));\r
         NSHeadMsg[schedulerType]->taskType = taskType;\r
         NSHeadMsg[schedulerType]->taskData = data;\r
@@ -157,7 +157,7 @@ void NSPushQueue(NSSchedulerType schedulerType, NSTaskType taskType, void* data)
     }\r
     else\r
     {\r
-        NSTask* newNode = (NSTask*) malloc(sizeof(NSTask));\r
+        NSTask* newNode = (NSTask*) OICMalloc(sizeof(NSTask));\r
         memset(newNode, 0, sizeof(NSTask));\r
         newNode->taskType = taskType;\r
         newNode->taskData = data;\r
index 6c9bf1d..8d89db5 100755 (executable)
 #include <stdio.h>\r
 #include <pthread.h>\r
 #include <semaphore.h>\r
-#include <oic_malloc.h>\r
 #include <stdbool.h>\r
 #include "ocstack.h"\r
 #include "NSCommon.h"\r
 #include "NSConstants.h"\r
 #include "NSStructs.h"\r
 #include "logger.h"\r
+#include "oic_malloc.h"\r
+#include "oic_string.h"\r
 \r
 extern NSTask* NSHeadMsg[THREAD_COUNT]; // Current MSG;\r
 extern NSTask* NSTailMsg[THREAD_COUNT]; // Recently MSG;\r