change asynccall Function to synccall function.
authorjaesick.shin <jaesick.shin@samsung.com>
Mon, 10 Oct 2016 04:10:43 +0000 (13:10 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 13 Oct 2016 00:44:12 +0000 (00:44 +0000)
this patch include,
1. change sync call about NSProviderSetConsumerTopic Function.
2. change sync call about NSProviderUnsetConsumerTopic Function.

second patch include,
modify invalid return value.

Change-Id: Ia73d6544489dd36f4612c97108ca488f76e038e3
Signed-off-by: jaesick.shin <jaesick.shin@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13001
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
service/notification/src/provider/NSProviderInterface.c
service/notification/src/provider/NSProviderTopic.c
service/notification/src/provider/NSProviderTopic.h

index ea574a93920b5bd841188ce3a589cd8b47f33e08..84c38098d8fff62d3e22a9accf1d0a79e8c42b74 100644 (file)
@@ -346,7 +346,7 @@ NSResult NSProviderRegisterTopic(const char * topicName)
     }
 
     NSTopicSyncResult topicSyncResult;
-    topicSyncResult.topicName = OICStrdup(topicName);
+    topicSyncResult.topicData = (void *) OICStrdup(topicName);
     topicSyncResult.condition = &nstopicCond;
     topicSyncResult.result = NS_OK;
     topicSyncResult.mutex = &nsInitMutex;
@@ -377,7 +377,7 @@ NSResult NSProviderUnregisterTopic(const char * topicName)
     }
 
     NSTopicSyncResult topicSyncResult;
-    topicSyncResult.topicName = OICStrdup(topicName);
+    topicSyncResult.topicData = (void *) OICStrdup(topicName);
     topicSyncResult.condition = &nstopicCond;
     topicSyncResult.result = NS_OK;
     topicSyncResult.mutex = &nsInitMutex;
@@ -389,7 +389,7 @@ NSResult NSProviderUnregisterTopic(const char * topicName)
         pthread_mutex_unlock(&nsInitMutex);
         return NS_FAIL;
     }
-    OICFree(topicSyncResult.topicName);
+    OICFree(topicSyncResult.topicData);
 
     pthread_mutex_unlock(&nsInitMutex);
     NS_LOG(DEBUG, "NSProviderDeleteTopics - OUT");
@@ -417,11 +417,18 @@ NSResult NSProviderSetConsumerTopic(const char * consumerId, const char * topicN
     OICStrcpy(topicSubData->id, NS_UUID_STRING_SIZE, consumerId);
     topicSubData->topicName = OICStrdup(topicName);
 
-    NSPushQueue(TOPIC_SCHEDULER, TASK_SUBSCRIBE_TOPIC, (void *)topicSubData);
+    NSTopicSyncResult topicSyncResult;
+    topicSyncResult.topicData = (void *) topicSubData;
+    topicSyncResult.condition = &nstopicCond;
+    topicSyncResult.result = NS_FAIL;
+    topicSyncResult.mutex = &nsInitMutex;
+
+    NSPushQueue(TOPIC_SCHEDULER, TASK_SUBSCRIBE_TOPIC, (void *)&topicSyncResult);
+    pthread_cond_wait(topicSyncResult.condition, &nsInitMutex);
 
     pthread_mutex_unlock(&nsInitMutex);
     NS_LOG(DEBUG, "NSProviderSelectTopics - OUT");
-    return NS_OK;
+    return topicSyncResult.result;
 }
 
 NSResult NSProviderUnsetConsumerTopic(const char * consumerId, const char * topicName)
@@ -445,9 +452,16 @@ NSResult NSProviderUnsetConsumerTopic(const char * consumerId, const char * topi
     OICStrcpy(topicSubData->id, NS_UUID_STRING_SIZE, consumerId);
     topicSubData->topicName = OICStrdup(topicName);
 
-    NSPushQueue(TOPIC_SCHEDULER, TASK_UNSUBSCRIBE_TOPIC, (void *)topicSubData);
+    NSTopicSyncResult topicSyncResult;
+    topicSyncResult.topicData = (void *) topicSubData;
+    topicSyncResult.condition = &nstopicCond;
+    topicSyncResult.result = NS_FAIL;
+    topicSyncResult.mutex = &nsInitMutex;
+
+    NSPushQueue(TOPIC_SCHEDULER, TASK_UNSUBSCRIBE_TOPIC, (void *)&topicSyncResult);
+    pthread_cond_wait(topicSyncResult.condition, &nsInitMutex);
 
     pthread_mutex_unlock(&nsInitMutex);
     NS_LOG(DEBUG, "NSProviderUnselectTopics - OUT");
-    return NS_OK;
+    return topicSyncResult.result;
 }
