[CONPRO-1337] Disabled Presence Feature 08/192408/1
authorAmit KS <amit.s12@samsung.com>
Mon, 5 Nov 2018 09:03:24 +0000 (14:33 +0530)
committerAmit KS <amit.s12@samsung.com>
Mon, 5 Nov 2018 09:03:24 +0000 (14:33 +0530)
For disabling presence, DISABLE_PRESENCE=1, flag
should be defined at time of scons build.

https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/325
(cherry picked from commit cc5a552d03e658c6b04886cd0586ed57cd3bdac1)

Change-Id: I0349ab93f85dd3f77b2f84321c157aaf65a671f0
Signed-off-by: Amit KS <amit.s12@samsung.com>
18 files changed:
build_common/SConscript
plugins/samples/linux/IotivityandZigbeeServer.c
resource/csdk/stack/include/octypes.h
resource/csdk/stack/src/ocserverrequest.c
resource/examples/SConscript
resource/src/InProcClientWrapper.cpp
resource/src/InProcServerWrapper.cpp
resource/unittests/OCExceptionTest.cpp
resource/unittests/OCRepresentationEncodingTest.cpp
service/notification/src/common/NSUtil.c [changed mode: 0755->0644]
service/notification/src/consumer/NSConsumerDiscovery.c
service/notification/src/consumer/NSConsumerDiscovery.h
service/notification/src/consumer/NSConsumerNetworkEventListener.c
service/notification/src/provider/NSProviderDiscovery.c
service/notification/src/provider/NSProviderDiscovery.h
service/resource-encapsulation/src/resourceBroker/src/DevicePresence.cpp
service/resource-encapsulation/src/resourceBroker/src/ResourcePresence.cpp
service/resource-encapsulation/src/resourceCache/src/ObserveCache.cpp

index 3d2404c..4a9a350 100644 (file)
@@ -101,6 +101,7 @@ help_vars.Add(BoolVariable('WITH_PROXY', 'Build with CoAP-HTTP Proxy', False))
 help_vars.Add(ListVariable('WITH_MQ', 'Build with MQ publisher/broker', 'OFF', ['OFF', 'SUB', 'PUB', 'BROKER']))
 help_vars.Add(BoolVariable('WITH_CLOUD', 'Build including AccountManager class and Cloud Client sample', False))
 help_vars.Add(ListVariable('RD_MODE', 'Resource Directory build mode', 'CLIENT', ['CLIENT', 'SERVER']))
+help_vars.Add(BoolVariable('DISABLE_PRESENCE', 'Disable Presence Feature', False))
 
 help_vars.Add(BoolVariable('SIMULATOR', 'Build with simulator module', False))
 
@@ -358,6 +359,9 @@ if env.get('WITH_TCP'):
 if env.get('DISABLE_TCP_SERVER'):
        defines.append('-DDISABLE_TCP_SERVER=1')
 
+if env.get('DISABLE_PRESENCE') == False:
+    env.AppendUnique(CPPDEFINES = ['WITH_PRESENCE'])
+
 libs = []
 if env.get('SECURED') == '1':
     defines.append('-D__WITH_DTLS__=1')
index 8caa729..74d987c 100644 (file)
@@ -51,13 +51,14 @@ int main()
         goto IotivityStop;
     }
 
+#ifdef WITH_PRESENCE
     result  = OCStartPresence(0);
     if (result != OC_STACK_OK)
     {
         OIC_LOG_V(ERROR, TAG, "OCStartPresence Failed: %d", result);
         goto IotivityStop;
     }
-
+#endif
     // PIStartPlugin
     PIPlugin* plugin = NULL;
     OIC_LOG(INFO, TAG, "IoTivity Initialized properly, Starting Zigbee Plugin...");
