From 2eab9056105d92fb3998de0c64404db5c1bc58c3 Mon Sep 17 00:00:00 2001 From: YounghyunJoo Date: Thu, 7 Jul 2016 15:36:28 +0900 Subject: [PATCH] Modify Consumer Logic - Modify data type for message ID & message TTL (uint64_t: %llu->%lld). - Rename NSConsumerQueueScheduler file name to NSConsumerScheduler. - Modify NSConsumerScheduler to process sync type command for GetProvider. - Add APIs to get message/provider Change-Id: Ie40166fd6674bad162df9ead064a70b7e696ef13 Signed-off-by: YounghyunJoo Reviewed-on: https://gerrit.iotivity.org/gerrit/9193 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi Tested-by: Uze Choi --- .../examples/linux/notificationconsumer.c | 4 +-- service/notification/include/NSConsumerInterface.h | 4 +++ service/notification/src/common/NSConstants.h | 2 +- service/notification/src/common/NSUtil.c | 2 +- .../src/consumer/NSConsumerCommunication.c | 6 ++-- .../src/consumer/NSConsumerInterface.c | 17 ++++++++++- .../consumer/NSConsumerInternalTaskController.c | 35 ++++++++++------------ .../consumer/NSConsumerInternalTaskController.h | 18 +++++++++-- ...sumerQueueScheduler.c => NSConsumerScheduler.c} | 18 ++++++++++- ...sumerQueueScheduler.h => NSConsumerScheduler.h} | 5 ++++ .../consumer/cache/linux/NSConsumerMemoryCache.c | 4 +-- 11 files changed, 81 insertions(+), 34 deletions(-) rename service/notification/src/consumer/{NSConsumerQueueScheduler.c => NSConsumerScheduler.c} (93%) rename service/notification/src/consumer/{NSConsumerQueueScheduler.h => NSConsumerScheduler.h} (89%) diff --git a/service/notification/examples/linux/notificationconsumer.c b/service/notification/examples/linux/notificationconsumer.c index 7a762eb..2ecf765 100644 --- a/service/notification/examples/linux/notificationconsumer.c +++ b/service/notification/examples/linux/notificationconsumer.c @@ -20,7 +20,7 @@ void onSubscriptionAccepted(NSProvider * provider) void onNotificationPosted(NSMessage * notification) { - printf("id : %llu\n", notification->messageId); + printf("id : %lld\n", notification->messageId); printf("title : %s\n", notification->title); printf("content : %s\n", notification->contentText); printf("source : %s\n", notification->sourceName); @@ -29,7 +29,7 @@ void onNotificationPosted(NSMessage * notification) void onNotificationSync(NSSyncInfo * sync) { - printf("Sync ID : %llu\n", sync->messageId); + printf("Sync ID : %lld\n", sync->messageId); printf("Sync STATE : %d\n", sync->state); } diff --git a/service/notification/include/NSConsumerInterface.h b/service/notification/include/NSConsumerInterface.h index ba49e1f..c028820 100644 --- a/service/notification/include/NSConsumerInterface.h +++ b/service/notification/include/NSConsumerInterface.h @@ -105,6 +105,10 @@ NSResult NSUnsubscribe(NSProvider *provider); NSResult NSConsumerSendSyncInfo( const char * providerId, uint64_t messageId, NSSyncType type); +NSProvider * NSConsumerGetProvider(const char * providerId); + +NSMessage * NSConsumerGetMessage(uint64_t messageId); + #ifdef __cplusplus } #endif // __cplusplus diff --git a/service/notification/src/common/NSConstants.h b/service/notification/src/common/NSConstants.h index d313c0e..b8299b1 100644 --- a/service/notification/src/common/NSConstants.h +++ b/service/notification/src/common/NSConstants.h @@ -33,7 +33,7 @@ ((level) == 0) ? "DEBUG" : \ ((level) == 1) ? "INFO" : \ ((level) == 2) ? "WARNING" : \ - ((level) == 3) ? "ERROR" : "FATAL") + ((level) == 3) ? "ERROR" : "FATAL") #define NS_LOG_V(level, format, ...) \ { \ printf("%s: %s ", NS_CONVERT_LEVEL(level), __NS_FILE__); \ diff --git a/service/notification/src/common/NSUtil.c b/service/notification/src/common/NSUtil.c index 57f4730..6945199 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 : %llu", retSync->messageId); + NS_LOG_V(DEBUG, "Sync ID : %lld", retSync->messageId); NS_LOG_V(DEBUG, "Sync State : %d", (int) retSync->state); NS_LOG(DEBUG, "NSGetSyncInfo - OUT"); diff --git a/service/notification/src/consumer/NSConsumerCommunication.c b/service/notification/src/consumer/NSConsumerCommunication.c index 0189b2b..f944caf 100644 --- a/service/notification/src/consumer/NSConsumerCommunication.c +++ b/service/notification/src/consumer/NSConsumerCommunication.c @@ -209,13 +209,13 @@ NSMessage_consumer * NSGetMessage(OCClientResponse * clientResponse) 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 : %llu", retMsg->messageId); + NS_LOG_V(DEBUG, "Msg ID : %lld", 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 : %llu", retMsg->ttl); + NS_LOG_V(DEBUG, "Msg ttl : %lld", retMsg->ttl); return retMsg; } @@ -245,7 +245,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 : %llu", retSync->messageId); + NS_LOG_V(DEBUG, "Sync ID : %lld", retSync->messageId); NS_LOG_V(DEBUG, "Sync State : %d", (int) retSync->state); NS_LOG_V(DEBUG, "Sync Provider ID : %s", retSync->providerId); diff --git a/service/notification/src/consumer/NSConsumerInterface.c b/service/notification/src/consumer/NSConsumerInterface.c index b73adfb..37b4c00 100644 --- a/service/notification/src/consumer/NSConsumerInterface.c +++ b/service/notification/src/consumer/NSConsumerInterface.c @@ -26,7 +26,7 @@ #include "NSCommon.h" #include "NSConsumerCommon.h" #include "NSConstants.h" -#include "NSConsumerQueueScheduler.h" +#include "NSConsumerScheduler.h" #include "oic_malloc.h" #include "oic_string.h" @@ -106,6 +106,21 @@ NSResult NSRescanProvider() return NSConsumerPushEvent(discoverTask); } +NSProvider * NSConsumerGetProvider(const char * providerId) +{ + NS_VERIFY_NOT_NULL(providerId, NULL); + + return (NSProvider *) NSConsumerFindNSProvider(providerId); +} + +NSMessage * NSConsumerGetMessage(uint64_t messageId) +{ + char msgId[NS_DEVICE_ID_LENGTH] = { 0, }; + snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", messageId); + + return (NSMessage *) NSConsumerFindNSMessage(msgId); +} + NSResult NSDropNSMessage(NSMessage * obj) { NS_VERIFY_NOT_NULL(obj, NS_ERROR); diff --git a/service/notification/src/consumer/NSConsumerInternalTaskController.c b/service/notification/src/consumer/NSConsumerInternalTaskController.c index b61e6e0..25e7b71 100644 --- a/service/notification/src/consumer/NSConsumerInternalTaskController.c +++ b/service/notification/src/consumer/NSConsumerInternalTaskController.c @@ -81,9 +81,9 @@ NSMessage_consumer * NSMessageCacheFind(const char * messageId) NSSetMessageCacheList(MessageCache); } - NSMessage_consumer * retMsg = NSStorageRead(MessageCache, messageId); + NSCacheElement * cacheElement = NSStorageRead(MessageCache, messageId); - return retMsg; + return (NSMessage_consumer *) cacheElement->data; } NSProvider_internal * NSProviderCacheFind(const char * providerId) @@ -101,9 +101,9 @@ NSProvider_internal * NSProviderCacheFind(const char * providerId) NSSetMessageCacheList(ProviderCache); } - NSProvider_internal * retMsg = NSStorageRead(ProviderCache, providerId); + NSCacheElement * cacheElement = NSStorageRead(ProviderCache, providerId); - return retMsg; + return (NSProvider_internal *) cacheElement->data; } @@ -175,8 +175,8 @@ void NSConsumerHandleProviderDiscovered(NSProvider_internal * provider) { NS_VERIFY_NOT_NULL_V(provider); - NSCacheElement * cacheElement = NSProviderCacheFind(provider->providerId); - NS_VERIFY_NOT_NULL_V(cacheElement); + NSProvider_internal * providerCacheData = NSProviderCacheFind(provider->providerId); + NS_VERIFY_NOT_NULL_V(!providerCacheData); NS_LOG (ERROR, "New provider is discovered"); NSResult ret = NSProviderCacheUpdate(provider); @@ -202,12 +202,10 @@ void NSConsumerHandleRecvSubscriptionConfirmed(NSMessage_consumer * msg) { NS_VERIFY_NOT_NULL_V(msg); - NSCacheElement * cacheElement = NSMessageCacheFind(msg->providerId); - NS_VERIFY_NOT_NULL_V(cacheElement); - - NSProvider * provider = (NSProvider *) cacheElement->data; + NSProvider_internal * provider = NSProviderCacheFind(msg->providerId); + NS_VERIFY_NOT_NULL_V(provider); - NSSubscriptionAccepted(provider); + NSSubscriptionAccepted((NSProvider *) provider); } void NSConsumerHandleRecvMessage(NSMessage_consumer * msg) @@ -224,16 +222,15 @@ void NSConsumerHandleRecvSyncInfo(NSSyncInfo * sync) { NS_VERIFY_NOT_NULL_V(sync); - NSCacheElement * providerCacheElement = NSProviderCacheFind(sync->providerId); - NS_VERIFY_NOT_NULL_V(providerCacheElement); + NSProvider_internal * provider = NSProviderCacheFind(sync->providerId); + NS_VERIFY_NOT_NULL_V(provider); char msgId[NS_DEVICE_ID_LENGTH] = { 0, }; - snprintf(msgId, NS_DEVICE_ID_LENGTH, "%llu", sync->messageId); + snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", sync->messageId); - NSCacheElement * messageCacheElement = NSMessageCacheFind(msgId); - NS_VERIFY_NOT_NULL_V (messageCacheElement); + NSMessage_consumer * msg = NSMessageCacheFind(msgId); + NS_VERIFY_NOT_NULL_V(msg); - NSMessage_consumer * msg = (NSMessage_consumer *) messageCacheElement->data; NSResult ret = NSMessageCacheUpdate(msg, sync->state); NS_VERIFY_NOT_NULL_V(ret == NS_OK ? (void *) 1 : NULL); @@ -244,9 +241,7 @@ void NSConsumerHandleMakeSyncInfo(NSSyncInfo * sync) { NS_VERIFY_NOT_NULL_V(sync); - NSCacheElement * providerCacheElement = NSProviderCacheFind(sync->providerId); - NS_VERIFY_NOT_NULL_V (providerCacheElement); - NSProvider_internal * provider = (NSProvider_internal *) providerCacheElement->data; + NSProvider_internal * provider = NSProviderCacheFind(sync->providerId); NS_VERIFY_NOT_NULL_V (provider); NSSyncInfo_internal * syncInfo = (NSSyncInfo_internal *)OICMalloc(sizeof(NSSyncInfo_internal)); diff --git a/service/notification/src/consumer/NSConsumerInternalTaskController.h b/service/notification/src/consumer/NSConsumerInternalTaskController.h index 04d3312..0be9f17 100644 --- a/service/notification/src/consumer/NSConsumerInternalTaskController.h +++ b/service/notification/src/consumer/NSConsumerInternalTaskController.h @@ -18,8 +18,8 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -#ifndef _NS_CONSUMER_SUBSCRIPTION_H_ -#define _NS_CONSUMER_SUBSCRIPTION_H_ +#ifndef _NS_CONSUMER_INTERNAL_TASK_CONTROLLER_H_ +#define _NS_CONSUMER_INTERNAL_TASK_CONTROLLER_H_ #ifdef __cplusplus extern "C" { @@ -29,14 +29,26 @@ extern "C" { #include "NSStorageAdapter.h" #include "NSConsumerCommunication.h" +NSCacheList ** NSGetMessageCacheList(); + +void NSSetMessageCacheList(NSCacheList *); + +NSCacheList ** NSGetProviderCacheList(); + +void NSSetProviderCacheList(NSCacheList *); + void NSDestroyMessageCacheList(); void NSDestroyProviderCacheList(); +NSMessage_consumer * NSMessageCacheFind(const char *); + +NSProvider_internal * NSProviderCacheFind(const char *); + void NSConsumerInternalTaskProcessing(NSTask *); #ifdef __cplusplus } #endif // __cplusplus -#endif // _NS_CONSUMER_SUBSCRIPTION_H_ +#endif // _NS_CONSUMER_INTERNAL_TASK_CONTROLLER_H_ diff --git a/service/notification/src/consumer/NSConsumerQueueScheduler.c b/service/notification/src/consumer/NSConsumerScheduler.c similarity index 93% rename from service/notification/src/consumer/NSConsumerQueueScheduler.c rename to service/notification/src/consumer/NSConsumerScheduler.c index 551b1db..e58f3bb 100644 --- a/service/notification/src/consumer/NSConsumerQueueScheduler.c +++ b/service/notification/src/consumer/NSConsumerScheduler.c @@ -18,6 +18,8 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +#include "NSConsumerScheduler.h" + #include #include #include @@ -37,7 +39,6 @@ #include "NSConsumerDiscovery.h" #include "NSConsumerInternalTaskController.h" #include "NSConsumerNetworkEventListener.h" -#include "NSConsumerQueueScheduler.h" #include "NSConsumerSystem.h" void * NSConsumerMsgHandleThreadFunc(void * handle); @@ -112,6 +113,7 @@ NSResult NSConsumerPushEvent(NSTask * task) void NSConsumerMessageHandlerExit() { NSDestroyMessageCacheList(); + NSDestroyProviderCacheList(); NSConsumerListenerTermiate(); NSThreadStop(*(NSGetMsgHandleThreadHandle())); NSDestroyQueue(*(NSGetMsgHandleQueue())); @@ -228,3 +230,17 @@ void NSConsumerTaskProcessing(NSTask * task) break; } } + +NSMessage_consumer * NSConsumerFindNSMessage(const char* messageId) +{ + NS_VERIFY_NOT_NULL(messageId, NULL); + + return NSMessageCacheFind(messageId); +} + +NSProvider_internal * NSConsumerFindNSProvider(const char * providerId) +{ + NS_VERIFY_NOT_NULL(providerId, NULL); + + return NSProviderCacheFind(providerId); +} diff --git a/service/notification/src/consumer/NSConsumerQueueScheduler.h b/service/notification/src/consumer/NSConsumerScheduler.h similarity index 89% rename from service/notification/src/consumer/NSConsumerQueueScheduler.h rename to service/notification/src/consumer/NSConsumerScheduler.h index ee873db..af20bd2 100644 --- a/service/notification/src/consumer/NSConsumerQueueScheduler.h +++ b/service/notification/src/consumer/NSConsumerScheduler.h @@ -31,6 +31,7 @@ extern "C" { #include "ocstack.h" #include "NSCommon.h" #include "NSStructs.h" +#include "NSConsumerCommon.h" NSResult NSConsumerMessageHandlerInit(); @@ -38,6 +39,10 @@ void NSConsumerMessageHandlerExit(); extern NSResult NSConsumerPushEvent(NSTask *); +NSMessage_consumer * NSConsumerFindNSMessage(const char *); + +NSProvider_internal * NSConsumerFindNSProvider(const char *); + #ifdef __cplusplus } #endif // __cplusplus diff --git a/service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.c b/service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.c index f56568f..e4f2b43 100644 --- a/service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.c +++ b/service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.c @@ -210,7 +210,7 @@ NSResult NSConsumerCacheWriteMessage(NSCacheList * list, NSCacheElement * newObj pthread_mutex_unlock(mutex); char msgId[NS_DEVICE_ID_LENGTH] = {0, }; - snprintf(msgId, NS_DEVICE_ID_LENGTH, "%llu", newMsgObj->messageId); + snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", newMsgObj->messageId); NSCacheElement * it = NSStorageRead(list, msgId); pthread_mutex_lock(mutex); @@ -416,7 +416,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, "%llu", msg->messageId); + snprintf(msgId, NS_DEVICE_ID_LENGTH, "%lld", msg->messageId); if (!strcmp(msgId, id)) { return true; -- 2.7.4