From 888b206fe7fa679be3b7bc8f8e3233b14b26c8fe Mon Sep 17 00:00:00 2001 From: HyunJun Kim Date: Fri, 23 Jan 2015 13:15:09 +0900 Subject: [PATCH] Fix GroupSync API of about GroupSync of Group feature. 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 Reviewed-on: https://gerrit.iotivity.org/gerrit/228 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi (cherry picked from commit 135e8386212533f4c62e892f0695c78d945f2879) Reviewed-on: https://gerrit.iotivity.org/gerrit/375 Reviewed-by: Sudarshan Prasad --- service/things-manager/sdk/src/GroupManager.cpp | 3 + .../sdk/src/GroupSynchronization.cpp | 74 +++++++++++++++------- 2 files changed, 53 insertions(+), 24 deletions(-) diff --git a/service/things-manager/sdk/src/GroupManager.cpp b/service/things-manager/sdk/src/GroupManager.cpp index da2763c..777ac08 100644 --- a/service/things-manager/sdk/src/GroupManager.cpp +++ b/service/things-manager/sdk/src/GroupManager.cpp @@ -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(); diff --git a/service/things-manager/sdk/src/GroupSynchronization.cpp b/service/things-manager/sdk/src/GroupSynchronization.cpp index d99fc36..a1daf83 100644 --- a/service/things-manager/sdk/src/GroupSynchronization.cpp +++ b/service/things-manager/sdk/src/GroupSynchronization.cpp @@ -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; -- 2.7.4