From 127c4d9e2773e22cb3f4d6ffd8a568fa67312ec2 Mon Sep 17 00:00:00 2001 From: Amit KS Date: Mon, 5 Nov 2018 11:42:57 +0530 Subject: [PATCH] [CONPRO-1337] Disabled Presence Feature 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: I895cdc110bbec1c62d3e4bafbb70fabf329210f1 Signed-off-by: Amit KS Signed-off-by: DoHyun Pyun --- build_common/SConscript | 4 ++++ plugins/samples/linux/IotivityandZigbeeServer.c | 3 ++- resource/csdk/stack/include/octypes.h | 6 +----- resource/csdk/stack/src/ocserverrequest.c | 4 ++-- resource/examples/SConscript | 3 ++- resource/src/InProcClientWrapper.cpp | 10 ++++++++++ resource/src/InProcServerWrapper.cpp | 8 ++++++++ resource/unittests/OCExceptionTest.cpp | 2 ++ resource/unittests/OCRepresentationEncodingTest.cpp | 2 ++ service/notification/src/common/NSUtil.c | 2 ++ service/notification/src/consumer/NSConsumerDiscovery.c | 7 +++++-- service/notification/src/consumer/NSConsumerDiscovery.h | 3 ++- .../notification/src/consumer/NSConsumerNetworkEventListener.c | 7 ++++--- service/notification/src/provider/NSProviderDiscovery.c | 4 ++++ service/notification/src/provider/NSProviderDiscovery.h | 2 ++ .../src/resourceBroker/src/DevicePresence.cpp | 2 ++ .../src/resourceBroker/src/ResourcePresence.cpp | 2 ++ .../src/resourceCache/src/ObserveCache.cpp | 2 ++ 18 files changed, 58 insertions(+), 15 deletions(-) mode change 100755 => 100644 service/notification/src/common/NSUtil.c diff --git a/build_common/SConscript b/build_common/SConscript index 3d2404c..4a9a350 100644 --- a/build_common/SConscript +++ b/build_common/SConscript @@ -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') diff --git a/plugins/samples/linux/IotivityandZigbeeServer.c b/plugins/samples/linux/IotivityandZigbeeServer.c index 8caa729..74d987c 100644 --- a/plugins/samples/linux/IotivityandZigbeeServer.c +++ b/plugins/samples/linux/IotivityandZigbeeServer.c @@ -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..."); diff --git a/resource/csdk/stack/include/octypes.h b/resource/csdk/stack/include/octypes.h index 6afdb95..df6df44 100644 --- a/resource/csdk/stack/include/octypes.h +++ b/resource/csdk/stack/include/octypes.h @@ -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" diff --git a/resource/csdk/stack/src/ocserverrequest.c b/resource/csdk/stack/src/ocserverrequest.c index 325abb7..3dde884 100644 --- a/resource/csdk/stack/src/ocserverrequest.c +++ b/resource/csdk/stack/src/ocserverrequest.c @@ -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); diff --git a/resource/examples/SConscript b/resource/examples/SConscript index 4896179..b2ce91f 100644 --- a/resource/examples/SConscript +++ b/resource/examples/SConscript @@ -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) diff --git a/resource/src/InProcClientWrapper.cpp b/resource/src/InProcClientWrapper.cpp index ee47425..41bb8fa 100644 --- a/resource/src/InProcClientWrapper.cpp +++ b/resource/src/InProcClientWrapper.cpp @@ -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 diff --git a/resource/src/InProcServerWrapper.cpp b/resource/src/InProcServerWrapper.cpp index b4b799e..5989cf5 100644 --- a/resource/src/InProcServerWrapper.cpp +++ b/resource/src/InProcServerWrapper.cpp @@ -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( diff --git a/resource/unittests/OCExceptionTest.cpp b/resource/unittests/OCExceptionTest.cpp index 921b45f..d95d320 100644 --- a/resource/unittests/OCExceptionTest.cpp +++ b/resource/unittests/OCExceptionTest.cpp @@ -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, diff --git a/resource/unittests/OCRepresentationEncodingTest.cpp b/resource/unittests/OCRepresentationEncodingTest.cpp index ff0c657..83e74df 100644 --- a/resource/unittests/OCRepresentationEncodingTest.cpp +++ b/resource/unittests/OCRepresentationEncodingTest.cpp @@ -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) { diff --git a/service/notification/src/common/NSUtil.c b/service/notification/src/common/NSUtil.c old mode 100755 new mode 100644 index 8efb307..35c1e25 --- a/service/notification/src/common/NSUtil.c +++ b/service/notification/src/common/NSUtil.c @@ -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; diff --git a/service/notification/src/consumer/NSConsumerDiscovery.c b/service/notification/src/consumer/NSConsumerDiscovery.c index 28c137e..a408b6e 100644 --- a/service/notification/src/consumer/NSConsumerDiscovery.c +++ b/service/notification/src/consumer/NSConsumerDiscovery.c @@ -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; diff --git a/service/notification/src/consumer/NSConsumerDiscovery.h b/service/notification/src/consumer/NSConsumerDiscovery.h index 01b3a25..33803fd 100644 --- a/service/notification/src/consumer/NSConsumerDiscovery.h +++ b/service/notification/src/consumer/NSConsumerDiscovery.h @@ -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 *); diff --git a/service/notification/src/consumer/NSConsumerNetworkEventListener.c b/service/notification/src/consumer/NSConsumerNetworkEventListener.c index d48d897..21881b1 100644 --- a/service/notification/src/consumer/NSConsumerNetworkEventListener.c +++ b/service/notification/src/consumer/NSConsumerNetworkEventListener.c @@ -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, diff --git a/service/notification/src/provider/NSProviderDiscovery.c b/service/notification/src/provider/NSProviderDiscovery.c index 9452103..7dac222 100644 --- a/service/notification/src/provider/NSProviderDiscovery.c +++ b/service/notification/src/provider/NSProviderDiscovery.c @@ -20,6 +20,7 @@ #include "NSProviderDiscovery.h" +#ifdef WITH_PRESENCE NSResult NSStartPresence() { NS_LOG(DEBUG, "NSStartPresence()"); @@ -47,6 +48,7 @@ NSResult NSStopPresence() NS_LOG(DEBUG, "NSStopPresence() NS_OK"); return NS_OK; } +#endif void * NSDiscoverySchedule(void * ptr) { @@ -67,6 +69,7 @@ void * NSDiscoverySchedule(void * ptr) switch (node->taskType) { +#ifdef WITH_PRESENCE case TASK_START_PRESENCE: NS_LOG(DEBUG, "CASE TASK_START_PRESENCE : "); NSStartPresence(); @@ -75,6 +78,7 @@ void * NSDiscoverySchedule(void * ptr) NS_LOG(DEBUG, "CASE TASK_STOP_PRESENCE : "); NSStopPresence(); break; +#endif case TASK_REGISTER_RESOURCE: NS_LOG(DEBUG, "CASE TASK_REGISTER_RESOURCE : "); NSRegisterResource(); diff --git a/service/notification/src/provider/NSProviderDiscovery.h b/service/notification/src/provider/NSProviderDiscovery.h index c020ecb..1b1ffb0 100644 --- a/service/notification/src/provider/NSProviderDiscovery.h +++ b/service/notification/src/provider/NSProviderDiscovery.h @@ -26,7 +26,9 @@ #include "NSProviderScheduler.h" #include "NSProviderResource.h" +#ifdef WITH_PRESENCE NSResult NSStartPresence(); NSResult NSStopPresence(); +#endif #endif /* _NS_PROVIDER_DISCOVERY_H_ */ diff --git a/service/resource-encapsulation/src/resourceBroker/src/DevicePresence.cpp b/service/resource-encapsulation/src/resourceBroker/src/DevicePresence.cpp index 7ebdf3f..5c36b78 100644 --- a/service/resource-encapsulation/src/resourceBroker/src/DevicePresence.cpp +++ b/service/resource-encapsulation/src/resourceBroker/src/DevicePresence.cpp @@ -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); diff --git a/service/resource-encapsulation/src/resourceBroker/src/ResourcePresence.cpp b/service/resource-encapsulation/src/resourceBroker/src/ResourcePresence.cpp index 9836438..a85e240 100644 --- a/service/resource-encapsulation/src/resourceBroker/src/ResourcePresence.cpp +++ b/service/resource-encapsulation/src/resourceBroker/src/ResourcePresence.cpp @@ -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; diff --git a/service/resource-encapsulation/src/resourceCache/src/ObserveCache.cpp b/service/resource-encapsulation/src/resourceCache/src/ObserveCache.cpp index 2703af7..c1b7a8f 100644 --- a/service/resource-encapsulation/src/resourceCache/src/ObserveCache.cpp +++ b/service/resource-encapsulation/src/resourceCache/src/ObserveCache.cpp @@ -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; -- 2.7.4