Rename Function and arguments for API.
authorjaesick.shin <jaesick.shin@samsung.com>
Mon, 29 Aug 2016 13:51:30 +0000 (22:51 +0900)
committerUze Choi <uzchoi@samsung.com>
Tue, 30 Aug 2016 08:09:27 +0000 (08:09 +0000)
this patch included,
1. Rename function for API.
2. Modify the unittested by the first.
3. comment out the cpp-wrapper in SConscript.

Change-Id: I5f7ba966e757dc14389eab58d96ed3e5cfa521fe
Signed-off-by: jaesick.shin <jaesick.shin@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11071
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
service/notification/SConscript
service/notification/examples/linux/notificationprovider.c
service/notification/include/NSProviderInterface.h
service/notification/src/provider/NSProviderInterface.c
service/notification/src/provider/NSProviderSubscription.c
service/notification/unittest/NSProviderTest.cpp

index ab866e8088909825f95745577e44198dafe5af4d..4ec3d60b24eb010f20cd52c22727b2751ae7af19 100755 (executable)
@@ -124,4 +124,4 @@ if target_os == 'android':
     SConscript('android/SConscript')
 
 # Go to build c++ wrapper
-SConscript('cpp-wrapper/SConscript')
+#SConscript('cpp-wrapper/SConscript')
index c638d2317610fcd87e5764cd3131cfe61f155c59..3454acb7fe3b41ec61685167c934c509e787b9b7 100644 (file)
@@ -78,7 +78,7 @@ void subscribeRequestCallback(NSConsumer *consumer)
         OICStrcpy(mainConsumer, 37, consumer->consumerId);
     }
 
-    NSAcceptSubscription(consumer, true);
+    NSAcceptSubscription(consumer->consumerId, true);
 }
 
 void syncCallback(NSSyncInfo *sync)
@@ -255,28 +255,28 @@ int main()
 
             case 5:
                 printf("NSProviderAddTopic\n");
-                NSProviderAddTopic("OCF_TOPIC1");
-                NSProviderAddTopic("OCF_TOPIC2");
-                NSProviderAddTopic("OCF_TOPIC3");
-                NSProviderAddTopic("OCF_TOPIC4");
+                NSProivderRegisterTopic("OCF_TOPIC1");
+                NSProivderRegisterTopic("OCF_TOPIC2");
+                NSProivderRegisterTopic("OCF_TOPIC3");
+                NSProivderRegisterTopic("OCF_TOPIC4");
                 break;
 
             case 6:
                 printf("NSProviderDeleteTopic\n");
-                NSProviderDeleteTopic("OCF_TOPIC2");
+                NSProviderUnregisterTopic("OCF_TOPIC2");
                 break;
 
             case 7:
                 printf("NSProviderSelectTopic\n");
-                NSProviderSelectTopic(mainConsumer, "OCF_TOPIC1");
-                NSProviderSelectTopic(mainConsumer, "OCF_TOPIC2");
-                NSProviderSelectTopic(mainConsumer, "OCF_TOPIC3");
-                NSProviderSelectTopic(mainConsumer, "OCF_TOPIC4");
+                NSProviderSetConsumerTopic(mainConsumer, "OCF_TOPIC1");
+                NSProviderSetConsumerTopic(mainConsumer, "OCF_TOPIC2");
+                NSProviderSetConsumerTopic(mainConsumer, "OCF_TOPIC3");
+                NSProviderSetConsumerTopic(mainConsumer, "OCF_TOPIC4");
                 break;
 
             case 8:
                 printf("NSProviderUnSelectTopic\n");
-                NSProviderUnselectTopic(mainConsumer, "OCF_TOPIC1");
+                NSProviderUnsetConsumerTopic(mainConsumer, "OCF_TOPIC1");
                 break;
 
             case 9:
index 5304c73ef7745c6b2a3a8d77c3ccf3d89a642f9f..af9c19f3064e8acc69b803071bd686557d68d883 100644 (file)
@@ -86,21 +86,21 @@ NSResult NSStopProvider();
  * @param[in]  server address combined with IP address and port number using delimiter :\r
  * @return ::NS_OK or result code of NSResult\r
  */\r
-NSResult NSProviderEnableRemoteService(char *serverAddress);\r
+NSResult NSProviderEnableRemoteService(char * serverAddress);\r
 \r
 /**\r
  * Request to cancel remote service using cloud server\r
  * @param[in]  server address combined with IP address and port number using delimiter :\r
  * @return ::NS_OK or result code of NSResult\r
  */\r
-NSResult NSProviderDisableRemoteService(char *serverAddress);\r
+NSResult NSProviderDisableRemoteService(char * serverAddress);\r
 \r
 /**\r
  * Send notification message to all subscribers\r
  * @param[in]  message  Notification message including id, title, contentText\r
  * @return ::NS_OK or result code of NSResult\r
  */\r
-NSResult NSSendMessage(NSMessage *msg);\r
+NSResult NSSendMessage(NSMessage * msg);\r
 \r
 /**\r
  * Send acceptance to consumer who subscribes the resource of notification message\r
@@ -108,7 +108,7 @@ NSResult NSSendMessage(NSMessage *msg);
  * @param[in]  accepted  the result of acceptance; Allow or Deny\r
  * @return ::NS_OK or result code of NSResult\r
  */\r
-NSResult NSAcceptSubscription(NSConsumer *consumer, bool accepted);\r
+NSResult NSAcceptSubscription(const char * consumerId, bool accepted);\r
 \r
 /**\r
  * Get consumer list that is stored in the cache of notification service\r
@@ -137,14 +137,14 @@ NSMessage * NSCreateMessage();
  * @param[in]  topicName Topic name to add\r
  * @return ::NS_OK or result code of NSResult\r
  */\r
-NSResult NSProviderAddTopic(char* topicName);\r
+NSResult NSProivderRegisterTopic(const char * topicName);\r
 \r
 /**\r
  * Delete topic from topic list\r
  * @param[in]  topicName Topic name to delete\r
  * @return ::NS_OK or result code of NSResult\r
  */\r
-NSResult NSProviderDeleteTopic(char* topicName);\r
+NSResult NSProviderUnregisterTopic(const char * topicName);\r
 \r
 /**\r
  * Select a topic name for a consumer\r
@@ -152,7 +152,7 @@ NSResult NSProviderDeleteTopic(char* topicName);
  * @param[in]  topicName Topic name to select\r
  * @return ::NS_OK or result code of NSResult\r
  */\r
-NSResult NSProviderSelectTopic(char* consumerId, char* topicName);\r
+NSResult NSProviderSetConsumerTopic(const char * consumerId, const char * topicName);\r
 \r
 /**\r
  * Unselect a topic from the topic list for consumer\r
@@ -160,14 +160,14 @@ NSResult NSProviderSelectTopic(char* consumerId, char* topicName);
  * @param[in]  topicName Topic name to unselect\r
  * @return ::NS_OK or result code of NSResult\r
  */\r
-NSResult NSProviderUnselectTopic(char* consumerId, char* topicName);\r
+NSResult NSProviderUnsetConsumerTopic(const char * consumerId, const char * topicName);\r
 \r
 /**\r
  * Request topic list with selection state for the consumer\r
  * @param[in] consumerid  the id of consumer which topic list is subscribed for\r
  * @return :: Topic list\r
  */\r