index 6afdb95..df6df44 100644 (file)
@@ -39,9 +39,6 @@
 extern "C" {
 #endif // __cplusplus
 
-/** For the feature presence.*/
-#define WITH_PRESENCE
-
 #include "ocpresence.h"
 
 // TODO : need for secure psi
@@ -87,12 +84,11 @@ extern "C" {
 
 /** Presence URI through which the OIC devices advertise their presence.*/
 #define OC_RSRVD_PRESENCE_URI                 "/oic/ad"
+#endif // WITH_PRESENCE
 
 /** Presence URI through which the OIC devices advertise their device presence.*/
 #define OC_RSRVD_DEVICE_PRESENCE_URI         "/oic/prs"
 
-#endif // WITH_PRESENCE
-
 /** For multicast Discovery mechanism.*/
 #define OC_MULTICAST_DISCOVERY_URI            "/oic/res"
 
index 325abb7..3dde884 100644 (file)
@@ -739,8 +739,8 @@ OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse)
 
     OIC_LOG(INFO, TAG, "Calling OCSendResponse with:");
     OIC_LOG_V(INFO, TAG, "\tEndpoint address: %s", responseEndpoint.addr);
-    OIC_LOG_V(INFO, TAG, "\tEndpoint adapter: %s", responseEndpoint.adapter);
-    OIC_LOG_V(INFO, TAG, "\tResponse result : %s", responseInfo.result);
+    OIC_LOG_V(INFO, TAG, "\tEndpoint adapter: %d", responseEndpoint.adapter);
+    OIC_LOG_V(INFO, TAG, "\tResponse result : %d", responseInfo.result);
     OIC_LOG_V(INFO, TAG, "\tResponse for uri: %s", responseInfo.info.resourceUri);
 
     result = OCSendResponse(&responseEndpoint, &responseInfo);
index 4896179..b2ce91f 100644 (file)
@@ -102,7 +102,6 @@ example_names = [
 if target_os not in ['windows', 'msys_nt']:
        example_names += [
                'fridgeserver', 'fridgeclient',
-               'presenceserver', 'presenceclient',
                'roomserver', 'roomclient',
                'garageserver',
                'garageclient',
@@ -115,6 +114,8 @@ if target_os not in ['windows', 'msys_nt']:
                examples_env.AppendUnique(CPPPATH = ['../csdk/resource-directory/include'])
                example_names += ['rdclient']
                examples_env.AppendUnique(LIBS = ['resource_directory'])
+       if examples_env.get('DISABLE_PRESENCE') == False:
+               example_names += ['presenceserver', 'presenceclient']
 
 examples = map(make_single_file_cpp_program, example_names)
 
index ee47425..41bb8fa 100644 (file)
@@ -1433,6 +1433,7 @@ namespace OC
         return result;
     }
 
+#ifdef WITH_PRESENCE
     OCStackApplicationResult subscribePresenceCallback(void* ctx,
                                                        OCDoHandle /*handle*/,
             OCClientResponse* clientResponse)
@@ -1453,11 +1454,13 @@ namespace OC
 
         return OC_STACK_KEEP_TRANSACTION;
     }
+#endif
 
     OCStackResult InProcClientWrapper::SubscribePresence(OCDoHandle* handle,
         const std::string& host, const std::string& resourceType,
         OCConnectivityType connectivityType, SubscribeCallback& presenceHandler)
     {
+#ifdef WITH_PRESENCE
         if (!presenceHandler)
         {
             return OC_STACK_INVALID_PARAM;
@@ -1491,10 +1494,14 @@ namespace OC
                             os.str().c_str(), nullptr,
                             nullptr, connectivityType,
                             OC_LOW_QOS, &cbdata, NULL, 0);
+#else
+        return OC_STACK_NOT_IMPLEMENTED;
+#endif
     }
 
     OCStackResult InProcClientWrapper::UnsubscribePresence(OCDoHandle handle)
     {
+#ifdef WITH_PRESENCE
         OCStackResult result;
         auto cLock = m_csdkLock.lock();
 
@@ -1509,6 +1516,9 @@ namespace OC
         }
 
         return result;
+#else
+        return OC_STACK_NOT_IMPLEMENTED;
+#endif
     }
 
 #ifdef WITH_CLOUD
index b4b799e..5989cf5 100644 (file)
@@ -606,6 +606,7 @@ namespace OC
 
     OCStackResult InProcServerWrapper::startPresence(const unsigned int seconds)
     {
+#ifdef WITH_PRESENCE
         auto cLock = m_csdkLock.lock();
         OCStackResult result = OC_STACK_ERROR;
         if(cLock)
@@ -619,10 +620,14 @@ namespace OC
             throw OCException(OC::Exception::START_PRESENCE_FAILED, result);
         }
         return result;
+#else
+        return OC_STACK_NOT_IMPLEMENTED;
+#endif
     }
 
     OCStackResult InProcServerWrapper::stopPresence()
     {
+#ifdef WITH_PRESENCE
         auto cLock = m_csdkLock.lock();
         OCStackResult result = OC_STACK_ERROR;
         if(cLock)
@@ -636,6 +641,9 @@ namespace OC
             throw OCException(OC::Exception::END_PRESENCE_FAILED, result);
         }
         return result;
