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)
committerUze Choi <uzchoi@samsung.com>
Fri, 23 Jan 2015 08:25:02 +0000 (08:25 +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>
service/things-manager/sdk/src/GroupManager.cpp
service/things-manager/sdk/src/GroupSynchronization.cpp

index ca8c1907ba20993ef78025dbc60695d438a3a8df..a86071168916dcef1e0cbc5ce84c02bd9305b08d 100644 (file)
@@ -418,6 +418,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 9a448bb44c5f8743f810045591b0e9efffb3ceb5..2b476b5b20f637931063fb445011f390a39019a1 100644 (file)
@@ -191,12 +191,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;
@@ -325,34 +331,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
@@ -395,6 +419,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;