-NSTopicLL * NSProviderGetConsumerTopics(char *consumerId);\r
+NSTopicLL * NSProviderGetConsumerTopics(const char * consumerId);\r
 \r
 /**\r
  * Request topics list already registered by provider user\r
index cddb775d1ab95658d920e951d2facbbfa8a483e9..c963a815ab6ba2e07cf7c0a3c52e44c82af5d218 100644 (file)
@@ -127,7 +127,7 @@ NSResult NSStopProvider()
     return NS_OK;\r
 }\r
 \r
-NSResult NSProviderEnableRemoteService(char *serverAddress)\r
+NSResult NSProviderEnableRemoteService(char * serverAddress)\r
 {\r
     NS_LOG(DEBUG, "NSProviderEnableRemoteService - IN");\r
     pthread_mutex_lock(&nsInitMutex);\r
@@ -171,7 +171,7 @@ NSResult NSProviderDisableRemoteService(char *serverAddress)
     return NS_OK;\r
 }\r
 \r
-NSResult NSSendMessage(NSMessage *msg)\r
+NSResult NSSendMessage(NSMessage * msg)\r
 {\r
     NS_LOG(DEBUG, "NSSendNotification - IN");\r
 \r
@@ -209,22 +209,22 @@ NSResult NSProviderSendSyncInfo(uint64_t messageId, NSSyncType type)
     return NS_OK;\r
 }\r
 \r
-NSResult NSAcceptSubscription(NSConsumer *consumer, bool accepted)\r
+NSResult NSAcceptSubscription(const char * consumerId, bool accepted)\r
 {\r
     NS_LOG(DEBUG, "NSAccept - IN");\r
 \r
     pthread_mutex_lock(&nsInitMutex);\r
 \r
-    NSConsumer * newConsumer = NSDuplicateConsumer(consumer);\r
+    char * newConsumerId = OICStrdup(consumerId);\r
     if(accepted)\r
     {\r
         NS_LOG(DEBUG, "accepted is true - ALLOW");\r
-        NSPushQueue(SUBSCRIPTION_SCHEDULER, TASK_SEND_ALLOW, newConsumer);\r
+        NSPushQueue(SUBSCRIPTION_SCHEDULER, TASK_SEND_ALLOW, newConsumerId);\r
     }\r
     else\r
     {\r
         NS_LOG(DEBUG, "accepted is false - DENY");\r
-        NSPushQueue(SUBSCRIPTION_SCHEDULER, TASK_SEND_DENY, newConsumer);\r
+        NSPushQueue(SUBSCRIPTION_SCHEDULER, TASK_SEND_DENY, newConsumerId);\r
     }\r
 \r
     pthread_mutex_unlock(&nsInitMutex);\r
@@ -245,7 +245,7 @@ NSMessage * NSCreateMessage()
     return msg;\r
 }\r
 \r
-NSTopicLL * NSProviderGetConsumerTopics(char *consumerId)\r
+NSTopicLL * NSProviderGetConsumerTopics(const char * consumerId)\r
 {\r
     NS_LOG(DEBUG, "NSProviderGetConsumerTopics - IN");\r
     pthread_mutex_lock(&nsInitMutex);\r
@@ -277,7 +277,7 @@ NSTopicLL * NSProviderGetTopics()
     return topics;\r
 }\r
 \r
-NSResult NSProviderAddTopic(char *topicName)\r
+NSResult NSProviderRegisterTopic(const char * topicName)\r
 {\r
     NS_LOG(DEBUG, "NSProviderAddTopics - IN");\r
     pthread_mutex_lock(&nsInitMutex);\r
@@ -296,7 +296,7 @@ NSResult NSProviderAddTopic(char *topicName)
     return NS_OK;\r
 }\r
 \r
-NSResult NSProviderDeleteTopic(char *topicName)\r
+NSResult NSProviderUnregisterTopic(const char * topicName)\r
 {\r
     NS_LOG(DEBUG, "NSProviderDeleteTopics - IN");\r
     pthread_mutex_lock(&nsInitMutex);\r
@@ -315,7 +315,7 @@ NSResult NSProviderDeleteTopic(char *topicName)
     return NS_OK;\r
 }\r
 \r
-NSResult NSProviderSelectTopic(char *consumerId, char *topicName)\r
+NSResult NSProviderSetConsumerTopic(const char * consumerId, const char * topicName)\r
 {\r
     NS_LOG(DEBUG, "NSProviderSelectTopics - IN");\r
     pthread_mutex_lock(&nsInitMutex);\r
@@ -341,7 +341,7 @@ NSResult NSProviderSelectTopic(char *consumerId, char *topicName)
     return NS_OK;\r
 }\r
 \r
-NSResult NSProviderUnselectTopic(char *consumerId, char *topicName)\r
+NSResult NSProviderUnsetConsumerTopic(const char * consumerId, const char * topicName)\r
 {\r
     NS_LOG(DEBUG, "NSProviderUnselectTopics - IN");\r
     pthread_mutex_lock(&nsInitMutex);\r
index 17a0f3b02f30a20e7aa436ec963049fca20cb4ff..026fb6c7bff45efbf61ca5a6f6e456e610f123da 100644 (file)
@@ -359,21 +359,21 @@ void * NSSubScriptionSchedule(void *ptr)
                 case TASK_SEND_ALLOW:\r
                 {\r
                     NS_LOG(DEBUG, "CASE TASK_SEND_ALLOW : ");\r
-                    NSConsumer * consumer = (NSConsumer *) node->taskData;\r
+                    char * consumerId = (char *) node->taskData;\r
 \r
-                    NSCacheUpdateSubScriptionState(consumerSubList, consumer->consumerId, true);\r
-                    NSSendResponse(consumer->consumerId, true);\r
-                    NSFreeConsumer(consumer);\r
+                    NSCacheUpdateSubScriptionState(consumerSubList, consumerId, true);\r
+                    NSSendResponse(consumerId, true);\r
+                    OICFree(consumerId);\r
                     break;\r
                 }\r
                 case TASK_SEND_DENY:\r
                 {\r
                     NS_LOG(DEBUG, "CASE TASK_SEND_DENY : ");\r
-                    NSConsumer * consumer = (NSConsumer *) node->taskData;\r
+                    char * consumerId = (char *) node->taskData;\r
 \r
-                    NSCacheUpdateSubScriptionState(consumerSubList, consumer->consumerId, false);\r
-                    NSSendResponse(consumer->consumerId, false);\r
-                    NSFreeConsumer(consumer);\r
+                    NSCacheUpdateSubScriptionState(consumerSubList, consumerId, false);\r
+                    NSSendResponse(consumerId, false);\r
+                    NSFreeConsumer(consumerId);\r
 \r
                     break;\r
                 }\r
index 989a8bdcc515fd40ad010e5eb384cd8b2593b506..1ae689ff7d48995babb0ed82d577264f401d1d9a 100755 (executable)
@@ -40,7 +40,7 @@ namespace
     std::mutex mutexForCondition;
 
     NSConsumerSimulator g_consumerSimul;
-    NSConsumer * g_consumer;
+    char * g_consumerID;
 }
 
 class TestWithMock: public testing::Test
@@ -177,13 +177,12 @@ TEST_F(NotificationProviderTest, StartProviderPositiveWithNSPolicyFalse)
 
 TEST_F(NotificationProviderTest, ExpectCallbackWhenReceiveSubscribeRequestWithAccepterProvider)
 {
-    g_consumer = NULL;
+    g_consumerID = NULL;
     mocks.OnCallFunc(NSRequestedSubscribeCallbackEmpty).Do(
             [](NSConsumer * consumer)
             {
                 std::cout << "NSRequestedSubscribeCallback" << std::endl;
-                g_consumer = (NSConsumer *)malloc(sizeof(NSConsumer));
-                strncpy(g_consumer->consumerId , consumer->consumerId, 37);
+                g_consumerID = strdup(consumer->consumerId);
                 responseCon.notify_all();
             });
 
@@ -207,7 +206,7 @@ TEST_F(NotificationProviderTest, ExpectCallbackWhenReceiveSubscribeRequestWithAc
     std::unique_lock< std::mutex > lock{ mutexForCondition };
     responseCon.wait_for(lock, std::chrono::milliseconds(1000));
 
-    EXPECT_NE((void*)g_consumer, (void*)NULL);
+    EXPECT_NE((void*)g_consumerID, (void*)NULL);
 }
 
 TEST_F(NotificationProviderTest, NeverCallNotifyOnConsumerByAcceptIsFalse)
@@ -225,7 +224,7 @@ TEST_F(NotificationProviderTest, NeverCallNotifyOnConsumerByAcceptIsFalse)
                 }
             });
 
-    NSAcceptSubscription(g_consumer, false);
+    NSAcceptSubscription(g_consumerID, false);
 
     NSMessage * msg = NSCreateMessage();
     msgID = (int)msg->messageId;
@@ -244,7 +243,7 @@ TEST_F(NotificationProviderTest, NeverCallNotifyOnConsumerByAcceptIsFalse)
 
     EXPECT_EQ(expectTrue, true);
 
-    NSAcceptSubscription(g_consumer, true);
+    NSAcceptSubscription(g_consumerID, true);
 }
 
 TEST_F(NotificationProviderTest, ExpectCallNotifyOnConsumerByAcceptIsTrue)
@@ -262,7 +261,7 @@ TEST_F(NotificationProviderTest, ExpectCallNotifyOnConsumerByAcceptIsTrue)
                 }
             });
 
-    NSAcceptSubscription(g_consumer, true);
+    NSAcceptSubscription(g_consumerID, true);
 
     NSMessage * msg = NSCreateMessage();
     msgID = (int)msg->messageId;