From 71d4ed1e7431b9f786ace8f43926635e81dc7443 Mon Sep 17 00:00:00 2001 From: Jihun Ha Date: Mon, 20 Apr 2015 14:27:19 +0900 Subject: [PATCH] Add an exception handling logic in collection presence in Group Manager subscribeCollectionPresence() in GroupManager is intended to be used for group resource having remote resources as child resources, not conventional collection resource having local resources. After requesting a list of child resources by sending GET to a collection resource, if the child resource has a URI without a coap prefix "coap://", \ it is obviously a local (child) resource, which is not a desired resource we want to send a request to presence check. Thus, we're going to ignore it. Ref: [IOT-289] Change-Id: I517f4fc25bb6a5e964e3624eb858a15c2dbafc03 Signed-off-by: Jihun Ha Reviewed-on: https://gerrit.iotivity.org/gerrit/773 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- service/things-manager/sdk/src/GroupManager.cpp | 63 ++++++++++++++----------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/service/things-manager/sdk/src/GroupManager.cpp b/service/things-manager/sdk/src/GroupManager.cpp index 30720f0..581b3bb 100755 --- a/service/things-manager/sdk/src/GroupManager.cpp +++ b/service/things-manager/sdk/src/GroupManager.cpp @@ -319,12 +319,6 @@ void GroupManager::checkCollectionRepresentation(const OCRepresentation& rep, { std::cout << "\tResource URI: " << rep.getUri() << std::endl; - /* //bug not found - if(rep.hasAttribute("name")) - { - std::cout << "\tRoom name: " << rep.getValue("name") << std::endl; - } - */ std::vector< OCRepresentation > children = rep.getChildren(); if(children.size() == 0 ) { @@ -334,7 +328,14 @@ 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; + if(oit->getUri().find("coap://") == std::string::npos) + { + std::cout << "The resource with a URI " << oit->getUri() << " is not a remote resource." + << " Thus, we ignore to send a request for presence check to the resource.\n"; + + continue; + } + std::vector< std::string > hostAddressVector = str_split(oit->getUri(), '/'); std::string hostAddress = ""; for (unsigned int i = 0; i < hostAddressVector.size(); ++i) @@ -363,27 +364,33 @@ void GroupManager::checkCollectionRepresentation(const OCRepresentation& rep, OCPlatform::OCPresenceHandle presenceHandle; OCStackResult result = OC_STACK_ERROR; - result = OCPlatform::subscribePresence(presenceHandle, hostAddress, - // resourceType, - resourceTypes.front(), - OC_ETHERNET, - std::function< - void(OCStackResult result, const unsigned int nonce, - const std::string& hostAddress) >( - std::bind(&GroupManager::collectionPresenceHandler, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, hostAddress, oit->getUri()))); - - result = OCPlatform::subscribePresence(presenceHandle, hostAddress, - // resourceType, - resourceTypes.front(), - OC_WIFI, - std::function< - void(OCStackResult result, const unsigned int nonce, - const std::string& hostAddress) >( - std::bind(&GroupManager::collectionPresenceHandler, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, hostAddress, oit->getUri()))); + try + { + result = OCPlatform::subscribePresence(presenceHandle, hostAddress, + // resourceType, + resourceTypes.front(), + OC_ETHERNET, + std::function< + void(OCStackResult result, const unsigned int nonce, + const std::string& hostAddress) >( + std::bind(&GroupManager::collectionPresenceHandler, this, + std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3, hostAddress, oit->getUri()))); + + result = OCPlatform::subscribePresence(presenceHandle, hostAddress, + // resourceType, + resourceTypes.front(), + OC_WIFI, + std::function< + void(OCStackResult result, const unsigned int nonce, + const std::string& hostAddress) >( + std::bind(&GroupManager::collectionPresenceHandler, this, + std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3, hostAddress, oit->getUri()))); + }catch(OCException& e) + { + std::cout<< "Exception in subscribePresence: "<< e.what() << std::endl; + } if (result == OC_STACK_OK) { -- 2.7.4