Move getWindowRoot() implementation to DeviceImpl 53/291053/3
authorDaekwang Ryu <dkdk.ryu@samsung.com>
Thu, 6 Apr 2023 05:16:21 +0000 (14:16 +0900)
committerDaekwang Ryu <dkdk.ryu@samsung.com>
Wed, 12 Apr 2023 08:24:40 +0000 (17:24 +0900)
The getTizenWindowInfo function depends on Tizen platform.
It has been moved to TizenDeviceImpl.

This change helps in running and implementing UTC.

Change-Id: Icfe725a21e9178244ae7b9698c1be13fa60efb95

12 files changed:
libaurum/inc/Impl/MockDeviceImpl.h
libaurum/inc/Impl/TizenDeviceImpl.h
libaurum/inc/Impl/TizenWindow.h [moved from libaurum/inc/TizenWindow.h with 100% similarity]
libaurum/inc/Interface/IDevice.h
libaurum/inc/UiDevice.h
libaurum/meson.build
libaurum/src/Impl/MockDeviceImpl.cc
libaurum/src/Impl/TizenDeviceImpl.cc
libaurum/src/Impl/TizenWindow.cc [moved from libaurum/src/TizenWindow.cc with 100% similarity]
libaurum/src/Impl/meson.build
libaurum/src/UiDevice.cc
libaurum/src/meson.build

index 4631912..e387a8e 100644 (file)
@@ -19,6 +19,7 @@
 #define _MOCK_DEVICE_IMPL_H_
 
 #include "config.h"
+#include "AccessibleNode.h"
 #include "IDevice.h"
 
 #include <set>
@@ -173,6 +174,11 @@ public:
      */
     const Size2D<int> getScreenSize() override;
 
+    /**
+     * @copydoc IDevice::getWindowRoot()
+     */
+    std::vector<std::shared_ptr<AccessibleNode>> getWindowRoot() const override;
+
 protected:
     /**
      * @brief TBD
index 774841c..e73a564 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "config.h"
 #include "IDevice.h"
+#include "TizenWindow.h"
 
 #include <set>
 #include <efl_util.h>
@@ -135,6 +136,11 @@ public:
      */
     const Size2D<int> getScreenSize() override;
 
+    /**
+     * @copydoc IDevice::getWindowRoot()
+     */
+    std::vector<std::shared_ptr<AccessibleNode>> getWindowRoot() const override;
+
 protected:
     /**
      * @brief Press and release given key during duration time.
@@ -186,6 +192,15 @@ private:
      */
     int stopTimer(void);
 
+    /**
+     * @brief Gets currently window information from window system.
+     *
+     * @return TizenWindow ptr vector
+     *
+     * @since_tizen 7.0
+     */
+    std::vector<std::shared_ptr<TizenWindow>> getTizenWindowInfo() const;
+
 private:
     efl_util_inputgen_h mFakeTouchHandle;
     efl_util_inputgen_h mFakeKeyboardHandle;
@@ -209,6 +224,7 @@ private:
      */
     Size2D<int> mScreenSize;
     static std::mutex CaptureMutex;
+    static std::vector<std::shared_ptr<TizenWindow>> mTizenWindows;
 };
 
 }
index e501b7e..5dc6314 100644 (file)
 
 #include "config.h"
 #include "Size2D.h"
+#include "AccessibleNode.h"
 #include <string>
 
+
 namespace Aurum {
 
 /**
@@ -290,6 +292,15 @@ public:
      * @since_tizen 6.5
      */
     virtual const Size2D<int> getScreenSize() = 0;
+
+    /**
+     * @brief Gets currently enabled applications root window.
+     *
+     * @return AccessibleNode ptr vector
+     *
+     * @since_tizen 7.5
+     */
+    virtual std::vector<std::shared_ptr<AccessibleNode>> getWindowRoot() const = 0;
 };
 
 }
index 1c6a49b..f1369df 100644 (file)
@@ -22,7 +22,6 @@
 
 #include "UiObject.h"
 #include "UiSelector.h"
