Fix some issues of GroupManager
authorjjack.lee <jjack.lee@samsung.com>
Tue, 30 Dec 2014 05:22:58 +0000 (14:22 +0900)
committerSudarshan Prasad <sudarshan.prasad@intel.com>
Thu, 22 Jan 2015 05:00:38 +0000 (05:00 +0000)
    - subscribeCollectionPresence()
        - IOT-197 : Handle null parameter
        - IOT-198 : Check that resource has child resource.
    - findCandidateResources()
        - IOT-210 : Handle null parameter

Change-Id: I6961aa776e5883890da226f07d3cfcf64571279c
Signed-off-by: Jack Lee <jjack.lee@samsung.com>
(cherry picked from commit be736343b6afaadba39bcfd64f2b6a50a9a83858)
Reviewed-on: https://gerrit.iotivity.org/gerrit/198
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sudarshan Prasad <sudarshan.prasad@intel.com>
service/things-manager/sdk/src/GroupManager.cpp

index d3ddab4..216ac0b 100644 (file)
@@ -197,12 +197,16 @@ OCStackResult GroupManager::findCandidateResources(std::vector< std::string > re
     {
         return OC_STACK_ERROR;
     }
+    if(callback == NULL)
+    {
+        return OC_STACK_ERROR;
+    }
 
     std::sort(resourceTypes.begin(), resourceTypes.end());
     resourceTypes.erase(std::unique(resourceTypes.begin(), resourceTypes.end()),
             resourceTypes.end());
 
-    if (waitsec != -1)
+    if (waitsec >= 0)
     {
         candidateRequestForTimer.insert(std::make_pair(resourceTypes, callback));
     }
@@ -222,7 +226,7 @@ OCStackResult GroupManager::findCandidateResources(std::vector< std::string > re
                                 std::placeholders::_1, waitsec)));
     }
 
-    if (waitsec != -1)
+    if (waitsec >= 0)
     {
         std::thread exec(
                 std::function< void(int second) >(
@@ -284,6 +288,12 @@ void GroupManager::checkCollectionRepresentation(const OCRepresentation& rep,
      }
      */
     std::vector< OCRepresentation > children = rep.getChildren();
+    
+    if(children.size() == 0 )
+    {
+        callback("", OC_STACK_ERROR);
+        return;
+    }
 
     for (auto oit = children.begin(); oit != children.end(); ++oit)
     {
@@ -357,6 +367,11 @@ void GroupManager::onGetForPresence(const HeaderOptions& headerOptions,
 OCStackResult GroupManager::subscribeCollectionPresence(
         std::shared_ptr< OCResource > collectionResource, CollectionPresenceCallback callback)
 {
+    if(callback == NULL || collectionResource == NULL)
+    {
+        return OC_STACK_ERROR;
+    }
+    
     OCStackResult result = OC_STACK_OK;
     //callback("core.room",OC_STACK_OK);