index e398e65acfe1b9179984ac8f67439cc1a3569c55..3037467c36984ee5eeda59046ccfcb4f681ef0ae 100644 (file)
@@ -444,31 +444,51 @@ void * NSTopicSchedule(void * ptr)
                 case TASK_SUBSCRIBE_TOPIC:\r
                 {\r
                     NS_LOG(DEBUG, "CASE TASK_SUBSCRIBE_TOPIC : ");\r
+                    NSTopicSyncResult * topicSyncResult = (NSTopicSyncResult *) node->taskData;\r
+                    pthread_mutex_lock(topicSyncResult->mutex);\r
                     NSCacheElement * newObj = (NSCacheElement *) OICMalloc(sizeof(NSCacheElement));\r
-                    if (newObj)\r
+                    NSCacheTopicSubData * subData =\r
+                            (NSCacheTopicSubData *) topicSyncResult->topicData;\r
+                    if (!newObj)\r
+                    {\r
+                        OICFree(subData->topicName);\r
+                        OICFree(subData);\r
+                        pthread_cond_signal(topicSyncResult->condition);\r
+                        pthread_mutex_unlock(topicSyncResult->mutex);\r
+                    }\r
+                    else\r
                     {\r
-                        newObj->data = node->taskData;\r
-                        newObj->next = NULL;\r
-                        if (NSProviderStorageWrite(consumerTopicList, newObj) == NS_OK)\r
+                        if (NSProviderStorageRead(registeredTopicList, subData->topicName))\r
                         {\r
-                            NSCacheTopicSubData * topicSubData =\r
-                                    (NSCacheTopicSubData *) node->taskData;\r
-                            NSSendTopicUpdationToConsumer(topicSubData->id);\r
+                            newObj->data = topicSyncResult->topicData;\r
+                            newObj->next = NULL;\r
+                            NSProviderStorageWrite(consumerTopicList, newObj);\r
+                            NSSendTopicUpdationToConsumer(subData->id);\r
+                            topicSyncResult->result = NS_OK;\r
                         }\r
-                    }
+                    }\r
+                    pthread_cond_signal(topicSyncResult->condition);\r
+                    pthread_mutex_unlock(topicSyncResult->mutex);\r
+
                 }\r
                     break;\r
                 case TASK_UNSUBSCRIBE_TOPIC:\r
                 {\r
-                    NS_LOG(DEBUG, "CASE TASK_SUBSCRIBE_TOPIC : ");\r
-                    NSCacheTopicSubData * topicSubData = (NSCacheTopicSubData *) node->taskData;\r
-                    if (NSProviderDeleteConsumerTopic(consumerTopicList,\r
-                            (NSCacheTopicSubData *) node->taskData) == NS_OK)\r
+                    NS_LOG(DEBUG, "CASE TASK_UNSUBSCRIBE_TOPIC : ");\r
+                    NSTopicSyncResult * topicSyncResult = (NSTopicSyncResult *) node->taskData;\r
+                    pthread_mutex_lock(topicSyncResult->mutex);\r
+                    NSCacheTopicSubData * topicSubData =\r
+                            (NSCacheTopicSubData *) topicSyncResult->topicData;\r
+                    if (NSProviderDeleteConsumerTopic(consumerTopicList, topicSubData) == NS_OK)\r
                     {\r
                         NSSendTopicUpdationToConsumer(topicSubData->id);\r
+                        topicSyncResult->result = NS_OK;\r
                     }\r
                     OICFree(topicSubData->topicName);\r
                     OICFree(topicSubData);\r
+                    pthread_cond_signal(topicSyncResult->condition);\r
+                    pthread_mutex_unlock(topicSyncResult->mutex);\r
+\r
                 }\r
                     break;\r
                 case TASK_REGISTER_TOPIC:\r
@@ -478,7 +498,7 @@ void * NSTopicSchedule(void * ptr)
 \r
                     pthread_mutex_lock(topicSyncResult->mutex);\r
                     topicSyncResult->result = NSRegisterTopic(\r
-                            (const char *) topicSyncResult->topicName);\r
+                            (const char *) topicSyncResult->topicData);\r
                     pthread_cond_signal(topicSyncResult->condition);\r
                     pthread_mutex_unlock(topicSyncResult->mutex);\r
                 }\r
@@ -489,7 +509,7 @@ void * NSTopicSchedule(void * ptr)
                     NSTopicSyncResult * topicSyncResult = (NSTopicSyncResult *) node->taskData;\r
                     pthread_mutex_lock(topicSyncResult->mutex);\r
                     topicSyncResult->result = NSUnregisterTopic(\r
-                            (const char *) topicSyncResult->topicName);\r
+                            (const char *) topicSyncResult->topicData);\r
                     pthread_cond_signal(topicSyncResult->condition);\r
                     pthread_mutex_unlock(topicSyncResult->mutex);\r
                 }\r
index c087a96c42d13d8c16c5c84c465492c5191d5ea2..f75a1f58c2a4d276e081bae8f31dc3340b2db85a 100644 (file)
@@ -38,7 +38,7 @@ typedef struct {
 typedef struct {\r
     pthread_cond_t * condition;\r
     pthread_mutex_t * mutex;\r
-    char * topicName;\r
+    void * topicData;\r
     NSResult result;\r
 } NSTopicSyncResult;\r
 \r