\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
\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
if (NSPutNotificationResource(NSGetSubscriptionAccepter(), ¬ificationResourceHandle)\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
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
// 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
\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
\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
\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
\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
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
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
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
\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
\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
\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
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
pthread_mutex_unlock(&NSMutex[SUBSCRIPTION_SCHEDULER]);\r
\r
}\r
+ NS_LOG(INFO, "Destroy NSSubScriptionSchedule");\r
return NULL;\r
}\r