Fixed locking of notification observe callback
authorAndriy Gudz <a.gudz@samsung.com>
Thu, 18 May 2017 12:36:48 +0000 (15:36 +0300)
committerAndriy Gudz <a.gudz@samsung.com>
Thu, 18 May 2017 12:36:48 +0000 (15:36 +0300)
device_core/README.md
device_core/iotivity_lib/src/iotivity.cpp
device_core/utest/test_iot_notification.cpp
device_core/utest/test_nmlibapi.cpp

index 4f830ce..5a3fb5b 100644 (file)
@@ -4,7 +4,7 @@
 
 Install package dependency:
 ```sh
-sudo apt-get install gbs cmake libboost-all-dev libgtest-dev
+sudo apt-get install gbs cmake libboost-all-dev libgtest-dev libsystemd-dev
 ```
 
 Compile gtest shared libraries:
index ffd2a7d..7eae00a 100644 (file)
@@ -92,6 +92,7 @@ struct Params
     PresenceHook presence_hook;
     std::mutex owned_mutex;
     std::shared_ptr<OCResource> notificationResource;
+    std::mutex notificationMtx;
 };
 
 IoTivity* IoTivity::instance = nullptr;
@@ -449,7 +450,6 @@ void IoTivity::subscribeNotifications(NM_NotificationCb callback, void* userData
     guardUnauthorized();
 
     std::mutex mtx;
-    std::mutex curResourceLock;
     std::unique_lock<std::mutex> lock(mtx);
     std::condition_variable condVar;
 
@@ -490,7 +490,7 @@ void IoTivity::subscribeNotifications(NM_NotificationCb callback, void* userData
 
     auto foundCb = [&](std::shared_ptr<OCResource> resource)
     {
-        lock_guard<std::mutex> lock(curResourceLock);
+        lock_guard<std::mutex> curResourceLock(params->notificationMtx);
 
         if(!params->notificationResource)
         {
index 356c802..968c205 100644 (file)
@@ -93,7 +93,6 @@ TEST_F(TestIotNotification, correct)
         ADD_FAILURE() << e.what();
     }
 
-    cout << "iot->unsubscribeNotifications();" << endl << flush;
     iot->unsubscribeNotifications();
     userDataCheck.notificationCV.wait_for(notificationLock, std::chrono::seconds(10));
 
index 36be15c..45ac0a3 100644 (file)
@@ -89,7 +89,6 @@ TEST(test_nmlibapi, notificationCorrect)
     ASSERT_EQ(EC_OK, NM_subscribeNotifications(ctx, notificationCb, userDataCheck));
     notificationCV.wait_for(notificationLock, std::chrono::seconds(10));
 
-    cout << "NM_unsubscribeNotifications(ctx);";
     NM_unsubscribeNotifications(ctx);
     notificationCV.wait_for(notificationLock, std::chrono::seconds(10));