+#else
+        return OC_STACK_NOT_IMPLEMENTED;
+#endif
     }
 
     OCStackResult InProcServerWrapper::sendResponse(
index 921b45f..d95d320 100644 (file)
@@ -72,9 +72,11 @@ namespace OC
                 OC_STACK_SVR_DB_NOT_EXIST,
                 OC_STACK_AUTHENTICATION_FAILURE,
                 OC_STACK_NOT_ALLOWED_OXM,
+#ifdef WITH_PRESENCE
                 OC_STACK_PRESENCE_STOPPED,
                 OC_STACK_PRESENCE_TIMEOUT,
                 OC_STACK_PRESENCE_DO_NOT_HANDLE,
+#endif
                 OC_STACK_USER_DENIED_REQ,
                 OC_STACK_NOT_ACCEPTABLE,
                 OC_STACK_METHOD_NOT_ALLOWED,
index ff0c657..83e74df 100644 (file)
@@ -283,6 +283,7 @@ namespace OCRepresentationEncodingTest
         OCPayloadDestroy((OCPayload *)platform1);
     }
 
+#ifdef WITH_PRESENCE
     TEST(PresencePayload, Normal)
     {
         static const char uri1[] = "/testuri";
@@ -308,6 +309,7 @@ namespace OCRepresentationEncodingTest
 
         OCPayloadDestroy(cparsed);
     }
