libaurum: apply smart pointer wider and extract impl out
authorWonki Kim <wonki_.kim@samsung.com>
Thu, 13 Aug 2020 02:35:45 +0000 (11:35 +0900)
committerJongmin Lee <jm105.lee@samsung.com>
Thu, 27 Aug 2020 05:00:13 +0000 (14:00 +0900)
this patch refactors few things.
* smart pointer
  smart pointer has been used but raw pointers are used in some place.
  this patch refactor libaurum to apply smart pointers wider.
* extracting implementation out
  extract low level dependency(atspi) out of base classes to make code mockable

Change-Id: I680015f80e6538573be12a5572e49a45345f9b96

78 files changed:
libaurum/inc/Accessibility/AccessibleApplication.h [new file with mode: 0644]
libaurum/inc/Accessibility/AccessibleNode.h [new file with mode: 0644]
libaurum/inc/Accessibility/AccessibleUtils.h [moved from libaurum/inc/AccessibleUtils.h with 62% similarity]
libaurum/inc/Accessibility/AccessibleWatcher.h [new file with mode: 0644]
libaurum/inc/Accessibility/AccessibleWindow.h [new file with mode: 0644]
libaurum/inc/AccessibleNode.h [deleted file]
libaurum/inc/Comparer.h
libaurum/inc/ISearchable.h
libaurum/inc/Impl/Accessibility/AtspiAccessibleApplication.h [new file with mode: 0644]
libaurum/inc/Impl/Accessibility/AtspiAccessibleNode.h [new file with mode: 0644]
libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h [moved from libaurum/inc/AccessibleWatcher.h with 56% similarity]
libaurum/inc/Impl/Accessibility/AtspiAccessibleWindow.h [new file with mode: 0644]
libaurum/inc/Impl/Accessibility/MockAccessibleApplication.h [new file with mode: 0644]
libaurum/inc/Impl/Accessibility/MockAccessibleNode.h [new file with mode: 0644]
libaurum/inc/Impl/Accessibility/MockAccessibleWatcher.h [new file with mode: 0644]
libaurum/inc/Impl/Accessibility/MockAccessibleWindow.h [new file with mode: 0644]
libaurum/inc/Impl/MockDeviceImpl.h [new file with mode: 0644]
libaurum/inc/Impl/TizenDeviceImpl.h [moved from libaurum/inc/DeviceImpl/TizenImpl.h with 94% similarity]
libaurum/inc/Misc/Point2D.h [new file with mode: 0644]
libaurum/inc/Misc/Rect.h [new file with mode: 0644]
libaurum/inc/PartialMatch.h
libaurum/inc/UiDevice.h
libaurum/inc/UiObject.h
libaurum/inc/UiScrollable.h [new file with mode: 0644]
libaurum/inc/UiSelector.h
libaurum/inc/Until.h
libaurum/meson.build
libaurum/src/Accessibility/AccessibleApplication.cc [new file with mode: 0644]
libaurum/src/Accessibility/AccessibleNode.cc [new file with mode: 0644]
libaurum/src/Accessibility/AccessibleUtils.cc [moved from libaurum/src/AccessibleUtils.cc with 100% similarity]
libaurum/src/Accessibility/AccessibleWatcher.cc [new file with mode: 0644]
libaurum/src/Accessibility/AccessibleWindow.cc [new file with mode: 0644]
libaurum/src/Accessibility/meson.build [new file with mode: 0644]
libaurum/src/AccessibleWatcher.cc [deleted file]
libaurum/src/Comparer.cc
libaurum/src/Impl/Accessibility/AtspiAccessibleApplication.cc [new file with mode: 0644]
libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc [moved from libaurum/src/AccessibleNode.cc with 59% similarity]
libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc [new file with mode: 0644]
libaurum/src/Impl/Accessibility/AtspiAccessibleWindow.cc [new file with mode: 0644]
libaurum/src/Impl/Accessibility/MockAccessibleApplication.cc [new file with mode: 0644]
libaurum/src/Impl/Accessibility/MockAccessibleNode.cc [new file with mode: 0644]
libaurum/src/Impl/Accessibility/MockAccessibleWatcher.cc [new file with mode: 0644]
libaurum/src/Impl/Accessibility/MockAccessibleWindow.cc [new file with mode: 0644]
libaurum/src/Impl/Accessibility/meson.build [new file with mode: 0644]
libaurum/src/Impl/MockDeviceImpl.cc [new file with mode: 0644]
libaurum/src/Impl/TizenDeviceImpl.cc [moved from libaurum/src/DeviceImpl/TizenImpl.cc with 79% similarity]
libaurum/src/Impl/meson.build [new file with mode: 0644]
libaurum/src/PartialMatch.cc
libaurum/src/UiDevice.cc
libaurum/src/UiObject.cc
libaurum/src/UiScrollable.cc [new file with mode: 0644]
libaurum/src/UiSelector.cc
libaurum/src/Until.cc
libaurum/src/Waiter.cc
libaurum/src/meson.build [new file with mode: 0644]
org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h
org.tizen.aurum-bootstrap/inc/Commands/ClearCommand.h
org.tizen.aurum-bootstrap/inc/Commands/FindElementCommand.h
org.tizen.aurum-bootstrap/inc/ObjectMapper.h
org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc
org.tizen.aurum-bootstrap/src/Commands/ClearCommand.cc
org.tizen.aurum-bootstrap/src/Commands/ClickCommand.cc
org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc
org.tizen.aurum-bootstrap/src/Commands/FlickCommand.cc
org.tizen.aurum-bootstrap/src/Commands/GetAttributeCommand.cc
org.tizen.aurum-bootstrap/src/Commands/GetDeviceTimeCommand.cc
org.tizen.aurum-bootstrap/src/Commands/GetSizeCommand.cc
org.tizen.aurum-bootstrap/src/Commands/GetValueCommand.cc
org.tizen.aurum-bootstrap/src/Commands/LongClickCommand.cc
org.tizen.aurum-bootstrap/src/Commands/SendKeyCommand.cc
org.tizen.aurum-bootstrap/src/Commands/SetValueCommand.cc
org.tizen.aurum-bootstrap/src/Commands/SyncCommand.cc
org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc
org.tizen.aurum-bootstrap/src/Commands/TouchDownCommand.cc
org.tizen.aurum-bootstrap/src/Commands/TouchMoveCommand.cc
org.tizen.aurum-bootstrap/src/Commands/TouchUpCommand.cc
org.tizen.aurum-bootstrap/src/ObjectMapper.cc
tests/ua_test.cpp

diff --git a/libaurum/inc/Accessibility/AccessibleApplication.h b/libaurum/inc/Accessibility/AccessibleApplication.h
new file mode 100644 (file)
index 0000000..5daa948
--- /dev/null
@@ -0,0 +1,25 @@
+#pragma once
+
+#include "AccessibleWindow.h"
+#include "AccessibleNode.h"
+
+#include <memory>
+
+class AccessibleApplication {
+public:
+    AccessibleApplication(std::shared_ptr<AccessibleNode> node);
+    virtual ~AccessibleApplication();
+
+public:
+    std::shared_ptr<AccessibleNode> getAccessibleNode();
+    bool isActive(void);
+
+public:
+    virtual std::vector<std::shared_ptr<AccessibleWindow>> getWindows(void) = 0;
+    virtual std::vector<std::shared_ptr<AccessibleWindow>> getActiveWindows(void);
+    virtual std::string getPackageName(void) = 0;
+
+private:
+    std::shared_ptr<AccessibleNode> mNode;
+};
+
diff --git a/libaurum/inc/Accessibility/AccessibleNode.h b/libaurum/inc/Accessibility/AccessibleNode.h
new file mode 100644 (file)
index 0000000..69b2a89
--- /dev/null
@@ -0,0 +1,340 @@
+#ifndef ACCESSIBLE_NODE_H
+#define ACCESSIBLE_NODE_H
+
+#include <map>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "AccessibleUtils.h"
+#include "Rect.h"
+#include "config.h"
+
+/**
+ * @brief AccessibleNodeInterface enum class
+ * @since_tizen 5.5
+ */
+enum class AccessibleNodeInterface {
+    ACTION          = 0x0001,
+    COLLECTION      = 0X0002,
+    COMPONENT       = 0X0004,
+    DOCUMENT        = 0X0008,
+
+    EDITABLETEXT    = 0X0010,
+    HYPERTEXT       = 0X0020,
+    IMAGE           = 0X0040,
+    SELECTION       = 0X0080,
+
+    TEXT            = 0X0100,
+    VALUE           = 0X0200,
+    ACCESSIBLE      = 0X0400,
+    TABLE           = 0X0800,
+
+    TABLECELL       = 0X1000,
+};
+
+/**
+ * @brief NodeFeatureProperties enum class
+ * @since_tizen 5.5
+ */
+enum class NodeFeatureProperties {
+    CHECKABLE       = 0x0001,
+    CHECKED         = 0X0002,
+    CLICKABLE       = 0X0004,
+    ENABLED         = 0X0008,
+
+    FOCUSABLE       = 0X0010,
+    FOCUSED         = 0X0020,
+    LONGCLICKABLE   = 0X0040,
+    SCROLLABLE      = 0X0080,
+
+    SELECTABLE      = 0X0100,
+    SELECTED        = 0X0200,
+    VISIBLE         = 0X0400,
+    SHOWING         = 0X0800,
+    ACTIVE          = 0X1000,
+    INVALID         = 0X2000,
+};
+
+class IAccessibleNode {
+public:
+    virtual ~IAccessibleNode() = 0;
+
+    
+};
+
+/**
+ * @brief AccessibleNode Class
+ * @since_tizen 5.5
+ */
+class AccessibleNode {
+public:  // Constructor & Destructor
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    AccessibleNode();
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    virtual ~AccessibleNode();
+
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    virtual int getChildCount() const = 0;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    virtual std::shared_ptr<AccessibleNode> getChildAt(int index) const = 0;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    virtual std::vector<std::shared_ptr<AccessibleNode>> getChildren() const = 0;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    virtual std::shared_ptr<AccessibleNode> getParent() const = 0;
+
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    std::string getText() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    std::string getPkg() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    std::string getRes() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    std::string getRole() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    std::string getType() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    std::string getStyle() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    Rect<int> getBoundingBox() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool isCheckable() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool isChecked() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool isClickable() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool isEnabled() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool isFocusable() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool isFocused() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool isLongClickable() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool isScrollable() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool isSelectable() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool isSelected() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool isVisible() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool isShowing() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool isActive() const;
+
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    void print(int);
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    void print(int, int);
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    virtual void* getRawHandler(void) const = 0;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    virtual void refresh() = 0;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    virtual std::vector<std::string> getActions() const = 0;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    virtual bool doAction(std::string action) = 0;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    virtual void setValue(std::string text) = 0;
+
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool isSupporting(AccessibleNodeInterface thisIface) const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool hasFeatureProperty(NodeFeatureProperties prop) const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    void setFeatureProperty(NodeFeatureProperties prop, bool has);
+
+protected:
+    /**
+     * @brief TBD
+     */
+    std::string mText;
+
+    /**
+     * @brief TBD
+     */
+    std::string mPkg;
+
+    /**
+     * @brief TBD
+     */
+    std::string mRole;
+
+    /**
+     * @brief TBD
+     */
+    std::string mRes;
+
+    /**
+     * @brief TBD
+     */
+    std::string mType;
+
+    /**
+     * @brief TBD
+     */
+    std::string mStyle;
+
+    /**
+     * @brief TBD
+     */
+    Rect<int> mBoundingBox;
+
+    /**
+     * @brief TBD
+     */
+    int mSupportingIfaces;
+
+    /**
+     * @brief TBD
+     */
+    int mFeatureProperty;
+
+};
+
+#endif
similarity index 62%
rename from libaurum/inc/AccessibleUtils.h
rename to libaurum/inc/Accessibility/AccessibleUtils.h
index 38d53fe..0fb722a 100644 (file)
@@ -1,10 +1,8 @@
-#ifndef ACCESSIBLE_UTILS_H
-#define ACCESSIBLE_UTILS_H
-
-#include <atspi/atspi.h>
+#pragma once
+//#include <atspi/atspi.h>
 #include <gio/gio.h>
-#include <string.h>
 
+#include <string.h>
 #include <memory>
 
 #include "config.h"
@@ -80,6 +78,35 @@ unique_ptr_gobj<T> make_gobj_ref_unique(T *ptr)
  * @brief TBD
  * @since_tizen 5.5
  */
-char *state_to_char(AtspiStateType state);
+template <class T>
+std::shared_ptr<T> make_gobj_shared(T *ptr)
+{
+    return std::shared_ptr<T>(ptr, [](T *ptr){ if(ptr) g_object_unref(ptr); });
+}
+
+/**
+ * @brief TBD
+ * @since_tizen 5.5
+ */
+template <class T>
+std::shared_ptr<T> make_garray_shared(T *ptr)
+{
+    return std::shared_ptr<T>(ptr,  [](T *ptr){ if(ptr) g_array_free(ptr, 1); });
+}
 
-#endif
\ No newline at end of file
+/**
+ * @brief TBD
+ * @since_tizen 5.5
+ */
+template <class T>
+std::shared_ptr<T> make_gobj_ref_shared(T *ptr)
+{
+    g_object_ref(ptr);
+    return std::shared_ptr<T>(ptr,  [](T *ptr){ if(ptr) g_object_unref(ptr); });
+}
+
+/**
+ * @brief TBD
+ * @since_tizen 5.5
+ */
+//char *state_to_char(AtspiStateType state);
diff --git a/libaurum/inc/Accessibility/AccessibleWatcher.h b/libaurum/inc/Accessibility/AccessibleWatcher.h
new file mode 100644 (file)
index 0000000..d332713
--- /dev/null
@@ -0,0 +1,63 @@
+#ifndef ACCESSIBLE_H
+#define ACCESSIBLE_H
+
+
+#include "AccessibleApplication.h"
+#include "AccessibleWindow.h"
+#include "AccessibleNode.h"
+
+#include "AccessibleUtils.h"
+
+#include <memory>
+#include <vector>
+
+
+#include "config.h"
+
+
+/**
+ * @brief AccessibleWatcher class
+ * @since_tizen 5.5
+ */
+class AccessibleWatcher {
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    virtual ~AccessibleWatcher();
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    static const AccessibleWatcher *getInstance(AccessibleWatcher *watcherImpl = nullptr);
+
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    virtual int getApplicationCount(void) const = 0;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    virtual std::shared_ptr<AccessibleApplication> getApplicationAt(int index) const = 0;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    virtual std::vector<std::shared_ptr<AccessibleApplication>> getApplications(void) const = 0;
+
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    virtual std::vector<std::shared_ptr<AccessibleApplication>> getActiveApplications(void) const;
+};
+
+#endif
diff --git a/libaurum/inc/Accessibility/AccessibleWindow.h b/libaurum/inc/Accessibility/AccessibleWindow.h
new file mode 100644 (file)
index 0000000..44e87c6
--- /dev/null
@@ -0,0 +1,26 @@
+#pragma once
+
+#include "AccessibleNode.h"
+
+#include <string>
+#include <memory>
+
+class AccessibleApplication;
+
+class AccessibleWindow {
+public:
+    AccessibleWindow(std::shared_ptr<AccessibleApplication> app, std::shared_ptr<AccessibleNode> node);
+    virtual ~AccessibleWindow();
+
+public:
+    std::string getTitle(void);
+    bool isShowing();
+    bool isActive();
+
+    std::shared_ptr<AccessibleApplication> getApplication(void);
+    std::shared_ptr<AccessibleNode> getNode(void);
+
+private:
+    std::shared_ptr<AccessibleNode> mNode;
+    std::shared_ptr<AccessibleApplication> mApp;
+};
\ No newline at end of file
diff --git a/libaurum/inc/AccessibleNode.h b/libaurum/inc/AccessibleNode.h
deleted file mode 100644 (file)
index 11dfcc8..0000000
+++ /dev/null
@@ -1,479 +0,0 @@
-#ifndef ACCESSIBLE_NODE_H
-#define ACCESSIBLE_NODE_H
-#include <atspi/atspi.h>
-
-#include <map>
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "AccessibleUtils.h"
-#include "config.h"
-
-/**
- * @brief AccessibleNodeInterface enum class
- * @since_tizen 5.5
- */
-enum class AccessibleNodeInterface {
-    ACTION = 0x0001,
-    COLLECTION = 0X0002,
-    COMPONENT = 0X0004,
-    DOCUMENT = 0X0008,
-
-    EDITABLETEXT = 0X0010,
-    HYPERTEXT = 0X0020,
-    IMAGE = 0X0040,
-    SELECTION = 0X0080,
-
-    TEXT = 0X0100,
-    VALUE = 0X0200,
-    ACCESSIBLE = 0X0400,
-    TABLE = 0X0800,
-
-    TABLECELL = 0X1000,
-};
-
-/**
- * @brief NodeFeatureProperties enum class
- * @since_tizen 5.5
- */
-enum class NodeFeatureProperties {
-    CHECKABLE = 0x0001,
-    CHECKED = 0X0002,
-    CLICKABLE = 0X0004,
-    ENABLED = 0X0008,
-    FOCUSABLE = 0X0010,
-    FOCUSED = 0X0020,
-    LONGCLICKABLE = 0X0040,
-    SCROLLABLE = 0X0080,
-
-    SELECTABLE = 0X0100,
-    SELECTED = 0X0200,
-    VISIBLE = 0X0400,
-    SHOWING = 0X0800,
-    ACTIVE = 0X0800,
-};
-
-/**
- * @brief Point2d Class
- * @since_tizen 5.5
- */
-template <typename T>
-class Point2D {
-public:
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    Point2D() : x{0}, y{0} {}
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    Point2D(const Point2D &src)
-    {
-        x = src.x;
-        y = src.y;
-    }
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    Point2D(const T &x, const T &y)
-    {
-        this->x = x;
-        this->y = y;
-    }
-
-    /**
-     * @brief TBD
-     */
-    T x;
-
-    /**
-     * @brief TBD
-     */
-    T y;
-};
-
-/**
- * @brief Rect Class
- * @since_tizen 5.5
- */
-template <typename T>
-class Rect {
-public:
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    Rect() : mTopLeft{0, 0}, mBottomRight{0, 0} {}
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    Rect(const Point2D<T> &tl, const Point2D<T> &br)
-        : mTopLeft(tl), mBottomRight(br)
-    {
-    }
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    Rect(const T &x1, const T &y1, const T &x2, const T &y2)
-        : mTopLeft{x1, y1}, mBottomRight{x2, y2}
-    {
-    }
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    Rect(const Rect<T> &src)
-
-    {
-        this->mTopLeft = Point2D<int>{src.mTopLeft};
-        this->mBottomRight = Point2D<int>{src.mBottomRight};
-    }
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    Point2D<T> midPoint() const
-    {
-        return Point2D<T>{mTopLeft.x + static_cast<T>(width() / 2),
-                          mTopLeft.y + static_cast<T>(height() / 2)};
-    }
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    T width() const { return mBottomRight.x - mTopLeft.x; }
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    T height() const { return mBottomRight.y - mTopLeft.y; }
-
-    /**
-     * @brief TBD
-     */
-    Point2D<T> mTopLeft;
-
-    /**
-     * @brief TBD
-     */
-    Point2D<T> mBottomRight;
-};
-
-/**
- * @brief AccessibleNode Class
- * @since_tizen 5.5
- */
-class AccessibleNode {
-public:  // Constructor & Destructor
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    AccessibleNode();
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    AccessibleNode(AtspiAccessible *node);
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    ~AccessibleNode();
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    static std::unique_ptr<AccessibleNode> get(AtspiAccessible *node);
-
-public:
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    int getChildCount() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    std::unique_ptr<AccessibleNode> getChildAt(int index) const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    std::unique_ptr<AccessibleNode> getParent() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    AtspiAccessible *getAccessible() const;
-
-public:
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    std::string getDesc() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    std::string getText() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    std::string getPkg() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    std::string getRes() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    std::string getType() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    std::string getStyle() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    Rect<int> getBoundingBox() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    bool isCheckable() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    bool isChecked() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    bool isClickable() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    bool isEnabled() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    bool isFocusable() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    bool isFocused() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    bool isLongClickable() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    bool isScrollable() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    bool isSelectable() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    bool isSelected() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    bool isVisible() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    bool isShowing() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    bool isActive() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    std::vector<std::string> getActions() const;
-
-public:
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    void print(int) const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    void print(int, int) const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    void refresh() const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    void setValue(std::string text) const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    bool doAction(std::string action) const;
-
-private:
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    bool isSupporting(AccessibleNodeInterface thisIface) const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    bool hasFeatureProperty(NodeFeatureProperties prop) const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    void setFeatureProperty(NodeFeatureProperties prop, bool has) const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    void setFeatureProperty(AtspiStateType type) const;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    static std::map<AtspiAccessible *, AccessibleNode *> mNodeMap;
-
-private:
-    /**
-     * @brief TBD
-     */
-    unique_ptr_gobj<AtspiAccessible> mNode;
-
-    mutable std::string mText;
-
-    /**
-     * @brief TBD
-     */
-    mutable std::string mPkg;
-
-    /**
-     * @brief TBD
-     */
-    mutable std::string mRole;
-
-    /**
-     * @brief TBD
-     */
-    mutable std::string mDesc;
-
-    /**
-     * @brief TBD
-     */
-    mutable std::string mRes;
-
-    /**
-     * @brief TBD
-     */
-    mutable std::string mType;
-
-    /**
-     * @brief TBD
-     */
-    mutable std::string mStyle;
-
-    /**
-     * @brief TBD
-     */
-    mutable Rect<int> mBoundingBox;
-
-    /**
-     * @brief TBD
-     */
-    int mSupportingIfaces;
-
-    /**
-     * @brief TBD
-     */
-    mutable int mFeatureProperty;
-
-    /**
-     * @brief TBD
-     */
-    bool mIsAlive;
-};
-
-#endif
index db146b0..91df714 100644 (file)
@@ -22,7 +22,7 @@ private:
      * @brief TBD
      * @since_tizen 5.5
      */
