modify NSPolicy in Provider side.
authorjaesick.shin <jaesick.shin@samsung.com>
Tue, 26 Jul 2016 04:11:14 +0000 (13:11 +0900)
committerUze Choi <uzchoi@samsung.com>
Wed, 27 Jul 2016 06:24:45 +0000 (06:24 +0000)
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 <jaesick.shin@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9709
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Hun-je Yeon <hunje.yeon@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/notification/android/notification-service/src/main/jni/notificationProvider.c
service/notification/cpp-wrapper/provider/src/NSConsumer.cpp
service/notification/examples/linux/notificationprovider.c
service/notification/include/NSCommon.h
service/notification/include/NSProviderInterface.h
service/notification/src/common/NSConstants.h
service/notification/src/provider/NSProviderInterface.c
service/notification/src/provider/NSProviderSubscription.c
service/notification/src/provider/NSProviderSubscription.h
service/notification/src/provider/NSProviderSystem.c

index 86fbe8d..c906357 100644 (file)
@@ -53,9 +53,9 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_notification_IoTNotification_NS
     g_obj_syncListener = (jobject) (*env)->NewGlobalRef(env, jSyncListener);\r
 \r
     // check access policy\r
-    NSAccessPolicy access = NS_ACCESS_ALLOW;\r
+    bool policy = true;\r
 \r