+#endif
     // Representation Payloads
     TEST(RepresentationEncoding, BaseAttributeTypes)
     {
old mode 100755 (executable)
new mode 100644 (file)
index 8efb307..35c1e25
@@ -609,7 +609,9 @@ bool NSOCResultToSuccess(OCStackResult ret)
         case OC_STACK_OK:
         case OC_STACK_RESOURCE_CREATED:
         case OC_STACK_RESOURCE_DELETED:
+#ifdef WITH_PRESENCE
         case OC_STACK_PRESENCE_STOPPED:
+#endif
         case OC_STACK_CONTINUE:
         case OC_STACK_RESOURCE_CHANGED:
             return true;
index 28c137e..a408b6e 100644 (file)
@@ -32,6 +32,7 @@
 #define NS_DISCOVER_QUERY "/oic/res?rt=x.org.iotivity.notification"
 #define NS_PRESENCE_SUBSCRIBE_QUERY_TCP "/oic/ad?rt=x.org.iotivity.notification"
 
+#ifdef WITH_PRESENCE
 OCStackApplicationResult NSConsumerPresenceListener(
         void * ctx, OCDoHandle handle, OCClientResponse * clientResponse)
 {
@@ -83,6 +84,7 @@ OCStackApplicationResult NSConsumerPresenceListener(
 
     return OC_STACK_KEEP_TRANSACTION;
 }
+#endif
 
 OCStackApplicationResult NSProviderDiscoverListener(
         void * ctx, OCDoHandle handle, OCClientResponse * clientResponse)
@@ -198,11 +200,12 @@ void NSConsumerHandleRequestDiscover(OCDevAddr * address, NSConsumerDiscoverType
         else if (address->adapter == OC_ADAPTER_TCP)
         {
             type = CT_ADAPTER_TCP;
-            NS_LOG(DEBUG, "Request discover and subscribe presence [TCP]");
+            NS_LOG(DEBUG, "Request discover [TCP]");
+#ifdef WITH_PRESENCE
             NS_LOG(DEBUG, "Subscribe presence [TCP]");
             NSInvokeRequest(NULL, OC_REST_PRESENCE, address, NS_PRESENCE_SUBSCRIBE_QUERY_TCP,
                     NULL, NSConsumerPresenceListener, NULL, NULL, type);
-
+#endif
             if (rType == NS_DISCOVER_CLOUD)
             {
                 callbackData = (void *) NS_DISCOVER_CLOUD;
index 01b3a25..33803fd 100644 (file)
@@ -32,8 +32,9 @@ extern "C" {
 
 void NSConsumerDiscoveryTaskProcessing(NSTask *);
 
+#ifdef WITH_PRESENCE
 OCStackApplicationResult NSConsumerPresenceListener(void *, OCDoHandle, OCClientResponse *);
-
+#endif
 // for discover result
 OCStackApplicationResult NSProviderDiscoverListener(void *, OCDoHandle, OCClientResponse *);
 
index d48d897..21881b1 100644 (file)
@@ -53,13 +53,14 @@ NSResult NSConsumerListenerInit()
 //    {
 //        return NS_ERROR;
 //    }
-
+    OCStackResult stackResult;
+#ifdef WITH_PRESENCE
     NS_LOG(DEBUG, "Request to subscribe presence");
-    OCStackResult stackResult = NSInvokeRequest(getPresenceHandle(), OC_REST_PRESENCE, NULL,
+    stackResult = NSInvokeRequest(getPresenceHandle(), OC_REST_PRESENCE, NULL,
                         NS_PRESENCE_SUBSCRIBE_QUERY, NULL, NSConsumerPresenceListener,
                         NULL, NULL, CT_DEFAULT);
     NS_VERIFY_STACK_SUCCESS(NSOCResultToSuccess(stackResult), NS_ERROR);
-
+#endif
     NS_LOG(DEBUG, "Request to discover provider");
     stackResult = NSInvokeRequest(NULL, OC_REST_DISCOVER, NULL,
                       NS_DISCOVER_QUERY, NULL, NSProviderDiscoverListener,
index 9452103..7dac222 100644 (file)
@@ -20,6 +20,7 @@
 \r
 #include "NSProviderDiscovery.h"\r
 \r
+#ifdef WITH_PRESENCE\r
 NSResult NSStartPresence()\r
 {\r
     NS_LOG(DEBUG, "NSStartPresence()");\r
@@ -47,6 +48,7 @@ NSResult NSStopPresence()
     NS_LOG(DEBUG, "NSStopPresence() NS_OK");\r
     return NS_OK;\r
 }\r
+#endif\r
 \r
 void * NSDiscoverySchedule(void * ptr)\r
 {\r
@@ -67,6 +69,7 @@ void * NSDiscoverySchedule(void * ptr)
 \r
             switch (node->taskType)\r
             {\r
+#ifdef WITH_PRESENCE\r
                 case TASK_START_PRESENCE:\r
                     NS_LOG(DEBUG, "CASE TASK_START_PRESENCE : ");\r
                     NSStartPresence();\r
@@ -75,6 +78,7 @@ void * NSDiscoverySchedule(void * ptr)
                     NS_LOG(DEBUG, "CASE TASK_STOP_PRESENCE : ");\r
                     NSStopPresence();\r
                     break;\r
+#endif\r
                 case TASK_REGISTER_RESOURCE:\r
                     NS_LOG(DEBUG, "CASE TASK_REGISTER_RESOURCE : ");\r
                     NSRegisterResource();\r
index c020ecb..1b1ffb0 100644 (file)
@@ -26,7 +26,9 @@
 #include "NSProviderScheduler.h"\r
 #include "NSProviderResource.h"\r
 \r
+#ifdef WITH_PRESENCE\r
 NSResult NSStartPresence();\r
 NSResult NSStopPresence();\r
+#endif\r
 \r
 #endif /* _NS_PROVIDER_DISCOVERY_H_ */\r
index 7ebdf3f..5c36b78 100644 (file)
@@ -158,9 +158,11 @@ namespace OIC
                 case OC_STACK_RESOURCE_DELETED:
                 case OC_STACK_TIMEOUT:
                 case OC_STACK_COMM_ERROR:
+#ifdef WITH_PRESENCE
                 case OC_STACK_PRESENCE_STOPPED:
                 case OC_STACK_PRESENCE_TIMEOUT:
                 case OC_STACK_PRESENCE_DO_NOT_HANDLE:
+#endif
                 {
                     setDeviceState(DEVICE_STATE::LOST_SIGNAL);
                     changeAllPresenceMode(BROKER_MODE::NON_PRESENCE_MODE);
index 9836438..a85e240 100644 (file)
@@ -288,8 +288,10 @@ namespace OIC
             case OC_STACK_INVALID_REQUEST_HANDLE:
             case OC_STACK_TIMEOUT:
             case OC_STACK_COMM_ERROR:
+#ifdef WITH_PRESENCE
             case OC_STACK_PRESENCE_STOPPED:
             case OC_STACK_PRESENCE_TIMEOUT:
+#endif
             default:
                 verifiedState = BROKER_STATE::LOST_SIGNAL;
                 break;
index 2703af7..c1b7a8f 100644 (file)
@@ -136,7 +136,9 @@ namespace OIC
                 case OC_STACK_OK:
                 case OC_STACK_RESOURCE_CREATED:
                 case OC_STACK_RESOURCE_DELETED:
+#ifdef WITH_PRESENCE
                 case OC_STACK_PRESENCE_STOPPED:
+#endif
                 case OC_STACK_CONTINUE:
                 case OC_STACK_RESOURCE_CHANGED:
                     return true;