From: jaesick.shin Date: Tue, 26 Jul 2016 04:11:14 +0000 (+0900) Subject: modify NSPolicy in Provider side. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fb557b59fab5834bed2d9672c7e77f8dbd24754c;p=contrib%2Fiotivity.git modify NSPolicy in Provider side. This commit included Not used NSAccessPolicy Enum. and move to Provider System as NSPolicy. second patch included build failed to NSAccept Function at CPP wrapper. NSAccept Function name is already changed to NSAcceptSubscription. Change-Id: I418d16f0f4631617116c073e333cb7964b6c12d6 Signed-off-by: jaesick.shin Reviewed-on: https://gerrit.iotivity.org/gerrit/9709 Tested-by: jenkins-iotivity Reviewed-by: Hun-je Yeon Reviewed-by: Uze Choi --- diff --git a/service/notification/android/notification-service/src/main/jni/notificationProvider.c b/service/notification/android/notification-service/src/main/jni/notificationProvider.c index 86fbe8d..c906357 100644 --- a/service/notification/android/notification-service/src/main/jni/notificationProvider.c +++ b/service/notification/android/notification-service/src/main/jni/notificationProvider.c @@ -53,9 +53,9 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NS g_obj_syncListener = (jobject) (*env)->NewGlobalRef(env, jSyncListener); // check access policy - NSAccessPolicy access = NS_ACCESS_ALLOW; + bool policy = true; - if (NSStartProvider(access, NSSubscribeRequestCb, NSSyncCb) != NS_OK) + if (NSStartProvider(policy, NSSubscribeRequestCb, NSSyncCb) != NS_OK) { LOGE("Fail to start NSProvider service"); return (jint) NS_ERROR; diff --git a/service/notification/cpp-wrapper/provider/src/NSConsumer.cpp b/service/notification/cpp-wrapper/provider/src/NSConsumer.cpp index 9fce017..d264191 100755 --- a/service/notification/cpp-wrapper/provider/src/NSConsumer.cpp +++ b/service/notification/cpp-wrapper/provider/src/NSConsumer.cpp @@ -50,7 +50,7 @@ namespace OIC { NS_LOG(DEBUG, "acceptSubscription - IN"); if (consumer != nullptr) - return NSAccept(consumer->getNSConsumer(), accepted); + return NSAcceptSubscription(consumer->getNSConsumer(), accepted); NS_LOG(DEBUG, "acceptSubscription - OUT"); return NS_ERROR; } diff --git a/service/notification/examples/linux/notificationprovider.c b/service/notification/examples/linux/notificationprovider.c index c3329f6..70d5821 100644 --- a/service/notification/examples/linux/notificationprovider.c +++ b/service/notification/examples/linux/notificationprovider.c @@ -155,11 +155,11 @@ int main() { case 1: printf("NSStartProvider(Accepter: Provider)"); - NSStartProvider(NS_ACCESS_ALLOW, subscribeRequestCallback, syncCallback); + NSStartProvider(true, subscribeRequestCallback, syncCallback); break; case 2: printf("NSStartProvider(Accepter: Consumer)"); - NSStartProvider(NS_ACCESS_DENY, subscribeRequestCallback, syncCallback); + NSStartProvider(false, subscribeRequestCallback, syncCallback); break; case 3: printf("NSSendNotification()"); diff --git a/service/notification/include/NSCommon.h b/service/notification/include/NSCommon.h index 41beb5d..fa3d1a0 100644 --- a/service/notification/include/NSCommon.h +++ b/service/notification/include/NSCommon.h @@ -65,7 +65,7 @@ typedef enum eAccessPolicy { NS_ACCESS_ALLOW = 0, NS_ACCESS_DENY = 1, -} NSAccessPolicy; +} NSAccessPolicy; // not used , this structure will be deleted. /** * Notification message status to synchronize diff --git a/service/notification/include/NSProviderInterface.h b/service/notification/include/NSProviderInterface.h index 5a7211c..dd979f1 100644 --- a/service/notification/include/NSProviderInterface.h +++ b/service/notification/include/NSProviderInterface.h @@ -57,7 +57,7 @@ typedef void (*NSProviderSyncInfoCallback)(NSSyncInfo *); * @param[in] syncCallback Callback function to register for receiving sync data * @return ::NS_OK or result code of NSResult */ -NSResult NSStartProvider(NSAccessPolicy policy, NSSubscribeRequestCallback subscribeRequestCb, +NSResult NSStartProvider(bool policy, NSSubscribeRequestCallback subscribeRequestCb, NSProviderSyncInfoCallback syncCb); /** diff --git a/service/notification/src/common/NSConstants.h b/service/notification/src/common/NSConstants.h index 9db4b55..e532115 100644 --- a/service/notification/src/common/NSConstants.h +++ b/service/notification/src/common/NSConstants.h @@ -84,6 +84,9 @@ #define NS_QUERY_ID_SIZE 10 +#define NS_POLICY_PROVIDER 1 +#define NS_POLICY_CONSUMER 0 + typedef enum eConnectionState { DISCONNECTED = 0, diff --git a/service/notification/src/provider/NSProviderInterface.c b/service/notification/src/provider/NSProviderInterface.c index 789eda3..7eb5553 100644 --- a/service/notification/src/provider/NSProviderInterface.c +++ b/service/notification/src/provider/NSProviderInterface.c @@ -42,7 +42,7 @@ void initializeMutex() nsInitMutex = initMutex; } -NSResult NSStartProvider(NSAccessPolicy policy, NSSubscribeRequestCallback subscribeRequestCb, +NSResult NSStartProvider(bool policy, NSSubscribeRequestCallback subscribeRequestCb, NSProviderSyncInfoCallback syncCb) { NS_LOG(DEBUG, "NSStartProvider - IN"); diff --git a/service/notification/src/provider/NSProviderSubscription.c b/service/notification/src/provider/NSProviderSubscription.c index 3c2c267..c259251 100644 --- a/service/notification/src/provider/NSProviderSubscription.c +++ b/service/notification/src/provider/NSProviderSubscription.c @@ -31,37 +31,32 @@ NSResult NSInitSubscriptionList() return NS_OK; } -NSResult NSSetSubscriptionAccessPolicy(NSAccessPolicy access) +NSResult NSSetSubscriptionAccessPolicy(bool policy) { NS_LOG(DEBUG, "NSSetSubscriptionAcceptPolicy - IN"); - if (access == NS_ACCESS_ALLOW) + if (policy == NS_POLICY_PROVIDER) { NS_LOG(DEBUG, "Place Provider as a subscription accepter"); } - else if (access == NS_ACCESS_DENY) + else if (policy == NS_POLICY_CONSUMER) { NS_LOG(DEBUG, "Place Consumer as a subscription accepter"); } - NSSubscriptionAccess = access; + NSSetPolicy(policy); NS_LOG(DEBUG, "NSSetSubscriptionAcceptPolicy - OUT"); return NS_OK; } -int NSGetSubscriptionAccepter() -{ - return NSSubscriptionAccess; -} - NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest) { NS_LOG(DEBUG, "NSSendAccessPolicyResponse - IN"); // put notification resource OCResourceHandle notificationResourceHandle = NULL; - if (NSPutNotificationResource(NSGetSubscriptionAccepter(), ¬ificationResourceHandle) + if (NSPutNotificationResource(NSGetPolicy(), ¬ificationResourceHandle) != NS_OK) { NS_LOG(ERROR, "Fail to put notification resource"); @@ -86,7 +81,7 @@ NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest OCRepPayloadSetUri(payload, NS_ROOT_URI); OCRepPayloadSetPropString(payload, NS_ATTRIBUTE_PROVIDER_ID, NSGetProviderInfo()->providerId); - OCRepPayloadSetPropInt(payload, NS_ATTRIBUTE_POLICY, NSGetSubscriptionAccepter()); + OCRepPayloadSetPropInt(payload, NS_ATTRIBUTE_POLICY, NSGetPolicy()); OCRepPayloadSetPropString(payload, NS_ATTRIBUTE_MESSAGE, NS_COLLECTION_MESSAGE_URI); OCRepPayloadSetPropString(payload, NS_ATTRIBUTE_SYNC, NS_COLLECTION_SYNC_URI); @@ -159,12 +154,14 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour NS_LOG(DEBUG, "fail to write cache"); } - if (NSGetSubscriptionAccepter() == NS_ACCESS_ALLOW) + bool currPolicy = NSGetPolicy(); + + if (currPolicy == NS_POLICY_PROVIDER) { NS_LOG(DEBUG, "NSGetSubscriptionAccepter == NS_ACCEPTER_PROVIDER"); NSAskAcceptanceToUser(entityHandlerRequest); } - else if (NSGetSubscriptionAccepter() == NS_ACCESS_DENY) + else if (currPolicy == NS_POLICY_CONSUMER) { NS_LOG(DEBUG, "NSGetSubscriptionAccepter == NS_ACCEPTER_CONSUMER"); NSSendSubscriptionResponse(entityHandlerRequest, true); diff --git a/service/notification/src/provider/NSProviderSubscription.h b/service/notification/src/provider/NSProviderSubscription.h index e6d3a25..a8f2139 100644 --- a/service/notification/src/provider/NSProviderSubscription.h +++ b/service/notification/src/provider/NSProviderSubscription.h @@ -33,12 +33,11 @@ #include "oic_string.h" #include "oic_malloc.h" -NSAccessPolicy NSSubscriptionAccess; NSCacheList * consumerSubList; NSResult NSInitSubscriptionList(); -NSResult NSSetSubscriptionAccessPolicy(NSAccessPolicy policy); -int NSGetSubscriptionAccepter(); +NSResult NSSetSubscriptionAccessPolicy(bool policy); +bool NSGetPolicy(); NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest); void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResourceType resourceType); void NSHandleUnsubscription(OCEntityHandlerRequest *entityHandlerRequest); diff --git a/service/notification/src/provider/NSProviderSystem.c b/service/notification/src/provider/NSProviderSystem.c index b9b2bf6..778bcce 100644 --- a/service/notification/src/provider/NSProviderSystem.c +++ b/service/notification/src/provider/NSProviderSystem.c @@ -24,6 +24,7 @@ static NSConnectionState NSProviderConnectionState; static char NSRemoteServerAddress[MAX_SERVER_ADDRESS] = {0,}; NSProviderInfo * providerInfo; +bool NSPolicy = true; void NSSetProviderConnectionState(NSConnectionState state) { @@ -103,3 +104,13 @@ NSProviderInfo * NSGetProviderInfo() return providerInfo; } +bool NSGetPolicy() +{ + return NSPolicy; +} + +void NSSetPolicy(bool policy) +{ + NSPolicy = policy; +} +