#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"
NS_ERROR = 200,
NS_SUCCESS = 300,
NS_FAIL = 400,
- NS_ALLOW = 500,
- NS_DENY = 600,
} NSResult;
*/
typedef struct
{
- char consumerId[37];
+ char consumerId[NS_UUID_STRING_SIZE];
} NSConsumer;
*/
typedef struct
{
- char providerId[37];
+ char providerId[NS_UUID_STRING_SIZE];
} NSProvider;
{
//Mandatory
uint64_t messageId;
- char providerId[37];
+ char providerId[NS_UUID_STRING_SIZE];
//optional
NSMessageType type;
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_ */
#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 "="
DISCOVERY_SCHEDULER = 1,
SUBSCRIPTION_SCHEDULER = 2,
NOTIFICATION_SCHEDULER = 3,
+ TOPIC_SCHEDULER = 4,
} NSSchedulerType;
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
{
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,
{
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_ */
\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
\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
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
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
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
NSNotificationResource NotificationResource;
NSMessageResource NotificationMessageResource;
NSSyncResource NotificationSyncResource;
+NSTopicResource NotificationTopicResource;
#ifdef WITH_CLOUD
OCStackApplicationResult NSHandlePublishCb(void *ctx, OCDoHandle handle,
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,
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");
{
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");
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;
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;
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;
+}
NSResult NSPutSyncResource(NSSyncInfo *sync, OCResourceHandle * handle);
+NSResult NSPutTopicResource(NSTopicList **topicList, OCResourceHandle * handle);
+
#endif /* _NS_PROVIDER_RESOURCE_H_ */