Modify logic for related topic.
authorjaesick.shin <jaesick.shin@samsung.com>
Tue, 30 Aug 2016 04:58:44 +0000 (13:58 +0900)
committerUze Choi <uzchoi@samsung.com>
Tue, 30 Aug 2016 10:01:56 +0000 (10:01 +0000)
this patch included,
1. Modify logic for NSSendTopicList.
2-1. change NSProviderTopicListSize to NSProviderGetTopicListSize.
2-2. and move NSProviderMemoryCache to NSProviderTopic.c
3. rename Function for NSProviderRegisterTopic.

Change-Id: I829435e5504b117f1f4d71453b5c9ca6ab02c511
Signed-off-by: jaesick.shin <jaesick.shin@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11101
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
service/notification/examples/linux/notificationprovider.c
service/notification/src/provider/NSProviderMemoryCache.c
service/notification/src/provider/NSProviderMemoryCache.h
service/notification/src/provider/NSProviderTopic.c

index 3454acb..cdf1f60 100644 (file)
@@ -255,10 +255,10 @@ int main()
 
             case 5:
                 printf("NSProviderAddTopic\n");
-                NSProivderRegisterTopic("OCF_TOPIC1");
-                NSProivderRegisterTopic("OCF_TOPIC2");
-                NSProivderRegisterTopic("OCF_TOPIC3");
-                NSProivderRegisterTopic("OCF_TOPIC4");
+                NSProviderRegisterTopic("OCF_TOPIC1");
+                NSProviderRegisterTopic("OCF_TOPIC2");
+                NSProviderRegisterTopic("OCF_TOPIC3");
+                NSProviderRegisterTopic("OCF_TOPIC4");
                 break;
 
             case 6:
index 712aa52..a03b9f8 100644 (file)
@@ -557,29 +557,6 @@ NSTopicLL * NSProviderGetConsumerTopicsCacheData(NSCacheList * regTopicList,
     return topics;\r
 }\r
 \r
-size_t NSProviderGetListSize(NSCacheElement * firstElement)\r
-{\r
-    pthread_mutex_lock(&NSCacheMutex);\r
-    if(!firstElement)\r
-    {\r
-        pthread_mutex_unlock(&NSCacheMutex);\r
-        return 0;\r
-    }\r
-\r
-    int cnt = 0;\r
-\r
-    NSCacheElement * iter = firstElement;\r
-\r
-    while(iter)\r
-    {\r
-        cnt++;\r
-        iter = iter->next;\r
-    }\r
-\r
-    pthread_mutex_unlock(&NSCacheMutex);\r
-    return cnt;\r
-}\r
-\r
 bool NSProviderIsTopicSubScribed(NSCacheElement * conTopicList, char * cId, char * topicName)\r
 {\r
     pthread_mutex_lock(&NSCacheMutex);\r
index 830d50f..5608870 100644 (file)
@@ -47,8 +47,6 @@ NSTopicLL * NSProviderGetTopicsCacheData(NSCacheList * regTopicList);
 NSTopicLL * NSProviderGetConsumerTopicsCacheData(NSCacheList * regTopicList,\r
         NSCacheList * conTopicList, char *consumerId);\r
 \r
-size_t NSProviderGetListSize(NSCacheElement * firstElement);\r
-\r
 bool NSProviderIsTopicSubScribed(NSCacheElement * conTopicList, char * cId, char * topicName);\r
 \r
 NSResult NSProviderDeleteConsumerTopic(NSCacheList * conTopicList,\r
index 015895f..8538550 100644 (file)
@@ -37,6 +37,26 @@ NSResult NSInitTopicList()
     return NS_OK;\r
 }\r
 \r
+size_t NSProviderGetTopicListSize(NSTopicLL * firstElement)\r
+{\r
+    if(!firstElement)\r
+    {\r
+        return 0;\r
+    }\r
+\r
+    int cnt = 0;\r
+\r
+    NSTopicLL * iter = firstElement;\r
+\r
+    while(iter)\r
+    {\r
+        cnt++;\r
+        iter = iter->next;\r
+    }\r
+\r
+    return cnt;\r
+}\r
+\r
 NSResult NSAddTopics(const char * topicName)\r
 {\r
     NS_LOG(DEBUG, "NSWriteTopicsToStorage()");\r
@@ -204,18 +224,20 @@ NSResult NSSendTopicList(OCEntityHandlerRequest * entityHandlerRequest)
     {\r
         NS_LOG(DEBUG, "Send registered topic list");\r
         topics = NSProviderGetTopicsCacheData(registeredTopicList);\r
-        currList = registeredTopicList->head;\r
     }\r
     else\r
     {\r
         NS_LOG(DEBUG, "Send subscribed topic list to consumer");\r
         topics = NSProviderGetConsumerTopicsCacheData(registeredTopicList, consumerTopicList, id);\r
-        currList = consumerTopicList->head;\r
+        if(!topics)\r
+        {\r
+            topics = NSProviderGetTopicsCacheData(registeredTopicList);\r
+        }\r
     }\r
 \r
-    if(!currList)\r
+    if(!topics)\r
     {\r
-        NS_LOG(DEBUG, "currList is NULL");\r
+        NS_LOG(DEBUG, "topicList is NULL");\r
         return NS_ERROR;\r
     }\r
 \r
@@ -233,10 +255,7 @@ NSResult NSSendTopicList(OCEntityHandlerRequest * entityHandlerRequest)
         return NS_ERROR;\r
     }\r
 \r
-    // set topics to the array of resource property\r
-\r
-    NSCacheElement * iter = currList;\r
-    size_t dimensionSize = (size_t)NSProviderGetListSize(iter);\r
+    size_t dimensionSize = (size_t)NSProviderGetTopicListSize(topics);\r
 \r
     NS_LOG_V(DEBUG, "dimensionSize = %d", dimensionSize);\r
 \r
@@ -249,19 +268,18 @@ NSResult NSSendTopicList(OCEntityHandlerRequest * entityHandlerRequest)
             sizeof(OCRepPayload *) * dimensionSize);\r
 \r
     size_t dimensions[3] = {dimensionSize, 0, 0};\r
+\r
     for (int i = 0; i < (int)dimensionSize; i++)\r
     {\r
-        NSTopicLL * topic = (NSTopicLL *) iter->data;\r
-\r
-        NS_LOG_V(DEBUG, "topicName = %s", topic->topicName);\r
-        NS_LOG_V(DEBUG, "topicState = %d",(int) topic->state);\r
+        NS_LOG_V(DEBUG, "topicName = %s", topics->topicName);\r
+        NS_LOG_V(DEBUG, "topicState = %d",(int) topics->state);\r
 \r
         payloadTopicArray[i] = OCRepPayloadCreate();\r
-        OCRepPayloadSetPropString(payloadTopicArray[i], NS_ATTRIBUTE_TOPIC_NAME, topic->topicName);\r
+        OCRepPayloadSetPropString(payloadTopicArray[i], NS_ATTRIBUTE_TOPIC_NAME, topics->topicName);\r
         OCRepPayloadSetPropInt(payloadTopicArray[i], NS_ATTRIBUTE_TOPIC_SELECTION,\r
-                (int)topic->state);\r
+                (int)topics->state);\r
 \r
-        iter = iter->next;\r
+        topics = topics->next;\r
     }\r
 \r
     OCRepPayloadSetUri(payload, NS_COLLECTION_TOPIC_URI);\r