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
{\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
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
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