implementation NSStopProvider and bug fixed.
[platform/upstream/iotivity.git] / service / notification / src / provider / NSProviderSubscription.c
index 54a27c1..49c76fd 100644 (file)
@@ -37,12 +37,10 @@ NSResult NSSetSubscriptionAcceptPolicy(NSAccessPolicy policy)
 \r
     if (policy == NS_ACCEPTER_PROVIDER)\r
     {\r
-        OIC_LOG(INFO, SUBSCRIPTION_TAG, "Place Provider as a subscription accepter");\r
         NS_LOG(DEBUG, "Place Provider as a subscription accepter");\r
     }\r
     else if (policy == NS_ACCEPTER_CONSUMER)\r
     {\r
-        OIC_LOG(INFO, SUBSCRIPTION_TAG, "Place Consumer as a subscription accepter");\r
         NS_LOG(DEBUG, "Place Consumer as a subscription accepter");\r
     }\r
 \r
@@ -59,7 +57,6 @@ int NSGetSubscriptionAccepter()
 \r
 NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest)\r
 {\r
-    OIC_LOG(DEBUG, NOTIFICATION_TAG, "Send Notification Policy to consumer");\r
     NS_LOG(DEBUG, "NSSendAccessPolicyResponse - IN");\r
 \r
     // put notification resource\r
@@ -67,7 +64,6 @@ NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest
     if (NSPutNotificationResource(NSGetSubscriptionAccepter(), &notificationResourceHandle)\r
             != NS_OK)\r
     {\r
-        OIC_LOG(ERROR, SUBSCRIPTION_TAG, PCF("Failed to put notification resource"));\r
         NS_LOG(ERROR, "Fail to put notification resource");\r
         return NS_ERROR;\r
     }\r
@@ -82,7 +78,6 @@ NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest
     OCRepPayload* payload = OCRepPayloadCreate();\r
     if (!payload)\r
     {\r
-        OIC_LOG(ERROR, SUBSCRIPTION_TAG, PCF("Failed to allocate Payload"));\r
         NS_LOG(ERROR, "payload is NULL");\r
         return NS_ERROR;\r
     }\r
@@ -101,7 +96,6 @@ NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest
     // Send Response\r
     if (OCDoResponse(&response) != OC_STACK_OK)\r
     {\r
-        OIC_LOG(ERROR, SUBSCRIPTION_TAG, PCF("Fail to send response"));\r
         NS_LOG(ERROR, "Fail to AccessPolicy send response");\r
         return NS_ERROR;\r
     }\r
@@ -114,8 +108,6 @@ NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest
 \r
 void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResourceType resourceType)\r
 {\r
-\r
-    OIC_LOG(INFO, SUBSCRIPTION_TAG, "Start to subscription process");\r
     NS_LOG(DEBUG, "NSHandleSubscription - IN");\r
 \r
     if (resourceType == NS_RESOURCE_MESSAGE)\r
@@ -180,7 +172,6 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour
 \r
 void NSHandleUnsubscription(OCEntityHandlerRequest *entityHandlerRequest)\r
 {\r
-    OIC_LOG(INFO, SUBSCRIPTION_TAG, "Start to unsubscription process");\r
     NS_LOG(DEBUG, "NSHandleUnsubscription - IN");\r
 \r
     NSCacheElement * element = (NSCacheElement *) OICMalloc(sizeof(NSCacheElement));\r
@@ -197,7 +188,6 @@ void NSHandleUnsubscription(OCEntityHandlerRequest *entityHandlerRequest)
 \r
     if (NSCacheWrite(consumerSubList, element) != NS_OK)\r
     {\r
-        OIC_LOG(ERROR, SUBSCRIPTION_TAG, "fail to write consumer white list");\r
         NS_LOG(ERROR, "fail to write consumer white list");\r
     }\r
 \r
@@ -207,7 +197,6 @@ void NSHandleUnsubscription(OCEntityHandlerRequest *entityHandlerRequest)
 \r
 void NSAskAcceptanceToUser(OCEntityHandlerRequest *entityHandlerRequest)\r
 {\r
-    OIC_LOG(DEBUG, SUBSCRIPTION_TAG, "Ask for user to Allow or Deny");\r
     NS_LOG(DEBUG, "NSAskAcceptanceToUser - IN");\r
 \r
     NSPushQueue(RESPONSE_SCHEDULER, TASK_CB_SUBSCRIPTION, entityHandlerRequest);\r
@@ -222,7 +211,6 @@ NSResult NSSendResponse(const char * id, bool accepted)
     OCRepPayload* payload = OCRepPayloadCreate();\r
     if (!payload)\r
     {\r
-        OIC_LOG(ERROR, SUBSCRIPTION_TAG, PCF("Failed to allocate Payload"));\r
         NS_LOG(ERROR, "fail to create playload");\r
         return NS_ERROR;\r
     }\r
@@ -230,7 +218,6 @@ NSResult NSSendResponse(const char * id, bool accepted)
     OCResourceHandle rHandle;\r
     if (NSPutMessageResource(NULL, &rHandle) != NS_OK)\r
     {\r
-        OIC_LOG(ERROR, NOTIFICATION_TAG, PCF("Fail to put notification resource"));\r
         NS_LOG(ERROR, "Fail to put notification resource");\r
         return NS_ERROR;\r
     }\r
@@ -251,7 +238,6 @@ NSResult NSSendResponse(const char * id, bool accepted)
     if (OCNotifyListOfObservers(rHandle, (OCObservationId*)&subData->messageObId, 1, payload, OC_HIGH_QOS)\r
             != OC_STACK_OK)\r
     {\r
-        OIC_LOG(ERROR, SUBSCRIPTION_TAG, "fail to send Acceptance");\r
         NS_LOG(ERROR, "fail to send Acceptance");\r
         OCRepPayloadDestroy(payload);\r
         return NS_ERROR;\r
@@ -265,12 +251,11 @@ NSResult NSSendResponse(const char * id, bool accepted)
 \r
 NSResult NSSendSubscriptionResponse(OCEntityHandlerRequest *entityHandlerRequest, bool accepted)\r
 {\r
-    OIC_LOG(INFO, SUBSCRIPTION_TAG, "Send ACCEPT message to consumer");\r
     NS_LOG(DEBUG, "NSSendSubscriptionResponse - IN");\r
 \r
     if (!entityHandlerRequest)\r
     {\r
-        OIC_LOG (ERROR, LISTENER_TAG, "Invalid request pointer");\r
+        NS_LOG(ERROR, "Invalid request pointer");\r
         return OC_EH_ERROR;\r
     }\r
 \r
@@ -289,7 +274,6 @@ NSResult NSSendSubscriptionResponse(OCEntityHandlerRequest *entityHandlerRequest
 \r
         if (NSCacheWrite(consumerSubList, element) != NS_OK)\r
         {\r
-            OIC_LOG(ERROR, SUBSCRIPTION_TAG, "fail to write consumer white list");\r
             NS_LOG(ERROR, "fail to write consumer white list");\r
         }\r
     }\r
@@ -303,10 +287,8 @@ NSResult NSSendSubscriptionResponse(OCEntityHandlerRequest *entityHandlerRequest
 \r
 void * NSSubScriptionSchedule(void *ptr)\r
 {\r
-\r
     if (ptr == NULL)\r
     {\r
-        OIC_LOG(INFO, SUBSCRIPTION_TAG, "Create NSSubscriptionSchedule");\r
         NS_LOG(DEBUG, "Create NSSubScriptionSchedule");\r
     }\r
 \r
@@ -343,32 +325,26 @@ void * NSSubScriptionSchedule(void *ptr)
                     NS_LOG(DEBUG, "CASE TASK_SEND_ALLOW : ");\r
                     NSConsumer * consumer = (NSConsumer *) node->taskData;\r
 \r
-                    NSCacheSubData * subData = (NSCacheSubData *) OICMalloc(sizeof(NSCacheSubData));\r
-                    subData->id = OICStrdup(consumer->mId);\r
-                    subData->isWhite = true;\r
-                    subData->messageObId = 0;\r
-                    subData->syncObId = 0;\r
-\r
-                    NSCacheUpdateSubScriptionState(consumerSubList, subData);\r
-                    NSSendResponse(consumer->mId, true);\r
+                    char * id = OICStrdup(consumer->mDeviceId);\r
 \r
+                    NSCacheUpdateSubScriptionState(consumerSubList, id, true);\r
+                    NSSendResponse(id, true);\r
+                    OICFree(id);\r
+                    NSFreeConsumer(consumer);\r
                     break;\r
                 }\r
                 case TASK_SEND_DENY:\r
                 {\r
                     NS_LOG(DEBUG, "CASE TASK_SEND_DENY : ");\r
                     NSConsumer * consumer = (NSConsumer *) node->taskData;\r
-                    int * pObId = (int *) consumer->mUserData;\r
 \r
-                    NSCacheSubData * subData = (NSCacheSubData *) OICMalloc(sizeof(NSCacheSubData));\r
-                    subData->id = OICStrdup(consumer->mId);\r
-                    subData->isWhite = false;\r
-                    subData->messageObId = 0;\r
-                    subData->syncObId = 0;\r
+                    char * id = OICStrdup(consumer->mDeviceId);\r
+\r
+                    NSCacheUpdateSubScriptionState(consumerSubList, id, false);\r
+                    NSSendResponse(id, false);\r
+                    OICFree(id);\r
+                    NSFreeConsumer(consumer);\r
 \r
-                    NSCacheUpdateSubScriptionState(consumerSubList, subData);\r
-                    printf("observer ID = %d\n", *pObId);\r
-                    NSSendResponse(consumer->mId, false);\r
                     break;\r
                 }\r
                 case TASK_SYNC_SUBSCRIPTION:\r
@@ -386,5 +362,6 @@ void * NSSubScriptionSchedule(void *ptr)
         pthread_mutex_unlock(&NSMutex[SUBSCRIPTION_SCHEDULER]);\r
 \r
     }\r
+    NS_LOG(INFO, "Destroy NSSubScriptionSchedule");\r
     return NULL;\r
 }\r