Fix GroupSync API of about GroupSync of Group feature.
authorHyunJun Kim <hyunjun2.kim@samsung.com>
Fri, 23 Jan 2015 04:15:09 +0000 (13:15 +0900)
committerSudarshan Prasad <sudarshan.prasad@intel.com>
Fri, 20 Feb 2015 17:02:49 +0000 (17:02 +0000)
Crash is occured when som api of ThingsManager is called multiple times.

Fix [IOT-261], [IOT-264], [IOT-268]

Change-Id: Iec1cb11c570357411351c69450ace91ea6fa3754
Signed-off-by: HyunJun Kim <hyunjun2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/228
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
(cherry picked from commit 135e8386212533f4c62e892f0695c78d945f2879)
Reviewed-on: https://gerrit.iotivity.org/gerrit/375
Reviewed-by: Sudarshan Prasad <sudarshan.prasad@intel.com>
service/things-manager/sdk/src/GroupManager.cpp
service/things-manager/sdk/src/GroupSynchronization.cpp

index da2763c..777ac08 100644 (file)
@@ -421,6 +421,9 @@ std::string GroupManager::getStringFromActionSet(const ActionSet *newActionSet)
 {
     std::string message = "";
 
+    if(newActionSet == NULL)
+        return message;
+
     message = newActionSet->actionsetName;
     message.append("*");
     for (auto iterAction = newActionSet->listOfAction.begin();
index d99fc36..a1daf83 100644 (file)
@@ -194,12 +194,18 @@ namespace OIC
 
         OCResourceHandle collectionResHandle = resIt->second;
 
-        OCStackResult result = OCPlatform::bindResource(collectionResHandle, resourceHandle);
-        if (result != OC_STACK_OK)
-        {
-            cout << "GroupSynchronization::joinGroup : To bind resource was unsuccessful."
-                    << "result - " << result << endl;
-            return OC_STACK_ERROR;
+        try{
+            OCStackResult result = OCPlatform::bindResource(collectionResHandle, resourceHandle);
+            if (result != OC_STACK_OK)
+            {
+                cout << "GroupSynchronization::joinGroup : To bind resource was unsuccessful."
+                        << "result - " << result << endl;
+                return OC_STACK_ERROR;
+            }
+        } catch(OCException &e) {
+
+            return OC_STACK_INVALID_PARAM;
+            
         }
         cout << "GroupSynchronization::joinGroup : "
                 << "To bind collectionResHandle and resourceHandle" << endl;
@@ -328,34 +334,52 @@ namespace OIC
             collectionResHandle = handleIt->second;
 //            cout << "GroupSynchronization::leaveGroup : collection handle uri - "
 //                    << OCGetResourceUri(collectionResHandle) << endl;
+            if(collectionResHandle == NULL)
+                return OC_STACK_INVALID_PARAM;
 
-            OCStackResult result = OCPlatform::unbindResource(collectionResHandle, resourceHandle);
-            if (OC_STACK_OK == result)
+            OCStackResult result;
+            try
             {
-                cout << "GroupSynchronization::leaveGroup : "
-                        << "To unbind resource was successful." << endl;
-            }
-            else
-            {
-                cout << "GroupSynchronization::leaveGroup : "
-                        << "To unbind resource was unsuccessful. result - " << result << endl;
+                result = OCPlatform::unbindResource(collectionResHandle, resourceHandle);
+                if (OC_STACK_OK == result)
+                {
+                    cout << "GroupSynchronization::leaveGroup : "
+                            << "To unbind resource was successful." << endl;
+                }
+                else
+                {
+                    cout << "GroupSynchronization::leaveGroup : "
+                            << "To unbind resource was unsuccessful. result - " << result << endl;
+                    return result;
+                }
+            } catch(OCException &e) {
+                cout << "ERROR : " << e.reason() << endl;
+                return OC_STACK_NO_RESOURCE;
             }
 
             auto It = std::find(deviceResourceHandleList.begin(), deviceResourceHandleList.end(),
                     resourceHandle);
             if (It == deviceResourceHandleList.end()) // there is no resource handle to find
             {
-                result = OCPlatform::unregisterResource(resourceHandle);
-                if (OC_STACK_OK == result)
+                try
                 {
-                    cout << "GroupSynchronization::leaveGroup : "
-                            << "To unregister resource was successful." << endl;
-                }
-                else
+                    result = OCPlatform::unregisterResource(resourceHandle);
+                    if (OC_STACK_OK == result)
+                    {
+                        cout << "GroupSynchronization::leaveGroup : "
+                                << "To unregister resource was successful." << endl;
+                    }
+                    else
+                    {
+                        cout << "GroupSynchronization::leaveGroup : "
+                                << "To unregister resource was unsuccessful. result - " << result
+                                << endl;
+                        return result;
+                    }
+                } catch(OCException &e) 
                 {
-                    cout << "GroupSynchronization::leaveGroup : "
-                            << "To unregister resource was unsuccessful. result - " << result
-                            << endl;
+                    cout << "ERROR : " << e.reason() << endl;
+                    return OC_STACK_NO_RESOURCE;
                 }
             }
             else
@@ -398,6 +422,8 @@ namespace OIC
             }
 
             std::shared_ptr< OCResource > resource = resourceIt->second;
+            if(resource == NULL)
+                return OC_STACK_NO_RESOURCE;
 //            cout << "GroupSynchronization::leaveGroup : group sync resource uri - "
 //                    << resource->uri() << endl;