Create topic resource
authorch79.cho <ch79.cho@samsung.com>
Mon, 8 Aug 2016 07:12:52 +0000 (16:12 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Mon, 8 Aug 2016 10:02:33 +0000 (10:02 +0000)
Topic resource is created in resource module with defined resource
attribute.

Change-Id: I1b4818f01349669f66503100c7edf28966e7eada
Signed-off-by: ch79.cho <ch79.cho@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9779
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/notification/include/NSCommon.h
service/notification/src/common/NSConstants.h
service/notification/src/common/NSStructs.h
service/notification/src/provider/NSProviderListener.c
service/notification/src/provider/NSProviderListener.h
service/notification/src/provider/NSProviderResource.c
service/notification/src/provider/NSProviderResource.h

index fa3d1a0..6233554 100644 (file)
 
 #include <stdint.h>
 
+#define NS_UUID_STRING_SIZE 37
+
 #define NS_ATTRIBUTE_POLICY "ACCEPTER"
 #define NS_ATTRIBUTE_MESSAGE "MESSAGE_URI"
 #define NS_ATTRIBUTE_SYNC "SYNC_URI"
 #define NS_ATTRIBUTE_ACCPETANCE "ACCEPTANCE"
 #define NS_ATTRIBUTE_MESSAGE_ID "MESSAGE_ID"
 #define NS_ATTRIBUTE_PROVIDER_ID "PROVIDER_ID"
+#define NS_ATTRIBUTE_CONSUMER_ID "CONSUMER_ID"
+#define NS_ATTRIBUTE_TOPIC_LIST "TOPIC_LIST"
+#define NS_ATTRIBUTE_TOPIC_NAME "TOPIC_NAME"
+#define NS_ATTRIBUTE_TOPIC_SELECTION "TOPIC_STATE"
 #define NS_ATTRIBUTE_TITLE "TITLE"
 #define NS_ATTRIBUTE_TEXT "CONTENTTEXT"
 #define NS_ATTRIBUTE_SOURCE "SOURCE"
@@ -53,8 +59,6 @@ typedef enum eResult
     NS_ERROR = 200,
     NS_SUCCESS = 300,
     NS_FAIL = 400,
-    NS_ALLOW = 500,
-    NS_DENY = 600,
 
 } NSResult;
 
@@ -98,7 +102,7 @@ typedef enum
  */
 typedef struct
 {
-    char consumerId[37];
+    char consumerId[NS_UUID_STRING_SIZE];
 
 } NSConsumer;
 
@@ -107,7 +111,7 @@ typedef struct
  */
 typedef struct
 {
-    char providerId[37];
+    char providerId[NS_UUID_STRING_SIZE];
 
 } NSProvider;
 
@@ -127,7 +131,7 @@ typedef struct
 {
     //Mandatory
     uint64_t messageId;
-    char providerId[37];
+    char providerId[NS_UUID_STRING_SIZE];
 
     //optional
     NSMessageType type;
@@ -146,10 +150,35 @@ typedef struct
 typedef struct
 {
     uint64_t messageId;
-    char providerId[37];
+    char providerId[NS_UUID_STRING_SIZE];
     NSSyncType state;
 
 } NSSyncInfo;
 
+/**
+ *  Notification topic
+ */
+typedef enum
+{
+    NS_TOPIC_CREATED = 0,
+    NS_TOPIC_SUBSCRIBED = 1,
+    NS_TOPIC_UNSUBSCRIBED = 2,
+
+} NSTopicState;
+
+typedef struct
+{
+    char * topicName;
+    NSTopicState state;
+
+} NSTopic;
+
+typedef struct
+{
+    char consumerId[NS_UUID_STRING_SIZE];
+    NSTopic ** topics;
+
+} NSTopicList;
+
 #endif /* _NS_COMMON_H_ */
 
index c263fba..56320ee 100644 (file)
@@ -51,9 +51,9 @@
 #define NS_TAG                     "IOT_NOTI"
 
 // SCHEDULE //
-#define THREAD_COUNT               4
+#define THREAD_COUNT               5
 
-// NOTIOBJ // 
+// NOTIOBJ //
 #define NOTIOBJ_TITLE_KEY          "title"
 #define NOTIOBJ_ID_KEY             "id"
 #define NOTOOBJ_CONTENT_KEY        "contentText"
 #define SCHEDULER_TAG              "NS_PROVIDER_SCHEDULER"
 #define LISTENER_TAG               "NS_PROVIDER_LISTENER"
 #define RESOURCE_TAG               "NS_PROVIDER_RESOURCE"
+#define TOPIC_TAG                  "NS_PROVIDER_TOPIC"
 
 #define NS_ROOT_TYPE               "oic.r.notification"
 #define NS_COLLECTION_MESSAGE_TYPE "oic.r.notification.message"
 #define NS_COLLECTION_SYNC_TYPE    "oic.r.notification.sync"
+#define NS_COLLECTION_TOPIC_TYPE   "oic.r.notification.topic"
 
 #define NS_DEFAULT_INTERFACE       "oic.if.baseline"
 
 #define NS_ROOT_URI                "/notification"
 #define NS_COLLECTION_MESSAGE_URI  "/notification/message"
 #define NS_COLLECTION_SYNC_URI     "/notification/sync"
+#define NS_COLLECTION_TOPIC_URI    "/notification/topic"
 
 #define NS_QUERY_SEPARATOR         "&;"
 #define NS_KEY_VALUE_DELIMITER     "="
@@ -182,6 +185,7 @@ typedef enum eSchedulerType
     DISCOVERY_SCHEDULER = 1,
     SUBSCRIPTION_SCHEDULER = 2,
     NOTIFICATION_SCHEDULER = 3,
+    TOPIC_SCHEDULER = 4,
 } NSSchedulerType;
 
 typedef enum eTaskType
