+ NS_LOG(DEBUG, "NSPostConsumerTopics() - IN");\r
+\r
+ char * consumerId = NULL;\r
+ OCRepPayload * payload = (OCRepPayload *) entityHandlerRequest->payload;\r
+ OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_CONSUMER_ID, &consumerId);\r
+\r
+ if (!consumerId)\r
+ {\r
+ NS_LOG(DEBUG, "Invalid consumer ID");\r
+ return NS_FAIL;\r
+ }\r
+\r
+ NS_LOG_V(DEBUG, "TOPIC consumer ID = %s", consumerId);\r
+\r
+ consumerTopicList->cacheType = NS_PROVIDER_CACHE_CONSUMER_TOPIC_CID;\r
+
+ while (NSProviderStorageDelete(consumerTopicList, consumerId) != NS_FAIL)\r
+ {\r
+ }\r
+ consumerTopicList->cacheType = NS_PROVIDER_CACHE_CONSUMER_TOPIC_NAME;\r
+\r
+ OCRepPayload ** topicListPayload = NULL;\r
+ OCRepPayloadValue * payloadValue = NULL;\r
+ payloadValue = NSPayloadFindValue(payload, NS_ATTRIBUTE_TOPIC_LIST);\r
+ size_t dimensionSize = calcDimTotal(payloadValue->arr.dimensions);\r
+ size_t dimensions[3] = { dimensionSize, 0, 0 };\r
+ OCRepPayloadGetPropObjectArray(payload, NS_ATTRIBUTE_TOPIC_LIST, &topicListPayload, dimensions);\r
+\r
+ for (int i = 0; i < (int) dimensionSize; i++)\r
+ {\r
+ char * topicName = NULL;\r
+ int64_t topicState = 0;\r
+\r
+ OCRepPayloadGetPropString(topicListPayload[i], NS_ATTRIBUTE_TOPIC_NAME, &topicName);\r
+ OCRepPayloadGetPropInt(topicListPayload[i], NS_ATTRIBUTE_TOPIC_SELECTION, &topicState);\r
+ NS_LOG_V(DEBUG, "Topic Name(state): %s(%d)", topicName, (int)topicState);\r
+\r
+ if (NS_TOPIC_SUBSCRIBED == (NSTopicState) topicState)\r
+ {\r
+ NSCacheTopicSubData * topicSubData = (NSCacheTopicSubData *) OICMalloc(\r
+ sizeof(NSCacheTopicSubData));\r
+ NS_VERIFY_NOT_NULL(topicSubData, NS_FAIL);\r
+\r
+ OICStrcpy(topicSubData->id, NS_UUID_STRING_SIZE, consumerId);\r
+ topicSubData->topicName = topicName;\r
+\r
+ NSCacheElement * newObj = (NSCacheElement *) OICMalloc(sizeof(NSCacheElement));\r
+\r
+ if (!newObj)\r
+ {\r
+ OICFree(topicSubData->topicName);\r
+ OICFree(topicSubData);\r
+ OICFree(consumerId);\r
+ return NS_FAIL;\r
+ }\r
+\r
+ newObj->data = (NSCacheData *) topicSubData;\r
+ newObj->next = NULL;\r
+\r
+ NSProviderStorageWrite(consumerTopicList, newObj);
+ }\r
+ }\r
+ NSSendTopicUpdationToConsumer(consumerId);\r
+ OICFree(consumerId);\r
+ NS_LOG(DEBUG, "NSPostConsumerTopics() - OUT");\r
+ return NS_OK;\r