Commit 71d4ed1e authored by Jihun Ha's avatar Jihun Ha Committed by Uze Choi

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: default avatarJihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/773Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarUze Choi <uzchoi@samsung.com>
parent 31d39181
......@@ -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<std::string>("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)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment