TizenDeviceImpl: fix thread safety 06/300306/2 accepted/tizen/unified/20231024.032154
authorHosang Kim <hosang12.kim@samsung.com>
Fri, 20 Oct 2023 06:57:40 +0000 (15:57 +0900)
committerHosang Kim <hosang12.kim@samsung.com>
Fri, 20 Oct 2023 07:01:03 +0000 (16:01 +0900)
Remove static variable for thread safe

Change-Id: I512484329c7c13e5c1bab56c6df3e73ea6bb94fe

libaurum/inc/Impl/TizenDeviceImpl.h
libaurum/src/Impl/TizenDeviceImpl.cc

index df9970a..e62b7a6 100644 (file)
@@ -200,7 +200,7 @@ private:
      *
      * @since_tizen 7.0
      */
-    std::vector<std::shared_ptr<TizenWindow>> getTizenWindowInfo() const;
+    void getTizenWindowInfo(std::vector<std::shared_ptr<TizenWindow>> &mTizenWindows) const;
 
 private:
     efl_util_inputgen_h mFakeTouchHandle;
@@ -225,7 +225,6 @@ private:
      */
     Size2D<int> mScreenSize;
     static std::mutex CaptureMutex;
-    static std::vector<std::shared_ptr<TizenWindow>> mTizenWindows;
 };
 
 }
index c99b130..47fc3b6 100644 (file)
@@ -45,7 +45,6 @@ using namespace AurumInternal;
 #define WM_METHOD_NAME_INFO "GetVisibleWinInfo_v3"
 
 std::mutex TizenDeviceImpl::CaptureMutex = std::mutex{};
-std::vector<std::shared_ptr<TizenWindow>> TizenDeviceImpl::mTizenWindows;
 static GDBusConnection *system_conn;
 
 TizenDeviceImpl::TizenDeviceImpl()
@@ -442,7 +441,9 @@ bool TizenDeviceImpl::releaseTouchSeqNumber(int seq)
 std::vector<std::shared_ptr<AccessibleNode>> TizenDeviceImpl::getWindowRoot() const
 {
     LOGI("Request window info");
-    getTizenWindowInfo();
+
+    std::vector<std::shared_ptr<TizenWindow>> mTizenWindows{};
+    getTizenWindowInfo(mTizenWindows);
 
     std::vector<std::shared_ptr<AccessibleNode>> ret{};
     std::unordered_map<int, std::shared_ptr<AccessibleApplication>> pidToAppNode{};
@@ -482,7 +483,7 @@ std::vector<std::shared_ptr<AccessibleNode>> TizenDeviceImpl::getWindowRoot() co
     return ret;
 }
 
-std::vector<std::shared_ptr<TizenWindow>> TizenDeviceImpl::getTizenWindowInfo() const
+void TizenDeviceImpl::getTizenWindowInfo(std::vector<std::shared_ptr<TizenWindow>> &mTizenWindows) const
 {
     GError *err = NULL;
     GDBusMessage *msg;
@@ -507,14 +508,12 @@ std::vector<std::shared_ptr<TizenWindow>> TizenDeviceImpl::getTizenWindowInfo()
     int layer;
     char *name;
 
-    mTizenWindows.clear();
-
     if (system_conn == NULL) {
         conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
         if (conn == NULL) {
             LOGE("g_bus_get_sync() is failed. %s", err->message);
             g_error_free(err);
-            return mTizenWindows;
+            return;
         }
         system_conn = conn;
     }
@@ -525,7 +524,7 @@ std::vector<std::shared_ptr<TizenWindow>> TizenDeviceImpl::getTizenWindowInfo()
             WM_METHOD_NAME_INFO);
     if (msg == NULL) {
         LOGE("g_dbus_message_new_method_call() is failed.");
-        return mTizenWindows;
+        return;
     }
 
     reply = g_dbus_connection_send_message_with_reply_sync(system_conn, msg,
@@ -584,6 +583,4 @@ out:
         g_object_unref(msg);
     if (reply)
         g_object_unref(reply);
-
-    return mTizenWindows;
 }