#include "NSProviderResource.h"
-const char* NSType = "oic.r.notification";
-const char* NSMessageType = "oic.r.notification.message";
-const char* NSSyncType = "oic.r.notification.sync";
-
-const char* NSInterface = "oic.if.baseline";
-const char* NSMessgeInterface = "oic.if.baseline.message";
-const char* NSSyncInterface = "oic.if.baseline.sync";
-
-const char* NSUri = "/notification";
-const char* NSMessageUri = "/notification/message";
-const 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;
NSResult NSCreateResource(char *uri)
{
+ 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;
}
-
- printf("NotificationResource.handle = %u\n", NotificationResource.handle);
-
-
}
- 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;
}
-
- printf("NotificationMessageResource.handle = %u\n", NotificationMessageResource.handle);
-
-
}
- else if (strcmp(uri, NSSyncUri) == 0)
+ else if (strcmp(uri, NS_COLLECTION_SYNC_URI) == 0)
{
NotificationSyncResource.id = NULL;
NotificationSyncResource.state = NULL;
- NotificationSyncResource.device;
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;
}
-
- printf("NotificationSyncResource.handle = %u\n", NotificationSyncResource.handle);
-
}
else
{
- OIC_LOG(ERROR, RESOURCE_TAG, PCF("Fail to create resource with invalid URI"));
+ NS_LOG(ERROR, "Fail to create resource with invalid URI");
return NS_ERROR;
}
+ NS_LOG(DEBUG, "NSCreateResource - OUT");
return NS_OK;
}
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(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(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(ERROR, "Fail to register Notification Resource");
return NS_ERROR;
}
+ NS_LOG(DEBUG, "NSRegisterResource - OUT");
+ 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;
+ NS_LOG(DEBUG, "NSPutNotificationResource - OUT");
return NS_OK;
}
NSResult NSPutMessageResource(NSMessage *msg, OCResourceHandle * handle)
{
- OIC_LOG(INFO, RESOURCE_TAG, "Put notification message to Resource");
+ NS_LOG(DEBUG, "NSPutMessageResource - IN");
if(msg != NULL)
{
- printf("msg is not null\n");
- NotificationMessageResource.id = strdup(msg->mId);
- NotificationMessageResource.title = strdup(msg->mTitle);
- NotificationMessageResource.body = strdup(msg->mContentText);
+ NS_LOG(DEBUG, "NSMessage is valid");
+
+ 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
{
- printf("msg is null\n");
+ NS_LOG(ERROR, "NSMessage is NULL");
}
*handle = NotificationMessageResource.handle;
+ NS_LOG(DEBUG, "NSPutMessageResource - OUT");
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;
*handle = NotificationSyncResource.handle;
+ 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;
-}