From f1b10862b39077d84b15ba22855b7e9de07e37a5 Mon Sep 17 00:00:00 2001 From: coderhyme Date: Mon, 22 Feb 2016 19:03:46 -0800 Subject: [PATCH] Fixed a bug in RCSDiscoveryManager and some minor issues. An empty resource type must be allowed only when there is no other requested types, because an empty resource type means all resource types, which means other types are meaningless. Change-Id: I51be73a3a21c3e84151b12333ab86aed656c2a3c Signed-off-by: coderhyme Reviewed-on: https://gerrit.iotivity.org/gerrit/5123 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- .../include/RCSDiscoveryManager.h | 2 +- .../src/resourceClient/RCSDiscoveryManager.cpp | 10 ++++---- .../src/resourceClient/RCSDiscoveryManagerImpl.cpp | 29 ++++++++++++++-------- .../src/resourceClient/RCSDiscoveryManagerImpl.h | 2 +- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/service/resource-encapsulation/include/RCSDiscoveryManager.h b/service/resource-encapsulation/include/RCSDiscoveryManager.h index 3aaf3d0..18572b5 100644 --- a/service/resource-encapsulation/include/RCSDiscoveryManager.h +++ b/service/resource-encapsulation/include/RCSDiscoveryManager.h @@ -65,7 +65,7 @@ namespace OIC DiscoveryTask& operator =(DiscoveryTask&&) const = delete; /** - * It is cancelling the task of discovery. + * It cancels the task of discovery. * If it is already canceled, the operation is ignored. */ void cancel(); diff --git a/service/resource-encapsulation/src/resourceClient/RCSDiscoveryManager.cpp b/service/resource-encapsulation/src/resourceClient/RCSDiscoveryManager.cpp index 6fbeb73..007d49c 100755 --- a/service/resource-encapsulation/src/resourceClient/RCSDiscoveryManager.cpp +++ b/service/resource-encapsulation/src/resourceClient/RCSDiscoveryManager.cpp @@ -83,10 +83,8 @@ namespace OIC const RCSAddress& address, const std::string& relativeUri, const std::string& resourceType, ResourceDiscoveredCallback cb) { - return discoverResourceByTypes(address, - relativeUri.empty() ? OC_RSRVD_WELL_KNOWN_URI : relativeUri, - std::vector< std::string > - { resourceType }, std::move(cb)); + return discoverResourceByTypes(address, relativeUri, + std::vector< std::string >{ resourceType }, std::move(cb)); } RCSDiscoveryManager::DiscoveryTask::Ptr RCSDiscoveryManager::discoverResourceByTypes( @@ -94,7 +92,9 @@ namespace OIC const std::vector< std::string >& resourceTypes, ResourceDiscoveredCallback cb) { return RCSDiscoveryManagerImpl::getInstance()->startDiscovery(address, - relativeUri.empty() ? OC_RSRVD_WELL_KNOWN_URI : relativeUri, resourceTypes, + relativeUri.empty() ? OC_RSRVD_WELL_KNOWN_URI : relativeUri, + resourceTypes.empty() ? std::vector< std::string >{ + RCSDiscoveryManagerImpl::ALL_RESOURCE_TYPE } : resourceTypes, std::move(cb)); } } diff --git a/service/resource-encapsulation/src/resourceClient/RCSDiscoveryManagerImpl.cpp b/service/resource-encapsulation/src/resourceClient/RCSDiscoveryManagerImpl.cpp index cc9db98..bc57893 100755 --- a/service/resource-encapsulation/src/resourceClient/RCSDiscoveryManagerImpl.cpp +++ b/service/resource-encapsulation/src/resourceClient/RCSDiscoveryManagerImpl.cpp @@ -34,6 +34,19 @@ namespace { return resource->getSid() + resource->getUri(); } + + void validateTypes(const std::vector< std::string >& resourceTypes) { + if (resourceTypes.size() == 1) return; + + for (const auto& type : resourceTypes) + { + if (type == OIC::Service::RCSDiscoveryManagerImpl::ALL_RESOURCE_TYPE) + { + throw OIC::Service::RCSBadRequestException{ + "resource types must have no empty string!" }; + } + } + } } namespace OIC @@ -45,7 +58,7 @@ namespace OIC RCSDiscoveryManagerImpl::RCSDiscoveryManagerImpl() { - subscribePresenceWithMuticast(); + subscribePresenceWithMulticast(); m_timer.post(POLLING_INTERVAL_TIME, std::bind(&RCSDiscoveryManagerImpl::onPolling, this)); @@ -83,13 +96,7 @@ namespace OIC throw RCSInvalidParameterException{ "Callback is empty" }; } - for(auto it = resourceTypes.begin()+1; it < resourceTypes.end(); it++) - { - if ((*it).compare(ALL_RESOURCE_TYPE) == 0) - { - throw RCSInvalidParameterException{ "ResourceType is duplicated!" }; - } - } + validateTypes(resourceTypes); const ID discoveryId = createId(); @@ -104,11 +111,11 @@ namespace OIC m_discoveryMap.insert(std::make_pair(discoveryId, std::move(discoveryInfo))); } - return std::unique_ptr < RCSDiscoveryManager::DiscoveryTask - > (new RCSDiscoveryManager::DiscoveryTask(discoveryId)); + return std::unique_ptr< RCSDiscoveryManager::DiscoveryTask >( + new RCSDiscoveryManager::DiscoveryTask(discoveryId)); } - void RCSDiscoveryManagerImpl::subscribePresenceWithMuticast() + void RCSDiscoveryManagerImpl::subscribePresenceWithMulticast() { using namespace std::placeholders; diff --git a/service/resource-encapsulation/src/resourceClient/RCSDiscoveryManagerImpl.h b/service/resource-encapsulation/src/resourceClient/RCSDiscoveryManagerImpl.h index b1d75f0..0fea0cd 100755 --- a/service/resource-encapsulation/src/resourceClient/RCSDiscoveryManagerImpl.h +++ b/service/resource-encapsulation/src/resourceClient/RCSDiscoveryManagerImpl.h @@ -118,7 +118,7 @@ namespace OIC RCSDiscoveryManagerImpl(); ~RCSDiscoveryManagerImpl() = default; - void subscribePresenceWithMuticast(); + void subscribePresenceWithMulticast(); /** * Check duplicated callback and invoke callback when resource is discovered -- 2.7.4