Add logic for NSIsTopicSubscribed.
authorjaesick.shin <jaesick.shin@samsung.com>
Thu, 18 Aug 2016 02:11:46 +0000 (11:11 +0900)
committerUze Choi <uzchoi@samsung.com>
Fri, 19 Aug 2016 04:36:44 +0000 (04:36 +0000)
this function is checking the each of consumer subscribe.

second patch included,
modify invalid types.

Change-Id: I2cb1adfc5af804ed59207244638985f5b67bd754
Signed-off-by: jaesick.shin <jaesick.shin@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10569
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Chihyun Cho <ch79.cho@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
service/notification/src/provider/NSProviderMemoryCache.c
service/notification/src/provider/NSProviderMemoryCache.h
service/notification/src/provider/NSProviderNotification.c
service/notification/src/provider/NSProviderTopic.c

index 2f1df89..1565016 100644 (file)
@@ -568,7 +568,7 @@ NSTopicLL * NSProviderGetConsumerTopicsCacheData(NSCacheList * conTopicList, cha
 \r
     while(iter)\r
     {\r
-        NSCacheTopicSubData * curr = (NSCacheTopicSubData)iter->data;\r
+        NSCacheTopicSubData * curr = (NSCacheTopicSubData *)iter->data;\r
 \r
         if(curr && strcmp(curr->id, consumerId) == 0)\r
         {\r
@@ -616,3 +616,30 @@ size_t NSProviderGetListSize(NSCacheElement * firstElement)
     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
+\r
+    if(!conTopicList || !cId || !topicName)\r
+    {\r
+        return false;\r
+        pthread_mutex_unlock(&NSCacheMutex);\r
+    }\r
+\r
+    NSCacheElement * iter = conTopicList;\r
+    while(iter)\r
+    {\r
+        NSCacheTopicSubData * curr = (NSCacheTopicSubData *) iter->data;\r
+\r
+        if( (strcmp(curr->id, cId) == 0) && (strcmp(curr->topicName, topicName) == 0) )\r
+        {\r
+            pthread_mutex_unlock(&NSCacheMutex);\r
+            return true;\r
+        }\r
+        iter = iter->next;\r
+    }\r
+\r
+    pthread_mutex_unlock(&NSCacheMutex);\r
+    return false;\r
+}\r
index a513fb4..0512fe6 100644 (file)
@@ -48,6 +48,8 @@ NSTopicLL * NSProviderGetConsumerTopicsCacheData(NSCacheList * conTopicList, cha
 \r
 size_t NSProviderGetListSize(NSCacheElement * firstElement);\r
 \r
+bool NSProviderIsTopicSubScribed(NSCacheElement * conTopicList, char * cId, char * topicName);\r
+\r
 pthread_mutex_t NSCacheMutex;\r
 pthread_mutexattr_t NSCacheMutexAttr;\r
 \r
index 7d42720..d3fbe8a 100644 (file)
@@ -108,8 +108,6 @@ NSResult NSSendNotification(NSMessage *msg)
         return NS_ERROR;
     }
 
-    NS_LOG_V(DEBUG, "this is topic message: %s", msg->topic);
-
     NSCacheElement * it = consumerSubList->head;
 
     while (it)
@@ -128,6 +126,8 @@ NSResult NSSendNotification(NSMessage *msg)
             {
                 if(msg->topic)
                 {
+                    NS_LOG_V(DEBUG, "this is topic message: %s", msg->topic);
+
                     if(NSIsTopicSubscribed(subData->id, msg->topic))
                     {
                         obArray[obCount++] = subData->messageObId;
index e54a97b..b17bbfe 100644 (file)
@@ -276,8 +276,7 @@ NSResult NSSendTopicList(OCEntityHandlerRequest * entityHandlerRequest)
 \r
 bool NSIsTopicSubscribed(char * consumerId, char * topic)\r
 {\r
-    //TODO: implement function\r
-    return true;\r
+    return NSProviderIsTopicSubScribed(consumerTopicList->head, consumerId, topic);\r
 }\r
 \r
 NSResult NSPostConsumerTopics(OCEntityHandlerRequest * entityHandlerRequest)\r