Rename Functions, variables, structs and bug fixed. 93/8393/5
authorjaesick.shin <jaesick.shin@samsung.com>
Tue, 31 May 2016 08:49:53 +0000 (17:49 +0900)
committerUze Choi <uzchoi@samsung.com>
Wed, 1 Jun 2016 06:50:55 +0000 (06:50 +0000)
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 <jaesick.shin@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8393
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
24 files changed:
service/notification/SConscript
service/notification/examples/linux/notificationprovider.c
service/notification/include/NSCommon.h
service/notification/include/NSProviderInterface.h
service/notification/src/common/NSConstants.h
service/notification/src/common/NSStorageAdapter.h [moved from service/notification/src/common/NSCacheAdapter.h with 69% similarity, mode: 0644]
service/notification/src/common/NSUtil.c
service/notification/src/common/NSUtil.h
service/notification/src/consumer/NSConsumerNotification.c
service/notification/src/consumer/NSConsumerSubsription.c
service/notification/src/consumer/NSConsumerSubsription.h
service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.c
service/notification/src/consumer/cache/linux/NSConsumerMemoryCache.h
service/notification/src/provider/NSProviderInterface.c
service/notification/src/provider/NSProviderListener.c
service/notification/src/provider/NSProviderListener.h
service/notification/src/provider/NSProviderNotification.c
service/notification/src/provider/NSProviderNotification.h
service/notification/src/provider/NSProviderScheduler.c
service/notification/src/provider/NSProviderSubscription.c
service/notification/src/provider/NSProviderSubscription.h
service/notification/src/provider/cache/linux/NSProviderMemoryCache.c
service/notification/src/provider/cache/linux/NSProviderMemoryCache.h
service/notification/unittest/NSProviderTest.cpp

index f61a60a..8dbaf5c 100644 (file)
@@ -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'])
index 8f47ff2..079b7da 100644 (file)
@@ -143,7 +143,7 @@ int main()
                 msg->mContentText = OICStrdup(body);\r
                 msg->mSource = NULL;\r
 \r
-                NSSendNotification(msg);\r
+                NSSendMessage(msg);\r
 \r
                 break;\r
 \r
index eb0642e..56c9121 100644 (file)
@@ -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,
 
index f5c5578..b4ea0d7 100644 (file)
@@ -71,7 +71,7 @@ NSResult NSStopProvider();
  * @param[in]  message  Notification message including id, title, contentText\r
  * @return ::NS_OK or result code of NSResult\r
  */\r
-NSResult NSSendNotification(NSMessage *msg);\r
+NSResult NSSendMessage(NSMessage *msg);\r
 \r
 /**\r
  * Send acceptance to consumer who subscribes the resource of notification message\r
@@ -94,7 +94,7 @@ NSResult NSAccept(NSConsumer *consumer, bool accepted);
  * @param[in]  message  Notification message to synchronize the status\r
  * @return ::NS_OK or result code of NSResult\r
  */\r
-NSResult NSProviderReadCheck(NSMessage *);\r
+NSResult NSReadCheck(NSMessage *);\r
 \r
 #ifdef __cplusplus\r
 }\r
index c75d16c..40c6273 100644 (file)
@@ -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,
old mode 100755 (executable)
new mode 100644 (file)
similarity index 69%
rename from service/notification/src/common/NSCacheAdapter.h
rename to service/notification/src/common/NSStorageAdapter.h
index c87a05c..27aff40
@@ -18,8 +18,8 @@
 //\r
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
 \r
-#ifndef _NS_CACHEADAPTER__H_\r
-#define _NS_CACHEADAPTER__H_\r
+#ifndef _NS_STORAGEADAPTER__H_\r
+#define _NS_STORAGEADAPTER__H_\r
 \r
 #include "logger.h"\r
 #include <octypes.h>\r
 #include "NSStructs.h"\r
 #include "NSConstants.h"\r
 \r
