#define CLOUD_IOTIVITYNS_SESSION "" // refer to IoTivity Cloud Module Sample
#endif
+NSProvider * g_provider = NULL;
+
void onDiscoverNotification(NSProvider * provider)
{
printf("notification resource discovered\n");
printf("startSubscribing\n");
}
+void printProviderTopicList(NSProvider *provider)
+{
+ printf("printProviderTopicList\n");
+ if (provider->topicLL)
+ {
+ NSTopicLL * iter = provider->topicLL;
+ while (iter)
+ {
+ printf("Topic Name: %s\t Topic State: %d\n", iter->topicName, iter->state);
+ iter = iter->next;
+ }
+ }
+}
+
void onProviderChanged(NSProvider * provider, NSResponse response)
{
printf("Provider changed: %d\n", response);
if (response == NS_TOPIC)
{
printf ("Provider Topic Updated\n");
- if (provider->topicLL)
- {
- NSTopicLL * iter = provider->topicLL;
- while (iter)
- {
- printf("Topic Name: %s\t Topic State: %d\n", iter->topicName, iter->state);
- iter = iter->next;
- }
- }
-
- printf("3. Get Topics\n");
- printf("4. Select Topics\n");
- printf("input: ");
-
- int num = 0;
- char dummy = '\0';
- scanf("%d", &num);
- fflush(stdin);
- scanf("%c", &dummy);
- fflush(stdin);
- switch (num)
- {
- case 3:
- printf("3. Get Topics\n");
- NSConsumerGetInterestTopics(provider);
- break;
- case 4:
- printf("4. Select Topics\n");
- if (provider->topicLL)
- {
- NSTopicLL * iter = provider->topicLL;
- int i = 0;
- while (iter)
- {
- iter->state = (i++)%2;
- printf("Topic Name: %s\t Topic State: %d\n", iter->topicName, iter->state);
- iter = iter->next;
- }
- }
- NSConsumerSelectInterestTopics(provider);
- break;
- }
+ printProviderTopicList(provider);
+ g_provider = provider;
}
}
printf("Sync STATE : %d\n", sync->state);
}
-
#ifdef WITH_CLOUD
OCStackApplicationResult handleLoginoutCB(void *ctx,
OCDoHandle handle,
printf("1. Start Consumer\n");
printf("2. Stop Consumer\n");
+ printf("3. Get Topics\n");
+ printf("4. Select Topics\n");
printf("5. Exit\n");
printf("Input: ");
printf("2. Stop Consumer");
NSStopConsumer();
break;
+ case 3:
+ printf("3. Get Topics\n");
+ if(g_provider)
+ {
+ NSConsumerGetInterestTopics(g_provider);
+ }
+ break;
+ case 4:
+ printf("4. Select Topics\n");
+
+ if (g_provider && g_provider->topicLL)
+ {
+ NSTopicLL * iter = g_provider->topicLL;
+ int i = 0;
+ while (iter)
+ {
+ iter->state = (i++)%2;
+ printf("Topic Name: %s\t Topic State: %d\n", iter->topicName, iter->state);
+ iter = iter->next;
+ }
+ NSConsumerSelectInterestTopics(g_provider);
+ }
+ break;
case 5:
printf("5. Exit");
isExit = true;
break;
}
}
-
return 0;
}
NSTopicLL * iter = topicHead;
+ NS_LOG_V(DEBUG, "[NSCopyTopicLL] Name:%s\t State:%d", iter->topicName, iter->state);
NSTopicLL * newTopicHead = NSCopyTopicNode(iter);
NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(newTopicHead, NULL, NSRemoveTopicLL(newTopicHead));
while (iter)
{
+ NS_LOG_V(DEBUG, "[NSCopyTopicLL] Name:%s\t State:%d", iter->topicName, iter->state);
NSTopicLL * newTopicNode = NSCopyTopicNode(iter);
NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(newTopicNode, NULL, NSRemoveTopicLL(newTopicHead));
while (iter)
{
topicLLSize ++;
+ NS_LOG_V(DEBUG, "[%d] Topic Name:%s\tTopic State:%d",
+ topicLLSize, iter->topicName, iter->state);
iter = (NSTopicLL *) iter->next;
}
OCRepPayloadSetPropString(payload, NS_ATTRIBUTE_CONSUMER_ID, *NSGetConsumerId());
+ NS_LOG_V(DEBUG, "NS_ATTRIBUTE_CONSUMER_ID: %s", *NSGetConsumerId());
iter = topicLL;
int iterSize = 0;
+ NS_LOG_V(DEBUG, "DimensionSize: %d", topicLLSize);
OCRepPayload ** topicPayload = NULL;
if (topicLLSize > 0)
iter->topicName);
OCRepPayloadSetPropInt(topicPayload[iterSize], NS_ATTRIBUTE_TOPIC_SELECTION,
iter->state);
+ NS_LOG_V(DEBUG, "NS_ATTRIBUTE_TOPIC_NAME: %s", iter->topicName);
+ NS_LOG_V(DEBUG, "NS_ATTRIBUTE_TOPIC_SELECTION: %d", iter->state);
iterSize++;
iter = iter->next;
}
size_t dimensions[3] = {topicLLSize, 0, 0};
+
OCRepPayloadSetPropObjectArrayAsOwner(payload, NS_ATTRIBUTE_TOPIC_LIST,
topicPayload, dimensions);
}
NS_VERIFY_NOT_NULL(provider, NS_ERROR);
+ NS_LOG_V(DEBUG, "NSProvider ID: %s", provider->providerId);
NSProvider_internal * prov = NSConsumerFindNSProvider(provider->providerId);
NS_VERIFY_NOT_NULL(prov, NS_ERROR);
NSSelector selector = prov->accessPolicy;
if (provider->connection->next == NULL && provider->accessPolicy == NS_SELECTION_CONSUMER)
{
NS_LOG(DEBUG, "call back to user");
- NSProviderChanged((NSProvider *) provider, (NSResponse) msg->messageId);
+ NSProvider * prov = NSCopyProvider(provider);
+ NSProviderChanged(prov, (NSResponse) msg->messageId);
+ NSRemoveProvider_internal(provider);
}
}
NSResult ret = NSProviderCacheUpdate(provider);
NS_VERIFY_NOT_NULL_V(ret == NS_OK ? (void *) 1 : NULL);
- if (provider->connection->next == NULL)
- {
- NS_LOG(DEBUG, "call back to user");
- NSProviderChanged((NSProvider *) provider, (NSResponse) NS_TOPIC);
- }
+ NS_LOG(DEBUG, "call back to user");
+ NSProvider * prov = NSCopyProvider(provider);
+ NSProviderChanged((NSProvider *) prov, (NSResponse) NS_TOPIC);
}
void NSConsumerInternalTaskProcessing(NSTask * task)
case TASK_CONSUMER_GET_TOPIC_LIST:
case TASK_CONSUMER_SELECT_TOPIC_LIST:
{
+ NSProvider * provider = (NSProvider *)task->taskData;
NSProvider_internal * prov =
- NSConsumerFindNSProvider(((NSProvider *)task->taskData)->providerId);
+ NSConsumerFindNSProvider(provider->providerId);
NS_VERIFY_NOT_NULL_V(prov);
+ if (task->taskType == TASK_CONSUMER_SELECT_TOPIC_LIST)
+ {
+ NSRemoveTopicLL(prov->topicLL);
+ prov->topicLL = NSCopyTopicLL((NSTopicLL *)provider->topicLL);
+ }
+
NSTask * topTask = NSMakeTask(task->taskType, prov);
NS_VERIFY_NOT_NULL_V(topTask);
NSConsumerCommunicationTaskProcessing(topTask);