From 12465ee9340ac0a7c334cba8649409616b427018 Mon Sep 17 00:00:00 2001 From: KIM JungYong Date: Mon, 13 Jun 2016 12:59:03 +0900 Subject: [PATCH] Updated sturcture of consumer. Task type about discover protocol is added. NSMessage_consumer and messageId in NSMessage is updated. messageId in NSMessage handling logic is modified to cause changed variable type. Change-Id: I6454227f40c3406516932eca0ed6d8fb3b6e0e9a Signed-off-by: KIM JungYong Reviewed-on: https://gerrit.iotivity.org/gerrit/8611 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi Tested-by: Uze Choi --- .../examples/linux/notificationconsumer.c | 4 +- service/notification/include/NSCommon.h | 3 + service/notification/src/common/NSConstants.h | 16 +++-- service/notification/src/common/NSUtil.c | 21 +++---- .../notification/src/consumer/NSConsumerCommon.c | 31 +++++----- .../notification/src/consumer/NSConsumerCommon.h | 18 ++++-- .../src/consumer/NSConsumerCommunication.c | 69 ++++++++++++++-------- .../src/consumer/NSConsumerInterface.c | 3 +- .../consumer/NSConsumerInternalTaskController.c | 5 +- .../consumer/cache/linux/NSConsumerMemoryCache.c | 8 ++- 10 files changed, 107 insertions(+), 71 deletions(-) diff --git a/service/notification/examples/linux/notificationconsumer.c b/service/notification/examples/linux/notificationconsumer.c index 778f428..46d0eb8 100644 --- a/service/notification/examples/linux/notificationconsumer.c +++ b/service/notification/examples/linux/notificationconsumer.c @@ -9,7 +9,7 @@ void onNotificationPosted(NSProvider * provider, NSMessage * notification) { printf("Notification from : %s:%d\n", ((OCDevAddr *)provider->mUserData)->addr, ((OCDevAddr *)provider->mUserData)->port); - printf("id : %s\n", notification->messageId); + printf("id : %ld\n", notification->messageId); printf("title : %s\n", notification->title); printf("content : %s\n", notification->contentText); printf("source : %s\n", notification->sourceName); @@ -28,7 +28,7 @@ void onNotificationSync(NSProvider * provider, NSSyncInfo * sync) { printf("Sync from : %s:%d\n", ((OCDevAddr *)provider->mUserData)->addr, ((OCDevAddr *)provider->mUserData)->port); - printf("Sync ID : %s\n", sync->messageId); + printf("Sync ID : %ld\n", sync->messageId); printf("Sync STATE : %d\n", sync->state); } diff --git a/service/notification/include/NSCommon.h b/service/notification/include/NSCommon.h index 33139c4..811b980 100644 --- a/service/notification/include/NSCommon.h +++ b/service/notification/include/NSCommon.h @@ -40,6 +40,9 @@ #define NS_ATTRIBUTE_SOURCE "SOURCE" #define NS_ATTRIBUTE_STATE "STATE" #define NS_ATTRIBUTE_DEVICE "DEVICE" +#define NS_ATTRIBUTE_TYPE "TYPE" +#define NS_ATTRIBUTE_DATETIME "DATE_TIME" +#define NS_ATTRIBUTE_TTL "TTL" /** * Result code of notification service diff --git a/service/notification/src/common/NSConstants.h b/service/notification/src/common/NSConstants.h index 210e958..76f52f3 100644 --- a/service/notification/src/common/NSConstants.h +++ b/service/notification/src/common/NSConstants.h @@ -34,14 +34,18 @@ ((level) == 1) ? "INFO" : \ ((level) == 2) ? "WARNING" : \ ((level) == 3) ? "ERROR" : "FATAL") -#define NS_LOG_V(level, format, ...) { \ +#define NS_LOG_V(level, format, ...) \ + { \ printf("%s: %s ", NS_CONVERT_LEVEL(level), __NS_FILE__); \ printf((format), __VA_ARGS__); \ - printf("\n"); } -#define NS_LOG(level, msg) { \ + printf("\n"); \ + } +#define NS_LOG(level, msg) \ + { \ printf("%s: %s ", NS_CONVERT_LEVEL(level), __NS_FILE__); \ printf((msg)); \ - printf("\n"); } + printf("\n"); \ + } #endif #define NS_TAG "IOT_NOTI" @@ -114,6 +118,10 @@ typedef enum eTaskType TASK_CONSUMER_REQ_SUBSCRIBE_CANCEL = 8003, TASK_CONSUMER_RECV_MESSAGE = 8101, + TASK_CONSUMER_PROVIDER_DISCOVERED = 8201, + TASK_CONSUMER_PROVIDER_DELETED = 8202, + TASK_CONSUMER_RECV_CONFIRM = 8206, + TASK_EVENT_CONNECTED = 9000, TASK_EVENT_DISCONNECTED = 9001, diff --git a/service/notification/src/common/NSUtil.c b/service/notification/src/common/NSUtil.c index ac9205a..ebc7afc 100755 --- a/service/notification/src/common/NSUtil.c +++ b/service/notification/src/common/NSUtil.c @@ -91,8 +91,7 @@ NSResult NSFreeMessage(NSMessage * obj) if (obj->messageId) { - OICFree(obj->messageId); - obj->messageId = NULL; + obj->messageId = 0; } if (obj->title) @@ -130,13 +129,13 @@ NSMessage * NSDuplicateMessage(NSMessage * copyMsg) newMsg = (NSMessage *)OICMalloc(sizeof(NSMessage)); newMsg->contentText = NULL; - newMsg->messageId = NULL; + newMsg->messageId = 0; newMsg->sourceName = NULL; newMsg->title = NULL; if (copyMsg->messageId) { - newMsg->messageId = OICStrdup(copyMsg->messageId); + newMsg->messageId = copyMsg->messageId; } if (copyMsg->title) @@ -166,8 +165,7 @@ NSResult NSFreeSync(NSSyncInfo * obj) if (obj->messageId) { - OICFree(obj->messageId); - obj->messageId = NULL; + obj->messageId = 0; } if (obj->providerId) @@ -193,13 +191,13 @@ NSSyncInfo* NSDuplicateSync(NSSyncInfo * copyMsg) } newMsg = (NSSyncInfo *)OICMalloc(sizeof(NSSyncInfo)); - newMsg->messageId = NULL; + newMsg->messageId = 0; newMsg->providerId = NULL; newMsg->state = -1; if (copyMsg->messageId) { - newMsg->messageId = OICStrdup(copyMsg->messageId); + newMsg->messageId = copyMsg->messageId; } if (copyMsg->providerId) @@ -291,11 +289,11 @@ NSSyncInfo * NSGetSyncInfo(OCPayload * payload) return NULL; } - retSync->messageId = NULL; + retSync->messageId = 0; retSync->state = NS_SYNC_READ; OCRepPayload * repPayload = (OCRepPayload *)payload; - if (!OCRepPayloadGetPropString(repPayload, NS_ATTRIBUTE_MESSAGE_ID, &retSync->messageId)) + if (!OCRepPayloadGetPropInt(repPayload, NS_ATTRIBUTE_MESSAGE_ID, (int64_t *)&retSync->messageId)) { OICFree(retSync); return NULL; @@ -308,14 +306,13 @@ NSSyncInfo * NSGetSyncInfo(OCPayload * payload) int64_t state; if (!OCRepPayloadGetPropInt(repPayload, NS_ATTRIBUTE_STATE, &state)) { - OICFree(retSync->messageId); OICFree(retSync); return NULL; } retSync->state = (NSSyncType) state; - NS_LOG_V(DEBUG, "Sync ID : %s", retSync->messageId); + NS_LOG_V(DEBUG, "Sync ID : %ld", retSync->messageId); NS_LOG_V(DEBUG, "Sync State : %d", (int) retSync->state); NS_LOG(DEBUG, "NSBuildOICNotificationSync - OUT"); diff --git a/service/notification/src/consumer/NSConsumerCommon.c b/service/notification/src/consumer/NSConsumerCommon.c index 7581989..6eab997 100644 --- a/service/notification/src/consumer/NSConsumerCommon.c +++ b/service/notification/src/consumer/NSConsumerCommon.c @@ -174,34 +174,33 @@ NSMessage_consumer * NSCopyMessage(NSMessage_consumer * msg) NS_VERTIFY_NOT_NULL_WITH_POST_CLEANING(newMsg, NULL, OICFree(newMsg)); memcpy(newMsg->addr, msg->addr, sizeof(OCDevAddr)); - newMsg->mId = OICStrdup(msg->mId); - newMsg->mTitle = OICStrdup(msg->mTitle); - newMsg->mContentText = OICStrdup(msg->mContentText); - newMsg->mSource = OICStrdup(msg->mSource); + newMsg->messageId = msg->messageId; + newMsg->title = OICStrdup(msg->title); + newMsg->contentText = OICStrdup(msg->contentText); + newMsg->sourceName = OICStrdup(msg->sourceName); return newMsg; } void NSRemoveMessage(NSMessage_consumer * msg) { - if (msg->mId) + if (msg->messageId) { - OICFree(msg->mId); - msg->mId = NULL; + msg->messageId = 0; } - if (msg->mTitle) + if (msg->title) { - OICFree(msg->mTitle); - msg->mTitle = NULL; + OICFree(msg->title); + msg->title = NULL; } - if (msg->mContentText) + if (msg->contentText) { - OICFree(msg->mContentText); - msg->mContentText = NULL; + OICFree(msg->contentText); + msg->contentText = NULL; } - if (msg->mSource) + if (msg->sourceName) { - OICFree(msg->mSource); - msg->mSource = NULL; + OICFree(msg->sourceName); + msg->sourceName = NULL; } if (msg->addr) { diff --git a/service/notification/src/consumer/NSConsumerCommon.h b/service/notification/src/consumer/NSConsumerCommon.h index 350c704..06d9494 100644 --- a/service/notification/src/consumer/NSConsumerCommon.h +++ b/service/notification/src/consumer/NSConsumerCommon.h @@ -95,16 +95,22 @@ typedef enum typedef struct { // Mandatory - char * mId; - char * mTitle; + uint64_t messageId; + char * providerId; + + //optional + NSMessageType type; + char * dateTime; + uint64_t ttl; + char * title; + char * contentText; + char * sourceName; + NSMediaContents mediaContents; //Optional - char * mContentText; - char * mSource; - OCDevAddr * addr; char * syncUri; - NSConsumerMessageTypes type; + NSConsumerMessageTypes messageTypes; } NSMessage_consumer; bool NSIsStartedConsumer(); diff --git a/service/notification/src/consumer/NSConsumerCommunication.c b/service/notification/src/consumer/NSConsumerCommunication.c index 7e76b65..04cb312 100644 --- a/service/notification/src/consumer/NSConsumerCommunication.c +++ b/service/notification/src/consumer/NSConsumerCommunication.c @@ -89,7 +89,8 @@ OCStackApplicationResult NSConsumerSyncInfoListener( NS_VERTIFY_NOT_NULL(provider, OC_STACK_KEEP_TRANSACTION); newNoti = NSGetNSSyncInfo(clientResponse); - NS_VERTIFY_NOT_NULL(newNoti, OC_STACK_KEEP_TRANSACTION); + NS_VERTIFY_NOT_NULL_WITH_POST_CLEANING( + newNoti, OC_STACK_KEEP_TRANSACTION, OICFree(provider)); NSTaskType taskType = TASK_RECV_READ; @@ -129,7 +130,7 @@ OCStackApplicationResult NSConsumerMessageListener( NS_VERTIFY_NOT_NULL_WITH_POST_CLEANING( newNoti, OC_STACK_KEEP_TRANSACTION, OICFree(provider)); - if (!strcmp(newNoti->mId, NS_MESSAGE_ACCEPTANCE)) + if (newNoti->messageId == 0) { // TODO update provider list. NS_LOG(DEBUG, "Receive Subscribe confirm"); @@ -167,37 +168,50 @@ NSMessage_consumer * NSGetNSMessage(OCClientResponse * clientResponse) { NS_VERTIFY_NOT_NULL(clientResponse->payload, NULL); - NS_LOG(DEBUG, "get id"); + NS_LOG(DEBUG, "get msg id"); OCRepPayload * payload = (OCRepPayload *)clientResponse->payload; - char * id = NULL; - bool getResult = OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_MESSAGE_ID, &id); + uint64_t id = NULL; + bool getResult = OCRepPayloadGetPropInt(payload, NS_ATTRIBUTE_MESSAGE_ID, (int64_t *)&id); + NS_VERTIFY_NOT_NULL(getResult == true ? (void *) 1 : NULL, NULL); + + NS_LOG(DEBUG, "get provider id"); + char * pId = NULL; + getResult = OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_PROVIDER_ID, &pId); NS_VERTIFY_NOT_NULL(getResult == true ? (void *) 1 : NULL, NULL); NS_LOG(DEBUG, "create NSMessage"); NSMessage_consumer * retNoti = (NSMessage_consumer *)OICMalloc(sizeof(NSMessage_consumer)); NS_VERTIFY_NOT_NULL(retNoti, NULL); - retNoti->mId = id; - retNoti->mTitle = NULL; - retNoti->mContentText = NULL; - retNoti->mSource = NULL; + retNoti->messageId = id; + retNoti->providerId = pId; + retNoti->title = NULL; + retNoti->contentText = NULL; + retNoti->sourceName = NULL; - OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_TITLE, &retNoti->mTitle); - OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_TEXT, &retNoti->mContentText); - OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_SOURCE, &retNoti->mSource); + OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_TITLE, &retNoti->title); + OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_TEXT, &retNoti->contentText); + OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_SOURCE, &retNoti->sourceName); + + OCRepPayloadGetPropInt(payload, NS_ATTRIBUTE_TYPE, (int64_t *)&retNoti->type); + OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_DATETIME, &retNoti->dateTime); + OCRepPayloadGetPropInt(payload, NS_ATTRIBUTE_TTL, (int64_t *)&retNoti->ttl); NS_LOG_V(DEBUG, "Msg Address : %s", clientResponse->addr->addr); - NS_LOG_V(DEBUG, "Msg ID : %s", retNoti->mId); - NS_LOG_V(DEBUG, "Msg Title : %s", retNoti->mTitle); - NS_LOG_V(DEBUG, "Msg Content : %s", retNoti->mContentText); - NS_LOG_V(DEBUG, "Msg Source : %s", retNoti->mSource); + NS_LOG_V(DEBUG, "Msg ID : %ld", retNoti->messageId); + NS_LOG_V(DEBUG, "Msg Title : %s", retNoti->title); + NS_LOG_V(DEBUG, "Msg Content : %s", retNoti->contentText); + NS_LOG_V(DEBUG, "Msg Source : %s", retNoti->sourceName); + NS_LOG_V(DEBUG, "Msg Type : %d", retNoti->type); + NS_LOG_V(DEBUG, "Msg Date : %s", retNoti->dateTime); + NS_LOG_V(DEBUG, "Msg ttl : %ld", retNoti->ttl); NS_LOG(DEBUG, "copy target address"); retNoti->addr = (OCDevAddr *)OICMalloc(sizeof(OCDevAddr)); NS_VERTIFY_NOT_NULL(retNoti->addr, NULL); memcpy(retNoti->addr, clientResponse->addr, sizeof(OCDevAddr)); - retNoti->type = Notification; + retNoti->messageTypes = Notification; return retNoti; } @@ -213,9 +227,14 @@ NSSyncInfo * NSGetNSSyncInfo(OCClientResponse * clientResponse) bool getResult = OCRepPayloadGetPropInt(payload, NS_ATTRIBUTE_STATE, & state); NS_VERTIFY_NOT_NULL(getResult == true ? (void *) 1 : NULL, NULL); - NS_LOG(DEBUG, "get id"); - char * id = NULL; - getResult = OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_MESSAGE_ID, &id); + NS_LOG(DEBUG, "get msg id"); + uint64_t id = NULL; + getResult = OCRepPayloadGetPropInt(payload, NS_ATTRIBUTE_MESSAGE_ID, (int64_t *)&id); + NS_VERTIFY_NOT_NULL(getResult == true ? (void *) 1 : NULL, NULL); + + NS_LOG(DEBUG, "get provider id"); + char * pId = NULL; + getResult = OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_PROVIDER_ID, &pId); NS_VERTIFY_NOT_NULL(getResult == true ? (void *) 1 : NULL, NULL); NS_LOG(DEBUG, "create NSSyncInfo"); @@ -224,9 +243,11 @@ NSSyncInfo * NSGetNSSyncInfo(OCClientResponse * clientResponse) retSync->messageId = id; retSync->state = (NSSyncType) state; + retSync->providerId = pId; - NS_LOG_V(DEBUG, "Sync ID : %s", retSync->messageId); + NS_LOG_V(DEBUG, "Sync ID : %ld", retSync->messageId); NS_LOG_V(DEBUG, "Sync State : %d", (int) retSync->state); + NS_LOG_V(DEBUG, "Sync Provider ID : %s", retSync->providerId); return retSync; } @@ -285,11 +306,11 @@ OCRepPayload * NSGetPayloadofSyncInfo(NSMessage_consumer * message, int type) OCRepPayload * payload = OCRepPayloadCreate(); NS_VERTIFY_NOT_NULL(payload, NULL); - OCRepPayloadSetPropString(payload, "ID", (char *) message->mId); + OCRepPayloadSetPropInt(payload, "ID", (int64_t)message->messageId); OCRepPayloadSetPropInt(payload, "STATE", type); - if (message->mSource) + if (message->sourceName) { - OCRepPayloadSetPropString(payload, "SOURCE", (char *) message->mSource); + OCRepPayloadSetPropString(payload, "SOURCE", (char *) message->sourceName); } return payload; diff --git a/service/notification/src/consumer/NSConsumerInterface.c b/service/notification/src/consumer/NSConsumerInterface.c index eba3c94..cb211d6 100644 --- a/service/notification/src/consumer/NSConsumerInterface.c +++ b/service/notification/src/consumer/NSConsumerInterface.c @@ -112,8 +112,7 @@ NSResult NSDropNSObject(NSMessage * obj) if (obj->messageId) { - OICFree(obj->messageId); - obj->messageId = NULL; + obj->messageId = 0; } if (obj->title) diff --git a/service/notification/src/consumer/NSConsumerInternalTaskController.c b/service/notification/src/consumer/NSConsumerInternalTaskController.c index 1cb8038..1ba1d90 100644 --- a/service/notification/src/consumer/NSConsumerInternalTaskController.c +++ b/service/notification/src/consumer/NSConsumerInternalTaskController.c @@ -72,8 +72,8 @@ void NSConsumerSubscriptionTaskProcessing(NSTask * task) { NS_VERTIFY_NOT_NULL_V(task); - NSCacheList * cache; - if (!*(NSGetCacheList())) + NSCacheList * cache = *(NSGetCacheList()); + if (!cache) { NS_LOG(DEBUG, "Cache Init"); cache = NSStorageCreate(); @@ -82,7 +82,6 @@ void NSConsumerSubscriptionTaskProcessing(NSTask * task) cache->cacheType = NS_CONSUMER_CACHE_MESSAGE; NSSetCacheList(cache); } - cache = *(NSGetCacheList()); NSResult ret = NS_ERROR; NS_LOG_V(DEBUG, "Receive Event : %d", (int)task->taskType); diff --git a/service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.c b/service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.c index 5ca69ab..cb6a198 100644 --- a/service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.c +++ b/service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.c @@ -190,7 +190,9 @@ NSResult NSConsumerCacheWriteMessage(NSCacheList * list, NSCacheElement * newObj NSMessage_consumer * newMsgObj = (NSMessage_consumer *) newObj->data; pthread_mutex_unlock(mutex); - NSCacheElement * it = NSStorageRead(list, newMsgObj->mId); + char msgId[] = {0, }; + sprintf(msgId, "%ld", newMsgObj->messageId); + NSCacheElement * it = NSStorageRead(list, msgId); pthread_mutex_lock(mutex); if (it) @@ -288,7 +290,9 @@ bool NSConsumerCompareIdCacheData(NSCacheType type, void * data, const char * id { NSMessage_consumer * msg = (NSMessage_consumer *) data; - if (!strcmp(msg->mId, id)) + char msgId[] = {0, }; + sprintf(msgId, "%ld", msg->messageId); + if (!strcmp(msgId, id)) { return true; } -- 2.7.4