-NSCacheList * NSCacheCreate();\r
-NSCacheElement * NSCacheRead(NSCacheList * list, const char * findId);\r
-NSResult NSCacheWrite(NSCacheList * list, NSCacheElement * newObj);\r
-NSResult NSCacheDelete(NSCacheList * list, const char * delId);\r
-NSResult NSCacheDestroy(NSCacheList * list);\r
+NSCacheList * NSStorageCreate();\r
+NSCacheElement * NSStorageRead(NSCacheList * list, const char * findId);\r
+NSResult NSStorageWrite(NSCacheList * list, NSCacheElement * newObj);\r
+NSResult NSStorageDelete(NSCacheList * list, const char * delId);\r
+NSResult NSStorageDestroy(NSCacheList * list);\r
 \r
-#endif /* _NS_CACHEADAPTER__H_ */\r
+#endif /* _NS_STORAGEADAPTER__H_ */\r
index a4253c8..a5eeea2 100755 (executable)
@@ -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;
+}
index a99a011..5d59cf8 100755 (executable)
@@ -40,8 +40,13 @@ NSMessage * NSDuplicateMessage(NSMessage *);
 \r
 NSResult NSFreeSync(NSSync *);\r
 NSSync * NSDuplicateSync(NSSync *);\r
+NSSync * NSGetSyncInfo(OCPayload * payload);\r
 \r
 NSResult NSFreeConsumer(NSConsumer *);\r
 NSConsumer * NSDuplicateConsumer(NSConsumer *);\r
 \r
+void NSDuplicateSetPropertyString(OCRepPayload **, const char *, const char *);\r
+\r
+\r
+\r
 #endif /* _NS_UTIL__H_ */\r