-    Comparer(const UiDevice *device, const std::shared_ptr<UiSelector> selector,
+    Comparer(const std::shared_ptr<UiDevice> device, const std::shared_ptr<UiSelector> selector,
              const bool &earlyReturn);
 
     /**
@@ -36,31 +36,31 @@ public:
      * @brief TBD
      * @since_tizen 5.5
      */
-    static std::unique_ptr<AccessibleNode>             findObject(const UiDevice *      device,
+    static std::shared_ptr<AccessibleNode>             findObject(const std::shared_ptr<UiDevice> device,
                                                     const std::shared_ptr<UiSelector> selector,
-                                                    const AccessibleNode *root);
+                                                    const std::shared_ptr<AccessibleNode> root);
 
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    static std::vector<std::unique_ptr<AccessibleNode>> findObjects(
-        const UiDevice *device, const std::shared_ptr<UiSelector> selector,
-        const AccessibleNode *root);
+    static std::vector<std::shared_ptr<AccessibleNode>> findObjects(
+        const std::shared_ptr<UiDevice> device, const std::shared_ptr<UiSelector> selector,
+        const std::shared_ptr<AccessibleNode> root);
 
 private:
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    std::vector<std::unique_ptr<AccessibleNode>> findObjects(const AccessibleNode *root);
+    std::vector<std::shared_ptr<AccessibleNode>> findObjects(const std::shared_ptr<AccessibleNode> root);
 
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    std::vector<std::unique_ptr<AccessibleNode>> findObjects(
-        const AccessibleNode *root, const int &index, const int &depth,
+    std::vector<std::shared_ptr<AccessibleNode>> findObjects(
+        const std::shared_ptr<AccessibleNode> root, const int &index, const int &depth,
         std::list<std::shared_ptr<PartialMatch>> &partialMatches);
 
 private:
@@ -68,16 +68,16 @@ private:
      * @brief TBD
      * @since_tizen 5.5
      */
-    std::unique_ptr<PartialMatch> accept(const AccessibleNode *node,
+   /* std::unique_ptr<PartialMatch> accept(const AccessibleNode *node,
                                          const std::shared_ptr<UiSelector> selector,
                                          const int &index, const int &depth,
                                          const int &relDepth);
-
+*/
 private:
     /**
      * @brief TBD
      */
-    const UiDevice *mDevice;
+    const std::shared_ptr<UiDevice> mDevice;
 
     /**
      * @brief TBD
index 06eafed..8695ee7 100644 (file)
@@ -31,14 +31,14 @@ public:
      * @brief TBD
      * @since_tizen 5.5
      */
-    virtual std::unique_ptr<UiObject> findObject(
+    virtual std::shared_ptr<UiObject> findObject(
         const std::shared_ptr<UiSelector> selector) const = 0;
 
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    virtual std::vector<std::unique_ptr<UiObject>> findObjects(
+    virtual std::vector<std::shared_ptr<UiObject>> findObjects(
         const std::shared_ptr<UiSelector> selector) const = 0;
 };
 
diff --git a/libaurum/inc/Impl/Accessibility/AtspiAccessibleApplication.h b/libaurum/inc/Impl/Accessibility/AtspiAccessibleApplication.h
new file mode 100644 (file)
index 0000000..78208af
--- /dev/null
@@ -0,0 +1,17 @@
+#pragma once
+#include "AccessibleApplication.h"
+
+#include <memory>
+#include <atspi/atspi.h>
+
+class AtspiAccessibleApplication : public AccessibleApplication, public std::enable_shared_from_this<AtspiAccessibleApplication> {
+public:
+    AtspiAccessibleApplication(std::shared_ptr<AccessibleNode> node);
+    virtual ~AtspiAccessibleApplication();
+
+public:
+    std::vector<std::shared_ptr<AccessibleWindow>> getWindows(void) override;
+    //std::vector<std::shared_ptr<AccessibleWindow>> getActiveWindows(void) override;
+    std::string getPackageName(void) override;
+
+};
\ No newline at end of file
diff --git a/libaurum/inc/Impl/Accessibility/AtspiAccessibleNode.h b/libaurum/inc/Impl/Accessibility/AtspiAccessibleNode.h
new file mode 100644 (file)
index 0000000..3121f8c
--- /dev/null
@@ -0,0 +1,95 @@
+#pragma once
+#include "AccessibleNode.h"
+#include <atspi/atspi.h>
+
+class AtspiAccessibleNode : public AccessibleNode {
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    AtspiAccessibleNode(AtspiAccessible *node);
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+   ~AtspiAccessibleNode() override;
+
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    int getChildCount() const override;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    std::shared_ptr<AccessibleNode> getChildAt(int index) const override;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    std::vector<std::shared_ptr<AccessibleNode>> getChildren() const override;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    std::shared_ptr<AccessibleNode> getParent() const override;
+
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    void* getRawHandler(void) const override;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    void refresh() override;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    std::vector<std::string> getActions() const override;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool doAction(std::string action) override;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    void setValue(std::string text) override;
+
+private:
+    using AccessibleNode::setFeatureProperty;
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    void setFeatureProperty(AtspiStateType type);
+
+private:
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    //static std::map<AtspiAccessible *, AccessibleNode *> mNodeMap;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    AtspiAccessible* mNode;
+};
\ No newline at end of file
similarity index 56%
rename from libaurum/inc/AccessibleWatcher.h
rename to libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h
index 9ee7d22..93ded42 100644 (file)
@@ -1,23 +1,17 @@
-#ifndef ACCESSIBLE_H
-#define ACCESSIBLE_H
+#pragma once
+#include "AccessibleNode.h"
+#include "AccessibleWatcher.h"
 
 #include <atspi/atspi.h>
-#include "AccessibleNode.h"
-#include "AccessibleUtils.h"
+#include <gio/gio.h>
 
-#include <list>
-#include <map>
+#include <mutex>
+#include <shared_mutex>
 #include <memory>
+#include <list>
 #include <vector>
 #include <set>
-
-
-#include <gio/gio.h>
-#include <mutex>
-#include <shared_mutex>
-#include "config.h"
-
-
+#include <map>
 
 /**
  * @brief WindowActivateInfoType enum class
@@ -46,147 +40,146 @@ public:
      * @brief TBD
      * @since_tizen 5.5
      */
-    virtual void onWindowActivated(AtspiAccessible *      node,
-                                   WindowActivateInfoType type) = 0;
+    virtual void onWindowActivated(AtspiAccessible* node, WindowActivateInfoType type) = 0;
+
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    virtual void onWindowDeactivated(AtspiAccessible *node) = 0;
+    virtual void onWindowDeactivated(AtspiAccessiblenode) = 0;
 
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    virtual void onWindowCreated(AtspiAccessible *node) = 0;
+    virtual void onWindowCreated(AtspiAccessiblenode) = 0;
 
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    virtual void onWindowDestroyed(AtspiAccessible *node) = 0;
+    virtual void onWindowDestroyed(AtspiAccessiblenode) = 0;
 
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    virtual void onVisibilityChanged(AtspiAccessible *node,
-                                     bool             visible) = 0;
+    virtual void onVisibilityChanged(AtspiAccessible* node, bool visible) = 0;
 
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    virtual void onObjectDefunct(AtspiAccessible *node) = 0;
+    virtual void onObjectDefunct(AtspiAccessiblenode) = 0;
 };
 
-/**
- * @brief AccessibleWatcher class
- * @since_tizen 5.5
- */
-class AccessibleWatcher : public IAtspiEvents {
-private:
 
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
-    AccessibleWatcher();
+class AtspiAccessibleWatcher : public AccessibleWatcher, public IAtspiEvents {
+public:
+    AtspiAccessibleWatcher();
+    virtual ~AtspiAccessibleWatcher();
 
 public:
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    static const AccessibleWatcher *getInstance();
-        /**
+    virtual int getApplicationCount(void) const override;
+
+    /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    virtual ~AccessibleWatcher();
+    virtual std::shared_ptr<AccessibleApplication> getApplicationAt(int index) const override;
 
-public:
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    std::unique_ptr<AccessibleNode> getRootNode() const;
+    virtual std::vector<std::shared_ptr<AccessibleApplication>> getApplications(void) const override;
+
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    std::vector<std::unique_ptr<AccessibleNode>> getTopNode() const;
+    //std::shared_ptr<AccessibleNode> getRootNode() const override;
+
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
+    //std::vector<std::shared_ptr<AccessibleNode>> getTopNode() const override;
+
 
-    void onWindowActivated(AtspiAccessible *      node,
-                                   WindowActivateInfoType type) override;
+public:
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    void onWindowDeactivated(AtspiAccessible *node) override;
+    static void onAtspiWindowEvent(AtspiEvent *event, void *user_data);
+
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
+    void onWindowActivated(AtspiAccessible* node, WindowActivateInfoType type) override;
 
-    void onWindowCreated(AtspiAccessible *node) override;
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    void onWindowDestroyed(AtspiAccessible *node) override;
+    void onWindowDeactivated(AtspiAccessible* node) override;
+
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
+    void onWindowCreated(AtspiAccessible* node) override;
 
-    void onVisibilityChanged(AtspiAccessible *node,
-                                     bool             visible) override;
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    void onObjectDefunct(AtspiAccessible *node) override;
+    void onWindowDestroyed(AtspiAccessible* node) override;
+
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
+    void onVisibilityChanged(AtspiAccessible* node, bool visible) override;
 
-    void printDbgInformation() const;
-
-private:
-    void        clearWindowList() const;
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    static void onAtspiWindowEvent(AtspiEvent *event, void *user_data);
+    void onObjectDefunct(AtspiAccessible* node) override;
+
+private:
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-
     bool removeFromActivatedList(AtspiAccessible *node);
+
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
     bool addToActivatedList(AtspiAccessible *node);
+
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
     bool removeFromWindowSet(AtspiAccessible *node);
+
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
     bool addToWindowSet(AtspiAccessible *node);
 
+    void print_debug();
 
 private:
     /**
@@ -197,32 +190,28 @@ private:
     /**
      * @brief TBD
      */
-    mutable std::list<AtspiAccessible *>          mActivatedWindowList;
+    GDBusProxy *                                  mDbusProxy;
 
     /**
      * @brief TBD
      */
-    mutable std::list<AtspiAccessible *>          mActivatedApplicationList;
+    std::mutex                            mLock;
 
     /**
      * @brief TBD
      */
-    mutable std::set<AtspiAccessible *>           mWindowSet;;
+    std::list<AtspiAccessible *>          mActivatedWindowList;
 
     /**
      * @brief TBD
      */
-    GDBusProxy *                                  mDbusProxy;
+    std::list<AtspiAccessible *>          mActivatedApplicationList;
 
     /**
      * @brief TBD
      */
-    std::map<AtspiAccessible *, AccessibleNode *> mAccessibleNode;
+    std::set<AtspiAccessible *>            mWindowSet;
 
-    /**
-     * @brief TBD
-     */
-    mutable std::mutex                            mLock;
-};
+    std::map<AtspiAccessible *, AtspiAccessible *> mWindowAppMap;
 
-#endif
+};
\ No newline at end of file
diff --git a/libaurum/inc/Impl/Accessibility/AtspiAccessibleWindow.h b/libaurum/inc/Impl/Accessibility/AtspiAccessibleWindow.h
new file mode 100644 (file)
index 0000000..6883bf6
--- /dev/null
@@ -0,0 +1,9 @@
+#pragma once
+#include "AccessibleWindow.h"
+
+class AtspiAccessibleWindow : public AccessibleWindow {
+public:
+    AtspiAccessibleWindow(std::shared_ptr<AccessibleApplication> app, std::shared_ptr<AccessibleNode> node);
+    ~AtspiAccessibleWindow();
+
+};
\ No newline at end of file
diff --git a/libaurum/inc/Impl/Accessibility/MockAccessibleApplication.h b/libaurum/inc/Impl/Accessibility/MockAccessibleApplication.h
new file mode 100644 (file)
index 0000000..dc4359e
--- /dev/null
@@ -0,0 +1,23 @@
+#pragma once
+#include "AccessibleApplication.h"
+
+#include <memory>
+
+class MockAccessibleApplication : public AccessibleApplication, public std::enable_shared_from_this<MockAccessibleApplication> {
+public:
+    MockAccessibleApplication(std::shared_ptr<AccessibleNode> node);
+    virtual ~MockAccessibleApplication();
+
+public:
+    std::vector<std::shared_ptr<AccessibleWindow>> getWindows(void) override;
+    //std::vector<std::shared_ptr<AccessibleWindow>> getActiveWindows(void) override;
+    std::string getPackageName(void) override;
+
+public:
+    void addWindow(std::shared_ptr<AccessibleWindow> window);
+    void clearWindows(void);
+
+private:
+    std::vector<std::shared_ptr<AccessibleWindow>> mWindowList;
+
+};
\ No newline at end of file
diff --git a/libaurum/inc/Impl/Accessibility/MockAccessibleNode.h b/libaurum/inc/Impl/Accessibility/MockAccessibleNode.h
new file mode 100644 (file)
index 0000000..98bbb44
--- /dev/null
@@ -0,0 +1,103 @@
+#pragma once
+#include "AccessibleNode.h"
+
+#include <set>
+
+class MockAccessibleNode : public AccessibleNode {
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    MockAccessibleNode(std::shared_ptr<AccessibleNode> parent, std::string text,std::string pkg,std::string role, std::string res,std::string type,std::string style,Rect<int> boundingBox,int supportingIfaces,int featureProperty);
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+   ~MockAccessibleNode() override;
+
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    int getChildCount() const override;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    std::shared_ptr<AccessibleNode> getChildAt(int index) const override;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    std::vector<std::shared_ptr<AccessibleNode>> getChildren() const override;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    std::shared_ptr<AccessibleNode> getParent() const override;
+
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    void* getRawHandler(void) const override;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    void refresh() override;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    std::vector<std::string> getActions() const override;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool doAction(std::string action) override;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    void setValue(std::string text) override;
+
+public:
+    using AccessibleNode::setFeatureProperty;
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    void setFeatureProperty(int type);
+
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    void addChild(std::shared_ptr<AccessibleNode> child);
+    void clearChildren(void);
+    void addAction(std::string action);
+    void clearActions(void);
+    void setProperties(std::string text,std::string pkg, std::string role, std::string res, std::string type, std::string style, Rect<int> boundingBox, int supportingIfaces, int featureProperty);
+
+private:
+
+    std::shared_ptr<AccessibleNode> mParentNode;
+    std::vector<std::shared_ptr<AccessibleNode>> mChildrenList;
+    std::set<std::string> mActionSet;
+
+};
+
+
diff --git a/libaurum/inc/Impl/Accessibility/MockAccessibleWatcher.h b/libaurum/inc/Impl/Accessibility/MockAccessibleWatcher.h
new file mode 100644 (file)
index 0000000..e3476d2
--- /dev/null
@@ -0,0 +1,50 @@
+#pragma once
+#include "AccessibleNode.h"
+#include "AccessibleWatcher.h"
+
+#include <mutex>
+#include <shared_mutex>
+#include <memory>
+#include <list>
+#include <vector>
+#include <set>
+#include <map>
+
+
+class MockAccessibleWatcher : public AccessibleWatcher {
+public:
+    MockAccessibleWatcher();
+    virtual ~MockAccessibleWatcher();
+
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    virtual int getApplicationCount(void) const override;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    virtual std::shared_ptr<AccessibleApplication> getApplicationAt(int index) const override;
+
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    virtual std::vector<std::shared_ptr<AccessibleApplication>> getApplications(void) const override;
+
+public:
+    void addApplication(std::shared_ptr<AccessibleApplication> application);
+
+private:
+    std::vector<std::shared_ptr<AccessibleApplication>> mApplicationList;
+
+    /**
+     * @brief TBD
+     */
+    std::mutex                            mLock;
+
+};
\ No newline at end of file
diff --git a/libaurum/inc/Impl/Accessibility/MockAccessibleWindow.h b/libaurum/inc/Impl/Accessibility/MockAccessibleWindow.h
new file mode 100644 (file)
index 0000000..e7ec0b5
--- /dev/null
@@ -0,0 +1,8 @@
+#pragma once
+#include "AccessibleWindow.h"
+
+class MockAccessibleWindow : public AccessibleWindow {
+public:
+    MockAccessibleWindow(std::shared_ptr<AccessibleApplication> app, std::shared_ptr<AccessibleNode> node);
+    ~MockAccessibleWindow();
+};
\ No newline at end of file
diff --git a/libaurum/inc/Impl/MockDeviceImpl.h b/libaurum/inc/Impl/MockDeviceImpl.h
new file mode 100644 (file)
index 0000000..dd35e6f
--- /dev/null
@@ -0,0 +1,62 @@
+#pragma once
+#include "config.h"
+#include "IDevice.h"
+
+#include <set>
+
+class MockDeviceImpl : public IDevice {
+public:
+    MockDeviceImpl();
+    ~MockDeviceImpl();
+
+    bool click(const int x, const int y) override;
+    bool click(const int x, const int y, const unsigned int intv) override;
+
+    bool drag(const int sx, const int sy, const int ex, const int ey,
+              const int steps, const int durationMs) override;
+
+    int touchDown(const int x, const int y) override;
+    bool touchMove(const int x, const int y, const int seq) override;
+    bool touchUp(const int x, const int y, const int seq) override;
+
+    bool wheelUp(int amount, const int durationMs) override;
+    bool wheelDown(int amount, const int durationMs) override;
+
+    bool pressBack(KeyRequestType type) override;
+    bool pressHome(KeyRequestType type) override;
+    bool pressMenu(KeyRequestType type) override;
+    bool pressVolUp(KeyRequestType type) override;
+    bool pressVolDown(KeyRequestType type) override;
+    bool pressPower(KeyRequestType type) override;
+    bool pressKeyCode(std::string keycode, KeyRequestType type) override;
+    bool takeScreenshot(std::string path, float scale, int quality) override;
+    long long getSystemTime(TimeRequestType type) override;
+
+protected:
+    bool strokeKeyCode(std::string keycode, unsigned int intv);
+    bool pressKeyCode(std::string keycode);
+    bool releaseKeyCode(std::string keycode);
+
+    int grabTouchSeqNumber();
+    bool releaseTouchSeqNumber(int seq);
+
+private:
+    void startTimer(void);
+    int stopTimer(void);
+
+private:
+    static const unsigned int INTV_CLICK = 5;
+    static const unsigned int INTV_SHORTSTROKE = 100;
+    static const unsigned int INTV_LONGSTROKE = 2000;
+
+    static const unsigned int INTV_MINIMUM_DRAG_MS = 25;
+    static const unsigned int INTV_MINIMUM_USLEEP = 1000;
+    static const unsigned int MINIMUM_DURATION_DRAG = 100;
+    static const unsigned int MSEC_PER_SEC = 1000;
+    static const unsigned int MAX_FINGER_NUMBER = 2;
+
+    struct timespec tStart;
+    bool isTimerStarted;
+
+    std::set<int> mTouchSeq;
+};
\ No newline at end of file
similarity index 94%
rename from libaurum/inc/DeviceImpl/TizenImpl.h
rename to libaurum/inc/Impl/TizenDeviceImpl.h
index d9ea2ce..f275e91 100644 (file)
@@ -9,13 +9,13 @@
 #include <efl_util.h>
 #endif
 /**
- * @brief TizenImpl Class
+ * @brief TizenDeviceImpl Class
  * @since_tizen 5.5
  */
-class TizenImpl : public IDevice {
+class TizenDeviceImpl : public IDevice {
 public:
-    TizenImpl();
-    ~TizenImpl();
+    TizenDeviceImpl();
+    ~TizenDeviceImpl();
 
     bool click(const int x, const int y) override;
     bool click(const int x, const int y, const unsigned int intv) override;
diff --git a/libaurum/inc/Misc/Point2D.h b/libaurum/inc/Misc/Point2D.h
new file mode 100644 (file)
index 0000000..9bb304f
--- /dev/null
@@ -0,0 +1,45 @@
+#pragma once
+
+/**
+ * @brief Point2d Class
+ * @since_tizen 5.5
+ */
+template <typename T>
+class Point2D {
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    Point2D() : x{0}, y{0} {}
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    Point2D(const Point2D &src)
+    {
+        x = src.x;
+        y = src.y;
+    }
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    Point2D(const T &x, const T &y)
+    {
+        this->x = x;
+        this->y = y;
+    }
+
+    /**
+     * @brief TBD
+     */
+    T x;
+
+    /**
+     * @brief TBD
+     */
+    T y;
+};
\ No newline at end of file
diff --git a/libaurum/inc/Misc/Rect.h b/libaurum/inc/Misc/Rect.h
new file mode 100644 (file)
index 0000000..62aa39e
--- /dev/null
@@ -0,0 +1,77 @@
+#pragma once
+#include "Point2D.h"
+
+/**
+ * @brief Rect Class
+ * @since_tizen 5.5
+ */
+template <typename T>
+class Rect {
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    Rect() : mTopLeft{0, 0}, mBottomRight{0, 0} {}
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    Rect(const Point2D<T> &tl, const Point2D<T> &br)
+        : mTopLeft(tl), mBottomRight(br)
+    {
+    }
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    Rect(const T &x1, const T &y1, const T &x2, const T &y2)
+        : mTopLeft{x1, y1}, mBottomRight{x2, y2}
+    {
+    }
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    Rect(const Rect<T> &src)
+
+    {
+        this->mTopLeft = Point2D<int>{src.mTopLeft};
+        this->mBottomRight = Point2D<int>{src.mBottomRight};
+    }
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    Point2D<T> midPoint() const
+    {
+        return Point2D<T>{mTopLeft.x + static_cast<T>(width() / 2),
+                          mTopLeft.y + static_cast<T>(height() / 2)};
+    }
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    T width() const { return mBottomRight.x - mTopLeft.x; }
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    T height() const { return mBottomRight.y - mTopLeft.y; }
+
+    /**
+     * @brief TBD
+     */
+    Point2D<T> mTopLeft;
+
+    /**
+     * @brief TBD
+     */
+    Point2D<T> mBottomRight;
+};
index 987f8c9..b3165b2 100644 (file)
@@ -31,7 +31,7 @@ public:
      * @brief TBD
      * @since_tizen 5.5
      */
-    void update(const AccessibleNode *node, int index, int depth,
+    void update(const std::shared_ptr<AccessibleNode> node, int index, int depth,
                 std::list<std::shared_ptr<PartialMatch>> &partialMatches);
 
     /**
@@ -47,7 +47,7 @@ public:
     void debugPrint();
 
 public:
-    static std::shared_ptr<PartialMatch> accept(const AccessibleNode *node,
+    static std::shared_ptr<PartialMatch> accept(const std::shared_ptr<AccessibleNode> node,
                                                 const std::shared_ptr<UiSelector> selector,
                                                 int index, int depth);
 
@@ -55,7 +55,7 @@ public:
      * @brief TBD
      * @since_tizen 5.5
      */
-    static std::shared_ptr<PartialMatch> accept(const AccessibleNode *node,
+    static std::shared_ptr<PartialMatch> accept(const std::shared_ptr<AccessibleNode> node,
                                                 const std::shared_ptr<UiSelector> selector,
                                                 int index, int absoluteDepth,
                                                 int relativeDepth);
@@ -66,7 +66,7 @@ public:
      */
 private:
     static bool checkCriteria(const std::shared_ptr<UiSelector> selector,
-                              const AccessibleNode *node);
+                              const std::shared_ptr<AccessibleNode> node);
 
     /**
      * @brief TBD
index 9ed7e1f..64f75f9 100644 (file)
 
 #include <functional>
 #include <string>
-/**
- * @brief DeviceType enum class
- * @since_tizen 5.5
- */
-enum class DeviceType {
-    DEFAULT,
-    NUM_DEVICETYPE,
-};
+
 /**
  * @brief UiDevice class
  * @since_tizen 5.5
@@ -142,14 +135,14 @@ public:
      * @brief TBD
      * @since_tizen 5.5
      */
-    std::unique_ptr<UiObject> findObject(
+    std::shared_ptr<UiObject> findObject(
         const std::shared_ptr<UiSelector> selector) const override;
 
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    std::vector<std::unique_ptr<UiObject>> findObjects(
+    std::vector<std::shared_ptr<UiObject>> findObjects(
         const std::shared_ptr<UiSelector> selector) const override;
 
     /**
@@ -163,29 +156,28 @@ public:
      * @brief TBD
      * @since_tizen 5.5
      */
-    std::unique_ptr<UiObject> waitFor(
-        const std::function<std::unique_ptr<UiObject>(const ISearchable *)>
+    std::shared_ptr<UiObject> waitFor(
+        const std::function<std::shared_ptr<UiObject>(const ISearchable *)>
             condition) const;
-
 public:
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    static UiDevice *getInstance(DeviceType type);
+    static std::shared_ptr<UiDevice> getInstance(IDevice *deviceImpl = nullptr);
 
-private:
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    std::vector<std::unique_ptr<AccessibleNode>> getWindowRoot() const;
-
+    std::vector<std::shared_ptr<AccessibleNode>> getWindowRoot() const;
+private:
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
     bool waitForIdle() const;
+
 private:
     /**
      * @brief TBD
@@ -197,8 +189,9 @@ private:
      * @brief TBD
      * @since_tizen 5.5
      */
-    UiDevice(DeviceType type, IDevice *impl);
+    UiDevice(IDevice *impl);
 
+public:
     /**
      * @brief TBD
      * @since_tizen 5.5
@@ -209,10 +202,6 @@ private:
     /**
      * @brief TBD
      */
-    DeviceType    mType;
-    /**
-     * @brief TBD
-     */
     IDevice *     mDeviceImpl;
     /**
      * @brief TBD
index b56470e..6735242 100644 (file)
@@ -21,15 +21,15 @@ public:
      * @brief TBD
      * @since_tizen 5.5
      */
-    UiObject(const UiDevice *device, const std::shared_ptr<UiSelector> selector,
+    UiObject(const std::shared_ptr<UiDevice> device, const std::shared_ptr<UiSelector> selector,
              const AccessibleNode *node);
 
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    UiObject(const UiDevice *device, const std::shared_ptr<UiSelector> selector,
-             std::unique_ptr<AccessibleNode> node);
+    UiObject(const std::shared_ptr<UiDevice> device, const std::shared_ptr<UiSelector> selector,
+             std::shared_ptr<AccessibleNode> node);
 //    UiObject(const UiObject &src);  // copy constroctur
 
     /**
@@ -66,14 +66,14 @@ public:
      * @brief TBD
      * @since_tizen 5.5
      */
-    std::unique_ptr<UiObject> findObject(
+    std::shared_ptr<UiObject> findObject(
         const std::shared_ptr<UiSelector> selector) const override;
 
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    std::vector<std::unique_ptr<UiObject>> findObjects(
+    std::vector<std::shared_ptr<UiObject>> findObjects(
         const std::shared_ptr<UiSelector> selector) const override;
 
     /**
@@ -87,8 +87,8 @@ public:
      * @brief TBD
      * @since_tizen 5.5
      */
-    std::unique_ptr<UiObject> waitFor(
-        const std::function<std::unique_ptr<UiObject>(const ISearchable *)>
+    std::shared_ptr<UiObject> waitFor(
+        const std::function<std::shared_ptr<UiObject>(const ISearchable *)>
             condition) const;
 
     /**
@@ -114,25 +114,31 @@ public:
      * @brief TBD
      * @since_tizen 5.5
      */
-    std::vector<std::unique_ptr<UiObject>> getChildren() const;
+    std::vector<std::shared_ptr<UiObject>> getChildren() const;
 
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    std::string getContentDescription() const;
+    std::string getApplicationPackage() const;
 
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    std::string getApplicationPackage() const;
+    std::string getResourceName() const;
 
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    std::string getResourceName() const;
+    std::string getElementType() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    std::string getElementStyle() const;
 
     /**
      * @brief TBD
@@ -144,7 +150,13 @@ public:
      * @brief TBD
      * @since_tizen 5.5
      */
-    void        setText(std::string text);
+    std::string getRole() const;
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    void setText(std::string text);
 
     /**
      * @brief TBD
@@ -254,18 +266,17 @@ public:
      */
     void refresh() const;
 
-private:
     /**
      * @brief TBD
      * @since_tizen 5.5
      */
-    const AccessibleNode *getAccessibleNode() const;
+    std::shared_ptr<AccessibleNode> getAccessibleNode() const;
 
 private:
     /**
      * @brief TBD
      */
-    const UiDevice *      mDevice;
+    std::shared_ptr<UiDevice> mDevice;
 
     /**
      * @brief TBD
@@ -275,13 +286,12 @@ private:
     /**
      * @brief TBD
      */
-    std::unique_ptr<AccessibleNode> mNode;
+    std::shared_ptr<AccessibleNode> mNode;
 
     /**
      * @brief TBD
      */
     const Waiter *        mWaiter;
-    //std::unique_ptr<AccessibleNode> mNode_src;
 
     /**
      * @brief TBD
diff --git a/libaurum/inc/UiScrollable.h b/libaurum/inc/UiScrollable.h
new file mode 100644 (file)
index 0000000..ecabb2f
--- /dev/null
@@ -0,0 +1,78 @@
+#pragma once
+#include "UiObject.h"
+#include <memory>
+/**
+ * @brief UiScrollable class
+ * @since_tizen 5.5
+ */
+class UiScrollable : public UiObject
+{
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    UiScrollable(std::shared_ptr<UiSelector> selector);
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    UiScrollable();
+
+public:
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool exists(UiObject *obj);
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool scrollToObject(UiObject *obj);
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool scrollForward();
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool scrollForward(int steps);
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool scrollBackward();
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool scrollBackward(int steps);
+
+    /**
+     * @brief TBD
+     * @since_tizen 5.5
+     */
+    bool scrollToBegin();
+
+private:
+    /**
+     * @brief TBD
+     */
+    std::shared_ptr<UiSelector> mSelector;
+
+    /**
+     * @brief TBD
+     */
+    int mMaxSearchSwipe;
+
+    /**
+     * @brief TBD
+     */
+    int mScrollStep;
+};
\ No newline at end of file
index 4a52580..81d5719 100644 (file)
@@ -271,12 +271,6 @@ public:
      * @brief TBD
      * @since_tizen 5.5
      */
-    std::unique_ptr<std::string> mDesc;
-
-    /**
-     * @brief TBD
-     * @since_tizen 5.5
-     */
     std::vector<std::shared_ptr<UiSelector>> mChild;
 };
 
index 4ad2be3..a4baafe 100644 (file)
@@ -53,7 +53,7 @@ public:
      * @brief TBD
      * @since_tizen 5.5
      */
-    static std::function<std::unique_ptr<UiObject>(const ISearchable *)>
+    static std::function<std::shared_ptr<UiObject>(const ISearchable *)>
                                                  findObject(const std::shared_ptr<UiSelector> selector);
 
     /**
index c2e2eb8..78bdc12 100644 (file)
@@ -1,32 +1,17 @@
 libaurum_inc = [
   include_directories('./inc'),
+  include_directories('./inc/Accessibility'),
+  include_directories('./inc/Impl'),
+  include_directories('./inc/Impl/Accessibility'),
+  include_directories('./inc/Misc'),
   root_inc,
   loguru_inc,
 ]
 
-libaurum_src = [
-  files('src/Sel.cc'),
-  files('src/UiDevice.cc'),
-  files('src/UiObject.cc'),
-  files('src/UiSelector.cc'),
-  files('src/AccessibleWatcher.cc'),
-  files('src/AccessibleNode.cc'),
-  files('src/AccessibleUtils.cc'),
-  files('src/Comparer.cc'),
-  files('src/Until.cc'),
-  files('src/Waiter.cc'),
-  files('src/PartialMatch.cc'),
-]
-
-if get_option('tizen') == true
-libaurum_src +=[
-  files('src/DeviceImpl/TizenImpl.cc'),
-]
-endif
+libaurum_src = []
+subdir('src')
 
 libaurum_dep = [
-  dependency('capi-system-info'),
-  dependency('libtdm'),
   dependency('atspi-2'),
   dependency('gio-2.0'),
   dependency('threads'),
@@ -38,6 +23,7 @@ if get_option('tizen') == true
     dependency('capi-system-info'),
     dependency('capi-ui-efl-util'),
     dependency('elementary'),
+    dependency('libtdm'),
   ]
 endif
 
diff --git a/libaurum/src/Accessibility/AccessibleApplication.cc b/libaurum/src/Accessibility/AccessibleApplication.cc
new file mode 100644 (file)
index 0000000..cd0e1de
--- /dev/null
@@ -0,0 +1,38 @@
+#include "AccessibleApplication.h"
+#include "AccessibleWatcher.h"
+
+#include <algorithm>
+#include <loguru.hpp>
+
+AccessibleApplication::AccessibleApplication(std::shared_ptr<AccessibleNode> node)
+: mNode{node}
+{
+}
+
+AccessibleApplication::~AccessibleApplication()
+{
+}
+
+std::shared_ptr<AccessibleNode> AccessibleApplication::getAccessibleNode()
+{
+    return mNode;
+}
+
+bool AccessibleApplication::isActive(void)
+{
+    auto children = this->getActiveWindows();
+    return children.size() > 0;
+}
+
+std::vector<std::shared_ptr<AccessibleWindow>> AccessibleApplication::getActiveWindows(void)
+{
+    auto children = getWindows();
+
+    children.erase(std::remove_if(children.begin(), children.end(), [](auto child){
+                        return !(child->isActive() && child->isShowing()); // && child->isShowing() && child->isVisible());
+                    }), children.end());
+
+    LOG_SCOPE_F(INFO, "getActiveWindows app(%s) for %p, size:%d", getPackageName().c_str(), getAccessibleNode()->getRawHandler(), children.size());
+
+    return children;
+}
\ No newline at end of file
diff --git a/libaurum/src/Accessibility/AccessibleNode.cc b/libaurum/src/Accessibility/AccessibleNode.cc
new file mode 100644 (file)
index 0000000..14de23f
--- /dev/null
@@ -0,0 +1,156 @@
+#include "AccessibleNode.h"
+#include <string.h>
+#include <iostream>
+#include <vector>
+
+#include <loguru.hpp>
+#include "config.h"
+
+
+AccessibleNode::~AccessibleNode()
+{
+}
+
+AccessibleNode::AccessibleNode()
+    : mText{""}, mPkg{""}, mRole{""}, mRes{""}, mType{""}, mStyle{""},
+      mBoundingBox{0,0,0,0}, mSupportingIfaces(0), mFeatureProperty(0)
+{
+}
+
+void AccessibleNode::print(int depth, int maxDepth)
+{
+    if (maxDepth <= 0 || depth > maxDepth) return;
+
+    this->print(depth);
+    auto children = this->getChildren();
+    for ( auto &child : children ) {
+        if (child) child->print(depth +1, maxDepth);
+    }
+}
+
+void AccessibleNode::print(int d)
+{
+    this->refresh();
+    LOG_F(INFO, "%s - %p(%s)  /  pkg:%s, text:%s",
+          std::string(d, ' ').c_str(), getRawHandler(), getText().c_str(),
+          getPkg().c_str(), getText().c_str());
+}
+
+bool AccessibleNode::isSupporting(AccessibleNodeInterface thisIface) const
+{
+    return (mSupportingIfaces & static_cast<int>(thisIface)) != 0;
+}
+
+bool AccessibleNode::hasFeatureProperty(NodeFeatureProperties prop) const
+{
+    return (mFeatureProperty & static_cast<int>(prop)) != 0;
+}
+
+void AccessibleNode::setFeatureProperty(NodeFeatureProperties prop, bool has)
+{
+    if (has)
+        mFeatureProperty |= static_cast<int>(prop);
+    else
+        mFeatureProperty &= ~static_cast<int>(prop);
+}
+
+
+std::string AccessibleNode::getText() const
+{
+    return mText;
+}
+
+std::string AccessibleNode::getPkg() const
+{
+    return mPkg;
+}
+
+std::string AccessibleNode::getRes() const
+{
+    return mRes;
+}
+
+std::string AccessibleNode::getRole() const
+{
+    return mRole;
+}
+
+std::string AccessibleNode::getType() const
+{
+    return mType;
+}
+
+std::string AccessibleNode::getStyle() const
+{
+    return mStyle;
+}
+
+Rect<int> AccessibleNode::getBoundingBox() const
+{
+    return mBoundingBox;
+}
+
+bool AccessibleNode::isCheckable() const
+{
+    return hasFeatureProperty(NodeFeatureProperties::CHECKABLE);
+}
+
+bool AccessibleNode::isChecked() const
+{
+    return hasFeatureProperty(NodeFeatureProperties::CHECKED);
+}
+
+bool AccessibleNode::isClickable() const
+{
+    return hasFeatureProperty(NodeFeatureProperties::CLICKABLE);
+}
+
+bool AccessibleNode::isEnabled() const
+{
+    return hasFeatureProperty(NodeFeatureProperties::ENABLED);
+}
+
+bool AccessibleNode::isFocusable() const
+{
+    return hasFeatureProperty(NodeFeatureProperties::FOCUSABLE);
+}
+
+bool AccessibleNode::isFocused() const
+{
+    return hasFeatureProperty(NodeFeatureProperties::FOCUSED);
+}
+
+bool AccessibleNode::isLongClickable() const
+{
+    return hasFeatureProperty(NodeFeatureProperties::LONGCLICKABLE);
+}
+
+bool AccessibleNode::isScrollable() const
+{
+    return hasFeatureProperty(NodeFeatureProperties::SCROLLABLE);
+}
+
+bool AccessibleNode::isSelectable() const
+{
+    return hasFeatureProperty(NodeFeatureProperties::SELECTABLE);
+}
+
+bool AccessibleNode::isSelected() const
+{
+    return hasFeatureProperty(NodeFeatureProperties::SELECTED);
+}
+
+bool AccessibleNode::isVisible() const
+{
+    return hasFeatureProperty(NodeFeatureProperties::VISIBLE);
+}
+
+bool AccessibleNode::isShowing() const
+{
+    return hasFeatureProperty(NodeFeatureProperties::SHOWING);
+}
+
+bool AccessibleNode::isActive() const
+{
+    return hasFeatureProperty(NodeFeatureProperties::ACTIVE);
+}
\ No newline at end of file
diff --git a/libaurum/src/Accessibility/AccessibleWatcher.cc b/libaurum/src/Accessibility/AccessibleWatcher.cc
new file mode 100644 (file)
index 0000000..25fb94e
--- /dev/null
@@ -0,0 +1,75 @@
+
+#include "AccessibleWatcher.h"
+
+#ifdef TIZEN
+#include "AtspiAccessibleWatcher.h"
+#endif
+
+#include "MockAccessibleWatcher.h"
+
+#include <string.h>
+#include <iostream>
+#include <utility>
+#include <algorithm>
+#include <loguru.hpp>
+
+
+
+AccessibleWatcher::~AccessibleWatcher()
+{
+}
+
+/*
+void AccessibleWatcher::printDbgInformation() const
+{
+    LOG_SCOPE_F(INFO, "%d %d", mActivatedWindowList.size(),  mWindowSet.size());
+
+    for (auto iter = mActivatedWindowList.begin(); iter != mActivatedWindowList.end(); ++iter) {
+        LOG_F(INFO, "%p", *iter);
+    }
+        LOG_F(INFO, "-----------");
+
+    for (auto iter = mWindowSet.begin(); iter != mWindowSet.end(); ++iter) {
+        LOG_F(INFO, "%p", *iter);
+    }
+}
+*/
+
+const AccessibleWatcher *AccessibleWatcher::getInstance(AccessibleWatcher *watcherImpl)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    static AccessibleWatcher *mInstance = nullptr;
+    if (watcherImpl) {
+        delete mInstance;
+        mInstance = watcherImpl;
+        return mInstance;
+    } else {
+        if (mInstance) return mInstance;
+        else {
+#ifdef TIZEN
+            mInstance = new AtspiAccessibleWatcher();
+#else
+            mInstance = new MockAccessibleWatcher();
+#endif
+        }
+    }
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return mInstance;
+}
+
+std::vector<std::shared_ptr<AccessibleApplication>> AccessibleWatcher::getActiveApplications(void) const
+{
+    LOG_SCOPE_F(INFO, "getActiveApplications for this(%p)", this);
+
+    std::vector<std::shared_ptr<AccessibleApplication>> ret{};
+    auto apps = this->getApplications();
+    LOG_F(INFO, "apps size %d", apps.size());
+
+    apps.erase(std::remove_if(apps.begin(), apps.end(), [](auto app){
+        return !app->isActive();
+    }), apps.end());
+
+    LOG_F(INFO, "active apps size %d", apps.size());
+
+    return apps;
+}
\ No newline at end of file
diff --git a/libaurum/src/Accessibility/AccessibleWindow.cc b/libaurum/src/Accessibility/AccessibleWindow.cc
new file mode 100644 (file)
index 0000000..8de9d5a
--- /dev/null
@@ -0,0 +1,36 @@
+#include "AccessibleWindow.h"
+#include "AccessibleWatcher.h"
+
+AccessibleWindow::AccessibleWindow(std::shared_ptr<AccessibleApplication> app, std::shared_ptr<AccessibleNode> node)
+: mApp{app}, mNode{node}
+{
+}
+
+AccessibleWindow::~AccessibleWindow()
+{
+}
+
+std::string AccessibleWindow::getTitle(void)
+{
+    return mNode->getText();
+}
+
+bool AccessibleWindow::isShowing()
+{
+    return mNode->isShowing();
+}
+
+bool AccessibleWindow::isActive()
+{
+    return mNode->isActive();
+}
+
+std::shared_ptr<AccessibleApplication> AccessibleWindow::getApplication(void)
+{
+    return mApp;
+}
+
+std::shared_ptr<AccessibleNode> AccessibleWindow::getNode(void)
+{
+    return mNode;
+}
\ No newline at end of file
diff --git a/libaurum/src/Accessibility/meson.build b/libaurum/src/Accessibility/meson.build
new file mode 100644 (file)
index 0000000..9eb7868
--- /dev/null
@@ -0,0 +1,7 @@
+libaurum_src += [
+    files('AccessibleApplication.cc'),
+    files('AccessibleNode.cc'),
+    #files('AccessibleUtils.cc'),
+    files('AccessibleWatcher.cc'),
+    files('AccessibleWindow.cc'),
+]
\ No newline at end of file
diff --git a/libaurum/src/AccessibleWatcher.cc b/libaurum/src/AccessibleWatcher.cc
deleted file mode 100644 (file)
index 8a00fe2..0000000
+++ /dev/null
@@ -1,326 +0,0 @@
-
-#include "AccessibleWatcher.h"
-
-#include <string.h>
-#include <iostream>
-#include <utility>
-
-#include <loguru.hpp>
-
-AtspiEventListener *AccessibleWatcher::listener = nullptr;
-
-
-
-static bool iShowingNode(AtspiAccessible *node)
-{
-    char *name = NULL;
-    if (node) name = atspi_accessible_get_name(node, NULL);
-    else return false;
-
-    LOG_SCOPE_F(INFO, "isShowing %s", name);
-    auto stateSet = make_gobj_unique(atspi_accessible_get_state_set(node));
-    auto states = make_garray_unique(atspi_state_set_get_states(stateSet.get()));
-
-    if (atspi_state_set_contains(stateSet.get(), ATSPI_STATE_ACTIVE)
-        && atspi_state_set_contains(stateSet.get(), ATSPI_STATE_SHOWING)) {
-        LOG_F(INFO, "active and showing %p %s", node, name);
-        free(name);
-        return true;
-    }
-    free(name);
-    return false;
-}
-
-static std::vector<AtspiAccessible *>
-findActiveNode(AtspiAccessible *node, int depth,
-                                       int max_depth)
-{
-    std::vector<AtspiAccessible *> ret{};
-    if (depth >= max_depth) return ret;
-
-    if (iShowingNode(node)) {
-        g_object_ref(node);
-        char *name = atspi_accessible_get_name(node, NULL);
-        if (name) {
-            LOG_SCOPE_F(INFO, "%s", name);
-            free(name);
-        }
-        ret.push_back(node);
-        return ret;
-    }
-
-    int nchild = atspi_accessible_get_child_count(node, NULL);
-    for (int i = 0; i < nchild; i++) {
-        auto child = make_gobj_unique(atspi_accessible_get_child_at_index(node, i, NULL));
-        std::vector<AtspiAccessible *> childRet = findActiveNode(child.get(), depth + 1, max_depth);
-        ret.insert(ret.end(), childRet.begin(), childRet.end());
-    }
-
-    return ret;
-}
-
-AccessibleWatcher::AccessibleWatcher() : mActivatedWindowList{}, mWindowSet{}
-{
-    GVariant *enabled_variant = nullptr, *result = nullptr;
-    GError *  error = nullptr;
-    atspi_set_main_context (g_main_context_default ());
-    atspi_init();
-
-    listener =
-        atspi_event_listener_new(AccessibleWatcher::onAtspiWindowEvent, this, NULL);
-    atspi_event_listener_register(listener, "window:create", NULL);
-    atspi_event_listener_register(listener, "window:destroy", NULL);
-    atspi_event_listener_register(listener, "window:activate", NULL);
-    atspi_event_listener_register(listener, "window:deactivate", NULL);
-    atspi_event_listener_register(listener, "object:", NULL);
-
-    mDbusProxy = g_dbus_proxy_new_for_bus_sync(
-        G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE,
-        NULL, /* GDBusInterfaceInfo */
-        "org.a11y.Bus", "/org/a11y/bus", "org.freedesktop.DBus.Properties",
-        NULL, &error);
-
-    enabled_variant = g_variant_new_boolean(true);
-    result = g_dbus_proxy_call_sync(
-        mDbusProxy, "Set",
-        g_variant_new("(ssv)", "org.a11y.Status", "IsEnabled", enabled_variant),
-        G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-
-    g_variant_unref(enabled_variant);
-    g_variant_unref(result);
-
-}
-
-AccessibleWatcher::~AccessibleWatcher()
-{
-    GVariant *enabled_variant = nullptr, *result = nullptr;
-    GError *  error = nullptr;
-
-    enabled_variant = g_variant_new_boolean(false);
-    result = g_dbus_proxy_call_sync(
-        mDbusProxy, "Set",
-        g_variant_new("(ssv)", "org.a11y.Status", "IsEnabled", enabled_variant),
-        G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
-
-
-    for (auto it = mAccessibleNode.begin(); it != mAccessibleNode.end(); ++it) {
-        g_object_unref(it->first);
-        delete it->second;
-    }
-    atspi_event_listener_deregister(listener, "window:", NULL);
-    atspi_event_listener_deregister(listener, "object:", NULL);
-
-    g_object_unref(listener);
-    g_object_unref(mDbusProxy);
-    g_variant_unref(enabled_variant);
-    g_variant_unref(result);
-
-    atspi_event_quit();
-    atspi_exit();
-}
-
-std::unique_ptr<AccessibleNode> AccessibleWatcher::getRootNode() const
-{
-    auto node = make_gobj_unique(atspi_get_desktop(0));
-    auto accNode = AccessibleNode::get(node.get());
-    if(node.get()) g_object_unref(node.get());
-    return accNode;
-}
-
-std::vector<std::unique_ptr<AccessibleNode>> AccessibleWatcher::getTopNode() const
-{
-    AtspiAccessible *topNode = nullptr, *activeNode = nullptr;
-    std::vector<std::unique_ptr<AccessibleNode>> ret;
-
-    {
-        std::unique_lock<std::mutex> lock(mLock);
-        if (!mActivatedWindowList.empty()) {
-            topNode = mActivatedWindowList.front();
-            std::list<AtspiAccessible *>::const_iterator iterator;
-            for (iterator = mActivatedWindowList.begin(); iterator != mActivatedWindowList.end(); ++iterator){
-                if (*iterator && iShowingNode(*iterator)) {
-                    AtspiAccessible *child = atspi_accessible_get_application(*iterator, NULL);
-                    if (child) {
-                        auto tmpNode = make_gobj_unique(child);
-                        auto node =  AccessibleNode::get(tmpNode.get());
-                        if (tmpNode.get()) g_object_unref(tmpNode.get());
-                        ret.push_back(std::move(node));
-                    }
-                }
-            }
-            return ret;
-        }
-    }
-
-    LOG_F(INFO, "Mo activated window node or Invisible acticated window / topNdoe(%p)", topNode);
-    LOG_F(INFO, "Trying fallback logic");
-
-    auto rootNode = make_gobj_unique(atspi_get_desktop(0));
-
-    if (rootNode) {
-        std::vector<AtspiAccessible*> activeNodes = findActiveNode(rootNode.get(), 0, 2);
-        if (!activeNodes.empty()) {
-            std::vector<AtspiAccessible*>::const_iterator iterator;
-            for (iterator = activeNodes.begin(); iterator != activeNodes.end(); ++iterator){
-                auto tmpNode = make_gobj_unique(atspi_accessible_get_application(*iterator, NULL));
-                auto node = AccessibleNode::get(tmpNode.get());
-                if (tmpNode.get()) g_object_unref(tmpNode.get());
-                g_object_unref(*iterator);
-                ret.push_back(std::move(node));
-            }
-        } else {
-            auto node = AccessibleNode::get(rootNode.get());
-            if (rootNode.get()) g_object_unref(rootNode.get());
-            ret.push_back(std::move(node));
-        }
-    }
-    return ret;
-}
-
-void AccessibleWatcher::onAtspiWindowEvent(AtspiEvent *event, void *user_data)
-{
-    char *name = NULL, *pname = NULL;
-    IAtspiEvents *instance = (IAtspiEvents *)user_data;
-
-    if (!event->source)
-    {
-        LOG_F(INFO, "event->source is NULL. Skip event handling");
-        return;
-    }
-
-    auto p = make_gobj_unique(atspi_accessible_get_parent(event->source, NULL));
-
-    name = atspi_accessible_get_name(event->source, NULL);
-    if (p) pname = atspi_accessible_get_name(p.get(), NULL);
-
-     LOG_SCOPE_F(INFO, "event:%s, src:%p(%s), p:%p(%s), d1:%p d2:%p instance:%p",
-                 event->type, event->source, name, p.get(), pname, event->detail1,
-                 event->detail2, instance);
-
-    if (!strcmp(event->type, "window:activate")) {
-        instance->onWindowActivated(
-            static_cast<AtspiAccessible *>(event->source),
-            static_cast<WindowActivateInfoType>(event->detail1));
-    } else if (!strcmp(event->type, "window:deactivate")) {
-        instance->onWindowDeactivated(static_cast<AtspiAccessible *>(event->source));
-    } else if (!strcmp(event->type, "window:create")) {
-        instance->onWindowCreated(static_cast<AtspiAccessible *>(event->source));
-    } else if (!strcmp(event->type, "window:destroy")) {
-        instance->onWindowDestroyed(static_cast<AtspiAccessible *>(event->source));
-    } else if (!strcmp(event->type, "object:state-changed:visible")) {
-        instance->onVisibilityChanged(
-            static_cast<AtspiAccessible *>(event->source),
-            (event->detail1 != 0));
-    } else if (!strcmp(event->type, "object:state-changed:defunct")) {
-        instance->onObjectDefunct(
-            static_cast<AtspiAccessible *>(event->source));
-    }
-    if (name) free(name);
-    if (pname) free(pname);
-}
-
-void AccessibleWatcher::printDbgInformation() const
-{
-    LOG_SCOPE_F(INFO, "%d %d", mActivatedWindowList.size(),  mWindowSet.size());
-
-    for (auto iter = mActivatedWindowList.begin(); iter != mActivatedWindowList.end(); ++iter) {
-        LOG_F(INFO, "%p", *iter);
-    }
-        LOG_F(INFO, "-----------");
-
-    for (auto iter = mWindowSet.begin(); iter != mWindowSet.end(); ++iter) {
-        LOG_F(INFO, "%p", *iter);
-    }
-}
-
-const AccessibleWatcher *AccessibleWatcher::getInstance()
-{
-    static AccessibleWatcher *mInstance = nullptr;
-    if (!mInstance) mInstance = new AccessibleWatcher();
-    return mInstance;
-}
-
-void AccessibleWatcher::clearWindowList() const
-{
-    std::unique_lock<std::mutex> lock(mLock);
-    while (!mActivatedWindowList.empty()) {
-        AtspiAccessible *n = mActivatedWindowList.front();
-        mActivatedWindowList.pop_front();
-        g_object_unref(n);
-    }
-
-    mWindowSet.clear();
-}
-
-bool AccessibleWatcher::removeFromActivatedList(AtspiAccessible *node)
-{
-    mActivatedWindowList.remove_if([&](auto &n) { return n == node; });
-    return true;
-}
-
-bool AccessibleWatcher::addToActivatedList(AtspiAccessible *node)
-{
-    mActivatedWindowList.remove_if([&](auto &n) { return n == node; });
-    mActivatedWindowList.push_front(node);
-
-    auto iter = mWindowSet.find(node);
-    if ( iter == mWindowSet.end()) mWindowSet.insert(node);
-    return true;
-}
-
-bool AccessibleWatcher::removeFromWindowSet(AtspiAccessible *node)
-{
-    removeFromActivatedList(node);
-    auto iter = mWindowSet.find(node);
-    if ( iter != mWindowSet.end()){
-        mWindowSet.erase(node);
-        return true;
-    }
-    return false;
-}
-
-bool AccessibleWatcher::addToWindowSet(AtspiAccessible *node)
-{
-    auto iter = mWindowSet.find(node);
-    if ( iter == mWindowSet.end()){
-        mWindowSet.insert(node);
-        return true;
-    }
-    return false;
-}
-
-void AccessibleWatcher::onWindowActivated(AtspiAccessible *      node,
-                            WindowActivateInfoType type)
-{
-    std::unique_lock<std::mutex> lock(mLock);
-    addToActivatedList(node);
-    return;
-}
-
-void AccessibleWatcher::onWindowDeactivated(AtspiAccessible *node)
-{
-    std::unique_lock<std::mutex> lock(mLock);
-    removeFromActivatedList(node);
-    return;
-}
-
-void AccessibleWatcher::onWindowCreated(AtspiAccessible *node)
-{
-    std::unique_lock<std::mutex> lock(mLock);
-    addToWindowSet(node);
-}
-
-void AccessibleWatcher::onWindowDestroyed(AtspiAccessible *node)
-{
-    std::unique_lock<std::mutex> lock(mLock);
-    removeFromWindowSet(node);
-}
-
-void AccessibleWatcher::onVisibilityChanged(AtspiAccessible *node, bool visible)
-{
-}
-
-void AccessibleWatcher::onObjectDefunct(AtspiAccessible *node)
-{
-    LOG_SCOPE_F(INFO, "object defuncted %p", node);
-}
index e9cdc11..1b74334 100644 (file)
@@ -2,7 +2,7 @@
 
 #include <loguru.hpp>
 
-Comparer::Comparer(const UiDevice *device, const std::shared_ptr<UiSelector> selector,
+Comparer::Comparer(const std::shared_ptr<UiDevice> device, const std::shared_ptr<UiSelector> selector,
                    const bool &earlyReturn)
     : mDevice(device), mSelector(selector), mEarlyReturn(earlyReturn)
 {
@@ -10,60 +10,69 @@ Comparer::Comparer(const UiDevice *device, const std::shared_ptr<UiSelector> sel
 
 Comparer::~Comparer() {}
 
-std::unique_ptr<AccessibleNode> Comparer::findObject(const UiDevice *      device,
+std::shared_ptr<AccessibleNode> Comparer::findObject(const std::shared_ptr<UiDevice> device,
                                      const std::shared_ptr<UiSelector> selector,
-                                     const AccessibleNode *root)
+                                     const std::shared_ptr<AccessibleNode> root)
 {
     Comparer                      comparer(device, selector, true);
-    std::vector<std::unique_ptr<AccessibleNode>> ret = comparer.findObjects(root);
+    std::vector<std::shared_ptr<AccessibleNode>> ret = comparer.findObjects(root);
     if (ret.size() > 0)
         return std::move(ret[0]);
     else
         return nullptr;
 }
 
-std::vector<std::unique_ptr<AccessibleNode>> Comparer::findObjects(const UiDevice *  device,
+std::vector<std::shared_ptr<AccessibleNode>> Comparer::findObjects(const std::shared_ptr<UiDevice> device,
                                                     const std::shared_ptr<UiSelector> selector,
-                                                    const AccessibleNode *root)
+                                                    const std::shared_ptr<AccessibleNode> root)
 {
     Comparer                      comparer(device, selector, false);
-    std::vector<std::unique_ptr<AccessibleNode>> ret = comparer.findObjects(root);
+    std::vector<std::shared_ptr<AccessibleNode>> ret = comparer.findObjects(root);
     return ret;
 }
 
-std::vector<std::unique_ptr<AccessibleNode>> Comparer::findObjects(const AccessibleNode *root)
+std::vector<std::shared_ptr<AccessibleNode>> Comparer::findObjects(const std::shared_ptr<AccessibleNode> root)
 {
     std::list<std::shared_ptr<PartialMatch>> partialList{};
-    std::vector<std::unique_ptr<AccessibleNode>> ret = findObjects(root, 0, 0, partialList);
+    std::vector<std::shared_ptr<AccessibleNode>> ret = findObjects(root, 0, 0, partialList);
     return ret;
 }
 
-std::vector<std::unique_ptr<AccessibleNode>> Comparer::findObjects(
-    const AccessibleNode *root, const int &index, const int &depth,
+std::vector<std::shared_ptr<AccessibleNode>> Comparer::findObjects(
+    const std::shared_ptr<AccessibleNode> root, const int &index, const int &depth,
     std::list<std::shared_ptr<PartialMatch>> &partialMatches)
 {
-    std::vector<std::unique_ptr<AccessibleNode>> ret;
+    std::vector<std::shared_ptr<AccessibleNode>> ret;
     root->refresh();
+    LOG_SCOPE_F(INFO, "findObjects %s, %s, %s / i:%d d:%d / p.matches:%d", root->getText().c_str(), root->getType().c_str(), root->getStyle().c_str(), index, depth, partialMatches.size());
 
-    for (auto match : partialMatches)
+    for (auto &match : partialMatches)
         match->update(root, index, depth, partialMatches);
 
     std::shared_ptr<PartialMatch> currentMatch =
         PartialMatch::accept(root, mSelector, index, depth);
     if (currentMatch) partialMatches.push_front(currentMatch);
 
-    int childCnt = root->getChildCount();
-    for (int i = 0; i < childCnt; i++) {
-        std::unique_ptr<AccessibleNode> childNode = root->getChildAt(i);
-        std::vector<std::unique_ptr<AccessibleNode>> childret =
-            findObjects(childNode.get(), i, depth + 1, partialMatches);
-        std::move(std::begin(childret), std::end(childret), std::back_inserter(ret));
+    if (!(mSelector->mMaxDepth && (depth+1 > *(mSelector->mMaxDepth)))) {
+        int childCnt = root->getChildCount();
+        for (int i = 0; i < childCnt; i++) {
+            std::shared_ptr<AccessibleNode> childNode = root->getChildAt(i);
+            if (childNode == nullptr) continue;
 
-        if (!ret.empty() && mEarlyReturn) return ret;
+            std::vector<std::shared_ptr<AccessibleNode>> childret =
+                findObjects(childNode, i, depth + 1, partialMatches);
+            std::move(std::begin(childret), std::end(childret), std::back_inserter(ret));
+
+            if (!ret.empty() && mEarlyReturn) return ret;
+        }
+    } else {
+        LOG_F(INFO, "no need to search children(maxDepth limit overflow, %d < %d < %d)", mSelector->mMinDepth?*(mSelector->mMinDepth):-1, depth, mSelector->mMaxDepth?*(mSelector->mMaxDepth):9999999);
     }
 
-    if (currentMatch && currentMatch->finalizeMatch())
-        ret.push_back(AccessibleNode::get(root->getAccessible()));
+    if (currentMatch && currentMatch->finalizeMatch()){
+        LOG_F(INFO, "child 3 %p(raw:%p)", root.get(), root->getRawHandler());
+        ret.push_back(root);
+    }
 
     return ret;
 }
\ No newline at end of file
diff --git a/libaurum/src/Impl/Accessibility/AtspiAccessibleApplication.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleApplication.cc
new file mode 100644 (file)
index 0000000..4c828c7
--- /dev/null
@@ -0,0 +1,34 @@
+#include "AtspiAccessibleApplication.h"
+#include "AtspiAccessibleWindow.h"
+#include <algorithm>
+#include <vector>
+
+#include <loguru.hpp>
+
+AtspiAccessibleApplication::AtspiAccessibleApplication(std::shared_ptr<AccessibleNode> node)
+: AccessibleApplication(node)
+{
+}
+
+AtspiAccessibleApplication::~AtspiAccessibleApplication()
+{
+}
+
+std::vector<std::shared_ptr<AccessibleWindow>> AtspiAccessibleApplication::getWindows(void)
+{
+    std::vector<std::shared_ptr<AccessibleWindow>> ret{};
+    auto children = getAccessibleNode()->getChildren();
+
+    std::transform(children.begin(), children.end(), std::back_inserter(ret),
+        [&](auto child) {
+            return std::make_shared<AtspiAccessibleWindow>(this->shared_from_this(), child);
+        }
+    );
+
+    return ret;
+}
+
+std::string AtspiAccessibleApplication::getPackageName(void)
+{
+    return getAccessibleNode()->getText();
+}
\ No newline at end of file
similarity index 59%
rename from libaurum/src/AccessibleNode.cc
rename to libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc
index dd07b01..a497533 100644 (file)
@@ -1,32 +1,15 @@
-#include "AccessibleNode.h"
-#include <string.h>
-#include <iostream>
-#include <vector>
+#include "AtspiAccessibleNode.h"
 
-#include <loguru.hpp>
-#include "config.h"
-
-std::map<AtspiAccessible *, AccessibleNode *> AccessibleNode::mNodeMap{};
-
-AccessibleNode::~AccessibleNode()
-{
+#include <gio/gio.h>
 
-}
+#include <loguru.hpp>
 
-AccessibleNode::AccessibleNode() : AccessibleNode(nullptr)
-{
-    // No meaning without AtspiAccessbile object
-    // prohibited to create this object with this constructor
-}
+//std::map<AtspiAccessible *, AccessibleNode *> AccessibleNode::mNodeMap{};
 
-AccessibleNode::AccessibleNode(AtspiAccessible *node)
-    : mNode(make_gobj_ref_unique(node)), mBoundingBox{0,0,0,0}, mSupportingIfaces(0), mFeatureProperty(0), mIsAlive(true)
+AtspiAccessibleNode::AtspiAccessibleNode(AtspiAccessible *node)
+: mNode{node}
 {
-    // prohibited to create this object this constructor
-    // better to use AccessibleNode::get factory method.
-
-    LOG_SCOPE_F(1, "AccessibleNode constructor %p", mNode.get());
-    GArray *ifaces = atspi_accessible_get_interfaces(mNode.get());
+  GArray *ifaces = atspi_accessible_get_interfaces(mNode);
     if (ifaces) {
         for (unsigned int i = 0; i < ifaces->len; i++) {
             char *iface = g_array_index(ifaces, char *, i);
@@ -74,32 +57,79 @@ AccessibleNode::AccessibleNode(AtspiAccessible *node)
 
             g_free(iface);
         }
-
         g_array_free(ifaces, FALSE);
     }
     this->refresh();
 }
 
-std::unique_ptr<AccessibleNode> AccessibleNode::get(AtspiAccessible *node)
+AtspiAccessibleNode::~AtspiAccessibleNode()
+{
+    if(mNode) g_object_unref(mNode);
+}
+
+int AtspiAccessibleNode::getChildCount() const
+{
+    int count = atspi_accessible_get_child_count(mNode, NULL);
+    if (count <= 0) return 0;
+    return count;
+}
+
+std::shared_ptr<AccessibleNode> AtspiAccessibleNode::getChildAt(int index) const
+{
+    LOG_SCOPE_F(INFO, "getChild @ %d from node(%p)", index, mNode);
+    AtspiAccessible *rawChild = atspi_accessible_get_child_at_index(mNode, index, NULL);
+    return std::make_shared<AtspiAccessibleNode>(rawChild);
+}
+
+std::vector<std::shared_ptr<AccessibleNode>> AtspiAccessibleNode::getChildren() const
 {
-    return std::make_unique<AccessibleNode>(node);
+    std::vector<std::shared_ptr<AccessibleNode>> ret{};
+    int nchild = this->getChildCount();
+    for (int i = 0; i < nchild; i++) {
+        auto child = getChildAt(i);
+        if (child) ret.push_back(child);
+    }
+    return ret;
 }
 
-void AccessibleNode::refresh() const
+std::shared_ptr<AccessibleNode> AtspiAccessibleNode::getParent() const
 {
-    gchar *rolename = atspi_accessible_get_role_name(mNode.get(), NULL);
+    AtspiAccessible *rawParent = atspi_accessible_get_parent(mNode, NULL);
+    return std::make_shared<AtspiAccessibleNode>(rawParent);
+/*  auto node = AccessibleNode::get(parent);
+    if (parent) g_object_unref(parent);
+    return node; */
+}
+
+
+void* AtspiAccessibleNode::getRawHandler(void) const
+{
+    return static_cast<void*>(mNode);
+}
+
+void AtspiAccessibleNode::refresh()
+{
+    gchar *rolename = atspi_accessible_get_role_name(mNode, NULL);
     if (rolename) {
         mRole = rolename;
         g_free(rolename);
     }
-
-    gchar *uID = atspi_accessible_get_unique_id(mNode.get(), NULL);
+#ifdef TIZEN
+    gchar *uID = atspi_accessible_get_unique_id(mNode, NULL);
     if (uID) {
         mRes = uID;
         g_free(uID);
     }
+#else
+    mRes = std::string{"N/A"};
+#endif
 
-    GHashTable *attributes = atspi_accessible_get_attributes(mNode.get(), NULL);
+    gchar *name = atspi_accessible_get_name(mNode, NULL);
+    mText = name;
+    mPkg = name;
+    g_free(name);
+
+    GHashTable *attributes = atspi_accessible_get_attributes(mNode, NULL);
     char *t = (char*)g_hash_table_lookup(attributes, "type");
     char *s = (char*)g_hash_table_lookup(attributes, "style");
 
@@ -111,7 +141,7 @@ void AccessibleNode::refresh() const
 
     g_hash_table_unref(attributes);
 
-    AtspiStateSet *st = atspi_accessible_get_state_set(mNode.get());
+    AtspiStateSet *st = atspi_accessible_get_state_set(mNode);
     GArray *states = atspi_state_set_get_states(st);
 
     char *state_name = NULL;
@@ -123,69 +153,83 @@ void AccessibleNode::refresh() const
 
     if (states) g_array_free(states, 0);
     g_object_unref(st);
-}
-
-int AccessibleNode::getChildCount() const
-{
-    return atspi_accessible_get_child_count(mNode.get(), NULL);
-}
 
-std::unique_ptr<AccessibleNode> AccessibleNode::getChildAt(int index) const
-{
-    AtspiAccessible *child =
-        atspi_accessible_get_child_at_index(mNode.get(), index, NULL);
-    if (child) {
-        auto node = AccessibleNode::get(child);
-        g_object_unref(child);
-        return node;
+    AtspiComponent *component = atspi_accessible_get_component_iface(mNode);
+    if (component) {
+        AtspiRect *extent = atspi_component_get_extents(
+            component, ATSPI_COORD_TYPE_SCREEN, NULL);
+        if (extent) {
+            mBoundingBox =
+                Rect<int>{extent->x, extent->y, extent->x + extent->width,
+                          extent->y + extent->height};
+            g_free(extent);
+        }
+        g_object_unref(component);
     }
-    return AccessibleNode::get(nullptr);
-}
-
-std::unique_ptr<AccessibleNode> AccessibleNode::getParent() const
-{
-    AtspiAccessible *parent = atspi_accessible_get_parent(mNode.get(), NULL);
-    auto node = AccessibleNode::get(parent);
-    if (parent) g_object_unref(parent);
-    return node;
 }
 
-void AccessibleNode::print(int d, int m) const
+std::vector<std::string> AtspiAccessibleNode::getActions() const
 {
-    if (m <= 0 || d > m) return;
+    std::vector<std::string> result{};
+    const char *name;
+    AtspiAction *action;
 
-    int             n = 0;
-    this->print(d);
-    n = getChildCount();
+    action = atspi_accessible_get_action_iface(mNode);
+    if (action) {
+        int a;
+        int n_actions = atspi_action_get_n_actions(action, NULL);
 
-    for (int i = 0; i < n; i++) {
-        auto child = getChildAt(i);
-        if (child) child->print(d + 1, m);
+        for (a = 0; a < n_actions; a++) {
+            char *action_name = atspi_action_get_action_name(action, a, NULL);
+            if (!action_name) continue;
+            result.push_back(std::string{action_name});
+            g_free(action_name);
+        }
+        g_object_unref(action);
     }
+    return result;
 }
 
-void AccessibleNode::print(int d) const
+bool AtspiAccessibleNode::doAction(std::string actionName)
 {
-    char *name = atspi_accessible_get_name(mNode.get(), NULL);
-    char *role = atspi_accessible_get_role_name(mNode.get(), NULL);
-    LOG_F(INFO, "%s - %p(%s)  /  role:%s, pkg:%s, text:%s",
-          std::string(d, ' ').c_str(), mNode.get(), name, role, getPkg().c_str(),
-          getText().c_str());
-    free(name);
-    free(role);
-}
+    const char *name;
+    AtspiAction *action;
 
-bool AccessibleNode::isSupporting(AccessibleNodeInterface thisIface) const
-{
-    return (mSupportingIfaces & static_cast<int>(thisIface)) != 0;
+    action = atspi_accessible_get_action_iface(mNode);
+    if (action) {
+        int a;
+        int n_actions = atspi_action_get_n_actions(action, NULL);
+
+        for (a = 0; a < n_actions; a++) {
+            char *action_name = atspi_action_get_action_name(action, a, NULL);
+            if (!action_name) return false;
+
+            if (!strcmp(actionName.c_str(), action_name)) {
+                atspi_action_do_action(action, a, NULL);
+                g_free(action_name);
+                g_object_unref(action);
+                return true;
+            }
+            g_free(action_name);
+        }
+        g_object_unref(action);
+    }
+    return false;
 }
 
-bool AccessibleNode::hasFeatureProperty(NodeFeatureProperties prop) const
+void AtspiAccessibleNode::setValue(std::string text)
 {
-    return (mFeatureProperty & static_cast<int>(prop)) != 0;
+    AtspiEditableText *iface = atspi_accessible_get_editable_text(mNode);
+    LOG_F(INFO,"set Value iface:%p obj:%p text:%s", iface, mNode, text.c_str() );
+    if (iface) {
+        int len = getText().length();
+        atspi_editable_text_delete_text(iface, 0, len, NULL);
+        atspi_editable_text_insert_text(iface, 0, text.c_str(), text.length(),
+                                        NULL);
+    }
 }
 
-void AccessibleNode::setFeatureProperty(AtspiStateType type) const
+void AtspiAccessibleNode::setFeatureProperty(AtspiStateType type)
 {
 /*
     LONGCLICKABLE = 0X0040,
@@ -225,15 +269,16 @@ void AccessibleNode::setFeatureProperty(AtspiStateType type) const
         case ATSPI_STATE_SENSITIVE:
             setFeatureProperty(NodeFeatureProperties::CLICKABLE, true);
             break;
-
+        case ATSPI_STATE_DEFUNCT:
+        case ATSPI_STATE_INVALID:
+            setFeatureProperty(NodeFeatureProperties::INVALID, true);
+            break;
         case ATSPI_STATE_TRANSIENT:
         case ATSPI_STATE_TRUNCATED:
         case ATSPI_STATE_ANIMATED:
-        case ATSPI_STATE_INVALID:
         case ATSPI_STATE_ARMED:
         case ATSPI_STATE_BUSY:
         case ATSPI_STATE_COLLAPSED:
-        case ATSPI_STATE_DEFUNCT:
         case ATSPI_STATE_EDITABLE:
         case ATSPI_STATE_EXPANDABLE:
         case ATSPI_STATE_EXPANDED:
@@ -262,196 +307,4 @@ void AccessibleNode::setFeatureProperty(AtspiStateType type) const
         case ATSPI_STATE_LAST_DEFINED:
         break;
     }
-}
-
-void AccessibleNode::setFeatureProperty(NodeFeatureProperties prop, bool has) const
-{
-    if (has)
-        mFeatureProperty |= static_cast<int>(prop);
-    else
-        mFeatureProperty &= ~static_cast<int>(prop);
-}
-
-std::string AccessibleNode::getDesc() const
-{
-    return mDesc;
-}
-
-std::string AccessibleNode::getText() const
-{
-    gchar *name = atspi_accessible_get_name(mNode.get(), NULL);
-    mText = name;
-    mPkg = name;
-    g_free(name);
-
-    return mText;
-}
-
-std::string AccessibleNode::getPkg() const
-{
-    return mPkg;
-}
-
-std::string AccessibleNode::getRes() const
-{
-    return mRes;
-}
-
-std::string AccessibleNode::getType() const
-{
-    return mType;
-}
-
-std::string AccessibleNode::getStyle() const
-{
-    return mStyle;
-}
-
-Rect<int> AccessibleNode::getBoundingBox() const
-{
-    AtspiComponent *component = atspi_accessible_get_component_iface(mNode.get());
-    if (component) {
-        AtspiRect *extent = atspi_component_get_extents(
-            component, ATSPI_COORD_TYPE_SCREEN, NULL);
-        if (extent) {
-            mBoundingBox =
-                Rect<int>{extent->x, extent->y, extent->x + extent->width,
-                          extent->y + extent->height};
-            g_free(extent);
-        }
-        g_object_unref(component);
-    }
-
-    return mBoundingBox;
-}
-
-bool AccessibleNode::isCheckable() const
-{
-    return hasFeatureProperty(NodeFeatureProperties::CHECKABLE);
-}
-
-bool AccessibleNode::isChecked() const
-{
-    return hasFeatureProperty(NodeFeatureProperties::CHECKED);
-}
-
-bool AccessibleNode::isClickable() const
-{
-    return hasFeatureProperty(NodeFeatureProperties::CLICKABLE);
-}
-
-bool AccessibleNode::isEnabled() const
-{
-    return hasFeatureProperty(NodeFeatureProperties::ENABLED);
-}
-
-bool AccessibleNode::isFocusable() const
-{
-    return hasFeatureProperty(NodeFeatureProperties::FOCUSABLE);
-}
-
-bool AccessibleNode::isFocused() const
-{
-    return hasFeatureProperty(NodeFeatureProperties::FOCUSED);
-}
-
-bool AccessibleNode::isLongClickable() const
-{
-    return hasFeatureProperty(NodeFeatureProperties::LONGCLICKABLE);
-}
-
-bool AccessibleNode::isScrollable() const
-{
-    return hasFeatureProperty(NodeFeatureProperties::SCROLLABLE);
-}
-
-bool AccessibleNode::isSelectable() const
-{
-    return hasFeatureProperty(NodeFeatureProperties::SELECTABLE);
-}
-
-bool AccessibleNode::isSelected() const
-{
-    return hasFeatureProperty(NodeFeatureProperties::SELECTED);
-}
-
-bool AccessibleNode::isVisible() const
-{
-    return hasFeatureProperty(NodeFeatureProperties::VISIBLE);
-}
-
-bool AccessibleNode::isShowing() const
-{
-    return hasFeatureProperty(NodeFeatureProperties::SHOWING);
-}
-
-bool AccessibleNode::isActive() const
-{
-    return hasFeatureProperty(NodeFeatureProperties::ACTIVE);
-}
-
-AtspiAccessible *AccessibleNode::getAccessible() const
-{
-    return mNode.get();
-}
-
-void AccessibleNode::setValue(std::string text) const
-{
-    AtspiEditableText *iface = atspi_accessible_get_editable_text(mNode.get());
-    LOG_F(INFO,"set Value iface:%p obj:%p text:%s", iface, mNode.get(), text.c_str() );
-    if (iface) {
-        int len = getText().length();
-        atspi_editable_text_delete_text(iface, 0, len, NULL);
-        atspi_editable_text_insert_text(iface, 0, text.c_str(), text.length(),
-                                        NULL);
-    }
-}
-
-std::vector<std::string> AccessibleNode::getActions() const
-{
-    std::vector<std::string> result{};
-    const char *name;
-    AtspiAction *action;
-
-    action = atspi_accessible_get_action_iface(mNode.get());
-    if (action) {
-        int a;
-        int n_actions = atspi_action_get_n_actions(action, NULL);
-
-        for (a = 0; a < n_actions; a++) {
-            char *action_name = atspi_action_get_action_name(action, a, NULL);
-            if (!action_name) continue;
-            result.push_back(std::string{action_name});
-            g_free(action_name);
-        }
-        g_object_unref(action);
-    }
-    return result;
-}
-
-bool AccessibleNode::doAction(std::string actionName) const
-{
-    const char *name;
-    AtspiAction *action;
-
-    action = atspi_accessible_get_action_iface(mNode.get());
-    if (action) {
-        int a;
-        int n_actions = atspi_action_get_n_actions(action, NULL);
-
-        for (a = 0; a < n_actions; a++) {
-            char *action_name = atspi_action_get_action_name(action, a, NULL);
-            if (!action_name) return false;
-
-            if (!strcmp(actionName.c_str(), action_name)) {
-                atspi_action_do_action(action, a, NULL);
-                g_free(action_name);
-                g_object_unref(action);
-                return true;
-            }
-            g_free(action_name);
-        }
-        g_object_unref(action);
-    }
-    return false;
 }
\ No newline at end of file
diff --git a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc
new file mode 100644 (file)
index 0000000..f82ae7a
--- /dev/null
@@ -0,0 +1,406 @@
+#include "AtspiAccessibleWatcher.h"
+
+#include "AtspiAccessibleApplication.h"
+#include "AtspiAccessibleWindow.h"
+#include "AtspiAccessibleNode.h"
+
+#include <algorithm>
+
+#include <loguru.hpp>
+
+AtspiEventListener *AtspiAccessibleWatcher::listener = nullptr;
+
+static bool iShowingNode(AtspiAccessible *node)
+{
+    char *name = NULL;
+    if (node) name = atspi_accessible_get_name(node, NULL);
+    else return false;
+
+    LOG_SCOPE_F(INFO, "isShowing %s", name);
+    auto stateSet = atspi_accessible_get_state_set(node);
+    auto states = atspi_state_set_get_states(stateSet);
+
+    if (atspi_state_set_contains(stateSet, ATSPI_STATE_ACTIVE)
+        && atspi_state_set_contains(stateSet, ATSPI_STATE_SHOWING)) {
+        LOG_F(INFO, "active and showing %p %s", node, name);
+        free(name);
+        // TODO : free states and stateSet
+        return true;
+    }
+    free(name);
+    // TODO : free states and stateSet
+    return false;
+}
+
+static std::vector<AtspiAccessible *>
+findActiveNode(AtspiAccessible *node, int depth,
+                                       int max_depth)
+{
+    LOG_SCOPE_F(INFO, "findActiveNode %p %d/%d", node, depth, max_depth);
+
+    std::vector<AtspiAccessible *> ret{};
+
+    if (iShowingNode(node)) {
+        g_object_ref(node);
+        char *name = atspi_accessible_get_name(node, NULL);
+        if (name) {
+            LOG_SCOPE_F(INFO, "%s", name);
+            free(name);
+        }
+        ret.push_back(node);
+        return ret;
+    }
+
+    if (depth >= max_depth) return ret;
+
+    int nchild = atspi_accessible_get_child_count(node, NULL);
+    if (nchild <= 0) return ret;
+
+    LOG_F(INFO, "findActiveNode node %p has %d children", node, nchild);
+    for (int i = 0; i < nchild; i++) {
+        AtspiAccessible* child = atspi_accessible_get_child_at_index(node, i, NULL);
+        LOG_F(INFO, "a child found @ %d : %p", i, child);
+        std::vector<AtspiAccessible *> childRet = findActiveNode(child, depth + 1, max_depth);
+        ret.insert(ret.end(), childRet.begin(), childRet.end());
+        g_object_unref(child);
+    }
+
+    return ret;
+}
+
+AtspiAccessibleWatcher::AtspiAccessibleWatcher()
+: mDbusProxy{nullptr}, mLock{}
+{
+    GVariant *enabled_variant = nullptr, *result = nullptr;
+    GError *  error = nullptr;
+    atspi_set_main_context (g_main_context_default ());
+    atspi_init();
+
+    listener =
+        atspi_event_listener_new(AtspiAccessibleWatcher::onAtspiWindowEvent, this, NULL);
+    LOG_SCOPE_F(INFO, "WKWK init this:%p", this);
+
+    atspi_event_listener_register(listener, "window:create", NULL);
+    atspi_event_listener_register(listener, "window:destroy", NULL);
+    atspi_event_listener_register(listener, "window:activate", NULL);
+    atspi_event_listener_register(listener, "window:deactivate", NULL);
+    atspi_event_listener_register(listener, "object:", NULL);
+
+    mDbusProxy = g_dbus_proxy_new_for_bus_sync(
+        G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE,
+        NULL, /* GDBusInterfaceInfo */
+        "org.a11y.Bus", "/org/a11y/bus", "org.freedesktop.DBus.Properties",
+        NULL, &error);
+
+    enabled_variant = g_variant_new_boolean(true);
+    result = g_dbus_proxy_call_sync(
+        mDbusProxy, "Set",
+        g_variant_new("(ssv)", "org.a11y.Status", "IsEnabled", enabled_variant),
+        G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+    g_variant_unref(enabled_variant);
+    g_variant_unref(result);
+}
+
+AtspiAccessibleWatcher::~AtspiAccessibleWatcher()
+{
+    GVariant *enabled_variant = nullptr, *result = nullptr;
+    GError *  error = nullptr;
+
+    enabled_variant = g_variant_new_boolean(false);
+    result = g_dbus_proxy_call_sync(
+        mDbusProxy, "Set",
+        g_variant_new("(ssv)", "org.a11y.Status", "IsEnabled", enabled_variant),
+        G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+    atspi_event_listener_deregister(listener, "window:", NULL);
+    atspi_event_listener_deregister(listener, "object:", NULL);
+
+    g_object_unref(listener);
+    g_object_unref(mDbusProxy);
+    g_variant_unref(enabled_variant);
+    g_variant_unref(result);
+
+    atspi_event_quit();
+    atspi_exit();
+}
+
+
+void AtspiAccessibleWatcher::onAtspiWindowEvent(AtspiEvent *event, void *user_data)
+{
+    char *name = NULL, *pname = NULL;
+    AtspiAccessibleWatcher *instance = (AtspiAccessibleWatcher *)user_data;
+
+    if (!event->source)
+    {
+        LOG_F(INFO, "event->source is NULL. Skip event handling");
+        return;
+    }
+
+
+    AtspiAccessible *parent = atspi_accessible_get_parent(event->source, NULL);
+
+    name = atspi_accessible_get_name(event->source, NULL);
+    if (parent) {
+        pname = atspi_accessible_get_name(parent, NULL);
+        g_object_unref(parent);
+    }
+
+     LOG_SCOPE_F(INFO, "event:%s, src:%p(%s), p:%p(%s), d1:%p d2:%p instance:%p",
+                 event->type, event->source, name, parent, pname, event->detail1,
+                 event->detail2, instance);
+
+    if (!strcmp(event->type, "window:activate")) {
+        instance->onWindowActivated(
+            static_cast<AtspiAccessible *>(event->source),
+            static_cast<WindowActivateInfoType>(event->detail1));
+    } else if (!strcmp(event->type, "window:deactivate")) {
+        instance->onWindowDeactivated(static_cast<AtspiAccessible *>(event->source));
+    } else if (!strcmp(event->type, "window:create")) {
+        instance->onWindowCreated(static_cast<AtspiAccessible *>(event->source));
+    } else if (!strcmp(event->type, "window:destroy")) {
+        instance->onWindowDestroyed(static_cast<AtspiAccessible *>(event->source));
+    } else if (!strcmp(event->type, "object:state-changed:visible")) {
+        instance->onVisibilityChanged(
+            static_cast<AtspiAccessible *>(event->source),
+            (event->detail1 != 0));
+    } else if (!strcmp(event->type, "object:state-changed:defunct")) {
+        instance->onObjectDefunct(
+            static_cast<AtspiAccessible *>(event->source));
+    }
+    if (name) free(name);
+    if (pname) free(pname);
+
+//    instance->print_debug();
+}
+
+void AtspiAccessibleWatcher::print_debug()
+{
+    LOG_F(INFO, "activatewindowlist-------------------");
+    std::for_each(mActivatedWindowList.begin(), mActivatedWindowList.end(), [](auto acc){
+        LOG_F(INFO, "child:%p", acc);
+    });
+
+    LOG_F(INFO, "mActivatedApplicationList--------------------------");
+    std::for_each(mActivatedApplicationList.begin(), mActivatedApplicationList.end(), [](auto acc){
+        LOG_F(INFO, "child:%p", acc);
+    });
+
+    LOG_F(INFO, "mWindowSet------------------------------");
+    std::for_each(mWindowSet.begin(), mWindowSet.end(), [](auto acc){
+        LOG_F(INFO, "child:%p", acc);
+    });
+    LOG_F(INFO, "------------------------------");
+
+}
+
+void AtspiAccessibleWatcher::onWindowActivated(AtspiAccessible *node,
+                            WindowActivateInfoType type)
+{
+    //std::unique_lock<std::mutex> lock(mLock);
+    LOG_SCOPE_F(INFO, "onWindowActivated obj:%p", node);
+    //addToActivatedList((node));
+    return;
+}
+
+void AtspiAccessibleWatcher::onWindowDeactivated(AtspiAccessible *node)
+{
+    std::unique_lock<std::mutex> lock(mLock);
+    LOG_SCOPE_F(INFO, "onWindowDeactivated obj:%p", node);
+    //removeFromActivatedList(node);
+}
+
+void AtspiAccessibleWatcher::onWindowCreated(AtspiAccessible *node)
+{
+    std::unique_lock<std::mutex> lock(mLock);
+    LOG_SCOPE_F(INFO, "onWindowCreated obj:%p", node);
+    //addToWindowSet(node);
+}
+
+void AtspiAccessibleWatcher::onWindowDestroyed(AtspiAccessible *node)
+{
+    std::unique_lock<std::mutex> lock(mLock);
+    LOG_SCOPE_F(INFO, "onWindowDestroyed obj:%p vis:%d", node);
+    //removeFromWindowSet(node);
+}
+
+void AtspiAccessibleWatcher::onVisibilityChanged(AtspiAccessible *node, bool visible)
+{
+    std::unique_lock<std::mutex> lock(mLock);
+    LOG_SCOPE_F(INFO, "onVisibilityChanged obj:%p vis:%d", node, visible);
+}
+
+void AtspiAccessibleWatcher::onObjectDefunct(AtspiAccessible *node)
+{
+    std::unique_lock<std::mutex> lock(mLock);
+    LOG_SCOPE_F(INFO, "onObjectDefunct obj:%p", node);
+}
+
+
+int AtspiAccessibleWatcher::getApplicationCount(void) const
+{
+    AtspiAccessible *root = atspi_get_desktop(0);
+    int nchild = atspi_accessible_get_child_count(root, NULL);
+    g_object_unref(root);
+    if (nchild <= 0) return 0;
+    return nchild;
+}
+
+std::shared_ptr<AccessibleApplication> AtspiAccessibleWatcher::getApplicationAt(int index) const
+{
+    AtspiAccessible *root = atspi_get_desktop(0);
+    AtspiAccessible* child = atspi_accessible_get_child_at_index(root, index, NULL);
+    g_object_unref(root);
+    return std::make_shared<AtspiAccessibleApplication>(std::make_shared<AtspiAccessibleNode>(child));
+}
+
+std::vector<std::shared_ptr<AccessibleApplication>> AtspiAccessibleWatcher::getApplications(void) const
+{
+    LOG_SCOPE_F(INFO, "getApplications for this(%p)", this);
+    std::vector<std::shared_ptr<AccessibleApplication>> ret{};
+    AtspiAccessible *root = atspi_get_desktop(0);
+    int nchild = atspi_accessible_get_child_count(root, NULL);
+    if (nchild <= 0) {
+        g_object_unref(root);
+        return ret;
+    }
+
+    for (int i = 0; i < nchild; i++){
+        AtspiAccessible* child = atspi_accessible_get_child_at_index(root, i, NULL);
+        if (child) {
+            ret.push_back(std::make_shared<AtspiAccessibleApplication>(std::make_shared<AtspiAccessibleNode>(child)));
+        }
+    }
+    g_object_unref(root);
+    return ret;
+}
+
+/*
+std::shared_ptr<AccessibleNode> AtspiAccessibleWatcher::getRootNode() const
+{
+    auto node = atspi_get_desktop(0);
+    auto aNode = std::make_shared<AccessibleNode>(node);
+    return accNode;
+}
+
+std::vector<std::shared_ptr<AccessibleNode>> AtspiAccessibleWatcher::getTopNode() const
+{
+    AtspiAccessible *topNode = nullptr, *activeNode = nullptr;
+    std::vector<std::shared_ptr<AccessibleNode>> ret;
+
+    {
+        std::unique_lock<std::mutex> lock(mLock);
+        if (!mActivatedWindowList.empty()) {
+            topNode = mActivatedWindowList.front();
+            std::list<AtspiAccessible *>::const_iterator iterator;
+            for (iterator = mActivatedWindowList.begin(); iterator != mActivatedWindowList.end(); ++iterator){
+                if (*iterator && iShowingNode(*iterator)) {
+                    AtspiAccessible *child = atspi_accessible_get_application(*iterator, NULL);
+                    if (child) {
+                        auto tmpNode = make_gobj_unique(child);
+                        auto node =  AccessibleNode::get(tmpNode.get());
+                        if (tmpNode.get()) g_object_unref(tmpNode.get());
+                        ret.push_back((node));
+                    }
+                }
+            }
+            return ret;
+        }
+    }
+
+    LOG_F(INFO, "Mo activated window node or Invisible acticated window / topNdoe(%p)", topNode);
+    LOG_F(INFO, "Trying fallback logic");
+
+    auto rootNode = make_gobj_unique(atspi_get_desktop(0));
+
+    if (rootNode) {
+        std::vector<AtspiAccessible*> activeNodes = findActiveNode(rootNode.get(), 0, 2);
+        if (!activeNodes.empty()) {
+            std::set<AtspiAccessible*> appset{};
+            for (auto iterator = activeNodes.begin(); iterator != activeNodes.end(); ++iterator){
+                //auto tmpNode = make_gobj_unique(atspi_accessible_get_application(*iterator, NULL));
+                auto app = atspi_accessible_get_application(*iterator, NULL);
+                appset.insert(app);
+            }
+            for (auto iterator = appset.begin(); iterator != appset.end(); ++iterator){
+                auto node = AccessibleNode::get(*iterator);
+                g_object_unref(*iterator);
+                LOG_F(INFO, "app has showing window found %p %s %s", node.get(), node->getText().c_str(), node->getPkg().c_str());
+                ret.push_back((node));
+            }
+        } else {
+            auto node = AccessibleNode::get(rootNode.get());
+            if (rootNode.get()) g_object_unref(rootNode.get());
+            ret.push_back((node));
+        }
+    }
+    return ret;
+}
+*/
+/*
+void AtspiAccessibleWatcher::clearWindowList()
+{
+    std::unique_lock<std::mutex> lock(mLock);
+
+    std::for_each(mActivatedWindowSet.begin(), mActivatedWindowSet.end(), [](auto window){
+        g_object_unref(window);
+    });
+    mActivatedWindowSet.clear();
+
+    mWindowSet.clear();
+}
+*/
+
+bool AtspiAccessibleWatcher::removeFromActivatedList(AtspiAccessible *node)
+{
+    LOG_SCOPE_F(INFO,"remove from activelist node %p", node);
+    mActivatedWindowList.remove_if([&](auto &n) { return n == node; });
+
+    AtspiAccessible *app = atspi_accessible_get_application(node, NULL);
+    LOG_F(INFO, "node:%p, app:%p", node, app);
+    if (app) {
+        mActivatedApplicationList.remove_if([&](auto &n) { return n == app; });
+        g_object_unref(app);
+    }
+    return true;
+}
+
+bool AtspiAccessibleWatcher::addToActivatedList(AtspiAccessible *node)
+{
+    LOG_SCOPE_F(INFO,"add to activelist node %p", node);
+    mActivatedWindowList.remove_if([&](auto &n) { return n == node; });
+    mActivatedWindowList.push_front(node);
+
+    auto iter = mWindowSet.find(node);
+    if ( iter == mWindowSet.end()) mWindowSet.insert(node);
+
+    AtspiAccessible *app = atspi_accessible_get_application(node, NULL);
+    LOG_F(INFO, "node:%p, app:%p", node, app);
+    if (app) {
+        mActivatedApplicationList.remove_if([&](auto &n) { if(n == app) { g_object_unref(app); return true;} else return false; });
+        mActivatedApplicationList.push_front(app);
+    }
+
+    return true;
+}
+
+bool AtspiAccessibleWatcher::removeFromWindowSet(AtspiAccessible *node)
+{
+    removeFromActivatedList(node);
+    auto iter = mWindowSet.find(node);
+    if ( iter != mWindowSet.end()){
+        mWindowSet.erase(node);
+        return true;
+    }
+    return false;
+}
+
+bool AtspiAccessibleWatcher::addToWindowSet(AtspiAccessible *node)
+{
+    auto iter = mWindowSet.find(node);
+    if ( iter == mWindowSet.end()){
+        mWindowSet.insert(node);
+        return true;
+    }
+    return false;
+}
\ No newline at end of file
diff --git a/libaurum/src/Impl/Accessibility/AtspiAccessibleWindow.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleWindow.cc
new file mode 100644 (file)
index 0000000..d563df8
--- /dev/null
@@ -0,0 +1,13 @@
+#include "AtspiAccessibleWindow.h"
+
+
+AtspiAccessibleWindow::AtspiAccessibleWindow(std::shared_ptr<AccessibleApplication> app, std::shared_ptr<AccessibleNode> node)
+: AccessibleWindow(app, node)
+{
+
+}
+
+AtspiAccessibleWindow::~AtspiAccessibleWindow()
+{
+
+}
\ No newline at end of file
diff --git a/libaurum/src/Impl/Accessibility/MockAccessibleApplication.cc b/libaurum/src/Impl/Accessibility/MockAccessibleApplication.cc
new file mode 100644 (file)
index 0000000..a4326dc
--- /dev/null
@@ -0,0 +1,65 @@
+#include "MockAccessibleApplication.h"
+#include "MockAccessibleWindow.h"
+#include "MockAccessibleNode.h"
+
+#include <algorithm>
+
+#include <loguru.hpp>
+
+MockAccessibleApplication::MockAccessibleApplication(std::shared_ptr<AccessibleNode> node)
+: AccessibleApplication(node), mWindowList{}
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+}
+
+MockAccessibleApplication::~MockAccessibleApplication()
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+}
+
+std::vector<std::shared_ptr<AccessibleWindow>> MockAccessibleApplication::getWindows(void)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return mWindowList;
+}
+/*
+std::vector<std::shared_ptr<AccessibleWindow>> MockAccessibleApplication::getActiveWindows(void)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+
+    std::vector<std::shared_ptr<AccessibleWindow>> ret{};
+
+    auto children = getWindows();
+
+    children.erase(std::remove_if(children.begin(), children.end(), [](auto child){
+                        return !(child->isActive()); // && child->isShowing() && child->isVisible());
+                    }), children.end());
+
+    LOG_SCOPE_F(INFO, "getActiveWindows app(%s) for %p, size:%d", getPackageName().c_str(), getAccessibleNode()->getRawHandler(), children.size());
+
+    // std::transform(children.begin(), children.end(), std::back_inserter(ret),
+    //     [&](std::shared_ptr<AccessibleNode> child) {
+    //         return std::make_shared<MockAccessibleWindow>(this->shared_from_this(), child);
+    //     }
+    // );
+
+    return ret;
+}
+*/
+std::string MockAccessibleApplication::getPackageName(void)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return "This.Is.Mock.Application";
+}
+
+void MockAccessibleApplication::addWindow(std::shared_ptr<AccessibleWindow> window)
+{
+    mWindowList.push_back(window);
+    // auto node = getAccessibleNode();
+    // auto node2 = dynamic_cast<std::shared_ptr<MockAccessibleNode>>(node);
+    // node2->addChild(window->getNode());
+}
+void MockAccessibleApplication::clearWindows(void)
+{
+    mWindowList.clear();
+}
\ No newline at end of file
diff --git a/libaurum/src/Impl/Accessibility/MockAccessibleNode.cc b/libaurum/src/Impl/Accessibility/MockAccessibleNode.cc
new file mode 100644 (file)
index 0000000..0ce2788
--- /dev/null
@@ -0,0 +1,149 @@
+#include "MockAccessibleNode.h"
+
+#include <algorithm>
+
+MockAccessibleNode::MockAccessibleNode(std::shared_ptr<AccessibleNode> parent, std::string text, std::string pkg, std::string role, std::string res, std::string type, std::string style, Rect<int> boundingBox, int supportingIfaces,int featureProperty)
+: mParentNode(parent), mChildrenList{}, mActionSet{}
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    setProperties(text,pkg,role,res,type,style,boundingBox, supportingIfaces, featureProperty);
+}
+
+MockAccessibleNode::~MockAccessibleNode()
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+}
+
+int MockAccessibleNode::getChildCount() const
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return mChildrenList.size();
+}
+
+std::shared_ptr<AccessibleNode> MockAccessibleNode::getChildAt(int index) const
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return mChildrenList.at(index);
+}
+std::vector<std::shared_ptr<AccessibleNode>> MockAccessibleNode::getChildren() const
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return mChildrenList;
+}
+
+std::shared_ptr<AccessibleNode> MockAccessibleNode::getParent() const
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return mParentNode;
+}
+
+void* MockAccessibleNode::getRawHandler(void) const
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return (void*)0;
+}
+
+void MockAccessibleNode::setProperties(std::string text,std::string pkg,std::string role,std::string res,std::string type,std::string style,Rect<int> boundingBox,int supportingIfaces,int featureProperty)
+{
+    mText = text;
+    mPkg = pkg;
+    mRole = role;
+    mRes = res;
+    mType = type;
+    mStyle = style;
+    mBoundingBox = boundingBox;
+    mSupportingIfaces = supportingIfaces;
+    mFeatureProperty = featureProperty;
+}
+
+void MockAccessibleNode::refresh()
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+}
+
+std::vector<std::string> MockAccessibleNode::getActions() const
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    std::vector<std::string> ret{};
+    std::transform(mActionSet.begin(), mActionSet.end(), std::back_inserter(ret), [](auto action){
+        return action;
+    });
+    return ret;
+}
+
+bool MockAccessibleNode::doAction(std::string action)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    if (mActionSet.find(action) != mActionSet.end()) return true;
+    return false;
+}
+
+void MockAccessibleNode::setValue(std::string text)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    mText = text;
+}
+
+void MockAccessibleNode::setFeatureProperty(int type)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    switch(type) {
+        case 1:
+            setFeatureProperty(NodeFeatureProperties::CHECKED, true);
+            break;
+        case 2:
+            setFeatureProperty(NodeFeatureProperties::CHECKABLE, true);
+            break;
+        case 3:
+            setFeatureProperty(NodeFeatureProperties::ENABLED, true);
+            break;
+        case 4:
+            setFeatureProperty(NodeFeatureProperties::FOCUSABLE, true);
+            break;
+        case 5:
+            setFeatureProperty(NodeFeatureProperties::FOCUSED, true);
+            break;
+        case 6:
+            setFeatureProperty(NodeFeatureProperties::SELECTABLE, true);
+            break;
+        case 7:
+            setFeatureProperty(NodeFeatureProperties::SELECTED, true);
+            break;
+        case 8:
+            setFeatureProperty(NodeFeatureProperties::SHOWING, true);
+            break;
+        case 9:
+            setFeatureProperty(NodeFeatureProperties::VISIBLE, true);
+            break;
+        case 10:
+            setFeatureProperty(NodeFeatureProperties::ACTIVE, true);
+            break;
+        case 11:
+            setFeatureProperty(NodeFeatureProperties::CLICKABLE, true);
+            break;
+        case 12:
+        case 13:
+            setFeatureProperty(NodeFeatureProperties::INVALID, true);
+            break;
+    }
+}
+
+void MockAccessibleNode::addChild(std::shared_ptr<AccessibleNode> child)
+{
+    mChildrenList.push_back(child);
+}
+
+void MockAccessibleNode::clearChildren(void)
+{
+    mChildrenList.clear();
+}
+
+void MockAccessibleNode::addAction(std::string action)
+{
+    mActionSet.insert(action);
+}
+
+void MockAccessibleNode::clearActions(void)
+{
+    mActionSet.clear();
+}
\ No newline at end of file
diff --git a/libaurum/src/Impl/Accessibility/MockAccessibleWatcher.cc b/libaurum/src/Impl/Accessibility/MockAccessibleWatcher.cc
new file mode 100644 (file)
index 0000000..6c4b9e0
--- /dev/null
@@ -0,0 +1,68 @@
+#include "MockAccessibleWatcher.h"
+#include "MockAccessibleWindow.h"
+#include "MockAccessibleNode.h"
+
+#include <stdio.h>
+
+MockAccessibleWatcher::MockAccessibleWatcher()
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+
+    /*
+        Root
+            Application
+                Window
+                    Node
+                        Node
+                            Node
+                            Node
+                            Node
+                            Node
+                        Node
+                            Node
+                            Node
+                        Node
+                    Node
+                    Node
+                Window
+                    Node
+                        Node
+            Application
+                Window
+            Application
+                Window
+            Application
+                Window
+            Application
+                Window
+    */
+}
+
+MockAccessibleWatcher::~MockAccessibleWatcher()
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+}
+
+int MockAccessibleWatcher::getApplicationCount(void) const
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return -1;
+}
+
+std::shared_ptr<AccessibleApplication> MockAccessibleWatcher::getApplicationAt(int index) const
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return mApplicationList.at(index);
+}
+
+std::vector<std::shared_ptr<AccessibleApplication>> MockAccessibleWatcher::getApplications(void) const
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return mApplicationList;
+}
+
+void MockAccessibleWatcher::addApplication(std::shared_ptr<AccessibleApplication> application)
+{
+    mApplicationList.push_back(application);
+    
+}
\ No newline at end of file
diff --git a/libaurum/src/Impl/Accessibility/MockAccessibleWindow.cc b/libaurum/src/Impl/Accessibility/MockAccessibleWindow.cc
new file mode 100644 (file)
index 0000000..23ea498
--- /dev/null
@@ -0,0 +1,12 @@
+#include "MockAccessibleWindow.h"
+
+MockAccessibleWindow::MockAccessibleWindow(std::shared_ptr<AccessibleApplication> app, std::shared_ptr<AccessibleNode> node)
+: AccessibleWindow(app, node)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+}
+
+MockAccessibleWindow::~MockAccessibleWindow()
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+}
\ No newline at end of file
diff --git a/libaurum/src/Impl/Accessibility/meson.build b/libaurum/src/Impl/Accessibility/meson.build
new file mode 100644 (file)
index 0000000..5226d60
--- /dev/null
@@ -0,0 +1,13 @@
+    libaurum_src += [
+        files('AtspiAccessibleApplication.cc'),
+        files('AtspiAccessibleWindow.cc'),
+        files('AtspiAccessibleNode.cc'),
+        files('AtspiAccessibleWatcher.cc'),
+    ]
+
+    libaurum_src += [
+        files('MockAccessibleApplication.cc'),
+        files('MockAccessibleWindow.cc'),
+        files('MockAccessibleNode.cc'),
+        files('MockAccessibleWatcher.cc'),
+    ]
\ No newline at end of file
diff --git a/libaurum/src/Impl/MockDeviceImpl.cc b/libaurum/src/Impl/MockDeviceImpl.cc
new file mode 100644 (file)
index 0000000..cf56af2
--- /dev/null
@@ -0,0 +1,182 @@
+#include "MockDeviceImpl.h"
+#include <loguru.hpp>
+
+#include <functional>
+#include <tuple>
+#include <iostream>
+#include <memory>
+
+#include <stdlib.h>
+#include <time.h>
+
+#include <stdio.h>
+
+MockDeviceImpl::MockDeviceImpl()
+{
+    printf("mockdevice ctor\n");printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+}
+
+MockDeviceImpl::~MockDeviceImpl()
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+}
+
+bool MockDeviceImpl::click(const int x, const int y)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return false;
+}
+
+bool MockDeviceImpl::click(const int x, const int y, const unsigned int intv)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return false;
+}
+
+bool MockDeviceImpl::drag(const int sx, const int sy, const int ex, const int ey,
+            const int steps, const int durationMs)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return false;
+}
+
+int MockDeviceImpl::touchDown(const int x, const int y)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return -1;
+}
+
+bool MockDeviceImpl::touchMove(const int x, const int y, const int seq)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return false;
+}
+
+bool MockDeviceImpl::touchUp(const int x, const int y, const int seq)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return false;
+
+}
+
+bool MockDeviceImpl::wheelUp(int amount, const int durationMs)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return false;
+
+}
+
+bool MockDeviceImpl::wheelDown(int amount, const int durationMs)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return false;
+
+}
+
+bool MockDeviceImpl::pressBack(KeyRequestType type)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return false;
+
+}
+
+bool MockDeviceImpl::pressHome(KeyRequestType type)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return false;
+
+}
+
+bool MockDeviceImpl::pressMenu(KeyRequestType type)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return false;
+
+}
+
+bool MockDeviceImpl::pressVolUp(KeyRequestType type)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return false;
+
+}
+
+bool MockDeviceImpl::pressVolDown(KeyRequestType type)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return false;
+
+}
+
+bool MockDeviceImpl::pressPower(KeyRequestType type)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return false;
+
+}
+
+bool MockDeviceImpl::pressKeyCode(std::string keycode, KeyRequestType type)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return false;
+
+}
+
+bool MockDeviceImpl::takeScreenshot(std::string path, float scale, int quality)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return false;
+
+}
+
+long long MockDeviceImpl::getSystemTime(TimeRequestType type)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return -1;
+}
+
+bool MockDeviceImpl::strokeKeyCode(std::string keycode, unsigned int intv)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return false;
+
+}
+
+bool MockDeviceImpl::pressKeyCode(std::string keycode)
+{
+
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return false;
+
+}
+
+bool MockDeviceImpl::releaseKeyCode(std::string keycode)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return false;
+
+}
+
+int MockDeviceImpl::grabTouchSeqNumber()
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return 0;
+}
+
+bool MockDeviceImpl::releaseTouchSeqNumber(int seq)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return false;
+
+}
+
+void MockDeviceImpl::startTimer(void)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+}
+
+int MockDeviceImpl::stopTimer(void)
+{
+    printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__);
+    return 0;
+}
\ No newline at end of file
similarity index 79%
rename from libaurum/src/DeviceImpl/TizenImpl.cc
rename to libaurum/src/Impl/TizenDeviceImpl.cc
index 7e469d7..a6d9006 100644 (file)
@@ -1,4 +1,4 @@
-#include "DeviceImpl/TizenImpl.h"
+#include "TizenDeviceImpl.h"
 #include <loguru.hpp>
 
 #include <functional>
 #include <tbm_surface.h>
 #include <system_info.h>
 
