X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Fnotification%2Fsrc%2Fprovider%2FNSProviderResource.c;h=494b6705ad65446e770bf7da36bcdb7d53821ce8;hb=refs%2Ftags%2Fsubmit%2Ftizen%2F20171214.102437;hp=8da879673aed7d8e75889528871e851b61d35e22;hpb=83cce9ed0ab42d4c4968e00ad7ad9b795620725e;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/notification/src/provider/NSProviderResource.c b/service/notification/src/provider/NSProviderResource.c index 8da8796..494b670 100644 --- a/service/notification/src/provider/NSProviderResource.c +++ b/service/notification/src/provider/NSProviderResource.c @@ -19,17 +19,24 @@ //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #include "NSProviderResource.h" +#include +#include "rd_client.h" NSNotificationResource NotificationResource; NSMessageResource NotificationMessageResource; NSSyncResource NotificationSyncResource; +NSTopicResource NotificationTopicResource; + +#if (defined WITH_CLOUD) +#define DEFAULT_CONTEXT_VALUE 0x99 OCStackApplicationResult NSHandlePublishCb(void *ctx, OCDoHandle handle, OCClientResponse *clientResponse) { + (void) handle; if (ctx != (void *)DEFAULT_CONTEXT_VALUE) { - NS_LOG(DEBUG, "Invalid publish callback received"); + NS_LOG(DEBUG, "Invalid Publish callback received"); } NS_LOG_V(DEBUG, "Publish resource response received code: %d", clientResponse->result); @@ -39,42 +46,72 @@ OCStackApplicationResult NSHandlePublishCb(void *ctx, OCDoHandle handle, NSResult NSPublishResourceToCloud(char *serverAddress) { - NS_LOG(DEBUG, "NSPublishResourceToCloud - IN"); - NS_LOG_V(DEBUG, "Cloud address: %s", serverAddress); + NS_LOG_V(INFO_PRIVATE, "Remote Server Address: %s", serverAddress); + + OCCallbackData cbData; + cbData.cb = NSHandlePublishCb; + cbData.context = (void *)DEFAULT_CONTEXT_VALUE; + cbData.cd = NULL; - const char * publishQuery = "/oic/rd?rt=oic.wk.rdpub"; + OCResourceHandle resourceHandles[1] = { NotificationResource.handle }; + OCStackResult res = OCRDPublish(NULL, serverAddress, CT_ADAPTER_TCP, resourceHandles, 1, + &cbData, OC_LOW_QOS); - if (NSCloudPublish(serverAddress, publishQuery, &NSHandlePublishCb, 1, - NotificationResource.handle) != OC_STACK_OK) + if (res != OC_STACK_OK) { - NS_LOG(DEBUG, "Unable to publish resources to cloud"); + NS_LOG_V(DEBUG, "Unable to publish resources to cloud: %d", res); } NS_LOG(DEBUG, "NSPublishResourceToCloud - OUT"); return NS_OK; } +#endif NSResult NSCreateResource(char *uri) { NS_LOG(DEBUG, "NSCreateResource - IN"); + if (!uri) { - NS_LOG(NS_ERROR, "Resource URI cannot be NULL"); + NS_LOG(ERROR, "Resource URI cannot be NULL"); return NS_ERROR; } + uint8_t resourceProperties; + if (strcmp(uri, NS_ROOT_URI) == 0) { - NotificationResource.accepter = 0; + NotificationResource.policy = true; + (NotificationResource.providerId)[0] = '\0'; NotificationResource.message_uri = NS_COLLECTION_MESSAGE_URI; NotificationResource.sync_uri = NS_COLLECTION_SYNC_URI; + NotificationResource.topic_uri = NS_COLLECTION_TOPIC_URI; + NotificationResource.version = VERSION; NotificationResource.handle = NULL; - if (OCCreateResource(&NotificationResource.handle, NS_ROOT_TYPE, NS_DEFAULT_INTERFACE, - NS_ROOT_URI, NSEntityHandlerNotificationCb, NULL, OC_DISCOVERABLE) != OC_STACK_OK) + if (NSGetResourceSecurity()) + { + NS_LOG(DEBUG, "Create secured resource"); + resourceProperties = OC_DISCOVERABLE | OC_SECURE; + } + else + { + resourceProperties = OC_DISCOVERABLE; + } + + if (OCCreateResource(&NotificationResource.handle, NS_ROOT_TYPE, NS_INTERFACE_BASELINE, + NS_ROOT_URI, NSEntityHandlerNotificationCb, NULL, + resourceProperties) != OC_STACK_OK) { - NS_LOG(NS_ERROR, "Fail to Create Notification Resource"); + NS_LOG(ERROR, "Fail to Create Notification Resource"); + return NS_ERROR; + } + + if (OCBindResourceInterfaceToResource(NotificationResource.handle, NS_INTERFACE_READ) + != OC_STACK_OK) + { + NS_LOG(ERROR, "Fail to bind Notification Resource Type"); return NS_ERROR; } } @@ -90,27 +127,97 @@ NSResult NSCreateResource(char *uri) NotificationMessageResource.title = NULL; NotificationMessageResource.contentText = NULL; NotificationMessageResource.sourceName = NULL; + NotificationMessageResource.topicName = NULL; NotificationMessageResource.mediaContents = NULL; + if (NSGetResourceSecurity()) + { + NS_LOG(DEBUG, "Create secured resource"); + resourceProperties = OC_OBSERVABLE | OC_SECURE; + } + else + { + resourceProperties = OC_OBSERVABLE; + } + if (OCCreateResource(&NotificationMessageResource.handle, NS_COLLECTION_MESSAGE_TYPE, - NS_DEFAULT_INTERFACE, NS_COLLECTION_MESSAGE_URI, NSEntityHandlerMessageCb, NULL, - OC_OBSERVABLE) != OC_STACK_OK) + NS_INTERFACE_BASELINE, NS_COLLECTION_MESSAGE_URI, NSEntityHandlerMessageCb, NULL, + resourceProperties) != OC_STACK_OK) { - NS_LOG(NS_ERROR, "Fail to Create Notification Message Resource"); + NS_LOG(ERROR, "Fail to Create Notification Message Resource"); + return NS_ERROR; + } + + if (OCBindResourceInterfaceToResource(NotificationMessageResource.handle, NS_INTERFACE_READ) + != OC_STACK_OK) + { + NS_LOG(ERROR, "Fail to bind Notification Message Resource Type"); return NS_ERROR; } } else if (strcmp(uri, NS_COLLECTION_SYNC_URI) == 0) { - NotificationSyncResource.id = NULL; + NotificationSyncResource.messageId = 0; + (NotificationSyncResource.providerId)[0] = '\0'; NotificationSyncResource.state = NULL; NotificationSyncResource.handle = NULL; + if (NSGetResourceSecurity()) + { + NS_LOG(DEBUG, "Create secured resource"); + resourceProperties = OC_OBSERVABLE | OC_SECURE; + } + else + { + resourceProperties = OC_OBSERVABLE; + } + if (OCCreateResource(&(NotificationSyncResource.handle), NS_COLLECTION_SYNC_TYPE, - NS_DEFAULT_INTERFACE, NS_COLLECTION_SYNC_URI, NSEntityHandlerSyncCb, NULL, - OC_OBSERVABLE) != OC_STACK_OK) + NS_INTERFACE_BASELINE, NS_COLLECTION_SYNC_URI, NSEntityHandlerSyncCb, NULL, + resourceProperties) != OC_STACK_OK) + { + NS_LOG(ERROR, "Fail to Create Notification Sync Resource"); + return NS_ERROR; + } + + if (OCBindResourceInterfaceToResource(NotificationSyncResource.handle, + NS_INTERFACE_READWRITE) + != OC_STACK_OK) + { + NS_LOG(ERROR, "Fail to bind Notification Sync Resource Type"); + return NS_ERROR; + } + } + else if (strcmp(uri, NS_COLLECTION_TOPIC_URI) == 0) + { + (NotificationTopicResource.providerId)[0] = '\0'; + (NotificationTopicResource.consumerId)[0] = '\0'; + NotificationTopicResource.TopicList = NULL; + NotificationTopicResource.handle = NULL; + + if (NSGetResourceSecurity()) + { + NS_LOG(DEBUG, "Create secured resource"); + resourceProperties = OC_RES_PROP_NONE | OC_SECURE; + } + else + { + resourceProperties = OC_RES_PROP_NONE; + } + + if (OCCreateResource(&(NotificationTopicResource.handle), NS_COLLECTION_TOPIC_TYPE, + NS_INTERFACE_BASELINE, NS_COLLECTION_TOPIC_URI, NSEntityHandlerTopicCb, NULL, + resourceProperties) != OC_STACK_OK) + { + NS_LOG(ERROR, "Fail to Create Notification Sync Resource"); + return NS_ERROR; + } + + if (OCBindResourceInterfaceToResource(NotificationTopicResource.handle, + NS_INTERFACE_READWRITE) + != OC_STACK_OK) { - NS_LOG(NS_ERROR, "Fail to Create Notification Sync Resource"); + NS_LOG(ERROR, "Fail to bind Notification Topic Resource Type"); return NS_ERROR; } } @@ -128,23 +235,14 @@ NSResult NSRegisterResource() { NS_LOG(DEBUG, "NSRegisterResource - IN"); - if (NSCreateResource(NS_COLLECTION_SYNC_URI) != NS_OK) - { - NS_LOG(ERROR, "Fail to register Sync Resource"); - return NS_ERROR; - } - - if (NSCreateResource(NS_COLLECTION_MESSAGE_URI) != NS_OK) - { - NS_LOG(ERROR, "Fail to register Message Resource"); - return NS_ERROR; - } - - if (NSCreateResource(NS_ROOT_URI) != NS_OK) - { - NS_LOG(ERROR, "Fail to register Notification Resource"); - return NS_ERROR; - } + NS_CREATE_RESOURCE( + NSCreateResource(NS_COLLECTION_TOPIC_URI), "Fail to register Topic Resource"); + NS_CREATE_RESOURCE( + NSCreateResource(NS_COLLECTION_SYNC_URI), "Fail to register Sync Resource"); + NS_CREATE_RESOURCE( + NSCreateResource(NS_COLLECTION_MESSAGE_URI), "Fail to register Message Resource"); + NS_CREATE_RESOURCE( + NSCreateResource(NS_ROOT_URI), "Fail to register Notification Resource"); NS_LOG(DEBUG, "NSRegisterResource - OUT"); return NS_OK; @@ -154,39 +252,35 @@ 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; - } + NS_DELETE_RESOURCE( + OCDeleteResource(NotificationResource.handle), "Fail to Delete Notification Resource"); + NS_DELETE_RESOURCE(OCDeleteResource(NotificationMessageResource.handle), + "Fail to Delete Notification Message Resource"); + NS_DELETE_RESOURCE(OCDeleteResource(NotificationSyncResource.handle), + "Fail to Delete Notification Sync Resource"); + NS_DELETE_RESOURCE(OCDeleteResource(NotificationTopicResource.handle), + "Fail to Delete Notification Topic Resource"); NotificationResource.handle = NULL; NotificationMessageResource.handle = NULL; NotificationSyncResource.handle = NULL; + NotificationTopicResource.handle = NULL; NS_LOG(DEBUG, "NSUnRegisterResource - OUT"); return NS_OK; } -NSResult NSPutNotificationResource(int accepter, OCResourceHandle * handle) +NSResult NSPutNotificationResource(bool policy, OCResourceHandle * handle) { NS_LOG(DEBUG, "NSPutNotificationResource - IN"); - NotificationResource.accepter = accepter; + NotificationResource.policy = policy; + OICStrcpy(NotificationResource.providerId, UUID_STRING_SIZE, + NSGetProviderInfo()->providerId); NotificationResource.message_uri = NS_COLLECTION_MESSAGE_URI; NotificationResource.sync_uri = NS_COLLECTION_SYNC_URI; + NotificationResource.topic_uri = NS_COLLECTION_TOPIC_URI; + NotificationResource.version = VERSION; *handle = NotificationResource.handle; @@ -210,6 +304,7 @@ NSResult NSPutMessageResource(NSMessage *msg, OCResourceHandle * handle) NotificationMessageResource.title = msg->title; NotificationMessageResource.contentText = msg->contentText; NotificationMessageResource.sourceName = msg->sourceName; + NotificationMessageResource.topicName = msg->topic; NotificationMessageResource.mediaContents = msg->mediaContents; } else @@ -218,8 +313,8 @@ NSResult NSPutMessageResource(NSMessage *msg, OCResourceHandle * handle) } *handle = NotificationMessageResource.handle; - NS_LOG(DEBUG, "NSPutMessageResource - OUT"); + NS_LOG(DEBUG, "NSPutMessageResource - OUT"); return NS_OK; } @@ -234,3 +329,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; +}