[Scene-Manager] Fix for the request/response mismatch for execute scene API 11/19711/7
authorJay Sharma <jay.sharma@samsung.com>
Wed, 10 May 2017 03:13:56 +0000 (08:43 +0530)
committerUze Choi <uzchoi@samsung.com>
Thu, 11 May 2017 01:34:13 +0000 (01:34 +0000)
    - Added mutex lock in reponse handler of execute scene API.
    - Unit test case fix.

Bug : https://jira.iotivity.org/browse/IOT-2100
Change-Id: I89a737c3f6f09f7b2c648708366d193cac1f278f
Signed-off-by: Jay Sharma <jay.sharma@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/19711
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/scene-manager/src/SceneCollectionResource.cpp
service/scene-manager/src/SceneCollectionResource.h
service/scene-manager/unittests/SceneTest.cpp

index 7409e79..6f2a547 100755 (executable)
@@ -431,6 +431,7 @@ namespace OIC
         void SceneCollectionResource::SceneExecuteResponseHandler::
         onResponse(const RCSResourceAttributes & /*attributes*/, int errorCode)
         {
+            std::unique_lock<std::mutex> responseLock(m_responseMutex);
             m_responseMembers++;
             if (errorCode != SCENE_RESPONSE_SUCCESS && m_errorCode != errorCode)
             {
@@ -438,6 +439,13 @@ namespace OIC
             }
             if (m_responseMembers == m_numOfMembers)
             {
+               /* Explicitly unlocking the unique_lock.
+                * Reason:- As we are using the scope lock using unique_lock,
+                * it will be released once it goes out of scope,
+                * In this case, lock will be acquired till application callback
+                * returns. So, its better to release the lock explicitly.
+                */
+                responseLock.unlock();
                 m_cb(m_errorCode);
             }
         }
index f625df6..c0c9c69 100755 (executable)
@@ -86,6 +86,7 @@ namespace OIC
                 int m_errorCode;
                 std::weak_ptr<SceneCollectionResource> m_owner;
                 SceneExecuteCallback m_cb;
+                std::mutex m_responseMutex;
 
                 static SceneExecuteResponseHandler::Ptr createExecuteHandler(
                         const SceneCollectionResource::Ptr, SceneExecuteCallback);
index 80f250e..ff63d0e 100755 (executable)
@@ -193,7 +193,7 @@ TEST_F(SceneTest, executeScene)
     pScene1->addNewSceneAction(pRemoteResource2, KEY_2, VALUE_2);
 
     pScene1->execute(executeCallback);
-    waitForCb(100);
+    waitForCb(3000);
 }
 
 TEST_F(SceneTest, executeSceneUsingEmptyCallback)