Modify Consumer Topic Logic 29/10329/10
authorYounghyunJoo <yh_.joo@samsung.com>
Wed, 17 Aug 2016 08:09:16 +0000 (17:09 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 18 Aug 2016 02:22:49 +0000 (02:22 +0000)
- Modify Topic Logic as changing Topics structure
- Remove consumerId value in the Topics structure
- Remove comment block in consumer codes

Change-Id: I256b6d5b18fd757957b4fbd58ebd631c2236ebf1
Signed-off-by: YounghyunJoo <yh_.joo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10329
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/notification/SConscript
service/notification/include/NSCommon.h
service/notification/include/NSConsumerInterface.h
service/notification/include/NSProviderInterface.h
service/notification/src/consumer/NSConsumerCommon.c
service/notification/src/consumer/NSConsumerCommon.h
service/notification/src/consumer/NSConsumerCommunication.c
service/notification/src/consumer/NSConsumerDiscovery.c
service/notification/src/consumer/NSConsumerInterface.c
service/notification/src/consumer/NSConsumerInternalTaskController.c
service/notification/src/consumer/NSConsumerScheduler.c

index 1553295..7b3b447 100755 (executable)
@@ -88,24 +88,24 @@ notification_provider_src = [
 notification_consumer_src = [
        env.Glob('src/consumer/*.c'), env.Glob('src/common/*.c')]
 
-providersdk = notification_env.SharedLibrary('notification_provider', notification_provider_src)
-notification_env.InstallTarget(providersdk, 'libnotification_provider')
-notification_env.UserInstallTargetLib(providersdk, 'libnotification_provider')
+#providersdk = notification_env.SharedLibrary('notification_provider', notification_provider_src)
+#notification_env.InstallTarget(providersdk, 'libnotification_provider')
+#notification_env.UserInstallTargetLib(providersdk, 'libnotification_provider')
 
 consumersdk = notification_env.SharedLibrary('notification_consumer', notification_consumer_src)
 notification_env.InstallTarget(consumersdk, 'libnotification_consumer')
 notification_env.UserInstallTargetLib(consumersdk, 'libnotification_consumer')
 
-providersdk = notification_env.StaticLibrary('notification_provider', notification_provider_src)
-notification_env.InstallTarget(providersdk, 'libnotification_provider')
-notification_env.UserInstallTargetLib(providersdk, 'libnotification_provider')
+#providersdk = notification_env.StaticLibrary('notification_provider', notification_provider_src)
+#notification_env.InstallTarget(providersdk, 'libnotification_provider')
+#notification_env.UserInstallTargetLib(providersdk, 'libnotification_provider')
 
 consumersdk = notification_env.StaticLibrary('notification_consumer', notification_consumer_src)
 notification_env.InstallTarget(consumersdk, 'libnotification_consumer')
 notification_env.UserInstallTargetLib(consumersdk, 'libnotification_consumer')
 
-notification_env.UserInstallTargetHeader('include/NSProviderInterface.h',\
-       'service/notification', 'NSProviderInterface.h')
+#notification_env.UserInstallTargetHeader('include/NSProviderInterface.h',\
+#      'service/notification', 'NSProviderInterface.h')
 notification_env.UserInstallTargetHeader('include/NSConsumerInterface.h',\
        'service/notification', 'NSConsumerInterface.h')
 
@@ -114,11 +114,11 @@ notification_env.UserInstallTargetHeader('include/NSConsumerInterface.h',\
 # SConscript('unittest/SConscript')
 
 # Go to build sample apps
-SConscript('examples/SConscript')
+#SConscript('examples/SConscript')
 
 # Go to build jni
-if target_os == 'android':
-    SConscript('android/SConscript')
+#if target_os == 'android':
+#    SConscript('android/SConscript')
 
 # Go to build c++ wrapper
-SConscript('cpp-wrapper/SConscript')
+#SConscript('cpp-wrapper/SConscript')
index 70ca1ca..96b20f8 100644 (file)
@@ -124,15 +124,15 @@ typedef struct _nsTopic
     NSTopicState state;
     struct _nsTopic * next;
 
-} NSTopics;
+} NSTopicLL;
 
 typedef struct
 {
-    NSTopics * head;
-    NSTopics * tail;
+    NSTopicLL * head;
+    NSTopicLL * tail;
     //TODO: decide struct fields
     char consumerId[NS_UUID_STRING_SIZE];
-    NSTopics ** topics;
+    NSTopicLL ** topics;
 
 } NSTopicList;
 
@@ -151,7 +151,7 @@ typedef struct
 typedef struct
 {
     char providerId[NS_UUID_STRING_SIZE];
-    NSTopicList * topicList;
+    NSTopicLL * topicLL;
 
 } NSProvider;
 
index 9fc89c0..798b733 100644 (file)
@@ -137,14 +137,14 @@ NSProvider * NSConsumerGetProvider(const char * providerId);
 NSMessage * NSConsumerGetMessage(uint64_t messageId);
 
 /**
- * Request NSTopicList that is subscribed from provider
+ * Request NSTopic list that is subscribed from provider
  * @param[in]  provider  the provider that user wants to get
  * @return NSResult
  */
 NSResult NSConsumerGetInterestTopics(NSProvider * provider);
 
 /**
- * Select Topics that is wanted to subscribe from provider
+ * Select Topic list that is wanted to subscribe from provider
  * @param[in]  provider  the provider that user wants to set
  * @return NSResult
  */
index 56ec204..5304c73 100644 (file)
@@ -167,13 +167,13 @@ NSResult NSProviderUnselectTopic(char* consumerId, char* topicName);
  * @param[in] consumerid  the id of consumer which topic list is subscribed for\r
  * @return :: Topic list\r
  */\r
-NSTopics * NSProviderGetConsumerTopics(char *consumerId);\r
+NSTopicLL * NSProviderGetConsumerTopics(char *consumerId);\r
 \r
 /**\r
  * Request topics list already registered by provider user\r
  * @return :: Topic list\r
  */\r
-NSTopics * NSProviderGetTopics();\r
+NSTopicLL * NSProviderGetTopics();\r
 \r
 #ifdef __cplusplus\r
 }\r
index b4b6079..63af3d3 100644 (file)
@@ -1,3 +1,4 @@
+
 //******************************************************************
 //
 // Copyright 2016 Samsung Electronics All Rights Reserved.
@@ -336,41 +337,88 @@ NSProviderConnectionInfo * NSCopyProviderConnections(NSProviderConnectionInfo *
     return retInfo;
 }
 
-void NSRemoveProviderTopicList(NSTopicList * topicList, size_t dimensionSize)
+void NSRemoveTopicNode(NSTopicLL * topicNode)
+{
+    NS_VERIFY_NOT_NULL_V(topicNode);
+
+    NSOICFree(topicNode->topicName);
+    topicNode->next = NULL;
+
+    NSOICFree(topicNode);
+}
+
+NSTopicLL * NSCopyTopicNode(NSTopicLL * topicNode)
+{
+    NS_VERIFY_NOT_NULL(topicNode, NULL);
+
+    NSTopicLL * newTopicNode = (NSTopicLL *)OICMalloc(sizeof(NSTopicLL));
+    NS_VERIFY_NOT_NULL(newTopicNode, NULL);
+
+    newTopicNode->topicName = OICStrdup(topicNode->topicName);
+    newTopicNode->state = topicNode->state;
+    newTopicNode->next = NULL;
+
+    return newTopicNode;
+}
+
+NSResult NSInsertTopicNode(NSTopicLL * topicHead, NSTopicLL * topicNode)
 {
-    NS_VERIFY_NOT_NULL_V(topicList);
+    NS_VERIFY_NOT_NULL(topicHead, NS_ERROR);
+    NS_VERIFY_NOT_NULL(topicNode, NS_ERROR);
+
+    NSTopicLL * iter = topicHead;
 
-    for (int i = -1; i < (int)dimensionSize; i++)
+    while (iter)
     {
-        NSOICFree(topicList->topics[i]);
+        iter = (NSTopicLL *) iter->next;
     }
-    NSOICFree(topicList);
+
+    iter->next = topicNode;
+    topicNode->next = NULL;
+
+    return NS_OK;
 }
 
-NSTopicList * NSCopyProviderTopicList(NSTopicList * topicList, size_t dimensionSize)
+void NSRemoveTopicLL(NSTopicLL * topicHead)
 {
-    NS_VERIFY_NOT_NULL(topicList, NULL);
+    NS_VERIFY_NOT_NULL_V(topicHead);
+
+    NSTopicLL * iter = topicHead;
 
-    NSTopicList * newTopicList = (NSTopicList *)OICMalloc(sizeof(NSTopicList));
-    NS_VERIFY_NOT_NULL(newTopicList, NULL);
+    while (iter)
+    {
+        NSRemoveTopicNode(iter);
 
-    OICStrcpy(newTopicList->consumerId, NS_DEVICE_ID_LENGTH, topicList->consumerId);
+        iter = (NSTopicLL *) iter->next;
+    }
 
-    newTopicList->topics = (NSTopics **) OICMalloc(sizeof(NSTopics *)*dimensionSize);
-    NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(newTopicList->topics,
-            NULL, NSRemoveProviderTopicList(newTopicList, -1));
+    NSOICFree(topicHead);
+}
+
+NSTopicLL * NSCopyTopicLL(NSTopicLL * topicHead)
+{
+    NS_VERIFY_NOT_NULL(topicHead, NULL);
 
-    for (int i = 0; i < (int)dimensionSize; i++)
+    NSTopicLL * iter = topicHead;
+
+    NSTopicLL * newTopicHead = NSCopyTopicNode(iter);
+    NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(newTopicHead, NULL, NSRemoveTopicLL(newTopicHead));
+
+    iter = (NSTopicLL *) iter->next;
+
+    while (iter)
     {
-        newTopicList->topics[i] = (NSTopics *) OICMalloc(sizeof(NSTopics));
-        NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(newTopicList->topics[i],
-            NULL, NSRemoveProviderTopicList(newTopicList, i));
+        NSTopicLL * newTopicNode = NSCopyTopicNode(iter);
+        NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(newTopicNode, NULL, NSRemoveTopicLL(newTopicHead));
 
-        newTopicList->topics[i]->topicName = OICStrdup(topicList->topics[i]->topicName);
-        newTopicList->topics[i]->state = topicList->topics[i]->state;
+        NSResult ret = NSInsertTopicNode(newTopicHead, newTopicNode);
+        NS_VERIFY_STACK_SUCCESS_WITH_POST_CLEANING(NSOCResultToSuccess(ret),
+                    NULL, NSRemoveTopicLL(newTopicHead));
+
+        iter = (NSTopicLL *) iter->next;
     }
 
-    return newTopicList;
+    return newTopicHead;
 }
 
 void NSCopyProviderPostClean(
@@ -390,17 +438,15 @@ NSProvider_internal * NSCopyProvider(NSProvider_internal * prov)
     NSProvider_internal * newProv = (NSProvider_internal *) OICMalloc(sizeof(NSProvider_internal));
     NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(newProv, NULL, NSRemoveConnections(connections));
 
-    newProv->topicList = NULL;
-    newProv->topicListSize = 0;
+    newProv->topicLL = NULL;
 
-    if (prov->topicList)
+    if (prov->topicLL)
     {
-        NSTopicList * topicList = NSCopyProviderTopicList(prov->topicList, prov->topicListSize);
-        NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(topicList, NULL,
+        NSTopicLL * newTopicLL = NSCopyTopicLL(prov->topicLL);
+        NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(newTopicLL, NULL,
                     NSCopyProviderPostClean(connections, newProv));
 
-        newProv->topicList = topicList;
-        newProv->topicListSize = prov->topicListSize;
+        newProv->topicLL = newTopicLL;
     }
 
     newProv->connection = connections;
@@ -421,7 +467,10 @@ void NSRemoveProvider(NSProvider_internal * prov)
     NSOICFree(prov->syncUri);
     NSOICFree(prov->topicUri);
     NSRemoveConnections(prov->connection);
-    NSRemoveProviderTopicList(prov->topicList, prov->topicListSize);
+    if (prov->topicLL)
+    {
+        NSRemoveTopicLL(prov->topicLL);
+    }
 
     NSOICFree(prov);
 }
index c1511f9..86cadd1 100644 (file)
@@ -18,8 +18,8 @@
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
-#ifndef _NS_CONSUMER_CONSTANTS_H_
-#define _NS_CONSUMER_CONSTANTS_H_
+#ifndef _NS_CONSUMER_COMMON_H_
+#define _NS_CONSUMER_COMMON_H_
 
 #ifdef __cplusplus
 extern "C" {
@@ -74,6 +74,8 @@ typedef struct
 {
     char providerId[NS_DEVICE_ID_LENGTH];
 
+    NSTopicLL * topicLL;
+
     char * messageUri;
     char * syncUri;
     char * topicUri;
@@ -82,9 +84,6 @@ typedef struct
 
     NSProviderConnectionInfo * connection;
 
-    NSTopicList * topicList;
-    size_t topicListSize;
-
 } NSProvider_internal;
 
 typedef struct
@@ -131,9 +130,9 @@ NSResult NSConsumerPushEvent(NSTask *);
 NSMessage * NSCopyMessage(NSMessage *);
 void NSRemoveMessage(NSMessage *);
 
-NSProviderConnectionInfo * NSCreateProviderConnections(OCDevAddr * inAddr);
-NSProviderConnectionInfo * NSCopyProviderConnections(NSProviderConnectionInfo * conn);
-void NSRemoveConnections(NSProviderConnectionInfo * connections);
+NSProviderConnectionInfo * NSCreateProviderConnections(OCDevAddr *);
+NSProviderConnectionInfo * NSCopyProviderConnections(NSProviderConnectionInfo *);
+void NSRemoveConnections(NSProviderConnectionInfo *);
 
 NSProvider_internal * NSCopyProvider(NSProvider_internal *);
 void NSRemoveProvider(NSProvider_internal *);
@@ -141,8 +140,12 @@ void NSRemoveProvider(NSProvider_internal *);
 NSSyncInfo_internal * NSCopySyncInfo(NSSyncInfo_internal *);
 void NSRemoveSyncInfo(NSSyncInfo_internal *);
 
-NSTopicList * NSCopyProviderTopicList(NSTopicList * topicList, size_t dimensionSize);
-void NSRemoveProviderTopicList(NSTopicList * topicList, size_t dimensionSize);
+NSTopicLL * NSCopyTopicNode(NSTopicLL *);
+void NSRemoveTopicNode(NSTopicLL *);
+NSResult NSInsertTopicNode(NSTopicLL *, NSTopicLL *);
+
+NSTopicLL * NSCopyTopicLL(NSTopicLL *);
+void NSRemoveTopicLL(NSTopicLL *);
 
 OCStackResult NSInvokeRequest(OCDoHandle * handle,
         OCMethod method, const OCDevAddr * addr,
@@ -155,4 +158,4 @@ bool NSOCResultToSuccess(OCStackResult ret);
 }
 #endif // __cplusplus
 
-#endif // _NS_CONSUMER_CONSTANTS_H_
+#endif // _NS_CONSUMER_COMMON_H_
index 32c37db..507a9c7 100644 (file)
@@ -404,32 +404,8 @@ void NSConsumerCommunicationTaskProcessing(NSTask * task)
             connections = connections->next;
         }
     }
-    /* TODO next commit, modify code.
-    else if (task->taskType == TASK_CONSUMER_REQ_TOPIC_LIST)
-    {
-        NSProvider_internal * provider = (NSProvider_internal *)task->taskData;
-
-        NSProviderConnectionInfo * connections = provider->connection;
-        NS_VERIFY_NOT_NULL_V(connections);
-
-        char * topicUri = OICStrdup(provider->topicUri);
-
-        OCConnectivityType type = CT_DEFAULT;
-        if (connections->addr->adapter == OC_ADAPTER_TCP)
-        {
-            type = CT_ADAPTER_TCP;
-            if (connections->isCloudConnection == true)
-            {
-                topicUri = NSGetCloudUri(provider->providerId, topicUri);
-            }
-        }
-
-        OCStackResult ret = NSInvokeRequest(NULL, OC_REST_GET, connections->addr,
-                                topicUri, NULL, NSIntrospectTopic, (void *) provider, type);
-        NS_VERIFY_STACK_SUCCESS_V(NSOCResultToSuccess(ret));
-        NSOICFree(topicUri);
-    }
-    else if (task->taskType == TASK_CONSUMER_GET_TOPIC_LIST)
+    else if (task->taskType == TASK_CONSUMER_REQ_TOPIC_LIST
+                || task->taskType == TASK_CONSUMER_GET_TOPIC_LIST)
     {
         NSProvider_internal * provider = (NSProvider_internal *)task->taskData;
 
@@ -450,13 +426,21 @@ void NSConsumerCommunicationTaskProcessing(NSTask * task)
 
         NS_LOG(DEBUG, "get topic query");
         char * query = NULL;
-        query = NSMakeRequestUriWithConsumerId(topicUri);
+        if (task->taskType == TASK_CONSUMER_REQ_TOPIC_LIST)
+        {
+            query = OICStrdup(topicUri);
+        }
+        else if (task->taskType == TASK_CONSUMER_GET_TOPIC_LIST)
+        {
+            query = NSMakeRequestUriWithConsumerId(topicUri);
+        }
         NS_VERIFY_NOT_NULL_V(query);
         NS_LOG_V(DEBUG, "topic query : %s", query);
 
         OCStackResult ret = NSInvokeRequest(NULL, OC_REST_GET, connections->addr,
-                                query, NULL, NSIntrospectTopic, NULL, type);
+                                query, NULL, NSIntrospectTopic, (void *) provider, type);
         NS_VERIFY_STACK_SUCCESS_V(NSOCResultToSuccess(ret));
+
         NSOICFree(query);
         NSOICFree(topicUri);
     }
@@ -469,23 +453,45 @@ void NSConsumerCommunicationTaskProcessing(NSTask * task)
 
         OCRepPayload * payload = OCRepPayloadCreate();
         NS_VERIFY_NOT_NULL_V(payload);
-        OCRepPayload ** topicPayload = (OCRepPayload **) OICMalloc(
-                                        sizeof(OCRepPayload *)*provider->topicListSize);
-        NS_VERIFY_NOT_NULL_V(topicPayload);
+
+        NSTopicLL * topicLL = provider->topicLL;
+        NSTopicLL * iter = topicLL;
+        int topicLLSize = 0;
+        while (iter)
+        {
+            topicLLSize ++;
+            iter = (NSTopicLL *) iter->next;
+        }
 
         OCRepPayloadSetPropString(payload, NS_ATTRIBUTE_CONSUMER_ID, *NSGetConsumerId());
 
-        NSTopic ** topic = provider->topicList->topics;
+        iter = topicLL;
+        int iterSize = 0;
 
-        for (int i = 0; i < (int)provider->topicListSize; i++)
+        OCRepPayload ** topicPayload = NULL;
+        if (topicLLSize > 0)
         {
-            topicPayload[i] = OCRepPayloadCreate();
-            OCRepPayloadSetPropString(topicPayload[i], NS_ATTRIBUTE_TOPIC_NAME, topic[i]->topicName);
-            OCRepPayloadSetPropInt(topicPayload[i], NS_ATTRIBUTE_TOPIC_SELECTION, topic[i]->state);
-        }
+            topicPayload = (OCRepPayload **) OICMalloc(sizeof(OCRepPayload *)*topicLLSize);
+            NS_VERIFY_NOT_NULL_V(topicPayload);
 
-        size_t dimensions[3] = {provider->topicListSize, 0, 0};
-        OCRepPayloadSetPropObjectArray(payload, NS_ATTRIBUTE_TOPIC_LIST, (const OCRepPayload **)topicPayload, dimensions);
+            while (iter || iterSize < topicLLSize)
+            {
+                topicPayload[iterSize] = OCRepPayloadCreate();
+                OCRepPayloadSetPropString(topicPayload[iterSize], NS_ATTRIBUTE_TOPIC_NAME,
+                                            iter->topicName);
+                OCRepPayloadSetPropInt(topicPayload[iterSize], NS_ATTRIBUTE_TOPIC_SELECTION,
+                                            iter->state);
+                iterSize++;
+                iter = iter->next;
+            }
+            size_t dimensions[3] = {topicLLSize, 0, 0};
+            OCRepPayloadSetPropObjectArrayAsOwner(payload, NS_ATTRIBUTE_TOPIC_LIST,
+                                                    topicPayload, dimensions);
+        }
+        else
+        {
+            OCRepPayloadSetNull(payload, NS_ATTRIBUTE_TOPIC_LIST);
+        }
 
         char * topicUri = OICStrdup(provider->topicUri);
 
@@ -505,12 +511,13 @@ void NSConsumerCommunicationTaskProcessing(NSTask * task)
         NS_VERIFY_NOT_NULL_V(query);
         NS_LOG_V(DEBUG, "topic query : %s", query);
 
-        OCStackResult ret = NSInvokeRequest(NULL, OC_REST_GET, connections->addr,
+        OCStackResult ret = NSInvokeRequest(NULL, OC_REST_POST, connections->addr,
                                 query, (OCPayload*)payload, NSConsumerCheckPostResult, NULL, type);
         NS_VERIFY_STACK_SUCCESS_V(NSOCResultToSuccess(ret));
+
         NSOICFree(query);
         NSOICFree(topicUri);
-    }*/
+    }
     else
     {
         NS_LOG(ERROR, "Unknown type message");
@@ -519,19 +526,9 @@ void NSConsumerCommunicationTaskProcessing(NSTask * task)
     NSOICFree(task);
 }
 
-void NSGetTopicPostClean(
-        char * cId, NSTopicList * tList, size_t dSize)
+NSTopicLL * NSGetTopicLL(OCClientResponse * clientResponse)
 {
-    /* TODO next commit, modify code.
-    NSOICFree(cId);
-    NSRemoveProviderTopicList(tList, dSize);
-    */
-}
-
-NSTopicList * NSGetTopic(OCClientResponse * clientResponse, size_t * topicListSize)
-{
-    /* TODO next commit, modify code.
-    NS_LOG(DEBUG, "create NSTopic");
+    NS_LOG(DEBUG, "create NSTopicLL");
     NS_VERIFY_NOT_NULL(clientResponse->payload, NULL);
 
     OCRepPayload * payload = (OCRepPayload *)clientResponse->payload;
@@ -544,71 +541,75 @@ NSTopicList * NSGetTopic(OCClientResponse * clientResponse, size_t * topicListSi
     payload = (OCRepPayload *)clientResponse->payload;
 
     char * consumerId = NULL;
-    OCRepPayload ** topicListPayload = NULL;
-    NSTopicList * topicList = (NSTopicList *) OICMalloc(sizeof(NSTopicList));
-    NS_VERIFY_NOT_NULL(topicList, NULL);
+    OCRepPayload ** topicLLPayload = NULL;
 
     NS_LOG(DEBUG, "get information of consumerId");
-    bool getResult = OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_CONSUMER_ID, & consumerId); // is NULL possible? (initial getting)
-    NS_VERIFY_NOT_NULL(getResult == true ? (void *) 1 : NULL, NULL);
 
-    OICStrcpy(topicList->consumerId, NS_DEVICE_ID_LENGTH, consumerId);
+    bool getResult = OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_CONSUMER_ID, & consumerId);
+    NSOICFree(consumerId);
 
     OCRepPayloadValue * payloadValue = NULL;
     payloadValue = NSPayloadFindValue(payload, NS_ATTRIBUTE_TOPIC_LIST);
-    NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(payloadValue, NULL, NSOICFree(consumerId));
+    NS_VERIFY_NOT_NULL(payloadValue, NULL);
 
     size_t dimensionSize = calcDimTotal(payloadValue->arr.dimensions);
-    size_t dimensions[3] = {dimensionSize, 0, 0};
-    *topicListSize = dimensionSize;
 
-    NS_LOG(DEBUG, "get information of topicList(OCRepPayload)");
-    getResult = OCRepPayloadGetPropObjectArray(payload, NS_ATTRIBUTE_TOPIC_LIST, 
-            & topicListPayload, dimensions);
-    NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(getResult == true ? (void *) 1 : NULL, 
-            NULL, NSOICFree(consumerId));
+    if (dimensionSize == 0 || payloadValue->type == OCREP_PROP_NULL ||
+            payloadValue->arr.objArray == NULL)
+    {
+        NS_LOG(DEBUG, "No TopicLL");
+        return NULL;
+    }
 
-    topicList->topics = (NSTopic **) OICMalloc(sizeof(NSTopic *)*dimensionSize);
-    NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(topicList->topics,
-            NULL, NSGetTopicPostClean(consumerId, topicList, -1));
+    topicLLPayload = payloadValue->arr.objArray;
 
+    NSTopicLL * topicLL = NULL;
     for (int i = 0; i < (int)dimensionSize; i++)
     {
         char * topicName = NULL;
         int64_t state = 0;
 
-        topicList->topics[i] = (NSTopic *) OICMalloc(sizeof(NSTopic));
-        NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(topicList->topics[i],
-                NULL, NSGetTopicPostClean(consumerId, topicList, i));
+        NSTopicLL * topicNode = (NSTopicLL *) OICMalloc(sizeof(NSTopicLL));
+        NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(topicNode, NULL, NSRemoveTopicLL(topicLL));
+
+        NS_LOG(DEBUG, "get topic selection");
+        getResult = OCRepPayloadGetPropInt(topicLLPayload[i],
+                NS_ATTRIBUTE_TOPIC_SELECTION, & state);
+        NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(getResult == true ? (void *) 1 : NULL,
+                NULL, NSRemoveTopicLL(topicLL));
 
         NS_LOG(DEBUG, "get topic name");
-        getResult = OCRepPayloadGetPropString(topicListPayload[i], NS_ATTRIBUTE_TOPIC_NAME, &topicName);
+        getResult = OCRepPayloadGetPropString(topicLLPayload[i],
+                NS_ATTRIBUTE_TOPIC_NAME, & topicName);
         NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(getResult == true ? (void *) 1 : NULL,
-                NULL, NSGetTopicPostClean(consumerId, topicList, i));
+                NULL, NSRemoveTopicLL(topicLL));
 
+        topicNode->topicName = topicName;
+        topicNode->state = state;
 
-        NS_LOG(DEBUG, "get topic selection");
-        getResult = OCRepPayloadGetPropInt(topicListPayload[i], NS_ATTRIBUTE_TOPIC_SELECTION, &state);
-        NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(getResult == true ? (void *) 1 : NULL,
-                NULL, NSGetTopicPostClean(consumerId, topicList, i));
+        if (i == 0)
+        {
+            topicLL = topicNode;
+            continue;
+        }
 
-        topicList->topics[i]->topicName = topicName;
-        topicList->topics[i]->state = state;
+        NSResult ret = NSInsertTopicNode(topicLL, topicNode);
+        NS_VERIFY_STACK_SUCCESS_WITH_POST_CLEANING(NSOCResultToSuccess(ret),
+                    NULL, NSRemoveTopicLL(topicLL));
     }
 
-    NSOICFree(consumerId);
-
-    return topicList;*/
+    return topicLL;
 }
 
 OCStackApplicationResult NSIntrospectTopic(
         void * ctx, OCDoHandle handle, OCClientResponse * clientResponse)
 {
-/* TODO next commit, modify code.
     (void) handle;
 
-    NS_VERIFY_NOT_NULL(clientResponse, OC_STACK_KEEP_TRANSACTION);
-    NS_VERIFY_STACK_SUCCESS(NSOCResultToSuccess(clientResponse->result), OC_STACK_KEEP_TRANSACTION);
+    NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(clientResponse, OC_STACK_KEEP_TRANSACTION,
+            NSRemoveProvider((NSProvider_internal *) ctx));
+    NS_VERIFY_STACK_SUCCESS_WITH_POST_CLEANING(NSOCResultToSuccess(clientResponse->result),
+            OC_STACK_KEEP_TRANSACTION, NSRemoveProvider((NSProvider_internal *) ctx));
 
     NS_LOG_V(DEBUG, "GET response income : %s:%d",
             clientResponse->devAddr.addr, clientResponse->devAddr.port);
@@ -619,24 +620,21 @@ OCStackApplicationResult NSIntrospectTopic(
     NS_LOG_V(DEBUG, "GET response resource uri : %s",
             clientResponse->resourceUri);
     NS_LOG_V(DEBUG, "GET response Transport Type : %d",
-                    clientResponse->devAddr.adapter);
+            clientResponse->devAddr.adapter);
 
-    size_t topicListSize = 0;
-    NSTopicList * newTopicList = NSGetTopic(clientResponse, &topicListSize);
-    NS_VERIFY_NOT_NULL(newTopicList, OC_STACK_KEEP_TRANSACTION);
+    NSTopicLL * newTopicLL = NSGetTopicLL(clientResponse);
+    NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(newTopicLL, OC_STACK_KEEP_TRANSACTION,
+            NSRemoveProvider((NSProvider_internal *) ctx));
 
-    // TODO Call the callback function registered at the start
     NSProvider_internal * provider = (NSProvider_internal *) ctx;
-    provider->topicList = NSCopyProviderTopicList(newTopicList, topicListSize);
-    provider->topicListSize = topicListSize;
+    provider->topicLL = NSCopyTopicLL(newTopicLL);
 
     NS_LOG(DEBUG, "build NSTask");
     NSTask * task = NSMakeTask(TASK_CONSUMER_RECV_TOPIC_LIST, (void *) provider);
     NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(task, NS_ERROR, NSRemoveProvider(provider));
 
     NSConsumerPushEvent(task);
-    NSRemoveProviderTopicList(newTopicList, topicListSize);
+    NSRemoveTopicLL(newTopicLL);
 
     return OC_STACK_KEEP_TRANSACTION;
-    */
 }
index a334b78..6d321c9 100644 (file)
@@ -214,12 +214,10 @@ NSProvider_internal * NSGetProvider(OCClientResponse * clientResponse)
     NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(getResult == true ? (void *) 1 : NULL, NULL,
             NSGetProviderPostClean(providerId, messageUri, syncUri, topicUri, connection));
 
-    /* TODO next commit, modify code.
     NS_LOG(DEBUG, "get topic URI");
     getResult = OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_TOPIC, & topicUri);
     NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(getResult == true ? (void *) 1 : NULL, NULL,
             NSGetProviderPostClean(providerId, messageUri, syncUri, topicUri, connection));
-    */
 
     NS_LOG(DEBUG, "get provider connection information");
     NS_VERIFY_NOT_NULL(clientResponse->addr, NULL);
index 13ba403..9b7e379 100644 (file)
@@ -155,38 +155,41 @@ NSMessage * NSConsumerGetMessage(uint64_t messageId)
 
 NSResult NSConsumerGetInterestTopics(NSProvider * provider)
 {
-    /* TODO next commit, modify code.
     bool isStartedConsumer = NSIsStartedConsumer();
     NS_VERIFY_NOT_NULL(isStartedConsumer == true ? (void *) 1 : NULL, NS_ERROR);
 
     NS_VERIFY_NOT_NULL(provider, NS_ERROR);
 
+    NSSelector selector = (NSSelector)((NSProvider_internal *) provider)->accessPolicy;
+    NS_VERIFY_NOT_NULL(selector == NS_SELECTION_CONSUMER ? (void *) 1 : NULL, NS_ERROR);
+
     NSTask * topicTask = NSMakeTask(TASK_CONSUMER_GET_TOPIC_LIST, (void *) provider);
     NS_VERIFY_NOT_NULL(topicTask, NS_ERROR);
 
     return NSConsumerPushEvent(topicTask);
-    */
 }
 
 NSResult NSConsumerSelectInterestTopics(NSProvider * provider)
 {
-    /* TODO next commit, modify code.
     bool isStartedConsumer = NSIsStartedConsumer();
     NS_VERIFY_NOT_NULL(isStartedConsumer == true ? (void *) 1 : NULL, NS_ERROR);
 
     NS_VERIFY_NOT_NULL(provider, NS_ERROR);
 
-    if (!provider->topicList)
-        provider->topicList = (NSTopicList *) OICMalloc(sizeof(NSTopicList));
-    NS_VERIFY_NOT_NULL(provider->topicList, NS_ERROR);
+    NSSelector selector = (NSSelector)((NSProvider_internal *) provider)->accessPolicy;
+    NS_VERIFY_NOT_NULL(selector == NS_SELECTION_CONSUMER ? (void *) 1 : NULL, NS_ERROR);
+
+    if (!provider->topicLL)
+    {
+        provider->topicLL = (NSTopicLL *) OICMalloc(sizeof(NSTopicLL));
+    }
+    NS_VERIFY_NOT_NULL(provider->topicLL, NS_ERROR);
 
-    OICStrcpy(provider->topicList->consumerId, NS_DEVICE_ID_LENGTH, provider->providerId);
 
     NSTask * topicTask = NSMakeTask(TASK_CONSUMER_SELECT_TOPIC_LIST, (void *) provider);
     NS_VERIFY_NOT_NULL(provider, NS_ERROR);
 
     return NSConsumerPushEvent(topicTask);
-    */
 }
 
 NSResult NSDropNSMessage(NSMessage * obj)
