added cacheadapter interface and memorycache of notification. 91/8191/5
authorjaesick.shin <jaesick.shin@samsung.com>
Tue, 17 May 2016 09:03:56 +0000 (18:03 +0900)
committerUze Choi <uzchoi@samsung.com>
Wed, 18 May 2016 00:33:45 +0000 (00:33 +0000)
this patch included cacheadapter and using the memorycache.
previosuly, we used the only observeid(unique id).
currently, we use the ip in OCDevaddr Struct.

Change-Id: Ie1b3ff6a88b00f83772f2cddd08a186a2122d69f
Signed-off-by: jaesick.shin <jaesick.shin@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8191
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
39 files changed:
service/SConscript
service/notification/SConscript
service/notification/examples/linux/notificationconsumer.c
service/notification/examples/linux/notificationprovider.c
service/notification/include/NSCommon.h
service/notification/include/NSConsumerInterface.h
service/notification/include/NSProviderInterface.h
service/notification/src/common/NSCacheAdapter.h [new file with mode: 0755]
service/notification/src/common/NSConstants.h
service/notification/src/common/NSStructs.h
service/notification/src/common/NSUtil.c [new file with mode: 0755]
service/notification/src/common/NSUtil.h [new file with mode: 0755]
service/notification/src/consumer/NSConsumerCache.c
service/notification/src/consumer/NSConsumerCache.h
service/notification/src/consumer/NSConsumerCommon.c
service/notification/src/consumer/NSConsumerCommon.h
service/notification/src/consumer/NSConsumerDiscovery.c
service/notification/src/consumer/NSConsumerInterface.c
service/notification/src/consumer/NSConsumerListener.c
service/notification/src/consumer/NSConsumerMessageHandler.c
service/notification/src/consumer/NSConsumerNotification.c
service/notification/src/consumer/NSConsumerQueue.c
service/notification/src/consumer/NSConsumerSubsription.c
service/notification/src/consumer/NSConsumerSystem.c
service/notification/src/consumer/NSThread.c
service/notification/src/provider/NSProviderCacheAdapter.c [deleted file]
service/notification/src/provider/NSProviderDiscovery.c
service/notification/src/provider/NSProviderDiscovery.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 [moved from service/notification/src/common/NSQueueScheduler.c with 95% similarity, mode: 0755]
service/notification/src/provider/NSProviderScheduler.h [moved from service/notification/src/common/NSQueueScheduler.h with 90% similarity, mode: 0755]
service/notification/src/provider/NSProviderSubscription.c
service/notification/src/provider/NSProviderSubscription.h
service/notification/src/provider/cache/linux/NSProviderMemoryCache.c [new file with mode: 0755]
service/notification/src/provider/cache/linux/NSProviderMemoryCache.h [moved from service/notification/src/provider/NSProviderCacheAdapter.h with 68% similarity, mode: 0755]

index 2e8d1f5..bbd66d4 100755 (executable)
@@ -43,8 +43,8 @@ if target_os not in ['arduino','darwin', 'ios']:
     if target_os in ['linux']:
         SConscript('scene-manager/SConscript')
 
-    #if target_os in ['linux']:
-        #SConscript('notification/SConscript')
+    if target_os in ['linux']:
+        SConscript('notification/SConscript')
 
     # Build simulator module
     if target_os in ['linux'] and env.get('SIMULATOR', False):
index 067bbe2..b1e51df 100644 (file)
@@ -48,6 +48,12 @@ notification_env.AppendUnique(CPPPATH = ['src/provider'])
 notification_env.AppendUnique(CPPPATH = ['../../resource/csdk/stack/include'])
 notification_env.AppendUnique(CPPPATH = ['../../resource/csdk/connectivity/api'])
 
+if target_os == 'linux':
+    notification_env.AppendUnique(CPPPATH = ['src/provider/cache/linux'])
+
+if target_os == 'android':
+    notification_env.AppendUnique(CPPPATH = ['src/provider/cache/android'])
+
 notification_env.PrependUnique(LIBS = [
        'octbstack',
        'oc_logger',
@@ -56,7 +62,7 @@ notification_env.PrependUnique(LIBS = [
        ])
 
 if target_os not in ['windows', 'winrt']:
-       notification_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])
+       notification_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0'])
 
 if target_os not in ['darwin', 'ios', 'windows', 'winrt']:
        notification_env.AppendUnique(LINKFLAGS = ['-Wl,--no-undefined'])
@@ -76,11 +82,18 @@ if target_os == 'android':
 ######################################################################
 # Source files and Targets
 ######################################################################
+
+if target_os == 'linux':
+    PROVIDER_CACHE = File('src/provider/cache/linux/NSProviderMemoryCache.c')
+
+if target_os == 'android':
+    PROVIDER_CACHE = File('src/provider/cache/linux/NSProviderMemoryCache.c')
+
 notification_provider_src = [
        env.Glob('src/provider/*.c'),
-       env.Glob('src/common/*.c')]
+       env.Glob('src/common/*.c'), PROVIDER_CACHE]
 notification_consumer_src = [
-       #env.Glob('src/common/*.c'),
+       env.Glob('src/common/*.c'),
        env.Glob('src/consumer/*.c')]
 
 providersdk = notification_env.SharedLibrary('notification_provider', notification_provider_src)
index 701786a..85810bd 100644 (file)
@@ -13,13 +13,13 @@ void onNotificationPosted(NSProvider * provider, NSMessage * notification)
     printf("title : %s\n", notification->mTitle);
     printf("content : %s\n", notification->mContentText);
 //    NSDropNSObject(notification);
-    NSRead(notification);
+    NSConsumerReadCheck(notification);
 }
 
 void onDiscoverNotification(NSProvider * provider)
 {
     printf("notification resource discovered\n");
-    printf("subscribe result %d\n", NSSubscribeProvider(provider));
+    printf("subscribe result %d\n", NSSubscribe(provider));
     printf("startSubscribing\n");
 }
 
index e4422d3..c614294 100644 (file)
@@ -20,7 +20,7 @@ int id;
 \r
 void OCProcessThread(void * ptr)\r
 {\r
-    (void*) ptr;\r
+    (void) ptr;\r
     while (!isExit)\r
     {\r
         if (OCProcess() != OC_STACK_OK)\r
@@ -36,17 +36,16 @@ void subscribeRequestCallback(NSConsumer *consumer)
     OIC_LOG(INFO, TAG, "consumer requested to subscribe");\r
     char *cid = consumer->mId;\r
 \r
-    printf("Consumer ID: %s\n", cid);\r
+    printf("NS_ Consumer ID: %s\n", cid);\r
 \r
     NSAccept(consumer, true);\r
 }\r
 \r
-void syncCallback(NSProvider *provider, NSSync *sync)\r
+void syncCallback(NSSync *sync)\r
 {\r
     OIC_LOG(INFO, TAG, "sync requested");\r
 \r
-    printf("Sync State: %d\n", sync->mState);\r
-\r
+    printf("NS_ Sync State: %d\n", sync->mState);\r
 }\r
 \r
 int main()\r
@@ -80,8 +79,8 @@ int main()
         printf("4. NSRead \n");\r
         //printf("5. NSAccept \n");\r
         printf("6. NSGetConsumerList \n");\r
-        printf("7. startPresence \n");\r
-        printf("8. stopPresence \n");\r
+        //printf("7. startPresence \n");\r
+        //printf("8. stopPresence \n");\r
         printf("0. Exit() \n");\r
 \r
         printf("input : ");\r
@@ -120,6 +119,7 @@ int main()
                 printf("app - mTitle : %s \n", title);\r
                 printf("app - mContentText : %s \n", body);\r
 \r
+\r
                 NSMessage * msg = (NSMessage *)malloc(sizeof(NSMessage));\r
 \r
                 sprintf(charID, "%d", id);\r
@@ -175,12 +175,12 @@ int main()
                     */\r
                 break;\r
             case 7:\r
-                OIC_LOG(INFO, TAG, "NSStartPresence");\r
-                NSTestStartPresence();\r
+                OIC_LOG(INFO, TAG, "NSStartPresence - not working");\r
+                //NSTestStartPresence();\r
                 break;\r
             case 8:\r
-                OIC_LOG(INFO, TAG, "NSStopPresence");\r
-                NSTestStopPresence();\r
+                OIC_LOG(INFO, TAG, "NSStopPresence- not working");\r
+                //NSTestStopPresence();\r
                 break;\r
             default:\r
                 OIC_LOG(INFO, TAG, "Under Construction");\r
index 3348303..3d299be 100644 (file)
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
+/**
+ * @file
+ *
+ * This file provides APIs of Notification Service for common functions.
+ */
+
 #ifndef _NS_COMMON_H_
 #define _NS_COMMON_H_
 
+#include <ocstack.h>
+
 #define NS_ATTRIBUTE_POLICY "ACCEPTER"
 #define NS_ATTRIBUTE_MESSAGE "MESSAGE_URI"
 #define NS_ATTRIBUTE_SYNC "SYNC_URI"
@@ -31,6 +39,9 @@
 #define NS_ATTRIBUTE_STATE "STATE"
 #define NS_ATTRIBUTE_DEVICE "DEVICE"
 
+/**
+ * Result code of notification service
+ */
 typedef enum eResult
 {
     NS_OK = 100,
@@ -42,6 +53,9 @@ typedef enum eResult
 
 } NSResult;
 
+/**
+ * Access policy exchanged between provider and consumer during subscription process
+ */
 typedef enum eAccessPolicy
 {
     NS_ACCEPTER_PROVIDER = 0,
@@ -49,39 +63,55 @@ typedef enum eAccessPolicy
 
 } NSAccessPolicy;
 
+/**
+ * Notification message status to synchronize
+ */
+typedef enum
+{
+    Notification_Read,
+    Notification_Dismiss,
+} NSSyncTypes;
+
+/**
+ *  Device information
+ */
 typedef struct
 {
     char * mId;
     void * mUserData;
 } NSDevice;
 
+/**
+ *  Consumer information is same to device information
+ */
 typedef NSDevice NSConsumer;
 
+/**
+ *  Provider information
+ */
 typedef struct
 {
     char * mId;
     char * mUserData;
     char * messageUri;
     char * syncUri;
+    OCDoHandle messageHandle;
+    OCDoHandle syncHandle;
 } NSProvider;
 
+/**
+ *  Notification Message
+ */
 typedef struct
 {
-    // Mandatory
     char * mId;
     char * mTitle;
-
-    //Optional
     char * mContentText;
-
 } NSMessage;
 
-typedef enum
-{
-    Notification_Read,
-    Notification_Dismiss,
-} NSSyncTypes;
-
+/**
+ *  Synchronization information of the notification message
+ */
 typedef struct
 {
     // Mandatory
@@ -90,15 +120,7 @@ typedef struct
 
     //Optional
     NSDevice * mDevice;
-
 } NSSync;
 
-typedef void (* NSSubscribeRequestCallback)(NSConsumer *);
-typedef void (* NSSyncCallback)(NSProvider *, NSSync *);
-
-typedef void (* NSProviderDiscoveredCallback)(NSProvider *);
-// NSMessage should deleted as user.
-typedef void (* NSNotificationReceivedCallback)(NSProvider *, NSMessage *);
-
 #endif /* _NS_COMMON_H_ */
 
index 108f797..9461cc5 100644 (file)
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
+/**
+ * @file
+ *
+ * This file provides APIs of Notification Service for Consumer.
+ */
+
 #ifndef _NS_CONSUMER_INTERFACE_H_
 #define _NS_CONSUMER_INTERFACE_H_
 
 #ifdef __cplusplus
-extern "C" {
+extern "C"
+{
 #endif // __cplusplus
 
 #include "NSCommon.h"
 
-NSResult NSStartConsumer(
-        NSProviderDiscoveredCallback discoverCb,
-        NSNotificationReceivedCallback  postCb,
-        NSSyncCallback syncCb);
+/**
+ * Provider and consumer use this callback function to receive the status of the message
+ * synchronization
+ * @param[in] provider    Provider who requests synchronization with the status
+ * @param[in] sync        Synchronization information of the notification message
+ */
+typedef void (*NSSyncCallback)(NSProvider *, NSSync *);
+
+/**
+ * Consumer uses this callback function to receive the discovered providers
+ * @param[in] provider        Provider who has the notification resource
+ */
+typedef void (*NSProviderDiscoveredCallback)(NSProvider *);
+
+/**
+ * Consumer use this callback function to receive notification message from provider
+ * synchronization
+ * @param[in] provider    Provider who sends notification message
+ * @param[in] message     Notification message
+ */
+typedef void (*NSNotificationReceivedCallback)(NSProvider *, NSMessage *);
 
+/**
+ * Initialize notification service for consumer
+ * @param[in]  providerDiscoveredCallback   Callback function to discover notification providers
+ * @param[in]  notificationReceivedCallback   Callback function to receive notification messages
+ * @param[in]  syncCallback   Callback function to receive synchronization status of notification
+ * @return ::NS_OK or result code of NSResult
+ */
+NSResult NSStartConsumer(NSProviderDiscoveredCallback discoverCb,
+        NSNotificationReceivedCallback postCb, NSSyncCallback syncCb);
+
+/**
+ * Terminate notification service for consumer
+ * @return ::NS_OK or result code of NSResult
+ */
 NSResult NSStopConsumer();
 
-NSResult NSRead(NSMessage *);
+/**
+ * Request discovery manually
+ * @return ::NS_OK or result code of NSResult
+ */
+NSResult NSRescanProvider();
 
-NSResult NSDismiss(NSMessage *);
+/**
+ * Request to subscribe notification message resource of provider
+ * @param[in]  provider  Provider who send the notification message
+ * @return ::NS_OK or result code of NSResult
+ */
+NSResult NSSubscribe(NSProvider *provider);
 
-NSResult NSSubscribeProvider(NSProvider *);
+/**
+ * Request to unsubscribe in order not to receive notification message from provider
+ * @param[in]  provider  Provider who send the notification message
+ * @return ::NS_OK or result code of NSResult
+ */
+NSResult NSUnsubscribe(NSProvider *provider);
 
-NSResult NSUnsubscribeProvider(NSProvider *);
+NSResult NSConsumerReadCheck(NSMessage *);
 
-NSResult NSRescanProvider();
+NSResult NSConsumerDismissCheck(NSMessage *);
 
+//** Remove below functions **//
 NSResult NSDropNSObject(NSMessage *);
+//** end of functions to be removed **//
 
 #ifdef __cplusplus
 }
index 606ff5c..f5c5578 100644 (file)
 //\r
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
 \r
+/**\r
+ * @file\r
+ *\r
+ * This file provides APIs of Notification Service for Provider.\r
+ */\r
+\r
 #ifndef _NS_PROVIDER_INTERFACE_H_\r
 #define _NS_PROVIDER_INTERFACE_H_\r
 \r
 #ifdef __cplusplus\r
-extern "C" {\r
+extern "C"\r
+{\r
 #endif // __cplusplus\r
 \r
 #include "NSCommon.h"\r
 #include <stdbool.h>\r
 #include <stdint.h>\r
 \r
+/**\r
+ * Provider uses this callback function to receive subscription request of consumer\r
+ * @param[in] consumer        Consumer who subscribes the resource\r
+ */\r
+typedef void (*NSSubscribeRequestCallback)(NSConsumer *);\r
+\r
+/**\r
+ * Provider use this callback function to receive the status of the message\r
+ * synchronization\r
+ * @param[in] sync        Synchronization information of the notification message\r
+ */\r
+typedef void (*NSSyncCallback)(NSSync *);\r
+\r
+/**\r
+ * Initialize notification service for provider\r
+ * @param[in]  policy   Accepter\r
+ * @param[in]  subscribeRequestCallback   Callback function to register for receiving\r
+ * subscription request from consumer\r
+ * @param[in]  syncCallback   Callback function to register for receiving  sync data\r
+ * @return ::NS_OK or result code of NSResult\r
+ */\r
 NSResult NSStartProvider(NSAccessPolicy policy, NSSubscribeRequestCallback subscribeRequestCb,\r
         NSSyncCallback syncCb);\r
 \r
+/**\r
+ * Terminate notification service for provider\r
+ * @return ::NS_OK or result code of NSResult\r
+ */\r
 NSResult NSStopProvider();\r
 \r
+/**\r
+ * Send notification message to all subscribers\r
+ * @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
 \r
-NSResult NSReadCheck(NSMessage *msg);\r
-\r
+/**\r
+ * Send acceptance to consumer who subscribes the resource of notification message\r
+ * @param[in]  consumer  Consumer who subscribes the resource\r
+ * @param[in]  accepted  the result of acceptance; Allow or Deny\r
+ * @return ::NS_OK or result code of NSResult\r
+ */\r
 NSResult NSAccept(NSConsumer *consumer, bool accepted);\r
 \r
-NSResult NSGetConsumerList(uint8_t *list, uint32_t size);\r
-\r
-NSResult NSTestStartPresence();\r
+/**\r
+ * Get consumer list that is stored in the cache of notification service\r
+ * @param[in]  list  Consumer list\r
+ * @param[in]  size  the number of consumers stored in the cache\r
+ * @return ::NS_OK or result code of NSResult\r
+ */\r
+// NSResult NSGetConsumerList(uint8_t *list, uint32_t size);\r
 \r
-NSResult NSTestStopPresence();\r
+/**\r
+ * Send read-check to provider in order to synchronize notification status with other consumers\r
+ * @param[in]  message  Notification message to synchronize the status\r
+ * @return ::NS_OK or result code of NSResult\r
+ */\r
+NSResult NSProviderReadCheck(NSMessage *);\r
 \r
 #ifdef __cplusplus\r
 }\r
diff --git a/service/notification/src/common/NSCacheAdapter.h b/service/notification/src/common/NSCacheAdapter.h
new file mode 100755 (executable)
index 0000000..9f732f5
--- /dev/null
@@ -0,0 +1,38 @@
+//******************************************************************\r
+//\r
+// Copyright 2016 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+//      http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+#ifndef _NS_CACHEADAPTER__H_\r
+#define _NS_CACHEADAPTER__H_\r
+\r
+#include "logger.h"\r
+#include <octypes.h>\r
+#include <stdbool.h>\r
+#include "ocstack.h"\r
+#include "ocpayload.h"\r
+#include "NSStructs.h"\r
+#include "NSConstants.h"\r
+\r
+NSCacheList * NSCacheCreate();\r
+NSCacheElement * NSCacheRead(NSCacheList * list, char * findId);\r
+NSResult NSCacheWrite(NSCacheList * list, NSCacheElement * newObj);\r
+NSResult NSCacheDelete(NSCacheList * list, char * delId);\r
+NSResult NSCacheDestroy(NSCacheList * list);\r
+\r
+#endif /* _NS_CACHEADAPTER__H_ */\r
index bbf4aef..83a4f6c 100644 (file)
 #ifndef _NS_CONSTANTS_H_
 #define _NS_CONSTANTS_H_
 
+#define __NS_FILE__ ( strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__ )
+
+#ifdef TB_LOG
+#include "logger.h"
+#define NS_LOG_V(level, format, ...) (OIC_LOG_V((level), __NS_FILE__, (format), __VA_ARGS__))
+#define NS_LOG(level, msg) (OIC_LOG((level), __NS_FILE__, (msg)))
+#else
+#include "logger.h"
+#define NS_CONVERT_LEVEL(level) ( \
+        ((level) == 0) ? "DEBUG" : \
+        ((level) == 1) ? "INFO" : \
+        ((level) == 2) ? "WARNING" : \
+       ((level) == 3) ? "ERROR" : "FATAL")
+#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("%s: %s ", NS_CONVERT_LEVEL(level), __NS_FILE__); \
+        printf((msg)); \
+        printf("\n"); }
+#endif
+
 #define NS_TAG "IOT_NOTI"
 
 // SCHEDULE //
@@ -97,4 +120,16 @@ typedef enum eCache
 
 } NSCache;
 
+typedef enum eCacheType
+{
+    NS_PROVIDER_CACHE_SUBSCRIBER = 1000,
+    NS_PROVIDER_CACHE_MESSAGE = 1001,
+} NSCacheType;
+
+typedef enum eResourceType
+{
+    NS_RESOURCE_MESSAGE = 1000,
+    NS_RESOURCE_SYNC = 1001,
+} NSResourceType;
+
 #endif /* _NS_CONSTANTS_H_ */
index 8305aaf..f8c6ca1 100644 (file)
@@ -23,6 +23,8 @@
 \r
 #include <string.h>\r
 #include <stdlib.h>\r
+#include <stdio.h>\r
+#include <stdbool.h>\r
 #include "NSCommon.h"\r
 #include "NSConstants.h"\r
 \r
@@ -33,4 +35,34 @@ typedef struct _nsTask
     struct _nsTask* nextTask;\r
 } NSTask;\r
 \r
+typedef void * NSCacheData;\r
+\r
+typedef struct _NSCacheElement\r
+{\r
+    NSCacheData * data;\r
+    struct _NSCacheElement * next;\r
+} NSCacheElement;\r
+\r
+typedef struct\r
+{\r
+    NSCacheType cacheType;\r
+    NSCacheElement * head;\r
+    NSCacheElement * tail;\r
+} NSCacheList;\r
+\r
+typedef struct\r
+{\r
+    char * id; // ip\r
+    int syncObId;\r
+    int messageObId;\r
+    bool isWhite;\r
+}NSCacheSubData;\r
+\r
+typedef struct\r
+{\r
+    char * id; // ip ? ? ?\r
+    int messageType; // noti = 1, read = 2, dismiss = 3\r
+    NSMessage * nsMessage;\r
+}NSCacheMsgData;\r
+\r
 #endif /* _NS_STRUCTS_H_ */\r
diff --git a/service/notification/src/common/NSUtil.c b/service/notification/src/common/NSUtil.c
new file mode 100755 (executable)
index 0000000..0ddeaa9
--- /dev/null
@@ -0,0 +1,53 @@
+//******************************************************************
+//
+// Copyright 2016 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "NSUtil.h"
+
+NSResult NSFreeMessage(NSMessage * obj)
+{
+    if (!obj)
+    {
+        return NS_ERROR;
+    }
+
+    if (obj->mId)
+    {
+        OICFree(obj->mId);
+        obj->mId = NULL;
+    }
+
+    if (obj->mTitle)
+    {
+        OICFree(obj->mTitle);
+        obj->mTitle = NULL;
+    }
+
+    if (obj->mContentText)
+    {
+        OICFree(obj->mContentText);
+        obj->mContentText = NULL;
+    }
+
+    OICFree(obj);
+
+    return NS_OK;
+}
+
+
diff --git a/service/notification/src/common/NSUtil.h b/service/notification/src/common/NSUtil.h
new file mode 100755 (executable)
index 0000000..c52d9cd
--- /dev/null
@@ -0,0 +1,34 @@
+//******************************************************************\r
+//\r
+// Copyright 2016 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+//      http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+#ifndef _NS_UTIL__H_\r
+#define _NS_UTIL__H_\r
+\r
+#include "logger.h"\r
+#include <octypes.h>\r
+#include <stdbool.h>\r
+#include "ocstack.h"\r
+#include "ocpayload.h"\r
+#include "NSStructs.h"\r
+#include "NSConstants.h"\r
+\r
+NSResult NSFreeMessage(NSMessage *);\r
+\r
+#endif /* _NS_UTIL__H_ */\r
index 1fad925..b9874c8 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "NSConsumerCache.h"
 #include "NSConsumerCommon.h"
+#include "NSConstants.h"
 
 #include "stdlib.h"
 #include "oic_malloc.h"
@@ -34,7 +35,7 @@ NSCacheList * NSConsumerCacheInit()
     }
 
     retNSCacheList->head = NULL;
-    retNSCacheList->last = NULL;
+    retNSCacheList->tail = NULL;
 
     return retNSCacheList;
 }
@@ -64,16 +65,16 @@ NSResult NSConsumerCacheInsert(NSCacheList * list, NSCacheObject * newObj)
     NSCacheObject * obj = (NSCacheObject *)OICMalloc(sizeof(NSCacheObject));
     if (!obj)
     {
-        NS_CONSUMER_LOG(ERROR, "Fail to Create New Object");
+        NS_LOG(ERROR, "Fail to Create New Object");
         return NS_ERROR;
     }
 
     NSMessage_consumer * msgObj = (NSMessage_consumer *) OICMalloc(sizeof(NSMessage_consumer));
     NSMessage_consumer * newMsgObj = (NSMessage_consumer *) newObj->data;
 
-    NS_CONSUMER_LOG_V(DEBUG, "Title: %s", newMsgObj->mTitle);
-    NS_CONSUMER_LOG_V(DEBUG, "ID: %s", newMsgObj->mId);
-    NS_CONSUMER_LOG_V(DEBUG, "TEXT: %s", newMsgObj->mContentText);
+    NS_LOG_V(DEBUG, "Title: %s", newMsgObj->mTitle);
+    NS_LOG_V(DEBUG, "ID: %s", newMsgObj->mId);
+    NS_LOG_V(DEBUG, "TEXT: %s", newMsgObj->mContentText);
 
     msgObj->mTitle = OICStrdup(newMsgObj->mTitle);
     msgObj->mId = OICStrdup(newMsgObj->mId);
@@ -81,13 +82,13 @@ NSResult NSConsumerCacheInsert(NSCacheList * list, NSCacheObject * newObj)
 
     if (!msgObj->mId)
     {
-        NS_CONSUMER_LOG(ERROR, "Notification Attributes copy fail");
+        NS_LOG(ERROR, "Notification Attributes copy fail");
     }
 
     msgObj->addr = (OCDevAddr *)OICMalloc(sizeof(OCDevAddr));
     if (!msgObj->addr)
     {
-        NS_CONSUMER_LOG(ERROR, "OCDevAddr allocation is failed.");
+        NS_LOG(ERROR, "OCDevAddr allocation is failed.");
     }
 
     memcpy(msgObj->addr, newMsgObj->addr, sizeof(OCDevAddr));
@@ -117,12 +118,12 @@ NSResult NSConsumerCacheInsert(NSCacheList * list, NSCacheObject * newObj)
         iter = (NSCacheObject *) iter->next;
     }
 
-    if (list->last)
+    if (list->tail)
     {
-        (list->last)->next = obj;
+        (list->tail)->next = obj;
     }
 
-    list->last = obj;
+    list->tail = obj;
 
     return NS_OK;
 }