-TizenImpl::TizenImpl()
+TizenDeviceImpl::TizenDeviceImpl()
 : mFakeTouchHandle{0}, mFakeKeyboardHandle{0}, mFakeWheelHandle{0}, isTimerStarted{false}, mTouchSeq{}
 {
     LOG_SCOPE_F(INFO, "device implementation init");
     ecore_main_loop_thread_safe_call_sync([](void *data)->void*{
-        TizenImpl *obj = static_cast<TizenImpl*>(data);
+        TizenDeviceImpl *obj = static_cast<TizenDeviceImpl*>(data);
         obj->mFakeTouchHandle = efl_util_input_initialize_generator(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN);
         obj->mFakeKeyboardHandle =
             efl_util_input_initialize_generator(EFL_UTIL_INPUT_DEVTYPE_KEYBOARD);
@@ -28,10 +28,10 @@ TizenImpl::TizenImpl()
     }, this);
 }
 
-TizenImpl::~TizenImpl()
+TizenDeviceImpl::~TizenDeviceImpl()
 {
     ecore_main_loop_thread_safe_call_sync([](void *data)->void*{
-        TizenImpl *obj = static_cast<TizenImpl*>(data);
+        TizenDeviceImpl *obj = static_cast<TizenDeviceImpl*>(data);
         efl_util_input_deinitialize_generator(obj->mFakeTouchHandle);
         efl_util_input_deinitialize_generator(obj->mFakeKeyboardHandle);
         efl_util_input_deinitialize_generator(obj->mFakeWheelHandle);
@@ -39,12 +39,12 @@ TizenImpl::~TizenImpl()
     }, this);
 }
 
