From a8ae4f8ef81e7940c7ee4347777bb666cc17a4ea Mon Sep 17 00:00:00 2001 From: KIM JungYong Date: Fri, 22 Jul 2016 11:19:01 +0900 Subject: [PATCH] Added logic for remove NSProvider. When subscribe cancel API called by user, information of target provider need to be removed in storage. NSProvider is removed when user call subscribe cancel API. Conflicts: service/notification/src/consumer/NSConsumerCommunication.c Change-Id: I480f2253d3eb52af62bab01235ba5cb2888fda8a Signed-off-by: KIM JungYong Reviewed-on: https://gerrit.iotivity.org/gerrit/9493 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi Tested-by: Uze Choi --- .../examples/linux/notificationconsumer.c | 4 ++-- service/notification/include/NSCommon.h | 2 ++ service/notification/src/common/NSStructs.h | 1 + service/notification/src/common/NSUtil.c | 2 +- service/notification/src/consumer/NSConsumerCommon.c | 9 +++++---- service/notification/src/consumer/NSConsumerCommon.h | 4 +--- .../src/consumer/NSConsumerCommunication.c | 19 +++++-------------- .../notification/src/consumer/NSConsumerInterface.c | 2 +- .../src/consumer/NSConsumerInternalTaskController.c | 11 ++++++++--- .../notification/src/consumer/NSConsumerScheduler.c | 11 ++++++++++- .../src/consumer/cache/linux/NSConsumerMemoryCache.c | 4 ++-- 11 files changed, 38 insertions(+), 31 deletions(-) diff --git a/service/notification/examples/linux/notificationconsumer.c b/service/notification/examples/linux/notificationconsumer.c index 9d526e7..4d72807 100644 --- a/service/notification/examples/linux/notificationconsumer.c +++ b/service/notification/examples/linux/notificationconsumer.c @@ -33,7 +33,7 @@ void onSubscriptionAccepted(NSProvider * provider) void onNotificationPosted(NSMessage * notification) { - printf("id : %lld\n", notification->messageId); + printf("id : %lld\n", (long long int)notification->messageId); printf("title : %s\n", notification->title); printf("content : %s\n", notification->contentText); printf("source : %s\n", notification->sourceName); @@ -42,7 +42,7 @@ void onNotificationPosted(NSMessage * notification) void onNotificationSync(NSSyncInfo * sync) { - printf("Sync ID : %lld\n", sync->messageId); + printf("Sync ID : %lld\n", (long long int)sync->messageId); printf("Sync STATE : %d\n", sync->state); } diff --git a/service/notification/include/NSCommon.h b/service/notification/include/NSCommon.h index e5c64bb..41beb5d 100644 --- a/service/notification/include/NSCommon.h +++ b/service/notification/include/NSCommon.h @@ -27,6 +27,8 @@ #ifndef _NS_COMMON_H_ #define _NS_COMMON_H_ +#include + #define NS_ATTRIBUTE_POLICY "ACCEPTER" #define NS_ATTRIBUTE_MESSAGE "MESSAGE_URI" #define NS_ATTRIBUTE_SYNC "SYNC_URI" diff --git a/service/notification/src/common/NSStructs.h b/service/notification/src/common/NSStructs.h index 777113a..47e30ed 100644 --- a/service/notification/src/common/NSStructs.h +++ b/service/notification/src/common/NSStructs.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "NSCommon.h" #include "NSConstants.h" diff --git a/service/notification/src/common/NSUtil.c b/service/notification/src/common/NSUtil.c index 6945199..5b6f41b 100755 --- a/service/notification/src/common/NSUtil.c +++ b/service/notification/src/common/NSUtil.c @@ -272,7 +272,7 @@ NSSyncInfo * NSGetSyncInfo(OCPayload * payload) OICFree(providerId); NS_LOG_V(DEBUG, "Provider ID : %s", retSync->providerId); - NS_LOG_V(DEBUG, "Sync ID : %lld", retSync->messageId); + NS_LOG_V(DEBUG, "Sync ID : %lld", (long long int)retSync->messageId); NS_LOG_V(DEBUG, "Sync State : %d", (int) retSync->state); NS_LOG(DEBUG, "NSGetSyncInfo - OUT"); diff --git a/service/notification/src/consumer/NSConsumerCommon.c b/service/notification/src/consumer/NSConsumerCommon.c index 87b3d40..2004680 100644 --- a/service/notification/src/consumer/NSConsumerCommon.c +++ b/service/notification/src/consumer/NSConsumerCommon.c @@ -241,9 +241,6 @@ NSMessage_consumer * NSCopyMessage(NSMessage_consumer * msg) NS_VERIFY_NOT_NULL(newMsg, NULL); OICStrcpy(newMsg->providerId, NS_DEVICE_ID_LENGTH, msg->providerId); - newMsg->i_addr = (OCDevAddr *)OICMalloc(sizeof(OCDevAddr)); - NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(newMsg, NULL, NSOICFree(newMsg)); - memcpy(newMsg->i_addr, msg->i_addr, sizeof(OCDevAddr)); newMsg->messageId = msg->messageId; newMsg->title = OICStrdup(msg->title); @@ -261,7 +258,10 @@ void NSRemoveMessage(NSMessage_consumer * msg) NSOICFree(msg->title); NSOICFree(msg->contentText); NSOICFree(msg->sourceName); - NSOICFree(msg->i_addr); + NSOICFree(msg->dateTime); + + // TODO change to remove function. + NSOICFree(msg->mediaContents); NSOICFree(msg); } @@ -312,6 +312,7 @@ NSProviderConnectionInfo * NSCopyProviderConnections(NSProviderConnectionInfo * NSProviderConnectionInfo * tmp = conn; NSProviderConnectionInfo * retInfo = NSCreateProviderConnections(tmp->addr); + NS_VERIFY_NOT_NULL(retInfo, NULL); tmp = tmp->next; NSProviderConnectionInfo * copyInfo = retInfo; diff --git a/service/notification/src/consumer/NSConsumerCommon.h b/service/notification/src/consumer/NSConsumerCommon.h index d2d4f3e..d1e9272 100644 --- a/service/notification/src/consumer/NSConsumerCommon.h +++ b/service/notification/src/consumer/NSConsumerCommon.h @@ -181,10 +181,8 @@ typedef struct char * title; char * contentText; char * sourceName; - NSMediaContents mediaContents; + NSMediaContents * mediaContents; - OCDevAddr * i_addr; - NSSyncType i_messageTypes; } NSMessage_consumer; bool NSIsStartedConsumer(); diff --git a/service/notification/src/consumer/NSConsumerCommunication.c b/service/notification/src/consumer/NSConsumerCommunication.c index 274e007..249828a 100644 --- a/service/notification/src/consumer/NSConsumerCommunication.c +++ b/service/notification/src/consumer/NSConsumerCommunication.c @@ -204,19 +204,11 @@ NSMessage_consumer * NSGetMessage(OCClientResponse * clientResponse) NS_LOG_V (DEBUG, "provider id: %s", pId); NS_VERIFY_NOT_NULL(getResult == true ? (void *) 1 : NULL, NULL); - NS_LOG(DEBUG, "get provider address"); - OCDevAddr * addr = (OCDevAddr *)OICMalloc(sizeof(OCDevAddr)); - NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(addr, NULL, NSGetMessagePostClean(pId, addr)); - memcpy(addr, clientResponse->addr, sizeof(OCDevAddr)); - NS_LOG(DEBUG, "create NSMessage"); NSMessage_consumer * retMsg = NSCreateMessage_internal(id, pId); - NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(retMsg, NULL, NSGetMessagePostClean(pId, addr)); + NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(retMsg, NULL, NSOICFree(pId)); NSOICFree(pId); - retMsg->i_addr = addr; - retMsg->i_messageTypes = NS_SYNC_UNREAD; - NS_LOG(DEBUG, "get msg optional field"); OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_TITLE, &retMsg->title); OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_TEXT, &retMsg->contentText); @@ -226,14 +218,13 @@ NSMessage_consumer * NSGetMessage(OCClientResponse * clientResponse) OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_DATETIME, &retMsg->dateTime); OCRepPayloadGetPropInt(payload, NS_ATTRIBUTE_TTL, (int64_t *)&retMsg->ttl); - NS_LOG_V(DEBUG, "Msg Address : %s", retMsg->i_addr->addr); - NS_LOG_V(DEBUG, "Msg ID : %lld", retMsg->messageId); + NS_LOG_V(DEBUG, "Msg ID : %lld", (long long int)retMsg->messageId); NS_LOG_V(DEBUG, "Msg Title : %s", retMsg->title); NS_LOG_V(DEBUG, "Msg Content : %s", retMsg->contentText); NS_LOG_V(DEBUG, "Msg Source : %s", retMsg->sourceName); NS_LOG_V(DEBUG, "Msg Type : %d", retMsg->type); NS_LOG_V(DEBUG, "Msg Date : %s", retMsg->dateTime); - NS_LOG_V(DEBUG, "Msg ttl : %lld", retMsg->ttl); + NS_LOG_V(DEBUG, "Msg ttl : %lld", (long long int)retMsg->ttl); return retMsg; } @@ -263,7 +254,7 @@ NSSyncInfo * NSGetSyncInfoc(OCClientResponse * clientResponse) NSSyncInfo * retSync = NSCreateSyncInfo_consumer(id, pId, (NSSyncType)state); NS_VERIFY_NOT_NULL(retSync, NULL); - NS_LOG_V(DEBUG, "Sync ID : %lld", retSync->messageId); + NS_LOG_V(DEBUG, "Sync ID : %lld", (long long int)retSync->messageId); NS_LOG_V(DEBUG, "Sync State : %d", (int) retSync->state); NS_LOG_V(DEBUG, "Sync Provider ID : %s", retSync->providerId); @@ -283,7 +274,7 @@ NSMessage_consumer * NSCreateMessage_internal(uint64_t id, const char * provider retMsg->type = NS_MESSAGE_INFO; retMsg->dateTime = NULL; retMsg->ttl = 0; - retMsg->i_addr = NULL; + retMsg->mediaContents = NULL; return retMsg; } diff --git a/service/notification/src/consumer/NSConsumerInterface.c b/service/notification/src/consumer/NSConsumerInterface.c index 4425ac1..60cf0c3 100644 --- a/service/notification/src/consumer/NSConsumerInterface.c +++ b/service/notification/src/consumer/NSConsumerInterface.c @@ -124,7 +124,7 @@ NSProvider * NSConsumerGetProvider(const char * providerId) NSMessage * NSConsumerGetMessage(uint64_t messageId) { char msgId[NS_DEVICE_ID_LENGTH] = { 0, }; - snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", messageId); + snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", (long long int)messageId); return (NSMessage *) NSConsumerFindNSMessage(msgId); } diff --git a/service/notification/src/consumer/NSConsumerInternalTaskController.c b/service/notification/src/consumer/NSConsumerInternalTaskController.c index 8e8f7a0..a00e42a 100644 --- a/service/notification/src/consumer/NSConsumerInternalTaskController.c +++ b/service/notification/src/consumer/NSConsumerInternalTaskController.c @@ -237,8 +237,13 @@ void NSConsumerHandleProviderDiscovered(NSProvider_internal * provider) void NSConsumerHandleProviderDeleted(NSProvider_internal * provider) { - // TODO delete provider infomation on storage list. - (void) provider; + NS_VERIFY_NOT_NULL_V(provider); + + NSCacheList * providerCache = *(NSGetProviderCacheList()); + NS_VERIFY_NOT_NULL_V(providerCache); + + NSResult ret = NSStorageDelete(providerCache, provider->providerId); + NS_VERIFY_NOT_NULL_V(ret == NS_OK ? (void *)1 : NULL); } void NSConsumerHandleRecvSubscriptionConfirmed(NSMessage_consumer * msg) @@ -270,7 +275,7 @@ void NSConsumerHandleRecvSyncInfo(NSSyncInfo * sync) NS_VERIFY_NOT_NULL_V(sync); char msgId[NS_DEVICE_ID_LENGTH] = { 0, }; - snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", sync->messageId); + snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", (long long int)sync->messageId); NSMessage_consumer * msg = NSMessageCacheFind(msgId); NS_VERIFY_NOT_NULL_V(msg); diff --git a/service/notification/src/consumer/NSConsumerScheduler.c b/service/notification/src/consumer/NSConsumerScheduler.c index 82a9740..6e1ccf7 100644 --- a/service/notification/src/consumer/NSConsumerScheduler.c +++ b/service/notification/src/consumer/NSConsumerScheduler.c @@ -212,12 +212,21 @@ void NSConsumerTaskProcessing(NSTask * task) break; } case TASK_CONSUMER_REQ_SUBSCRIBE: - case TASK_CONSUMER_REQ_SUBSCRIBE_CANCEL: case TASK_SEND_SYNCINFO: { NSConsumerCommunicationTaskProcessing(task); break; } + case TASK_CONSUMER_REQ_SUBSCRIBE_CANCEL: + { + NSProvider_internal * data = NSCopyProvider((NSProvider_internal *)task->taskData); + NS_VERIFY_NOT_NULL_V(data); + NSTask * conTask = NSMakeTask(TASK_CONSUMER_REQ_SUBSCRIBE_CANCEL, data); + NS_VERIFY_NOT_NULL_V(conTask); + NSConsumerCommunicationTaskProcessing(task); + NSConsumerInternalTaskProcessing(conTask); + break; + } case TASK_RECV_SYNCINFO: case TASK_CONSUMER_RECV_MESSAGE: case TASK_CONSUMER_PROVIDER_DISCOVERED: diff --git a/service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.c b/service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.c index 81fb11a..56fc5c7 100644 --- a/service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.c +++ b/service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.c @@ -211,7 +211,7 @@ NSResult NSConsumerCacheWriteMessage(NSCacheList * list, NSCacheElement * newObj pthread_mutex_unlock(mutex); char msgId[NS_DEVICE_ID_LENGTH] = {0, }; - snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", newMsgObj->messageId); + snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", (long long int)newMsgObj->messageId); NSCacheElement * it = NSStorageRead(list, msgId); pthread_mutex_lock(mutex); @@ -427,7 +427,7 @@ bool NSConsumerCompareIdCacheData(NSCacheType type, void * data, const char * id NSMessage_consumer * msg = (NSMessage_consumer *) data; char msgId[NS_DEVICE_ID_LENGTH] = {0, }; - snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", msg->messageId); + snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", (long long int)msg->messageId); if (!strcmp(msgId, id)) { return true; -- 2.7.4