From 88bbfc3785ac7b4991b645dad9f699d209a15435 Mon Sep 17 00:00:00 2001 From: KIM JungYong Date: Tue, 27 Sep 2016 22:55:35 +0900 Subject: [PATCH] Fix to apply Coding convention on services. Change-Id: I9bdb0e8147bcbbad6a28a6635cd7c4c3c16d9359 Signed-off-by: KIM JungYong Reviewed-on: https://gerrit.iotivity.org/gerrit/12345 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- .../bundle-api/include/BundleActivator.h | 10 ++- .../bundle-api/include/NotificationReceiver.h | 10 ++- .../bundle-api/include/ProtocolBridgeConnector.h | 10 ++- .../bundle-api/include/ProtocolBridgeResource.h | 10 ++- .../BMISensorBundle/src/BMISensorResource.cpp | 6 ++ .../examples/ContainerSample.cpp | 26 ++++++- .../examples/ContainerSampleClient.cpp | 4 + .../examples/HueSampleBundle/src/HueConnector.cpp | 2 + service/resource-container/include/RCSBundleInfo.h | 8 +- service/resource-container/src/BundleResource.cpp | 15 ++-- service/resource-container/src/Configuration.cpp | 39 +++++++--- .../src/DiscoverResourceUnit.cpp | 6 +- .../resource-container/src/DiscoverResourceUnit.h | 10 ++- .../resource-container/src/RemoteResourceUnit.cpp | 12 ++- .../src/ResourceContainerImpl.cpp | 64 ++++++++++++---- .../resource-container/src/SoftSensorResource.cpp | 2 + .../unittests/ResourceContainerTest.cpp | 41 +++++++---- .../unittests/ResourceContainerTestSimulator.h | 7 +- .../TestBundle/include/TestBundleActivator.h | 5 +- .../examples/linux/NestedAttributesClient.cpp | 2 + .../examples/linux/NestedAttributesServer.cpp | 15 +++- .../examples/linux/SampleResourceClient.cpp | 42 +++++++---- .../examples/linux/SampleResourceServer.cpp | 22 ++++-- .../examples/linux/SeparateResponseServer.cpp | 10 ++- .../expiryTimer/unittests/ExpiryTimerTest.cpp | 44 ++++++++--- .../unittests/PresenceSubscriberTest.cpp | 3 +- .../unittests/ResourceAttributesTest.cpp | 6 +- .../unittest/DeviceAssociationUnitTest.cpp | 5 +- .../unittest/DevicePresenceUnitTest.cpp | 14 +++- .../unittest/ResourceBrokerUnitTest.cpp | 16 +++- .../unittest/ResourcePresenceUnitTest.cpp | 49 ++++++++----- .../src/resourceCache/unittests/DataCacheTest.cpp | 11 ++- .../resourceCache/unittests/ResourceCacheTest.cpp | 11 ++- .../unittests/DiscoveryManagerTest.cpp | 13 +++- .../linux/sampleConsumer/SampleConsumer.cpp | 15 +++- service/resource-hosting/src/HostingObject.cpp | 13 +++- service/resource-hosting/src/RequestObject.cpp | 7 +- service/resource-hosting/src/ResourceHosting.cpp | 23 ++++-- .../linux/configuration/FactorySetCollection.cpp | 4 +- .../sampleapp/linux/configuration/con-client.cpp | 35 ++++++++- service/things-manager/sdk/src/ActionSet.cpp | 14 +++- service/things-manager/sdk/src/GroupManager.cpp | 25 ++++++- .../things-manager/sdk/src/ThingsConfiguration.cpp | 55 +++++++++++++- .../things-manager/sdk/src/ThingsMaintenance.cpp | 34 +++++++++ .../things-manager/unittests/ThingsManagerTest.cpp | 85 +++++++++++++++++----- 45 files changed, 684 insertions(+), 176 deletions(-) diff --git a/service/resource-container/bundle-api/include/BundleActivator.h b/service/resource-container/bundle-api/include/BundleActivator.h index 5a69fb1..d5bea5a 100644 --- a/service/resource-container/bundle-api/include/BundleActivator.h +++ b/service/resource-container/bundle-api/include/BundleActivator.h @@ -43,12 +43,18 @@ namespace OIC /** * Constructor for BundleActivator */ - BundleActivator() { }; + BundleActivator() + { + + }; /** * Virtual destructor for BundleActivator */ - virtual ~BundleActivator() { }; + virtual ~BundleActivator() + { + + }; /** * Activate the Bundle to make bundle work and create bundle resources diff --git a/service/resource-container/bundle-api/include/NotificationReceiver.h b/service/resource-container/bundle-api/include/NotificationReceiver.h index a1d25a1..1cd6357 100644 --- a/service/resource-container/bundle-api/include/NotificationReceiver.h +++ b/service/resource-container/bundle-api/include/NotificationReceiver.h @@ -41,12 +41,18 @@ namespace OIC /** * Constructor for NotificationReceiver */ - NotificationReceiver() {}; + NotificationReceiver() + { + + }; /** * destructor for NotificationReceiver */ - ~NotificationReceiver() {}; + ~NotificationReceiver() + { + + }; /** * Callback method for getting notification from bundle resources diff --git a/service/resource-container/bundle-api/include/ProtocolBridgeConnector.h b/service/resource-container/bundle-api/include/ProtocolBridgeConnector.h index a549d2e..5f9361c 100644 --- a/service/resource-container/bundle-api/include/ProtocolBridgeConnector.h +++ b/service/resource-container/bundle-api/include/ProtocolBridgeConnector.h @@ -43,12 +43,18 @@ namespace OIC /** * Constructor for ProtocolBridgeConnector */ - ProtocolBridgeConnector() { }; + ProtocolBridgeConnector() + { + + }; /** * Virtual destructor for ProtocolBridgeConnector */ - virtual ~ProtocolBridgeConnector() { }; + virtual ~ProtocolBridgeConnector() + { + + }; /** * Execute the logic needed for connection with different protocol from IoTivity diff --git a/service/resource-container/bundle-api/include/ProtocolBridgeResource.h b/service/resource-container/bundle-api/include/ProtocolBridgeResource.h index bc846e4..c020ca6 100644 --- a/service/resource-container/bundle-api/include/ProtocolBridgeResource.h +++ b/service/resource-container/bundle-api/include/ProtocolBridgeResource.h @@ -43,12 +43,18 @@ namespace OIC /** * Constructor for ProtocolBridgeResource */ - ProtocolBridgeResource() { }; + ProtocolBridgeResource() + { + + }; /** * Virtual destructor for ProtocolBridgeResource */ - virtual ~ProtocolBridgeResource() { }; + virtual ~ProtocolBridgeResource() + { + + }; /** * Initialize attributes of the resource diff --git a/service/resource-container/examples/BMISensorBundle/src/BMISensorResource.cpp b/service/resource-container/examples/BMISensorBundle/src/BMISensorResource.cpp index 2a527b5..968863d 100644 --- a/service/resource-container/examples/BMISensorBundle/src/BMISensorResource.cpp +++ b/service/resource-container/examples/BMISensorBundle/src/BMISensorResource.cpp @@ -51,7 +51,9 @@ void BMISensorResource::executeLogic() std::string strBMIResult; if (m_pBMISensor->executeBMISensorLogic(&m_mapInputData, &strBMIResult) != -1) + { setAttribute("BMIresult", RCSResourceAttributes::Value(strBMIResult.c_str())); + } } void BMISensorResource::onUpdatedInputResource(const std::string attributeName, @@ -61,10 +63,14 @@ void BMISensorResource::onUpdatedInputResource(const std::string attributeName, m_mapInputData.clear(); if (!attributeName.compare("weight")) + { m_mapInputData.insert(std::make_pair("weight", values.back().get< std::string >())); + } if (!attributeName.compare("height")) + { m_mapInputData.insert(std::make_pair("height", values.back().get< std::string >())); + } executeLogic(); } diff --git a/service/resource-container/examples/ContainerSample.cpp b/service/resource-container/examples/ContainerSample.cpp index 420119a..4d1c2df 100644 --- a/service/resource-container/examples/ContainerSample.cpp +++ b/service/resource-container/examples/ContainerSample.cpp @@ -46,7 +46,9 @@ namespace EXIT = 11 } APPMenu; - struct CloseApp {}; + struct CloseApp + { + }; const int MAX_PATH = 2048; @@ -69,7 +71,9 @@ void getCurrentPath(std::string *pPath) char buffer[MAX_PATH]; if (!pPath->empty()) + { pPath->clear(); + } #if defined(__linux__) char *strPath = NULL; @@ -81,7 +85,9 @@ void getCurrentPath(std::string *pPath) strPath = strrchr(buffer, '/'); if (strPath != NULL) + { *strPath = '\0'; + } } #endif pPath->append(buffer); @@ -94,7 +100,9 @@ int processUserInput(int min, int max) std::cin >> input; if (!std::cin.fail() && min <= input && input <= max) + { return input; + } std::cin.clear(); std::cin.ignore(std::numeric_limits::max(), '\n'); @@ -141,7 +149,9 @@ bool checkBundleRegistered(std::string bundleId) for (auto &bundle : bundleList) { if (bundle->getID().compare(bundleId) == 0) + { return true; + } } } @@ -160,7 +170,9 @@ bool checkResourceRegistered(std::string bundleId, std::string resourceUri) for (auto &resource : resourceList) { if (resource.compare(resourceUri) == 0) + { return true; + } } } @@ -237,7 +249,9 @@ void StopSampleBundle() g_bSampleBundleStarted = false; } else + { std::cout << "Sample Bundle is not started." << std::endl; + } } else { @@ -250,7 +264,9 @@ void RemoveSampleBundle() if (g_pResourceContainer && g_bContainerStarted) { if (checkBundleRegistered(EXAMPLE_BUNDLE_ID)) + { g_pResourceContainer->removeBundle(EXAMPLE_BUNDLE_ID); + } } else { @@ -273,7 +289,9 @@ void AddSampleBundleResource() resourceParams); } else + { std::cout << "Sample Bundle is not started." << std::endl; + } } else { @@ -287,9 +305,13 @@ void RemoveSampleBundleResource() { if (checkResourceRegistered(EXAMPLE_BUNDLE_ID, EXAMPLE_RESOURCE_URI) && g_bSampleBundleStarted) + { g_pResourceContainer->removeResourceConfig(EXAMPLE_BUNDLE_ID, EXAMPLE_RESOURCE_URI); + } else + { std::cout << "Sample Bundle is not started." << std::endl; + } } else { @@ -434,7 +456,9 @@ int main() } if (g_bContainerStarted) + { g_pResourceContainer->stopContainer(); + } g_pResourceContainer = nullptr; diff --git a/service/resource-container/examples/ContainerSampleClient.cpp b/service/resource-container/examples/ContainerSampleClient.cpp index 3a8bf4e..d4d2729 100644 --- a/service/resource-container/examples/ContainerSampleClient.cpp +++ b/service/resource-container/examples/ContainerSampleClient.cpp @@ -180,9 +180,13 @@ void onPost2(const HeaderOptions &headerOptions, const OCRepresentation &rep, co } if (OBSERVE_TYPE_TO_USE == ObserveType::Observe) + { std::cout << std::endl << "Observe is used." << std::endl << std::endl; + } else if (OBSERVE_TYPE_TO_USE == ObserveType::ObserveAll) + { std::cout << std::endl << "ObserveAll is used." << std::endl << std::endl; + } curResource->observe(OBSERVE_TYPE_TO_USE, QueryParamsMap(), &onObserve); diff --git a/service/resource-container/examples/HueSampleBundle/src/HueConnector.cpp b/service/resource-container/examples/HueSampleBundle/src/HueConnector.cpp index 5a5a956..de7121b 100644 --- a/service/resource-container/examples/HueSampleBundle/src/HueConnector.cpp +++ b/service/resource-container/examples/HueSampleBundle/src/HueConnector.cpp @@ -95,7 +95,9 @@ std::string HueConnector::transmit(std::string target, std::string payload) res = curl_easy_perform(curl); /* Check for errors */ if (res != CURLE_OK) + { fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); + } /* always cleanup */ curl_easy_cleanup(curl); diff --git a/service/resource-container/include/RCSBundleInfo.h b/service/resource-container/include/RCSBundleInfo.h index 3a11445..7f30b1c 100644 --- a/service/resource-container/include/RCSBundleInfo.h +++ b/service/resource-container/include/RCSBundleInfo.h @@ -90,8 +90,12 @@ namespace OIC */ virtual bool isActivated() = 0; - RCSBundleInfo(){}; - virtual ~RCSBundleInfo(){}; + RCSBundleInfo() + { + }; + virtual ~RCSBundleInfo() + { + }; protected: std::string m_ID, m_path, m_version; diff --git a/service/resource-container/src/BundleResource.cpp b/service/resource-container/src/BundleResource.cpp index f39e77c..a5aacfb 100644 --- a/service/resource-container/src/BundleResource.cpp +++ b/service/resource-container/src/BundleResource.cpp @@ -51,7 +51,8 @@ namespace OIC { std::list< std::string > ret; - for (auto &it : m_resourceAttributes){ + for (auto &it : m_resourceAttributes) + { ret.push_back(it.key()); } @@ -81,12 +82,14 @@ namespace OIC m_resourceAttributes[it.key()] = it.value(); } - if(notify){ + if(notify) + { // asynchronous notification auto notifyFunc = [](NotificationReceiver *notificationReceiver, std::string uri) { - if (notificationReceiver){ + if (notificationReceiver) + { notificationReceiver->onNotificationReceived(uri); } }; @@ -104,12 +107,14 @@ namespace OIC std::lock_guard lock(m_resourceAttributes_mutex); m_resourceAttributes[key] = std::move(value); - if(notify){ + if(notify) + { // asynchronous notification auto notifyFunc = [](NotificationReceiver *notificationReceiver, std::string uri) { - if (notificationReceiver){ + if (notificationReceiver) + { notificationReceiver->onNotificationReceived(uri); } }; diff --git a/service/resource-container/src/Configuration.cpp b/service/resource-container/src/Configuration.cpp index 7fcd077..fc5e1ae 100644 --- a/service/resource-container/src/Configuration.cpp +++ b/service/resource-container/src/Configuration.cpp @@ -152,7 +152,8 @@ namespace OIC { strBundleId = bundle->first_node(BUNDLE_ID)->value(); } - else{ + else + { strBundleId = ""; } @@ -161,19 +162,23 @@ namespace OIC bundleConfigMap.insert(std::make_pair(BUNDLE_ID, trim_both(strBundleId))); // - if (bundle->first_node(BUNDLE_PATH)){ + if (bundle->first_node(BUNDLE_PATH)) + { strPath = bundle->first_node(BUNDLE_PATH)->value(); } - else{ + else + { strPath = ""; } bundleConfigMap.insert(std::make_pair(BUNDLE_PATH, trim_both(strPath))); // - if (bundle->first_node(BUNDLE_VERSION)){ + if (bundle->first_node(BUNDLE_VERSION)) + { strVersion = bundle->first_node(BUNDLE_VERSION)->value(); } - else{ + else + { strVersion = ""; } bundleConfigMap.insert( @@ -195,7 +200,8 @@ namespace OIC } void Configuration::getResourceConfiguration(std::string bundleId, std::string resourceUri, - resourceInfo *resourceInfoOut){ + resourceInfo *resourceInfoOut) + { rapidxml::xml_node< char > *bundle; rapidxml::xml_node< char > *resource; rapidxml::xml_node< char > *item, *subItem, *subItem2; @@ -227,7 +233,8 @@ namespace OIC OIC_LOG_V(INFO, CONTAINER_TAG, "Inspecting"); // bundle = bundle->first_node(OUTPUT_RESOURCES_TAG); - if (bundle){ + if (bundle) + { for (resource = bundle->first_node(OUTPUT_RESOURCE_INFO); resource; resource = resource->next_sibling()) { @@ -254,10 +261,14 @@ namespace OIC } else if (!strKey.compare(OUTPUT_RESOURCE_ADDR)) + { resourceInfoOut->address = trim_both(strValue); + } else if (!strKey.compare(OUTPUT_RESOURCE_TYPE)) + { resourceInfoOut->resourceType = trim_both(strValue); + } else { @@ -307,7 +318,8 @@ namespace OIC OIC_LOG_V(ERROR, CONTAINER_TAG, "Exception (%s)", e.what()); } } - else{ + else + { OIC_LOG(INFO, CONTAINER_TAG, "config is not loaded yet !!"); } } @@ -360,16 +372,24 @@ namespace OIC strValue = item->value(); if (!strKey.compare(OUTPUT_RESOURCE_NAME)) + { tempResourceInfo.name = trim_both(strValue); + } else if (!strKey.compare(OUTPUT_RESOURCE_URI)) + { tempResourceInfo.uri = trim_both(strValue); + } else if (!strKey.compare(OUTPUT_RESOURCE_ADDR)) + { tempResourceInfo.address = trim_both(strValue); + } else if (!strKey.compare(OUTPUT_RESOURCE_TYPE)) + { tempResourceInfo.resourceType = trim_both(strValue); + } else { @@ -420,7 +440,8 @@ namespace OIC OIC_LOG_V(ERROR, CONTAINER_TAG, "Exception (%s)", e.what()); } } - else{ + else + { OIC_LOG(INFO, CONTAINER_TAG, "config is not loaded yet !!"); } } diff --git a/service/resource-container/src/DiscoverResourceUnit.cpp b/service/resource-container/src/DiscoverResourceUnit.cpp index 36c2bc6..3ffeb8f 100644 --- a/service/resource-container/src/DiscoverResourceUnit.cpp +++ b/service/resource-container/src/DiscoverResourceUnit.cpp @@ -89,7 +89,8 @@ void DiscoverResourceUnit::discoverdCB(RCSRemoteResourceObject::Ptr remoteObject if (remoteObject && !isAlreadyDiscoveredResource(remoteObject)) { OIC_LOG_V(DEBUG, DISCOVER_TAG, "Discovered - uri: %s", uri.c_str()); - if (uri.empty() || uri.compare(remoteObject->getUri()) == 0){ + if (uri.empty() || uri.compare(remoteObject->getUri()) == 0) + { RemoteResourceUnit::Ptr newDiscoveredResource = RemoteResourceUnit::createRemoteResourceInfo(remoteObject, pUpdatedCBFromServer); @@ -99,7 +100,8 @@ void DiscoverResourceUnit::discoverdCB(RCSRemoteResourceObject::Ptr remoteObject OIC_LOG_V(DEBUG, DISCOVER_TAG, "Created remote resource unit"); } - else{ + else + { OIC_LOG_V(DEBUG, DISCOVER_TAG, "URI is not matching - uri: %s", uri.c_str()); } } diff --git a/service/resource-container/src/DiscoverResourceUnit.h b/service/resource-container/src/DiscoverResourceUnit.h index 38a440b..00ad5be 100644 --- a/service/resource-container/src/DiscoverResourceUnit.h +++ b/service/resource-container/src/DiscoverResourceUnit.h @@ -44,9 +44,15 @@ namespace OIC struct DiscoverResourceInfo { DiscoverResourceInfo() - : resourceUri(), resourceType(), attributeName() {} + : resourceUri(), resourceType(), attributeName() + { + + } DiscoverResourceInfo(std::string uri, std::string type, std::string name) - : resourceUri(uri), resourceType(type), attributeName(name) {} + : resourceUri(uri), resourceType(type), attributeName(name) + { + + } std::string resourceUri; std::string resourceType; std::string attributeName; diff --git a/service/resource-container/src/RemoteResourceUnit.cpp b/service/resource-container/src/RemoteResourceUnit.cpp index 7a5bda3..6c785b6 100644 --- a/service/resource-container/src/RemoteResourceUnit.cpp +++ b/service/resource-container/src/RemoteResourceUnit.cpp @@ -39,19 +39,23 @@ RemoteResourceUnit::~RemoteResourceUnit() { if(remoteObject->isCaching()) { - try{ + try + { remoteObject->stopCaching(); } - catch(std::exception &e){ + catch(std::exception &e) + { OIC_LOG_V(ERROR, CONTAINER_TAG, "%s", e.what()); } } if(remoteObject->isMonitoring()) { - try{ + try + { remoteObject->stopMonitoring(); } - catch(std::exception &e){ + catch(std::exception &e) + { OIC_LOG_V(ERROR, CONTAINER_TAG, "%s", e.what()); } } diff --git a/service/resource-container/src/ResourceContainerImpl.cpp b/service/resource-container/src/ResourceContainerImpl.cpp index 93be5f9..e22692d 100644 --- a/service/resource-container/src/ResourceContainerImpl.cpp +++ b/service/resource-container/src/ResourceContainerImpl.cpp @@ -68,7 +68,8 @@ namespace OIC activationLock.lock(); - try{ + try + { if (!configFile.empty()) { m_config = new Configuration(configFile); @@ -111,7 +112,9 @@ namespace OIC } OIC_LOG(INFO, CONTAINER_TAG, "Resource container started."); - }catch(...){ + } + catch (...) + { OIC_LOG(INFO, CONTAINER_TAG, "Resource container failed starting."); } activationLock.unlock(); @@ -142,7 +145,9 @@ namespace OIC } if (m_config) + { delete m_config; + } } void ResourceContainerImpl::activateBundle(shared_ptr bundleInfo) @@ -175,10 +180,12 @@ namespace OIC std::string(m_bundles[id]->getID()).c_str()); activationLock.lock(); - try{ + try + { activateBundleThread(id); } - catch(...){ + catch (...) + { OIC_LOG_V(INFO, CONTAINER_TAG, "Activating bundle: (%s) failed", std::string(m_bundles[id]->getID()).c_str()); } @@ -222,14 +229,15 @@ namespace OIC registerExtBundle(bundleInfo); #endif } - else if(has_suffix(bundleInfo->getPath(), ".so")) + else if (has_suffix(bundleInfo->getPath(), ".so")) { bundleInfoInternal->setSoBundle(true); bundleInfoInternal->setJavaBundle(false); registerSoBundle(bundleInfo); } // other cases might be for example .apk for android, which are loaded in the wrapper - else{ + else + { bundleInfoInternal->setSoBundle(false); bundleInfoInternal->setJavaBundle(false); registerExtBundle(bundleInfo); @@ -246,7 +254,7 @@ namespace OIC { unregisterBundleSo(bundleInfo->getID()); } - else if(bundleInfoInternal->getJavaBundle()) + else if (bundleInfoInternal->getJavaBundle()) { #if(JAVA_SUPPORT) unregisterBundleJava(bundleInfo->getID()); @@ -290,7 +298,8 @@ namespace OIC registrationLock.lock(); if (m_mapResources.find(strUri) == m_mapResources.end()) { - if (strInterface.empty()) { + if (strInterface.empty()) + { strInterface = "oic.if.baseline"; } @@ -321,7 +330,8 @@ namespace OIC strResourceType).c_str()); discoverInputResource(strUri); } - else{ + else + { OIC_LOG_V(INFO, CONTAINER_TAG, "Resource has no input (%s)", std::string(strUri + ", " + strResourceType).c_str()); @@ -395,7 +405,8 @@ namespace OIC { m_config->getResourceConfiguration(bundleId, configOutput); } - else{ + else + { OIC_LOG_V(DEBUG, CONTAINER_TAG, "no config present "); } } @@ -499,7 +510,9 @@ namespace OIC if (m_bundles.find(bundleId) != m_bundles.end()) { if (!m_bundles[bundleId]->isActivated()) + { activateBundle(m_bundles[bundleId]); + } else { OIC_LOG(ERROR, CONTAINER_TAG, "Bundle already started"); @@ -518,7 +531,9 @@ namespace OIC if (m_bundles.find(bundleId) != m_bundles.end()) { if (m_bundles[bundleId]->isActivated()) + { deactivateBundle(m_bundles[bundleId]); + } else { OIC_LOG(ERROR, CONTAINER_TAG, "Bundle not activated"); @@ -540,7 +555,9 @@ namespace OIC (void) bundleUri; if (m_bundles.find(bundleId) != m_bundles.end()) + { OIC_LOG(ERROR, CONTAINER_TAG, "BundleId already exist"); + } else { @@ -571,10 +588,14 @@ namespace OIC { shared_ptr bundleInfo = m_bundles[bundleId]; if (bundleInfo->isActivated()) + { deactivateBundle(bundleInfo); + } if (bundleInfo->isLoaded()) + { unregisterBundle(bundleInfo); + } } else { @@ -611,11 +632,17 @@ namespace OIC newResourceInfo.uri = resourceUri; if (params.find(OUTPUT_RESOURCE_NAME) != params.end()) + { newResourceInfo.name = params[OUTPUT_RESOURCE_NAME]; + } if (params.find(OUTPUT_RESOURCE_TYPE) != params.end()) + { newResourceInfo.resourceType = params[OUTPUT_RESOURCE_TYPE]; + } if (params.find(OUTPUT_RESOURCE_ADDR) != params.end()) + { newResourceInfo.address = params[OUTPUT_RESOURCE_ADDR]; + } addSoBundleResource(bundleId, newResourceInfo); } @@ -691,7 +718,8 @@ namespace OIC { OIC_LOG_V(ERROR, CONTAINER_TAG, "Error while loading .so bundle: (%s)", error); } - else{ + else + { OIC_LOG_V(DEBUG, CONTAINER_TAG, "Looked up %s", ("" + bundleInfoInternal->getActivatorName() + "_externalActivateBundle").c_str()); @@ -704,7 +732,8 @@ namespace OIC { OIC_LOG_V(ERROR, CONTAINER_TAG, "Error while loading .so bundle: (%s)", error); } - else{ + else + { OIC_LOG_V(DEBUG, CONTAINER_TAG, "Looked up %s", ("" + bundleInfoInternal->getActivatorName() + "_externalDeactivateBundle").c_str()); @@ -717,7 +746,8 @@ namespace OIC { OIC_LOG_V(ERROR, CONTAINER_TAG, "Error while loading .so bundle: (%s)", error); } - else{ + else + { OIC_LOG_V(DEBUG, CONTAINER_TAG, "Looked up %s", ("" + bundleInfoInternal->getActivatorName() + "_externalCreateResource").c_str()); @@ -730,7 +760,8 @@ namespace OIC { OIC_LOG_V(ERROR, CONTAINER_TAG, "Error while loading .so bundle: (%s)", error); } - else{ + else + { OIC_LOG_V(DEBUG, CONTAINER_TAG, "Looked up %s", ("" + bundleInfoInternal->getActivatorName() + "_externalDestroyResource").c_str()); @@ -763,7 +794,8 @@ namespace OIC OIC_LOG_V(DEBUG, CONTAINER_TAG, "Register SO bundle finished"); } - void ResourceContainerImpl::registerExtBundle(shared_ptr bundleInfo){ + void ResourceContainerImpl::registerExtBundle(shared_ptr bundleInfo) + { OIC_LOG_V(INFO, CONTAINER_TAG, "Registering ext bundle (%s)", std::string(bundleInfo->getID()).c_str()); OIC_LOG_V(INFO, CONTAINER_TAG, "Activator name (%s)", @@ -955,7 +987,7 @@ namespace OIC activateJavaBundle(id); #endif } - else if(m_bundles[id]->getSoBundle()) + else if (m_bundles[id]->getSoBundle()) { activateSoBundle (id); } diff --git a/service/resource-container/src/SoftSensorResource.cpp b/service/resource-container/src/SoftSensorResource.cpp index 753dd69..e289a74 100644 --- a/service/resource-container/src/SoftSensorResource.cpp +++ b/service/resource-container/src/SoftSensorResource.cpp @@ -50,7 +50,9 @@ namespace OIC // initialize output attributes for (itor = m_mapResourceProperty[SS_RESOURCE_OUTPUT].begin(); itor != m_mapResourceProperty[SS_RESOURCE_OUTPUT].end(); itor++) + { BundleResource::setAttribute((*itor)[SS_RESOURCE_OUTPUTNAME], nullptr); + } } } } diff --git a/service/resource-container/unittests/ResourceContainerTest.cpp b/service/resource-container/unittests/ResourceContainerTest.cpp index 6739f82..94415c3 100644 --- a/service/resource-container/unittests/ResourceContainerTest.cpp +++ b/service/resource-container/unittests/ResourceContainerTest.cpp @@ -69,7 +69,9 @@ void getCurrentPath(std::string *pPath) strPath = strrchr(buffer, '/'); if (strPath != NULL) + { *strPath = '\0'; + } } #endif pPath->append(buffer); @@ -98,7 +100,9 @@ dynamic_unique_ptr_cast( std::unique_ptr&& p ) class TestBundleResource: public BundleResource { public: - virtual void initAttributes() { } + virtual void initAttributes() + { + } virtual void handleSetAttributesRequest(const RCSResourceAttributes &attr, const std::map< std::string, std::string > &queryParams) @@ -119,7 +123,8 @@ class TestBundleResource: public BundleResource class TestBundleResourceWithAttrs: public BundleResource { public: - virtual void initAttributes() { + virtual void initAttributes() + { setAttribute("attrib1", RCSResourceAttributes::Value("test")); setAttribute("attrib2", RCSResourceAttributes::Value(1)); setAttribute("attrib3", RCSResourceAttributes::Value(true)); @@ -145,7 +150,8 @@ class TestBundleResourceWithAttrs: public BundleResource class TestSoftSensorResource: public SoftSensorResource { public: - virtual void initAttributes() { + virtual void initAttributes() + { SoftSensorResource::initAttributes(); } @@ -163,13 +169,13 @@ class TestSoftSensorResource: public SoftSensorResource return BundleResource::getAttributes(); } - virtual void executeLogic(){ - + virtual void executeLogic() + { } virtual void onUpdatedInputResource( - std::string, std::vector){ - + std::string, std::vector) + { } }; @@ -445,7 +451,8 @@ TEST_F(ResourceContainerBundleAPITest, RequestHandlerForResourceServerSetWhenReg { mocks.OnCallFunc(ResourceContainerImpl::buildResourceObject).Return( RCSResourceObject::Ptr(m_pResourceObject, [](RCSResourceObject *) - {})); + { + })); mocks.ExpectCall(m_pResourceObject, RCSResourceObject::setGetRequestHandler); mocks.ExpectCall(m_pResourceObject, RCSResourceObject::setSetRequestHandler); @@ -459,7 +466,8 @@ TEST_F(ResourceContainerBundleAPITest, BundleResourceUnregisteredWhenUnregisterR { mocks.OnCallFunc(ResourceContainerImpl::buildResourceObject).Return( RCSResourceObject::Ptr(m_pResourceObject, [](RCSResourceObject *) - {})); + { + })); mocks.ExpectCall(m_pResourceObject, RCSResourceObject::setGetRequestHandler); mocks.ExpectCall(m_pResourceObject, RCSResourceObject::setSetRequestHandler); @@ -477,7 +485,8 @@ TEST_F(ResourceContainerBundleAPITest, { mocks.OnCallFunc(ResourceContainerImpl::buildResourceObject).Return( RCSResourceObject::Ptr(m_pResourceObject, [](RCSResourceObject *) - {})); + { + })); mocks.ExpectCall(m_pResourceObject, RCSResourceObject::setGetRequestHandler); mocks.ExpectCall(m_pResourceObject, RCSResourceObject::setSetRequestHandler); @@ -694,7 +703,9 @@ class DiscoverResourceUnitTest: public TestWithMock testObject->createResource(); m_bundleId = "/a/TempHumSensor/Container"; m_pDiscoverResourceUnit = std::make_shared< DiscoverResourceUnit >( m_bundleId ); - m_updatedCB = ([](const std::string, std::vector< RCSResourceAttributes::Value >) { }); + m_updatedCB = ([](const std::string, std::vector< RCSResourceAttributes::Value >) + { + }); } void TearDown() @@ -733,7 +744,9 @@ TEST_F(DiscoverResourceUnitTest, onUpdateCalled) namespace { - void onCacheCB(const RCSResourceAttributes &) { } + void onCacheCB(const RCSResourceAttributes &) + { + } } class RemoteResourceUnitTest: public TestWithMock @@ -755,7 +768,9 @@ class RemoteResourceUnitTest: public TestWithMock testObject = std::make_shared(); testObject->defaultRunSimulator(); m_pRCSRemoteResourceObject = testObject->getRemoteResource(); - m_updatedCBFromServer = ([](RemoteResourceUnit::UPDATE_MSG, RCSRemoteResourceObject::Ptr) {}); + m_updatedCBFromServer = ([](RemoteResourceUnit::UPDATE_MSG, RCSRemoteResourceObject::Ptr) + { + }); } void TearDown() diff --git a/service/resource-container/unittests/ResourceContainerTestSimulator.h b/service/resource-container/unittests/ResourceContainerTestSimulator.h index 5d6ccd0..03a0bc7 100644 --- a/service/resource-container/unittests/ResourceContainerTestSimulator.h +++ b/service/resource-container/unittests/ResourceContainerTestSimulator.h @@ -64,7 +64,8 @@ class ResourceContainerTestSimulator RESOURCEINTERFACE("oic.if.baseline"), ATTR_KEY("TestResourceContainer"), ATTR_VALUE(0) - { } + { + } ~ResourceContainerTestSimulator() { @@ -184,7 +185,9 @@ class ResourceContainerTestSimulator { std::chrono::milliseconds interval(DEFAULT_WAITTIME); if (server != nullptr) + { server->setAttribute(ATTR_KEY, ATTR_VALUE + 10); + } std::this_thread::sleep_for(interval); } @@ -192,7 +195,9 @@ class ResourceContainerTestSimulator { std::chrono::milliseconds interval(DEFAULT_WAITTIME); if (server != nullptr) + { server = nullptr; + } std::this_thread::sleep_for(interval); } diff --git a/service/resource-container/unittests/TestBundle/include/TestBundleActivator.h b/service/resource-container/unittests/TestBundle/include/TestBundleActivator.h index 6657014..4490884 100644 --- a/service/resource-container/unittests/TestBundle/include/TestBundleActivator.h +++ b/service/resource-container/unittests/TestBundle/include/TestBundleActivator.h @@ -50,7 +50,10 @@ class TestBundleActivator : public BundleActivator class TestBundleResource : public BundleResource { public: - void initAttributes() { }; + void initAttributes() + { + + }; RCSResourceAttributes handleGetAttributesRequest( const std::map< std::string, std::string > &queryParams) diff --git a/service/resource-encapsulation/examples/linux/NestedAttributesClient.cpp b/service/resource-encapsulation/examples/linux/NestedAttributesClient.cpp index 5c764f7..8188e01 100644 --- a/service/resource-encapsulation/examples/linux/NestedAttributesClient.cpp +++ b/service/resource-encapsulation/examples/linux/NestedAttributesClient.cpp @@ -238,7 +238,9 @@ void process() displayMenu(); if (selectClientMenu(processUserInput()) == QUIT_INPUT) + { break; + } } } diff --git a/service/resource-encapsulation/examples/linux/NestedAttributesServer.cpp b/service/resource-encapsulation/examples/linux/NestedAttributesServer.cpp index fc579e7..770304b 100644 --- a/service/resource-encapsulation/examples/linux/NestedAttributesServer.cpp +++ b/service/resource-encapsulation/examples/linux/NestedAttributesServer.cpp @@ -293,15 +293,24 @@ void process() int ret = selectServerMenu(); - if (ret == QUIT) return; - if (ret == CORRECT_INPUT) break; + if (ret == QUIT) + { + return; + } + if (ret == CORRECT_INPUT) + { + break; + } } while (true) { displayControlMenu(); - if (selectControlMenu() == QUIT) return; + if (selectControlMenu() == QUIT) + { + return; + } } } diff --git a/service/resource-encapsulation/examples/linux/SampleResourceClient.cpp b/service/resource-encapsulation/examples/linux/SampleResourceClient.cpp index 1d15dc8..cf0ff40 100644 --- a/service/resource-encapsulation/examples/linux/SampleResourceClient.cpp +++ b/service/resource-encapsulation/examples/linux/SampleResourceClient.cpp @@ -92,7 +92,10 @@ int processUserInput(int min = std::numeric_limits::min(), std::cin >> input; std::cin.ignore(std::numeric_limits::max(), '\n'); - if (!std::cin.fail() && min <= input && input <= max) return input; + if (!std::cin.fail() && min <= input && input <= max) + { + return input; + } std::cin.clear(); std::cin.ignore(std::numeric_limits::max(), '\n'); @@ -115,7 +118,7 @@ void displayItems(const std::vector& items) const auto width = (items.size() + 1) / 10 + 1; - for(size_t i = 0; i < items.size(); ++i) + for (size_t i = 0; i < items.size(); ++i) { displayItem(width, i + 1, items[i]); } @@ -127,7 +130,10 @@ void selectItem(const std::vector& items) { int selected = processUserInput(1, items.size() + 1) - 1; - if(selected == static_cast(items.size())) throw CloseApp(); + if (selected == static_cast(items.size())) + { + throw CloseApp(); + } onSelected(items[selected]); } @@ -176,7 +182,7 @@ void printAttributes(const RCSResourceAttributes& attributes) std::cout << "\tattributes is empty" << std::endl; } - for(const auto& attr : attributes) + for (const auto& attr : attributes) { printAttribute(attr.key(), attr.value()); } @@ -191,7 +197,7 @@ void print(const std::string& name, const std::vector< std::string >& elements) } std::cout << "\t" << name << " : " << std::endl; - for(const auto& item : elements) + for (const auto& item : elements) { std::cout << item << " "; } @@ -200,7 +206,7 @@ void print(const std::string& name, const std::vector< std::string >& elements) void printUri(const std::string& uri) { - if(uri.empty()) + if (uri.empty()) { std::cout << "\turi is empty" << std::endl; } @@ -219,14 +225,14 @@ void printRepresentation(const RCSRepresentation& rep) const auto& children = rep.getChildren(); - if(children.empty()) + if (children.empty()) { std::cout << "\tchildren is empty" << std::endl; } else { int cnt = 0; - for(const auto& child : children) + for (const auto& child : children) { std::cout << "========================================================" << std::endl; std::cout << ++cnt << " chlid" << std::endl; @@ -240,7 +246,7 @@ void onResourceStateChanged(ResourceState resourceState) { std::cout << "onResourceStateChanged callback" << std::endl; - switch(resourceState) + switch (resourceState) { case ResourceState::NONE: std::cout << "\tState changed to : NOT_MONITORING" << std::endl; @@ -398,7 +404,7 @@ void getCachedAttribute() void stopCaching() { - if(!g_selectedResource->isCaching()) + if (!g_selectedResource->isCaching()) { std::cout << "\tCaching not started..." << std::endl; return; @@ -418,12 +424,16 @@ std::string selectResourceType() switch (processUserInput(RESOURCE_TEMP, RESOURCE_LIGHT)) { case RESOURCE_TEMP: + { g_attrKey = "Temperature"; return RESOURCE_TYPE_TEMP; + } case RESOURCE_LIGHT: + { g_attrKey = "Brightness"; return RESOURCE_TYPE_LIGHT; } + } throw std::logic_error("unreachable"); } @@ -436,7 +446,10 @@ RCSAddress inputAddress() std::string address; - if(std::cin.peek() != '\n') std::cin >> address; + if (std::cin.peek() != '\n') + { + std::cin >> address; + } return address.empty() ? RCSAddress::multicast() : RCSAddress::unicast(address); } @@ -469,7 +482,7 @@ void discoverResource() auto discoveryTask = RCSDiscoveryManager::getInstance()->discoverResourceByType(address, resourceType, onResourceDiscovered); - while(processUserInput() != 1); + while (processUserInput() != 1); discoveryTask->cancel(); } @@ -509,7 +522,10 @@ void runDiscovery() handleItems(discoveryMenuItems); - if (g_discoveredResources.empty()) throw std::runtime_error("No resource found!"); + if (g_discoveredResources.empty()) + { + throw std::runtime_error("No resource found!"); + } g_currentRun = runResourceSelection; } diff --git a/service/resource-encapsulation/examples/linux/SampleResourceServer.cpp b/service/resource-encapsulation/examples/linux/SampleResourceServer.cpp index 3c03da3..2c95ee9 100644 --- a/service/resource-encapsulation/examples/linux/SampleResourceServer.cpp +++ b/service/resource-encapsulation/examples/linux/SampleResourceServer.cpp @@ -59,8 +59,14 @@ int processUserInput(int min, int max) if (!std::cin.fail()) { - if(input == max + 1) throw CloseApp(); - if(min <= input && input <= max) return input; + if (input == max + 1) + { + throw CloseApp(); + } + if (min <= input && input <= max) + { + return input; + } } std::cin.clear(); @@ -89,7 +95,7 @@ void displayControlLightMenu() void printAttributes(const RCSResourceAttributes& attrs) { - for(const auto& attr : attrs) + for (const auto& attr : attrs) { std::cout << "\tkey : " << attr.key() << "\n\tvalue : " << attr.value().toString() << std::endl; @@ -144,7 +150,7 @@ void updateAttribute(const std::string& attrKey, int control) attrs[attrKey] = attrs[attrKey].get() + diff; } - if(control == INCREASE) + if (control == INCREASE) { std::cout << attrKey << " increased." << std::endl; } @@ -237,17 +243,17 @@ int main(void) { g_currentRun = runPresenceSelection; - while(true) + while (true) { try { g_currentRun(); } - catch(const std::exception& e) + catch (const std::exception& e) { std::cout << e.what() << std::endl; } - catch(const CloseApp&) + catch (const CloseApp&) { break; } @@ -256,7 +262,7 @@ int main(void) g_resource.reset(); - if(g_isPresenceStarted) + if (g_isPresenceStarted) { stopPresence(); } diff --git a/service/resource-encapsulation/examples/linux/SeparateResponseServer.cpp b/service/resource-encapsulation/examples/linux/SeparateResponseServer.cpp index 9edf591..f01d1e8 100755 --- a/service/resource-encapsulation/examples/linux/SeparateResponseServer.cpp +++ b/service/resource-encapsulation/examples/linux/SeparateResponseServer.cpp @@ -45,7 +45,10 @@ void handleRequestWithDelay(int delayInMillis, const RCSRequest& request, auto& resAttrs = resObject->getAttributes(); for (const auto& kv : requestedAttrs) { - if (resAttrs.contains(kv.key())) resAttrs[kv.key()] = kv.value(); + if (resAttrs.contains(kv.key())) + { + resAttrs[kv.key()] = kv.value(); + } } } @@ -75,7 +78,10 @@ int processUserInput(int min, int max) if (!std::cin.fail()) { - if(min <= input && input <= max) return input; + if(min <= input && input <= max) + { + return input; + } } std::cin.clear(); diff --git a/service/resource-encapsulation/src/common/expiryTimer/unittests/ExpiryTimerTest.cpp b/service/resource-encapsulation/src/common/expiryTimer/unittests/ExpiryTimerTest.cpp index bf96c77..c91597b 100644 --- a/service/resource-encapsulation/src/common/expiryTimer/unittests/ExpiryTimerTest.cpp +++ b/service/resource-encapsulation/src/common/expiryTimer/unittests/ExpiryTimerTest.cpp @@ -34,9 +34,15 @@ constexpr int TOLERANCE_IN_MILLIS{ 50 }; class FunctionObject { public: - virtual ~FunctionObject() { } + virtual ~FunctionObject() + { + + } - virtual void execute(ExpiryTimerImpl::Id) { } + virtual void execute(ExpiryTimerImpl::Id) + { + + } }; class ExpiryTimerImplTest: public TestWithMock @@ -61,7 +67,10 @@ private: TEST_F(ExpiryTimerImplTest, PostThrowsIfDelayIsNegative) { - ASSERT_THROW(ExpiryTimerImpl::getInstance()->post(-1, [](ExpiryTimerImpl::Id){}), RCSException); + ASSERT_THROW(ExpiryTimerImpl::getInstance()->post(-1, + [](ExpiryTimerImpl::Id) + { + }), RCSException); } TEST_F(ExpiryTimerImplTest, PostThrowsIfCallbackIsEmpty) @@ -74,7 +83,8 @@ TEST_F(ExpiryTimerImplTest, CallbackBeInvokedWithinTolerance) FunctionObject* functor = mocks.Mock< FunctionObject >(); mocks.ExpectCall(functor, FunctionObject::execute).Do( - [this](ExpiryTimerImpl::Id){ + [this](ExpiryTimerImpl::Id) + { Proceed(); } ); @@ -91,11 +101,13 @@ TEST_F(ExpiryTimerImplTest, CallbackBeInvokedWithTimerId) FunctionObject* functor = mocks.Mock< FunctionObject >(); mocks.ExpectCall(functor, FunctionObject::execute).Match( - [this, &returnedId](ExpiryTimerImpl::Id id){ + [this, &returnedId](ExpiryTimerImpl::Id id) + { return returnedId == id; } ).Do( - [this](ExpiryTimerImpl::Id){ + [this](ExpiryTimerImpl::Id) + { Proceed(); } ); @@ -133,7 +145,8 @@ TEST_F(ExpiryTimerImplTest, CancelReturnsFalseIfAlreadyExecuted) FunctionObject* functor = mocks.Mock< FunctionObject >(); mocks.ExpectCall(functor, FunctionObject::execute).Do( - [this](ExpiryTimerImpl::Id){ + [this](ExpiryTimerImpl::Id) + { Proceed(); } ); @@ -193,7 +206,10 @@ private: TEST_F(ExpiryTimerTest, PostThrowsIfDelayIsNegative) { - ASSERT_THROW(timer.post(-1, [](ExpiryTimer::Id){}), RCSException); + ASSERT_THROW(timer.post(-1, + [](ExpiryTimer::Id) + { + }), RCSException); } TEST_F(ExpiryTimerTest, PostThrowsIfCallbackIsEmpty) @@ -206,7 +222,8 @@ TEST_F(ExpiryTimerTest, CallbackBeInvokedWithinTolerance) FunctionObject* functor = mocks.Mock< FunctionObject >(); mocks.ExpectCall(functor, FunctionObject::execute).Do( - [this](ExpiryTimer::Id){ + [this](ExpiryTimer::Id) + { Proceed(); } ); @@ -223,11 +240,13 @@ TEST_F(ExpiryTimerTest, CallbackBeInvokedWithTimerId) FunctionObject* functor = mocks.Mock< FunctionObject >(); mocks.ExpectCall(functor, FunctionObject::execute).Match( - [this, &returnedId](ExpiryTimer::Id id){ + [this, &returnedId](ExpiryTimer::Id id) + { return returnedId == id; } ).Do( - [this](ExpiryTimer::Id){ + [this](ExpiryTimer::Id) + { Proceed(); } ); @@ -262,7 +281,8 @@ TEST_F(ExpiryTimerTest, CancelReturnsFalseIfAlreadyExecuted) FunctionObject* functor = mocks.Mock< FunctionObject >(); mocks.ExpectCall(functor, FunctionObject::execute).Do( - [this](ExpiryTimer::Id){ + [this](ExpiryTimer::Id) + { Proceed(); } ); diff --git a/service/resource-encapsulation/src/common/primitiveResource/unittests/PresenceSubscriberTest.cpp b/service/resource-encapsulation/src/common/primitiveResource/unittests/PresenceSubscriberTest.cpp index 191e8ec..5d12ad6 100644 --- a/service/resource-encapsulation/src/common/primitiveResource/unittests/PresenceSubscriberTest.cpp +++ b/service/resource-encapsulation/src/common/primitiveResource/unittests/PresenceSubscriberTest.cpp @@ -77,7 +77,8 @@ TEST_F(PresenceSubscriberNonMemberTest, UnsubscribePresenceThrowIfResultIsNotOK) class PresenceSubscriberTest: public TestWithMock { protected: - void SetUp() { + void SetUp() + { mocks.OnCallFuncOverload( static_cast< SubscribePresence1 >(OC::OCPlatform::subscribePresence)).Do( diff --git a/service/resource-encapsulation/src/common/primitiveResource/unittests/ResourceAttributesTest.cpp b/service/resource-encapsulation/src/common/primitiveResource/unittests/ResourceAttributesTest.cpp index acb8732..ec1fde4 100644 --- a/service/resource-encapsulation/src/common/primitiveResource/unittests/ResourceAttributesTest.cpp +++ b/service/resource-encapsulation/src/common/primitiveResource/unittests/ResourceAttributesTest.cpp @@ -165,7 +165,8 @@ TEST_F(ResourceAttributesIteratorTest, CanIteratesWithForeach) int count = 0; - for (auto& i : resourceAttributes) { + for (auto& i : resourceAttributes) + { i.key(); ++count; } @@ -178,7 +179,8 @@ TEST_F(ResourceAttributesIteratorTest, IteratesWithRef) const char arbitraryStr[] { "ftryb457" }; resourceAttributes[KEY] = 1; - for (auto& i : resourceAttributes) { + for (auto& i : resourceAttributes) + { i.value() = arbitraryStr; } diff --git a/service/resource-encapsulation/src/resourceBroker/unittest/DeviceAssociationUnitTest.cpp b/service/resource-encapsulation/src/resourceBroker/unittest/DeviceAssociationUnitTest.cpp index ed6225c..524445d 100644 --- a/service/resource-encapsulation/src/resourceBroker/unittest/DeviceAssociationUnitTest.cpp +++ b/service/resource-encapsulation/src/resourceBroker/unittest/DeviceAssociationUnitTest.cpp @@ -69,7 +69,10 @@ protected: TestWithMock::SetUp(); instance = DeviceAssociation::getInstance(); device = (DevicePresencePtr)new DevicePresence(); - pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource*){}); + pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), + [](PrimitiveResource*) + { + }); } void TearDown() diff --git a/service/resource-encapsulation/src/resourceBroker/unittest/DevicePresenceUnitTest.cpp b/service/resource-encapsulation/src/resourceBroker/unittest/DevicePresenceUnitTest.cpp index e773f15..65646fe 100644 --- a/service/resource-encapsulation/src/resourceBroker/unittest/DevicePresenceUnitTest.cpp +++ b/service/resource-encapsulation/src/resourceBroker/unittest/DevicePresenceUnitTest.cpp @@ -52,8 +52,15 @@ protected: { TestWithMock::SetUp(); instance = (DevicePresence*)new DevicePresence(); - pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource*){}); - cb = ([](BROKER_STATE)->OCStackResult{return OC_STACK_OK;}); + pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), + [](PrimitiveResource*) + { + + }); + cb = ([](BROKER_STATE)->OCStackResult + { + return OC_STACK_OK; + }); id = 0; } @@ -85,7 +92,8 @@ TEST_F(DevicePresenceTest,SubscribeCB_NormalHandlingIfMessageOC_STACK_OK) mocks.OnCall(pResource.get(), PrimitiveResource::getHost).Return(std::string()); mocks.OnCallFuncOverload(static_cast< subscribePresenceSig1 >(OC::OCPlatform::subscribePresence)).Do( [](OC::OCPlatform::OCPresenceHandle&, - const std::string&, OCConnectivityType, SubscribeCallback callback)->OCStackResult{ + const std::string&, OCConnectivityType, SubscribeCallback callback)->OCStackResult + { callback(OC_STACK_OK,0,std::string()); return OC_STACK_OK; diff --git a/service/resource-encapsulation/src/resourceBroker/unittest/ResourceBrokerUnitTest.cpp b/service/resource-encapsulation/src/resourceBroker/unittest/ResourceBrokerUnitTest.cpp index 2cddd25..478f716 100644 --- a/service/resource-encapsulation/src/resourceBroker/unittest/ResourceBrokerUnitTest.cpp +++ b/service/resource-encapsulation/src/resourceBroker/unittest/ResourceBrokerUnitTest.cpp @@ -48,8 +48,15 @@ protected: { TestWithMock::SetUp(); brokerInstance = ResourceBroker::getInstance(); - pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource*){}); - cb = ([](BROKER_STATE)->OCStackResult{return OC_STACK_OK;}); + pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), + [](PrimitiveResource*) + { + + }); + cb = ([](BROKER_STATE)->OCStackResult + { + return OC_STACK_OK; + }); id = 0; } @@ -179,7 +186,10 @@ TEST_F(ResourceBrokerTest,getResourceState_NormalErrorHandlingIfAbnormalResource for(int i=0;i!=3;i++) { - resource[i] = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource*){}); + resource[i] = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), + [](PrimitiveResource*) + { + }); mocks.OnCall(resource[i].get(), PrimitiveResource::requestGet); mocks.OnCall(resource[i].get(), PrimitiveResource::getHost).Return(std::string()); mocks.OnCallFuncOverload(static_cast< subscribePresenceSig1 >(OC::OCPlatform::subscribePresence)).Return(OC_STACK_OK); diff --git a/service/resource-encapsulation/src/resourceBroker/unittest/ResourcePresenceUnitTest.cpp b/service/resource-encapsulation/src/resourceBroker/unittest/ResourcePresenceUnitTest.cpp index 31ca22e..d87d186 100644 --- a/service/resource-encapsulation/src/resourceBroker/unittest/ResourcePresenceUnitTest.cpp +++ b/service/resource-encapsulation/src/resourceBroker/unittest/ResourcePresenceUnitTest.cpp @@ -59,8 +59,15 @@ protected: { TestWithMock::SetUp(); instance.reset(new ResourcePresence()); - pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource*){}); - cb = ([](BROKER_STATE)->OCStackResult{return OC_STACK_OK;}); + pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), + [](PrimitiveResource*) + { + + }); + cb = ([](BROKER_STATE)->OCStackResult + { + return OC_STACK_OK; + }); id = 0; } @@ -75,7 +82,11 @@ protected: void MockingFunc() { - mocks.OnCall(pResource.get(), PrimitiveResource::requestGet).Do([](GetCallback){}); + mocks.OnCall(pResource.get(), PrimitiveResource::requestGet).Do( + [](GetCallback) + { + + }); mocks.OnCall(pResource.get(), PrimitiveResource::getHost).Return(std::string()); mocks.OnCallFuncOverload(static_cast< subscribePresenceSig1 >(OC::OCPlatform::subscribePresence)).Return(OC_STACK_OK); } @@ -218,30 +229,32 @@ TEST_F(ResourcePresenceTest,getCB_NormalHandlingIfMessageOC_STACK_OK) { mocks.ExpectCall(pResource.get(), PrimitiveResource::requestGet).Do( - [](GetCallback callback){ - - OIC::Service::HeaderOptions op; - RCSResourceAttributes attr; - OIC::Service::ResponseStatement res(attr); + [](GetCallback callback) + { + OIC::Service::HeaderOptions op; + RCSResourceAttributes attr; + OIC::Service::ResponseStatement res(attr); - callback(op,res,OC_STACK_OK); + callback(op,res,OC_STACK_OK); - }); + }); mocks.OnCall(pResource.get(), PrimitiveResource::requestGet).Do( - [](GetCallback){ - std::cout <<"End call requestGetFunc()\n"; - }); + [](GetCallback) + { + std::cout <<"End call requestGetFunc()\n"; + }); mocks.OnCall(pResource.get(), PrimitiveResource::getHost).Return("address1"); mocks.OnCallFuncOverload(static_cast< subscribePresenceSig1 >(OC::OCPlatform::subscribePresence)).Do( [](OC::OCPlatform::OCPresenceHandle&, - const std::string&, OCConnectivityType, SubscribeCallback callback)->OCStackResult{ - - callback(OC_STACK_OK,0,std::string()); - return OC_STACK_OK; + const std::string&, OCConnectivityType, SubscribeCallback callback)->OCStackResult + { + callback(OC_STACK_OK,0,std::string()); + return OC_STACK_OK; - }).Return(OC_STACK_OK); + } + ).Return(OC_STACK_OK); instance->initializeResourcePresence(pResource); sleep(3); diff --git a/service/resource-encapsulation/src/resourceCache/unittests/DataCacheTest.cpp b/service/resource-encapsulation/src/resourceCache/unittests/DataCacheTest.cpp index 41029b7..b7a8d56 100644 --- a/service/resource-encapsulation/src/resourceCache/unittests/DataCacheTest.cpp +++ b/service/resource-encapsulation/src/resourceCache/unittests/DataCacheTest.cpp @@ -50,11 +50,18 @@ class DataCacheTest : public TestWithMock virtual void SetUp() { TestWithMock::SetUp(); - pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource *) {}); + pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), + [](PrimitiveResource *) + { + + }); mocks.OnCall(pResource.get(), PrimitiveResource::isObservable).Return(false); cacheHandler.reset(new DataCache()); - cb = ([](std::shared_ptr, const RCSResourceAttributes &)->OCStackResult {return OC_STACK_OK;}); + cb = ([](std::shared_ptr, const RCSResourceAttributes &)->OCStackResult + { + return OC_STACK_OK; + }); } virtual void TearDown() diff --git a/service/resource-encapsulation/src/resourceCache/unittests/ResourceCacheTest.cpp b/service/resource-encapsulation/src/resourceCache/unittests/ResourceCacheTest.cpp index 5bf9f74..43bfe41 100644 --- a/service/resource-encapsulation/src/resourceCache/unittests/ResourceCacheTest.cpp +++ b/service/resource-encapsulation/src/resourceCache/unittests/ResourceCacheTest.cpp @@ -40,9 +40,16 @@ class ResourceCacheManagerTest : public TestWithMock { TestWithMock::SetUp(); cacheInstance = ResourceCacheManager::getInstance(); - pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource *) {}); + pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), + [](PrimitiveResource *) + { + + }); mocks.OnCall(pResource.get(), PrimitiveResource::isObservable).Return(false); - cb = ([](std::shared_ptr, const RCSResourceAttributes &)->OCStackResult {return OC_STACK_OK;}); + cb = ([](std::shared_ptr, const RCSResourceAttributes &)->OCStackResult + { + return OC_STACK_OK; + }); } virtual void TearDown() diff --git a/service/resource-encapsulation/unittests/DiscoveryManagerTest.cpp b/service/resource-encapsulation/unittests/DiscoveryManagerTest.cpp index 7572022..84624e1 100755 --- a/service/resource-encapsulation/unittests/DiscoveryManagerTest.cpp +++ b/service/resource-encapsulation/unittests/DiscoveryManagerTest.cpp @@ -40,7 +40,10 @@ constexpr char RESOURCE_URI[]{ "/a/TemperatureSensor" }; constexpr char RESOURCE_TYPE[]{ "resource.type" }; constexpr char SECOND_RESOURCETYPE[]{ "resource.type.second" }; -void onResourceDiscovered(RCSRemoteResourceObject::Ptr) {} +void onResourceDiscovered(RCSRemoteResourceObject::Ptr) +{ + +} class ScopedTask { @@ -52,7 +55,10 @@ public: ~ScopedTask() { - if (m_task) m_task->cancel(); + if (m_task) + { + m_task->cancel(); + } } RCSDiscoveryManager::DiscoveryTask* operator->() @@ -126,7 +132,8 @@ TEST(DiscoveryManagerTest, TaskCanBeCanceled) ASSERT_TRUE(aTaskToBeCanceled->isCanceled()); } -TEST(DiscoveryManagerTest, CallbackWouldNotBeCalledForSameRemoteResource) { +TEST(DiscoveryManagerTest, CallbackWouldNotBeCalledForSameRemoteResource) +{ FindCallback callback; MockRepository mocks; diff --git a/service/resource-hosting/SampleApp/linux/sampleConsumer/SampleConsumer.cpp b/service/resource-hosting/SampleApp/linux/sampleConsumer/SampleConsumer.cpp index c9b9e9b..e01cb84 100644 --- a/service/resource-hosting/SampleApp/linux/sampleConsumer/SampleConsumer.cpp +++ b/service/resource-hosting/SampleApp/linux/sampleConsumer/SampleConsumer.cpp @@ -95,7 +95,9 @@ void startObserve(std::shared_ptr< OCResource > resource) QueryParamsMap test; if (OC_STACK_OK != resource->observe(ObserveType::Observe , test , &onObserve)) + { std::cout << "To Fail resource observe() process" << std::endl; + } } void startGet(std::shared_ptr< OCResource > resource) @@ -110,7 +112,9 @@ void startGet(std::shared_ptr< OCResource > resource) QueryParamsMap test; std::cout << "URI :" << resource->uri() << std::endl; if (OC_STACK_OK != resource->get(test, &onGet)) + { std::cout << "To Fail resource get() process" << std::endl; + } } void startPost(std::shared_ptr< OCResource > resource) @@ -128,7 +132,9 @@ void startPost(std::shared_ptr< OCResource > resource) QueryParamsMap test; if (OC_STACK_OK != resource->post(rep, test, &onPost)) + { std::cout << "To Fail resource post() process" << std::endl; + } } void startDelete(std::shared_ptr< OCResource > resource) @@ -141,7 +147,9 @@ void startDelete(std::shared_ptr< OCResource > resource) g_curResource = resource; if (OC_STACK_OK != resource->deleteResource(&onDelete)) + { std::cout << "To Fail resource delete() process" << std::endl; + } } int observe_count() @@ -368,7 +376,8 @@ int main() continue; } - try { + try + { switch ((int)in) { case OBSERVE: @@ -384,7 +393,9 @@ int main() std::cout << "Invalid input, please try again" << std::endl; break; } - }catch(OCException & e) { + } + catch(OCException & e) + { std::cout<< "Caught OCException [Code: "<getAttributes() = RCSResourceAttributes(returnedAttributes); diff --git a/service/resource-hosting/src/ResourceHosting.cpp b/service/resource-hosting/src/ResourceHosting.cpp index 2ead1e4..fa7ab72 100755 --- a/service/resource-hosting/src/ResourceHosting.cpp +++ b/service/resource-hosting/src/ResourceHosting.cpp @@ -51,14 +51,20 @@ namespace OIC void ResourceHosting::startHosting() { - if (m_isStartedHosting) return; + if (m_isStartedHosting) + { + return; + } m_isStartedHosting = true; createDiscoveryListener(); } void ResourceHosting::stopHosting() { - if (!m_isStartedHosting) return; + if (!m_isStartedHosting) + { + return; + } if (!m_discoveryTask->isCanceled()) { @@ -89,7 +95,10 @@ namespace OIC } auto foundHostingObject = findRemoteResource(remoteResource); - if (foundHostingObject != nullptr) return; + if (foundHostingObject != nullptr) + { + return; + } try { @@ -100,7 +109,8 @@ namespace OIC RHLock lock(m_mutexForList); m_hostingObjects.insert(std::make_pair(key, foundHostingObject)); - } catch (const RCSException & e) + } + catch (const RCSException & e) { OIC_HOSTING_LOG(DEBUG, "[ResourceHosting::discoverHandler]InvalidParameterException:%s", e.what()); @@ -112,7 +122,10 @@ namespace OIC RHLock lock(m_mutexForList); auto iter = m_hostingObjects.find(generateHostingObjectKey(remoteResource)); - if (iter != m_hostingObjects.end()) return iter->second; + if (iter != m_hostingObjects.end()) + { + return iter->second; + } return nullptr; } diff --git a/service/things-manager/sampleapp/linux/configuration/FactorySetCollection.cpp b/service/things-manager/sampleapp/linux/configuration/FactorySetCollection.cpp index acef45b..39090b2 100755 --- a/service/things-manager/sampleapp/linux/configuration/FactorySetCollection.cpp +++ b/service/things-manager/sampleapp/linux/configuration/FactorySetCollection.cpp @@ -42,7 +42,9 @@ FactorySetResource::FactorySetResource() m_configurationRep.setResourceTypes(m_configurationTypes); } -FactorySetResource::~FactorySetResource(){} +FactorySetResource::~FactorySetResource() +{ +} /// This function internally calls registerResource API. void FactorySetResource::createResources(ResourceEntityHandler callback) diff --git a/service/things-manager/sampleapp/linux/configuration/con-client.cpp b/service/things-manager/sampleapp/linux/configuration/con-client.cpp index d83e86d..5ba9877 100755 --- a/service/things-manager/sampleapp/linux/configuration/con-client.cpp +++ b/service/things-manager/sampleapp/linux/configuration/con-client.cpp @@ -114,15 +114,25 @@ void onUpdate(const HeaderOptions& /*headerOptions*/, const OCRepresentation& re std::cout << "\tResource URI: " << rep.getUri() << std::endl; if (rep.hasAttribute("n")) + { std::cout << "\t\tDeviceName:" << rep.getValue< std::string >("n") << std::endl; + } if (rep.hasAttribute("loc")) + { std::cout << "\t\tLocation:" << rep.getValue< std::string >("loc") << std::endl; + } if (rep.hasAttribute("locn")) + { std::cout << "\t\tLocationName:" << rep.getValue< std::string >("locn") << std::endl; + } if (rep.hasAttribute("c")) + { std::cout << "\t\tCurrency:" << rep.getValue< std::string >("c") << std::endl; + } if (rep.hasAttribute("r")) + { std::cout << "\t\tRegion:" << rep.getValue< std::string >("r") << std::endl; + } } void onGet(const HeaderOptions& /*headerOptions*/, const OCRepresentation& rep, const int eCode) @@ -139,15 +149,25 @@ void onGet(const HeaderOptions& /*headerOptions*/, const OCRepresentation& rep, std::cout << "\tResource URI: " << rep.getUri() << std::endl; if (rep.hasAttribute("n")) + { std::cout << "\t\tDeviceName:" << rep.getValue< std::string >("n") << std::endl; + } if (rep.hasAttribute("loc")) + { std::cout << "\t\tLocation:" << rep.getValue< std::string >("loc") << std::endl; + } if (rep.hasAttribute("locn")) + { std::cout << "\t\tLocationName:" << rep.getValue< std::string >("locn") << std::endl; + } if (rep.hasAttribute("c")) + { std::cout << "\t\tCurrency:" << rep.getValue< std::string >("c") << std::endl; + } if (rep.hasAttribute("r")) + { std::cout << "\t\tRegion:" << rep.getValue< std::string >("r") << std::endl; + } } // Callback to found collection resource @@ -165,11 +185,17 @@ void onFoundCollectionResource(std::vector< std::shared_ptr< OCResource > > reso if (resource) { if (resource->uri() == "/core/a/configuration/resourceset") + { g_configurationCollection = resource; + } else if (resource->uri() == "/core/a/maintenance/resourceset") + { g_maintenanceCollection = resource; + } else if (resource->uri() == "/core/a/factoryset/resourceset") + { g_setCollection = resource; + } else { pthread_mutex_lock(&mutex_lock); @@ -232,20 +258,26 @@ void onFoundCandidateResource(std::vector< std::shared_ptr< OCResource > > resou OCPlatform::bindResource(configurationCollectionHandle, foundResourceHandle); if (g_configurationResource == NULL) + { g_configurationResource = resource; + } } else if (resource->uri() == "/oic/mnt") { OCPlatform::bindResource(maintenanceCollectionHandle, foundResourceHandle); if (g_maintenanceResource == NULL) + { g_maintenanceResource = resource; + } } else if (resource->uri() == "/factoryset") { OCPlatform::bindResource(setCollectionHandle, foundResourceHandle); if (g_setResource == NULL) + { g_setResource = resource; + } } resourceHandleVector.push_back(foundResourceHandle); @@ -517,7 +549,8 @@ int main() } } - }catch (OCException e) + } + catch (OCException e) { std::cout << "Exception in main: " << e.what(); } diff --git a/service/things-manager/sdk/src/ActionSet.cpp b/service/things-manager/sdk/src/ActionSet.cpp index e925ca9..d2f431c 100755 --- a/service/things-manager/sdk/src/ActionSet.cpp +++ b/service/things-manager/sdk/src/ActionSet.cpp @@ -55,9 +55,13 @@ void Time::setTime(unsigned int yy, unsigned int mm, unsigned int dd, void Time::setDayOfWeekForRecursive(int day) { if (day != -1) + { type = RECURSIVE; + } else + { return; + } setTime(0, 0, 0, 0, 0, 0, day); } @@ -87,8 +91,10 @@ unsigned int Time::getSec() } long int Time::getSecondsFromAbsoluteTime() { - if(mTime.tm_year > 1900) + if (mTime.tm_year > 1900) + { mTime.tm_year -= 1900; + } mTime.tm_mon -= 1; @@ -100,8 +106,10 @@ long int Time::getSecAbsTime() } long int Time::getSecondsForWeeklySchedule() { - if(mTime.tm_year > 1900) + if (mTime.tm_year > 1900) + { mTime.tm_year -= 1900; + } mTime.tm_mon -= 1; return getRelativeIntervalOfWeek(&mTime); @@ -109,7 +117,7 @@ long int Time::getSecondsForWeeklySchedule() void Time::setDelay(long int seconds) { - if(type != NONE) + if (type != NONE) { mDelay = seconds; } diff --git a/service/things-manager/sdk/src/GroupManager.cpp b/service/things-manager/sdk/src/GroupManager.cpp index 1568447..fcaa5e6 100755 --- a/service/things-manager/sdk/src/GroupManager.cpp +++ b/service/things-manager/sdk/src/GroupManager.cpp @@ -266,7 +266,7 @@ OCStackResult GroupManager::bindResourceToGroup(OCResourceHandle& childHandle, s } return result; - } +} @@ -370,7 +370,8 @@ void GroupManager::checkCollectionRepresentation(const OCRepresentation& rep, std::bind(&GroupManager::collectionPresenceHandler, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, hostAddress, oit->getUri()))); - }catch(OCException& e) + } + catch(OCException& e) { std::cout<< "Exception in subscribePresence: "<< e.what() << std::endl; } @@ -437,7 +438,9 @@ std::string GroupManager::getStringFromActionSet(const ActionSet *newActionSet) std::string message = ""; if(newActionSet == NULL) + { return message; + } message = newActionSet->actionsetName; message.append("*"); @@ -458,7 +461,9 @@ std::string GroupManager::getStringFromActionSet(const ActionSet *newActionSet) message.append((*iterCapa)->status); if (iterCapa + 1 != (*iterAction)->listOfCapability.end()) + { message.append("|"); + } } if (iterAction + 1 != newActionSet->listOfAction.end()) @@ -470,12 +475,14 @@ std::string GroupManager::getStringFromActionSet(const ActionSet *newActionSet) return message; } -#define DELETE(p) { \ +#define DELETE(p) \ +{ \ delete p; \ p = NULL; \ } -#define DELETEARRAY(p) { \ +#define DELETEARRAY(p) \ +{ \ delete[] p; \ p = NULL; \ } @@ -517,7 +524,9 @@ ActionSet* GroupManager::getActionSetfromString(std::string description) actionset->actionsetName = std::string(token); if((actionset->actionsetName).empty()) + { goto exit; + } // Find the second token token = strtok_r(NULL, ACTION_DELIMITER, &plainPtr); @@ -618,14 +627,20 @@ ActionSet* GroupManager::getActionSetfromString(std::string description) token = strtok_r(NULL, ATTR_DELIMITER, &attrPtr); if( token == NULL ) + { goto exit; + } capa->status = std::string(token); if (action != NULL) + { action->listOfCapability.push_back(capa); + } else + { goto exit; + } } token = strtok_r(NULL, ATTR_DELIMITER, &attrPtr); @@ -640,7 +655,9 @@ ActionSet* GroupManager::getActionSetfromString(std::string description) action = NULL; } else + { goto exit; + } //delete action; } else diff --git a/service/things-manager/sdk/src/ThingsConfiguration.cpp b/service/things-manager/sdk/src/ThingsConfiguration.cpp index 1d93883..02e3234 100755 --- a/service/things-manager/sdk/src/ThingsConfiguration.cpp +++ b/service/things-manager/sdk/src/ThingsConfiguration.cpp @@ -80,10 +80,14 @@ namespace OIC { "c","Currency", "/oic/con" } }; for (int i = 0; i < NUMCONFUNIT; i++) + { ConfigurationUnitTable.push_back(unit[i]); + } } - ThingsConfiguration::~ThingsConfiguration(void){} + ThingsConfiguration::~ThingsConfiguration(void) + { + } void ThingsConfiguration::setGroupManager(GroupManager *groupmanager) { @@ -113,7 +117,9 @@ namespace OIC for (auto it = ConfigurationUnitTable.begin(); ConfigurationUnitTable.end() != it; it++) { if ((*it).m_name == name) + { return (*it).m_attribute; + } } return ""; @@ -124,7 +130,9 @@ namespace OIC for (auto it = ConfigurationUnitTable.begin(); ConfigurationUnitTable.end() != it; it++) { if ((*it).m_name == name) + { return (*it).m_uri; + } } return ""; @@ -136,9 +144,13 @@ namespace OIC configurationRequestTable.find(conf); if (it == configurationRequestTable.end()) + { return NULL; + } else + { return it->second.m_updateVal; + } } std::shared_ptr< OCResource > ThingsConfiguration::getResource(std::string conf) @@ -147,9 +159,13 @@ namespace OIC configurationRequestTable.find(conf); if (it == configurationRequestTable.end()) + { return NULL; + } else + { return it->second.m_resource; + } } ConfigurationCallback ThingsConfiguration::getCallback(std::string conf) @@ -158,9 +174,13 @@ namespace OIC configurationRequestTable.find(conf); if (it == configurationRequestTable.end()) + { return NULL; + } else + { return it->second.m_callback; + } } std::string ThingsConfiguration::getListOfSupportedConfigurationUnits() @@ -176,9 +196,13 @@ namespace OIC it++; if (it == ConfigurationUnitTable.end()) + { break; + } else + { res += ","; + } } res += "]}"; @@ -192,9 +216,13 @@ namespace OIC std::string newUri; if ((f = oldUri.find("/factoryset/oic/")) != string::npos) + { newUri = oldUri.replace(f, oldUri.size(), ""); + } else if ((f = oldUri.find("/oic/")) != string::npos) + { newUri = oldUri.replace(f, oldUri.size(), ""); + } return newUri; } @@ -249,7 +277,9 @@ namespace OIC std::string attrKey = conf; if (uri == "") + { return; + } if (resource) { @@ -309,12 +339,18 @@ namespace OIC std::string uri = getUriByConfigurationName(conf); if (uri == "") + { return; + } if (uri == "/factoryset" || uri == "/factoryset/oic/con") + { m_if.push_back(BATCH_INTERFACE); + } else + { m_if.push_back(DEFAULT_INTERFACE); + } std::vector < OCRepresentation > children = rep.getChildren(); for (auto oit = children.begin(); oit != children.end(); ++oit) @@ -333,7 +369,8 @@ namespace OIC oit->getResourceTypes(), m_if); p_resources.push_back(tempResource); - } catch (std::exception& e) + } + catch (std::exception& e) { std::cout << "Exception: " << e.what() << std::endl; } @@ -406,7 +443,9 @@ namespace OIC for (unsigned int i = 0; i < resource->getResourceTypes().size(); ++i) { if (resource->getResourceTypes().at(i).find(".resourceset", 0) != std::string::npos) + { return false; + } } return true; @@ -417,7 +456,9 @@ namespace OIC for (unsigned int i = 0; i < resource->getResourceInterfaces().size(); ++i) { if (resource->getResourceInterfaces().at(i) == BATCH_INTERFACE) + { return true; + } } return false; @@ -479,7 +520,9 @@ namespace OIC std::map< std::string, ConfigurationRequestEntry >::iterator iter = configurationRequestTable.find(conf); if (iter != configurationRequestTable.end()) + { configurationRequestTable.erase(iter); + } // Create new request entry stored in the queue ConfigurationRequestEntry newCallback(conf, callback, resource, it->second); @@ -538,7 +581,9 @@ namespace OIC std::map< std::string, ConfigurationRequestEntry >::iterator iter = configurationRequestTable.find(conf); if (iter != configurationRequestTable.end()) + { configurationRequestTable.erase(iter); + } // Create new request entry stored in the queue ConfigurationRequestEntry newCallback(conf, callback, resource, conf); @@ -553,7 +598,9 @@ namespace OIC std::string m_if = DEFAULT_INTERFACE; if (hasBatchInterface(resource)) + { m_if = BATCH_INTERFACE; + } return resource->get(resource->getResourceTypes().at(0), m_if, query, std::function< @@ -633,9 +680,13 @@ namespace OIC OCStackResult ThingsConfiguration::doBootstrap(ConfigurationCallback callback) { if(callback == NULL) + { return OC_STACK_ERROR; + } else + { g_bootstrapCallback = callback; + } // Find bootstrap server. std::vector < std::string > type; diff --git a/service/things-manager/sdk/src/ThingsMaintenance.cpp b/service/things-manager/sdk/src/ThingsMaintenance.cpp index 7255911..7bf0ff3 100755 --- a/service/things-manager/sdk/src/ThingsMaintenance.cpp +++ b/service/things-manager/sdk/src/ThingsMaintenance.cpp @@ -72,7 +72,9 @@ namespace OIC { "fr", "Factory Reset", "/oic/mnt" } }; for (int i = 0; i < NUMDIAGUNIT; i++) + { MaintenanceUnitTable.push_back(unit[i]); + } } ThingsMaintenance::~ThingsMaintenance() @@ -107,7 +109,9 @@ namespace OIC for (auto it = MaintenanceUnitTable.begin(); MaintenanceUnitTable.end() != it; it++) { if ((*it).m_name == name) + { return (*it).m_attribute; + } } return ""; @@ -118,7 +122,9 @@ namespace OIC for (auto it = MaintenanceUnitTable.begin(); MaintenanceUnitTable.end() != it; it++) { if ((*it).m_name == name) + { return (*it).m_uri; + } } return ""; @@ -130,9 +136,13 @@ namespace OIC maintenanceRequestTable.find(mnt); if (it == maintenanceRequestTable.end()) + { return NULL; + } else + { return it->second.m_updateVal; + } } std::shared_ptr< OCResource > ThingsMaintenance::getResource(std::string mnt) @@ -141,9 +151,13 @@ namespace OIC maintenanceRequestTable.find(mnt); if (it == maintenanceRequestTable.end()) + { return NULL; + } else + { return it->second.m_resource; + } } MaintenanceCallback ThingsMaintenance::getCallback(std::string mnt) @@ -152,9 +166,13 @@ namespace OIC maintenanceRequestTable.find(mnt); if (it == maintenanceRequestTable.end()) + { return NULL; + } else + { return it->second.m_callback; + } } std::string ThingsMaintenance::getHostFromURI(std::string oldUri) @@ -163,9 +181,13 @@ namespace OIC std::string newUri; if ((f = oldUri.find("/factoryset/oic/")) != string::npos) + { newUri = oldUri.replace(f, oldUri.size(), ""); + } else if ((f = oldUri.find("/oic/")) != string::npos) + { newUri = oldUri.replace(f, oldUri.size(), ""); + } return newUri; } @@ -183,9 +205,13 @@ namespace OIC it++; if (it == MaintenanceUnitTable.end()) + { break; + } else + { res += ","; + } } res += "]}"; @@ -220,7 +246,9 @@ namespace OIC std::string attrKey = mnt; if (uri == "") + { return; + } if (resource) { @@ -348,7 +376,9 @@ namespace OIC for (unsigned int i = 0; i < resource->getResourceTypes().size(); ++i) { if (resource->getResourceTypes().at(0).find(".resourceset", 0) != std::string::npos) + { return false; + } } return true; @@ -369,7 +399,9 @@ namespace OIC std::map< std::string, MaintenanceRequestEntry >::iterator iter = maintenanceRequestTable.find(mnt); if (iter != maintenanceRequestTable.end()) + { maintenanceRequestTable.erase(iter); + } // Create new request entry stored in the queue MaintenanceRequestEntry newCallback(mnt, callback, resource, "true"); @@ -422,7 +454,9 @@ namespace OIC std::map< std::string, MaintenanceRequestEntry >::iterator iter = maintenanceRequestTable.find(mnt); if (iter != maintenanceRequestTable.end()) + { maintenanceRequestTable.erase(iter); + } // Create new request entry stored in the queue MaintenanceRequestEntry newCallback(mnt, callback, resource, "true"); diff --git a/service/things-manager/unittests/ThingsManagerTest.cpp b/service/things-manager/unittests/ThingsManagerTest.cpp index 53812ff..e12ebab 100755 --- a/service/things-manager/unittests/ThingsManagerTest.cpp +++ b/service/things-manager/unittests/ThingsManagerTest.cpp @@ -1134,7 +1134,10 @@ TEST_F(ThingsManagerTest, testAddActionSetAllBulbOff) mocks.ExpectCallFunc(onPut). Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/, - const int /*eCode*/) { Proceed();}); + const int /*eCode*/) + { + Proceed(); + }); for (auto iter = lights.begin(); iter != lights.end(); ++iter) { @@ -1207,7 +1210,10 @@ TEST_F(ThingsManagerTest, testAddActionSetAllBulbOn) mocks.ExpectCallFunc(onPut). Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/, - const int /*eCode*/) { Proceed();}); + const int /*eCode*/) + { + Proceed(); + }); for (auto iter = lights.begin(); iter != lights.end(); ++iter) { @@ -1304,7 +1310,10 @@ TEST_F(ThingsManagerTest, testExecuteActionSetAllBulbOn) mocks.ExpectCallFunc(onPost). Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/, - const int /*eCode*/) { Proceed();}); + const int /*eCode*/) + { + Proceed(); + }); if (g_resource) { @@ -1330,7 +1339,10 @@ TEST_F(ThingsManagerTest, testExecuteActionSetAllBulbOff) { mocks.ExpectCallFunc(onPost). Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/, - const int /*eCode*/) { Proceed();}); + const int /*eCode*/) + { + Proceed(); + }); if (g_resource) { @@ -1360,7 +1372,10 @@ TEST_F(ThingsManagerTest, testExcecuteActionSetWithDelay) mocks.ExpectCallFunc(onPut). Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/, - const int /*eCode*/) { Proceed();}); + const int /*eCode*/) + { + Proceed(); + }); for (auto iter = lights.begin(); iter != lights.end(); ++iter) { @@ -1382,7 +1397,10 @@ TEST_F(ThingsManagerTest, testExcecuteActionSetWithDelay) mocks.ExpectCallFunc(onPost). Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/, - const int /*eCode*/) { Proceed();}); + const int /*eCode*/) + { + Proceed(); + }); if (g_resource) { @@ -1404,7 +1422,10 @@ TEST_F(ThingsManagerTest, testExcecuteActionSetWithDelayEqulasZero) mocks.ExpectCallFunc(onPut). Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/, - const int /*eCode*/) { Proceed();}); + const int /*eCode*/) + { + Proceed(); + }); for (auto iter = lights.begin(); iter != lights.end(); ++iter) { @@ -1444,7 +1465,10 @@ TEST_F(ThingsManagerTest, testExcecuteActionSetWithInvalidDelay) mocks.ExpectCallFunc(onPut). Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/, - const int /*eCode*/) { Proceed();}); + const int /*eCode*/) + { + Proceed(); + }); for (auto iter = lights.begin(); iter != lights.end(); ++iter) { @@ -1485,7 +1509,10 @@ TEST_F(ThingsManagerTest, testExcecuteActionSetWithDelayWithResourceNull) mocks.ExpectCallFunc(onPut). Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/, - const int /*eCode*/) { Proceed();}); + const int /*eCode*/) + { + Proceed(); + }); for (auto iter = lights.begin(); iter != lights.end(); ++iter) { @@ -1516,7 +1543,10 @@ TEST_F(ThingsManagerTest, testCancelActionSet) { mocks.ExpectCallFunc(onPost). Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/, - const int /*eCode*/) { Proceed();}); + const int /*eCode*/) + { + Proceed(); + }); if (g_resource) { @@ -1541,7 +1571,10 @@ TEST_F(ThingsManagerTest, testDeleteActionSet) { mocks.ExpectCallFunc(onPut). Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/, - const int /*eCode*/) { Proceed();}); + const int /*eCode*/) + { + Proceed(); + }); if (g_resource) { @@ -1566,7 +1599,10 @@ TEST_F(ThingsManagerTest, testGetActionSet) { mocks.ExpectCallFunc(onPost). Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/, - const int /*eCode*/) { Proceed();}); + const int /*eCode*/) + { + Proceed(); + }); if (g_resource) { @@ -1598,7 +1634,10 @@ TEST_F(ThingsManagerTest, testGetConfigurations) mocks.ExpectCallFunc(onGet). Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/, - const int /*eCode*/) { Proceed();}); + const int /*eCode*/) + { + Proceed(); + }); vector types; types.push_back("oic.wk.con"); @@ -1672,7 +1711,10 @@ TEST_F(ThingsManagerTest, testDoBootstrap) mocks.ExpectCallFunc(onGetBootstrapInformation). Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/, - const int /*eCode*/) { Proceed();}); + const int /*eCode*/) + { + Proceed(); + }); result = g_thingsConf->doBootstrap(&onGetBootstrapInformation); Wait(); EXPECT_TRUE(result == OC_STACK_OK); @@ -1702,7 +1744,10 @@ TEST_F(ThingsManagerTest, testUpdateConfiguration) mocks.ExpectCallFunc(onUpdate). Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/, - const int /*eCode*/) { Proceed();}); + const int /*eCode*/) + { + Proceed(); + }); vector types; types.push_back("oic.wk.con"); @@ -1770,7 +1815,10 @@ TEST_F(ThingsManagerTest, testReboot) mocks.ExpectCallFunc(onReboot). Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/, - const int /*eCode*/) { Proceed();}); + const int /*eCode*/) + { + Proceed(); + }); vector types; types.push_back("oic.wk.mnt"); @@ -1807,7 +1855,10 @@ TEST_F(ThingsManagerTest, testFactoryReset) mocks.ExpectCallFunc(onFactoryReset). Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/, - const int /*eCode*/) { Proceed();}); + const int /*eCode*/) + { + Proceed(); + }); vector types; types.push_back("oic.wk.mnt"); -- 2.7.4