index d19ea9b..c2cb116 100644 (file)
@@ -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
index 791320a..9d8d3ca 100644 (file)
@@ -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)
         {
index f303c49..4aee268 100644 (file)
@@ -26,7 +26,7 @@ extern "C" {
 #endif // __cplusplus
 
 #include "NSStructs.h"
-#include "NSCacheAdapter.h"
+#include "../common/NSStorageAdapter.h"
 #include "NSConsumerNotification.h"
 
 void NSDestroyCacheList();
index 67617a0..5ca69ab 100644 (file)
@@ -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();
 
index ad3dc74..19c3f11 100644 (file)
@@ -28,7 +28,7 @@ extern "C" {
 #include <stdlib.h>
 #include <stdbool.h>
 #include <pthread.h>
-#include "NSCacheAdapter.h"
+#include "NSStorageAdapter.h"
 #include "NSConsumerCommon.h"
 
 
index f6c3078..ccf4747 100644 (file)
@@ -21,9 +21,9 @@
 #include "NSProviderInterface.h"\r
 #include "NSProviderScheduler.h"\r
 #include "NSProviderListener.h"\r
-#include "NSCacheAdapter.h"\r
 #include "NSProviderSubscription.h"\r
 #include "NSProviderNotification.h"\r
+#include "NSStorageAdapter.h"\r
 #include "NSProviderMemoryCache.h"\r
 #include "oic_malloc.h"\r
 #include "oic_string.h"\r
@@ -82,7 +82,7 @@ NSResult NSStartProvider(NSAccessPolicy policy, NSSubscribeRequestCallback subsc
     {\r
         NS_LOG(DEBUG, "Init Provider");\r
         initProvider = true;\r
-        NSSetSubscriptionAcceptPolicy(policy);\r
+        NSSetSubscriptionAccessPolicy(policy);\r
         NSRegisterSubscribeRequestCb(subscribeRequestCb);\r
         NSRegisterSyncCb(syncCb);\r
         CARegisterNetworkMonitorHandler(NSProviderAdapterStateListener,\r
@@ -127,8 +127,8 @@ NSResult NSStopProvider()
         NSRegisterSubscribeRequestCb((NSSubscribeRequestCallback)NULL);\r
         NSRegisterSyncCb((NSSyncCallback)NULL);\r
         NSStopScheduler();\r
-        NSCacheDestroy(consumerSubList);\r
-        NSCacheDestroy(messageList);\r
+        NSStorageDestroy(consumerSubList);\r
+        NSStorageDestroy(messageList);\r
 \r
         initProvider = false;\r
     }\r
@@ -138,7 +138,7 @@ NSResult NSStopProvider()
     return NS_OK;\r
 }\r
 \r
-NSResult NSSendNotification(NSMessage *msg)\r
+NSResult NSSendMessage(NSMessage *msg)\r
 {\r
     NS_LOG(DEBUG, "NSSendNotification - IN");\r
 \r
@@ -161,7 +161,7 @@ NSResult NSSendNotification(NSMessage *msg)
     return NS_OK;\r
 }\r
 \r
-NSResult NSProviderReadCheck(NSMessage *msg)\r
+NSResult NSReadCheck(NSMessage *msg)\r
 {\r
     NS_LOG(DEBUG, "NSProviderReadCheck - IN");\r
 \r
@@ -197,22 +197,22 @@ NSResult NSAccept(NSConsumer *consumer, bool accepted)
     return NS_OK;\r
 }\r
 \r
-void * NSCallbackSchedule(void * ptr)\r
+void * NSInterfaceSchedule(void * ptr)\r
 {\r
     if (ptr == NULL)\r
     {\r
         NS_LOG(DEBUG, "Create NSReponseSchedule");\r
     }\r
 \r
-    while (NSIsRunning[CALLBACK_SCHEDULER])\r
+    while (NSIsRunning[INTERFACE_SCHEDULER])\r
     {\r
-        sem_wait(&NSSemaphore[CALLBACK_SCHEDULER]);\r
-        pthread_mutex_lock(&NSMutex[CALLBACK_SCHEDULER]);\r
+        sem_wait(&NSSemaphore[INTERFACE_SCHEDULER]);\r
+        pthread_mutex_lock(&NSMutex[INTERFACE_SCHEDULER]);\r
 \r
-        if (NSHeadMsg[CALLBACK_SCHEDULER] != NULL)\r
+        if (NSHeadMsg[INTERFACE_SCHEDULER] != NULL)\r
         {\r
-            NSTask *node = NSHeadMsg[CALLBACK_SCHEDULER];\r
-            NSHeadMsg[CALLBACK_SCHEDULER] = node->nextTask;\r
+            NSTask *node = NSHeadMsg[INTERFACE_SCHEDULER];\r
+            NSHeadMsg[INTERFACE_SCHEDULER] = node->nextTask;\r
 \r
             switch (node->taskType)\r
             {\r
@@ -235,7 +235,8 @@ void * NSCallbackSchedule(void * ptr)
                 {\r
                     NS_LOG(DEBUG, "CASE TASK_CB_SYNC : ");\r
                     NSSync * sync = (NSSync*)node->taskData;\r
-                    NSSyncCb(sync);\r
+                    NSSyncCb(NSDuplicateSync(sync));\r
+                    NSFreeSync(sync);\r
                     break;\r
                 }\r
                 default:\r
@@ -245,7 +246,7 @@ void * NSCallbackSchedule(void * ptr)
             OICFree(node);\r
         }\r
 \r
-        pthread_mutex_unlock(&NSMutex[CALLBACK_SCHEDULER]);\r
+        pthread_mutex_unlock(&NSMutex[INTERFACE_SCHEDULER]);\r
 \r
     }\r
 \r
index abb7a6f..cb76c94 100644 (file)
@@ -309,7 +309,7 @@ OCEntityHandlerResult NSEntityHandlerSyncCb(OCEntityHandlerFlag flag,
             NS_LOG(DEBUG, "NSEntityHandlerSyncCb - OC_REST_POST");\r
 \r
             NSPushQueue(NOTIFICATION_SCHEDULER, TASK_RECV_READ,\r
-                    NSBuildOICNotificationSync(entityHandlerRequest->payload));\r
+                    NSGetSyncInfo(entityHandlerRequest->payload));\r
             ehResult = OC_EH_OK;\r
         }\r
         else if (OC_REST_DELETE == entityHandlerRequest->method)\r
@@ -439,44 +439,3 @@ void NSProviderAdapterStateListener(CATransportAdapter_t adapter, bool enabled)
     NS_LOG(DEBUG, "NSProviderAdapterStateListener - OUT");\r
 }\r
 \r
-NSSync * NSBuildOICNotificationSync(OCPayload * payload)\r
-{\r
-    NS_LOG(DEBUG, "NSBuildOICNotificationSync - IN");\r
-\r
-    if(!payload)\r
-    {\r
-        return NULL;\r
-    }\r
-    NSSync * retSync = (NSSync *)OICMalloc(sizeof(NSSync));\r
-    if (!retSync)\r
-    {\r
-        return NULL;\r
-    }\r
-\r
-    retSync->mMessageId = NULL;\r
-    retSync->mState = Notification_Read;\r
-\r
-    OCRepPayload * repPayload = (OCRepPayload *)payload;\r
-    if (!OCRepPayloadGetPropString(repPayload, NS_ATTRIBUTE_ID, &retSync->mMessageId))\r
-    {\r
-        OICFree(retSync);\r
-        return NULL;\r
-    }\r
-    int64_t state;\r
-    if (!OCRepPayloadGetPropInt(repPayload, NS_ATTRIBUTE_STATE, & state))\r
-    {\r
-        OICFree(retSync->mMessageId);\r
-        OICFree(retSync);\r
-        return NULL;\r
-    }\r
-\r
-    retSync->mState = (NSSyncTypes) state;\r
-\r
-    NS_LOG_V(DEBUG, "Sync ID : %s", retSync->mMessageId);\r
-    NS_LOG_V(DEBUG, "Sync State : %d", (int) retSync->mState);\r
-\r
-    NS_LOG(DEBUG, "NSBuildOICNotificationSync - OUT");\r
-\r
-    return retSync;\r
-}\r
-\r
index 2d8b065..77f9b22 100644 (file)
@@ -33,6 +33,7 @@
 #include "oic_string.h"\r
 #include "oic_malloc.h"\r
 #include "NSUtil.h"\r
+#include "NSStorageAdapter.h"\r
 \r
 OCEntityHandlerResult NSEntityHandlerNotificationCb(OCEntityHandlerFlag flag,\r
         OCEntityHandlerRequest *entityHandlerRequest, void* callback);\r
@@ -50,6 +51,4 @@ void NSProviderAdapterStateListener(CATransportAdapter_t adapter, bool enabled);
 \r
 NSResult NSMakeTask(NSTaskType type, OCEntityHandlerRequest *request, NSTask * task);\r
 \r
-NSSync * NSBuildOICNotificationSync(OCPayload * payload);\r
-\r
 #endif /* _NS_PROVIDER_LISTENER__H_ */\r
index d12a435..902b6d4 100644 (file)
@@ -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:
index 8570cd3..7133e3e 100644 (file)
@@ -22,7 +22,6 @@
 #define _NS_PROVIDER_NOTIFICATION_H_\r
 \r
 #include <ocstack.h>\r
-#include "NSCacheAdapter.h"\r
 #include "logger.h"\r
 #include "NSProviderScheduler.h"\r
 #include "NSProviderListener.h"\r
index f4a4da4..820f9b2 100755 (executable)
@@ -29,7 +29,7 @@ bool NSIsRunning[THREAD_COUNT] =
 NSTask* NSHeadMsg[THREAD_COUNT];\r
 NSTask* NSTailMsg[THREAD_COUNT];\r
 \r
-void * NSCallbackSchedule(void *ptr);\r
+void * NSInterfaceSchedule(void *ptr);\r
 void * NSDiscoverySchedule(void *ptr);\r
 void * NSSubScriptionSchedule(void *ptr);\r
 void * NSNotificationSchedule(void *ptr);\r
@@ -62,10 +62,10 @@ bool NSStartScheduler()
 \r
         switch (i)\r
         {\r
-            case CALLBACK_SCHEDULER:\r
+            case INTERFACE_SCHEDULER:\r
             {\r
                 NS_LOG(DEBUG, "CASE RESPONSE_SCHEDULER :");\r
-                pthread_create(&NSThread[i], NULL, NSCallbackSchedule, NULL);\r
+                pthread_create(&NSThread[i], NULL, NSInterfaceSchedule, NULL);\r
             }\r
                 break;\r
 \r
@@ -184,7 +184,7 @@ void NSFreeData(NSSchedulerType type, NSTask * task)
 {\r
     NS_LOG(DEBUG, "NSFreeData - IN");\r
 \r
-    if (type == CALLBACK_SCHEDULER)\r
+    if (type == INTERFACE_SCHEDULER)\r
     {\r
         switch (task->taskType)\r
         {\r
index 873f3f9..85a20ff 100644 (file)
@@ -24,27 +24,27 @@ NSResult NSInitSubscriptionList()
 {\r
     NS_LOG(DEBUG, "NSInitSubscriptionList - IN");\r
 \r
-    consumerSubList = NSCacheCreate();\r
+    consumerSubList = NSStorageCreate();\r
     consumerSubList->cacheType = NS_PROVIDER_CACHE_SUBSCRIBER;\r
 \r
     NS_LOG(DEBUG, "NSInitSubscriptionList - OUT");\r
     return NS_OK;\r
 }\r
 \r
-NSResult NSSetSubscriptionAcceptPolicy(NSAccessPolicy policy)\r
+NSResult NSSetSubscriptionAccessPolicy(NSAccessPolicy access)\r
 {\r
     NS_LOG(DEBUG, "NSSetSubscriptionAcceptPolicy - IN");\r
 \r
-    if (policy == NS_ACCEPTER_PROVIDER)\r
+    if (access == NS_ACCESS_ALLOW)\r
     {\r
         NS_LOG(DEBUG, "Place Provider as a subscription accepter");\r
     }\r
-    else if (policy == NS_ACCEPTER_CONSUMER)\r
+    else if (access == NS_ACCESS_DENY)\r
     {\r
         NS_LOG(DEBUG, "Place Consumer as a subscription accepter");\r
     }\r
 \r
-    NSSubscriptionAccepter = policy;\r
+    NSSubscriptionAccess = access;\r
 \r
     NS_LOG(DEBUG, "NSSetSubscriptionAcceptPolicy - OUT");\r
     return NS_OK;\r
@@ -52,7 +52,7 @@ NSResult NSSetSubscriptionAcceptPolicy(NSAccessPolicy policy)
 \r
 int NSGetSubscriptionAccepter()\r
 {\r
-    return NSSubscriptionAccepter;\r
+    return NSSubscriptionAccess;\r
 }\r
 \r
 NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest)\r
@@ -127,7 +127,7 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour
         NS_LOG_V(DEBUG, "SubList IP[ID] = [%s]", subData->id);\r
         NS_LOG_V(DEBUG, "SubList message observation ID = [%d]", subData->messageObId);\r
 \r
-        if (NSCacheWrite(consumerSubList, element) != NS_OK)\r
+        if (NSStorageWrite(consumerSubList, element) != NS_OK)\r
         {\r
             NS_LOG(DEBUG, "fail to write cache");\r
         }\r
@@ -161,7 +161,7 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour
         NS_LOG_V(DEBUG, "SubList IP[ID] = [%s]", subData->id);\r
         NS_LOG_V(DEBUG, "SubList sync observation ID = [%d]", subData->syncObId);\r
 \r
-        if (NSCacheWrite(consumerSubList, element) != NS_OK)\r
+        if (NSStorageWrite(consumerSubList, element) != NS_OK)\r
         {\r
             NS_LOG(ERROR, "Fail to write cache");\r
         }\r
@@ -186,7 +186,7 @@ void NSHandleUnsubscription(OCEntityHandlerRequest *entityHandlerRequest)
     NS_LOG_V(DEBUG, "SubList IP[ID] = [%s]", subData->id);\r
     NS_LOG_V(DEBUG, "SubList observation ID = [%d]", subData->syncObId);\r
 \r
-    if (NSCacheWrite(consumerSubList, element) != NS_OK)\r
+    if (NSStorageWrite(consumerSubList, element) != NS_OK)\r
     {\r
         NS_LOG(ERROR, "fail to write consumer white list");\r
     }\r
@@ -199,7 +199,7 @@ void NSAskAcceptanceToUser(OCEntityHandlerRequest *entityHandlerRequest)
 {\r
     NS_LOG(DEBUG, "NSAskAcceptanceToUser - IN");\r
 \r
-    NSPushQueue(CALLBACK_SCHEDULER, TASK_CB_SUBSCRIPTION, entityHandlerRequest);\r
+    NSPushQueue(INTERFACE_SCHEDULER, TASK_CB_SUBSCRIPTION, entityHandlerRequest);\r
 \r
     NS_LOG(DEBUG, "NSAskAcceptanceToUser - OUT");\r
 }\r
@@ -226,7 +226,7 @@ NSResult NSSendResponse(const char * id, bool accepted)
     OCRepPayloadSetPropString(payload, NS_ATTRIBUTE_ID, "0000-0000-0000-0000");\r
     OCRepPayloadSetPropBool(payload, NS_ATTRIBUTE_ACCPETANCE, accepted);\r
 \r
-    NSCacheElement * element = NSCacheRead(consumerSubList, id);\r
+    NSCacheElement * element = NSStorageRead(consumerSubList, id);\r
 \r
     if(element == NULL)\r
     {\r
@@ -272,7 +272,7 @@ NSResult NSSendSubscriptionResponse(OCEntityHandlerRequest *entityHandlerRequest
         element->data = (void*) subData;\r
         element->next = NULL;\r
 \r
-        if (NSCacheWrite(consumerSubList, element) != NS_OK)\r
+        if (NSStorageWrite(consumerSubList, element) != NS_OK)\r
         {\r
             NS_LOG(ERROR, "fail to write consumer white list");\r
         }\r
index 4f27a20..a26f51a 100644 (file)
 #include "NSConstants.h"\r
 #include "NSProviderScheduler.h"\r
 #include "NSProviderResource.h"\r
-#include "NSCacheAdapter.h"\r
 #include "NSProviderMemoryCache.h"\r
 #include "oic_string.h"\r
+#include "oic_malloc.h"\r
 \r
-NSAccessPolicy NSSubscriptionAccepter;\r
+NSAccessPolicy NSSubscriptionAccess;\r
 NSCacheList * consumerSubList;\r
 \r
 NSResult NSInitSubscriptionList();\r
-NSResult NSSetSubscriptionAcceptPolicy(NSAccessPolicy policy);\r
+NSResult NSSetSubscriptionAccessPolicy(NSAccessPolicy policy);\r
 int NSGetSubscriptionAccepter();\r
 NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest);\r
 void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResourceType resourceType);\r
index 374afd2..f66d7e8 100755 (executable)
 // limitations under the License.\r
 //\r
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
 #include "NSProviderMemoryCache.h"\r
 \r
-NSCacheList * NSCacheCreate()\r
+NSCacheList * NSStorageCreate()\r
 {\r
     pthread_mutex_lock(&NSCacheMutex);\r
     NSCacheList * newList = (NSCacheList *) OICMalloc(sizeof(NSCacheList));\r
@@ -38,7 +39,7 @@ NSCacheList * NSCacheCreate()
     return newList;\r
 }\r
 \r
-NSCacheElement * NSCacheRead(NSCacheList * list, const char * findId)\r
+NSCacheElement * NSStorageRead(NSCacheList * list, const char * findId)\r
 {\r
     pthread_mutex_lock(&NSCacheMutex);\r
 \r
@@ -86,7 +87,7 @@ NSResult NSCacheUpdateSubScriptionState(NSCacheList * list, char * id, bool stat
     }\r
 \r
     pthread_mutex_unlock(&NSCacheMutex);\r
-    NSCacheElement * it = NSCacheRead(list, id);\r
+    NSCacheElement * it = NSStorageRead(list, id);\r
     pthread_mutex_lock(&NSCacheMutex);\r
 \r
     if (it)\r
@@ -120,7 +121,7 @@ NSResult NSCacheUpdateSubScriptionState(NSCacheList * list, char * id, bool stat
     return NS_ERROR;\r
 }\r
 \r
-NSResult NSCacheWrite(NSCacheList * list, NSCacheElement * newObj)\r
+NSResult NSStorageWrite(NSCacheList * list, NSCacheElement * newObj)\r
 {\r
     pthread_mutex_lock(&NSCacheMutex);\r
 \r
@@ -142,7 +143,7 @@ NSResult NSCacheWrite(NSCacheList * list, NSCacheElement * newObj)
         NSCacheSubData * subData = (NSCacheSubData *) newObj->data;\r
 \r
         pthread_mutex_unlock(&NSCacheMutex);\r
-        NSCacheElement * it = NSCacheRead(list, subData->id);\r
+        NSCacheElement * it = NSStorageRead(list, subData->id);\r
         pthread_mutex_lock(&NSCacheMutex);\r
 \r
         if (it)\r
@@ -187,7 +188,7 @@ NSResult NSCacheWrite(NSCacheList * list, NSCacheElement * newObj)
 \r
         NSCacheMsgData * msgData = (NSCacheMsgData *) newObj->data;\r
 \r
-        NSCacheElement * it = NSCacheRead(list, msgData->id);\r
+        NSCacheElement * it = NSStorageRead(list, msgData->id);\r
         if (it)\r
         {\r
             NSCacheMsgData * itData = (NSCacheMsgData *) it->data;\r
@@ -218,7 +219,7 @@ NSResult NSCacheWrite(NSCacheList * list, NSCacheElement * newObj)
     return NS_OK;\r
 }\r
 \r
-NSResult NSCacheDelete(NSCacheList * list, const char * delId)\r
+NSResult NSStorageDelete(NSCacheList * list, const char * delId)\r
 {\r
     pthread_mutex_lock(&NSCacheMutex);\r
     NSCacheElement * prev = list->head;\r
@@ -264,7 +265,7 @@ NSResult NSCacheDelete(NSCacheList * list, const char * delId)
     return NS_OK;\r
 }\r
 \r
-NSResult NSCacheDestroy(NSCacheList * list)\r
+NSResult NSStorageDestroy(NSCacheList * list)\r
 {\r
     NSCacheElement * iter = list->head;\r
     NSCacheElement * next = NULL;\r
index 1668722..096d18b 100755 (executable)
 #ifndef _NS_PROVIDER_CACHEADAPTER__H_\r
 #define _NS_PROVIDER_CACHEADAPTER__H_\r
 \r
-#include <stdbool.h>\r
-#include <octypes.h>\r
 #include <pthread.h>\r
-#include "logger.h"\r
-#include "ocstack.h"\r
-#include "ocpayload.h"\r
-#include "NSStructs.h"\r
+#include <stdbool.h>\r
+#include <string.h>\r
+\r
+#include "NSCommon.h"\r
 #include "NSConstants.h"\r
-#include "NSCacheAdapter.h"\r
+#include "NSStructs.h"\r
 #include "oic_malloc.h"\r
 #include "oic_string.h"\r
+#include "NSStorageAdapter.h"\r
 #include "NSUtil.h"\r
 \r
 NSResult NSProviderDeleteCacheData(NSCacheType, void *);\r
index 22f8421..41c7fab 100644 (file)
@@ -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);