From: jaesick.shin Date: Tue, 31 May 2016 08:49:53 +0000 (+0900) Subject: Rename Functions, variables, structs and bug fixed. X-Git-Tag: 1.2.0+RC1~52^2~154 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=036893394112e1512dbb3b23b8b2897745d47136;p=platform%2Fupstream%2Fiotivity.git Rename Functions, variables, structs and bug fixed. This patch included, Rename the Interface API, structs. Add setting OCPayload exception. Second patch included, modified sconscript and Removed NSCacheAdapter.h --> changed NSStorageAdapter. third patch included, remove not required path. remove empty space in sconscript. fourth patch included, NSCallbackSchedule change to NSInterfaceSchedule. Change-Id: I2be68c1917dec9f48139a6986f79569dc7a24ccc Signed-off-by: jaesick.shin Reviewed-on: https://gerrit.iotivity.org/gerrit/8393 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi Tested-by: Uze Choi --- diff --git a/service/notification/SConscript b/service/notification/SConscript index f61a60a..8dbaf5c 100644 --- a/service/notification/SConscript +++ b/service/notification/SConscript @@ -45,7 +45,6 @@ target_os = env.get('TARGET_OS') notification_env.AppendUnique(CPPPATH = ['include']) notification_env.AppendUnique(CPPPATH = ['src/common']) notification_env.AppendUnique(CPPPATH = ['src/provider']) -notification_env.AppendUnique(CPPPATH = ['src/provider/cache/linux']) notification_env.AppendUnique(CPPPATH = ['src/consumer']) notification_env.AppendUnique(CPPPATH = ['../../resource/csdk/stack/include']) notification_env.AppendUnique(CPPPATH = ['../../resource/csdk/connectivity/api']) @@ -54,9 +53,10 @@ if target_os == 'linux': notification_env.AppendUnique(CPPPATH = ['src/provider/cache/linux']) notification_env.AppendUnique(CPPPATH = ['src/consumer/cache/linux']) -if target_os == 'android': - notification_env.AppendUnique(CPPPATH = ['src/provider/cache/android']) - notification_env.AppendUnique(CPPPATH = ['src/consumer/cache/android']) +# [TO-DO] change to android DB. +if target_os == 'android': + notification_env.AppendUnique(CPPPATH = ['src/provider/cache/linux']) + notification_env.AppendUnique(CPPPATH = ['src/consumer/cache/linux']) notification_env.PrependUnique(LIBS = [ 'octbstack', @@ -77,7 +77,7 @@ if target_os == 'linux': if target_os == 'android': notification_env.AppendUnique(CCFLAGS = ['-frtti', '-fexceptions']) notification_env.AppendUnique(LIBS = ['gnustl_shared','log']) - notification_env.AppendUnique(LINKFLAGS = ['-Wl,-soname,libnotification_provider.so']) + notification_env.AppendUnique(LINKFLAGS = ['-Wl,-soname,libnotification_provider.so']) if not env.get('RELEASE'): notification_env.AppendUnique(LIBS = ['log']) diff --git a/service/notification/examples/linux/notificationprovider.c b/service/notification/examples/linux/notificationprovider.c index 8f47ff2..079b7da 100644 --- a/service/notification/examples/linux/notificationprovider.c +++ b/service/notification/examples/linux/notificationprovider.c @@ -143,7 +143,7 @@ int main() msg->mContentText = OICStrdup(body); msg->mSource = NULL; - NSSendNotification(msg); + NSSendMessage(msg); break; diff --git a/service/notification/include/NSCommon.h b/service/notification/include/NSCommon.h index eb0642e..56c9121 100644 --- a/service/notification/include/NSCommon.h +++ b/service/notification/include/NSCommon.h @@ -59,6 +59,8 @@ typedef enum eResult */ typedef enum eAccessPolicy { + NS_ACCESS_ALLOW = 0, + NS_ACCESS_DENY = 1, NS_ACCEPTER_PROVIDER = 0, NS_ACCEPTER_CONSUMER = 1, diff --git a/service/notification/include/NSProviderInterface.h b/service/notification/include/NSProviderInterface.h index f5c5578..b4ea0d7 100644 --- a/service/notification/include/NSProviderInterface.h +++ b/service/notification/include/NSProviderInterface.h @@ -71,7 +71,7 @@ NSResult NSStopProvider(); * @param[in] message Notification message including id, title, contentText * @return ::NS_OK or result code of NSResult */ -NSResult NSSendNotification(NSMessage *msg); +NSResult NSSendMessage(NSMessage *msg); /** * Send acceptance to consumer who subscribes the resource of notification message @@ -94,7 +94,7 @@ NSResult NSAccept(NSConsumer *consumer, bool accepted); * @param[in] message Notification message to synchronize the status * @return ::NS_OK or result code of NSResult */ -NSResult NSProviderReadCheck(NSMessage *); +NSResult NSReadCheck(NSMessage *); #ifdef __cplusplus } diff --git a/service/notification/src/common/NSConstants.h b/service/notification/src/common/NSConstants.h index c75d16c..40c6273 100644 --- a/service/notification/src/common/NSConstants.h +++ b/service/notification/src/common/NSConstants.h @@ -81,13 +81,12 @@ typedef enum eConnectionState typedef enum eSchedulerType { - CALLBACK_SCHEDULER = 0, + INTERFACE_SCHEDULER = 0, DISCOVERY_SCHEDULER = 1, SUBSCRIPTION_SCHEDULER = 2, NOTIFICATION_SCHEDULER = 3, } NSSchedulerType; - typedef enum eTaskType { TASK_REGISTER_RESOURCE = 1000, diff --git a/service/notification/src/common/NSCacheAdapter.h b/service/notification/src/common/NSStorageAdapter.h old mode 100755 new mode 100644 similarity index 69% rename from service/notification/src/common/NSCacheAdapter.h rename to service/notification/src/common/NSStorageAdapter.h index c87a05c..27aff40 --- a/service/notification/src/common/NSCacheAdapter.h +++ b/service/notification/src/common/NSStorageAdapter.h @@ -18,8 +18,8 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -#ifndef _NS_CACHEADAPTER__H_ -#define _NS_CACHEADAPTER__H_ +#ifndef _NS_STORAGEADAPTER__H_ +#define _NS_STORAGEADAPTER__H_ #include "logger.h" #include @@ -29,10 +29,10 @@ #include "NSStructs.h" #include "NSConstants.h" -NSCacheList * NSCacheCreate(); -NSCacheElement * NSCacheRead(NSCacheList * list, const char * findId); -NSResult NSCacheWrite(NSCacheList * list, NSCacheElement * newObj); -NSResult NSCacheDelete(NSCacheList * list, const char * delId); -NSResult NSCacheDestroy(NSCacheList * list); +NSCacheList * NSStorageCreate(); +NSCacheElement * NSStorageRead(NSCacheList * list, const char * findId); +NSResult NSStorageWrite(NSCacheList * list, NSCacheElement * newObj); +NSResult NSStorageDelete(NSCacheList * list, const char * delId); +NSResult NSStorageDestroy(NSCacheList * list); -#endif /* _NS_CACHEADAPTER__H_ */ +#endif /* _NS_STORAGEADAPTER__H_ */ diff --git a/service/notification/src/common/NSUtil.c b/service/notification/src/common/NSUtil.c index a4253c8..a5eeea2 100755 --- a/service/notification/src/common/NSUtil.c +++ b/service/notification/src/common/NSUtil.c @@ -172,6 +172,7 @@ NSResult NSFreeSync(NSSync * obj) if (obj->mSourceId) { + NS_LOG_V(DEBUG, "obj->mSourceid = %s", obj->mSourceId); OICFree(obj->mSourceId); obj->mSourceId = NULL; } @@ -206,6 +207,8 @@ NSSync* NSDuplicateSync(NSSync * copyMsg) newMsg->mSourceId = OICStrdup(copyMsg->mSourceId); } + newMsg->mState = copyMsg->mState; + return newMsg; } @@ -259,3 +262,63 @@ NSConsumer* NSDuplicateConsumer(NSConsumer * copyMsg) return newMsg; } + +void NSDuplicateSetPropertyString(OCRepPayload** msgPayload, const char * name, + const char * copyString) +{ + if(copyString) + { + OCRepPayloadSetPropString(*msgPayload, name, copyString); + } + else + { + OCRepPayloadSetNull(*msgPayload, name); + } +} + + +NSSync * NSGetSyncInfo(OCPayload * payload) +{ + NS_LOG(DEBUG, "NSBuildOICNotificationSync - IN"); + + if(!payload) + { + return NULL; + } + NSSync * retSync = (NSSync *)OICMalloc(sizeof(NSSync)); + if (!retSync) + { + return NULL; + } + + retSync->mMessageId = NULL; + retSync->mState = Notification_Read; + + OCRepPayload * repPayload = (OCRepPayload *)payload; + if (!OCRepPayloadGetPropString(repPayload, NS_ATTRIBUTE_ID, &retSync->mMessageId)) + { + OICFree(retSync); + return NULL; + } + if (!OCRepPayloadGetPropString(repPayload, NS_ATTRIBUTE_SOURCE, &retSync->mSourceId)) + { + OICFree(retSync); + return NULL; + } + int64_t state; + if (!OCRepPayloadGetPropInt(repPayload, NS_ATTRIBUTE_STATE, & state)) + { + OICFree(retSync->mMessageId); + OICFree(retSync); + return NULL; + } + + retSync->mState = (NSSyncTypes) state; + + NS_LOG_V(DEBUG, "Sync ID : %s", retSync->mMessageId); + NS_LOG_V(DEBUG, "Sync State : %d", (int) retSync->mState); + + NS_LOG(DEBUG, "NSBuildOICNotificationSync - OUT"); + + return retSync; +} diff --git a/service/notification/src/common/NSUtil.h b/service/notification/src/common/NSUtil.h index a99a011..5d59cf8 100755 --- a/service/notification/src/common/NSUtil.h +++ b/service/notification/src/common/NSUtil.h @@ -40,8 +40,13 @@ NSMessage * NSDuplicateMessage(NSMessage *); NSResult NSFreeSync(NSSync *); NSSync * NSDuplicateSync(NSSync *); +NSSync * NSGetSyncInfo(OCPayload * payload); NSResult NSFreeConsumer(NSConsumer *); NSConsumer * NSDuplicateConsumer(NSConsumer *); +void NSDuplicateSetPropertyString(OCRepPayload **, const char *, const char *); + + + #endif /* _NS_UTIL__H_ */ diff --git a/service/notification/src/consumer/NSConsumerNotification.c b/service/notification/src/consumer/NSConsumerNotification.c index d19ea9b..c2cb116 100644 --- a/service/notification/src/consumer/NSConsumerNotification.c +++ b/service/notification/src/consumer/NSConsumerNotification.c @@ -307,6 +307,7 @@ void NSConsumerNotificationTaskProcessing(NSTask * task) int type = (task->taskType == TASK_SEND_READ) ? 0 : 1; OCRepPayloadSetPropString(payload, "ID", (char *) nsConsumer->mId); + OCRepPayloadSetPropString(payload, "SOURCE", (char *) nsConsumer->mSource); OCRepPayloadSetPropInt(payload, "STATE", type); // TODO fix param for uri diff --git a/service/notification/src/consumer/NSConsumerSubsription.c b/service/notification/src/consumer/NSConsumerSubsription.c index 791320a..9d8d3ca 100644 --- a/service/notification/src/consumer/NSConsumerSubsription.c +++ b/service/notification/src/consumer/NSConsumerSubsription.c @@ -43,7 +43,7 @@ void NSDestroyCacheList() cache = *(NSGetCacheList()); if (!cache) { - NSCacheDestroy(cache); + NSStorageDestroy(cache); } } @@ -60,7 +60,7 @@ NSResult NSCacheUpdate(NSCacheList * cache, NSTask * task, NSConsumerMessageType obj->data = (NSCacheData *) noti; obj->next = NULL; - if (NS_OK != NSCacheWrite(cache, obj)) + if (NS_OK != NSStorageWrite(cache, obj)) { NS_LOG(ERROR, "Cache write fail"); return NS_ERROR; @@ -84,7 +84,7 @@ void NSConsumerSubscriptionTaskProcessing(NSTask * task) if (!*(NSGetCacheList())) { NS_LOG(DEBUG, "Cache Init"); - cache = NSCacheCreate(); + cache = NSStorageCreate(); cache->cacheType = NS_CONSUMER_CACHE_MESSAGE; if (!cache) { diff --git a/service/notification/src/consumer/NSConsumerSubsription.h b/service/notification/src/consumer/NSConsumerSubsription.h index f303c49..4aee268 100644 --- a/service/notification/src/consumer/NSConsumerSubsription.h +++ b/service/notification/src/consumer/NSConsumerSubsription.h @@ -26,7 +26,7 @@ extern "C" { #endif // __cplusplus #include "NSStructs.h" -#include "NSCacheAdapter.h" +#include "../common/NSStorageAdapter.h" #include "NSConsumerNotification.h" void NSDestroyCacheList(); diff --git a/service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.c b/service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.c index 67617a0..5ca69ab 100644 --- a/service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.c +++ b/service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.c @@ -33,7 +33,7 @@ void NSSetCacheMutex(pthread_mutex_t mutex) *(NSGetCacheMutex()) = mutex; } -NSCacheList * NSCacheCreate() +NSCacheList * NSStorageCreate() { pthread_mutex_t * mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(mutex, NULL); @@ -58,7 +58,7 @@ NSCacheList * NSCacheCreate() return newList; } -NSCacheElement * NSCacheRead(NSCacheList * list, const char * findId) +NSCacheElement * NSStorageRead(NSCacheList * list, const char * findId) { pthread_mutex_t * mutex = NSGetCacheMutex(); @@ -89,7 +89,7 @@ NSCacheElement * NSCacheRead(NSCacheList * list, const char * findId) return NULL; } -NSResult NSCacheWrite(NSCacheList * list, NSCacheElement * newObj) +NSResult NSStorageWrite(NSCacheList * list, NSCacheElement * newObj) { pthread_mutex_t * mutex = NSGetCacheMutex(); @@ -117,7 +117,7 @@ NSResult NSCacheWrite(NSCacheList * list, NSCacheElement * newObj) return NS_ERROR; } -NSResult NSCacheDelete(NSCacheList * list, const char * delId) +NSResult NSStorageDelete(NSCacheList * list, const char * delId) { pthread_mutex_t * mutex = NSGetCacheMutex(); @@ -190,7 +190,7 @@ NSResult NSConsumerCacheWriteMessage(NSCacheList * list, NSCacheElement * newObj NSMessage_consumer * newMsgObj = (NSMessage_consumer *) newObj->data; pthread_mutex_unlock(mutex); - NSCacheElement * it = NSCacheRead(list, newMsgObj->mId); + NSCacheElement * it = NSStorageRead(list, newMsgObj->mId); pthread_mutex_lock(mutex); if (it) @@ -245,7 +245,7 @@ NSResult NSConsumerCacheWriteMessage(NSCacheList * list, NSCacheElement * newObj return NS_OK; } -NSResult NSCacheDestroy(NSCacheList * list) +NSResult NSStorageDestroy(NSCacheList * list) { pthread_mutex_t * mutex = NSGetCacheMutex(); diff --git a/service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.h b/service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.h index ad3dc74..19c3f11 100644 --- a/service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.h +++ b/service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.h @@ -28,7 +28,7 @@ extern "C" { #include #include #include -#include "NSCacheAdapter.h" +#include "NSStorageAdapter.h" #include "NSConsumerCommon.h" diff --git a/service/notification/src/provider/NSProviderInterface.c b/service/notification/src/provider/NSProviderInterface.c index f6c3078..ccf4747 100644 --- a/service/notification/src/provider/NSProviderInterface.c +++ b/service/notification/src/provider/NSProviderInterface.c @@ -21,9 +21,9 @@ #include "NSProviderInterface.h" #include "NSProviderScheduler.h" #include "NSProviderListener.h" -#include "NSCacheAdapter.h" #include "NSProviderSubscription.h" #include "NSProviderNotification.h" +#include "NSStorageAdapter.h" #include "NSProviderMemoryCache.h" #include "oic_malloc.h" #include "oic_string.h" @@ -82,7 +82,7 @@ NSResult NSStartProvider(NSAccessPolicy policy, NSSubscribeRequestCallback subsc { NS_LOG(DEBUG, "Init Provider"); initProvider = true; - NSSetSubscriptionAcceptPolicy(policy); + NSSetSubscriptionAccessPolicy(policy); NSRegisterSubscribeRequestCb(subscribeRequestCb); NSRegisterSyncCb(syncCb); CARegisterNetworkMonitorHandler(NSProviderAdapterStateListener, @@ -127,8 +127,8 @@ NSResult NSStopProvider() NSRegisterSubscribeRequestCb((NSSubscribeRequestCallback)NULL); NSRegisterSyncCb((NSSyncCallback)NULL); NSStopScheduler(); - NSCacheDestroy(consumerSubList); - NSCacheDestroy(messageList); + NSStorageDestroy(consumerSubList); + NSStorageDestroy(messageList); initProvider = false; } @@ -138,7 +138,7 @@ NSResult NSStopProvider() return NS_OK; } -NSResult NSSendNotification(NSMessage *msg) +NSResult NSSendMessage(NSMessage *msg) { NS_LOG(DEBUG, "NSSendNotification - IN"); @@ -161,7 +161,7 @@ NSResult NSSendNotification(NSMessage *msg) return NS_OK; } -NSResult NSProviderReadCheck(NSMessage *msg) +NSResult NSReadCheck(NSMessage *msg) { NS_LOG(DEBUG, "NSProviderReadCheck - IN"); @@ -197,22 +197,22 @@ NSResult NSAccept(NSConsumer *consumer, bool accepted) return NS_OK; } -void * NSCallbackSchedule(void * ptr) +void * NSInterfaceSchedule(void * ptr) { if (ptr == NULL) { NS_LOG(DEBUG, "Create NSReponseSchedule"); } - while (NSIsRunning[CALLBACK_SCHEDULER]) + while (NSIsRunning[INTERFACE_SCHEDULER]) { - sem_wait(&NSSemaphore[CALLBACK_SCHEDULER]); - pthread_mutex_lock(&NSMutex[CALLBACK_SCHEDULER]); + sem_wait(&NSSemaphore[INTERFACE_SCHEDULER]); + pthread_mutex_lock(&NSMutex[INTERFACE_SCHEDULER]); - if (NSHeadMsg[CALLBACK_SCHEDULER] != NULL) + if (NSHeadMsg[INTERFACE_SCHEDULER] != NULL) { - NSTask *node = NSHeadMsg[CALLBACK_SCHEDULER]; - NSHeadMsg[CALLBACK_SCHEDULER] = node->nextTask; + NSTask *node = NSHeadMsg[INTERFACE_SCHEDULER]; + NSHeadMsg[INTERFACE_SCHEDULER] = node->nextTask; switch (node->taskType) { @@ -235,7 +235,8 @@ void * NSCallbackSchedule(void * ptr) { NS_LOG(DEBUG, "CASE TASK_CB_SYNC : "); NSSync * sync = (NSSync*)node->taskData; - NSSyncCb(sync); + NSSyncCb(NSDuplicateSync(sync)); + NSFreeSync(sync); break; } default: @@ -245,7 +246,7 @@ void * NSCallbackSchedule(void * ptr) OICFree(node); } - pthread_mutex_unlock(&NSMutex[CALLBACK_SCHEDULER]); + pthread_mutex_unlock(&NSMutex[INTERFACE_SCHEDULER]); } diff --git a/service/notification/src/provider/NSProviderListener.c b/service/notification/src/provider/NSProviderListener.c index abb7a6f..cb76c94 100644 --- a/service/notification/src/provider/NSProviderListener.c +++ b/service/notification/src/provider/NSProviderListener.c @@ -309,7 +309,7 @@ OCEntityHandlerResult NSEntityHandlerSyncCb(OCEntityHandlerFlag flag, NS_LOG(DEBUG, "NSEntityHandlerSyncCb - OC_REST_POST"); NSPushQueue(NOTIFICATION_SCHEDULER, TASK_RECV_READ, - NSBuildOICNotificationSync(entityHandlerRequest->payload)); + NSGetSyncInfo(entityHandlerRequest->payload)); ehResult = OC_EH_OK; } else if (OC_REST_DELETE == entityHandlerRequest->method) @@ -439,44 +439,3 @@ void NSProviderAdapterStateListener(CATransportAdapter_t adapter, bool enabled) NS_LOG(DEBUG, "NSProviderAdapterStateListener - OUT"); } -NSSync * NSBuildOICNotificationSync(OCPayload * payload) -{ - NS_LOG(DEBUG, "NSBuildOICNotificationSync - IN"); - - if(!payload) - { - return NULL; - } - NSSync * retSync = (NSSync *)OICMalloc(sizeof(NSSync)); - if (!retSync) - { - return NULL; - } - - retSync->mMessageId = NULL; - retSync->mState = Notification_Read; - - OCRepPayload * repPayload = (OCRepPayload *)payload; - if (!OCRepPayloadGetPropString(repPayload, NS_ATTRIBUTE_ID, &retSync->mMessageId)) - { - OICFree(retSync); - return NULL; - } - int64_t state; - if (!OCRepPayloadGetPropInt(repPayload, NS_ATTRIBUTE_STATE, & state)) - { - OICFree(retSync->mMessageId); - OICFree(retSync); - return NULL; - } - - retSync->mState = (NSSyncTypes) state; - - NS_LOG_V(DEBUG, "Sync ID : %s", retSync->mMessageId); - NS_LOG_V(DEBUG, "Sync State : %d", (int) retSync->mState); - - NS_LOG(DEBUG, "NSBuildOICNotificationSync - OUT"); - - return retSync; -} - diff --git a/service/notification/src/provider/NSProviderListener.h b/service/notification/src/provider/NSProviderListener.h index 2d8b065..77f9b22 100644 --- a/service/notification/src/provider/NSProviderListener.h +++ b/service/notification/src/provider/NSProviderListener.h @@ -33,6 +33,7 @@ #include "oic_string.h" #include "oic_malloc.h" #include "NSUtil.h" +#include "NSStorageAdapter.h" OCEntityHandlerResult NSEntityHandlerNotificationCb(OCEntityHandlerFlag flag, OCEntityHandlerRequest *entityHandlerRequest, void* callback); @@ -50,6 +51,4 @@ void NSProviderAdapterStateListener(CATransportAdapter_t adapter, bool enabled); NSResult NSMakeTask(NSTaskType type, OCEntityHandlerRequest *request, NSTask * task); -NSSync * NSBuildOICNotificationSync(OCPayload * payload); - #endif /* _NS_PROVIDER_LISTENER__H_ */ diff --git a/service/notification/src/provider/NSProviderNotification.c b/service/notification/src/provider/NSProviderNotification.c index d12a435..902b6d4 100644 --- a/service/notification/src/provider/NSProviderNotification.c +++ b/service/notification/src/provider/NSProviderNotification.c @@ -24,16 +24,16 @@ NSResult NSInitMessageList() { NS_LOG(DEBUG, "NSInitMessageList - IN"); - messageList = NSCacheCreate(); + messageList = NSStorageCreate(); messageList->cacheType = NS_PROVIDER_CACHE_MESSAGE; NS_LOG(DEBUG, "NSInitMessageList - OUT"); return NS_OK; } -NSResult NSGetMessagePayload(NSMessage *msg, OCRepPayload** msgPayload) +NSResult NSSetMessagePayload(NSMessage *msg, OCRepPayload** msgPayload) { - NS_LOG(DEBUG, "NSGetMessagePayload - IN"); + NS_LOG(DEBUG, "NSSetMessagePayload - IN"); *msgPayload = OCRepPayloadCreate(); @@ -44,22 +44,19 @@ NSResult NSGetMessagePayload(NSMessage *msg, OCRepPayload** msgPayload) } OCRepPayloadSetUri(*msgPayload, NS_COLLECTION_MESSAGE_URI); - if(msg->mId) - OCRepPayloadSetPropString(*msgPayload, NS_ATTRIBUTE_ID, msg->mId); - if(msg->mTitle) - OCRepPayloadSetPropString(*msgPayload, NS_ATTRIBUTE_TITLE, msg->mTitle); - if(msg->mContentText) - OCRepPayloadSetPropString(*msgPayload, NS_ATTRIBUTE_TEXT, msg->mContentText); - if(msg->mSource) - OCRepPayloadSetPropString(*msgPayload, NS_ATTRIBUTE_SOURCE, msg->mSource); - - NS_LOG(DEBUG, "NSGetMessagePayload - OUT"); + + NSDuplicateSetPropertyString(msgPayload, NS_ATTRIBUTE_ID, msg->mId); + NSDuplicateSetPropertyString(msgPayload, NS_ATTRIBUTE_TITLE, msg->mTitle); + NSDuplicateSetPropertyString(msgPayload, NS_ATTRIBUTE_TEXT, msg->mContentText); + NSDuplicateSetPropertyString(msgPayload, NS_ATTRIBUTE_SOURCE, msg->mSource); + + NS_LOG(DEBUG, "NSSetMessagePayload - OUT"); return NS_OK; } -NSResult NSGetSyncPayload(NSSync *sync, OCRepPayload** syncPayload) +NSResult NSSetSyncPayload(NSSync *sync, OCRepPayload** syncPayload) { - NS_LOG(DEBUG, "NSGetSyncPayload - IN"); + NS_LOG(DEBUG, "NSSetSyncPayload - IN"); *syncPayload = OCRepPayloadCreate(); @@ -70,17 +67,17 @@ NSResult NSGetSyncPayload(NSSync *sync, OCRepPayload** syncPayload) } OCRepPayloadSetUri(*syncPayload, NS_COLLECTION_SYNC_URI); - if(sync->mMessageId) - { - OCRepPayloadSetPropString(*syncPayload, NS_ATTRIBUTE_ID, sync->mMessageId); - OCRepPayloadSetPropInt(*syncPayload, NS_ATTRIBUTE_STATE, sync->mState); - } - NS_LOG(DEBUG, "NSGetSyncPayload - OUT"); + NSDuplicateSetPropertyString(syncPayload, NS_ATTRIBUTE_ID, sync->mMessageId); + NSDuplicateSetPropertyString(syncPayload, NS_ATTRIBUTE_SOURCE, sync->mSourceId); + + OCRepPayloadSetPropInt(*syncPayload, NS_ATTRIBUTE_STATE, sync->mState); + + NS_LOG(DEBUG, "NSSetSyncPayload - OUT"); return NS_OK; } -NSResult NSSendMessage(NSMessage *msg) +NSResult NSSendNotification(NSMessage *msg) { NS_LOG(DEBUG, "NSSendMessage - IN"); @@ -102,7 +99,7 @@ NSResult NSSendMessage(NSMessage *msg) OCRepPayload* payload; - if (NSGetMessagePayload(msg, &payload) != NS_OK) + if (NSSetMessagePayload(msg, &payload) != NS_OK) { NS_LOG(ERROR, "fail to Get message payload"); return NS_ERROR; @@ -181,7 +178,7 @@ NSResult NSSendSync(NSSync *sync) } OCRepPayload* payload; - if (NSGetSyncPayload(sync, &payload) != NS_OK) + if (NSSetSyncPayload(sync, &payload) != NS_OK) { NS_LOG(ERROR, "Failed to allocate payload"); return NS_ERROR; @@ -235,17 +232,18 @@ void * NSNotificationSchedule(void *ptr) case TASK_SEND_NOTIFICATION: { NS_LOG(DEBUG, "CASE TASK_SEND_NOTIFICATION : "); - NSSendMessage((NSMessage *)node->taskData); + NSSendNotification((NSMessage *)node->taskData); break; } case TASK_SEND_READ: NS_LOG(DEBUG, "CASE TASK_SEND_READ : "); NSSendSync((NSSync*) node->taskData); + NSFreeSync((NSSync*) node->taskData); break; case TASK_RECV_READ: NS_LOG(DEBUG, "CASE TASK_RECV_READ : "); NSSendSync((NSSync*) node->taskData); - NSPushQueue(CALLBACK_SCHEDULER, TASK_CB_SYNC, node->taskData); + NSPushQueue(INTERFACE_SCHEDULER, TASK_CB_SYNC, node->taskData); break; default: diff --git a/service/notification/src/provider/NSProviderNotification.h b/service/notification/src/provider/NSProviderNotification.h index 8570cd3..7133e3e 100644 --- a/service/notification/src/provider/NSProviderNotification.h +++ b/service/notification/src/provider/NSProviderNotification.h @@ -22,7 +22,6 @@ #define _NS_PROVIDER_NOTIFICATION_H_ #include -#include "NSCacheAdapter.h" #include "logger.h" #include "NSProviderScheduler.h" #include "NSProviderListener.h" diff --git a/service/notification/src/provider/NSProviderScheduler.c b/service/notification/src/provider/NSProviderScheduler.c index f4a4da4..820f9b2 100755 --- a/service/notification/src/provider/NSProviderScheduler.c +++ b/service/notification/src/provider/NSProviderScheduler.c @@ -29,7 +29,7 @@ bool NSIsRunning[THREAD_COUNT] = NSTask* NSHeadMsg[THREAD_COUNT]; NSTask* NSTailMsg[THREAD_COUNT]; -void * NSCallbackSchedule(void *ptr); +void * NSInterfaceSchedule(void *ptr); void * NSDiscoverySchedule(void *ptr); void * NSSubScriptionSchedule(void *ptr); void * NSNotificationSchedule(void *ptr); @@ -62,10 +62,10 @@ bool NSStartScheduler() switch (i) { - case CALLBACK_SCHEDULER: + case INTERFACE_SCHEDULER: { NS_LOG(DEBUG, "CASE RESPONSE_SCHEDULER :"); - pthread_create(&NSThread[i], NULL, NSCallbackSchedule, NULL); + pthread_create(&NSThread[i], NULL, NSInterfaceSchedule, NULL); } break; @@ -184,7 +184,7 @@ void NSFreeData(NSSchedulerType type, NSTask * task) { NS_LOG(DEBUG, "NSFreeData - IN"); - if (type == CALLBACK_SCHEDULER) + if (type == INTERFACE_SCHEDULER) { switch (task->taskType) { diff --git a/service/notification/src/provider/NSProviderSubscription.c b/service/notification/src/provider/NSProviderSubscription.c index 873f3f9..85a20ff 100644 --- a/service/notification/src/provider/NSProviderSubscription.c +++ b/service/notification/src/provider/NSProviderSubscription.c @@ -24,27 +24,27 @@ NSResult NSInitSubscriptionList() { NS_LOG(DEBUG, "NSInitSubscriptionList - IN"); - consumerSubList = NSCacheCreate(); + consumerSubList = NSStorageCreate(); consumerSubList->cacheType = NS_PROVIDER_CACHE_SUBSCRIBER; NS_LOG(DEBUG, "NSInitSubscriptionList - OUT"); return NS_OK; } -NSResult NSSetSubscriptionAcceptPolicy(NSAccessPolicy policy) +NSResult NSSetSubscriptionAccessPolicy(NSAccessPolicy access) { NS_LOG(DEBUG, "NSSetSubscriptionAcceptPolicy - IN"); - if (policy == NS_ACCEPTER_PROVIDER) + if (access == NS_ACCESS_ALLOW) { NS_LOG(DEBUG, "Place Provider as a subscription accepter"); } - else if (policy == NS_ACCEPTER_CONSUMER) + else if (access == NS_ACCESS_DENY) { NS_LOG(DEBUG, "Place Consumer as a subscription accepter"); } - NSSubscriptionAccepter = policy; + NSSubscriptionAccess = access; NS_LOG(DEBUG, "NSSetSubscriptionAcceptPolicy - OUT"); return NS_OK; @@ -52,7 +52,7 @@ NSResult NSSetSubscriptionAcceptPolicy(NSAccessPolicy policy) int NSGetSubscriptionAccepter() { - return NSSubscriptionAccepter; + return NSSubscriptionAccess; } NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest) @@ -127,7 +127,7 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour NS_LOG_V(DEBUG, "SubList IP[ID] = [%s]", subData->id); NS_LOG_V(DEBUG, "SubList message observation ID = [%d]", subData->messageObId); - if (NSCacheWrite(consumerSubList, element) != NS_OK) + if (NSStorageWrite(consumerSubList, element) != NS_OK) { NS_LOG(DEBUG, "fail to write cache"); } @@ -161,7 +161,7 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour NS_LOG_V(DEBUG, "SubList IP[ID] = [%s]", subData->id); NS_LOG_V(DEBUG, "SubList sync observation ID = [%d]", subData->syncObId); - if (NSCacheWrite(consumerSubList, element) != NS_OK) + if (NSStorageWrite(consumerSubList, element) != NS_OK) { NS_LOG(ERROR, "Fail to write cache"); } @@ -186,7 +186,7 @@ void NSHandleUnsubscription(OCEntityHandlerRequest *entityHandlerRequest) NS_LOG_V(DEBUG, "SubList IP[ID] = [%s]", subData->id); NS_LOG_V(DEBUG, "SubList observation ID = [%d]", subData->syncObId); - if (NSCacheWrite(consumerSubList, element) != NS_OK) + if (NSStorageWrite(consumerSubList, element) != NS_OK) { NS_LOG(ERROR, "fail to write consumer white list"); } @@ -199,7 +199,7 @@ void NSAskAcceptanceToUser(OCEntityHandlerRequest *entityHandlerRequest) { NS_LOG(DEBUG, "NSAskAcceptanceToUser - IN"); - NSPushQueue(CALLBACK_SCHEDULER, TASK_CB_SUBSCRIPTION, entityHandlerRequest); + NSPushQueue(INTERFACE_SCHEDULER, TASK_CB_SUBSCRIPTION, entityHandlerRequest); NS_LOG(DEBUG, "NSAskAcceptanceToUser - OUT"); } @@ -226,7 +226,7 @@ NSResult NSSendResponse(const char * id, bool accepted) OCRepPayloadSetPropString(payload, NS_ATTRIBUTE_ID, "0000-0000-0000-0000"); OCRepPayloadSetPropBool(payload, NS_ATTRIBUTE_ACCPETANCE, accepted); - NSCacheElement * element = NSCacheRead(consumerSubList, id); + NSCacheElement * element = NSStorageRead(consumerSubList, id); if(element == NULL) { @@ -272,7 +272,7 @@ NSResult NSSendSubscriptionResponse(OCEntityHandlerRequest *entityHandlerRequest element->data = (void*) subData; element->next = NULL; - if (NSCacheWrite(consumerSubList, element) != NS_OK) + if (NSStorageWrite(consumerSubList, element) != NS_OK) { NS_LOG(ERROR, "fail to write consumer white list"); } diff --git a/service/notification/src/provider/NSProviderSubscription.h b/service/notification/src/provider/NSProviderSubscription.h index 4f27a20..a26f51a 100644 --- a/service/notification/src/provider/NSProviderSubscription.h +++ b/service/notification/src/provider/NSProviderSubscription.h @@ -28,15 +28,15 @@ #include "NSConstants.h" #include "NSProviderScheduler.h" #include "NSProviderResource.h" -#include "NSCacheAdapter.h" #include "NSProviderMemoryCache.h" #include "oic_string.h" +#include "oic_malloc.h" -NSAccessPolicy NSSubscriptionAccepter; +NSAccessPolicy NSSubscriptionAccess; NSCacheList * consumerSubList; NSResult NSInitSubscriptionList(); -NSResult NSSetSubscriptionAcceptPolicy(NSAccessPolicy policy); +NSResult NSSetSubscriptionAccessPolicy(NSAccessPolicy policy); int NSGetSubscriptionAccepter(); NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest); void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResourceType resourceType); diff --git a/service/notification/src/provider/cache/linux/NSProviderMemoryCache.c b/service/notification/src/provider/cache/linux/NSProviderMemoryCache.c index 374afd2..f66d7e8 100755 --- a/service/notification/src/provider/cache/linux/NSProviderMemoryCache.c +++ b/service/notification/src/provider/cache/linux/NSProviderMemoryCache.c @@ -17,9 +17,10 @@ // limitations under the License. // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + #include "NSProviderMemoryCache.h" -NSCacheList * NSCacheCreate() +NSCacheList * NSStorageCreate() { pthread_mutex_lock(&NSCacheMutex); NSCacheList * newList = (NSCacheList *) OICMalloc(sizeof(NSCacheList)); @@ -38,7 +39,7 @@ NSCacheList * NSCacheCreate() return newList; } -NSCacheElement * NSCacheRead(NSCacheList * list, const char * findId) +NSCacheElement * NSStorageRead(NSCacheList * list, const char * findId) { pthread_mutex_lock(&NSCacheMutex); @@ -86,7 +87,7 @@ NSResult NSCacheUpdateSubScriptionState(NSCacheList * list, char * id, bool stat } pthread_mutex_unlock(&NSCacheMutex); - NSCacheElement * it = NSCacheRead(list, id); + NSCacheElement * it = NSStorageRead(list, id); pthread_mutex_lock(&NSCacheMutex); if (it) @@ -120,7 +121,7 @@ NSResult NSCacheUpdateSubScriptionState(NSCacheList * list, char * id, bool stat return NS_ERROR; } -NSResult NSCacheWrite(NSCacheList * list, NSCacheElement * newObj) +NSResult NSStorageWrite(NSCacheList * list, NSCacheElement * newObj) { pthread_mutex_lock(&NSCacheMutex); @@ -142,7 +143,7 @@ NSResult NSCacheWrite(NSCacheList * list, NSCacheElement * newObj) NSCacheSubData * subData = (NSCacheSubData *) newObj->data; pthread_mutex_unlock(&NSCacheMutex); - NSCacheElement * it = NSCacheRead(list, subData->id); + NSCacheElement * it = NSStorageRead(list, subData->id); pthread_mutex_lock(&NSCacheMutex); if (it) @@ -187,7 +188,7 @@ NSResult NSCacheWrite(NSCacheList * list, NSCacheElement * newObj) NSCacheMsgData * msgData = (NSCacheMsgData *) newObj->data; - NSCacheElement * it = NSCacheRead(list, msgData->id); + NSCacheElement * it = NSStorageRead(list, msgData->id); if (it) { NSCacheMsgData * itData = (NSCacheMsgData *) it->data; @@ -218,7 +219,7 @@ NSResult NSCacheWrite(NSCacheList * list, NSCacheElement * newObj) return NS_OK; } -NSResult NSCacheDelete(NSCacheList * list, const char * delId) +NSResult NSStorageDelete(NSCacheList * list, const char * delId) { pthread_mutex_lock(&NSCacheMutex); NSCacheElement * prev = list->head; @@ -264,7 +265,7 @@ NSResult NSCacheDelete(NSCacheList * list, const char * delId) return NS_OK; } -NSResult NSCacheDestroy(NSCacheList * list) +NSResult NSStorageDestroy(NSCacheList * list) { NSCacheElement * iter = list->head; NSCacheElement * next = NULL; diff --git a/service/notification/src/provider/cache/linux/NSProviderMemoryCache.h b/service/notification/src/provider/cache/linux/NSProviderMemoryCache.h index 1668722..096d18b 100755 --- a/service/notification/src/provider/cache/linux/NSProviderMemoryCache.h +++ b/service/notification/src/provider/cache/linux/NSProviderMemoryCache.h @@ -21,17 +21,16 @@ #ifndef _NS_PROVIDER_CACHEADAPTER__H_ #define _NS_PROVIDER_CACHEADAPTER__H_ -#include -#include #include -#include "logger.h" -#include "ocstack.h" -#include "ocpayload.h" -#include "NSStructs.h" +#include +#include + +#include "NSCommon.h" #include "NSConstants.h" -#include "NSCacheAdapter.h" +#include "NSStructs.h" #include "oic_malloc.h" #include "oic_string.h" +#include "NSStorageAdapter.h" #include "NSUtil.h" NSResult NSProviderDeleteCacheData(NSCacheType, void *); diff --git a/service/notification/unittest/NSProviderTest.cpp b/service/notification/unittest/NSProviderTest.cpp index 22f8421..41c7fab 100644 --- a/service/notification/unittest/NSProviderTest.cpp +++ b/service/notification/unittest/NSProviderTest.cpp @@ -200,7 +200,7 @@ TEST_F(NotificationProviderTest, NeverCallNotifyOnConsumerByAcceptIsFalse) msg->mId = strdup(std::string("NeverCallNotifyOnConsumerByAcceptIsFalse").c_str()); msg->mTitle = strdup(std::string("Title").c_str()); msg->mContentText = strdup(std::string("ContentText").c_str()); - NSSendNotification(msg); + NSSendMessage(msg); { std::unique_lock< std::mutex > lock{ mutexForCondition }; responseCon.wait_for(lock, g_waitForResponse); @@ -230,7 +230,7 @@ TEST_F(NotificationProviderTest, ExpectCallNotifyOnConsumerByAcceptIsTrue) msg->mId = strdup(std::string("ExpectCallNotifyOnConsumerByAcceptIsTrue").c_str()); msg->mTitle = strdup(std::string("Title").c_str()); msg->mContentText = strdup(std::string("ContentText").c_str()); - NSSendNotification(msg); + NSSendMessage(msg); { std::unique_lock< std::mutex > lock{ mutexForCondition }; responseCon.wait_for(lock, g_waitForResponse);