Add an exception handling logic in collection presence in Group Manager
authorJihun Ha <jihun.ha@samsung.com>
Mon, 20 Apr 2015 05:27:19 +0000 (14:27 +0900)
committerUze Choi <uzchoi@samsung.com>
Mon, 20 Apr 2015 10:30:38 +0000 (10:30 +0000)
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 <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/773
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/things-manager/sdk/src/GroupManager.cpp

index 30720f0..581b3bb 100755 (executable)
@@ -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)
         {