@@ -143,10 +144,10 @@ NSResult NSConsumerCacheDelete(NSCacheList * list, NSCacheObject * delObj) // Fr
     {
         if (beDelete == delObj)
         {
-            if (beDelete == list->last)
+            if (beDelete == list->tail)
             {
                 pre->next = NULL;
-                list->last = pre;
+                list->tail = pre;
             }
             else
             {
@@ -165,21 +166,21 @@ NSResult NSConsumerCacheDelete(NSCacheList * list, NSCacheObject * delObj) // Fr
 NSCacheObject * NSConsumerCacheFind(NSCacheList * list, char * findId)
 {
 
-    NS_CONSUMER_LOG_V(DEBUG, "findID: %s", findId);
+    NS_LOG_V(DEBUG, "findID: %s", findId);
     NSCacheObject * retObj = list->head;
     if (!retObj)
     {
-        NS_CONSUMER_LOG(DEBUG, "findcache is null");
+        NS_LOG(DEBUG, "findcache is null");
         return retObj;
     }
 
     NSMessage_consumer * obj = (NSMessage_consumer *) retObj->data;
-    NS_CONSUMER_LOG_V(DEBUG, "objmID: %s", obj->mId);
+    NS_LOG_V(DEBUG, "objmID: %s", obj->mId);
 
     while (retObj)
     {
         NSMessage_consumer * obj = (NSMessage_consumer *) retObj->data;
-        NS_CONSUMER_LOG_V(DEBUG, "objmID: %s", obj->mId);
+        NS_LOG_V(DEBUG, "objmID: %s", obj->mId);
         if (!strcmp(obj->mId, findId))
         {
             return retObj;
index 802b2f9..22b1576 100644 (file)
@@ -40,12 +40,6 @@ typedef struct _NSCacheObject
     struct _NSCacheObject * next;
 } NSCacheObject;
 
-typedef struct
-{
-    NSCacheObject * head;
-    NSCacheObject * last;
-} NSCacheList;
-
 NSCacheList * NSConsumerCacheInit();
 NSResult NSConsumerCacheDestroy(NSCacheList * list);
 
index 94c48bf..1cc11aa 100644 (file)
@@ -19,6 +19,7 @@
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
 #include "NSConsumerCommon.h"
+#include "NSConstants.h"
 #include "NSThread.h"
 #include "oic_malloc.h"
 #include "oic_string.h"
@@ -68,7 +69,7 @@ void NSDiscoveredProvider(NSProvider * provider)
 {
     if (!NSThreadInit(NSDiscoverdProviderFunc, (void *) provider))
     {
-        NS_CONSUMER_LOG(ERROR, "execute discovered provider callback fail");
+        NS_LOG(ERROR, "execute discovered provider callback fail");
         return;
     }
 }
@@ -107,7 +108,7 @@ void NSNotificationSync(NSProvider * provider, NSSync * sync)
 
     if (!NSThreadInit(NSNotificationSyncFunc, (void *) obj))
     {
-        NS_CONSUMER_LOG(ERROR, "execute noti post callback fail");
+        NS_LOG(ERROR, "execute noti post callback fail");
         return;
     }
 }
@@ -149,7 +150,7 @@ void NSNotificationPost(NSProvider * provider, NSMessage * msg)
     NSMessageData * obj = (NSMessageData *)OICMalloc(sizeof(NSMessageData));
     if (!obj)
     {
-        NS_CONSUMER_LOG(ERROR, "NSMessageData allocation is failed");
+        NS_LOG(ERROR, "NSMessageData allocation is failed");
         return;
     }
     obj->provider = provider;
@@ -157,7 +158,7 @@ void NSNotificationPost(NSProvider * provider, NSMessage * msg)
 
     if (!NSThreadInit(NSNotificationPostFunc, (void *) obj))
     {
-        NS_CONSUMER_LOG(ERROR, "execute noti post callback fail");
+        NS_LOG(ERROR, "execute noti post callback fail");
         return;
     }
 }
@@ -213,7 +214,7 @@ NSMessage_consumer * NSCopyMessage(NSMessage_consumer * msg)
     newMsg->addr = (OCDevAddr *)OICMalloc(sizeof(OCDevAddr));
     if (!newMsg->addr)
     {
-        NS_CONSUMER_LOG(ERROR, "OCDevAddr allocation is failed");
+        NS_LOG(ERROR, "OCDevAddr allocation is failed");
     }
     memcpy(newMsg->addr, msg->addr, sizeof(OCDevAddr));
 
@@ -260,10 +261,3 @@ OCStackResult NSRequestToResourceIntrospection(OCDoHandle * handle,
             payload, CT_DEFAULT, NS_QOS, &cbdata, NULL, 0);
 }
 
-const char * NS_CONVERT_LEVEL(int level)
-{
-    return ((level) == 0) ? "DEBUG" :
-           ((level) == 1) ? "INFO" :
-           ((level) == 2) ? "WARNING" :
-           ((level) == 3) ? "ERROR" : "FATAL";
-}
index 4a09769..00d7612 100644 (file)
@@ -31,30 +31,7 @@ extern "C" {
 #include "NSCommon.h"
 #include "NSStructs.h"
 #include "ocstack.h"
-
-#define NS_LOG_PRINTF 0
-
-#define __NS_FILE__ ( strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__ )
-
-const char * NS_CONVERT_LEVEL(int level);
-
-// TODO fix ns log using oic log.
-#ifdef TB_LOG
-#include "logger.h"
-#define NS_CONSUMER_LOG_V(level, format, ...) (OIC_LOG_V((level), __NS_FILE__, (format), __VA_ARGS__))
-#define NS_CONSUMER_LOG(level, msg) (OIC_LOG((level), __NS_FILE__, (msg)))
-#else
-#include "logger.h"
-#define NS_CONSUMER_LOG_V(level, format, ...) { \
-        printf("%s: %s ", NS_CONVERT_LEVEL(level), __NS_FILE__); \
-        printf((format), __VA_ARGS__); \
-        printf("\n"); }
-#define NS_CONSUMER_LOG(level, msg) { \
-        printf("%s: %s ", NS_CONVERT_LEVEL(level), __NS_FILE__); \
-        printf((msg)); \
-        printf("\n"); }
-
-#endif
+#include "NSConsumerInterface.h"
 
 #define NS_QOS OC_LOW_QOS
 #define NS_RESOURCE_TYPE "oic.r.notification"
index dc6ab9a..0eed05c 100644 (file)
@@ -23,6 +23,7 @@
 #include <string.h>
 #include "NSCommon.h"
 #include "NSConsumerCommon.h"
+#include "NSConstants.h"
 #include "ocpayload.h"
 #include "oic_malloc.h"
 
@@ -42,11 +43,11 @@ OCStackApplicationResult NSConsumerPresenceListener(
         OCDoHandle handle, OCClientResponse * clientResponse)
 {
     (void) handle;
-    NS_CONSUMER_LOG_V(DEBUG, "Presence income : %s:%d",
+    NS_LOG_V(DEBUG, "Presence income : %s:%d",
             clientResponse->devAddr.addr, clientResponse->devAddr.port);
-    NS_CONSUMER_LOG_V(DEBUG, "Presence result : %d",
+    NS_LOG_V(DEBUG, "Presence result : %d",
             clientResponse->result);
-    NS_CONSUMER_LOG_V(DEBUG, "Presence sequenceNum : %d",
+    NS_LOG_V(DEBUG, "Presence sequenceNum : %d",
             clientResponse->sequenceNumber);
 
     if (!NSIsStartedConsumer())
@@ -59,7 +60,7 @@ OCStackApplicationResult NSConsumerPresenceListener(
             clientResponse->result == OC_STACK_PRESENCE_STOPPED)
     {
         // TODO find request and cancel
-        NS_CONSUMER_LOG(DEBUG, "stopped presence or resource is deleted.");
+        NS_LOG(DEBUG, "stopped presence or resource is deleted.");
         //OCCancel(handle, NS_QOS, NULL, 0);
     }
 
@@ -76,11 +77,11 @@ OCStackApplicationResult NSProviderDiscoverListener(
         OCDoHandle handle, OCClientResponse * clientResponse)
 {
     (void) handle;
-    NS_CONSUMER_LOG_V(DEBUG, "Discover income : %s:%d",
+    NS_LOG_V(DEBUG, "Discover income : %s:%d",
             clientResponse->devAddr.addr, clientResponse->devAddr.port);
-    NS_CONSUMER_LOG_V(DEBUG, "Discover result : %d",
+    NS_LOG_V(DEBUG, "Discover result : %d",
             clientResponse->result);
-    NS_CONSUMER_LOG_V(DEBUG, "Discover sequenceNum : %d",
+    NS_LOG_V(DEBUG, "Discover sequenceNum : %d",
             clientResponse->sequenceNumber);
 
     if (!NSIsStartedConsumer())
@@ -114,13 +115,13 @@ OCStackApplicationResult NSGetProviderInformation(
     (void) handle;
     int64_t accepter = 0;
 
-    NS_CONSUMER_LOG_V(DEBUG, "GET response income : %s:%d",
+    NS_LOG_V(DEBUG, "GET response income : %s:%d",
             clientResponse->devAddr.addr, clientResponse->devAddr.port);
-    NS_CONSUMER_LOG_V(DEBUG, "GET response result : %d",
+    NS_LOG_V(DEBUG, "GET response result : %d",
             clientResponse->result);
-    NS_CONSUMER_LOG_V(DEBUG, "GET response sequenceNum : %d",
+    NS_LOG_V(DEBUG, "GET response sequenceNum : %d",
             clientResponse->sequenceNumber);
-    NS_CONSUMER_LOG_V(DEBUG, "GET response resource uri : %s",
+    NS_LOG_V(DEBUG, "GET response resource uri : %s",
             clientResponse->resourceUri);
 
     if (!NSIsStartedConsumer())
@@ -130,21 +131,21 @@ OCStackApplicationResult NSGetProviderInformation(
 
     if (!clientResponse->payload)
     {
-        NS_CONSUMER_LOG(ERROR, "payload is null");
+        NS_LOG(ERROR, "payload is null");
         return OC_STACK_KEEP_TRANSACTION;
     }
 
     if (!OCRepPayloadGetPropInt((OCRepPayload *)clientResponse->payload,
             NS_PAYLOAD_KEY_ACCEPTER, & accepter))
     {
-        NS_CONSUMER_LOG(ERROR, "can not seach for accepter");
+        NS_LOG(ERROR, "can not seach for accepter");
         return OC_STACK_KEEP_TRANSACTION;
     }
 
     NSProvider * newProvider = (NSProvider *)OICMalloc(sizeof(NSProvider));
     if (!newProvider)
     {
-        NS_CONSUMER_LOG(DEBUG, "NSProvider allocation fail");
+        NS_LOG(DEBUG, "NSProvider allocation fail");
         return OC_STACK_KEEP_TRANSACTION;
     }
 
@@ -153,7 +154,7 @@ OCStackApplicationResult NSGetProviderInformation(
     newProvider->mUserData = (void *)OICMalloc(sizeof(OCDevAddr));
     if (!newProvider)
     {
-        NS_CONSUMER_LOG(DEBUG, "OCDevAddr allocation fail");
+        NS_LOG(DEBUG, "OCDevAddr allocation fail");
         OICFree(newProvider);
         return OC_STACK_KEEP_TRANSACTION;
     }
@@ -163,7 +164,7 @@ OCStackApplicationResult NSGetProviderInformation(
         OCRepPayload * payload = (OCRepPayload *)clientResponse->payload;
         while (payload)
         {
-            NS_CONSUMER_LOG_V(DEBUG, "Payload Key : %s", payload->values->name);
+            NS_LOG_V(DEBUG, "Payload Key : %s", payload->values->name);
             payload = payload->next;
         }
     }
@@ -173,7 +174,7 @@ OCStackApplicationResult NSGetProviderInformation(
     {
         OICFree(newProvider->mUserData);
         OICFree(newProvider);
-        NS_CONSUMER_LOG(ERROR, "can not seach for message uri");
+        NS_LOG(ERROR, "can not seach for message uri");
         return OC_STACK_KEEP_TRANSACTION;
     }
 
@@ -183,24 +184,24 @@ OCStackApplicationResult NSGetProviderInformation(
         OICFree(newProvider->messageUri);
         OICFree(newProvider->mUserData);
         OICFree(newProvider);
-        NS_CONSUMER_LOG(ERROR, "can not seach for sync uri");
+        NS_LOG(ERROR, "can not seach for sync uri");
         return OC_STACK_KEEP_TRANSACTION;
     }
 
     if (accepter == NS_ACCEPTER_CONSUMER)
     {
-        NS_CONSUMER_LOG(DEBUG, "accepter is NS_ACCEPTER_CONSUMER, Callback to user");
+        NS_LOG(DEBUG, "accepter is NS_ACCEPTER_CONSUMER, Callback to user");
 
         NSDiscoveredProvider(newProvider);
     }
     else
     {
-        NS_CONSUMER_LOG(DEBUG, "accepter is NS_ACCEPTER_PROVIDER, request subscribe");
+        NS_LOG(DEBUG, "accepter is NS_ACCEPTER_PROVIDER, request subscribe");
 
         NSTask * task = NSMakeTask(TASK_CONSUMER_REQ_SUBSCRIBE, (void *) newProvider);
         if (!task)
         {
-            NS_CONSUMER_LOG(DEBUG, "NSTask allocation fail");
+            NS_LOG(DEBUG, "NSTask allocation fail");
             return OC_STACK_KEEP_TRANSACTION;
         }
 
@@ -214,11 +215,11 @@ void NSConsumerDiscoveryHandleMsg(NSTask * task)
 {
     if (!task)
     {
-        NS_CONSUMER_LOG(ERROR, "task is null");
+        NS_LOG(ERROR, "task is null");
         return;
     }
 
-    NS_CONSUMER_LOG_V(DEBUG, "Receive Event : %d", (int)task->taskType);
+    NS_LOG_V(DEBUG, "Receive Event : %d", (int)task->taskType);
     if (task->taskType == TASK_EVENT_CONNECTED || task->taskType == TASK_CONSUMER_REQ_DISCOVER)
     {
         NSRequestToResourceIntrospection(NULL, OC_REST_DISCOVER, NULL, NS_DISCOVER_QUERY,
@@ -226,7 +227,7 @@ void NSConsumerDiscoveryHandleMsg(NSTask * task)
     }
     else
     {
-        NS_CONSUMER_LOG(ERROR, "Unknown type message");
+        NS_LOG(ERROR, "Unknown type message");
     }
 }
 
index a81aff2..558a7d3 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "NSCommon.h"
 #include "NSConsumerCommon.h"
+#include "NSConstants.h"
 #include "NSConsumerMessageHandler.h"
 #include "oic_malloc.h"
 
@@ -36,10 +37,28 @@ NSResult NSStartConsumer(
 {
     if (NSIsStartedConsumer())
     {
-        printf("is already started consumer service?\n");
+        NS_LOG(DEBUG, "is already started consumer service?");
         return NS_OK;
     }
 
+    if (!discoverCb)
+    {
+        NS_LOG(ERROR, "discoverCb is NULL");
+        return NS_ERROR;
+    }
+
+    if (!postCb)
+    {
+        NS_LOG(ERROR, "postCb is NULL");
+        return NS_ERROR;
+    }
+
+    if (!syncCb)
+    {
+        NS_LOG(ERROR, "syncCb is NULL");
+        return NS_ERROR;
+    }
+
     NSSetDiscoverProviderCb(discoverCb);
     NSSetNotificationPostedCb(postCb);
     NSSetNotificationSyncCb(syncCb);
@@ -47,6 +66,7 @@ NSResult NSStartConsumer(
 
     if (NS_OK != NSConsumerMessageHandlerInit())
     {
+        NSStopConsumer();
         return NS_ERROR;
     }
 
@@ -60,27 +80,29 @@ NSResult NSStopConsumer()
     NSSetNotificationSyncCb(NULL);
     NSSetIsStartedConsumer(false);
 
+    NSConsumerMessageHandlerExit();
+
     return NS_OK;
 }
 
-NSResult NSSubscribeProvider(NSProvider * provider)
+NSResult NSSubscribe(NSProvider * provider)
 {
     NSTask * subscribeTask = NSMakeTask(TASK_CONSUMER_REQ_SUBSCRIBE, (void *) provider);
     if (!subscribeTask)
     {
-        NS_CONSUMER_LOG(ERROR, "NSTask allocation fail");
+        NS_LOG(ERROR, "NSTask allocation fail");
         return NS_ERROR;
     }
 
     return NSConsumerPushEvent(subscribeTask);
 }
 
-NSResult NSUnsubscribeProvider(NSProvider * provider)
+NSResult NSUnsubscribe(NSProvider * provider)
 {
     NSTask * unsubscribeTask = NSMakeTask(TASK_CONSUMER_REQ_SUBSCRIBE_CANCEL, (void *) provider);
     if (!unsubscribeTask)
     {
-        NS_CONSUMER_LOG(ERROR, "NSTask allocation fail");
+        NS_LOG(ERROR, "NSTask allocation fail");
         return NS_ERROR;
     }
 
@@ -92,31 +114,31 @@ NSResult NSRescanProvider()
     NSTask * discoverTask = NSMakeTask(TASK_CONSUMER_REQ_DISCOVER, NULL);
     if (!discoverTask)
     {
-        NS_CONSUMER_LOG(ERROR, "NSTask allocation fail");
+        NS_LOG(ERROR, "NSTask allocation fail");
         return NS_ERROR;
     }
 
     return NSConsumerPushEvent(discoverTask);
 }
 
-NSResult NSRead(NSMessage * obj)
+NSResult NSConsumerReadCheck(NSMessage * obj)
 {
     NSTask * readTask = NSMakeTask(TASK_SEND_READ, (void *) obj);
     if (!readTask)
     {
-        NS_CONSUMER_LOG(ERROR, "NSTask allocation fail");
+        NS_LOG(ERROR, "NSTask allocation fail");
         return NS_ERROR;
     }
 
     return NSConsumerPushEvent(readTask);
 }
 
-NSResult NSDismiss(NSMessage * obj)
+NSResult NSConsumerDismissCheck(NSMessage * obj)
 {
     NSTask * dismissTask = NSMakeTask(TASK_SEND_DISMISS, (void *) obj);
     if (!dismissTask)
     {
-        NS_CONSUMER_LOG(ERROR, "NSTask allocation fail");
+        NS_LOG(ERROR, "NSTask allocation fail");
         return NS_ERROR;
     }
 
index 8cba403..18adc7b 100644 (file)
@@ -23,6 +23,7 @@
 #include <memory.h>
 #include <string.h>
 
+#include "NSConstants.h"
 #include "NSConsumerCommon.h"
 #include "payload_logging.h"
 #include "cautilinterface.h"
@@ -56,14 +57,14 @@ NSResult NSConsumerListenerInit()
     if (OC_STACK_OK != NSRequestToResourceIntrospection(NULL, OC_REST_PRESENCE, NULL,
             NS_PRESENCE_SUBSCRIBE_QUERY, NULL, NSConsumerPresenceListener))
     {
-        NS_CONSUMER_LOG(ERROR, "Presence request fail");
+        NS_LOG(ERROR, "Presence request fail");
         return NS_ERROR;
     }
 
     if (OC_STACK_OK != NSRequestToResourceIntrospection(NULL, OC_REST_DISCOVER, NULL,
             NS_DISCOVER_QUERY, NULL, NSProviderDiscoverListener))
     {
-        NS_CONSUMER_LOG(ERROR, "Discover request fail");
+        NS_LOG(ERROR, "Discover request fail");
         return NS_ERROR;
     }
 
@@ -75,7 +76,7 @@ OCStackApplicationResult NSRIResponseListener(
 {
     if (ctx == NULL)
     {
-        NS_CONSUMER_LOG(ERROR, "Callback is null");
+        NS_LOG(ERROR, "Callback is null");
         return OC_STACK_DELETE_TRANSACTION;
     }
 
@@ -84,6 +85,10 @@ OCStackApplicationResult NSRIResponseListener(
         OIC_LOG_PAYLOAD(INFO, clientResponse->payload);
         ((onRIResponse)ctx)(handle, clientResponse);
     }
+    else
+    {
+        NS_LOG_V(ERROR, "result is not ok : %d", clientResponse->result);
+    }
 
     return OC_STACK_KEEP_TRANSACTION;
 }
@@ -91,21 +96,21 @@ OCStackApplicationResult NSRIResponseListener(
 void NSConnectionStateListener(CATransportAdapter_t adapter,
         const char *remote_address, bool connected)
 {
-    NS_CONSUMER_LOG_V(DEBUG, "adapter : %d", adapter);
-    NS_CONSUMER_LOG_V(DEBUG, "remote_address : %s", remote_address);
-    NS_CONSUMER_LOG_V(DEBUG, "isConnect : %d", connected);
+    NS_LOG_V(DEBUG, "adapter : %d", adapter);
+    NS_LOG_V(DEBUG, "remote_address : %s", remote_address);
+    NS_LOG_V(DEBUG, "isConnect : %d", connected);
 
     (void) adapter;
     (void) remote_address;
 
     if (connected)
     {
-        NS_CONSUMER_LOG(DEBUG, "try to discover notification provider.");
+        NS_LOG(DEBUG, "try to discover notification provider.");
 
         NSTask * task = NSMakeTask(TASK_EVENT_CONNECTED, NULL);
         if (!task)
         {
-            NS_CONSUMER_LOG(ERROR, "NSTask allocation fail.");
+            NS_LOG(ERROR, "NSTask allocation fail.");
             return;
         }
         NSConsumerPushEvent(task);
@@ -114,19 +119,19 @@ void NSConnectionStateListener(CATransportAdapter_t adapter,
 
 void NSAdapterStateListener(CATransportAdapter_t adapter, bool enabled)
 {
-    NS_CONSUMER_LOG_V(DEBUG, "adapter : %d", adapter);
-    NS_CONSUMER_LOG_V(DEBUG, "isEnabled : %d", enabled);
+    NS_LOG_V(DEBUG, "adapter : %d", adapter);
+    NS_LOG_V(DEBUG, "isEnabled : %d", enabled);
 
     (void) adapter;
 
     if (enabled)
     {
-        NS_CONSUMER_LOG(DEBUG, "try to discover notification provider.");
+        NS_LOG(DEBUG, "try to discover notification provider.");
 
         NSTask * task = NSMakeTask(TASK_EVENT_CONNECTED, NULL);
         if (!task)
         {
-            NS_CONSUMER_LOG(ERROR, "NSTask allocation fail.");
+            NS_LOG(ERROR, "NSTask allocation fail.");
             return;
         }
         NSConsumerPushEvent(task);
index 831ff04..6e0fcbc 100644 (file)
@@ -26,6 +26,7 @@
 #include "oic_malloc.h"
 
 #include "NSStructs.h"
+#include "NSConstants.h"
 #include "NSConsumerCommon.h"
 
 #include "NSThread.h"
@@ -72,20 +73,20 @@ NSResult NSConsumerMessageHandlerInit()
 
     if (NS_OK != NSConsumerListenerInit())
     {
-        NS_CONSUMER_LOG(ERROR, "listener init fail");
+        NS_LOG(ERROR, "listener init fail");
         return NS_ERROR;
     }
 
     if (NS_OK != NSConsumerSystemInit())
     {
-        NS_CONSUMER_LOG(ERROR, "system init fail");
+        NS_LOG(ERROR, "system init fail");
         return NS_ERROR;
     }
 
     handle = NSThreadInit(NSConsumerMsgHandleThreadFunc, NULL);
     if (!handle)
     {
-        NS_CONSUMER_LOG(ERROR, "msg handle thread init fail");
+        NS_LOG(ERROR, "msg handle thread init fail");
         return NS_ERROR;
     }
     NSSetMsgHandleThreadHandle(handle);
@@ -93,7 +94,7 @@ NSResult NSConsumerMessageHandlerInit()
     queue = NSCreateQueue();
     if (!queue)
     {
-        NS_CONSUMER_LOG(ERROR, "msg handle queue create fail");
+        NS_LOG(ERROR, "msg handle queue create fail");
         return NS_ERROR;
     }
     NSSetMsgHandleQueue(queue);
@@ -105,7 +106,7 @@ NSResult NSConsumerPushEvent(NSTask * task)
 {
     if (!NSThreadInit(NSConsumerMsgPushThreadFunc, (void *) task))
     {
-        NS_CONSUMER_LOG(ERROR, "insert to queue thread init fail");
+        NS_LOG(ERROR, "insert to queue thread init fail");
         return NS_ERROR;
     }
 
@@ -122,10 +123,10 @@ void * NSConsumerMsgHandleThreadFunc(void * threadHandle)
     NSConsumerQueue * queue = NULL;
     NSConsumerQueueObject * obj = NULL;
     NSThreadHandle * handle = (NSThreadHandle *) threadHandle;
-    NS_CONSUMER_LOG(DEBUG, "created thread for consumer message handle");
+    NS_LOG(DEBUG, "created thread for consumer message handle");
     if (!handle)
     {
-        NS_CONSUMER_LOG(ERROR, "thread handle is null");
+        NS_LOG(ERROR, "thread handle is null");
         return NULL;
     }
 
@@ -133,7 +134,7 @@ void * NSConsumerMsgHandleThreadFunc(void * threadHandle)
     {
         if (!handle->isStarted)
         {
-            NS_CONSUMER_LOG(ERROR, "msg handler thread will be terminated");
+            NS_LOG(ERROR, "msg handler thread will be terminated");
             break;
         }
 
@@ -149,11 +150,13 @@ void * NSConsumerMsgHandleThreadFunc(void * threadHandle)
         }
 
         NSThreadLock(handle);
-        NS_CONSUMER_LOG(DEBUG, "msg handler working");
+        NS_LOG(DEBUG, "msg handler working");
         obj = NSPopQueue(queue);
-        // TODO processing obj
 
-        NSConsumerHandleMsg((NSTask *)(obj->data));
+        if (obj)
+        {
+            NSConsumerHandleMsg((NSTask *)(obj->data));
+        }
 
         NSThreadUnlock(handle);
 
@@ -169,14 +172,14 @@ void * NSConsumerMsgPushThreadFunc(void * data)
     NSThreadHandle * handle = *(NSGetMsgHandleThreadHandle());
     if (!handle)
     {
-        NS_CONSUMER_LOG(ERROR, "NSThreadHandle is null. can not insert to queue");
+        NS_LOG(ERROR, "NSThreadHandle is null. can not insert to queue");
         return NULL;
     }
 
     obj = (NSConsumerQueueObject *)OICMalloc(sizeof(NSConsumerQueueObject));
     if (!obj)
     {
-        NS_CONSUMER_LOG(ERROR, "NSConsumerQueueObject allocation fail");
+        NS_LOG(ERROR, "NSConsumerQueueObject allocation fail");
         return NULL;
     }
 
@@ -188,7 +191,7 @@ void * NSConsumerMsgPushThreadFunc(void * data)
     queue = *(NSGetMsgHandleQueue());
     if (!queue)
     {
-        NS_CONSUMER_LOG(ERROR, "NSQueue is null. can not insert to queue");
+        NS_LOG(ERROR, "NSQueue is null. can not insert to queue");
         OICFree(data);
         OICFree(obj);
     }
@@ -213,6 +216,7 @@ void NSConsumerHandleMsg(NSTask * task)
         break;
     }
     case TASK_CONSUMER_REQ_SUBSCRIBE:
+    case TASK_CONSUMER_REQ_SUBSCRIBE_CANCEL:
     case TASK_SEND_READ:
     case TASK_SEND_DISMISS:
     {
@@ -227,7 +231,7 @@ void NSConsumerHandleMsg(NSTask * task)
         break;
     }
     default:
-        NS_CONSUMER_LOG(ERROR, "Unknown type of task");
+        NS_LOG(ERROR, "Unknown type of task");
         break;
     }
 }
index 84e81c0..62fc71e 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "NSConsumerNotification.h"
 
+#include "NSConstants.h"
 #include "NSConsumerCommon.h"
 #include "oic_malloc.h"
 #include "oic_string.h"
@@ -33,15 +34,15 @@ NSResult NSPushToCache(OCClientResponse * clientResponse, NSTaskType type);
 
 NSResult NSConsumerSubscribeProvider(NSProvider * provider)
 {
-    if (OC_STACK_OK != NSRequestToResourceIntrospection(NULL, OC_REST_OBSERVE,
-            (OCDevAddr *) provider->mUserData,
+    if (OC_STACK_OK != NSRequestToResourceIntrospection(&(provider->messageHandle),
+            OC_REST_OBSERVE, (OCDevAddr *) provider->mUserData,
             provider->messageUri, NULL, NSConsumerNotificationListener))
     {
         return NS_ERROR;
     }
 
-    if (OC_STACK_OK != NSRequestToResourceIntrospection(NULL, OC_REST_OBSERVE,
-            (OCDevAddr *) provider->mUserData,
+    if (OC_STACK_OK != NSRequestToResourceIntrospection(&(provider->syncHandle),
+            OC_REST_OBSERVE, (OCDevAddr *) provider->mUserData,
             provider->syncUri, NULL, NSConsumerSyncListener))
     {
         return NS_ERROR;
@@ -71,7 +72,7 @@ OCStackApplicationResult NSConsumerSyncListener(
     NSProvider * provider = NSGetProvider(clientResponse);
     if (!provider)
     {
-        NS_CONSUMER_LOG(ERROR, "getting provider is failed");
+        NS_LOG(ERROR, "getting provider is failed");
         return OC_STACK_KEEP_TRANSACTION;
     }
 
@@ -85,12 +86,12 @@ OCStackApplicationResult NSConsumerSyncListener(
 
     if (newNoti->mState != Notification_Read)
     {
-        NS_CONSUMER_LOG(DEBUG, "newNoti->type : Dismiss");
+        NS_LOG(DEBUG, "newNoti->type : Dismiss");
         taskType = TASK_RECV_DISMISS;
     }
     else
     {
-        NS_CONSUMER_LOG(DEBUG, "newNoti->type : Read");
+        NS_LOG(DEBUG, "newNoti->type : Read");
     }
 
     NSNotificationSync(provider, newNoti);
@@ -111,7 +112,7 @@ OCStackApplicationResult NSConsumerNotificationListener(
     NSProvider * provider = NSGetProvider(clientResponse);
     if (!provider)
     {
-        NS_CONSUMER_LOG(ERROR, "getting provider is failed");
+        NS_LOG(ERROR, "getting provider is failed");
         return OC_STACK_KEEP_TRANSACTION;
     }
 
@@ -123,7 +124,7 @@ OCStackApplicationResult NSConsumerNotificationListener(
 
     NSTaskType taskType = TASK_CONSUMER_RECV_NOTIFICATION;
 
-    NS_CONSUMER_LOG(DEBUG, "newNoti->type == Notification");
+    NS_LOG(DEBUG, "newNoti->type == Notification");
     NSNotificationPost(provider, (NSMessage *) newNoti);
 
     if (NS_OK != NSPushToCache(clientResponse, taskType))
@@ -145,7 +146,7 @@ NSResult NSPushToCache(OCClientResponse * clientResponse, NSTaskType type)
     NSTask * task = NSMakeTask(type, (void *) cachedNoti);
     if (!task)
     {
-        NS_CONSUMER_LOG(ERROR, "NSTask allocation fail");
+        NS_LOG(ERROR, "NSTask allocation fail");
         NSRemoveMessage(cachedNoti);
         return NS_ERROR;
     }
@@ -174,7 +175,7 @@ NSMessage_consumer * NSBuildOICNotification(OCClientResponse * clientResponse)
     OCRepPayload * payload = (OCRepPayload *)clientResponse->payload;
     if (!OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_ID, &retNoti->mId))
     {
-        NS_CONSUMER_LOG(ERROR, "id of received notification is null");
+        NS_LOG(ERROR, "id of received notification is null");
         OICFree(retNoti);
         return NULL;
     }
@@ -182,9 +183,10 @@ NSMessage_consumer * NSBuildOICNotification(OCClientResponse * clientResponse)
     OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_TITLE, &retNoti->mTitle);
     OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_TEXT, &retNoti->mContentText);
 
-    NS_CONSUMER_LOG_V(DEBUG, "Msg ID : %s", retNoti->mId);
-    NS_CONSUMER_LOG_V(DEBUG, "Msg Title : %s", retNoti->mTitle);
-    NS_CONSUMER_LOG_V(DEBUG, "Msg Content : %s", retNoti->mContentText);
+    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);
 
     retNoti->addr = (OCDevAddr *)OICMalloc(sizeof(OCDevAddr));
     memcpy(retNoti->addr, clientResponse->addr, sizeof(OCDevAddr));
@@ -212,14 +214,14 @@ NSSync * NSBuildOICNotificationSync(OCClientResponse * clientResponse)
     OCRepPayload * payload = (OCRepPayload *)clientResponse->payload;
     if (!OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_ID, &retSync->mMessageId))
     {
-        NS_CONSUMER_LOG(ERROR, "id of received sync is null");
+        NS_LOG(ERROR, "id of received sync is null");
         OICFree(retSync);
         return NULL;
     }
     int64_t state;
     if (!OCRepPayloadGetPropInt(payload, NS_ATTRIBUTE_STATE, & state))
     {
-        NS_CONSUMER_LOG(ERROR, "state of received sync is null");
+        NS_LOG(ERROR, "state of received sync is null");
         OICFree(retSync->mMessageId);
         OICFree(retSync);
         return NULL;
@@ -227,8 +229,8 @@ NSSync * NSBuildOICNotificationSync(OCClientResponse * clientResponse)
 
     retSync->mState = (NSSyncTypes) state;
 
-    NS_CONSUMER_LOG_V(DEBUG, "Sync ID : %s", retSync->mMessageId);
-    NS_CONSUMER_LOG_V(DEBUG, "Sync State : %d", (int) retSync->mState);
+    NS_LOG_V(DEBUG, "Sync ID : %s", retSync->mMessageId);
+    NS_LOG_V(DEBUG, "Sync State : %d", (int) retSync->mState);
 
     return retSync;
 }
@@ -238,7 +240,7 @@ NSProvider * NSGetProvider(OCClientResponse * clientResponse)
     NSProvider * newProvider = (NSProvider *)OICMalloc(sizeof(NSProvider));
     if (!newProvider)
     {
-        NS_CONSUMER_LOG(DEBUG, "NSProvider allocation fail");
+        NS_LOG(DEBUG, "NSProvider allocation fail");
         return NULL;
     }
 
@@ -247,7 +249,7 @@ NSProvider * NSGetProvider(OCClientResponse * clientResponse)
     newProvider->mUserData = (void *)OICMalloc(sizeof(OCDevAddr));
     if (!newProvider->mUserData)
     {
-        NS_CONSUMER_LOG(DEBUG, "OCDevAddr allocation fail");
+        NS_LOG(DEBUG, "OCDevAddr allocation fail");
         OICFree(newProvider);
         return NULL;
     }
@@ -260,16 +262,16 @@ void NSConsumerNotificationHandleMsg(NSTask * task)
 {
     if (!task)
     {
-        NS_CONSUMER_LOG(ERROR, "task is null");
+        NS_LOG(ERROR, "task is null");
         return;
     }
 
-    NS_CONSUMER_LOG_V(DEBUG, "Receive Event : %d", (int)task->taskType);
+    NS_LOG_V(DEBUG, "Receive Event : %d", (int)task->taskType);
     if (task->taskType == TASK_CONSUMER_REQ_SUBSCRIBE)
     {
         if (NS_OK != NSConsumerSubscribeProvider((NSProvider *)task->taskData))
         {
-            NS_CONSUMER_LOG(ERROR, "Subscribe fail");
+            NS_LOG(ERROR, "Subscribe fail");
             return;
         }
     }
@@ -278,29 +280,38 @@ void NSConsumerNotificationHandleMsg(NSTask * task)
         NSMessage_consumer * nsConsumer = (NSMessage_consumer *) task->taskData;
         if (!nsConsumer)
         {
-            NS_CONSUMER_LOG(ERROR, "taskData is NULL");
+            NS_LOG(ERROR, "taskData is NULL");
             return;
         }
 
         OCRepPayload * payload = OCRepPayloadCreate ();
         if (!payload)
         {
-            NS_CONSUMER_LOG(ERROR, "Failed to create POST payload object");
+            NS_LOG(ERROR, "Failed to create POST payload object");
             return;
         }
+
+        int type = (task->taskType == TASK_SEND_READ) ? 0 : 1;
         OCRepPayloadSetPropString(payload, "ID", (char *) nsConsumer->mId);
-        OCRepPayloadSetPropInt(payload, "STATE", (int) nsConsumer->type);
+        OCRepPayloadSetPropInt(payload, "STATE", type);
 
         // TODO fix param for uri
         if (NS_OK != NSConsumerPostProvider(
                 (OCDevAddr *) nsConsumer->addr, (OCPayload *) payload, "/notification/sync"))
         {
-            NS_CONSUMER_LOG(ERROR, "Subscribe fail");
+            NS_LOG(ERROR, "Subscribe fail");
             return;
         }
     }
+    else if (task->taskType == TASK_CONSUMER_REQ_SUBSCRIBE_CANCEL)
+    {
+        NSProvider * provider = (NSProvider *)task->taskData;
+
+        OCCancel(provider->messageHandle, NS_QOS, NULL, 0);
+        OCCancel(provider->syncHandle, NS_QOS, NULL, 0);
+    }
     else
     {
-        NS_CONSUMER_LOG(ERROR, "Unknown type message");
+        NS_LOG(ERROR, "Unknown type message");
     }
 }
index 8e0ded8..f37bec6 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "NSConsumerQueue.h"
 
+#include "NSConstants.h"
 #include "oic_malloc.h"
 #include "NSConsumerCommon.h"
 
@@ -60,7 +61,7 @@ bool NSPushQueue(NSConsumerQueue * queue, NSConsumerQueueObject * object)
 
     if (!object)
     {
-        NS_CONSUMER_LOG(ERROR, "object is null. can not insert to queue");
+        NS_LOG(ERROR, "object is null. can not insert to queue");
     }
 
     if (!(queue->head))
index 8df1f91..5b5eea3 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "NSConsumerSubsription.h"
 
+#include "NSConstants.h"
 #include "NSConsumerCommon.h"
 #include "NSConsumerCache.h"
 #include "NSStructs.h"
@@ -45,17 +46,17 @@ NSResult NSCacheUpdate(NSCacheList * cache, NSTask * task, NSConsumerMessageType
     NSCacheObject * obj = (NSCacheObject *)OICMalloc(sizeof(NSCacheObject));
     if (!obj)
     {
-        NS_CONSUMER_LOG(ERROR, "Cache allocation is failed");
+        NS_LOG(ERROR, "Cache allocation is failed");
     }
     obj->data = (NSCacheData *) noti;
     obj->next = NULL;
 
     if (NS_OK != NSConsumerCacheWrite(cache, obj))
     {
-        NS_CONSUMER_LOG(DEBUG, "CacheUpdate - NSConsumerCacheInsert");
+        NS_LOG(DEBUG, "CacheUpdate - NSConsumerCacheInsert");
         if (NS_OK != NSConsumerCacheInsert(cache, (NSCacheObject *) obj))
         {
-            NS_CONSUMER_LOG(ERROR, "Cache insert fail");
+            NS_LOG(ERROR, "Cache insert fail");
             return NS_ERROR;
         }
     }
@@ -70,18 +71,18 @@ void NSConsumerSubscriptionHandleMsg(NSTask * task)
 {
     if (!task)
     {
-        NS_CONSUMER_LOG(ERROR, "task is null");
+        NS_LOG(ERROR, "task is null");
         return;
     }
 
     NSCacheList * cache;
     if (!*(NSGetCacheList()))
     {
-        NS_CONSUMER_LOG(DEBUG, "Cache Init");
+        NS_LOG(DEBUG, "Cache Init");
         cache = NSConsumerCacheInit();
         if (!cache)
         {
-            NS_CONSUMER_LOG(ERROR, "Cache create fail");
+            NS_LOG(ERROR, "Cache create fail");
             return;
         }
         NSSetCacheList(cache);
@@ -89,52 +90,52 @@ void NSConsumerSubscriptionHandleMsg(NSTask * task)
     cache = *(NSGetCacheList());
     if (!cache->head)
     {
-        NS_CONSUMER_LOG(DEBUG, "Cache Head is null 2");
+        NS_LOG(DEBUG, "Cache Head is null 2");
     }
     else{
-        NS_CONSUMER_LOG(DEBUG, "Cache Head is not null 2");
+        NS_LOG(DEBUG, "Cache Head is not null 2");
     }
 
 
-    NS_CONSUMER_LOG_V(DEBUG, "Receive Event : %d", (int)task->taskType);
+    NS_LOG_V(DEBUG, "Receive Event : %d", (int)task->taskType);
 
     switch (task->taskType)
     {
         case TASK_CONSUMER_RECV_NOTIFICATION:
         {
-            NS_CONSUMER_LOG(DEBUG, "Receive New Notification");
+            NS_LOG(DEBUG, "Receive New Notification");
 
             if (NS_OK != NSCacheUpdate(cache, task, Notification))
             {
-                NS_CONSUMER_LOG(ERROR, "Cache Update fail");
+                NS_LOG(ERROR, "Cache Update fail");
                 return;
             }
             break;
         }
         case TASK_RECV_READ:
         {
-            NS_CONSUMER_LOG(DEBUG, "Receive Read Notification");
+            NS_LOG(DEBUG, "Receive Read Notification");
             // TODO update Cache.
             if (NS_OK != NSCacheUpdate(cache, task, Read))
             {
-                NS_CONSUMER_LOG(ERROR, "Cache Update fail");
+                NS_LOG(ERROR, "Cache Update fail");
                 return;
             }
             break;
         }
         case TASK_RECV_DISMISS:
         {
-            NS_CONSUMER_LOG(DEBUG, "Receive Dismiss Notification");
+            NS_LOG(DEBUG, "Receive Dismiss Notification");
             if (NS_OK != NSCacheUpdate(cache, task, Dismiss))
             {
-                NS_CONSUMER_LOG(ERROR, "Cache Update fail");
+                NS_LOG(ERROR, "Cache Update fail");
                 return;
             }
             break;
         }
         default :
         {
-            NS_CONSUMER_LOG(ERROR, "Unknown TASK Type");
+            NS_LOG(ERROR, "Unknown TASK Type");
             return ;
         }
     }
index 20b342f..d132b1c 100644 (file)
@@ -19,6 +19,8 @@
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
 #include "NSConsumerSystem.h"
+
+#include "NSConstants.h"
 #include "NSConsumerCommon.h"
 
 NSResult NSConsumerSystemInit()
index d75284c..810e176 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "NSThread.h"
 
+#include "NSConstants.h"
 #include "NSConsumerCommon.h"
 
 #include <memory.h>
@@ -31,14 +32,14 @@ NSThreadHandle * NSThreadInit(NSThreadFunc func, void * data)
 {
     if (!func)
     {
-        NS_CONSUMER_LOG(ERROR, "thread function is null");
+        NS_LOG(ERROR, "thread function is null");
         return NULL;
     }
 
     NSThreadHandle * handle = (NSThreadHandle *)OICMalloc(sizeof(NSThreadHandle));
     if (!handle)
     {
-        NS_CONSUMER_LOG(ERROR, "thread allocation fail");
+        NS_LOG(ERROR, "thread allocation fail");
         return NULL;
     }
 
@@ -47,21 +48,21 @@ NSThreadHandle * NSThreadInit(NSThreadFunc func, void * data)
     pthread_mutexattr_init(&(handle->mutex_attr));
     if (pthread_mutexattr_settype(&(handle->mutex_attr), PTHREAD_MUTEX_RECURSIVE))
     {
-        NS_CONSUMER_LOG(ERROR, "thread mutex_attr init fail");
+        NS_LOG(ERROR, "thread mutex_attr init fail");
         NSDestroyThreadHandle(handle);
         return NULL;
     }
 
     if (pthread_mutex_init(&(handle->mutex), &(handle->mutex_attr)))
     {
-        NS_CONSUMER_LOG(ERROR, "thread mutex init fail");
+        NS_LOG(ERROR, "thread mutex init fail");
         NSDestroyThreadHandle(handle);
         return NULL;
     }
 
     if (pthread_mutex_lock(&(handle->mutex)))
     {
-        NS_CONSUMER_LOG(ERROR, "thread mutex lock fail");
+        NS_LOG(ERROR, "thread mutex lock fail");
         NSDestroyThreadHandle(handle);
         return NULL;
     }
@@ -71,7 +72,7 @@ NSThreadHandle * NSThreadInit(NSThreadFunc func, void * data)
     if (pthread_create(&(handle->thread_id), NULL, func,
             (data == NULL) ? (void *) handle : (void *)data))
     {
-        NS_CONSUMER_LOG(ERROR, "thread create fail");
+        NS_LOG(ERROR, "thread create fail");
         NSDestroyThreadHandle(handle);
         return NULL;
     }
diff --git a/service/notification/src/provider/NSProviderCacheAdapter.c b/service/notification/src/provider/NSProviderCacheAdapter.c
deleted file mode 100644 (file)
index 0b5a270..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-//******************************************************************\r
-//\r
-// Copyright 2016 Samsung Electronics All Rights Reserved.\r
-//\r
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
-//\r
-// Licensed under the Apache License, Version 2.0 (the "License");\r
-// you may not use this file except in compliance with the License.\r
-// You may obtain a copy of the License at\r
-//\r
-//      http://www.apache.org/licenses/LICENSE-2.0\r
-//\r
-// Unless required by applicable law or agreed to in writing, software\r
-// distributed under the License is distributed on an "AS IS" BASIS,\r
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-// See the License for the specific language governing permissions and\r
-// limitations under the License.\r
-//\r
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
-#include "NSProviderCacheAdapter.h"\r
-\r
-\r
-NSWhiteList whiteMessageList;\r
-NSBlackList blackMessageList;\r
-\r
-NSWhiteList whiteSyncList;\r
-NSBlackList blackSyncList;\r
-\r
-NSResult NSProviderInitCache()\r
-{\r
-    // create cache\r
-\r
-    return NS_OK;\r
-}\r
-\r
-NSResult NSProviderWriteToCache(NSCache target, OCObservationId observeId, int state)\r
-{\r
-    printf("NSProviderWriteToCache - 0\n");\r
-    if(state == 0) // message\r
-    {\r
-        printf("NSProviderWriteToCache - 0 - 1\n");\r
-        if (NS_CONSUMER_BLACKLIST == target)\r
-        {\r
-            printf("NSProviderWriteToCache - 0 - 1 - 1\n");\r
-            blackMessageList.idList[blackMessageList.size] = observeId;\r
-            blackMessageList.size++;\r
-        }\r
-        else if (NS_CONSUMER_WHITELIST == target)\r
-        {\r
-            printf("NSProviderWriteToCache - 0 - 1 - 2\n");\r
-            whiteMessageList.idList[whiteMessageList.size] = observeId;\r
-            whiteMessageList.size++;\r
-        }\r
-    }\r
-    else if(state == 1)\r
-    {\r
-        printf("NSProviderWriteToCache - 1 - 1\n");\r
-        if (NS_CONSUMER_BLACKLIST == target)\r
-        {\r
-            printf("NSProviderWriteToCache - 1 - 1 - 1\n");\r
-            blackSyncList.idList[blackSyncList.size] = observeId;\r
-            blackSyncList.size++;\r
-        }\r
-        else if (NS_CONSUMER_WHITELIST == target)\r
-        {\r
-            printf("NSProviderWriteToCache - 1 - 1 - 2\n");\r
-            whiteSyncList.idList[whiteSyncList.size] = observeId;\r
-            whiteSyncList.size++;\r
-        }\r
-    }\r
-\r
-    return NS_OK;\r
-}\r
-\r
-NSCommonList * NSProviderReadCache(NSCache target, int state)\r
-{\r
-    if(state == 0) // message\r
-    {\r
-        if(NS_CONSUMER_BLACKLIST == target)\r
-        {\r
-            return (NSCommonList *)&blackMessageList;\r
-        }\r
-        else if(NS_CONSUMER_WHITELIST == target)\r
-        {\r
-            return (NSCommonList *)&whiteMessageList;\r
-        }\r
-    }\r
-    else if(state == 1)\r
-    {\r
-        if(NS_CONSUMER_BLACKLIST == target)\r
-        {\r
-            return (NSCommonList *)&blackSyncList;\r
-        }\r
-        else if(NS_CONSUMER_WHITELIST == target)\r
-        {\r
-            return (NSCommonList *)&whiteSyncList;\r
-        }\r
-    }\r
-    return NULL;\r
-}\r
-\r
-NSResult NSProviderDeleteCache()\r
-{\r
-    return NS_OK;\r
-}\r
index 975f0ca..5f245bc 100644 (file)
@@ -65,7 +65,7 @@ void * NSDiscoverySchedule(void * ptr)
             NSTask *node = NSHeadMsg[DISCOVERY_SCHEDULER];\r
             NSHeadMsg[DISCOVERY_SCHEDULER] = node->nextTask;\r
 \r
-            switch (node->taskType)\r
+            switch ((int)node->taskType)\r
             {\r
                 case TASK_START_PRESENCE:\r
                     NSStartPresence();\r
@@ -77,6 +77,7 @@ void * NSDiscoverySchedule(void * ptr)
                     NSRegisterResource();\r
                     break;\r
             }\r
+\r
             OICFree(node);\r
         }\r
 \r
index 31e5329..c020ecb 100644 (file)
@@ -23,7 +23,7 @@
 \r
 #include "NSCommon.h"\r
 #include "NSStructs.h"\r
-#include "NSQueueScheduler.h"\r
+#include "NSProviderScheduler.h"\r
 #include "NSProviderResource.h"\r
 \r
 NSResult NSStartPresence();\r
index f7ab929..16d98b3 100644 (file)
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
 \r
 #include "NSProviderInterface.h"\r
-#include "NSQueueScheduler.h"\r
+#include "NSProviderScheduler.h"\r
 #include "NSProviderListener.h"\r
+#include "NSCacheAdapter.h"\r
 #include "cautilinterface.h"\r
+#include "NSProviderSubscription.h"\r
+#include "NSProviderNotification.h"\r
 \r
-bool initSchedule = false;\r
+bool initProvider = false;\r
 static NSSubscribeRequestCallback g_subscribeRequestCb = NULL;\r
 static NSSyncCallback g_syncCb = NULL;\r
+pthread_mutex_t NSCacheMutex;\r
 \r
 void NSRegisterSubscribeRequestCb(NSSubscribeRequestCallback subscribeRequestCb)\r
 {\r
@@ -42,9 +46,9 @@ void NSSubscribeRequestCb(NSConsumer *consumer)
     g_subscribeRequestCb(consumer);\r
 }\r
 \r
-void NSSyncCb(NSProvider *provider, NSSync *sync)\r
+void NSSyncCb(NSSync *sync)\r
 {\r
-    g_syncCb(provider, sync);\r
+    g_syncCb(sync);\r
 }\r
 \r
 NSResult NSStartProvider(NSAccessPolicy policy, NSSubscribeRequestCallback subscribeRequestCb,\r
@@ -54,9 +58,11 @@ NSResult NSStartProvider(NSAccessPolicy policy, NSSubscribeRequestCallback subsc
 \r
     NSSetSubscriptionAcceptPolicy(policy);\r
 \r
-    if (!initSchedule)\r
+    if (!initProvider)\r
     {\r
-        initSchedule = true;\r
+        initProvider = true;\r
+\r
+        NSSetList();\r
         NSInitScheduler();\r
         NSStartScheduler();\r
     }\r
@@ -73,11 +79,18 @@ NSResult NSStartProvider(NSAccessPolicy policy, NSSubscribeRequestCallback subsc
     return NS_OK;\r
 }\r
 \r
+void NSSetList()\r
+{\r
+    pthread_mutex_init(&NSCacheMutex, NULL);\r
+    NSInitSubscriptionList();\r
+    NSInitMessageList();\r
+}\r
+\r
 NSResult NSStopProvider()\r
 {\r
-    NSRegisterSubscribeRequestCb(NULL);\r
-    NSRegisterSyncCb(NULL);\r
-    initSchedule = false;\r
+    NSRegisterSubscribeRequestCb((NSSubscribeRequestCallback)NULL);\r
+    NSRegisterSyncCb((NSSyncCallback)NULL);\r
+    initProvider = false;\r
     return NS_OK;\r
 }\r
 \r
@@ -90,22 +103,11 @@ NSResult NSSendNotification(NSMessage *msg)
     return NS_OK;\r
 }\r
 \r
-NSResult NSReadCheck(NSMessage *msg)\r
+NSResult NSProviderReadCheck(NSMessage *msg)\r
 {\r
     OIC_LOG(INFO, INTERFACE_TAG, "Read Sync");\r
 \r
-    NSTask * task = (NSTask*) OICMalloc(sizeof(NSTask));\r
-    if (!task)\r
-    {\r
-        OIC_LOG(ERROR, LISTENER_TAG, PCF("Fail to allocate memory"));\r
-        return NS_ERROR;\r
-    }\r
-\r
-    task->nextTask = NULL;\r
-    task->taskData = msg;\r
-    task->taskType = TASK_SEND_READ;\r
-\r
-    NSPushQueue(NOTIFICATION_SCHEDULER, task->taskType, task);\r
+    NSPushQueue(NOTIFICATION_SCHEDULER, TASK_SEND_READ, msg);\r
 \r
     return NS_OK;\r
 }\r
@@ -114,11 +116,19 @@ NSResult NSAccept(NSConsumer *consumer, bool accepted)
 {\r
     OIC_LOG(INFO, INTERFACE_TAG, "Response Acceptance");\r
 \r
-    NSPushQueue(SUBSCRIPTION_SCHEDULER, TASK_SEND_ALLOW, consumer);\r
+    if(accepted)\r
+    {\r
+        NSPushQueue(SUBSCRIPTION_SCHEDULER, TASK_SEND_ALLOW, consumer);\r
+    }\r
+    else\r
+    {\r
+        NSPushQueue(SUBSCRIPTION_SCHEDULER, TASK_SEND_DENY, consumer);\r
+    }\r
 \r
     return NS_OK;\r
 }\r
 \r
+/*\r
 NSResult NSGetConsumerList(uint8_t *list, uint32_t size)\r
 {\r
     OIC_LOG(INFO, INTERFACE_TAG, "Get consumer list");\r
@@ -127,13 +137,13 @@ NSResult NSGetConsumerList(uint8_t *list, uint32_t size)
     size = NSGetNumberOfObsList();\r
 \r
     return NS_OK;\r
-}\r
+}*/\r
 \r
 void * NSResponseSchedule(void * ptr)\r
 {\r
     if (ptr == NULL)\r
     {\r
-        OIC_LOG(ERROR, INTERFACE_TAG, "Fail to response to User");\r
+        OIC_LOG(INFO, INTERFACE_TAG, "Init NSResponseSchedule");\r
     }\r
 \r
     while (NSIsRunning[RESPONSE_SCHEDULER])\r
@@ -153,8 +163,9 @@ void * NSResponseSchedule(void * ptr)
                     printf("before - TASK_CB_SUBSCRIPTION :\n");\r
                     OCEntityHandlerRequest * request = (OCEntityHandlerRequest*)node->taskData;\r
                     NSConsumer consumer;\r
+\r
                     consumer.mId = strdup(request->devAddr.addr);\r
-                    int * obId = (int *) malloc (sizeof(int));\r
+                    int * obId = (int *) OICMalloc(sizeof(int));\r
                     *obId = request->obsInfo.obsId;\r
                     consumer.mUserData = obId;\r
 \r
@@ -165,7 +176,7 @@ void * NSResponseSchedule(void * ptr)
                 case TASK_CB_SYNC:\r
                 {\r
                     NSSync * sync = (NSSync*)node->taskData;\r
-                    NSSyncCb(NULL, sync);\r
+                    NSSyncCb(sync);\r
                     break;\r
                 }\r
                 default:\r
index 35edddf..7c59380 100644 (file)
@@ -31,6 +31,8 @@ OCEntityHandlerResult NSEntityHandlerNotificationCb(OCEntityHandlerFlag flag,
     { },\r
     { 0 }, false };\r
 \r
+    (void)callback;\r
+\r
     // Validate pointer\r
     if (!entityHandlerRequest)\r
     {\r
@@ -53,7 +55,7 @@ OCEntityHandlerResult NSEntityHandlerNotificationCb(OCEntityHandlerFlag flag,
         {\r
             OIC_LOG (INFO, LISTENER_TAG, "Received OC_REST_GET from client");\r
 \r
-            NSPushQueue(SUBSCRIPTION_SCHEDULER, TASK_SEND_POLICY, entityHandlerRequest);\r
+            NSPushQueue(SUBSCRIPTION_SCHEDULER, TASK_SEND_POLICY, (void *)entityHandlerRequest);\r
             ehResult = OC_EH_OK;\r
 \r
         }\r
@@ -150,6 +152,8 @@ OCEntityHandlerResult NSEntityHandlerMessageCb(OCEntityHandlerFlag flag,
     { },\r
     { 0 }, false };\r
 \r
+    (void)callback;\r
+\r
     // Validate pointer\r
     if (!entityHandlerRequest)\r
     {\r
@@ -272,6 +276,8 @@ OCEntityHandlerResult NSEntityHandlerSyncCb(OCEntityHandlerFlag flag,
     { },\r
     { 0 }, false };\r
 \r
+    (void)callback;\r
+\r
     // Validate pointer\r
     if (!entityHandlerRequest)\r
     {\r
index aabb82a..152dcca 100644 (file)
@@ -28,6 +28,7 @@
 #include "NSStructs.h"\r
 #include "NSConstants.h"\r
 #include "NSProviderSystem.h"\r
+#include "NSProviderScheduler.h"\r
 #include "cautilinterface.h"\r
 \r
 OCEntityHandlerResult NSEntityHandlerNotificationCb(OCEntityHandlerFlag flag,\r
index 98c23cb..3c31b98 100644 (file)
 
 #include "NSProviderNotification.h"
 
-NSResult NSGetObsIdList(OCObservationId *list)
+NSResult NSInitMessageList()
 {
-    // // TODO: return white list
-
-    list = NULL;
-
+    messageList = NSCacheCreate();
+    messageList->cacheType = NS_PROVIDER_CACHE_MESSAGE;
     return NS_OK;
 }
 
-uint32_t NSGetNumberOfObsList()
-{
-    // TODO: return # of list
-
-    return 0;
-}
-
 NSResult NSGetMessagePayload(NSMessage *msg, OCRepPayload** msgPayload)
 {
 
@@ -79,6 +70,9 @@ NSResult NSSendMessage(NSMessage *msg)
     int i;
     // Set Resource and get resource handle
     OCResourceHandle rHandle;
+    OCObservationId obArray[255] =
+    { 0, };
+    int obCount = 0;
     if (NSPutMessageResource(msg, &rHandle) != NS_OK)
     {
         OIC_LOG(ERROR, NOTIFICATION_TAG, PCF("Fail to put notification resource"));
@@ -87,11 +81,9 @@ NSResult NSSendMessage(NSMessage *msg)
 
     // Send Notification to subscribers
 
-    NSWhiteList * whiteList = NSProviderReadCache(NS_CONSUMER_WHITELIST, 0);
-
-    if(whiteList->size == 0)
+    if (consumerSubList->head == NULL)
     {
-        printf("printf - no observers\n");
+        printf("printf - no observers (consumerSubList->head == NULL)\n");
         OIC_LOG(ERROR, NOTIFICATION_TAG, PCF("no observers"));
         return NS_ERROR;
     }
@@ -105,28 +97,51 @@ NSResult NSSendMessage(NSMessage *msg)
         return NS_ERROR;
     }
 
-    for(i = 0; i < whiteList->size; ++i)
+    printf("printf - no observers - 3\n");
+    NSCacheElement * it = consumerSubList->head;
+    printf("printf - no observers - 4\n");
+    while (it)
+    {
+        printf("printf - no observers - 5\n");
+        NSCacheSubData * subData = (NSCacheSubData *) it->data;
+        printf("NS_ subData->id = %s\n", subData->id);
+        printf("NS_ subData->messageId = %d\n", subData->messageObId);
+        printf("NS_ subData->obID = %d\n", subData->syncObId);
+        printf("NS_ subData->isWhite = %d\n", subData->isWhite);
+
+        printf("printf - no observers - 6\n");
+        if (subData->isWhite)
+        {
+            printf("printf - no observers - 7\n");
+            obArray[obCount++] = subData->messageObId;
+            printf("printf - no observers - 8\n");
+        }
+
+        it = it->next;
+    }
+    printf("printf - no observers - 9\n");
+    for (i = 0; i < obCount; ++i)
     {
         printf("NS_ -------------------------------------------------------message\n");
-        printf("NS_ whiteList->idList[%d] = %d\n", i, whiteList->idList[i]);
+        printf("NS_ whiteList->idList[%d] = %d\n", i, obArray[i]);
         printf("NS_ -------------------------------------------------------message\n");
     }
-
+    printf("printf - no observers - 10\n");
     // Notify message to subscribers
 
-    OCStackResult ocstackResult = OCNotifyListOfObservers(rHandle, whiteList->idList, whiteList->size, payload, OC_LOW_QOS);
+    OCStackResult ocstackResult = OCNotifyListOfObservers(rHandle, obArray, obCount, payload,
+            OC_LOW_QOS);
     printf("NS_ message ocstackResult = %d\n", ocstackResult);
 
-
     if (ocstackResult != OC_STACK_OK)
     {
-        printf("printf - no observers - 3\n");
+        printf("printf - no observers - 11\n");
         OIC_LOG(ERROR, NOTIFICATION_TAG, "fail to send message");
         OCRepPayloadDestroy(payload);
         return NS_ERROR;
 
     }
-    printf("printf - no observers - 4\n");
+    printf("printf - no observers - 12\n");
     OCRepPayloadDestroy(payload);
 
     return NS_OK;
@@ -135,8 +150,10 @@ NSResult NSSendMessage(NSMessage *msg)
 NSResult NSSendSync(NSSync *sync)
 {
     OIC_LOG(DEBUG, NOTIFICATION_TAG, "Send Notification Sync to consumer");
+
+    OCObservationId obArray[255] = { 0, };
+    int obCount = 0;
     int i;
-    // Set Resource and get resource handle
 
     OCResourceHandle rHandle;
     if (NSPutSyncResource(sync, &rHandle) != NS_OK)
@@ -145,12 +162,18 @@ NSResult NSSendSync(NSSync *sync)
         return NS_ERROR;
     }
 
-    NSWhiteList * whiteList = NSProviderReadCache(NS_CONSUMER_WHITELIST, 1);
+    NSCacheElement * it = consumerSubList->head;
 
-    if(whiteList->size == 0)
+    while (it)
     {
-        OIC_LOG(ERROR, NOTIFICATION_TAG, PCF("no observers"));
-        return NS_ERROR;
+        NSCacheSubData * subData = (NSCacheSubData *) it->data;
+        if (subData->isWhite)
+        {
+            obArray[obCount++] = subData->syncObId;
+        }
+
+        it = it->next;
+
     }
 
     // Send sync to subscribers
@@ -164,14 +187,15 @@ NSResult NSSendSync(NSSync *sync)
 
     // Notify sync to subscribers
 
-    for(i = 0; i < whiteList->size; ++i)
+    for (i = 0; i < obCount; ++i)
     {
-        printf("NS_ -------------------------------------------------------sync\n");
-        printf("NS_ whiteList->idList[%d] = %d\n", i, whiteList->idList[i]);
-        printf("NS_ -------------------------------------------------------sync\n");
+        printf("NS_ -------------------------------------------------------message\n");
+        printf("NS_ whiteList->idList[%d] = %d\n", i, obArray[i]);
+        printf("NS_ -------------------------------------------------------message\n");
     }
 
-    OCStackResult ocstackResult = OCNotifyListOfObservers(rHandle, whiteList->idList, whiteList->size, payload, OC_LOW_QOS);
+    OCStackResult ocstackResult = OCNotifyListOfObservers(rHandle, obArray,
+            obCount, payload, OC_LOW_QOS);
 
     printf("NS_ sync ocstackResult = %d\n", ocstackResult);
     if (ocstackResult != OC_STACK_OK)
index e8afe37..e51b493 100644 (file)
 #define _NS_PROVIDER_NOTIFICATION_H_\r
 \r
 #include <ocstack.h>\r
+#include "../common/NSCacheAdapter.h"\r
 #include "logger.h"\r
-#include "NSQueueScheduler.h"\r
+#include "NSProviderScheduler.h"\r
 #include "NSProviderListener.h"\r
 #include "NSProviderResource.h"\r
-#include "NSProviderCacheAdapter.h"\r
+#include "NSProviderSubscription.h"\r
+\r
+NSCacheList * messageList;\r
 \r
 NSResult NSRegisterResource();\r
 \r
-NSResult NSGetObsIdList(OCObservationId *list);\r
+NSResult NSInitMessageList();\r
 \r
-uint32_t NSGetNumberOfObsList();\r
+NSResult NSPutNotificationMessage(NSMessage *, OCResourceHandle *);\r
 \r
-NSResult NSPutNotificationMessage(NSMessage *msg, OCResourceHandle *rHandle);\r
+NSResult NSSendNotificationMessage(NSMessage *);\r
 \r
-NSResult NSSendNotificationMessage(NSMessage *msg);\r
 \r
 #endif /* _NS_PROVIDER_NOTIFICATION_H_ */\r
old mode 100644 (file)
new mode 100755 (executable)
similarity index 95%
rename from service/notification/src/common/NSQueueScheduler.c
rename to service/notification/src/provider/NSProviderScheduler.c
index 89b478a..af3a90c
@@ -18,7 +18,7 @@
 //\r
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
 \r
-#include "NSQueueScheduler.h"\r
+#include "NSProviderScheduler.h"\r
 \r
 pthread_t NSThread[THREAD_COUNT];\r
 pthread_mutex_t NSMutex[THREAD_COUNT];\r
old mode 100644 (file)
new mode 100755 (executable)
similarity index 90%
rename from service/notification/src/common/NSQueueScheduler.h
rename to service/notification/src/provider/NSProviderScheduler.h
index 906e5e2..6c9bf1d
@@ -18,8 +18,8 @@
 //\r
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
 \r
-#ifndef _QUEUE_SCHEDULER_H_\r
-#define _QUEUE_SCHEDULER_H_\r
+#ifndef _PROVIDER_SCHEDULER_H_\r
+#define _PROVIDER_SCHEDULER_H_\r
 \r
 #include <stdio.h>\r
 #include <pthread.h>\r
@@ -45,9 +45,10 @@ extern void * NSDiscoverySchedule(void *ptr);
 extern void * NSSubScriptionSchedule(void *ptr);\r
 extern void * NSNotificationSchedule(void *ptr);\r
 \r
+void NSSetList();\r
 bool NSInitScheduler();\r
 bool NSStartScheduler();\r
 bool NSStopScheduler();\r
 void NSPushQueue(NSSchedulerType, NSTaskType, void*);\r
 \r
-#endif /* _QUEUE_SCHEDULER_H_ */\r
+#endif /* _PROVIDER_SCHEDULER_H_ */\r
index ac58034..a0aae6d 100644 (file)
 \r
 #include "NSProviderSubscription.h"\r
 \r
+NSResult NSInitSubscriptionList()\r
+{\r
+    consumerSubList = NSCacheCreate();\r
+    consumerSubList->cacheType = NS_PROVIDER_CACHE_SUBSCRIBER;\r
+    return NS_OK;\r
+}\r
+\r
 NSResult NSSetSubscriptionAcceptPolicy(NSAccessPolicy policy)\r
 {\r
     if (policy == NS_ACCEPTER_PROVIDER)\r
@@ -47,7 +54,8 @@ NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest
 \r
     // put notification resource\r
     OCResourceHandle notificationResourceHandle;\r
-    if(NSPutNotificationResource(NSGetSubscriptionAccepter(), &notificationResourceHandle) != NS_OK)\r
+    if (NSPutNotificationResource(NSGetSubscriptionAccepter(), &notificationResourceHandle)\r
+            != NS_OK)\r
     {\r
         OIC_LOG(ERROR, SUBSCRIPTION_TAG, PCF("Failed to put notification resource"));\r
         return NS_ERROR;\r
@@ -77,8 +85,7 @@ NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest
     response.resourceHandle = entityHandlerRequest->resource;\r
     response.persistentBufferFlag = 0;\r
     response.ehResult = OC_EH_OK;\r
-    response.payload = (OCPayload *)payload;\r
-\r
+    response.payload = (OCPayload *) payload;\r
 \r
     // Send Response\r
     if (OCDoResponse(&response) != OC_STACK_OK)\r
@@ -91,7 +98,7 @@ NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest
     return NS_OK;\r
 }\r
 \r
-void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, int state)\r
+void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResourceType resourceType)\r
 {\r
 \r
     OIC_LOG(INFO, SUBSCRIPTION_TAG, "Start to subscription process");\r
@@ -99,17 +106,29 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, int stat
     printf("state = 0 \n");\r
 \r
     // write consumer info to cache\r
-    if(state == 0)\r
+\r
+    if (resourceType == NS_RESOURCE_MESSAGE)\r
     {\r
+        int obId = entityHandlerRequest->obsInfo.obsId;\r
+\r
+        NSCacheElement * element = (NSCacheElement *) malloc(sizeof(NSCacheElement));\r
+\r
+        NSCacheSubData * subData = (NSCacheSubData *) malloc(sizeof(NSCacheSubData));\r
+        subData->id = OICStrdup(entityHandlerRequest->devAddr.addr);\r
+        subData->isWhite = false;\r
+        subData->messageObId = entityHandlerRequest->obsInfo.obsId;\r
+        subData->syncObId = 0;\r
 \r
-        printf("state = 0 - 1\n");\r
+        element->data = (void*) subData;\r
+        element->next = NULL;\r
 \r
-        if (NSProviderWriteToCache(NS_CONSUMER_BLACKLIST, entityHandlerRequest->obsInfo.obsId, state) != NS_OK)\r
+        printf("NS_ message ob Id = %d\n", subData->messageObId);\r
+\r
+        if (NSCacheWrite(consumerSubList, element) != NS_OK)\r
         {\r
-            OIC_LOG(ERROR, SUBSCRIPTION_TAG, PCF("fail to write consumer black list"));\r
+            printf("Cache Write Error\n");\r
         }\r
-        printf("state = 0 - 2\n");\r
-        // check access policy\r
+\r
         if (NSGetSubscriptionAccepter() == NS_ACCEPTER_PROVIDER)\r
         {\r
             // OCDevAddr --> NSConsumer\r
@@ -123,14 +142,28 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, int stat
             NSSendSubscriptionResponse(entityHandlerRequest, NS_ACCEPTER_CONSUMER, true);\r
         }\r
     }\r
-    else if(state == 1)\r
+    else if (resourceType == NS_RESOURCE_SYNC)\r
     {\r
-        printf("state = 1 - 0\n");\r
-        if (NSProviderWriteToCache(NS_CONSUMER_WHITELIST, entityHandlerRequest->obsInfo.obsId, state) != NS_OK)\r
+        int obId = entityHandlerRequest->obsInfo.obsId;\r
+\r
+        NSCacheElement * element = (NSCacheElement *) malloc(sizeof(NSCacheElement));\r
+\r
+        NSCacheSubData * subData = (NSCacheSubData *) malloc(sizeof(NSCacheSubData));\r
+        printf("NS_ entityHandlerRequest->devAddr.addr = %s\n", entityHandlerRequest->devAddr.addr);\r
+        subData->id = OICStrdup(entityHandlerRequest->devAddr.addr);\r
+        subData->isWhite = false;\r
+        subData->syncObId = entityHandlerRequest->obsInfo.obsId;\r
+        subData->messageObId = 0;\r
+\r
+        element->data = (void*) subData;\r
+        element->next = NULL;\r
+\r
+        printf("NS_ sync ob Id = %d\n", subData->syncObId);\r
+\r
+        if (NSCacheWrite(consumerSubList, element) != NS_OK)\r
         {\r
-            OIC_LOG(ERROR, SUBSCRIPTION_TAG, PCF("fail to write consumer white list"));\r
+            printf("Cache Write Error\n");\r
         }\r
-        printf("state = 1 - 1\n");\r
     }\r
 }\r
 \r
@@ -141,9 +174,20 @@ void NSHandleUnsubscription(OCEntityHandlerRequest *entityHandlerRequest)
     // ProcessObserveUnregister (entityHandlerRequest);\r
 \r
     // write consumer info to cache\r
-    if (NSProviderWriteToCache(NS_CONSUMER_BLACKLIST, entityHandlerRequest->devAddr) != NS_OK)\r
+    int obId = entityHandlerRequest->obsInfo.obsId;\r
+\r
+    NSCacheElement * element = (NSCacheElement *) OICMalloc(sizeof(NSCacheElement));\r
+    NSCacheSubData * subData = (NSCacheSubData *) OICMalloc(sizeof(NSCacheSubData));\r
+    subData->id = OICStrdup(entityHandlerRequest->devAddr.addr);\r
+    subData->isWhite = false;\r
+    subData->messageObId = entityHandlerRequest->obsInfo.obsId;\r
+\r
+    element->data = (void*) subData;\r
+    element->next = NULL;\r
+\r
+    if (NSCacheWrite(consumerSubList, element) != NS_OK)\r
     {\r
-        OIC_LOG(ERROR, SUBSCRIPTION_TAG, "fail to write consumer black list");\r
+        OIC_LOG(ERROR, SUBSCRIPTION_TAG, "fail to write consumer white list");\r
     }\r
 }\r
 \r
@@ -155,7 +199,7 @@ void NSAskAcceptanceToUser(OCEntityHandlerRequest *entityHandlerRequest)
     // one queue is required for response callback to ask subscription allowance\r
 }\r
 \r
-NSResult NSSendResponse(int observeId, bool accepted)\r
+NSResult NSSendResponse(const char * id, bool accepted)\r
 {\r
 \r
     OCRepPayload* payload = OCRepPayloadCreate();\r
@@ -176,7 +220,11 @@ NSResult NSSendResponse(int observeId, bool accepted)
     OCRepPayloadSetPropString(payload, NS_ATTRIBUTE_ID, "0000-0000-0000-0000");\r
     OCRepPayloadSetPropBool(payload, NS_ATTRIBUTE_ACCPETANCE, accepted);\r
 \r
-    if (OCNotifyListOfObservers(rHandle, &observeId, 1, payload, OC_HIGH_QOS) != OC_STACK_OK)\r
+    NSCacheElement * element = NSCacheRead(consumerSubList, id);\r
+    NSCacheSubData * subData = element->data;\r
+\r
+    if (OCNotifyListOfObservers(rHandle, &subData->messageObId, 1, payload, OC_HIGH_QOS)\r
+            != OC_STACK_OK)\r
     {\r
         OIC_LOG(ERROR, SUBSCRIPTION_TAG, "fail to send Acceptance");\r
         OCRepPayloadDestroy(payload);\r
@@ -204,7 +252,19 @@ NSResult NSSendSubscriptionResponse(OCEntityHandlerRequest *entityHandlerRequest
     printf("accepted 1 \n");\r
     if (accepted)\r
     {\r
-        if (NSProviderWriteToCache(NS_CONSUMER_WHITELIST, entityHandlerRequest->obsInfo.obsId) != NS_OK)\r
+        int obId = entityHandlerRequest->obsInfo.obsId;\r
+\r
+        NSCacheElement * element = (NSCacheElement *) OICMalloc(sizeof(NSCacheElement));\r
+\r
+        NSCacheSubData * subData = (NSCacheSubData *) OICMalloc(sizeof(NSCacheSubData));\r
+        subData->id = OICStrdup(entityHandlerRequest->devAddr.addr);\r
+        subData->isWhite = true;\r
+        subData->messageObId = entityHandlerRequest->obsInfo.obsId;\r
+\r
+        element->data = (void*) subData;\r
+        element->next = NULL;\r
+\r
+        if (NSCacheWrite(consumerSubList, element) != NS_OK)\r
         {\r
             OIC_LOG(ERROR, SUBSCRIPTION_TAG, "fail to write consumer white list");\r
         }\r
@@ -244,7 +304,8 @@ void * NSSubScriptionSchedule(void *ptr)
 \r
                 case TASK_RECV_SUBSCRIPTION:\r
                     printf("before TASK_RECV_SUBSCRIPTION:\n");\r
-                    NSHandleSubscription((OCEntityHandlerRequest*) node->taskData, 0);\r
+                    NSHandleSubscription((OCEntityHandlerRequest*) node->taskData,\r
+                            NS_RESOURCE_MESSAGE);\r
                     printf("after TASK_RECV_SUBSCRIPTION:\n");\r
                     break;\r
 \r
@@ -255,27 +316,42 @@ void * NSSubScriptionSchedule(void *ptr)
 \r
                 case TASK_SEND_ALLOW:\r
                 {\r
-                    NSConsumer * consumer = (NSConsumer *)node->taskData;\r
-                    int * pObId = (int *)consumer->mUserData;\r
+                    NSConsumer * consumer = (NSConsumer *) node->taskData;\r
+                    int * pObId = (int *) consumer->mUserData;\r
+\r
+                    NSCacheSubData * subData = (NSCacheMsgData *) OICMalloc(sizeof(NSCacheSubData));\r
+                    subData->id = OICStrdup(consumer->mId);\r
+                    subData->isWhite = true;\r
+                    subData->messageObId = 0;\r
+                    subData->syncObId = 0;\r
+\r
+                    NSCacheUpdateSubScriptionState(consumerSubList, subData);\r
 \r
                     printf("observer ID = %d\n", *pObId);\r
 \r
-                    if (NSProviderWriteToCache(NS_CONSUMER_WHITELIST, *pObId, 0) != NS_OK)\r
-                    {\r
-                        OIC_LOG(ERROR, SUBSCRIPTION_TAG, "fail to write consumer white list");\r
-                    }\r
-                    NSSendResponse(*pObId, true);\r
+                    NSSendResponse(consumer->mId, true);\r
 \r
                     break;\r
                 }\r
                 case TASK_SEND_DENY:\r
+                {\r
+                    NSConsumer * consumer = (NSConsumer *) node->taskData;\r
+                    int * pObId = (int *) consumer->mUserData;\r
 \r
-//                    NSSendSubscriptionResponse((OCEntityHandlerRequest*) node->taskData,\r
-//                            NS_ACCEPTER_PROVIDER, false);\r
-                    break;\r
+                    NSCacheSubData * subData = (NSCacheMsgData *) OICMalloc(sizeof(NSCacheSubData));\r
+                    subData->id = OICStrdup(consumer->mId);\r
+                    subData->isWhite = false;\r
+                    subData->messageObId = 0;\r
+                    subData->syncObId = 0;\r
 \r
+                    NSCacheUpdateSubScriptionState(consumerSubList, subData);\r
+                    printf("observer ID = %d\n", *pObId);\r
+                    NSSendResponse(consumer->mId, false);\r
+                    break;\r
+                }\r
                 case TASK_SYNC_SUBSCRIPTION:\r
-                    NSHandleSubscription((OCEntityHandlerRequest*) node->taskData, 1);\r
+                    NSHandleSubscription((OCEntityHandlerRequest*) node->taskData,\r
+                            NS_RESOURCE_SYNC);\r
                     break;\r
 \r
             }\r
index 847e4af..60813fb 100644 (file)
 #include "ocpayload.h"\r
 #include "NSCommon.h"\r
 #include "NSConstants.h"\r
-#include "NSQueueScheduler.h"\r
+#include "NSProviderScheduler.h"\r
 #include "NSProviderResource.h"\r
+#include "NSCacheAdapter.h"\r
 \r
-static NSAccessPolicy NSSubscriptionAccepter;\r
+NSAccessPolicy NSSubscriptionAccepter;\r
+NSCacheList * consumerSubList;\r
 \r
+NSResult NSInitSubscriptionList();\r
 NSResult NSSetSubscriptionAcceptPolicy(NSAccessPolicy policy);\r
 int NSGetSubscriptionAccepter();\r
 NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest);\r
-void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, int state);\r
+void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResourceType resourceType);\r
 void NSHandleUnsubscription(OCEntityHandlerRequest *entityHandlerRequest);\r
 void NSAskAcceptanceToUser(OCEntityHandlerRequest *entityHandlerRequest);\r
 NSResult NSSendSubscriptionResponse(OCEntityHandlerRequest *entityHandlerRequest,\r
diff --git a/service/notification/src/provider/cache/linux/NSProviderMemoryCache.c b/service/notification/src/provider/cache/linux/NSProviderMemoryCache.c
new file mode 100755 (executable)
index 0000000..7e41915
--- /dev/null
@@ -0,0 +1,361 @@
+//******************************************************************\r
+//\r
+// Copyright 2016 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+//      http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+#include "NSProviderMemoryCache.h"\r
+\r
+NSCacheList * NSCacheCreate()\r
+{\r
+    pthread_mutex_lock(&NSCacheMutex);\r
+    NSCacheList * newList = (NSCacheList *) OICMalloc(sizeof(NSCacheList));\r
+    if (!newList)\r
+    {\r
+        pthread_mutex_unlock(&NSCacheMutex);\r
+        return NULL;\r
+    }\r
+\r
+    newList->head = newList->tail = NULL;\r
+\r
+    pthread_mutex_unlock(&NSCacheMutex);\r
+\r
+    return newList;\r
+}\r
+\r
+NSCacheElement * NSCacheRead(NSCacheList * list, char * findId)\r
+{\r
+    pthread_mutex_lock(&NSCacheMutex);\r
+    NSCacheElement * iter = list->head;\r
+    NSCacheElement * next = NULL;\r
+    NSCacheType type = list->cacheType;\r
+\r
+    printf("NS_ findId = %s\n", findId);\r
+\r
+    while (iter)\r
+    {\r
+        next = iter->next;\r
+\r
+        printf("NS_ findId2 = %s\n", findId);\r
+        pthread_mutex_unlock(&NSCacheMutex);\r
+\r
+        if (NSProviderCompareIdCacheData(type, iter->data, findId))\r
+        {\r
+            pthread_mutex_unlock(&NSCacheMutex);\r
+            return iter;\r
+        }\r
+\r
+        iter = next;\r
+    }\r
+\r
+    pthread_mutex_unlock(&NSCacheMutex);\r
+\r
+    return NULL;\r
+}\r
+\r
+NSResult NSCacheUpdateSubScriptionState(NSCacheList * list, NSCacheSubData * subData)\r
+{\r
+    pthread_mutex_lock(&NSCacheMutex);\r
+\r
+    NSCacheType type = list->cacheType;\r
+\r
+    printf("NS_ NSCacheWrite\n");\r
+\r
+    if (subData == NULL)\r
+    {\r
+        printf("NS_ NSCacheWrite - newObj is NULL\n");\r
+        pthread_mutex_unlock(&NSCacheMutex);\r
+        return NS_ERROR;\r
+    }\r
+\r
+    printf("NS_ findId0 - 0 = %s\n", subData->id);\r
+    pthread_mutex_unlock(&NSCacheMutex);\r
+    NSCacheElement * it = NSCacheRead(list, subData->id);\r
+    pthread_mutex_lock(&NSCacheMutex);\r
+    printf("NS_ findId0 -1 = %s\n", subData->id);\r
+    if (it)\r
+    {\r
+        printf("NS_ findId1 = %s\n", subData->id);\r
+        NSCacheSubData * itData = (NSCacheSubData *) it->data;\r
+        printf("NS_ findId2 = %s\n", subData->id);\r
+        if (strcmp(itData->id, subData->id) == 0)\r
+        {\r
+            printf("NS_ findId3_subdata_id = %s\n", subData->id);\r
+            printf("NS_ findId3_subdata_messageobId = %d\n", subData->messageObId);\r
+            printf("NS_ findId3_subdata_syncobId = %d\n", subData->syncObId);\r
+            printf("NS_ findId3_subdata_isWhite = %d\n", subData->isWhite);\r
+\r
+            printf("NS_ findId3_itdata_id = %s\n", itData->id);\r
+            printf("NS_ findId3_itdata_messageobId = %d\n", itData->messageObId);\r
+            printf("NS_ findId3_itdata_isWhite = %d\n", itData->isWhite);\r
+\r
+            itData->isWhite = subData->isWhite;\r
+\r
+            printf("_NS : PROVIDER_CACHE_SUBSCRIBER UPDATE\n");\r
+\r
+            pthread_mutex_unlock(&NSCacheMutex);\r
+            return NS_OK;\r
+\r
+        }\r
+    }\r
+    pthread_mutex_unlock(&NSCacheMutex);\r
+    return NS_OK;\r
+}\r
+\r
+NSResult NSCacheWrite(NSCacheList * list, NSCacheElement * newObj)\r
+{\r
+    pthread_mutex_lock(&NSCacheMutex);\r
+\r
+    NSCacheType type = list->cacheType;\r
+\r
+    printf("NS_ NSCacheWrite\n");\r
+\r
+    if (newObj == NULL)\r
+    {\r
+        printf("NS_ NSCacheWrite - newObj is NULL\n");\r
+        pthread_mutex_unlock(&NSCacheMutex);\r
+        return NS_ERROR;\r
+    }\r
+\r
+    if (type == NS_PROVIDER_CACHE_SUBSCRIBER)\r
+    {\r
+        NSCacheSubData * subData = (NSCacheSubData *) newObj->data;\r
+\r
+        printf("NS_ findId0 - 0 = %s\n", subData->id);\r
+        pthread_mutex_unlock(&NSCacheMutex);\r
+        NSCacheElement * it = NSCacheRead(list, subData->id);\r
+        pthread_mutex_lock(&NSCacheMutex);\r
+        printf("NS_ findId0 -1 = %s\n", subData->id);\r
+        if (it)\r
+        {\r
+            printf("NS_ findId1 = %s\n", subData->id);\r
+            NSCacheSubData * itData = (NSCacheSubData *) it->data;\r
+            printf("NS_ findId2 = %s\n", subData->id);\r
+            if (strcmp(itData->id, subData->id) == 0)\r
+            {\r
+                printf("NS_ findId3_subdata_id = %s\n", subData->id);\r
+                printf("NS_ findId3_subdata_messageobId = %d\n", subData->messageObId);\r
+                printf("NS_ findId3_subdata_syncobId = %d\n", subData->syncObId);\r
+                printf("NS_ findId3_subdata_isWhite = %d\n", subData->isWhite);\r
+\r
+                printf("NS_ findId3_itdata_id = %s\n", itData->id);\r
+                printf("NS_ findId3_itdata_messageobId = %d\n", itData->messageObId);\r
+                printf("NS_ findId3_itdata_isWhite = %d\n", itData->isWhite);\r
+                if (itData->messageObId == 0)\r
+                {\r
+                    itData->messageObId = subData->messageObId;\r
+                }\r
+\r
+                if (itData->syncObId == 0)\r
+                {\r
+                    itData->syncObId = subData->syncObId;\r
+                }\r
+\r
+                //itData->isWhite = subData->isWhite;\r
+\r
+                printf("_NS : PROVIDER_CACHE_SUBSCRIBER UPDATE\n");\r
+\r
+                pthread_mutex_unlock(&NSCacheMutex);\r
+                return NS_OK;\r
+\r
+            }\r
+        }\r
+\r
+    }\r
+    else if (type == NS_PROVIDER_CACHE_MESSAGE)\r
+    {\r
+        NSCacheMsgData * msgData = (NSCacheMsgData *) newObj->data;\r
+\r
+        NSCacheElement * it = NSCacheRead(list, msgData->id);\r
+        if (it)\r
+        {\r
+            NSCacheMsgData * itData = (NSCacheMsgData *) it->data;\r
+\r
+            if (strcmp(itData->id, msgData->id) == 0)\r
+            {\r
+\r
+                itData->messageType = msgData->messageType;\r
+                printf("_NS : PROVIDER_CACHE_MESSAGE UPDATE\n");\r
+                pthread_mutex_unlock(&NSCacheMutex);\r
+                return NS_OK;\r
+\r
+            }\r
+        }\r
+    }\r
+\r
+    printf("NS_ berfore list->head == NULL\n");\r
+    if (list->head == NULL)\r
+    {\r
+        list->head = list->tail = newObj;\r
+        printf("NS_ list->head == NULL\n");\r
+        pthread_mutex_unlock(&NSCacheMutex);\r
+        return NS_OK;\r
+    }\r
+\r
+    list->tail = list->tail->next = newObj;\r
+    printf("NS_ list->head == not NULL\n");\r
+    pthread_mutex_unlock(&NSCacheMutex);\r
+    return NS_OK;\r
+}\r
+\r
+NSResult NSCacheDelete(NSCacheList * list, char * delId)\r
+{\r
+\r
+    pthread_mutex_lock(&NSCacheMutex);\r
+    NSCacheElement * prev = list->head;\r
+    NSCacheElement * del = list->head;\r
+\r
+    NSCacheType type = list->cacheType;\r
+\r
+    if (NSProviderCompareIdCacheData(type, del->data, delId))\r
+    {\r
+        if (del == list->head) // first object\r
+        {\r
+            if (del == list->tail) // first object (one object)\r
+                list->tail = del->next;\r
+\r
+            list->head = del->next;\r
+\r
+            NSProviderDeleteCacheData(type, del->data);\r
+            OICFree(del);\r
+            pthread_mutex_unlock(&NSCacheMutex);\r
+            return NS_OK;\r
+        }\r
+    }\r
+\r
+    del = del->next;\r
+    while (del)\r
+    {\r
+        if (NSProviderCompareIdCacheData(type, del->data, delId))\r
+        {\r
+            if (del == list->tail) // delete object same to last object\r
+                list->tail = prev;\r
+\r
+            prev->next = del->next;\r
+            NSProviderDeleteCacheData(type, del->data);\r
+            OICFree(del);\r
+            pthread_mutex_unlock(&NSCacheMutex);\r
+            return NS_OK;\r
+        }\r
+\r
+        prev = del;\r
+        del = del->next;\r
+    }\r
+    pthread_mutex_unlock(&NSCacheMutex);\r
+    return NS_OK;\r
+}\r
+\r
+NSResult NSCacheDestroy(NSCacheList * list)\r
+{\r
+    NSCacheElement * iter = list->head;\r
+    NSCacheElement * next = NULL;\r
+\r
+    NSCacheType type = list->cacheType;\r
+\r
+    while (iter)\r
+    {\r
+        next = (NSCacheElement *) iter->next;\r
+\r
+        NSProviderDeleteCacheData(type, iter->data);\r
+        OICFree(iter);\r
+\r
+        iter = next;\r
+    }\r
+\r
+    OICFree(list);\r
+\r
+    return NS_OK;\r
+}\r
+\r
+bool NSProviderCompareIdCacheData(NSCacheType type, void * data, char * id)\r
+{\r
+    if (data == NULL)\r
+    {\r
+        return false;\r
+    }\r
+\r
+    if (type == NS_PROVIDER_CACHE_SUBSCRIBER)\r
+    {\r
+        NSCacheSubData * subData = (NSCacheSubData *) data;\r
+\r
+        printf("NS_ subdata->id = %s\n", subData->id);\r
+        printf("NS_ id = %s\n", id);\r
+\r
+        if (strcmp(subData->id, id) == 0)\r
+        {\r
+            return true;\r
+        }\r
+        return false;\r
+\r
+    }\r
+    else if (type == NS_PROVIDER_CACHE_MESSAGE)\r
+    {\r
+        NSCacheMsgData * msgData = (NSCacheMsgData *) data;\r
+\r
+        if (strcmp(msgData->id, id) == 0)\r
+        {\r
+            return true;\r
+        }\r
+\r
+        return false;\r
+    }\r
+\r
+    return false;\r
+}\r
+\r
+NSResult NSProviderDeleteCacheData(NSCacheType type, void * data)\r
+{\r
+    if (data == NULL)\r
+    {\r
+        return NS_OK;\r
+    }\r
+\r
+    if (type == NS_PROVIDER_CACHE_SUBSCRIBER)\r
+    {\r
+        NSCacheSubData * subData = (NSCacheSubData *) data;\r
+        if (subData->id)\r
+        {\r
+            OICFree(subData->id);\r
+            subData->id = NULL;\r
+        }\r
+\r
+        OICFree(subData);\r
+\r
+        return NS_OK;\r
+    }\r
+    else if (type == NS_PROVIDER_CACHE_MESSAGE)\r
+    {\r
+        NSCacheMsgData * msgData = (NSCacheMsgData *) data;\r
+\r
+        if (msgData->id)\r
+        {\r
+            OICFree(msgData->id);\r
+            msgData->id = NULL;\r
+        }\r
+\r
+        if (msgData->nsMessage)\r
+        {\r
+            NSFreeMessage(msgData->nsMessage);\r
+        }\r
+\r
+        OICFree(msgData);\r
+\r
+        return NS_OK;\r
+    }\r
+\r
+    return NS_OK;\r
+}\r
+\r
old mode 100644 (file)
new mode 100755 (executable)
similarity index 68%
rename from service/notification/src/provider/NSProviderCacheAdapter.h
rename to service/notification/src/provider/cache/linux/NSProviderMemoryCache.h
index 32b2c21..4e96aff
 #ifndef _NS_PROVIDER_CACHEADAPTER__H_\r
 #define _NS_PROVIDER_CACHEADAPTER__H_\r
 \r
-#include "logger.h"\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 "NSConstants.h"\r
+#include "NSCacheAdapter.h"\r
+\r
+NSResult NSProviderDeleteCacheData(NSCacheType, void *);\r
 \r
-typedef struct _messageData\r
-{\r
-    NSMessage * msg;\r
-    uint8_t state;\r
-    uint8_t size;\r
-}NSMessageData;\r
+bool NSProviderCompareIdCacheData(NSCacheType, void *, char *);\r
 \r
-typedef struct _observerList\r
-{\r
-    OCObservationId idList[100];\r
-    uint8_t size;\r
-}NSWhiteList, NSBlackList;\r
+bool NSProviderIsFoundCacheData(NSCacheType, void *, void*);\r
 \r
-typedef NSWhiteList NSCommonList;\r
+NSResult NSCacheUpdateSubScriptionState(NSCacheList *, NSCacheSubData *);\r
 \r
-NSResult NSProviderWriteToCache(NSCache target, OCObservationId observeId, int state);\r
-NSCommonList * NSProviderReadCache(NSCache target, int state);\r
+pthread_mutex_t NSCacheMutex;\r
 \r
-#endif /* _NS_PROVIDER_CACHE__H_ */\r
+#endif /* _NS_PROVIDER_CACHEADAPTER__H_ */\r