#include "NSProviderResource.h"
-char* NSType = "oic.r.notification";
-char* NSMessageType = "oic.r.notification.message";
-char* NSSyncType = "oic.r.notification.sync";
-
-char* NSInterface = "oic.if.baseline";
-char* NSMessgeInterface = "oic.if.baseline.message";
-char* NSSyncInterface = "oic.if.baseline.sync";
-
-char* NSUri = "/notification";
-char* NSMessageUri = "/notification/message";
-char* NSSyncUri = "/notification/sync";
-
-/* Structure to represent notification resources */
-typedef struct
-{
- OCResourceHandle handle;
- int accepter;
- char* message_uri;
- char* sync_uri;
-} NSNotificationResource;
-
-typedef struct
-{
- OCResourceHandle handle;
- char* id;
- char* title;
- char* body;
-} NSMessageResource;
-
-typedef struct
-{
- OCResourceHandle handle;
- char* id;
- char* state;
- NSDevice device;
-} NSSyncResource;
-
NSNotificationResource NotificationResource;
NSMessageResource NotificationMessageResource;
NSSyncResource NotificationSyncResource;
NS_LOG(DEBUG, "NSCreateResource - IN");
if (!uri)
{
- OIC_LOG(ERROR, RESOURCE_TAG, "Resource URI cannot be NULL");
NS_LOG(NS_ERROR, "Resource URI cannot be NULL");
return NS_ERROR;
}
- if (strcmp(uri, NSUri) == 0)
+ if (strcmp(uri, NS_ROOT_URI) == 0)
{
-
NotificationResource.accepter = 0;
- NotificationResource.message_uri = NSMessageUri;
- NotificationResource.sync_uri = NSSyncUri;
+ NotificationResource.message_uri = NS_COLLECTION_MESSAGE_URI;
+ NotificationResource.sync_uri = NS_COLLECTION_SYNC_URI;
NotificationResource.handle = NULL;
- if (OCCreateResource(&NotificationResource.handle, NSType, NSInterface, NSUri,
- NSEntityHandlerNotificationCb, NULL, OC_DISCOVERABLE) != OC_STACK_OK)
+ if (OCCreateResource(&NotificationResource.handle, NS_ROOT_TYPE, NS_DEFAULT_INTERFACE,
+ NS_ROOT_URI, NSEntityHandlerNotificationCb, NULL, OC_DISCOVERABLE) != OC_STACK_OK)
{
- OIC_LOG(ERROR, RESOURCE_TAG, PCF("Fail to Create Notification Resource"));
NS_LOG(NS_ERROR, "Fail to Create Notification Resource");
return NS_ERROR;
}
}
- else if (strcmp(uri, NSMessageUri) == 0)
+ else if (strcmp(uri, NS_COLLECTION_MESSAGE_URI) == 0)
{
- NotificationMessageResource.id = NULL;
+ NotificationMessageResource.messageId = 0;
+
+ (NotificationMessageResource.providerId)[0] = '\0';
+ NotificationMessageResource.type = 0;
+ NotificationMessageResource.dateTime = NULL;
+ NotificationMessageResource.ttl = 0;
NotificationMessageResource.title = NULL;
- NotificationMessageResource.body = NULL;
- NotificationMessageResource.handle = NULL;
+ NotificationMessageResource.contentText = NULL;
+ NotificationMessageResource.sourceName = NULL;
+ NotificationMessageResource.mediaContents = NULL;
- if (OCCreateResource(&NotificationMessageResource.handle, NSMessageType, NSInterface,
- NSMessageUri, NSEntityHandlerMessageCb, NULL, OC_OBSERVABLE) != OC_STACK_OK)
+ if (OCCreateResource(&NotificationMessageResource.handle, NS_COLLECTION_MESSAGE_TYPE,
+ NS_DEFAULT_INTERFACE, NS_COLLECTION_MESSAGE_URI, NSEntityHandlerMessageCb, NULL,
+ OC_OBSERVABLE) != OC_STACK_OK)
{
- OIC_LOG(ERROR, RESOURCE_TAG, PCF("Fail to Create Notification Message Resource"));
NS_LOG(NS_ERROR, "Fail to Create Notification Message Resource");
return NS_ERROR;
}
}
- else if (strcmp(uri, NSSyncUri) == 0)
+ else if (strcmp(uri, NS_COLLECTION_SYNC_URI) == 0)
{
NotificationSyncResource.id = NULL;
NotificationSyncResource.state = NULL;
- memset(&NotificationSyncResource.device, 0, sizeof(NSDevice));
NotificationSyncResource.handle = NULL;
- if (OCCreateResource(&(NotificationSyncResource.handle), NSSyncType, NSInterface, NSSyncUri,
- NSEntityHandlerSyncCb, NULL, OC_OBSERVABLE) != OC_STACK_OK)
+ if (OCCreateResource(&(NotificationSyncResource.handle), NS_COLLECTION_SYNC_TYPE,
+ NS_DEFAULT_INTERFACE, NS_COLLECTION_SYNC_URI, NSEntityHandlerSyncCb, NULL,
+ OC_OBSERVABLE) != OC_STACK_OK)
{
- OIC_LOG(ERROR, RESOURCE_TAG, PCF("Fail to Create Notification Sync Resource"));
NS_LOG(NS_ERROR, "Fail to Create Notification Sync Resource");
return NS_ERROR;
}
}
else
{
- OIC_LOG(ERROR, RESOURCE_TAG, PCF("Fail to create resource with invalid URI"));
- NS_LOG(DEBUG, "Fail to create resource with invalid URI");
+ NS_LOG(ERROR, "Fail to create resource with invalid URI");
return NS_ERROR;
}
NSResult NSRegisterResource()
{
- OIC_LOG(INFO, RESOURCE_TAG, "NSRegisterResource");
NS_LOG(DEBUG, "NSRegisterResource - IN");
- if (NSCreateResource(NSSyncUri) != NS_OK)
+ if (NSCreateResource(NS_COLLECTION_SYNC_URI) != NS_OK)
{
- OIC_LOG(ERROR, RESOURCE_TAG, PCF("Fail to register Sync Resource"));
- NS_LOG(DEBUG, "Fail to register Sync Resource");
+ NS_LOG(ERROR, "Fail to register Sync Resource");
return NS_ERROR;
}
- if (NSCreateResource(NSMessageUri) != NS_OK)
+ if (NSCreateResource(NS_COLLECTION_MESSAGE_URI) != NS_OK)
{
- OIC_LOG(ERROR, RESOURCE_TAG, PCF("Fail to register Message Resource"));
- NS_LOG(DEBUG, "Fail to register Message Resource");
+ NS_LOG(ERROR, "Fail to register Message Resource");
return NS_ERROR;
}
- if (NSCreateResource(NSUri) != NS_OK)
+ if (NSCreateResource(NS_ROOT_URI) != NS_OK)
{
- OIC_LOG(ERROR, RESOURCE_TAG, PCF("Fail to register Notification Resource"));
- NS_LOG(DEBUG, "Fail to register Notification Resource");
+ NS_LOG(ERROR, "Fail to register Notification Resource");
return NS_ERROR;
}
return NS_OK;
}
+NSResult NSUnRegisterResource()
+{
+ NS_LOG(DEBUG, "NSUnRegisterResource - IN");
+
+ if (OCDeleteResource(NotificationResource.handle) != OC_STACK_OK)
+ {
+ NS_LOG(ERROR, "Fail to Delete Notification Resource");
+ return NS_ERROR;
+ }
+
+ if (OCDeleteResource(NotificationMessageResource.handle) != OC_STACK_OK)
+ {
+ NS_LOG(ERROR, "Fail to Delete Notification Message Resource");
+ return NS_ERROR;
+ }
+
+ if (OCDeleteResource(NotificationSyncResource.handle) != OC_STACK_OK)
+ {
+ NS_LOG(ERROR, "Fail to Delete Notification Sync Resource");
+ return NS_ERROR;
+ }
+
+ NotificationResource.handle = NULL;
+ NotificationMessageResource.handle = NULL;
+ NotificationSyncResource.handle = NULL;
+
+ NS_LOG(DEBUG, "NSUnRegisterResource - OUT");
+ return NS_OK;
+}
+
NSResult NSPutNotificationResource(int accepter, OCResourceHandle * handle)
{
NS_LOG(DEBUG, "NSPutNotificationResource - IN");
NotificationResource.accepter = accepter;
- NotificationResource.message_uri = NSMessageUri;
- NotificationResource.sync_uri = NSSyncUri;
+ NotificationResource.message_uri = NS_COLLECTION_MESSAGE_URI;
+ NotificationResource.sync_uri = NS_COLLECTION_SYNC_URI;
*handle = NotificationResource.handle;
NSResult NSPutMessageResource(NSMessage *msg, OCResourceHandle * handle)
{
- OIC_LOG(INFO, RESOURCE_TAG, "Put notification message to Resource");
NS_LOG(DEBUG, "NSPutMessageResource - IN");
if(msg != NULL)
{
NS_LOG(DEBUG, "NSMessage is valid");
- NS_LOG_V(DEBUG, "msg -> mId : %s", msg->mId);
- NS_LOG_V(DEBUG, "msg -> mTitle : %s", msg->mTitle);
- NS_LOG_V(DEBUG, "msg -> mContentText : %s", msg->mContentText);
- NotificationMessageResource.id = OICStrdup(msg->mId);
- NotificationMessageResource.title = OICStrdup(msg->mTitle);
- NotificationMessageResource.body = OICStrdup(msg->mContentText);
+ NotificationMessageResource.messageId = msg->messageId;
+ OICStrcpy(NotificationMessageResource.providerId, UUID_STRING_SIZE, msg->providerId);
+ NotificationMessageResource.type = msg->type;
+ NotificationMessageResource.dateTime = msg->dateTime;
+ NotificationMessageResource.ttl = msg->ttl;
+ NotificationMessageResource.title = msg->title;
+ NotificationMessageResource.contentText = msg->contentText;
+ NotificationMessageResource.sourceName = msg->sourceName;
+ NotificationMessageResource.mediaContents = msg->mediaContents;
}
else
{
return NS_OK;
}
-NSResult NSPutSyncResource(NSSync *sync, OCResourceHandle * handle)
+NSResult NSPutSyncResource(NSSyncInfo *sync, OCResourceHandle * handle)
{
- OIC_LOG(INFO, RESOURCE_TAG, "Put notification sync to Resource");
NS_LOG(DEBUG, "NSPutSyncResource - IN");
(void) sync;
NS_LOG(DEBUG, "NSPutSyncResource - OUT");
return NS_OK;
}
-
-const char* NSGetNotificationUri()
-{
- return NSUri;
-}
-
-const char* NSGetNotificationMessageUri()
-{
- return NSMessageUri;
-}
-
-const char* NSGetNotificationSyncUri()
-{
- return NSSyncUri;
-}
-
-NSResult NSCopyString(char** targetString, const char* sourceString)
-{
- if (sourceString)
- {
- *targetString = (char *) malloc(strlen(sourceString) + 1);
-
- if (*targetString)
- {
- strncpy(*targetString, sourceString, (strlen(sourceString) + 1));
- return NS_SUCCESS;
- }
- }
-
- return NS_FAIL;
-}