-    if (NSStartProvider(access, NSSubscribeRequestCb, NSSyncCb) != NS_OK)\r
+    if (NSStartProvider(policy, NSSubscribeRequestCb, NSSyncCb) != NS_OK)\r
     {\r
         LOGE("Fail to start NSProvider service");\r
         return (jint) NS_ERROR;\r
index 9fce017..d264191 100755 (executable)
@@ -50,7 +50,7 @@ namespace OIC
         {\r
             NS_LOG(DEBUG, "acceptSubscription - IN");\r
             if (consumer != nullptr)\r
-                return NSAccept(consumer->getNSConsumer(), accepted);\r
+                return NSAcceptSubscription(consumer->getNSConsumer(), accepted);\r
             NS_LOG(DEBUG, "acceptSubscription - OUT");\r
             return NS_ERROR;\r
         }\r
index c3329f6..70d5821 100644 (file)
@@ -155,11 +155,11 @@ int main()
         {\r
             case 1:\r
                 printf("NSStartProvider(Accepter: Provider)");\r
-                NSStartProvider(NS_ACCESS_ALLOW, subscribeRequestCallback, syncCallback);\r
+                NSStartProvider(true, subscribeRequestCallback, syncCallback);\r
                 break;\r
             case 2:\r
                 printf("NSStartProvider(Accepter: Consumer)");\r
-                NSStartProvider(NS_ACCESS_DENY, subscribeRequestCallback, syncCallback);\r
+                NSStartProvider(false, subscribeRequestCallback, syncCallback);\r
                 break;\r
             case 3:\r
                 printf("NSSendNotification()");\r
index 41beb5d..fa3d1a0 100644 (file)
@@ -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
index 5a7211c..dd979f1 100644 (file)
@@ -57,7 +57,7 @@ typedef void (*NSProviderSyncInfoCallback)(NSSyncInfo *);
  * @param[in]  syncCallback   Callback function to register for receiving  sync data\r
  * @return ::NS_OK or result code of NSResult\r
  */\r
-NSResult NSStartProvider(NSAccessPolicy policy, NSSubscribeRequestCallback subscribeRequestCb,\r
+NSResult NSStartProvider(bool policy, NSSubscribeRequestCallback subscribeRequestCb,\r
         NSProviderSyncInfoCallback syncCb);\r
 \r
 /**\r
index 9db4b55..e532115 100644 (file)
@@ -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,
index 789eda3..7eb5553 100644 (file)
@@ -42,7 +42,7 @@ void initializeMutex()
     nsInitMutex = initMutex;\r
 }\r
 \r
-NSResult NSStartProvider(NSAccessPolicy policy, NSSubscribeRequestCallback subscribeRequestCb,\r
+NSResult NSStartProvider(bool policy, NSSubscribeRequestCallback subscribeRequestCb,\r
         NSProviderSyncInfoCallback syncCb)\r
 {\r
     NS_LOG(DEBUG, "NSStartProvider - IN");\r
index 3c2c267..c259251 100644 (file)
@@ -31,37 +31,32 @@ NSResult NSInitSubscriptionList()
     return NS_OK;\r
 }\r
 \r
-NSResult NSSetSubscriptionAccessPolicy(NSAccessPolicy access)\r
+NSResult NSSetSubscriptionAccessPolicy(bool policy)\r
 {\r
     NS_LOG(DEBUG, "NSSetSubscriptionAcceptPolicy - IN");\r
 \r
-    if (access == NS_ACCESS_ALLOW)\r
+    if (policy == NS_POLICY_PROVIDER)\r
     {\r
         NS_LOG(DEBUG, "Place Provider as a subscription accepter");\r
     }\r
-    else if (access == NS_ACCESS_DENY)\r
+    else if (policy == NS_POLICY_CONSUMER)\r
     {\r
         NS_LOG(DEBUG, "Place Consumer as a subscription accepter");\r
     }\r
 \r
-    NSSubscriptionAccess = access;\r
+    NSSetPolicy(policy);\r
 \r
     NS_LOG(DEBUG, "NSSetSubscriptionAcceptPolicy - OUT");\r
     return NS_OK;\r
 }\r
 \r
-int NSGetSubscriptionAccepter()\r
-{\r
-    return NSSubscriptionAccess;\r
-}\r
-\r
 NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest)\r
 {\r
     NS_LOG(DEBUG, "NSSendAccessPolicyResponse - IN");\r
 \r
     // put notification resource\r
     OCResourceHandle notificationResourceHandle = NULL;\r
-    if (NSPutNotificationResource(NSGetSubscriptionAccepter(), &notificationResourceHandle)\r
+    if (NSPutNotificationResource(NSGetPolicy(), &notificationResourceHandle)\r
             != NS_OK)\r
     {\r
         NS_LOG(ERROR, "Fail to put notification resource");\r
@@ -86,7 +81,7 @@ NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest
 \r
     OCRepPayloadSetUri(payload, NS_ROOT_URI);\r
     OCRepPayloadSetPropString(payload, NS_ATTRIBUTE_PROVIDER_ID, NSGetProviderInfo()->providerId);\r
-    OCRepPayloadSetPropInt(payload, NS_ATTRIBUTE_POLICY, NSGetSubscriptionAccepter());\r
+    OCRepPayloadSetPropInt(payload, NS_ATTRIBUTE_POLICY, NSGetPolicy());\r
     OCRepPayloadSetPropString(payload, NS_ATTRIBUTE_MESSAGE, NS_COLLECTION_MESSAGE_URI);\r
     OCRepPayloadSetPropString(payload, NS_ATTRIBUTE_SYNC, NS_COLLECTION_SYNC_URI);\r
 \r
@@ -159,12 +154,14 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour
             NS_LOG(DEBUG, "fail to write cache");\r
         }\r
 \r
-        if (NSGetSubscriptionAccepter() == NS_ACCESS_ALLOW)\r
+        bool currPolicy = NSGetPolicy();\r
+\r
+        if (currPolicy == NS_POLICY_PROVIDER)\r
         {\r
             NS_LOG(DEBUG, "NSGetSubscriptionAccepter == NS_ACCEPTER_PROVIDER");\r
             NSAskAcceptanceToUser(entityHandlerRequest);\r
         }\r
-        else if (NSGetSubscriptionAccepter() == NS_ACCESS_DENY)\r
+        else if (currPolicy == NS_POLICY_CONSUMER)\r
         {\r
             NS_LOG(DEBUG, "NSGetSubscriptionAccepter == NS_ACCEPTER_CONSUMER");\r
             NSSendSubscriptionResponse(entityHandlerRequest, true);\r
index e6d3a25..a8f2139 100644 (file)
 #include "oic_string.h"\r
 #include "oic_malloc.h"\r
 \r
-NSAccessPolicy NSSubscriptionAccess;\r
 NSCacheList * consumerSubList;\r
 \r
 NSResult NSInitSubscriptionList();\r
-NSResult NSSetSubscriptionAccessPolicy(NSAccessPolicy policy);\r
-int NSGetSubscriptionAccepter();\r
+NSResult NSSetSubscriptionAccessPolicy(bool policy);\r
+bool NSGetPolicy();\r
 NSResult NSSendAccessPolicyResponse(OCEntityHandlerRequest *entityHandlerRequest);\r
 void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResourceType resourceType);\r
 void NSHandleUnsubscription(OCEntityHandlerRequest *entityHandlerRequest);\r
index b9b2bf6..778bcce 100644 (file)
@@ -24,6 +24,7 @@ static NSConnectionState NSProviderConnectionState;
 static char NSRemoteServerAddress[MAX_SERVER_ADDRESS] = {0,};\r
 \r
 NSProviderInfo * providerInfo;\r
+bool NSPolicy = true;\r
 \r
 void NSSetProviderConnectionState(NSConnectionState state)\r
 {\r
@@ -103,3 +104,13 @@ NSProviderInfo * NSGetProviderInfo()
     return providerInfo;\r
 }\r
 \r
+bool NSGetPolicy()\r
+{\r
+    return NSPolicy;\r
+}\r
+\r
+void NSSetPolicy(bool policy)\r
+{\r
+    NSPolicy = policy;\r
+}\r
+\r