-#include "TizenWindow.h"
 
 #include "IDevice.h"
 #include "ISearchable.h"
@@ -403,16 +402,7 @@ public:
      *
      * @since_tizen 6.5
      */
-    std::vector<std::shared_ptr<AccessibleNode>> getWindowRoot() const;
-
-    /**
-     * @brief Gets currently window information from window system.
-     *
-     * @return TizenWindow ptr vector
-     *
-     * @since_tizen 7.0
-     */
-    std::vector<std::shared_ptr<TizenWindow>> getTizenWindowInfo() const;
+    std::vector<std::shared_ptr<AccessibleNode>> getWindowRoot() const override;
 
 #ifdef MQTT_ENABLED
     /**
@@ -501,7 +491,6 @@ public:
 private:
     IDevice *mDeviceImpl;
     const Waiter *mWaiter;
-    static std::vector<std::shared_ptr<TizenWindow>> mTizenWindows;
     bool mIsWithSA;
 #ifdef MQTT_ENABLED
     static std::shared_ptr<ScreenAnalyzerWatcher> mSAWatcher;
index 58e8e18..7e31175 100644 (file)
@@ -4,7 +4,6 @@ libaurum_install_inc = [
   './inc/UiDevice.h',
   './inc/UiObject.h',
   './inc/UiSelector.h',
-  './inc/TizenWindow.h',
   './inc/Sel.h',
   './inc/Until.h',
   './inc/Waiter.h',
index 3d3ea8f..1f4c8dd 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #include "Aurum.h"
-
+#include "AccessibleWatcher.h"
 #include "MockDeviceImpl.h"
 
 #include <functional>
@@ -265,3 +265,23 @@ long long MockDeviceImpl::timeStamp(void)
     long long rtn = (t.tv_sec + t.tv_nsec/NANO_SEC) * MICRO_SEC;
     return rtn;
 }
+
+std::vector<std::shared_ptr<AccessibleNode>> MockDeviceImpl::getWindowRoot() const
+{
+    std::vector<std::shared_ptr<AccessibleNode>> ret{};
+
+    auto apps = AccessibleWatcher::getInstance()->getApplications();
+
+    for (auto app : apps)
+    {
+        auto wins = app->getWindows();
+        std::transform(wins.begin(), wins.end(), std::back_inserter(ret),
+            [&](std::shared_ptr<AccessibleWindow> window) {
+                 return window->getAccessibleNode();
+             }
+        );
+    }
+
+    return ret;
+}
+
index 273bd9c..84ac438 100644 (file)
@@ -31,6 +31,7 @@
 #include <tdm_helper.h>
 #include <tbm_surface.h>
 #include <system_info.h>
+#include <gio/gio.h>
 
 using namespace Aurum;
 using namespace AurumInternal;
@@ -38,8 +39,14 @@ using namespace AurumInternal;
 #define NANO_SEC 1000000000.0
 #define MICRO_SEC 1000000
 
+#define WM_BUS_NAME "org.enlightenment.wm"
+#define WM_OBJECT_PATH "/org/enlightenment/wm"
+#define WM_INTERFACE_NAME "org.enlightenment.wm.proc"
+#define WM_METHOD_NAME_INFO "GetVisibleWinInfo_v2"
 
 std::mutex TizenDeviceImpl::CaptureMutex = std::mutex{};
+std::vector<std::shared_ptr<TizenWindow>> TizenDeviceImpl::mTizenWindows;
+static GDBusConnection *system_conn;
 
 TizenDeviceImpl::TizenDeviceImpl()
 : mFakeTouchHandle{0}, mFakeKeyboardHandle{0}, mFakeWheelHandle{0}, tStart{}, isTimerStarted{false}, mTouchSeq{}
@@ -422,3 +429,145 @@ bool TizenDeviceImpl::releaseTouchSeqNumber(int seq)
     }
     return false;
 }
+
+std::vector<std::shared_ptr<AccessibleNode>> TizenDeviceImpl::getWindowRoot() const
+{
+    LOGI("Request window info");
+    getTizenWindowInfo();
+
+    std::vector<std::shared_ptr<AccessibleNode>> ret{};
+    std::unordered_map<int, std::shared_ptr<AccessibleApplication>> pidToAppNode{};
+
+    auto apps = AccessibleWatcher::getInstance()->getApplications();
+    for (auto app : apps)
+    {
+        app->getAccessibleNode()->updateName();
+        app->getAccessibleNode()->updatePid();
+        LOGI("App(%s) Pid(%d)", app->getPackageName().c_str(), app->getAccessibleNode()->getPid());
+        pidToAppNode[app->getAccessibleNode()->getPid()] = app;
+    }
+
+    for (auto tWin : mTizenWindows)
+    {
+        LOGI("Visible win (%d) (%d %d %d %d) (%s)", tWin->getPid(), tWin->getWindowGeometry().mTopLeft.x, tWin->getWindowGeometry().mTopLeft.y, tWin->getWindowGeometry().width(),
+            tWin->getWindowGeometry().height(), tWin->getName().c_str());
+
+        if (pidToAppNode.count(tWin->getPid()) == 0) continue;
+
+        LOGI("Active App : (%s) (%d)", tWin->getName().c_str(), tWin->getPid());
+        auto wins = pidToAppNode[tWin->getPid()]->getWindows();
+        std::transform(wins.begin(), wins.end(), std::back_inserter(ret),
+             [&](std::shared_ptr<AccessibleWindow> window) {
+                 window->getAccessibleNode()->updateApplication();
+                 LOGI("Target window add pkg: (%s), name (%s)", window->getAccessibleNode()->getPkg().c_str(), window->getTitle().c_str());
+                 return window->getAccessibleNode();
+             }
+        );
+
+        pidToAppNode.erase(tWin->getPid());
+    }
+
+    return ret;
+}
+
+std::vector<std::shared_ptr<TizenWindow>> TizenDeviceImpl::getTizenWindowInfo() const
+{
+    GError *err = NULL;
+    GDBusMessage *msg;
+    GDBusMessage *reply;
+    GDBusConnection *conn;
+    GVariant *body;
+    GVariantIter *iter = NULL;
+    int idx = 0;
+    int pid;
+    int x;
+    int y;
+    int w;
+    int h;
+    gboolean transformed;
+    gboolean alpha;
+    int opaque;
+    int visibility;
+    gboolean focused;
+    gboolean mapped;
+    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;
+        }
+        system_conn = conn;
+    }
+
+    msg = g_dbus_message_new_method_call(WM_BUS_NAME,
+            WM_OBJECT_PATH,
+            WM_INTERFACE_NAME,
+            WM_METHOD_NAME_INFO);
+    if (msg == NULL) {
+        LOGE("g_dbus_message_new_method_call() is failed.");
+        return mTizenWindows;
+    }
+
+    reply = g_dbus_connection_send_message_with_reply_sync(system_conn, msg,
+            G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
+
+    if (!reply) {
+        if (err != NULL) {
+            LOGE("Failed to get info [%s]", err->message);
+            g_error_free(err);
+        }
+        goto out;
+    }
+
+    body = g_dbus_message_get_body(reply);
+    if (!body) {
+        LOGE("Failed to get body");
+        goto out;
+    }
+
+    g_variant_get(body, "(a(iiiiibbiibbis))", &iter);
+    if (!iter) {
+        LOGE("Failed to get iter");
+        goto out;
+    }
+
+    LOGI("%-3s | %-6s | %-4s | %-4s | %-4s | %-4s | %-5s | %-5s | %-6s | %-3s | %-7s | %-6s | %-5s | %-20s", "No" ,"PID", "X", "Y", "W", "H", "Trans", "Alpha", "Opaque", "Vis", "Focused", "Mapped", "Layer", "Name");
+    while (g_variant_iter_loop(iter, "(iiiiibbiibbis)",
+                &pid,
+                &x,
+                &y,
+                &w,
+                &h,
+                &transformed,
+                &alpha,
+                &opaque,
+                &visibility,
+                &focused,
+                &mapped,
+                &layer,
+                &name)) {
+        LOGI("%-3d | %-6d | %-4d | %-4d | %-4d | %-4d | %-5d | %-5d | %-6d | %-3d | %-7d | %-6d | %-5d | %-20s", idx++, pid, x,y,w,h, transformed, alpha, opaque, visibility, focused, mapped, layer, name);
+        if (visibility == 0 && pid > 0)
+        {
+            Rect<int> geometry = {x,  y, w, h};
+            std::string winName(name);
+            mTizenWindows.push_back(std::make_shared<Aurum::TizenWindow>(pid, geometry, transformed, alpha, opaque, visibility, focused, mapped, layer, winName));
+        }
+    }
+
+out:
+    if (iter)
+        g_variant_iter_free(iter);
+    if (msg)
+        g_object_unref(msg);
+    if (reply)
+        g_object_unref(reply);
+
+    return mTizenWindows;
+}
index 04bdacc..6feed58 100644 (file)
@@ -1,6 +1,7 @@
 if get_option('tizen') == true
     libaurum_src += [
         files('TizenDeviceImpl.cc'),
+        files('TizenWindow.cc'),
     ]
 endif
 
index 7438bbf..a8f40e7 100644 (file)
 #include <thread>
 #include <algorithm>
 #include <iostream>
-#include <gio/gio.h>
 #include <unordered_set>
 #include <unordered_map>
 
 using namespace Aurum;
 using namespace AurumInternal;
 
-#define WM_BUS_NAME "org.enlightenment.wm"
-#define WM_OBJECT_PATH "/org/enlightenment/wm"
-#define WM_INTERFACE_NAME "org.enlightenment.wm.proc"
-#define WM_METHOD_NAME_INFO "GetVisibleWinInfo_v2"
-
-std::vector<std::shared_ptr<TizenWindow>> UiDevice::mTizenWindows;
 std::once_flag UiDevice::mOnceFlag;
-static GDBusConnection *system_conn;
 
 #ifdef MQTT_ENABLED
 std::shared_ptr<ScreenAnalyzerWatcher> UiDevice::mSAWatcher;
@@ -86,146 +78,9 @@ std::shared_ptr<UiDevice> UiDevice::getInstance(IDevice *deviceImpl)
     return device;
 }
 
-std::vector<std::shared_ptr<TizenWindow>> UiDevice::getTizenWindowInfo() const
-{
-    GError *err = NULL;
-    GDBusMessage *msg;
-    GDBusMessage *reply;
-    GDBusConnection *conn;
-    GVariant *body;
-    GVariantIter *iter = NULL;
-    int idx = 0;
-    int pid;
-    int x;
-    int y;
-    int w;
-    int h;
-    gboolean transformed;
-    gboolean alpha;
-    int opaque;
-    int visibility;
-    gboolean focused;
-    gboolean mapped;
-    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;
-        }
-        system_conn = conn;
-    }
-
-    msg = g_dbus_message_new_method_call(WM_BUS_NAME,
-            WM_OBJECT_PATH,
-            WM_INTERFACE_NAME,
-            WM_METHOD_NAME_INFO);
-    if (msg == NULL) {
-        LOGE("g_dbus_message_new_method_call() is failed.");
-        return mTizenWindows;
-    }
-
-    reply = g_dbus_connection_send_message_with_reply_sync(system_conn, msg,
-            G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
-
-    if (!reply) {
-        if (err != NULL) {
-            LOGE("Failed to get info [%s]", err->message);
-            g_error_free(err);
-        }
-        goto out;
-    }
-
-    body = g_dbus_message_get_body(reply);
-    if (!body) {
-        LOGE("Failed to get body");
-        goto out;
-    }
-
-    g_variant_get(body, "(a(iiiiibbiibbis))", &iter);
-    if (!iter) {
-        LOGE("Failed to get iter");
-        goto out;
-    }
-
-    LOGI("%-3s | %-6s | %-4s | %-4s | %-4s | %-4s | %-5s | %-5s | %-6s | %-3s | %-7s | %-6s | %-5s | %-20s", "No" ,"PID", "X", "Y", "W", "H", "Trans", "Alpha", "Opaque", "Vis", "Focused", "Mapped", "Layer", "Name");
-    while (g_variant_iter_loop(iter, "(iiiiibbiibbis)",
-                &pid,
-                &x,
-                &y,
-                &w,
-                &h,
-                &transformed,
-                &alpha,
-                &opaque,
-                &visibility,
-                &focused,
-                &mapped,
-                &layer,
-                &name)) {
-        LOGI("%-3d | %-6d | %-4d | %-4d | %-4d | %-4d | %-5d | %-5d | %-6d | %-3d | %-7d | %-6d | %-5d | %-20s", idx++, pid, x,y,w,h, transformed, alpha, opaque, visibility, focused, mapped, layer, name);
-        if (visibility == 0 && pid > 0)
-        {
-            Rect<int> geometry = {x,  y, w, h};
-            std::string winName(name);
-            mTizenWindows.push_back(std::make_shared<Aurum::TizenWindow>(pid, geometry, transformed, alpha, opaque, visibility, focused, mapped, layer, winName));
-        }
-    }
-
-out:
-    if (iter)
-        g_variant_iter_free(iter);
-    if (msg)
-        g_object_unref(msg);
-    if (reply)
-        g_object_unref(reply);
-
-    return mTizenWindows;
-}
-
 std::vector<std::shared_ptr<AccessibleNode>> UiDevice::getWindowRoot() const
 {
-    LOGI("Request window info");
-    getTizenWindowInfo();
-
-    std::vector<std::shared_ptr<AccessibleNode>> ret{};
-    std::unordered_map<int, std::shared_ptr<AccessibleApplication>> pidToAppNode{};
-
-    auto apps = AccessibleWatcher::getInstance()->getApplications();
-    for (auto app : apps)
-    {
-        app->getAccessibleNode()->updateName();
-        app->getAccessibleNode()->updatePid();
-        LOGI("App(%s) Pid(%d)", app->getPackageName().c_str(), app->getAccessibleNode()->getPid());
-        pidToAppNode[app->getAccessibleNode()->getPid()] = app;
-    }
-
-    for (auto tWin : mTizenWindows)
-    {
-        LOGI("Visible win (%d) (%d %d %d %d) (%s)", tWin->getPid(), tWin->getWindowGeometry().mTopLeft.x, tWin->getWindowGeometry().mTopLeft.y, tWin->getWindowGeometry().width(),
-            tWin->getWindowGeometry().height(), tWin->getName().c_str());
-
-        if (pidToAppNode.count(tWin->getPid()) == 0) continue;
-
-        LOGI("Active App : (%s) (%d)", tWin->getName().c_str(), tWin->getPid());
-        auto wins = pidToAppNode[tWin->getPid()]->getWindows();
-        std::transform(wins.begin(), wins.end(), std::back_inserter(ret),
-             [&](std::shared_ptr<AccessibleWindow> window) {
-                 window->getAccessibleNode()->updateApplication();
-                 LOGI("Target window add pkg: (%s), name (%s)", window->getAccessibleNode()->getPkg().c_str(), window->getTitle().c_str());
-                 return window->getAccessibleNode();
-             }
-        );
-
-        pidToAppNode.erase(tWin->getPid());
-    }
-
-    return ret;
+    return mDeviceImpl->getWindowRoot();
 }
 
 bool UiDevice::hasObject(const std::shared_ptr<UiSelector> selector) const
index 7e6a215..caae22d 100644 (file)
@@ -11,7 +11,6 @@ libaurum_src += [
   files('A11yEvent.cc'),
   files('A11yEventHandler.cc'),
   files('AurumXML.cc'),
-  files('TizenWindow.cc'),
 ]
 
 if get_option('mqtt_enabled') == true