From: jaesick.shin Date: Wed, 7 Sep 2016 06:36:29 +0000 (+0900) Subject: Add Macro for related resource and bug fixes for Topic. X-Git-Tag: 1.2.0+RC3~151^2^2~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=068e21f3db8172dd88768be23253bde4bc2da9af;p=platform%2Fupstream%2Fiotivity.git Add Macro for related resource and bug fixes for Topic. 1. Add Macro - createResource, deleteResource 2. Add NS_FAIL for fail case in NSAddTopics Function. Change-Id: Ic94403298cf824e9d7a47de91d8c42bfa84b1460 Signed-off-by: jaesick.shin Reviewed-on: https://gerrit.iotivity.org/gerrit/11489 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- diff --git a/service/notification/src/provider/NSProviderResource.c b/service/notification/src/provider/NSProviderResource.c index 900d83f..a056d68 100644 --- a/service/notification/src/provider/NSProviderResource.c +++ b/service/notification/src/provider/NSProviderResource.c @@ -162,29 +162,14 @@ 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"); - 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; @@ -194,29 +179,14 @@ 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; - } - - if (OCDeleteResource(NotificationTopicResource.handle) != OC_STACK_OK) - { - NS_LOG(ERROR, "Fail to Delete Notification Topic 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; diff --git a/service/notification/src/provider/NSProviderResource.h b/service/notification/src/provider/NSProviderResource.h index 7d38eea..b5bc6de 100644 --- a/service/notification/src/provider/NSProviderResource.h +++ b/service/notification/src/provider/NSProviderResource.h @@ -28,6 +28,26 @@ #include "oic_malloc.h" #include "oic_string.h" +#define NS_CREATE_RESOURCE(func, obj) \ + { \ + NSResult _ret = (func); \ + if ( _ret != NS_OK) \ + { \ + NS_LOG_V(ERROR, "%s : %s", __func__, #obj); \ + return (NS_ERROR); \ + } \ + } + +#define NS_DELETE_RESOURCE(func, obj) \ + { \ + OCStackResult _ret = (func); \ + if ( _ret != OC_STACK_OK) \ + { \ + NS_LOG_V(ERROR, "%s : %s", __func__, #obj); \ + return (NS_ERROR); \ + } \ + } + NSResult NSCreateResource(char *uri); NSResult NSPublishResourceToCloud(char *host); diff --git a/service/notification/src/provider/NSProviderTopic.c b/service/notification/src/provider/NSProviderTopic.c index f7d9940..1786b5b 100644 --- a/service/notification/src/provider/NSProviderTopic.c +++ b/service/notification/src/provider/NSProviderTopic.c @@ -73,6 +73,7 @@ NSResult NSAddTopics(const char * topicName) if(NSStorageWrite(registeredTopicList, element) != NS_OK) { NS_LOG(DEBUG, "fail to write cache"); + return NS_ERROR; } NSSendTopicUpdation();