From 49e0ac762003c82219c5c549a28374f062f7c36c Mon Sep 17 00:00:00 2001 From: HyunJun Kim Date: Mon, 2 Feb 2015 14:49:56 +0900 Subject: [PATCH] Fix API of ThingsManger. subscribeCollectionPresence and findCandidateResource are occurred exception or no response(callback) while to combine resource type when child resource doesn't have correct type name of resource. In this case we don't combine the type of resource and we will ignore. Fix [IOT-289] Change-Id: I59c48726a9738e34d6c5561b59a2cdda243168ec Signed-off-by: HyunJun Kim Reviewed-on: https://gerrit.iotivity.org/gerrit/277 Reviewed-by: Uze Choi Tested-by: Uze Choi --- service/things-manager/sdk/src/GroupManager.cpp | 43 ++++++++++++++----------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/service/things-manager/sdk/src/GroupManager.cpp b/service/things-manager/sdk/src/GroupManager.cpp index 90e3eb3..ceb2686 100644 --- a/service/things-manager/sdk/src/GroupManager.cpp +++ b/service/things-manager/sdk/src/GroupManager.cpp @@ -217,17 +217,20 @@ OCStackResult GroupManager::findCandidateResources(std::vector< std::string > re for (unsigned int i = 0; i < resourceTypes.size(); ++i) { - std::string query = "coap://224.0.1.187:5298/oc/core?rt="; // std::cout << "resourceTypes : " << resourceTypes.at(i) << std::endl; - query.append(resourceTypes.at(i)); #ifdef CA_INT + std::string query = "coap://224.0.1.187:5298/oc/core?rt="; + query.append(resourceTypes.at(i)); + OCPlatform::findResource("", query.c_str(), OC_ETHERNET | OC_WIFI, std::function < void(std::shared_ptr < OCResource > resource) > (std::bind(&GroupManager::onFoundResource, this, std::placeholders::_1, waitsec))); #else + std::string query = "coap://224.0.1.187/oc/core?rt="; + query.append(resourceTypes.at(i)); OCPlatform::findResource("", query.c_str(), std::function < void(std::shared_ptr < OCResource > resource) > (std::bind(&GroupManager::onFoundResource, this, std::placeholders::_1, @@ -319,7 +322,6 @@ void GroupManager::checkCollectionRepresentation(const OCRepresentation& rep, } */ std::vector< OCRepresentation > children = rep.getChildren(); - if(children.size() == 0 ) { callback("", OC_STACK_ERROR); @@ -328,7 +330,7 @@ void GroupManager::checkCollectionRepresentation(const OCRepresentation& rep, for (auto oit = children.begin(); oit != children.end(); ++oit) { - std::cout << "\t\tChild Resource URI: " << oit->getUri() << std::endl; + // std::cout << "\t\tChild Resource URI: " << oit->getUri() << std::endl; std::vector< std::string > hostAddressVector = str_split(oit->getUri(), '/'); std::string hostAddress = ""; for (unsigned int i = 0; i < hostAddressVector.size(); ++i) @@ -344,20 +346,23 @@ void GroupManager::checkCollectionRepresentation(const OCRepresentation& rep, } std::vector< std::string > resourceTypes = oit->getResourceTypes(); - for (unsigned int i = 0; i < resourceTypes.size(); ++i) - { - std::cout << "\t\t\tresourcetype :" << resourceTypes.at(i) << std::endl; - } - - std::string resourceType = "core."; - resourceType.append(str_split(oit->getUri(), '/').at(4)); - std::cout << "\t\tconvertRT : " << resourceType << std::endl; - std::cout << "\t\thost : " << hostAddress << std::endl; + // for (unsigned int i = 0; i < resourceTypes.size(); ++i) + // { + // std::cout << "\t\t\tresourcetype :" << resourceTypes.at(i) << std::endl; + // } + + // std::string resourceType = "core."; + // resourceType.append(str_split(oit->getUri(), '/').at(4)); + // std::cout << "\t\tconvertRT : " << resourceType << std::endl; + // std::cout << "\t\tresource type front : " << resourceTypes.front() << endl; + // std::cout << "\t\thost : " << hostAddress << std::endl; OCPlatform::OCPresenceHandle presenceHandle; + OCStackResult result = OC_STACK_ERROR; #ifdef CA_INT - OCStackResult result = OCPlatform::subscribePresence(presenceHandle, hostAddress, - resourceType, + result = OCPlatform::subscribePresence(presenceHandle, hostAddress, + // resourceType, + resourceTypes.front(), OC_ETHERNET | OC_WIFI, std::function< void(OCStackResult result, const unsigned int nonce, @@ -366,8 +371,9 @@ void GroupManager::checkCollectionRepresentation(const OCRepresentation& rep, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, hostAddress, oit->getUri()))); #else - OCStackResult result = OCPlatform::subscribePresence(presenceHandle, hostAddress, - resourceType, + result = OCPlatform::subscribePresence(presenceHandle, hostAddress, + // resourceType, + resourceTypes.front(), std::function< void(OCStackResult result, const unsigned int nonce, const std::string& hostAddress) >( @@ -378,14 +384,13 @@ void GroupManager::checkCollectionRepresentation(const OCRepresentation& rep, if (result == OC_STACK_OK) { - std::cout << "\t\tOK!" << std::endl; + // std::cout << "\t\tOK!" << std::endl; presenceCallbacks.insert(std::make_pair(oit->getUri(), callback)); } else { callback("", OC_STACK_ERROR); } - } } -- 2.7.4