-bool TizenImpl::click(const int x, const int y)
+bool TizenDeviceImpl::click(const int x, const int y)
 {
     return click(x, y, INTV_CLICK);
 }
 
-bool TizenImpl::click(const int x, const int y, const unsigned int intv)
+bool TizenDeviceImpl::click(const int x, const int y, const unsigned int intv)
 {
     int seq = touchDown(x, y);
     if (seq < 0) return false;
@@ -55,16 +55,16 @@ bool TizenImpl::click(const int x, const int y, const unsigned int intv)
 }
 
 
-int TizenImpl::touchDown(const int x, const int y)
+int TizenDeviceImpl::touchDown(const int x, const int y)
 {
     int seq = grabTouchSeqNumber();
     LOG_F(INFO, "touch down %d %d , seq:%d", x, y, seq);
     if (seq >= 0) {
         auto args = std::make_tuple(this, x, y, seq);
         long result = (long)ecore_main_loop_thread_safe_call_sync([](void *data)->void*{
-            TizenImpl *obj;
+            TizenDeviceImpl *obj;
             int x, y, seq;
-            std::tie(obj, x, y, seq) = *static_cast<std::tuple<TizenImpl*, int, int, int>*>(data);
+            std::tie(obj, x, y, seq) = *static_cast<std::tuple<TizenDeviceImpl*, int, int, int>*>(data);
             return (void*)efl_util_input_generate_touch(obj->mFakeTouchHandle, seq, EFL_UTIL_INPUT_TOUCH_BEGIN,
                                     x, y);
 
@@ -78,15 +78,15 @@ int TizenImpl::touchDown(const int x, const int y)
     return seq;
 }
 
-bool TizenImpl::touchMove(const int x, const int y, const int seq)
+bool TizenDeviceImpl::touchMove(const int x, const int y, const int seq)
 {
     LOG_F(INFO, "touch move %d %d, seq:%d", x, y, seq);
     if (seq >= 0) {
         auto args = std::make_tuple(this, x, y, seq);
         long result = (long)ecore_main_loop_thread_safe_call_sync([](void *data)->void*{
-            TizenImpl *obj;
+            TizenDeviceImpl *obj;
             int x, y, seq;
-            std::tie(obj, x, y, seq) = *static_cast<std::tuple<TizenImpl*, int, int, int>*>(data);
+            std::tie(obj, x, y, seq) = *static_cast<std::tuple<TizenDeviceImpl*, int, int, int>*>(data);
 
             return (void*)efl_util_input_generate_touch(obj->mFakeTouchHandle, seq, EFL_UTIL_INPUT_TOUCH_UPDATE,
                                     x, y);
@@ -97,15 +97,15 @@ bool TizenImpl::touchMove(const int x, const int y, const int seq)
     return false;
 }
 
-bool TizenImpl::touchUp(const int x, const int y, const int seq)
+bool TizenDeviceImpl::touchUp(const int x, const int y, const int seq)
 {
     LOG_F(INFO, "touch up %d %d, seq:%d", x, y, seq);
     if (seq >= 0) {
         auto args = std::make_tuple(this, x, y, seq);
         long result = (long)ecore_main_loop_thread_safe_call_sync([](void *data)->void*{
-            TizenImpl *obj;
+            TizenDeviceImpl *obj;
             int x, y, seq;
-            std::tie(obj, x, y, seq) = *static_cast<std::tuple<TizenImpl*, int, int, int>*>(data);
+            std::tie(obj, x, y, seq) = *static_cast<std::tuple<TizenDeviceImpl*, int, int, int>*>(data);
             return (void*)efl_util_input_generate_touch(obj->mFakeTouchHandle, seq, EFL_UTIL_INPUT_TOUCH_END,
                                     x, y);
         }, (void*)(&args));
@@ -114,15 +114,15 @@ bool TizenImpl::touchUp(const int x, const int y, const int seq)
     return false;
 }
 
-bool TizenImpl::wheelUp(int amount, const int durationMs)
+bool TizenDeviceImpl::wheelUp(int amount, const int durationMs)
 {
     LOG_F(INFO, "wheel up %d for %d", amount, durationMs);
     auto args = std::make_tuple(this);
     long result = -1;
     for (int i = 0; i < amount; i++){
         result = (long)ecore_main_loop_thread_safe_call_sync([](void *data)->void*{
-                TizenImpl *obj;
-                std::tie(obj) = *static_cast<std::tuple<TizenImpl*>*>(data);
+                TizenDeviceImpl *obj;
+                std::tie(obj) = *static_cast<std::tuple<TizenDeviceImpl*>*>(data);
             return (void*)efl_util_input_generate_wheel(obj->mFakeWheelHandle, EFL_UTIL_INPUT_POINTER_WHEEL_HORZ, 1);
         }, (void*)(&args));
         usleep(durationMs*MSEC_PER_SEC/amount);
@@ -131,15 +131,15 @@ bool TizenImpl::wheelUp(int amount, const int durationMs)
     return result == EFL_UTIL_ERROR_NONE;
 }
 
-bool TizenImpl::wheelDown(int amount, const int durationMs)
+bool TizenDeviceImpl::wheelDown(int amount, const int durationMs)
 {
     LOG_F(INFO, "wheel down %d for %d", amount, durationMs);
     auto args = std::make_tuple(this);
     long result = -1;
     for (int i = 0; i < amount; i++){
         result = (long)ecore_main_loop_thread_safe_call_sync([](void *data)->void*{
-                TizenImpl *obj;
-                std::tie(obj) = *static_cast<std::tuple<TizenImpl*>*>(data);
+                TizenDeviceImpl *obj;
+                std::tie(obj) = *static_cast<std::tuple<TizenDeviceImpl*>*>(data);
                 return (void*)efl_util_input_generate_wheel(obj->mFakeWheelHandle, EFL_UTIL_INPUT_POINTER_WHEEL_HORZ, -1);
             return NULL;
         }, (void*)(&args));
@@ -148,13 +148,13 @@ bool TizenImpl::wheelDown(int amount, const int durationMs)
 
     return result == EFL_UTIL_ERROR_NONE;
 }
-void TizenImpl::startTimer(void)
+void TizenDeviceImpl::startTimer(void)
 {
     isTimerStarted = true;
     clock_gettime(CLOCK_MONOTONIC, &tStart);
 }
 
-int TizenImpl::stopTimer(void)
+int TizenDeviceImpl::stopTimer(void)
 {
     struct timespec tEnd;
     if (!isTimerStarted) return 0;
@@ -163,7 +163,7 @@ int TizenImpl::stopTimer(void)
     return ((tEnd.tv_sec + tEnd.tv_nsec/1000000000.0) - (tStart.tv_sec + tStart.tv_nsec/1000000000.0)) * 1000000;
 }
 
-bool TizenImpl::drag(const int sx, const int sy, const int ex, const int ey,
+bool TizenDeviceImpl::drag(const int sx, const int sy, const int ex, const int ey,
                          const int steps, const int durationMs)
 {
     int i, j;
@@ -202,37 +202,37 @@ bool TizenImpl::drag(const int sx, const int sy, const int ex, const int ey,
     return true;
 }
 
-bool TizenImpl::pressBack(KeyRequestType type)
+bool TizenDeviceImpl::pressBack(KeyRequestType type)
 {
     return pressKeyCode("XF86Back", type);
 }
 
-bool TizenImpl::pressHome(KeyRequestType type)
+bool TizenDeviceImpl::pressHome(KeyRequestType type)
 {
     return pressKeyCode("XF86Home", type);
 }
 
-bool TizenImpl::pressMenu(KeyRequestType type)
+bool TizenDeviceImpl::pressMenu(KeyRequestType type)
 {
     return pressKeyCode("XF86Menu", type);
 }
 
-bool TizenImpl::pressVolUp(KeyRequestType type)
+bool TizenDeviceImpl::pressVolUp(KeyRequestType type)
 {
     return pressKeyCode("XF86AudioRaiseVolume", type);
 }
 
-bool TizenImpl::pressVolDown(KeyRequestType type)
+bool TizenDeviceImpl::pressVolDown(KeyRequestType type)
 {
     return pressKeyCode("XF86AudioLowerVolume", type);
 }
 
-bool TizenImpl::pressPower(KeyRequestType type)
+bool TizenDeviceImpl::pressPower(KeyRequestType type)
 {
     return pressKeyCode("XF86PowerOff", type);
 }
 
-bool TizenImpl::pressKeyCode(std::string keycode, KeyRequestType type)
+bool TizenDeviceImpl::pressKeyCode(std::string keycode, KeyRequestType type)
 {
     if (type == KeyRequestType::STROKE)
         return strokeKeyCode(keycode, INTV_SHORTSTROKE);
@@ -245,7 +245,7 @@ bool TizenImpl::pressKeyCode(std::string keycode, KeyRequestType type)
     return false;
 }
 
-bool TizenImpl::strokeKeyCode(std::string keycode, unsigned int intv)
+bool TizenDeviceImpl::strokeKeyCode(std::string keycode, unsigned int intv)
 {
     pressKeyCode(keycode);
     usleep(intv * 1000);
@@ -253,33 +253,33 @@ bool TizenImpl::strokeKeyCode(std::string keycode, unsigned int intv)
     return true;
 }
 
-bool TizenImpl::pressKeyCode(std::string keycode)
+bool TizenDeviceImpl::pressKeyCode(std::string keycode)
 {
     auto args = std::make_tuple(this, keycode);
     long result = (long)ecore_main_loop_thread_safe_call_sync([](void *data)->void*{
-        TizenImpl *obj;
+        TizenDeviceImpl *obj;
         std::string keycode;
-        std::tie(obj, keycode) = *static_cast<std::tuple<TizenImpl*, std::string>*>(data);
+        std::tie(obj, keycode) = *static_cast<std::tuple<TizenDeviceImpl*, std::string>*>(data);
         return (void*)efl_util_input_generate_key(obj->mFakeKeyboardHandle, keycode.c_str(), 1);
     }, (void*)(&args));
     ecore_main_loop_thread_safe_call_sync([](void *data)->void*{return NULL;}, NULL);
     return result == EFL_UTIL_ERROR_NONE;
 }
 
-bool TizenImpl::releaseKeyCode(std::string keycode)
+bool TizenDeviceImpl::releaseKeyCode(std::string keycode)
 {
     auto args = std::make_tuple(this, keycode);
     long result = (long)ecore_main_loop_thread_safe_call_sync([](void *data)->void*{
-        TizenImpl *obj;
+        TizenDeviceImpl *obj;
         std::string keycode;
-        std::tie(obj, keycode) = *static_cast<std::tuple<TizenImpl*, std::string>*>(data);
+        std::tie(obj, keycode) = *static_cast<std::tuple<TizenDeviceImpl*, std::string>*>(data);
         return (void*)efl_util_input_generate_key(obj->mFakeKeyboardHandle, keycode.c_str(), 0);
     }, (void*)(&args));
     ecore_main_loop_thread_safe_call_sync([](void *data)->void*{return NULL;}, NULL);
     return result == EFL_UTIL_ERROR_NONE;
 }
 
-bool TizenImpl::takeScreenshot(std::string path, float scale, int quality)
+bool TizenDeviceImpl::takeScreenshot(std::string path, float scale, int quality)
 {
     efl_util_screenshot_h screenshot = NULL;
     tbm_surface_h tbm_surface = NULL;
@@ -339,7 +339,7 @@ public:
     }
 };
 
-long long TizenImpl::getSystemTime(TimeRequestType type)
+long long TizenDeviceImpl::getSystemTime(TimeRequestType type)
 {
     std::unique_ptr<Clock> clock;
     if (type == TimeRequestType::MONOTONIC)
@@ -351,7 +351,7 @@ long long TizenImpl::getSystemTime(TimeRequestType type)
 
 }
 
-int TizenImpl::grabTouchSeqNumber()
+int TizenDeviceImpl::grabTouchSeqNumber()
 {
     for (int i = 0 ; i < MAX_FINGER_NUMBER; i++) {
         if (mTouchSeq.count(i) == 0) {
@@ -362,7 +362,7 @@ int TizenImpl::grabTouchSeqNumber()
     return -1;
 }
 
-bool TizenImpl::releaseTouchSeqNumber(int seq)
+bool TizenDeviceImpl::releaseTouchSeqNumber(int seq)
 {
     auto k = mTouchSeq.find(seq);
     if (k != mTouchSeq.end()) {
diff --git a/libaurum/src/Impl/meson.build b/libaurum/src/Impl/meson.build
new file mode 100644 (file)
index 0000000..04bdacc
--- /dev/null
@@ -0,0 +1,11 @@
+if get_option('tizen') == true
+    libaurum_src += [
+        files('TizenDeviceImpl.cc'),
+    ]
+endif
+
+libaurum_src += [
+    files('MockDeviceImpl.cc'),
+]
+
+subdir('Accessibility')
\ No newline at end of file
index 3bac438..5edc6f2 100644 (file)
@@ -27,8 +27,6 @@ void PartialMatch::debugPrint()
         LOG_F(INFO, "selector->pkg :%s", mSelector->mRes->c_str());
     if (mSelector->mText)
         LOG_F(INFO, "selector->pkg :%s", mSelector->mText->c_str());
-    if (mSelector->mDesc)
-        LOG_F(INFO, "selector->pkg :%s", mSelector->mDesc->c_str());
     if (mSelector->mType)
         LOG_F(INFO, "selector->pkg :%s", mSelector->mType->c_str());
     if (mSelector->mStyle)
@@ -36,12 +34,11 @@ void PartialMatch::debugPrint()
 }
 
 bool PartialMatch::checkCriteria(const std::shared_ptr<UiSelector> selector,
-                                 const AccessibleNode *node)
+                                 const std::shared_ptr<AccessibleNode> node)
 {
     if(checkCriteria(selector->mPkg.get(), node->getPkg())) return false;
     if(checkCriteria(selector->mRes.get(), node->getRes())) return false;
     if(checkCriteria(selector->mText.get(), node->getText())) return false;
-    if(checkCriteria(selector->mDesc.get(), node->getDesc())) return false;
     if(checkCriteria(selector->mType.get(), node->getType())) return false;
     if(checkCriteria(selector->mStyle.get(), node->getStyle())) return false;
     if(checkCriteria(selector->mStyle.get(), node->getStyle())) return false;
@@ -69,22 +66,29 @@ PartialMatch::PartialMatch(const std::shared_ptr<UiSelector> selector, const int
 {
 }
 
-std::shared_ptr<PartialMatch> PartialMatch::accept(const AccessibleNode *node,
+std::shared_ptr<PartialMatch> PartialMatch::accept(const std::shared_ptr<AccessibleNode> node,
                                                    const std::shared_ptr<UiSelector> selector,
                                                    int index, int depth)
 {
     return PartialMatch::accept(node, selector, index, depth, depth);
 }
 
-std::shared_ptr<PartialMatch> PartialMatch::accept(const AccessibleNode *node,
+std::shared_ptr<PartialMatch> PartialMatch::accept(const std::shared_ptr<AccessibleNode> node,
                                                    const std::shared_ptr<UiSelector> selector,
                                                    int index, int absoluteDepth,
                                                    int relativeDepth)
 {
+    LOG_SCOPE_F(INFO, "accept checking i:%d a:%d r:%d / %d < %d < %d", index, absoluteDepth, relativeDepth, selector->mMinDepth?*(selector->mMinDepth):-1, relativeDepth, selector->mMaxDepth?*(selector->mMaxDepth):9999999);
     PartialMatch *match = nullptr;
 
+    if ((selector->mMinDepth && (relativeDepth < *(selector->mMinDepth))) ||
+        (selector->mMaxDepth && (relativeDepth > *(selector->mMaxDepth)))) {
+        LOG_F(INFO, "depth limit overflow %d < %d < %d", selector->mMinDepth?*(selector->mMinDepth):-1, relativeDepth, selector->mMaxDepth?*(selector->mMaxDepth):9999999);
+        return std::shared_ptr<PartialMatch>(nullptr);
+    }
+
     if (PartialMatch::checkCriteria(selector, node)) {
-        LOG_SCOPE_F(INFO, "New Match found %p %d", selector, absoluteDepth);
+        LOG_F(INFO, "New Match found %p %d", selector, absoluteDepth);
         match = new PartialMatch(selector, absoluteDepth);
     }
 
@@ -92,10 +96,10 @@ std::shared_ptr<PartialMatch> PartialMatch::accept(const AccessibleNode *node,
 }
 
 void PartialMatch::update(
-    const AccessibleNode *node, int index, int depth,
+    const std::shared_ptr<AccessibleNode> node, int index, int depth,
     std::list<std::shared_ptr<PartialMatch>> &partialMatches)
 {
-    for (auto childSelector : mSelector->mChild) {
+    for (auto &childSelector : mSelector->mChild) {
         auto match = PartialMatch::accept(node, childSelector, index, depth,
                                           depth - mDepth);
         if (match) {
@@ -108,13 +112,13 @@ void PartialMatch::update(
 bool PartialMatch::finalizeMatch()
 {
     std::set<std::shared_ptr<UiSelector>> matches;
-    for (auto match : mPartialMatches) {
+    for (auto &match : mPartialMatches) {
         if (match->finalizeMatch()) {
             matches.insert(match->mSelector);
         }
     }
 
-    for (auto sel : mSelector->mChild) {
+    for (auto &sel : mSelector->mChild) {
         if (!matches.count(sel)) return false;
     }
     return true;
index a3c55b6..f694f28 100644 (file)
@@ -1,18 +1,24 @@
 #include "UiDevice.h"
 #include "AccessibleWatcher.h"
 #include "Comparer.h"
-#include "DeviceImpl/TizenImpl.h"
+
+#ifdef TIZEN
+#include "TizenDeviceImpl.h"
+#endif
+#include "MockDeviceImpl.h"
 
 #include <unistd.h>
 #include <utility>
 #include <vector>
 #include <chrono>
 #include <thread>
+#include <algorithm>
+#include <iostream>
 
-UiDevice::UiDevice() : UiDevice(DeviceType::DEFAULT, nullptr) {}
+UiDevice::UiDevice() : UiDevice(nullptr) {}
 
-UiDevice::UiDevice(DeviceType type, IDevice *impl)
-    : mType(type), mDeviceImpl(impl), mWaiter(new Waiter{this})
+UiDevice::UiDevice(IDevice *impl)
+    : mDeviceImpl(impl), mWaiter(new Waiter{this})
 {
 }
 
@@ -22,55 +28,77 @@ UiDevice::~UiDevice()
     delete mWaiter;
 }
 
-UiDevice *UiDevice::getInstance(DeviceType type)
+std::shared_ptr<UiDevice> UiDevice::getInstance(IDevice *deviceImpl)
 {
-    static UiDevice *device = nullptr;
+    static std::shared_ptr<UiDevice> device{nullptr};
+
+    if (deviceImpl) {
+        device.reset(new UiDevice(deviceImpl));
+    } else {
+        if (device) return device;
+        else {
 #ifdef TIZEN
-    if (!device) device = new UiDevice(type, new TizenImpl());
+            device.reset(new UiDevice(new TizenDeviceImpl()));
+#else
+            device.reset(new UiDevice(new MockDeviceImpl()));
 #endif
+        }
+    }
+
     return device;
 }
 
-std::vector<std::unique_ptr<AccessibleNode>> UiDevice::getWindowRoot() const
+std::vector<std::shared_ptr<AccessibleNode>> UiDevice::getWindowRoot() const
 {
-    return AccessibleWatcher::getInstance()->getTopNode();
+    std::vector<std::shared_ptr<AccessibleNode>> ret{};
+
+    auto apps = AccessibleWatcher::getInstance()->getActiveApplications();
+    for (auto &app : apps){
+        auto activeWindows = app->getActiveWindows();
+        std::transform(activeWindows.begin(), activeWindows.end(), std::back_inserter(ret),
+            [&](std::shared_ptr<AccessibleWindow> window){
+                return window->getNode();
+            }
+        );
+    }
+    return ret;
 }
 
 bool UiDevice::hasObject(const std::shared_ptr<UiSelector> selector) const
 {
-    auto root = getWindowRoot();
-    for (auto it = root.begin(); it != root.end(); ++it) {
-        std::unique_ptr<AccessibleNode> node =
-            Comparer::findObject(this, selector, (*it).get());
-        if (node != nullptr) return true;
+    auto rootNodes = getWindowRoot();
+    for (const auto &node : rootNodes) {
+        const std::shared_ptr<AccessibleNode> foundNode =
+            Comparer::findObject(getInstance(), selector, node);
+        if (foundNode) return true;
     }
 
     return false;
 }
 
-std::unique_ptr<UiObject> UiDevice::findObject(const std::shared_ptr<UiSelector> selector) const
+std::shared_ptr<UiObject> UiDevice::findObject(const std::shared_ptr<UiSelector> selector) const
 {
-    auto root = getWindowRoot();
-    for (auto it = root.begin(); it != root.end(); ++it) {
-        std::unique_ptr<AccessibleNode> node =
-            Comparer::findObject(this, selector, (*it).get());
-        if (node)
-            return std::make_unique<UiObject>(this, selector, std::move(node));
+    auto rootNodes = getWindowRoot();
+    for (const auto &node : rootNodes) {
+        const std::shared_ptr<AccessibleNode> foundNode =
+            Comparer::findObject(getInstance(), selector, node);
+        if (foundNode)
+            return std::make_shared<UiObject>(getInstance(), selector, foundNode);
     }
-    return std::unique_ptr<UiObject>{nullptr};
+    return std::shared_ptr<UiObject>{nullptr};
 }
 
-std::vector<std::unique_ptr<UiObject>> UiDevice::findObjects(
+
+std::vector<std::shared_ptr<UiObject>> UiDevice::findObjects(
     const std::shared_ptr<UiSelector> selector) const
 {
-    std::vector<std::unique_ptr<UiObject>> ret{};
-    auto root = getWindowRoot();
-    for (auto it = root.begin(); it != root.end(); ++it) {
-        std::vector<std::unique_ptr<AccessibleNode>>          nodes =
-            Comparer::findObjects(this, selector, (*it).get());
-
+    std::vector<std::shared_ptr<UiObject>> ret{};
+    auto rootNodes = getWindowRoot();
+    for (const auto &window : rootNodes) {
+        std::vector<std::shared_ptr<AccessibleNode>> nodes =
+            Comparer::findObjects(getInstance(), selector, window);
         for (auto &node : nodes)
-            ret.push_back(std::make_unique<UiObject>(this, selector, std::move(node)));
+            ret.push_back(std::make_shared<UiObject>(getInstance(), selector, node));
     }
     return ret;
 }
@@ -80,8 +108,8 @@ bool UiDevice::waitFor(
     return mWaiter->waitFor(condition);
 }
 
-std::unique_ptr<UiObject> UiDevice::waitFor(
-    const std::function<std::unique_ptr<UiObject>(const ISearchable *)>
+std::shared_ptr<UiObject> UiDevice::waitFor(
+    const std::function<std::shared_ptr<UiObject>(const ISearchable *)>
         condition) const
 {
     return mWaiter->waitFor(condition);
index 12502cb..2a4cb76 100644 (file)
@@ -7,6 +7,8 @@
 
 #include <loguru.hpp>
 
+#include <chrono>
+#include <thread>
 UiObject::UiObject() : UiObject(nullptr, nullptr, nullptr) {}
 
 UiObject::~UiObject()
@@ -14,17 +16,17 @@ UiObject::~UiObject()
     if (mWaiter) delete mWaiter;
 }
 
-UiObject::UiObject(const UiDevice *device, const std::shared_ptr<UiSelector> selector,
+UiObject::UiObject(const std::shared_ptr<UiDevice> device, const std::shared_ptr<UiSelector> selector,
                    const AccessibleNode *node)
     : mDevice(device),
       mSelector(selector),
-      mNode(std::unique_ptr<AccessibleNode>(const_cast<AccessibleNode*>(node))),
+      mNode(std::shared_ptr<AccessibleNode>(const_cast<AccessibleNode*>(node))),
       mWaiter(new Waiter{this, this})
 {
 }
 
-UiObject::UiObject(const UiDevice *device, const std::shared_ptr<UiSelector> selector,
-                   std::unique_ptr<AccessibleNode> node)
+UiObject::UiObject(const std::shared_ptr<UiDevice> device, const std::shared_ptr<UiSelector> selector,
+                   std::shared_ptr<AccessibleNode> node)
     : mDevice(device),
       mSelector(selector),
       mNode(std::move(node)),
@@ -61,7 +63,7 @@ std::shared_ptr<UiSelector> UiObject::getSelector()
 
 bool UiObject::hasObject(const std::shared_ptr<UiSelector> selector) const
 {
-    std::unique_ptr<AccessibleNode> node =
+    std::shared_ptr<AccessibleNode> node =
         Comparer::findObject(mDevice, selector, getAccessibleNode());
     if (node != nullptr) {
         // todo : what is this node.recycle()
@@ -70,20 +72,31 @@ bool UiObject::hasObject(const std::shared_ptr<UiSelector> selector) const
     return false;
 }
 
-std::unique_ptr<UiObject> UiObject::findObject(const std::shared_ptr<UiSelector> selector) const
+std::shared_ptr<UiObject> UiObject::findObject(const std::shared_ptr<UiSelector> selector) const
 {
-    std::unique_ptr<AccessibleNode> node =
+    std::shared_ptr<AccessibleNode> node =
         Comparer::findObject(mDevice, selector, getAccessibleNode());
     if (node)
-        return std::make_unique<UiObject>(mDevice, selector, std::move(node));
+        return std::make_shared<UiObject>(mDevice, selector, std::move(node));
     else
-        return std::unique_ptr<UiObject>{nullptr};
+        return std::shared_ptr<UiObject>{nullptr};
 }
 
-std::vector<std::unique_ptr<UiObject>> UiObject::findObjects(
+std::vector<std::shared_ptr<UiObject>> UiObject::findObjects(
     const std::shared_ptr<UiSelector> selector) const
 {
-    return std::vector<std::unique_ptr<UiObject>>{};
+    LOG_SCOPE_F(INFO, "findObjects");
+    std::vector<std::shared_ptr<UiObject>> result{};
+    auto nodes = Comparer::findObjects(mDevice, selector, getAccessibleNode());
+    LOG_SCOPE_F(INFO, "size : %d", nodes.size());
+    for ( auto& node : nodes) {
+        if (!node) {
+            LOG_F(INFO, "skipped(node == nullptr)");
+            continue;
+        }
+        result.push_back(std::make_shared<UiObject>(mDevice, selector, std::move(node)));
+    }
+    return result;
 }
 
 bool UiObject::waitFor(
@@ -92,8 +105,8 @@ bool UiObject::waitFor(
     return mWaiter->waitFor(condition);
 }
 
-std::unique_ptr<UiObject> UiObject::waitFor(
-    const std::function<std::unique_ptr<UiObject>(const ISearchable *)>
+std::shared_ptr<UiObject> UiObject::waitFor(
+    const std::function<std::shared_ptr<UiObject>(const ISearchable *)>
         condition) const
 {
     return mWaiter->waitFor(condition);
@@ -102,13 +115,12 @@ std::unique_ptr<UiObject> UiObject::waitFor(
 bool UiObject::waitFor(
     const std::function<bool(const UiObject *)> condition) const
 {
-    LOG_F(INFO, "asdf");
     return mWaiter->waitFor(condition);
 }
 
 UiObject *UiObject::getParent() const
 {
-    std::unique_ptr<AccessibleNode> node = getAccessibleNode()->getParent();
+    std::shared_ptr<AccessibleNode> node = getAccessibleNode()->getParent();
     if (!node) return nullptr;
     return new UiObject(mDevice, mSelector, std::move(node));
 }
@@ -118,14 +130,12 @@ int UiObject::getChildCount() const
     return getAccessibleNode()->getChildCount();
 }
 
-std::vector<std::unique_ptr<UiObject>> UiObject::getChildren() const
-{
-    return findObjects(Sel::depth(1));
-}
-
-std::string UiObject::getContentDescription() const
+std::vector<std::shared_ptr<UiObject>> UiObject::getChildren() const
 {
-    return getAccessibleNode()->getDesc();
+    auto sel = std::make_shared<UiSelector>();
+    sel->depth(1);
+    sel->isShowing(true);
+    return this->findObjects(sel);
 }
 
 std::string UiObject::getApplicationPackage() const
@@ -138,11 +148,26 @@ std::string UiObject::getResourceName() const
     return getAccessibleNode()->getRes();
 }
 
+std::string UiObject::getElementType() const
+{
+    return getAccessibleNode()->getType();
+}
+
+std::string UiObject::getElementStyle() const
+{
+    return getAccessibleNode()->getStyle();
+}
+
 std::string UiObject::getText() const
 {
     return getAccessibleNode()->getText();
 }
 
+std::string UiObject::getRole() const
+{
+    return getAccessibleNode()->getRole();
+}
+
 void UiObject::setText(std::string text)
 {
     getAccessibleNode()->setValue(text);
@@ -229,9 +254,8 @@ void UiObject::click() const
     LOG_SCOPE_F(INFO, "click on obj %p", this);
     mNode->refresh();
     const Rect<int> rect = mNode->getBoundingBox();
-    std::cout << rect.mTopLeft.x << ", " << rect.mTopLeft.y << std::endl;
     const Point2D<int> midPoint = rect.midPoint();
-    const_cast<UiDevice *>(mDevice)->click(midPoint.x, midPoint.y);
+    mDevice->click(midPoint.x, midPoint.y);
 }
 
 void UiObject::longClick(const unsigned int intv) const
@@ -239,9 +263,8 @@ void UiObject::longClick(const unsigned int intv) const
     LOG_SCOPE_F(INFO, "click on obj %p", this);
     mNode->refresh();
     const Rect<int> rect = mNode->getBoundingBox();
-    std::cout << rect.mTopLeft.x << ", " << rect.mTopLeft.y << std::endl;
     const Point2D<int> midPoint = rect.midPoint();
-    const_cast<UiDevice *>(mDevice)->click(midPoint.x, midPoint.y, intv);
+    mDevice->click(midPoint.x, midPoint.y, intv);
 }
 
 bool UiObject::DoAtspiActivate() const
@@ -250,13 +273,11 @@ bool UiObject::DoAtspiActivate() const
 }
 
 
-const AccessibleNode *UiObject::getAccessibleNode() const
+std::shared_ptr<AccessibleNode> UiObject::getAccessibleNode() const
 {
     if (mNode == nullptr) throw;
-
     // TODO : wait for animation and refresh current node
     // mDevice->waitForIdle();
-    // mNode->refresh();
-
-    return mNode.get();
+    mNode->refresh();
+    return mNode;
 }
\ No newline at end of file
diff --git a/libaurum/src/UiScrollable.cc b/libaurum/src/UiScrollable.cc
new file mode 100644 (file)
index 0000000..a051210
--- /dev/null
@@ -0,0 +1,62 @@
+#include "UiScrollable.h"
+
+UiScrollable::UiScrollable(std::shared_ptr<UiSelector> selector)
+: mSelector{selector}, mMaxSearchSwipe{100}, mScrollStep{50}
+{
+}
+
+UiScrollable::UiScrollable()
+: mSelector{nullptr}, mMaxSearchSwipe{1}, mScrollStep{1}
+{
+    // todo : find the top most scrollable object
+}
+
+bool UiScrollable::scrollToObject(UiObject *obj)
+{
+    auto sel = obj->getSelector();
+
+    if (exists(obj)) return true;
+
+    for (int i = 0 ; i < mMaxSearchSwipe ; ++i) {
+        bool scrolled = scrollForward();
+        if (exists(obj)) return true;
+        if (!scrolled) return false;
+    }
+}
+
+
+bool UiScrollable::exists(UiObject *obj)
+{
+    return (obj->isShowing() && obj->isVisible());
+}
+
+bool UiScrollable::scrollForward()
+{
+    return scrollForward(mScrollStep);
+}
+
+bool UiScrollable::scrollForward(int steps)
+{
+
+/*
+    화면 크기 확인 
+    scroll to 
+
+*/
+    return true;
+
+}
+
+bool UiScrollable::scrollBackward()
+{
+return true;
+}
+bool UiScrollable::scrollBackward(int steps)
+{
+return true;
+}
+
+bool UiScrollable::scrollToBegin()
+{
+return true;
+}
\ No newline at end of file
index 1ee665c..886c729 100644 (file)
@@ -24,12 +24,6 @@ UiSelector *UiSelector::id(std::string text)
     return this;
 }
 
-UiSelector *UiSelector::desc(std::string text)
-{
-    this->mDesc = std::make_unique<std::string>(text);
-    return this;
-}
-
 UiSelector *UiSelector::text(std::string text)
 {
     this->mText = std::make_unique<std::string>(text);
index bd9385f..9ca27e1 100644 (file)
@@ -8,17 +8,17 @@ std::function<bool(const ISearchable *)> Until::hasObject(
 {
     return [=](const ISearchable *searchable) -> bool {
         LOG_SCOPE_F(INFO, "sel:%p, search:%p", selector, searchable);
-        std::unique_ptr<UiObject> obj = searchable->findObject(selector);
+        std::shared_ptr<UiObject> obj = searchable->findObject(selector);
         return obj.get() != nullptr;
     };
 }
 
-std::function<std::unique_ptr<UiObject>(const ISearchable *)> Until::findObject(
+std::function<std::shared_ptr<UiObject>(const ISearchable *)> Until::findObject(
     const std::shared_ptr<UiSelector> selector)
 {
-    return [=](const ISearchable *searchable) -> std::unique_ptr<UiObject> {
+    return [=](const ISearchable *searchable) -> std::shared_ptr<UiObject> {
         LOG_SCOPE_F(INFO, "sel:%p, search:%p", selector, searchable);
-        std::unique_ptr<UiObject> obj = searchable->findObject(selector);
+        std::shared_ptr<UiObject> obj = searchable->findObject(selector);
         return obj;
     };
 }
index f353625..5e419b5 100644 (file)
@@ -22,8 +22,8 @@ Waiter::Waiter(const ISearchable *searchableObject, const UiObject *uiObject)
 template bool Waiter::waitFor(
     const std::function<bool(const ISearchable *)> condition) const;
 
-template std::unique_ptr<UiObject> Waiter::waitFor(
-    const std::function<std::unique_ptr<UiObject>(const ISearchable *)>
+template std::shared_ptr<UiObject> Waiter::waitFor(
+    const std::function<std::shared_ptr<UiObject>(const ISearchable *)>
         condition) const;
 
 template bool Waiter::waitFor(
diff --git a/libaurum/src/meson.build b/libaurum/src/meson.build
new file mode 100644 (file)
index 0000000..be6ee85
--- /dev/null
@@ -0,0 +1,14 @@
+
+libaurum_src += [
+  files('Sel.cc'),
+  files('UiDevice.cc'),
+  files('UiObject.cc'),
+  files('UiSelector.cc'),
+  files('Comparer.cc'),
+  files('Until.cc'),
+  files('Waiter.cc'),
+  files('PartialMatch.cc'),
+]
+
+subdir('Accessibility')
+subdir('Impl')
\ No newline at end of file
index a44efe6..103441e 100644 (file)
@@ -76,7 +76,6 @@ public:
     ::grpc::Status touchMove(::grpc::ServerContext *      context,
                              const ::aurum::ReqTouchMove *request,
                              ::aurum::RspTouchMove *      response) override;
-
     ::grpc::Status getDeviceTime(::grpc::ServerContext *          context,
                                  const ::aurum::ReqGetDeviceTime *request,
                                  ::aurum::RspGetDeviceTime *response) override;
@@ -86,10 +85,14 @@ public:
     ::grpc::Status sendKey(::grpc::ServerContext *context,
                            const ::aurum::ReqKey *request,
                            ::aurum::RspKey *      response) override;
-    ::grpc::Status takeScreenshot(
-        ::grpc::ServerContext *context,
-        const ::aurum::ReqTakeScreenshot *                 request,
-        ::grpc::ServerWriter< ::aurum::RspTakeScreenshot>* writer) override;
+
+    ::grpc::Status takeScreenshot(::grpc::ServerContext *context,
+                            const ::aurum::ReqTakeScreenshot *                 request,
+                            ::grpc::ServerWriter< ::aurum::RspTakeScreenshot>* writer) override;
+
+    ::grpc::Status dumpObjectTree(::grpc::ServerContext *context,
+                            const ::aurum::ReqDumpObjectTree *request,
+                            ::aurum::RspDumpObjectTree *      response) override;
 };
 
 #endif
index dd6b9f4..9f02ec0 100644 (file)
@@ -18,7 +18,7 @@ public:
     ::grpc::Status execute() override;
 
 protected:
-    bool hasHintText(UiObject *obj);
+    bool hasHintText(std::shared_ptr<UiObject> obj);
 };
 
 #endif
\ No newline at end of file
index 688d87c..3defda7 100644 (file)
@@ -21,7 +21,7 @@ public:
                        ::aurum::RspFindElement*       response);
     ::grpc::Status execute() override;
 protected:
-    virtual ISearchable* getSearchableTop(void);
+    virtual std::shared_ptr<ISearchable> getSearchableTop(void);
     virtual std::vector<std::shared_ptr<UiSelector>> getSelectors(void);
 };
 #endif
\ No newline at end of file
index b1f127f..3e9dc50 100644 (file)
@@ -8,7 +8,8 @@
 
 class ObjectMapper {
 private:
-    std::map<std::string, std::unique_ptr<UiObject>> mObjectMap;
+    std::map<std::string, std::shared_ptr<UiObject>> mObjectMap;
+    std::map<std::shared_ptr<UiObject>, std::string> mObjectMapReverse;
     unsigned long long                               mObjCounter;
 
 private:
@@ -19,8 +20,13 @@ public:
 
 public:
     static ObjectMapper *getInstance();
-    std::string          addElement(std::unique_ptr<UiObject> object);
-    UiObject *           getElement(const std::string &key);
+    std::string addElement(std::shared_ptr<UiObject> object);
+
+    std::shared_ptr<UiObject> getElement(const std::string key);
+    std::string getElement(std::shared_ptr<UiObject> object);
+
+    bool removeElement(const std::string key);
+    bool removeElement(std::shared_ptr<UiObject> object);
 };
 
 #endif
\ No newline at end of file
index 74c3727..4d177ea 100644 (file)
@@ -181,11 +181,10 @@ aurumServiceImpl::~aurumServiceImpl() {}
     std::unique_ptr<SendKeyCommand> cmd = std::make_unique<SendKeyCommand>(request, response);
     return execute(cmd.get());
 }
-::grpc::Status aurumServiceImpl::takeScreenshot(
-    ::grpc::ServerContext* context,
-    const ::aurum::ReqTakeScreenshot*                  request,
-    ::grpc::ServerWriter< ::aurum::RspTakeScreenshot>* writer)
+::grpc::Status aurumServiceImpl::takeScreenshot(::grpc::ServerContext* context,
+                                                const ::aurum::ReqTakeScreenshot* request,
+                                                ::grpc::ServerWriter< ::aurum::RspTakeScreenshot>* writer)
 {
     std::unique_ptr<TakeScreenshotCommand> cmd = std::make_unique<TakeScreenshotCommand>(request, writer);
     return execute(cmd.get());
-}
+}
\ No newline at end of file
index 5c24358..352c537 100644 (file)
@@ -9,7 +9,7 @@ ClearCommand::ClearCommand(const ::aurum::ReqClear* request,
 {
 }
 
-bool ClearCommand::hasHintText(UiObject *obj)
+bool ClearCommand::hasHintText(std::shared_ptr<UiObject> obj)
 {
     if (!obj) return false;
 
@@ -27,7 +27,7 @@ bool ClearCommand::hasHintText(UiObject *obj)
 {
     LOG_SCOPE_F(INFO, "Clear --------------- ");
     ObjectMapper* mObjMap = ObjectMapper::getInstance();
-    UiObject*     obj = mObjMap->getElement(mRequest->elementid());
+    std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
 
     if (obj) {
         obj->setText("");
index 2b152e1..8340168 100644 (file)
@@ -33,7 +33,7 @@ std::unique_ptr<ClickCommand> ClickCommand::createCommand(const ::aurum::ReqClic
 ::grpc::Status ClickElementCommand::execute()
 {
     ObjectMapper* mObjMap = ObjectMapper::getInstance();
-    UiObject* obj = mObjMap->getElement(mRequest->elementid());
+    std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
     LOG_SCOPE_F(INFO, "ClickElementCommand execute %p", obj);
 
     if (obj) {
@@ -47,9 +47,9 @@ std::unique_ptr<ClickCommand> ClickCommand::createCommand(const ::aurum::ReqClic
 
 ::grpc::Status ClickCoordCommand::execute()
 {
-    UiDevice* obj = UiDevice::getInstance(DeviceType::DEFAULT);
+    std::shared_ptr<UiDevice> obj = UiDevice::getInstance();
     const ::aurum::Point& point = mRequest->coordination();
-    LOG_SCOPE_F(INFO, "ClickCoordCommand execute %p @ (%d, %d)", obj, point.x(), point.y());
+    LOG_SCOPE_F(INFO, "ClickCoordCommand execute %p @ (%d, %d)", obj.get(), point.x(), point.y());
     obj->click(point.x(), point.y());
     mResponse->set_status(::aurum::RspStatus::OK);
     return grpc::Status::OK;
@@ -58,7 +58,7 @@ std::unique_ptr<ClickCommand> ClickCommand::createCommand(const ::aurum::ReqClic
 ::grpc::Status ClickAtspiCommand::execute()
 {
     ObjectMapper* mObjMap = ObjectMapper::getInstance();
-    UiObject* obj = mObjMap->getElement(mRequest->elementid());
+    std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
 
     LOG_SCOPE_F(INFO, "ClickAtspiCommand execute %p", obj);
 
index 8e8d106..c7935e8 100644 (file)
@@ -15,13 +15,14 @@ FindElementCommand::FindElementCommand(const ::aurum::ReqFindElement* request,
 {
     mObjMap = ObjectMapper::getInstance();
 }
-ISearchable* FindElementCommand::getSearchableTop(void)
+std::shared_ptr<ISearchable> FindElementCommand::getSearchableTop(void)
 {
-    ISearchable* searchableObj = nullptr;
+    std::shared_ptr<ISearchable> searchableObj{nullptr};
 
-    if (mRequest->_automationid_case() != 0)
+    if (mRequest->_automationid_case() != 0) {
         searchableObj = mObjMap->getElement(mRequest->elementid());
-    if (!searchableObj) searchableObj = UiDevice::getInstance(DeviceType::DEFAULT);
+    }
+    if (!searchableObj) searchableObj = UiDevice::getInstance();
 
     return searchableObj;
 }
@@ -56,9 +57,9 @@ std::vector<std::shared_ptr<UiSelector>> FindElementCommand::getSelectors(void)
     auto searchableObj = getSearchableTop();
     auto selectors     = getSelectors();
 
-    std::vector<std::unique_ptr<UiObject>> founds = {};
+    std::vector<std::shared_ptr<UiObject>> founds = {};
 
-    for ( auto sel : selectors ) {
+    for ( auto &sel : selectors ) {
         auto ret = searchableObj->findObjects(sel);
         std::move(std::begin(ret), std::end(ret), std::back_inserter(founds));
     }
index a1b58c6..b468e43 100644 (file)
@@ -17,7 +17,7 @@ FlickCommand::FlickCommand(const ::aurum::ReqFlick *request,
     const ::aurum::Point &endPoint = mRequest->endpoint();
     int                   durationMs = mRequest->durationms();
 
-    UiDevice *device = UiDevice::getInstance(DeviceType::DEFAULT);
+    std::shared_ptr<UiDevice> device = UiDevice::getInstance();
     device->drag(startPoint.x(), startPoint.y(), endPoint.x(), endPoint.y(), durationMs/MINIMUM_TOUCHEVENT_INTV_MS, durationMs);
     mResponse->set_status(::aurum::RspStatus::OK);
 
index 09e9949..5b0ced7 100644 (file)
@@ -52,7 +52,7 @@ std::unique_ptr<GetAttributeCommand> GetAttributeCommand::createCommand(const ::
 
 ::grpc::Status GetVisibleAttributeCommand::execute()
 {
-    UiObject* obj = mObjMap->getElement(mRequest->elementid());
+    std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
     if (!obj) {
         mResponse->set_boolvalue(false);
         mResponse->set_status(aurum::RspStatus::ERROR);
@@ -65,7 +65,7 @@ std::unique_ptr<GetAttributeCommand> GetAttributeCommand::createCommand(const ::
 
 ::grpc::Status GetFocusedAttributeCommand::execute()
 {
-    UiObject* obj = mObjMap->getElement(mRequest->elementid());
+    std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
     if (!obj) {
         mResponse->set_boolvalue(false);
         mResponse->set_status(aurum::RspStatus::ERROR);
@@ -78,7 +78,7 @@ std::unique_ptr<GetAttributeCommand> GetAttributeCommand::createCommand(const ::
 
 ::grpc::Status GetFocusableAttributeCommand::execute()
 {
-    UiObject* obj = mObjMap->getElement(mRequest->elementid());
+    std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
     if (!obj) {
         mResponse->set_boolvalue(false);
         mResponse->set_status(aurum::RspStatus::ERROR);
@@ -91,7 +91,7 @@ std::unique_ptr<GetAttributeCommand> GetAttributeCommand::createCommand(const ::
 
 ::grpc::Status GetCheckableAttributeCommand::execute()
 {
-    UiObject* obj = mObjMap->getElement(mRequest->elementid());
+    std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
     if (!obj) {
         mResponse->set_boolvalue(false);
         mResponse->set_status(aurum::RspStatus::ERROR);
@@ -104,7 +104,7 @@ std::unique_ptr<GetAttributeCommand> GetAttributeCommand::createCommand(const ::
 
 ::grpc::Status GetCheckedAttributeCommand::execute()
 {
-    UiObject* obj = mObjMap->getElement(mRequest->elementid());
+    std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
     if (!obj) {
         mResponse->set_boolvalue(false);
         mResponse->set_status(aurum::RspStatus::ERROR);
@@ -117,7 +117,7 @@ std::unique_ptr<GetAttributeCommand> GetAttributeCommand::createCommand(const ::
 
 ::grpc::Status GetEnabledAttributeCommand::execute()
 {
-    UiObject* obj = mObjMap->getElement(mRequest->elementid());
+    std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
     if (!obj) {
         mResponse->set_boolvalue(false);
         mResponse->set_status(aurum::RspStatus::ERROR);
@@ -130,7 +130,7 @@ std::unique_ptr<GetAttributeCommand> GetAttributeCommand::createCommand(const ::
 
 ::grpc::Status GetClickableAttributeCommand::execute()
 {
-    UiObject* obj = mObjMap->getElement(mRequest->elementid());
+    std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
     if (!obj) {
         mResponse->set_boolvalue(false);
         mResponse->set_status(aurum::RspStatus::ERROR);
@@ -143,7 +143,7 @@ std::unique_ptr<GetAttributeCommand> GetAttributeCommand::createCommand(const ::
 
 ::grpc::Status GetScrollableAttributeCommand::execute()
 {
-    UiObject* obj = mObjMap->getElement(mRequest->elementid());
+    std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
     if (!obj) {
         mResponse->set_boolvalue(false);
         mResponse->set_status(aurum::RspStatus::ERROR);
@@ -156,7 +156,7 @@ std::unique_ptr<GetAttributeCommand> GetAttributeCommand::createCommand(const ::
 
 ::grpc::Status GetSelectableAttributeCommand::execute()
 {
-    UiObject* obj = mObjMap->getElement(mRequest->elementid());
+    std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
     if (!obj) {
         mResponse->set_boolvalue(false);
         mResponse->set_status(aurum::RspStatus::ERROR);
@@ -169,7 +169,7 @@ std::unique_ptr<GetAttributeCommand> GetAttributeCommand::createCommand(const ::
 
 ::grpc::Status GetSelectedAttributeCommand::execute()
 {
-    UiObject* obj = mObjMap->getElement(mRequest->elementid());
+    std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
     if (!obj) {
         mResponse->set_boolvalue(false);
         mResponse->set_status(aurum::RspStatus::ERROR);
@@ -183,7 +183,7 @@ std::unique_ptr<GetAttributeCommand> GetAttributeCommand::createCommand(const ::
 
 ::grpc::Status GetShowingAttributeCommand::execute()
 {
-    UiObject* obj = mObjMap->getElement(mRequest->elementid());
+    std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
     if (!obj) {
         mResponse->set_boolvalue(false);
         mResponse->set_status(aurum::RspStatus::ERROR);
@@ -198,7 +198,7 @@ std::unique_ptr<GetAttributeCommand> GetAttributeCommand::createCommand(const ::
 
 ::grpc::Status GetActiveAttributeCommand::execute()
 {
-    UiObject* obj = mObjMap->getElement(mRequest->elementid());
+    std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
     if (!obj) {
         mResponse->set_boolvalue(false);
         mResponse->set_status(aurum::RspStatus::ERROR);
index a9f1142..ed71dcc 100644 (file)
@@ -88,7 +88,7 @@ public:
 {
     LOG_SCOPE_F(INFO, "GetDeviceTime --------------- ");
 
-    UiDevice* obj = UiDevice::getInstance(DeviceType::DEFAULT);
+    std::shared_ptr<UiDevice> obj = UiDevice::getInstance();
     ::aurum::ReqGetDeviceTime_TimeType type = mRequest->type();
     long long                          utcStampMs;
 
index de77d0e..919c196 100644 (file)
@@ -13,15 +13,14 @@ GetSizeCommand::GetSizeCommand(const ::aurum::ReqGetSize* request,
 {
     LOG_SCOPE_F(INFO, "GetSize --------------- ");
     ObjectMapper *mObjMap = ObjectMapper::getInstance();
-    UiObject* obj = mObjMap->getElement(mRequest->elementid());
+    std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
     if (obj) {
         const Rect<int> &size = obj->getBoundingBox();
-        ::aurum::Rect rect;
-        rect.set_x(size.mTopLeft.x);
-        rect.set_y(size.mTopLeft.y);
-        rect.set_width(size.width());
-        rect.set_height(size.height());
-        mResponse->mutable_size()->CopyFrom(rect);
+        ::aurum::Rect *rect = mResponse->mutable_size();
+        rect->set_x(size.mTopLeft.x);
+        rect->set_y(size.mTopLeft.y);
+        rect->set_width(size.width());
+        rect->set_height(size.height());
     }
 
     return grpc::Status::OK;
index 0eabcb5..ebe9c93 100644 (file)
@@ -13,7 +13,7 @@ GetValueCommand::GetValueCommand(const ::aurum::ReqGetValue* request,
 {
     LOG_SCOPE_F(INFO, "GetValue --------------- ");
     ObjectMapper* mObjMap = ObjectMapper::getInstance();
-    UiObject*     obj = mObjMap->getElement(mRequest->elementid());
+    std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
 
     if (obj) {
         std::string text = obj->getText();
index 6dcc5a1..6360c12 100644 (file)
@@ -18,14 +18,14 @@ LongClickCommand::LongClickCommand(const ::aurum::ReqClick* request,
     ::aurum::ReqClick_RequestType type = mRequest->type();
 
     if (type == ::aurum::ReqClick_RequestType_ELEMENTID) {
-        UiObject* obj = mObjMap->getElement(mRequest->elementid());
+        std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
         if (obj) {
             obj->longClick(LOGNCLICK_INTERVAL);
             mResponse->set_status(::aurum::RspStatus::OK);
         } else
             mResponse->set_status(::aurum::RspStatus::ERROR);
     } else if (type == ::aurum::ReqClick_RequestType_COORD) {
-        UiDevice* obj = UiDevice::getInstance(DeviceType::DEFAULT);
+        std::shared_ptr<UiDevice> obj = UiDevice::getInstance();
         const ::aurum::Point& point = mRequest->coordination();
         obj->click(point.x(), point.y(), LOGNCLICK_INTERVAL);
         mResponse->set_status(::aurum::RspStatus::OK);
index 2a113b8..6008d44 100644 (file)
@@ -12,7 +12,7 @@ SendKeyCommand::SendKeyCommand(const ::aurum::ReqKey* request,
 ::grpc::Status SendKeyCommand::execute()
 {
     LOG_SCOPE_F(INFO, "SendKey --------------- ");
-    UiDevice* mDevice = UiDevice::getInstance(DeviceType::DEFAULT);
+    std::shared_ptr<UiDevice> mDevice = UiDevice::getInstance();
     ::aurum::ReqKey_KeyType type = mRequest->type();
     ::aurum::ReqKey_KeyActionType action_type = mRequest->actiontype();
     KeyRequestType actionType = static_cast<KeyRequestType>(action_type);
index 9f574ee..32cd476 100644 (file)
@@ -11,7 +11,7 @@ SetValueCommand::SetValueCommand(const ::aurum::ReqSetValue* request,
 {
     LOG_SCOPE_F(INFO, "SetValue (text:%s) --------------- ", mRequest->stringvalue().c_str());
     ObjectMapper* mObjMap = ObjectMapper::getInstance();
-    UiObject*     obj = mObjMap->getElement(mRequest->elementid());
+    std::shared_ptr<UiObject> obj = mObjMap->getElement(mRequest->elementid());
     if (obj) obj->setText(const_cast<std::string&>(mRequest->stringvalue()));
     return grpc::Status::OK;
 }
\ No newline at end of file
index b84f700..70c4de6 100644 (file)
@@ -11,7 +11,7 @@ SyncCommand::SyncCommand(const ::aurum::ReqEmpty *request,
 
 ::grpc::Status SyncCommand::execute()
 {
-    UiDevice *obj = UiDevice::getInstance(DeviceType::DEFAULT);
+    std::shared_ptr<UiDevice> obj = UiDevice::getInstance();
     long long timeMs = obj->getSystemTime(TimeRequestType::WALLCLOCK);
     LOG_SCOPE_F(INFO, "Sync Command @ %f", timeMs/1000.0);
     // do post-command
index 47eb9d0..ad199b1 100644 (file)
@@ -16,7 +16,7 @@ TakeScreenshotCommand::TakeScreenshotCommand(
     LOG_SCOPE_F(INFO, "TakeScreenshot --------------- ");
 
     std::string path = "/tmp/screenshot.png";
-    UiDevice* mDevice = UiDevice::getInstance(DeviceType::DEFAULT);
+    std::shared_ptr<UiDevice> mDevice = UiDevice::getInstance();
     mDevice->takeScreenshot(path, 1.0, 1);
 
     std::ifstream ifs(path, std::ifstream::binary);
index 5f3d45f..533f520 100644 (file)
@@ -12,7 +12,7 @@ TouchDownCommand::TouchDownCommand(const ::aurum::ReqTouchDown* request,
 {
     LOG_SCOPE_F(INFO, "TouchDown --------------- ");
     const aurum::Point& point_ = mRequest->coordination();
-    int seq = UiDevice::getInstance(DeviceType::DEFAULT)
+    int seq = UiDevice::getInstance()
         ->touchDown(point_.x(), point_.y());
     mResponse->set_seqid(seq);
     return grpc::Status::OK;
index 883199a..d31c771 100644 (file)
@@ -13,6 +13,6 @@ TouchMoveCommand::TouchMoveCommand(const ::aurum::ReqTouchMove* request,
     LOG_SCOPE_F(INFO, "TouchMove --------------- ");
     const aurum::Point& point = mRequest->coordination();
     int seq = mRequest->seqid();
-    UiDevice::getInstance(DeviceType::DEFAULT)->touchMove(point.x(), point.y(), seq);
+    UiDevice::getInstance()->touchMove(point.x(), point.y(), seq);
     return grpc::Status::OK;
 }
\ No newline at end of file
index 0aa24a8..354ccad 100644 (file)
@@ -13,6 +13,6 @@ TouchUpCommand::TouchUpCommand(const ::aurum::ReqTouchUp* request,
     LOG_SCOPE_F(INFO, "TouchUp --------------- ");
     const aurum::Point& point = mRequest->coordination();
     int seq = mRequest->seqid();
-    UiDevice::getInstance(DeviceType::DEFAULT)->touchUp(point.x(), point.y(), seq);
+    UiDevice::getInstance()->touchUp(point.x(), point.y(), seq);
     return grpc::Status::OK;
 }
\ No newline at end of file
index 75bf956..e968875 100644 (file)
@@ -1,6 +1,8 @@
 #include "ObjectMapper.h"
+#include <memory>
+#include <loguru.hpp>
 
-ObjectMapper::ObjectMapper() : mObjectMap{}, mObjCounter{0} {}
+ObjectMapper::ObjectMapper() : mObjectMap{}, mObjectMapReverse{}, mObjCounter{0} {}
 
 ObjectMapper::~ObjectMapper() {}
 
@@ -10,22 +12,55 @@ ObjectMapper *ObjectMapper::getInstance()
     return mInstance;
 }
 
-std::string ObjectMapper::addElement(std::unique_ptr<UiObject> object)
+std::string ObjectMapper::addElement(std::shared_ptr<UiObject> object)
 {
     ++mObjCounter;
     std::string key = std::to_string(mObjCounter);
-    mObjectMap[key] = std::move(object);
+    mObjectMap[key] = object;
+    mObjectMapReverse[object] = key;
+    LOG_SCOPE_F(INFO, "addElement %p as key %s", object.get(), key.c_str());
     return key;
 }
 
-UiObject *ObjectMapper::getElement(const std::string &key)
+std::shared_ptr<UiObject> ObjectMapper::getElement(std::string key)
 {
+    LOG_SCOPE_F(INFO, "getElement for key(%s)", key.c_str());
     unsigned long long keyCnt = (unsigned long long)std::stoll(key); // this key is a result of calling std:to_string(mObjCounter)
     if (keyCnt <= 0 || keyCnt > mObjCounter) return nullptr;
     if (mObjectMap.count(key)) {
-        UiObject *obj = mObjectMap[key].get();
-        const_cast<const UiObject *>(obj)->refresh();
+        std::shared_ptr<UiObject> obj = mObjectMap[key];
+        obj->refresh();
+        LOG_F(INFO, "succeeded");
         return obj;
     }
+    LOG_F(INFO, "failed(object not found)");
     return nullptr;
 }
+
+std::string ObjectMapper::getElement(std::shared_ptr<UiObject> object)
+{
+    LOG_SCOPE_F(INFO, "getElement for object(%p)", object.get());
+    if (object && mObjectMapReverse.count(object)) {
+        LOG_F(INFO, "succeeded");
+        return mObjectMapReverse[object];
+    }
+    LOG_F(INFO, "failed(object not found)");
+    return std::string{""};
+}
+
+bool ObjectMapper::removeElement(const std::string key)
+{
+    std::shared_ptr<UiObject> obj = getElement(key);
+    if (obj) {
+        if (mObjectMap.erase(key) && mObjectMapReverse.erase(obj))
+            return true;
+    }
+    return false;
+}
+
+bool ObjectMapper::removeElement(std::shared_ptr<UiObject> object)
+{
+    std::string key = getElement(object);
+    if (key.empty()) return false;
+    return removeElement(key);
+}
\ No newline at end of file
index 7e0c3e1..30fde1a 100644 (file)
@@ -5,7 +5,27 @@
 #include <UiSelector.h>
 #include <Sel.h>
 
+#include "MockDeviceImpl.h"
+
+#include <iostream>
+#include <algorithm>
+
+#include <loguru.hpp>
+
+
+#include "MockAccessibleWatcher.h"
+#include "MockAccessibleApplication.h"
+#include "MockAccessibleWindow.h"
+#include "MockAccessibleNode.h"
+
+
 class UaTest : public ::testing::Test {
+    public:
+        UaTest(){
+            /*const char *logPath = "/tmp/ua.log";
+            loguru::g_preamble = false;
+            loguru::add_file(logPath, loguru::Append, loguru::Verbosity_MAX);*/
+        }
     protected:
         void SetUp() override {
         }
@@ -14,19 +34,63 @@ class UaTest : public ::testing::Test {
         }
 };
 
+
 TEST_F(UaTest, EmptyTest)
 {
     ASSERT_EQ(true, true);
 }
 
+
+
 TEST_F(UaTest, DeviceInit)
 {
-    const UiDevice *mDevice = UiDevice::getInstance(DeviceType::DEFAULT);
-    ASSERT_NE(mDevice, nullptr);
+    std::shared_ptr<UiDevice> mDevice1 = UiDevice::getInstance(nullptr);
+    ASSERT_NE(mDevice1, nullptr);
 }
 
+
 TEST_F(UaTest, TextSelector)
 {
     std::shared_ptr<UiSelector> sel = Sel::text("test");
     ASSERT_NE(sel.get(), nullptr);
+    auto result = UiDevice::getInstance()->findObjects(sel);
+    std::for_each(result.begin(), result.end(), [](auto obj){
+        std::cout << obj->getText() << std::endl;
+    });
+    ASSERT_EQ(nullptr, nullptr);
+}
+
+TEST_F(UaTest, DeviceClick)
+{
+    auto result = UiDevice::getInstance()->click(1,2);
+    ASSERT_EQ(result, false);
+}
+
+TEST_F(UaTest, FindElement)
+{
+    auto watcher = AccessibleWatcher::getInstance();
+
+    MockAccessibleWatcher *mockWatcher = dynamic_cast<MockAccessibleWatcher*>(const_cast<AccessibleWatcher*>(watcher));
+
+    std::shared_ptr<MockAccessibleNode> appNode = std::make_shared<MockAccessibleNode>(nullptr, "text", "pkg", "application", "res","type","style", Rect<int>{0,0,100,200}, 0, 0);
+    std::shared_ptr<MockAccessibleApplication> app = std::make_shared<MockAccessibleApplication>(appNode);
+    mockWatcher->addApplication(app);
+
+    std::shared_ptr<MockAccessibleNode> winNode = std::make_shared<MockAccessibleNode>(nullptr, "text", "pkg", "window", "res","type","style", Rect<int>{0,0,100,200}, 0, 0);
+    std::shared_ptr<MockAccessibleWindow> win = std::make_shared<MockAccessibleWindow>(app, winNode);
+    winNode->setFeatureProperty(8);
+    winNode->setFeatureProperty(9);
+    winNode->setFeatureProperty(10);
+    app->addWindow(win);
+
+    std::shared_ptr<MockAccessibleNode> node = std::make_shared<MockAccessibleNode>(nullptr, "test", "pkg", "ahahah", "res","type","style", Rect<int>{0,0,100,200}, 0, 0);
+    winNode->addChild(node);
+
+    std::shared_ptr<UiSelector> sel = Sel::text("test");
+    auto result = UiDevice::getInstance()->findObjects(sel);
+    std::for_each(result.begin(), result.end(), [](auto obj){
+        ASSERT_EQ(obj->getRole(), "ahahah");
+    });
+
+    ASSERT_EQ(nullptr, nullptr);
 }
\ No newline at end of file