@@ -227,6 +231,10 @@ typedef enum eTaskType
     TASK_CB_SUBSCRIPTION = 10000,
     TASK_CB_SYNC = 10001,
 
+    TASK_SEND_TOPICS = 11000,
+    TASK_SELECT_TOPICS = 11001,
+    TASK_SET_TOPICS = 11002,
+
 } NSTaskType;
 
 typedef enum eCache
@@ -240,6 +248,7 @@ typedef enum eCacheType
 {
     NS_PROVIDER_CACHE_SUBSCRIBER = 1000,
     NS_PROVIDER_CACHE_MESSAGE = 1001,
+    NS_PROVIDER_CACHE_TOPIC = 1002,
 
     NS_CONSUMER_CACHE_PROVIDER = 2000,
     NS_CONSUMER_CACHE_MESSAGE = 2001,
@@ -249,6 +258,16 @@ typedef enum eResourceType
 {
     NS_RESOURCE_MESSAGE = 1000,
     NS_RESOURCE_SYNC = 1001,
+    NS_RESOURCE_TOPIC = 1002,
 } NSResourceType;
 
+typedef enum eResponse
+{
+    NS_ALLOW = 1,
+    NS_DENY = 2,
+    NS_TOPIC = 3,
+
+} NSResponse;
+
+
 #endif /* _NS_CONSTANTS_H_ */
index 752f173..fb207c6 100644 (file)
@@ -71,10 +71,19 @@ typedef struct
 \r
 typedef struct\r
 {\r
+    char consumerId[37];\r
+    NSTopicList ** topicList;\r
+} NSCacheTopicData;\r
+\r
+typedef struct\r
+{\r
     OCResourceHandle handle;\r
     int accepter;\r
     char * message_uri;\r
     char * sync_uri;\r
+\r
+    //optional\r
+    char * topic_uri;\r
 } NSNotificationResource;\r
 \r
 typedef struct\r
@@ -103,6 +112,13 @@ typedef struct
 \r
 typedef struct\r
 {\r
+    OCResourceHandle handle;\r
+    char consumerId[37];\r
+    NSTopicList ** TopicList;\r
+} NSTopicResource;\r
+\r
+typedef struct\r
+{\r
     char providerId[37];\r
     char * providerName;\r
     char * userInfo;\r
index e6fb4c3..3b0e6bc 100644 (file)
@@ -127,8 +127,8 @@ OCEntityHandlerResult NSEntityHandlerSyncCb(OCEntityHandlerFlag flag,
         if (OC_REST_POST == entityHandlerRequest->method)\r
         {\r
             /** Receive sync data from consumer which read or dismiss notification message.\r
-                           And broadcast the sync data to all subscribers including provider app\r
-                           to synchronize the notification message status. */\r
+                And broadcast the sync data to all subscribers including provider app\r
+                to synchronize the notification message status. */\r
 \r
             NS_LOG(DEBUG, "NSEntityHandlerSyncCb - OC_REST_POST");\r
 \r
@@ -171,6 +171,60 @@ OCEntityHandlerResult NSEntityHandlerSyncCb(OCEntityHandlerFlag flag,
     return ehResult;\r
 }\r
 \r
+OCEntityHandlerResult NSEntityHandlerTopicCb(OCEntityHandlerFlag flag,\r
+        OCEntityHandlerRequest *entityHandlerRequest, void* callback)\r
+{\r
+    NS_LOG(DEBUG, "NSEntityHandlerTopicCb - IN");\r
+    OCEntityHandlerResult ehResult = OC_EH_OK;\r
+\r
+    (void)callback;\r
+\r
+    // Validate pointer\r
+    if (!entityHandlerRequest)\r
+    {\r
+        NS_LOG(ERROR, "Invalid request pointer");\r
+        return OC_EH_ERROR;\r
+    }\r
+\r
+    if (flag & OC_REQUEST_FLAG)\r
+    {\r
+        NS_LOG(DEBUG, "Flag includes OC_REQUEST_FLAG");\r
+\r
+        if (OC_REST_GET == entityHandlerRequest->method)\r
+        {\r
+            NS_LOG(DEBUG, "NSEntityHandlerTopicCb - OC_REST_GET");\r
+\r
+            // send consumer's interesting topic list if consumer id exists\r
+            // otherwise send  created / updated topic list\r
+\r
+            NSPushQueue(TOPIC_SCHEDULER, TASK_SEND_TOPICS,\r
+                    NSCopyOCEntityHandlerRequest(entityHandlerRequest));\r
+\r
+            ehResult = OC_EH_OK;\r
+        }\r
+        else if (OC_REST_POST == entityHandlerRequest->method)\r
+        {\r
+            // Receive interesting topic list from consumers\r
+            NS_LOG(DEBUG, "NSEntityHandlerTopicCb - OC_REST_POST");\r
+\r
+            // Send topic updated message(id=TOPIC) to the consumer who request to post.\r
+            NSPushQueue(TOPIC_SCHEDULER, TASK_SELECT_TOPICS,\r
+                    NSCopyOCEntityHandlerRequest(entityHandlerRequest));\r
+\r
+            ehResult = OC_EH_OK;\r
+        }\r
+        else\r
+        {\r
+            NS_LOG_V(DEBUG, "Received unsupported method %d from client",\r
+                    entityHandlerRequest->method);\r
+            ehResult = OC_EH_OK;\r
+        }\r
+    }\r
+\r
+    NS_LOG(DEBUG, "NSEntityHandlerTopicCb - OUT");\r
+    return ehResult;\r
+}\r
+\r
 void NSProviderConnectionStateListener(const CAEndpoint_t * info, bool connected)\r
 {\r
 \r
index e07c8e1..ddf5671 100644 (file)
@@ -45,6 +45,9 @@ OCEntityHandlerResult NSEntityHandlerMessageCb(OCEntityHandlerFlag flag,
 OCEntityHandlerResult NSEntityHandlerSyncCb(OCEntityHandlerFlag flag,\r
         OCEntityHandlerRequest *entityHandlerRequest, void* callback);\r
 \r
+OCEntityHandlerResult NSEntityHandlerTopicCb(OCEntityHandlerFlag flag,\r
+        OCEntityHandlerRequest *entityHandlerRequest, void* callback);\r
+\r
 void NSProviderConnectionStateListener(const CAEndpoint_t * info, bool isConnected);\r
 \r
 void NSProviderAdapterStateListener(CATransportAdapter_t adapter, bool enabled);\r
index 78e593e..0e4030f 100644 (file)
@@ -24,6 +24,7 @@
 NSNotificationResource NotificationResource;
 NSMessageResource NotificationMessageResource;
 NSSyncResource NotificationSyncResource;
+NSTopicResource NotificationTopicResource;
 
 #ifdef WITH_CLOUD
 OCStackApplicationResult NSHandlePublishCb(void *ctx, OCDoHandle handle,
@@ -74,6 +75,7 @@ NSResult NSCreateResource(char *uri)
         NotificationResource.accepter = 0;
         NotificationResource.message_uri = NS_COLLECTION_MESSAGE_URI;
         NotificationResource.sync_uri = NS_COLLECTION_SYNC_URI;
+        NotificationResource.topic_uri = NS_COLLECTION_TOPIC_URI;
         NotificationResource.handle = NULL;
 
         if (OCCreateResource(&NotificationResource.handle, NS_ROOT_TYPE, NS_DEFAULT_INTERFACE,
@@ -119,6 +121,20 @@ NSResult NSCreateResource(char *uri)
             return NS_ERROR;
         }
     }
+    else if (strcmp(uri, NS_COLLECTION_TOPIC_URI) == 0)
+    {
+        (NotificationTopicResource.consumerId)[0] = '\0';
+        NotificationTopicResource.TopicList = NULL;
+        NotificationTopicResource.handle = NULL;
+
+        if (OCCreateResource(&(NotificationTopicResource.handle), NS_COLLECTION_TOPIC_TYPE,
+                NS_DEFAULT_INTERFACE, NS_COLLECTION_TOPIC_URI, NSEntityHandlerTopicCb, NULL,
+                OC_DISCOVERABLE) != OC_STACK_OK)
+        {
+            NS_LOG(NS_ERROR, "Fail to Create Notification Sync Resource");
+            return NS_ERROR;
+        }
+    }
     else
     {
         NS_LOG(ERROR, "Fail to create resource with invalid URI");
@@ -133,6 +149,12 @@ NSResult NSRegisterResource()
 {
     NS_LOG(DEBUG, "NSRegisterResource - IN");
 
+    if (NSCreateResource(NS_COLLECTION_TOPIC_URI) != NS_OK)
+    {
+        NS_LOG(ERROR, "Fail to register Topic Resource");
+        return NS_ERROR;
+    }
+
     if (NSCreateResource(NS_COLLECTION_SYNC_URI) != NS_OK)
     {
         NS_LOG(ERROR, "Fail to register Sync Resource");
@@ -177,9 +199,16 @@ NSResult NSUnRegisterResource()
         return NS_ERROR;
     }
 
+    if (OCDeleteResource(NotificationTopicResource.handle) != OC_STACK_OK)
+    {
+        NS_LOG(ERROR, "Fail to Delete Notification Topic Resource");
+        return NS_ERROR;
+    }
+
     NotificationResource.handle = NULL;
     NotificationMessageResource.handle = NULL;
     NotificationSyncResource.handle = NULL;
+    NotificationTopicResource.handle = NULL;
 
     NS_LOG(DEBUG, "NSUnRegisterResource - OUT");
     return NS_OK;
@@ -192,6 +221,7 @@ NSResult NSPutNotificationResource(int accepter, OCResourceHandle * handle)
     NotificationResource.accepter = accepter;
     NotificationResource.message_uri = NS_COLLECTION_MESSAGE_URI;
     NotificationResource.sync_uri = NS_COLLECTION_SYNC_URI;
+    NotificationResource.topic_uri = NS_COLLECTION_TOPIC_URI;
 
     *handle = NotificationResource.handle;
 
@@ -239,3 +269,15 @@ NSResult NSPutSyncResource(NSSyncInfo *sync, OCResourceHandle * handle)
     NS_LOG(DEBUG, "NSPutSyncResource - OUT");
     return NS_OK;
 }
+
+NSResult NSPutTopicResource(NSTopicList **topicList, OCResourceHandle * handle)
+{
+    NS_LOG(DEBUG, "NSPutTopicResource - IN");
+
+    (void) topicList;
+
+    *handle = NotificationTopicResource.handle;
+
+    NS_LOG(DEBUG, "NSPutTopicResource - OUT");
+    return NS_OK;
+}
index 4ee6621..7c868c2 100644 (file)
@@ -42,4 +42,6 @@ NSResult NSPutMessageResource(NSMessage *msg, OCResourceHandle * handle);
 
 NSResult NSPutSyncResource(NSSyncInfo *sync, OCResourceHandle * handle);
 
+NSResult NSPutTopicResource(NSTopicList **topicList, OCResourceHandle * handle);
+
 #endif /* _NS_PROVIDER_RESOURCE_H_ */