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
{\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
{\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
{
NS_ACCESS_ALLOW = 0,
NS_ACCESS_DENY = 1,
-} NSAccessPolicy;
+} NSAccessPolicy; // not used , this structure will be deleted.
/**
* Notification message status to synchronize
* @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
#define NS_QUERY_ID_SIZE 10
+#define NS_POLICY_PROVIDER 1
+#define NS_POLICY_CONSUMER 0
+
typedef enum eConnectionState
{
DISCONNECTED = 0,
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
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(), ¬ificationResourceHandle)\r
+ if (NSPutNotificationResource(NSGetPolicy(), ¬ificationResourceHandle)\r
!= NS_OK)\r
{\r
NS_LOG(ERROR, "Fail to put notification resource");\r
\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
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
#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
static char NSRemoteServerAddress[MAX_SERVER_ADDRESS] = {0,};\r
\r
NSProviderInfo * providerInfo;\r
+bool NSPolicy = true;\r
\r
void NSSetProviderConnectionState(NSConnectionState state)\r
{\r
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