Add condition about provider initialize.
authorjaesick.shin <jaesick.shin@samsung.com>
Fri, 23 Sep 2016 07:55:58 +0000 (16:55 +0900)
committerUze Choi <uzchoi@samsung.com>
Mon, 26 Sep 2016 10:23:46 +0000 (10:23 +0000)
This patch include,
It added the code to verify that the provider is already started.

Second patch include,
modify invalid return type.

Change-Id: Ib3038f8cc2c74ab465a6178eac56d1f8e508a238
Signed-off-by: jaesick.shin <jaesick.shin@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/12173
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: JungYong KIM <jyong2.kim@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/notification/src/provider/NSProviderInterface.c

index b2ea382..09ccb18 100644 (file)
@@ -198,7 +198,7 @@ NSResult NSSendMessage(NSMessage * msg)
 
     pthread_mutex_lock(&nsInitMutex);
 
-    if(msg == NULL)
+    if (!initProvider || msg == NULL)
     {
         NS_LOG(ERROR, "Msg is NULL");
         pthread_mutex_unlock(&nsInitMutex);
@@ -219,6 +219,13 @@ NSResult NSProviderSendSyncInfo(uint64_t messageId, NSSyncType type)
     NS_LOG(DEBUG, "NSProviderReadCheck - IN");
     pthread_mutex_lock(&nsInitMutex);
 
+    if (!initProvider)
+    {
+        NS_LOG(ERROR, "Provider is not started");
+        pthread_mutex_unlock(&nsInitMutex);
+        return NS_FAIL;
+    }
+
     NSSyncInfo * syncInfo = (NSSyncInfo *)OICMalloc(sizeof(NSSyncInfo));
     OICStrcpy(syncInfo->providerId, UUID_STRING_SIZE, NSGetProviderInfo()->providerId);
     syncInfo->messageId = messageId;
@@ -235,9 +242,9 @@ NSResult NSAcceptSubscription(const char * consumerId, bool accepted)
     NS_LOG(DEBUG, "NSAccept - IN");
     pthread_mutex_lock(&nsInitMutex);
 
-    if(!consumerId || consumerId[0] == '\0' || NSGetPolicy() == NS_POLICY_CONSUMER)
+    if(!initProvider || !consumerId || consumerId[0] == '\0' || NSGetPolicy() == NS_POLICY_CONSUMER)
     {
-        NS_LOG(ERROR, "consumerId is NULL or NS Policy is Consumer");
+        NS_LOG(ERROR, "Provider is not started or consumerId is NULL or NS Policy is Consumer");
         pthread_mutex_unlock(&nsInitMutex);
         return NS_FAIL;
     }
@@ -278,9 +285,9 @@ NSTopicLL * NSProviderGetConsumerTopics(const char * consumerId)
     NS_LOG(DEBUG, "NSProviderGetConsumerTopics - IN");
     pthread_mutex_lock(&nsInitMutex);
 
-    if(!consumerId || consumerId[0] == '\0')
+    if(!initProvider || !consumerId || consumerId[0] == '\0')
     {
-        NS_LOG(DEBUG, "consumer id should be set");
+        NS_LOG(DEBUG, "Provider is not started or consumer id should be set");
         pthread_mutex_unlock(&nsInitMutex);
         return NULL;
     }
@@ -304,6 +311,13 @@ NSTopicLL * NSProviderGetTopics()
     NS_LOG(DEBUG, "NSProviderGetTopics - IN");
     pthread_mutex_lock(&nsInitMutex);
 
+    if (!initProvider)
+    {
+        NS_LOG(ERROR, "Provider is not started");
+        pthread_mutex_unlock(&nsInitMutex);
+        return NULL;
+    }
+
     NSTopicSynchronization topics;
     topics.consumerId = NULL;
     topics.topics = NULL;
@@ -322,10 +336,10 @@ NSResult NSProviderRegisterTopic(const char * topicName)
     NS_LOG(DEBUG, "NSProviderAddTopics - IN");
     pthread_mutex_lock(&nsInitMutex);
 
-    if(!topicName || topicName[0] == '\0')
+    if(!initProvider || !topicName || topicName[0] == '\0')
     {
         pthread_mutex_unlock(&nsInitMutex);
-        NS_LOG(DEBUG, "topic Name should be set");
+        NS_LOG(DEBUG, "Provider is not started or topic Name should be set");
         return NS_FAIL;
     }
 
@@ -341,10 +355,10 @@ NSResult NSProviderUnregisterTopic(const char * topicName)
     NS_LOG(DEBUG, "NSProviderDeleteTopics - IN");
     pthread_mutex_lock(&nsInitMutex);
 
-    if(!topicName || topicName[0] == '\0')
+    if(!initProvider || !topicName || topicName[0] == '\0')
     {
         pthread_mutex_unlock(&nsInitMutex);
-        NS_LOG(DEBUG, "topic Name should be set");
+        NS_LOG(DEBUG, "Provider is not started or topic Name should be set");
         return NS_FAIL;
     }
 
@@ -360,9 +374,11 @@ NSResult NSProviderSetConsumerTopic(const char * consumerId, const char * topicN
     NS_LOG(DEBUG, "NSProviderSelectTopics - IN");
     pthread_mutex_lock(&nsInitMutex);
 
-    if(!consumerId || consumerId[0] == '\0' || !topicName || topicName[0] == '\0' || !NSGetPolicy())
+    if(!initProvider || !consumerId || consumerId[0] == '\0' || !topicName || topicName[0] == '\0'
+            || !NSGetPolicy())
     {
-        NS_LOG(DEBUG, "consumer id should be set for topic subscription or "
+        NS_LOG(DEBUG, "provider is not started or "
+                "consumer id should be set for topic subscription or "
                 "Configuration must set to true.");
         pthread_mutex_unlock(&nsInitMutex);
         return NS_FAIL;
@@ -386,9 +402,11 @@ NSResult NSProviderUnsetConsumerTopic(const char * consumerId, const char * topi
     NS_LOG(DEBUG, "NSProviderUnselectTopics - IN");
     pthread_mutex_lock(&nsInitMutex);
 
-    if(!consumerId || consumerId[0] == '\0' || !topicName || topicName[0] == '\0' || !NSGetPolicy())
+    if(!initProvider || !consumerId || consumerId[0] == '\0' || !topicName || topicName[0] == '\0'
+            || !NSGetPolicy())
     {
-        NS_LOG(DEBUG, "consumer id should be set for topic subscription or "
+        NS_LOG(DEBUG, "provider is not started or "
+                "consumer id should be set for topic subscription or "
                 "Configuration must set to true.");
         pthread_mutex_unlock(&nsInitMutex);
         return NS_FAIL;