index a53ca7b..3973b59 100644 (file)
@@ -291,7 +291,7 @@ void NSConsumerHandleRecvProviderChanged(NSMessage * msg)
     NSProvider_internal * provider = NSProviderCacheFind(msg->providerId);
     NS_VERIFY_NOT_NULL_V(provider);
 
-    if (provider->connection->next == NULL)
+    if (provider->connection->next == NULL && provider->accessPolicy == NS_SELECTION_CONSUMER)
     {
         NS_LOG(DEBUG, "call back to user");
         NSProviderChanged((NSProvider *) provider, (NSResponse) msg->messageId);
@@ -362,14 +362,13 @@ void NSConsumerHandleGetTopicUri(NSMessage * msg)
     NSConsumerPushEvent(topicTask);
 }
 
-void NSConsumerHandleRecvTopicList(NSProvider_internal * provider)
+void NSConsumerHandleRecvTopicLL(NSProvider_internal * provider)
 {
     NS_VERIFY_NOT_NULL_V(provider);
 
     NSResult ret = NSProviderCacheUpdate(provider);
     NS_VERIFY_NOT_NULL_V(ret == NS_OK ? (void *) 1 : NULL);
 
-    // call the callback function when consumer is an accepter
     if (provider->connection->next == NULL)
     {
         NS_LOG(DEBUG, "call back to user");
@@ -431,7 +430,7 @@ void NSConsumerInternalTaskProcessing(NSTask * task)
         case TASK_CONSUMER_RECV_TOPIC_LIST:
         {
             NS_LOG(DEBUG, "Receive Topic List");
-            NSConsumerHandleRecvTopicList((NSProvider_internal *)task->taskData);
+            NSConsumerHandleRecvTopicLL((NSProvider_internal *)task->taskData);
             NSRemoveProvider((NSProvider_internal *)task->taskData);
             break;
         }
index 9ca91a8..6f4b92d 100644 (file)
@@ -244,7 +244,6 @@ void NSConsumerTaskProcessing(NSTask * task)
         case TASK_RECV_SYNCINFO:
         case TASK_CONSUMER_RECV_MESSAGE:
         case TASK_CONSUMER_PROVIDER_DISCOVERED:
-        //case TASK_CONSUMER_RECV_SUBSCRIBE_CONFIRMED:
         case TASK_CONSUMER_RECV_PROVIDER_CHANGED:
         case TASK_MAKE_SYNCINFO:
         case TASK_CONSUMER_REQ_TOPIC_URI: