From 8fe9dae887612c2996c89ad3f9ea07c18ce4baff Mon Sep 17 00:00:00 2001 From: Wonki Kim Date: Thu, 13 Aug 2020 11:35:45 +0900 Subject: [PATCH] libaurum: apply smart pointer wider and extract impl out 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 --- libaurum/inc/Accessibility/AccessibleApplication.h | 25 ++ libaurum/inc/Accessibility/AccessibleNode.h | 340 +++++++++++++++ libaurum/inc/{ => Accessibility}/AccessibleUtils.h | 41 +- libaurum/inc/Accessibility/AccessibleWatcher.h | 63 +++ libaurum/inc/Accessibility/AccessibleWindow.h | 26 ++ libaurum/inc/AccessibleNode.h | 479 --------------------- libaurum/inc/Comparer.h | 24 +- libaurum/inc/ISearchable.h | 4 +- .../Accessibility/AtspiAccessibleApplication.h | 17 + .../inc/Impl/Accessibility/AtspiAccessibleNode.h | 95 ++++ .../Accessibility/AtspiAccessibleWatcher.h} | 117 +++-- .../inc/Impl/Accessibility/AtspiAccessibleWindow.h | 9 + .../Impl/Accessibility/MockAccessibleApplication.h | 23 + .../inc/Impl/Accessibility/MockAccessibleNode.h | 103 +++++ .../inc/Impl/Accessibility/MockAccessibleWatcher.h | 50 +++ .../inc/Impl/Accessibility/MockAccessibleWindow.h | 8 + libaurum/inc/Impl/MockDeviceImpl.h | 62 +++ .../TizenImpl.h => Impl/TizenDeviceImpl.h} | 8 +- libaurum/inc/Misc/Point2D.h | 45 ++ libaurum/inc/Misc/Rect.h | 77 ++++ libaurum/inc/PartialMatch.h | 8 +- libaurum/inc/UiDevice.h | 33 +- libaurum/inc/UiObject.h | 44 +- libaurum/inc/UiScrollable.h | 78 ++++ libaurum/inc/UiSelector.h | 6 - libaurum/inc/Until.h | 2 +- libaurum/meson.build | 28 +- .../src/Accessibility/AccessibleApplication.cc | 38 ++ libaurum/src/Accessibility/AccessibleNode.cc | 156 +++++++ .../src/{ => Accessibility}/AccessibleUtils.cc | 0 libaurum/src/Accessibility/AccessibleWatcher.cc | 75 ++++ libaurum/src/Accessibility/AccessibleWindow.cc | 36 ++ libaurum/src/Accessibility/meson.build | 7 + libaurum/src/AccessibleWatcher.cc | 326 -------------- libaurum/src/Comparer.cc | 53 ++- .../Accessibility/AtspiAccessibleApplication.cc | 34 ++ .../Accessibility/AtspiAccessibleNode.cc} | 401 ++++++----------- .../Impl/Accessibility/AtspiAccessibleWatcher.cc | 406 +++++++++++++++++ .../Impl/Accessibility/AtspiAccessibleWindow.cc | 13 + .../Accessibility/MockAccessibleApplication.cc | 65 +++ .../src/Impl/Accessibility/MockAccessibleNode.cc | 149 +++++++ .../Impl/Accessibility/MockAccessibleWatcher.cc | 68 +++ .../src/Impl/Accessibility/MockAccessibleWindow.cc | 12 + libaurum/src/Impl/Accessibility/meson.build | 13 + libaurum/src/Impl/MockDeviceImpl.cc | 182 ++++++++ .../TizenImpl.cc => Impl/TizenDeviceImpl.cc} | 86 ++-- libaurum/src/Impl/meson.build | 11 + libaurum/src/PartialMatch.cc | 26 +- libaurum/src/UiDevice.cc | 92 ++-- libaurum/src/UiObject.cc | 83 ++-- libaurum/src/UiScrollable.cc | 62 +++ libaurum/src/UiSelector.cc | 6 - libaurum/src/Until.cc | 8 +- libaurum/src/Waiter.cc | 4 +- libaurum/src/meson.build | 14 + org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h | 13 +- .../inc/Commands/ClearCommand.h | 2 +- .../inc/Commands/FindElementCommand.h | 2 +- org.tizen.aurum-bootstrap/inc/ObjectMapper.h | 12 +- org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc | 9 +- .../src/Commands/ClearCommand.cc | 4 +- .../src/Commands/ClickCommand.cc | 8 +- .../src/Commands/FindElementCommand.cc | 13 +- .../src/Commands/FlickCommand.cc | 2 +- .../src/Commands/GetAttributeCommand.cc | 24 +- .../src/Commands/GetDeviceTimeCommand.cc | 2 +- .../src/Commands/GetSizeCommand.cc | 13 +- .../src/Commands/GetValueCommand.cc | 2 +- .../src/Commands/LongClickCommand.cc | 4 +- .../src/Commands/SendKeyCommand.cc | 2 +- .../src/Commands/SetValueCommand.cc | 2 +- .../src/Commands/SyncCommand.cc | 2 +- .../src/Commands/TakeScreenshotCommand.cc | 2 +- .../src/Commands/TouchDownCommand.cc | 2 +- .../src/Commands/TouchMoveCommand.cc | 2 +- .../src/Commands/TouchUpCommand.cc | 2 +- org.tizen.aurum-bootstrap/src/ObjectMapper.cc | 47 +- tests/ua_test.cpp | 68 ++- 78 files changed, 3024 insertions(+), 1456 deletions(-) create mode 100644 libaurum/inc/Accessibility/AccessibleApplication.h create mode 100644 libaurum/inc/Accessibility/AccessibleNode.h rename libaurum/inc/{ => Accessibility}/AccessibleUtils.h (62%) create mode 100644 libaurum/inc/Accessibility/AccessibleWatcher.h create mode 100644 libaurum/inc/Accessibility/AccessibleWindow.h delete mode 100644 libaurum/inc/AccessibleNode.h create mode 100644 libaurum/inc/Impl/Accessibility/AtspiAccessibleApplication.h create mode 100644 libaurum/inc/Impl/Accessibility/AtspiAccessibleNode.h rename libaurum/inc/{AccessibleWatcher.h => Impl/Accessibility/AtspiAccessibleWatcher.h} (56%) create mode 100644 libaurum/inc/Impl/Accessibility/AtspiAccessibleWindow.h create mode 100644 libaurum/inc/Impl/Accessibility/MockAccessibleApplication.h create mode 100644 libaurum/inc/Impl/Accessibility/MockAccessibleNode.h create mode 100644 libaurum/inc/Impl/Accessibility/MockAccessibleWatcher.h create mode 100644 libaurum/inc/Impl/Accessibility/MockAccessibleWindow.h create mode 100644 libaurum/inc/Impl/MockDeviceImpl.h rename libaurum/inc/{DeviceImpl/TizenImpl.h => Impl/TizenDeviceImpl.h} (94%) create mode 100644 libaurum/inc/Misc/Point2D.h create mode 100644 libaurum/inc/Misc/Rect.h create mode 100644 libaurum/inc/UiScrollable.h create mode 100644 libaurum/src/Accessibility/AccessibleApplication.cc create mode 100644 libaurum/src/Accessibility/AccessibleNode.cc rename libaurum/src/{ => Accessibility}/AccessibleUtils.cc (100%) create mode 100644 libaurum/src/Accessibility/AccessibleWatcher.cc create mode 100644 libaurum/src/Accessibility/AccessibleWindow.cc create mode 100644 libaurum/src/Accessibility/meson.build delete mode 100644 libaurum/src/AccessibleWatcher.cc create mode 100644 libaurum/src/Impl/Accessibility/AtspiAccessibleApplication.cc rename libaurum/src/{AccessibleNode.cc => Impl/Accessibility/AtspiAccessibleNode.cc} (59%) create mode 100644 libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc create mode 100644 libaurum/src/Impl/Accessibility/AtspiAccessibleWindow.cc create mode 100644 libaurum/src/Impl/Accessibility/MockAccessibleApplication.cc create mode 100644 libaurum/src/Impl/Accessibility/MockAccessibleNode.cc create mode 100644 libaurum/src/Impl/Accessibility/MockAccessibleWatcher.cc create mode 100644 libaurum/src/Impl/Accessibility/MockAccessibleWindow.cc create mode 100644 libaurum/src/Impl/Accessibility/meson.build create mode 100644 libaurum/src/Impl/MockDeviceImpl.cc rename libaurum/src/{DeviceImpl/TizenImpl.cc => Impl/TizenDeviceImpl.cc} (79%) create mode 100644 libaurum/src/Impl/meson.build create mode 100644 libaurum/src/UiScrollable.cc create mode 100644 libaurum/src/meson.build diff --git a/libaurum/inc/Accessibility/AccessibleApplication.h b/libaurum/inc/Accessibility/AccessibleApplication.h new file mode 100644 index 0000000..5daa948 --- /dev/null +++ b/libaurum/inc/Accessibility/AccessibleApplication.h @@ -0,0 +1,25 @@ +#pragma once + +#include "AccessibleWindow.h" +#include "AccessibleNode.h" + +#include + +class AccessibleApplication { +public: + AccessibleApplication(std::shared_ptr node); + virtual ~AccessibleApplication(); + +public: + std::shared_ptr getAccessibleNode(); + bool isActive(void); + +public: + virtual std::vector> getWindows(void) = 0; + virtual std::vector> getActiveWindows(void); + virtual std::string getPackageName(void) = 0; + +private: + std::shared_ptr mNode; +}; + diff --git a/libaurum/inc/Accessibility/AccessibleNode.h b/libaurum/inc/Accessibility/AccessibleNode.h new file mode 100644 index 0000000..69b2a89 --- /dev/null +++ b/libaurum/inc/Accessibility/AccessibleNode.h @@ -0,0 +1,340 @@ +#ifndef ACCESSIBLE_NODE_H +#define ACCESSIBLE_NODE_H + +#include +#include +#include +#include + +#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 getChildAt(int index) const = 0; + + /** + * @brief TBD + * @since_tizen 5.5 + */ + virtual std::vector> getChildren() const = 0; + + /** + * @brief TBD + * @since_tizen 5.5 + */ + virtual std::shared_ptr 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 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 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 mBoundingBox; + + /** + * @brief TBD + */ + int mSupportingIfaces; + + /** + * @brief TBD + */ + int mFeatureProperty; + +}; + +#endif diff --git a/libaurum/inc/AccessibleUtils.h b/libaurum/inc/Accessibility/AccessibleUtils.h similarity index 62% rename from libaurum/inc/AccessibleUtils.h rename to libaurum/inc/Accessibility/AccessibleUtils.h index 38d53fe..0fb722a 100644 --- a/libaurum/inc/AccessibleUtils.h +++ b/libaurum/inc/Accessibility/AccessibleUtils.h @@ -1,10 +1,8 @@ -#ifndef ACCESSIBLE_UTILS_H -#define ACCESSIBLE_UTILS_H - -#include +#pragma once +//#include #include -#include +#include #include #include "config.h" @@ -80,6 +78,35 @@ unique_ptr_gobj make_gobj_ref_unique(T *ptr) * @brief TBD * @since_tizen 5.5 */ -char *state_to_char(AtspiStateType state); +template +std::shared_ptr make_gobj_shared(T *ptr) +{ + return std::shared_ptr(ptr, [](T *ptr){ if(ptr) g_object_unref(ptr); }); +} + +/** + * @brief TBD + * @since_tizen 5.5 + */ +template +std::shared_ptr make_garray_shared(T *ptr) +{ + return std::shared_ptr(ptr, [](T *ptr){ if(ptr) g_array_free(ptr, 1); }); +} -#endif \ No newline at end of file +/** + * @brief TBD + * @since_tizen 5.5 + */ +template +std::shared_ptr make_gobj_ref_shared(T *ptr) +{ + g_object_ref(ptr); + return std::shared_ptr(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 index 0000000..d332713 --- /dev/null +++ b/libaurum/inc/Accessibility/AccessibleWatcher.h @@ -0,0 +1,63 @@ +#ifndef ACCESSIBLE_H +#define ACCESSIBLE_H + + +#include "AccessibleApplication.h" +#include "AccessibleWindow.h" +#include "AccessibleNode.h" + +#include "AccessibleUtils.h" + +#include +#include + + +#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 getApplicationAt(int index) const = 0; + + /** + * @brief TBD + * @since_tizen 5.5 + */ + virtual std::vector> getApplications(void) const = 0; + +public: + /** + * @brief TBD + * @since_tizen 5.5 + */ + virtual std::vector> getActiveApplications(void) const; +}; + +#endif diff --git a/libaurum/inc/Accessibility/AccessibleWindow.h b/libaurum/inc/Accessibility/AccessibleWindow.h new file mode 100644 index 0000000..44e87c6 --- /dev/null +++ b/libaurum/inc/Accessibility/AccessibleWindow.h @@ -0,0 +1,26 @@ +#pragma once + +#include "AccessibleNode.h" + +#include +#include + +class AccessibleApplication; + +class AccessibleWindow { +public: + AccessibleWindow(std::shared_ptr app, std::shared_ptr node); + virtual ~AccessibleWindow(); + +public: + std::string getTitle(void); + bool isShowing(); + bool isActive(); + + std::shared_ptr getApplication(void); + std::shared_ptr getNode(void); + +private: + std::shared_ptr mNode; + std::shared_ptr mApp; +}; \ No newline at end of file diff --git a/libaurum/inc/AccessibleNode.h b/libaurum/inc/AccessibleNode.h deleted file mode 100644 index 11dfcc8..0000000 --- a/libaurum/inc/AccessibleNode.h +++ /dev/null @@ -1,479 +0,0 @@ -#ifndef ACCESSIBLE_NODE_H -#define ACCESSIBLE_NODE_H -#include - -#include -#include -#include -#include - -#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 -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 -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 &tl, const Point2D &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 &src) - - { - this->mTopLeft = Point2D{src.mTopLeft}; - this->mBottomRight = Point2D{src.mBottomRight}; - } - - /** - * @brief TBD - * @since_tizen 5.5 - */ - Point2D midPoint() const - { - return Point2D{mTopLeft.x + static_cast(width() / 2), - mTopLeft.y + static_cast(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 mTopLeft; - - /** - * @brief TBD - */ - Point2D 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 get(AtspiAccessible *node); - -public: - /** - * @brief TBD - * @since_tizen 5.5 - */ - int getChildCount() const; - - /** - * @brief TBD - * @since_tizen 5.5 - */ - std::unique_ptr getChildAt(int index) const; - - /** - * @brief TBD - * @since_tizen 5.5 - */ - std::unique_ptr 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 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 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 mNodeMap; - -private: - /** - * @brief TBD - */ - unique_ptr_gobj 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 mBoundingBox; - - /** - * @brief TBD - */ - int mSupportingIfaces; - - /** - * @brief TBD - */ - mutable int mFeatureProperty; - - /** - * @brief TBD - */ - bool mIsAlive; -}; - -#endif diff --git a/libaurum/inc/Comparer.h b/libaurum/inc/Comparer.h index db146b0..91df714 100644 --- a/libaurum/inc/Comparer.h +++ b/libaurum/inc/Comparer.h @@ -22,7 +22,7 @@ private: * @brief TBD * @since_tizen 5.5 */ - Comparer(const UiDevice *device, const std::shared_ptr selector, + Comparer(const std::shared_ptr device, const std::shared_ptr selector, const bool &earlyReturn); /** @@ -36,31 +36,31 @@ public: * @brief TBD * @since_tizen 5.5 */ - static std::unique_ptr findObject(const UiDevice * device, + static std::shared_ptr findObject(const std::shared_ptr device, const std::shared_ptr selector, - const AccessibleNode *root); + const std::shared_ptr root); /** * @brief TBD * @since_tizen 5.5 */ - static std::vector> findObjects( - const UiDevice *device, const std::shared_ptr selector, - const AccessibleNode *root); + static std::vector> findObjects( + const std::shared_ptr device, const std::shared_ptr selector, + const std::shared_ptr root); private: /** * @brief TBD * @since_tizen 5.5 */ - std::vector> findObjects(const AccessibleNode *root); + std::vector> findObjects(const std::shared_ptr root); /** * @brief TBD * @since_tizen 5.5 */ - std::vector> findObjects( - const AccessibleNode *root, const int &index, const int &depth, + std::vector> findObjects( + const std::shared_ptr root, const int &index, const int &depth, std::list> &partialMatches); private: @@ -68,16 +68,16 @@ private: * @brief TBD * @since_tizen 5.5 */ - std::unique_ptr accept(const AccessibleNode *node, + /* std::unique_ptr accept(const AccessibleNode *node, const std::shared_ptr selector, const int &index, const int &depth, const int &relDepth); - +*/ private: /** * @brief TBD */ - const UiDevice *mDevice; + const std::shared_ptr mDevice; /** * @brief TBD diff --git a/libaurum/inc/ISearchable.h b/libaurum/inc/ISearchable.h index 06eafed..8695ee7 100644 --- a/libaurum/inc/ISearchable.h +++ b/libaurum/inc/ISearchable.h @@ -31,14 +31,14 @@ public: * @brief TBD * @since_tizen 5.5 */ - virtual std::unique_ptr findObject( + virtual std::shared_ptr findObject( const std::shared_ptr selector) const = 0; /** * @brief TBD * @since_tizen 5.5 */ - virtual std::vector> findObjects( + virtual std::vector> findObjects( const std::shared_ptr selector) const = 0; }; diff --git a/libaurum/inc/Impl/Accessibility/AtspiAccessibleApplication.h b/libaurum/inc/Impl/Accessibility/AtspiAccessibleApplication.h new file mode 100644 index 0000000..78208af --- /dev/null +++ b/libaurum/inc/Impl/Accessibility/AtspiAccessibleApplication.h @@ -0,0 +1,17 @@ +#pragma once +#include "AccessibleApplication.h" + +#include +#include + +class AtspiAccessibleApplication : public AccessibleApplication, public std::enable_shared_from_this { +public: + AtspiAccessibleApplication(std::shared_ptr node); + virtual ~AtspiAccessibleApplication(); + +public: + std::vector> getWindows(void) override; + //std::vector> 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 index 0000000..3121f8c --- /dev/null +++ b/libaurum/inc/Impl/Accessibility/AtspiAccessibleNode.h @@ -0,0 +1,95 @@ +#pragma once +#include "AccessibleNode.h" +#include + +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 getChildAt(int index) const override; + + /** + * @brief TBD + * @since_tizen 5.5 + */ + std::vector> getChildren() const override; + + /** + * @brief TBD + * @since_tizen 5.5 + */ + std::shared_ptr 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 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 mNodeMap; + + /** + * @brief TBD + * @since_tizen 5.5 + */ + AtspiAccessible* mNode; +}; \ No newline at end of file diff --git a/libaurum/inc/AccessibleWatcher.h b/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h similarity index 56% rename from libaurum/inc/AccessibleWatcher.h rename to libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h index 9ee7d22..93ded42 100644 --- a/libaurum/inc/AccessibleWatcher.h +++ b/libaurum/inc/Impl/Accessibility/AtspiAccessibleWatcher.h @@ -1,23 +1,17 @@ -#ifndef ACCESSIBLE_H -#define ACCESSIBLE_H +#pragma once +#include "AccessibleNode.h" +#include "AccessibleWatcher.h" #include -#include "AccessibleNode.h" -#include "AccessibleUtils.h" +#include -#include -#include +#include +#include #include +#include #include #include - - -#include -#include -#include -#include "config.h" - - +#include /** * @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(AtspiAccessible* node) = 0; /** * @brief TBD * @since_tizen 5.5 */ - virtual void onWindowCreated(AtspiAccessible *node) = 0; + virtual void onWindowCreated(AtspiAccessible* node) = 0; /** * @brief TBD * @since_tizen 5.5 */ - virtual void onWindowDestroyed(AtspiAccessible *node) = 0; + virtual void onWindowDestroyed(AtspiAccessible* node) = 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(AtspiAccessible* node) = 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 getApplicationAt(int index) const override; -public: /** * @brief TBD * @since_tizen 5.5 */ - std::unique_ptr getRootNode() const; + virtual std::vector> getApplications(void) const override; + /** * @brief TBD * @since_tizen 5.5 */ - std::vector> getTopNode() const; + //std::shared_ptr getRootNode() const override; + /** * @brief TBD * @since_tizen 5.5 */ + //std::vector> 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 mActivatedWindowList; + GDBusProxy * mDbusProxy; /** * @brief TBD */ - mutable std::list mActivatedApplicationList; + std::mutex mLock; /** * @brief TBD */ - mutable std::set mWindowSet;; + std::list mActivatedWindowList; /** * @brief TBD */ - GDBusProxy * mDbusProxy; + std::list mActivatedApplicationList; /** * @brief TBD */ - std::map mAccessibleNode; + std::set mWindowSet; - /** - * @brief TBD - */ - mutable std::mutex mLock; -}; + std::map 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 index 0000000..6883bf6 --- /dev/null +++ b/libaurum/inc/Impl/Accessibility/AtspiAccessibleWindow.h @@ -0,0 +1,9 @@ +#pragma once +#include "AccessibleWindow.h" + +class AtspiAccessibleWindow : public AccessibleWindow { +public: + AtspiAccessibleWindow(std::shared_ptr app, std::shared_ptr 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 index 0000000..dc4359e --- /dev/null +++ b/libaurum/inc/Impl/Accessibility/MockAccessibleApplication.h @@ -0,0 +1,23 @@ +#pragma once +#include "AccessibleApplication.h" + +#include + +class MockAccessibleApplication : public AccessibleApplication, public std::enable_shared_from_this { +public: + MockAccessibleApplication(std::shared_ptr node); + virtual ~MockAccessibleApplication(); + +public: + std::vector> getWindows(void) override; + //std::vector> getActiveWindows(void) override; + std::string getPackageName(void) override; + +public: + void addWindow(std::shared_ptr window); + void clearWindows(void); + +private: + std::vector> 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 index 0000000..98bbb44 --- /dev/null +++ b/libaurum/inc/Impl/Accessibility/MockAccessibleNode.h @@ -0,0 +1,103 @@ +#pragma once +#include "AccessibleNode.h" + +#include + +class MockAccessibleNode : public AccessibleNode { +public: + /** + * @brief TBD + * @since_tizen 5.5 + */ + MockAccessibleNode(std::shared_ptr parent, std::string text,std::string pkg,std::string role, std::string res,std::string type,std::string style,Rect 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 getChildAt(int index) const override; + + /** + * @brief TBD + * @since_tizen 5.5 + */ + std::vector> getChildren() const override; + + /** + * @brief TBD + * @since_tizen 5.5 + */ + std::shared_ptr 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 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 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 boundingBox, int supportingIfaces, int featureProperty); + +private: + + std::shared_ptr mParentNode; + std::vector> mChildrenList; + std::set mActionSet; + +}; + + diff --git a/libaurum/inc/Impl/Accessibility/MockAccessibleWatcher.h b/libaurum/inc/Impl/Accessibility/MockAccessibleWatcher.h new file mode 100644 index 0000000..e3476d2 --- /dev/null +++ b/libaurum/inc/Impl/Accessibility/MockAccessibleWatcher.h @@ -0,0 +1,50 @@ +#pragma once +#include "AccessibleNode.h" +#include "AccessibleWatcher.h" + +#include +#include +#include +#include +#include +#include +#include + + +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 getApplicationAt(int index) const override; + + + /** + * @brief TBD + * @since_tizen 5.5 + */ + virtual std::vector> getApplications(void) const override; + +public: + void addApplication(std::shared_ptr application); + +private: + std::vector> 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 index 0000000..e7ec0b5 --- /dev/null +++ b/libaurum/inc/Impl/Accessibility/MockAccessibleWindow.h @@ -0,0 +1,8 @@ +#pragma once +#include "AccessibleWindow.h" + +class MockAccessibleWindow : public AccessibleWindow { +public: + MockAccessibleWindow(std::shared_ptr app, std::shared_ptr 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 index 0000000..dd35e6f --- /dev/null +++ b/libaurum/inc/Impl/MockDeviceImpl.h @@ -0,0 +1,62 @@ +#pragma once +#include "config.h" +#include "IDevice.h" + +#include + +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 mTouchSeq; +}; \ No newline at end of file diff --git a/libaurum/inc/DeviceImpl/TizenImpl.h b/libaurum/inc/Impl/TizenDeviceImpl.h similarity index 94% rename from libaurum/inc/DeviceImpl/TizenImpl.h rename to libaurum/inc/Impl/TizenDeviceImpl.h index d9ea2ce..f275e91 100644 --- a/libaurum/inc/DeviceImpl/TizenImpl.h +++ b/libaurum/inc/Impl/TizenDeviceImpl.h @@ -9,13 +9,13 @@ #include #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 index 0000000..9bb304f --- /dev/null +++ b/libaurum/inc/Misc/Point2D.h @@ -0,0 +1,45 @@ +#pragma once + +/** + * @brief Point2d Class + * @since_tizen 5.5 + */ +template +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 index 0000000..62aa39e --- /dev/null +++ b/libaurum/inc/Misc/Rect.h @@ -0,0 +1,77 @@ +#pragma once +#include "Point2D.h" + +/** + * @brief Rect Class + * @since_tizen 5.5 + */ +template +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 &tl, const Point2D &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 &src) + + { + this->mTopLeft = Point2D{src.mTopLeft}; + this->mBottomRight = Point2D{src.mBottomRight}; + } + + /** + * @brief TBD + * @since_tizen 5.5 + */ + Point2D midPoint() const + { + return Point2D{mTopLeft.x + static_cast(width() / 2), + mTopLeft.y + static_cast(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 mTopLeft; + + /** + * @brief TBD + */ + Point2D mBottomRight; +}; diff --git a/libaurum/inc/PartialMatch.h b/libaurum/inc/PartialMatch.h index 987f8c9..b3165b2 100644 --- a/libaurum/inc/PartialMatch.h +++ b/libaurum/inc/PartialMatch.h @@ -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 node, int index, int depth, std::list> &partialMatches); /** @@ -47,7 +47,7 @@ public: void debugPrint(); public: - static std::shared_ptr accept(const AccessibleNode *node, + static std::shared_ptr accept(const std::shared_ptr node, const std::shared_ptr selector, int index, int depth); @@ -55,7 +55,7 @@ public: * @brief TBD * @since_tizen 5.5 */ - static std::shared_ptr accept(const AccessibleNode *node, + static std::shared_ptr accept(const std::shared_ptr node, const std::shared_ptr selector, int index, int absoluteDepth, int relativeDepth); @@ -66,7 +66,7 @@ public: */ private: static bool checkCriteria(const std::shared_ptr selector, - const AccessibleNode *node); + const std::shared_ptr node); /** * @brief TBD diff --git a/libaurum/inc/UiDevice.h b/libaurum/inc/UiDevice.h index 9ed7e1f..64f75f9 100644 --- a/libaurum/inc/UiDevice.h +++ b/libaurum/inc/UiDevice.h @@ -13,14 +13,7 @@ #include #include -/** - * @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 findObject( + std::shared_ptr findObject( const std::shared_ptr selector) const override; /** * @brief TBD * @since_tizen 5.5 */ - std::vector> findObjects( + std::vector> findObjects( const std::shared_ptr selector) const override; /** @@ -163,29 +156,28 @@ public: * @brief TBD * @since_tizen 5.5 */ - std::unique_ptr waitFor( - const std::function(const ISearchable *)> + std::shared_ptr waitFor( + const std::function(const ISearchable *)> condition) const; - public: /** * @brief TBD * @since_tizen 5.5 */ - static UiDevice *getInstance(DeviceType type); + static std::shared_ptr getInstance(IDevice *deviceImpl = nullptr); -private: /** * @brief TBD * @since_tizen 5.5 */ - std::vector> getWindowRoot() const; - + std::vector> 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 diff --git a/libaurum/inc/UiObject.h b/libaurum/inc/UiObject.h index b56470e..6735242 100644 --- a/libaurum/inc/UiObject.h +++ b/libaurum/inc/UiObject.h @@ -21,15 +21,15 @@ public: * @brief TBD * @since_tizen 5.5 */ - UiObject(const UiDevice *device, const std::shared_ptr selector, + UiObject(const std::shared_ptr device, const std::shared_ptr selector, const AccessibleNode *node); /** * @brief TBD * @since_tizen 5.5 */ - UiObject(const UiDevice *device, const std::shared_ptr selector, - std::unique_ptr node); + UiObject(const std::shared_ptr device, const std::shared_ptr selector, + std::shared_ptr node); // UiObject(const UiObject &src); // copy constroctur /** @@ -66,14 +66,14 @@ public: * @brief TBD * @since_tizen 5.5 */ - std::unique_ptr findObject( + std::shared_ptr findObject( const std::shared_ptr selector) const override; /** * @brief TBD * @since_tizen 5.5 */ - std::vector> findObjects( + std::vector> findObjects( const std::shared_ptr selector) const override; /** @@ -87,8 +87,8 @@ public: * @brief TBD * @since_tizen 5.5 */ - std::unique_ptr waitFor( - const std::function(const ISearchable *)> + std::shared_ptr waitFor( + const std::function(const ISearchable *)> condition) const; /** @@ -114,25 +114,31 @@ public: * @brief TBD * @since_tizen 5.5 */ - std::vector> getChildren() const; + std::vector> 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 getAccessibleNode() const; private: /** * @brief TBD */ - const UiDevice * mDevice; + std::shared_ptr mDevice; /** * @brief TBD @@ -275,13 +286,12 @@ private: /** * @brief TBD */ - std::unique_ptr mNode; + std::shared_ptr mNode; /** * @brief TBD */ const Waiter * mWaiter; - //std::unique_ptr mNode_src; /** * @brief TBD diff --git a/libaurum/inc/UiScrollable.h b/libaurum/inc/UiScrollable.h new file mode 100644 index 0000000..ecabb2f --- /dev/null +++ b/libaurum/inc/UiScrollable.h @@ -0,0 +1,78 @@ +#pragma once +#include "UiObject.h" +#include +/** + * @brief UiScrollable class + * @since_tizen 5.5 + */ +class UiScrollable : public UiObject +{ +public: + /** + * @brief TBD + * @since_tizen 5.5 + */ + UiScrollable(std::shared_ptr 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 mSelector; + + /** + * @brief TBD + */ + int mMaxSearchSwipe; + + /** + * @brief TBD + */ + int mScrollStep; +}; \ No newline at end of file diff --git a/libaurum/inc/UiSelector.h b/libaurum/inc/UiSelector.h index 4a52580..81d5719 100644 --- a/libaurum/inc/UiSelector.h +++ b/libaurum/inc/UiSelector.h @@ -271,12 +271,6 @@ public: * @brief TBD * @since_tizen 5.5 */ - std::unique_ptr mDesc; - - /** - * @brief TBD - * @since_tizen 5.5 - */ std::vector> mChild; }; diff --git a/libaurum/inc/Until.h b/libaurum/inc/Until.h index 4ad2be3..a4baafe 100644 --- a/libaurum/inc/Until.h +++ b/libaurum/inc/Until.h @@ -53,7 +53,7 @@ public: * @brief TBD * @since_tizen 5.5 */ - static std::function(const ISearchable *)> + static std::function(const ISearchable *)> findObject(const std::shared_ptr selector); /** diff --git a/libaurum/meson.build b/libaurum/meson.build index c2e2eb8..78bdc12 100644 --- a/libaurum/meson.build +++ b/libaurum/meson.build @@ -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 index 0000000..cd0e1de --- /dev/null +++ b/libaurum/src/Accessibility/AccessibleApplication.cc @@ -0,0 +1,38 @@ +#include "AccessibleApplication.h" +#include "AccessibleWatcher.h" + +#include +#include + +AccessibleApplication::AccessibleApplication(std::shared_ptr node) +: mNode{node} +{ +} + +AccessibleApplication::~AccessibleApplication() +{ +} + +std::shared_ptr AccessibleApplication::getAccessibleNode() +{ + return mNode; +} + +bool AccessibleApplication::isActive(void) +{ + auto children = this->getActiveWindows(); + return children.size() > 0; +} + +std::vector> 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 index 0000000..14de23f --- /dev/null +++ b/libaurum/src/Accessibility/AccessibleNode.cc @@ -0,0 +1,156 @@ +#include "AccessibleNode.h" +#include +#include +#include + +#include +#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(thisIface)) != 0; +} + +bool AccessibleNode::hasFeatureProperty(NodeFeatureProperties prop) const +{ + return (mFeatureProperty & static_cast(prop)) != 0; +} + +void AccessibleNode::setFeatureProperty(NodeFeatureProperties prop, bool has) +{ + if (has) + mFeatureProperty |= static_cast(prop); + else + mFeatureProperty &= ~static_cast(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 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/AccessibleUtils.cc b/libaurum/src/Accessibility/AccessibleUtils.cc similarity index 100% rename from libaurum/src/AccessibleUtils.cc rename to libaurum/src/Accessibility/AccessibleUtils.cc diff --git a/libaurum/src/Accessibility/AccessibleWatcher.cc b/libaurum/src/Accessibility/AccessibleWatcher.cc new file mode 100644 index 0000000..25fb94e --- /dev/null +++ b/libaurum/src/Accessibility/AccessibleWatcher.cc @@ -0,0 +1,75 @@ + +#include "AccessibleWatcher.h" + +#ifdef TIZEN +#include "AtspiAccessibleWatcher.h" +#endif + +#include "MockAccessibleWatcher.h" + +#include +#include +#include +#include +#include + + + +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> AccessibleWatcher::getActiveApplications(void) const +{ + LOG_SCOPE_F(INFO, "getActiveApplications for this(%p)", this); + + std::vector> 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 index 0000000..8de9d5a --- /dev/null +++ b/libaurum/src/Accessibility/AccessibleWindow.cc @@ -0,0 +1,36 @@ +#include "AccessibleWindow.h" +#include "AccessibleWatcher.h" + +AccessibleWindow::AccessibleWindow(std::shared_ptr app, std::shared_ptr 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 AccessibleWindow::getApplication(void) +{ + return mApp; +} + +std::shared_ptr 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 index 0000000..9eb7868 --- /dev/null +++ b/libaurum/src/Accessibility/meson.build @@ -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 index 8a00fe2..0000000 --- a/libaurum/src/AccessibleWatcher.cc +++ /dev/null @@ -1,326 +0,0 @@ - -#include "AccessibleWatcher.h" - -#include -#include -#include - -#include - -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 -findActiveNode(AtspiAccessible *node, int depth, - int max_depth) -{ - std::vector 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 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 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> AccessibleWatcher::getTopNode() const -{ - AtspiAccessible *topNode = nullptr, *activeNode = nullptr; - std::vector> ret; - - { - std::unique_lock lock(mLock); - if (!mActivatedWindowList.empty()) { - topNode = mActivatedWindowList.front(); - std::list::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 activeNodes = findActiveNode(rootNode.get(), 0, 2); - if (!activeNodes.empty()) { - std::vector::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(event->source), - static_cast(event->detail1)); - } else if (!strcmp(event->type, "window:deactivate")) { - instance->onWindowDeactivated(static_cast(event->source)); - } else if (!strcmp(event->type, "window:create")) { - instance->onWindowCreated(static_cast(event->source)); - } else if (!strcmp(event->type, "window:destroy")) { - instance->onWindowDestroyed(static_cast(event->source)); - } else if (!strcmp(event->type, "object:state-changed:visible")) { - instance->onVisibilityChanged( - static_cast(event->source), - (event->detail1 != 0)); - } else if (!strcmp(event->type, "object:state-changed:defunct")) { - instance->onObjectDefunct( - static_cast(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 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 lock(mLock); - addToActivatedList(node); - return; -} - -void AccessibleWatcher::onWindowDeactivated(AtspiAccessible *node) -{ - std::unique_lock lock(mLock); - removeFromActivatedList(node); - return; -} - -void AccessibleWatcher::onWindowCreated(AtspiAccessible *node) -{ - std::unique_lock lock(mLock); - addToWindowSet(node); -} - -void AccessibleWatcher::onWindowDestroyed(AtspiAccessible *node) -{ - std::unique_lock lock(mLock); - removeFromWindowSet(node); -} - -void AccessibleWatcher::onVisibilityChanged(AtspiAccessible *node, bool visible) -{ -} - -void AccessibleWatcher::onObjectDefunct(AtspiAccessible *node) -{ - LOG_SCOPE_F(INFO, "object defuncted %p", node); -} diff --git a/libaurum/src/Comparer.cc b/libaurum/src/Comparer.cc index e9cdc11..1b74334 100644 --- a/libaurum/src/Comparer.cc +++ b/libaurum/src/Comparer.cc @@ -2,7 +2,7 @@ #include -Comparer::Comparer(const UiDevice *device, const std::shared_ptr selector, +Comparer::Comparer(const std::shared_ptr device, const std::shared_ptr selector, const bool &earlyReturn) : mDevice(device), mSelector(selector), mEarlyReturn(earlyReturn) { @@ -10,60 +10,69 @@ Comparer::Comparer(const UiDevice *device, const std::shared_ptr sel Comparer::~Comparer() {} -std::unique_ptr Comparer::findObject(const UiDevice * device, +std::shared_ptr Comparer::findObject(const std::shared_ptr device, const std::shared_ptr selector, - const AccessibleNode *root) + const std::shared_ptr root) { Comparer comparer(device, selector, true); - std::vector> ret = comparer.findObjects(root); + std::vector> ret = comparer.findObjects(root); if (ret.size() > 0) return std::move(ret[0]); else return nullptr; } -std::vector> Comparer::findObjects(const UiDevice * device, +std::vector> Comparer::findObjects(const std::shared_ptr device, const std::shared_ptr selector, - const AccessibleNode *root) + const std::shared_ptr root) { Comparer comparer(device, selector, false); - std::vector> ret = comparer.findObjects(root); + std::vector> ret = comparer.findObjects(root); return ret; } -std::vector> Comparer::findObjects(const AccessibleNode *root) +std::vector> Comparer::findObjects(const std::shared_ptr root) { std::list> partialList{}; - std::vector> ret = findObjects(root, 0, 0, partialList); + std::vector> ret = findObjects(root, 0, 0, partialList); return ret; } -std::vector> Comparer::findObjects( - const AccessibleNode *root, const int &index, const int &depth, +std::vector> Comparer::findObjects( + const std::shared_ptr root, const int &index, const int &depth, std::list> &partialMatches) { - std::vector> ret; + std::vector> 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 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 childNode = root->getChildAt(i); - std::vector> 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 childNode = root->getChildAt(i); + if (childNode == nullptr) continue; - if (!ret.empty() && mEarlyReturn) return ret; + std::vector> 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 index 0000000..4c828c7 --- /dev/null +++ b/libaurum/src/Impl/Accessibility/AtspiAccessibleApplication.cc @@ -0,0 +1,34 @@ +#include "AtspiAccessibleApplication.h" +#include "AtspiAccessibleWindow.h" +#include +#include + +#include + +AtspiAccessibleApplication::AtspiAccessibleApplication(std::shared_ptr node) +: AccessibleApplication(node) +{ +} + +AtspiAccessibleApplication::~AtspiAccessibleApplication() +{ +} + +std::vector> AtspiAccessibleApplication::getWindows(void) +{ + std::vector> ret{}; + auto children = getAccessibleNode()->getChildren(); + + std::transform(children.begin(), children.end(), std::back_inserter(ret), + [&](auto child) { + return std::make_shared(this->shared_from_this(), child); + } + ); + + return ret; +} + +std::string AtspiAccessibleApplication::getPackageName(void) +{ + return getAccessibleNode()->getText(); +} \ No newline at end of file diff --git a/libaurum/src/AccessibleNode.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc similarity index 59% rename from libaurum/src/AccessibleNode.cc rename to libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc index dd07b01..a497533 100644 --- a/libaurum/src/AccessibleNode.cc +++ b/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc @@ -1,32 +1,15 @@ -#include "AccessibleNode.h" -#include -#include -#include +#include "AtspiAccessibleNode.h" -#include -#include "config.h" - -std::map AccessibleNode::mNodeMap{}; - -AccessibleNode::~AccessibleNode() -{ +#include -} +#include -AccessibleNode::AccessibleNode() : AccessibleNode(nullptr) -{ - // No meaning without AtspiAccessbile object - // prohibited to create this object with this constructor -} +//std::map 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::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 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(rawChild); +} + +std::vector> AtspiAccessibleNode::getChildren() const { - return std::make_unique(node); + std::vector> 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 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(rawParent); +/* auto node = AccessibleNode::get(parent); + if (parent) g_object_unref(parent); + return node; */ +} + + +void* AtspiAccessibleNode::getRawHandler(void) const +{ + return static_cast(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::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{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::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 AtspiAccessibleNode::getActions() const { - if (m <= 0 || d > m) return; + std::vector 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(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(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(prop); - else - mFeatureProperty &= ~static_cast(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 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{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 AccessibleNode::getActions() const -{ - std::vector 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 index 0000000..f82ae7a --- /dev/null +++ b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc @@ -0,0 +1,406 @@ +#include "AtspiAccessibleWatcher.h" + +#include "AtspiAccessibleApplication.h" +#include "AtspiAccessibleWindow.h" +#include "AtspiAccessibleNode.h" + +#include + +#include + +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 +findActiveNode(AtspiAccessible *node, int depth, + int max_depth) +{ + LOG_SCOPE_F(INFO, "findActiveNode %p %d/%d", node, depth, max_depth); + + std::vector 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 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(event->source), + static_cast(event->detail1)); + } else if (!strcmp(event->type, "window:deactivate")) { + instance->onWindowDeactivated(static_cast(event->source)); + } else if (!strcmp(event->type, "window:create")) { + instance->onWindowCreated(static_cast(event->source)); + } else if (!strcmp(event->type, "window:destroy")) { + instance->onWindowDestroyed(static_cast(event->source)); + } else if (!strcmp(event->type, "object:state-changed:visible")) { + instance->onVisibilityChanged( + static_cast(event->source), + (event->detail1 != 0)); + } else if (!strcmp(event->type, "object:state-changed:defunct")) { + instance->onObjectDefunct( + static_cast(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 lock(mLock); + LOG_SCOPE_F(INFO, "onWindowActivated obj:%p", node); + //addToActivatedList((node)); + return; +} + +void AtspiAccessibleWatcher::onWindowDeactivated(AtspiAccessible *node) +{ + std::unique_lock lock(mLock); + LOG_SCOPE_F(INFO, "onWindowDeactivated obj:%p", node); + //removeFromActivatedList(node); +} + +void AtspiAccessibleWatcher::onWindowCreated(AtspiAccessible *node) +{ + std::unique_lock lock(mLock); + LOG_SCOPE_F(INFO, "onWindowCreated obj:%p", node); + //addToWindowSet(node); +} + +void AtspiAccessibleWatcher::onWindowDestroyed(AtspiAccessible *node) +{ + std::unique_lock lock(mLock); + LOG_SCOPE_F(INFO, "onWindowDestroyed obj:%p vis:%d", node); + //removeFromWindowSet(node); +} + +void AtspiAccessibleWatcher::onVisibilityChanged(AtspiAccessible *node, bool visible) +{ + std::unique_lock lock(mLock); + LOG_SCOPE_F(INFO, "onVisibilityChanged obj:%p vis:%d", node, visible); +} + +void AtspiAccessibleWatcher::onObjectDefunct(AtspiAccessible *node) +{ + std::unique_lock 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 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(std::make_shared(child)); +} + +std::vector> AtspiAccessibleWatcher::getApplications(void) const +{ + LOG_SCOPE_F(INFO, "getApplications for this(%p)", this); + std::vector> 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(std::make_shared(child))); + } + } + g_object_unref(root); + return ret; +} + +/* +std::shared_ptr AtspiAccessibleWatcher::getRootNode() const +{ + auto node = atspi_get_desktop(0); + auto aNode = std::make_shared(node); + return accNode; +} + +std::vector> AtspiAccessibleWatcher::getTopNode() const +{ + AtspiAccessible *topNode = nullptr, *activeNode = nullptr; + std::vector> ret; + + { + std::unique_lock lock(mLock); + if (!mActivatedWindowList.empty()) { + topNode = mActivatedWindowList.front(); + std::list::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 activeNodes = findActiveNode(rootNode.get(), 0, 2); + if (!activeNodes.empty()) { + std::set 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 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 index 0000000..d563df8 --- /dev/null +++ b/libaurum/src/Impl/Accessibility/AtspiAccessibleWindow.cc @@ -0,0 +1,13 @@ +#include "AtspiAccessibleWindow.h" + + +AtspiAccessibleWindow::AtspiAccessibleWindow(std::shared_ptr app, std::shared_ptr 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 index 0000000..a4326dc --- /dev/null +++ b/libaurum/src/Impl/Accessibility/MockAccessibleApplication.cc @@ -0,0 +1,65 @@ +#include "MockAccessibleApplication.h" +#include "MockAccessibleWindow.h" +#include "MockAccessibleNode.h" + +#include + +#include + +MockAccessibleApplication::MockAccessibleApplication(std::shared_ptr 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> MockAccessibleApplication::getWindows(void) +{ + printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__); + return mWindowList; +} +/* +std::vector> MockAccessibleApplication::getActiveWindows(void) +{ + printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__); + + std::vector> 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 child) { + // return std::make_shared(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 window) +{ + mWindowList.push_back(window); + // auto node = getAccessibleNode(); + // auto node2 = dynamic_cast>(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 index 0000000..0ce2788 --- /dev/null +++ b/libaurum/src/Impl/Accessibility/MockAccessibleNode.cc @@ -0,0 +1,149 @@ +#include "MockAccessibleNode.h" + +#include + +MockAccessibleNode::MockAccessibleNode(std::shared_ptr parent, std::string text, std::string pkg, std::string role, std::string res, std::string type, std::string style, Rect 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 MockAccessibleNode::getChildAt(int index) const +{ + printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__); + return mChildrenList.at(index); +} +std::vector> MockAccessibleNode::getChildren() const +{ + printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__); + return mChildrenList; +} + +std::shared_ptr 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 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 MockAccessibleNode::getActions() const +{ + printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__); + std::vector 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 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 index 0000000..6c4b9e0 --- /dev/null +++ b/libaurum/src/Impl/Accessibility/MockAccessibleWatcher.cc @@ -0,0 +1,68 @@ +#include "MockAccessibleWatcher.h" +#include "MockAccessibleWindow.h" +#include "MockAccessibleNode.h" + +#include + +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 MockAccessibleWatcher::getApplicationAt(int index) const +{ + printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__); + return mApplicationList.at(index); +} + +std::vector> MockAccessibleWatcher::getApplications(void) const +{ + printf("%s:%d / %s\n",__FILE__, __LINE__, __PRETTY_FUNCTION__); + return mApplicationList; +} + +void MockAccessibleWatcher::addApplication(std::shared_ptr 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 index 0000000..23ea498 --- /dev/null +++ b/libaurum/src/Impl/Accessibility/MockAccessibleWindow.cc @@ -0,0 +1,12 @@ +#include "MockAccessibleWindow.h" + +MockAccessibleWindow::MockAccessibleWindow(std::shared_ptr app, std::shared_ptr 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 index 0000000..5226d60 --- /dev/null +++ b/libaurum/src/Impl/Accessibility/meson.build @@ -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 index 0000000..cf56af2 --- /dev/null +++ b/libaurum/src/Impl/MockDeviceImpl.cc @@ -0,0 +1,182 @@ +#include "MockDeviceImpl.h" +#include + +#include +#include +#include +#include + +#include +#include + +#include + +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 diff --git a/libaurum/src/DeviceImpl/TizenImpl.cc b/libaurum/src/Impl/TizenDeviceImpl.cc similarity index 79% rename from libaurum/src/DeviceImpl/TizenImpl.cc rename to libaurum/src/Impl/TizenDeviceImpl.cc index 7e469d7..a6d9006 100644 --- a/libaurum/src/DeviceImpl/TizenImpl.cc +++ b/libaurum/src/Impl/TizenDeviceImpl.cc @@ -1,4 +1,4 @@ -#include "DeviceImpl/TizenImpl.h" +#include "TizenDeviceImpl.h" #include #include @@ -14,12 +14,12 @@ #include #include -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(data); + TizenDeviceImpl *obj = static_cast(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(data); + TizenDeviceImpl *obj = static_cast(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*>(data); + std::tie(obj, x, y, seq) = *static_cast*>(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*>(data); + std::tie(obj, x, y, seq) = *static_cast*>(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*>(data); + std::tie(obj, x, y, seq) = *static_cast*>(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*>(data); + TizenDeviceImpl *obj; + std::tie(obj) = *static_cast*>(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*>(data); + TizenDeviceImpl *obj; + std::tie(obj) = *static_cast*>(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*>(data); + std::tie(obj, keycode) = *static_cast*>(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*>(data); + std::tie(obj, keycode) = *static_cast*>(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; 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 index 0000000..04bdacc --- /dev/null +++ b/libaurum/src/Impl/meson.build @@ -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 diff --git a/libaurum/src/PartialMatch.cc b/libaurum/src/PartialMatch.cc index 3bac438..5edc6f2 100644 --- a/libaurum/src/PartialMatch.cc +++ b/libaurum/src/PartialMatch.cc @@ -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 selector, - const AccessibleNode *node) + const std::shared_ptr 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 selector, const int { } -std::shared_ptr PartialMatch::accept(const AccessibleNode *node, +std::shared_ptr PartialMatch::accept(const std::shared_ptr node, const std::shared_ptr selector, int index, int depth) { return PartialMatch::accept(node, selector, index, depth, depth); } -std::shared_ptr PartialMatch::accept(const AccessibleNode *node, +std::shared_ptr PartialMatch::accept(const std::shared_ptr node, const std::shared_ptr 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(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::accept(const AccessibleNode *node, } void PartialMatch::update( - const AccessibleNode *node, int index, int depth, + const std::shared_ptr node, int index, int depth, std::list> &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> 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; diff --git a/libaurum/src/UiDevice.cc b/libaurum/src/UiDevice.cc index a3c55b6..f694f28 100644 --- a/libaurum/src/UiDevice.cc +++ b/libaurum/src/UiDevice.cc @@ -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 #include #include #include #include +#include +#include -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::getInstance(IDevice *deviceImpl) { - static UiDevice *device = nullptr; + static std::shared_ptr 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> UiDevice::getWindowRoot() const +std::vector> UiDevice::getWindowRoot() const { - return AccessibleWatcher::getInstance()->getTopNode(); + std::vector> 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 window){ + return window->getNode(); + } + ); + } + return ret; } bool UiDevice::hasObject(const std::shared_ptr selector) const { - auto root = getWindowRoot(); - for (auto it = root.begin(); it != root.end(); ++it) { - std::unique_ptr node = - Comparer::findObject(this, selector, (*it).get()); - if (node != nullptr) return true; + auto rootNodes = getWindowRoot(); + for (const auto &node : rootNodes) { + const std::shared_ptr foundNode = + Comparer::findObject(getInstance(), selector, node); + if (foundNode) return true; } return false; } -std::unique_ptr UiDevice::findObject(const std::shared_ptr selector) const +std::shared_ptr UiDevice::findObject(const std::shared_ptr selector) const { - auto root = getWindowRoot(); - for (auto it = root.begin(); it != root.end(); ++it) { - std::unique_ptr node = - Comparer::findObject(this, selector, (*it).get()); - if (node) - return std::make_unique(this, selector, std::move(node)); + auto rootNodes = getWindowRoot(); + for (const auto &node : rootNodes) { + const std::shared_ptr foundNode = + Comparer::findObject(getInstance(), selector, node); + if (foundNode) + return std::make_shared(getInstance(), selector, foundNode); } - return std::unique_ptr{nullptr}; + return std::shared_ptr{nullptr}; } -std::vector> UiDevice::findObjects( + +std::vector> UiDevice::findObjects( const std::shared_ptr selector) const { - std::vector> ret{}; - auto root = getWindowRoot(); - for (auto it = root.begin(); it != root.end(); ++it) { - std::vector> nodes = - Comparer::findObjects(this, selector, (*it).get()); - + std::vector> ret{}; + auto rootNodes = getWindowRoot(); + for (const auto &window : rootNodes) { + std::vector> nodes = + Comparer::findObjects(getInstance(), selector, window); for (auto &node : nodes) - ret.push_back(std::make_unique(this, selector, std::move(node))); + ret.push_back(std::make_shared(getInstance(), selector, node)); } return ret; } @@ -80,8 +108,8 @@ bool UiDevice::waitFor( return mWaiter->waitFor(condition); } -std::unique_ptr UiDevice::waitFor( - const std::function(const ISearchable *)> +std::shared_ptr UiDevice::waitFor( + const std::function(const ISearchable *)> condition) const { return mWaiter->waitFor(condition); diff --git a/libaurum/src/UiObject.cc b/libaurum/src/UiObject.cc index 12502cb..2a4cb76 100644 --- a/libaurum/src/UiObject.cc +++ b/libaurum/src/UiObject.cc @@ -7,6 +7,8 @@ #include +#include +#include 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 selector, +UiObject::UiObject(const std::shared_ptr device, const std::shared_ptr selector, const AccessibleNode *node) : mDevice(device), mSelector(selector), - mNode(std::unique_ptr(const_cast(node))), + mNode(std::shared_ptr(const_cast(node))), mWaiter(new Waiter{this, this}) { } -UiObject::UiObject(const UiDevice *device, const std::shared_ptr selector, - std::unique_ptr node) +UiObject::UiObject(const std::shared_ptr device, const std::shared_ptr selector, + std::shared_ptr node) : mDevice(device), mSelector(selector), mNode(std::move(node)), @@ -61,7 +63,7 @@ std::shared_ptr UiObject::getSelector() bool UiObject::hasObject(const std::shared_ptr selector) const { - std::unique_ptr node = + std::shared_ptr 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 selector) const return false; } -std::unique_ptr UiObject::findObject(const std::shared_ptr selector) const +std::shared_ptr UiObject::findObject(const std::shared_ptr selector) const { - std::unique_ptr node = + std::shared_ptr node = Comparer::findObject(mDevice, selector, getAccessibleNode()); if (node) - return std::make_unique(mDevice, selector, std::move(node)); + return std::make_shared(mDevice, selector, std::move(node)); else - return std::unique_ptr{nullptr}; + return std::shared_ptr{nullptr}; } -std::vector> UiObject::findObjects( +std::vector> UiObject::findObjects( const std::shared_ptr selector) const { - return std::vector>{}; + LOG_SCOPE_F(INFO, "findObjects"); + std::vector> 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(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::waitFor( - const std::function(const ISearchable *)> +std::shared_ptr UiObject::waitFor( + const std::function(const ISearchable *)> condition) const { return mWaiter->waitFor(condition); @@ -102,13 +115,12 @@ std::unique_ptr UiObject::waitFor( bool UiObject::waitFor( const std::function condition) const { - LOG_F(INFO, "asdf"); return mWaiter->waitFor(condition); } UiObject *UiObject::getParent() const { - std::unique_ptr node = getAccessibleNode()->getParent(); + std::shared_ptr 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> UiObject::getChildren() const -{ - return findObjects(Sel::depth(1)); -} - -std::string UiObject::getContentDescription() const +std::vector> UiObject::getChildren() const { - return getAccessibleNode()->getDesc(); + auto sel = std::make_shared(); + 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 rect = mNode->getBoundingBox(); - std::cout << rect.mTopLeft.x << ", " << rect.mTopLeft.y << std::endl; const Point2D midPoint = rect.midPoint(); - const_cast(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 rect = mNode->getBoundingBox(); - std::cout << rect.mTopLeft.x << ", " << rect.mTopLeft.y << std::endl; const Point2D midPoint = rect.midPoint(); - const_cast(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 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 index 0000000..a051210 --- /dev/null +++ b/libaurum/src/UiScrollable.cc @@ -0,0 +1,62 @@ +#include "UiScrollable.h" + +UiScrollable::UiScrollable(std::shared_ptr 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 diff --git a/libaurum/src/UiSelector.cc b/libaurum/src/UiSelector.cc index 1ee665c..886c729 100644 --- a/libaurum/src/UiSelector.cc +++ b/libaurum/src/UiSelector.cc @@ -24,12 +24,6 @@ UiSelector *UiSelector::id(std::string text) return this; } -UiSelector *UiSelector::desc(std::string text) -{ - this->mDesc = std::make_unique(text); - return this; -} - UiSelector *UiSelector::text(std::string text) { this->mText = std::make_unique(text); diff --git a/libaurum/src/Until.cc b/libaurum/src/Until.cc index bd9385f..9ca27e1 100644 --- a/libaurum/src/Until.cc +++ b/libaurum/src/Until.cc @@ -8,17 +8,17 @@ std::function Until::hasObject( { return [=](const ISearchable *searchable) -> bool { LOG_SCOPE_F(INFO, "sel:%p, search:%p", selector, searchable); - std::unique_ptr obj = searchable->findObject(selector); + std::shared_ptr obj = searchable->findObject(selector); return obj.get() != nullptr; }; } -std::function(const ISearchable *)> Until::findObject( +std::function(const ISearchable *)> Until::findObject( const std::shared_ptr selector) { - return [=](const ISearchable *searchable) -> std::unique_ptr { + return [=](const ISearchable *searchable) -> std::shared_ptr { LOG_SCOPE_F(INFO, "sel:%p, search:%p", selector, searchable); - std::unique_ptr obj = searchable->findObject(selector); + std::shared_ptr obj = searchable->findObject(selector); return obj; }; } diff --git a/libaurum/src/Waiter.cc b/libaurum/src/Waiter.cc index f353625..5e419b5 100644 --- a/libaurum/src/Waiter.cc +++ b/libaurum/src/Waiter.cc @@ -22,8 +22,8 @@ Waiter::Waiter(const ISearchable *searchableObject, const UiObject *uiObject) template bool Waiter::waitFor( const std::function condition) const; -template std::unique_ptr Waiter::waitFor( - const std::function(const ISearchable *)> +template std::shared_ptr Waiter::waitFor( + const std::function(const ISearchable *)> condition) const; template bool Waiter::waitFor( diff --git a/libaurum/src/meson.build b/libaurum/src/meson.build new file mode 100644 index 0000000..be6ee85 --- /dev/null +++ b/libaurum/src/meson.build @@ -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 diff --git a/org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h b/org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h index a44efe6..103441e 100644 --- a/org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h +++ b/org.tizen.aurum-bootstrap/inc/AurumServiceImpl.h @@ -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 diff --git a/org.tizen.aurum-bootstrap/inc/Commands/ClearCommand.h b/org.tizen.aurum-bootstrap/inc/Commands/ClearCommand.h index dd6b9f4..9f02ec0 100644 --- a/org.tizen.aurum-bootstrap/inc/Commands/ClearCommand.h +++ b/org.tizen.aurum-bootstrap/inc/Commands/ClearCommand.h @@ -18,7 +18,7 @@ public: ::grpc::Status execute() override; protected: - bool hasHintText(UiObject *obj); + bool hasHintText(std::shared_ptr obj); }; #endif \ No newline at end of file diff --git a/org.tizen.aurum-bootstrap/inc/Commands/FindElementCommand.h b/org.tizen.aurum-bootstrap/inc/Commands/FindElementCommand.h index 688d87c..3defda7 100644 --- a/org.tizen.aurum-bootstrap/inc/Commands/FindElementCommand.h +++ b/org.tizen.aurum-bootstrap/inc/Commands/FindElementCommand.h @@ -21,7 +21,7 @@ public: ::aurum::RspFindElement* response); ::grpc::Status execute() override; protected: - virtual ISearchable* getSearchableTop(void); + virtual std::shared_ptr getSearchableTop(void); virtual std::vector> getSelectors(void); }; #endif \ No newline at end of file diff --git a/org.tizen.aurum-bootstrap/inc/ObjectMapper.h b/org.tizen.aurum-bootstrap/inc/ObjectMapper.h index b1f127f..3e9dc50 100644 --- a/org.tizen.aurum-bootstrap/inc/ObjectMapper.h +++ b/org.tizen.aurum-bootstrap/inc/ObjectMapper.h @@ -8,7 +8,8 @@ class ObjectMapper { private: - std::map> mObjectMap; + std::map> mObjectMap; + std::map, std::string> mObjectMapReverse; unsigned long long mObjCounter; private: @@ -19,8 +20,13 @@ public: public: static ObjectMapper *getInstance(); - std::string addElement(std::unique_ptr object); - UiObject * getElement(const std::string &key); + std::string addElement(std::shared_ptr object); + + std::shared_ptr getElement(const std::string key); + std::string getElement(std::shared_ptr object); + + bool removeElement(const std::string key); + bool removeElement(std::shared_ptr object); }; #endif \ No newline at end of file diff --git a/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc b/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc index 74c3727..4d177ea 100644 --- a/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc +++ b/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc @@ -181,11 +181,10 @@ aurumServiceImpl::~aurumServiceImpl() {} std::unique_ptr cmd = std::make_unique(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 cmd = std::make_unique(request, writer); return execute(cmd.get()); -} +} \ No newline at end of file diff --git a/org.tizen.aurum-bootstrap/src/Commands/ClearCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/ClearCommand.cc index 5c24358..352c537 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/ClearCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/ClearCommand.cc @@ -9,7 +9,7 @@ ClearCommand::ClearCommand(const ::aurum::ReqClear* request, { } -bool ClearCommand::hasHintText(UiObject *obj) +bool ClearCommand::hasHintText(std::shared_ptr 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 obj = mObjMap->getElement(mRequest->elementid()); if (obj) { obj->setText(""); diff --git a/org.tizen.aurum-bootstrap/src/Commands/ClickCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/ClickCommand.cc index 2b152e1..8340168 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/ClickCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/ClickCommand.cc @@ -33,7 +33,7 @@ std::unique_ptr ClickCommand::createCommand(const ::aurum::ReqClic ::grpc::Status ClickElementCommand::execute() { ObjectMapper* mObjMap = ObjectMapper::getInstance(); - UiObject* obj = mObjMap->getElement(mRequest->elementid()); + std::shared_ptr obj = mObjMap->getElement(mRequest->elementid()); LOG_SCOPE_F(INFO, "ClickElementCommand execute %p", obj); if (obj) { @@ -47,9 +47,9 @@ std::unique_ptr ClickCommand::createCommand(const ::aurum::ReqClic ::grpc::Status ClickCoordCommand::execute() { - UiDevice* obj = UiDevice::getInstance(DeviceType::DEFAULT); + std::shared_ptr 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::createCommand(const ::aurum::ReqClic ::grpc::Status ClickAtspiCommand::execute() { ObjectMapper* mObjMap = ObjectMapper::getInstance(); - UiObject* obj = mObjMap->getElement(mRequest->elementid()); + std::shared_ptr obj = mObjMap->getElement(mRequest->elementid()); LOG_SCOPE_F(INFO, "ClickAtspiCommand execute %p", obj); diff --git a/org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc index 8e8d106..c7935e8 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc @@ -15,13 +15,14 @@ FindElementCommand::FindElementCommand(const ::aurum::ReqFindElement* request, { mObjMap = ObjectMapper::getInstance(); } -ISearchable* FindElementCommand::getSearchableTop(void) +std::shared_ptr FindElementCommand::getSearchableTop(void) { - ISearchable* searchableObj = nullptr; + std::shared_ptr 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> FindElementCommand::getSelectors(void) auto searchableObj = getSearchableTop(); auto selectors = getSelectors(); - std::vector> founds = {}; + std::vector> 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)); } diff --git a/org.tizen.aurum-bootstrap/src/Commands/FlickCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/FlickCommand.cc index a1b58c6..b468e43 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/FlickCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/FlickCommand.cc @@ -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 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); diff --git a/org.tizen.aurum-bootstrap/src/Commands/GetAttributeCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/GetAttributeCommand.cc index 09e9949..5b0ced7 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/GetAttributeCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/GetAttributeCommand.cc @@ -52,7 +52,7 @@ std::unique_ptr GetAttributeCommand::createCommand(const :: ::grpc::Status GetVisibleAttributeCommand::execute() { - UiObject* obj = mObjMap->getElement(mRequest->elementid()); + std::shared_ptr 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::createCommand(const :: ::grpc::Status GetFocusedAttributeCommand::execute() { - UiObject* obj = mObjMap->getElement(mRequest->elementid()); + std::shared_ptr 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::createCommand(const :: ::grpc::Status GetFocusableAttributeCommand::execute() { - UiObject* obj = mObjMap->getElement(mRequest->elementid()); + std::shared_ptr 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::createCommand(const :: ::grpc::Status GetCheckableAttributeCommand::execute() { - UiObject* obj = mObjMap->getElement(mRequest->elementid()); + std::shared_ptr 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::createCommand(const :: ::grpc::Status GetCheckedAttributeCommand::execute() { - UiObject* obj = mObjMap->getElement(mRequest->elementid()); + std::shared_ptr 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::createCommand(const :: ::grpc::Status GetEnabledAttributeCommand::execute() { - UiObject* obj = mObjMap->getElement(mRequest->elementid()); + std::shared_ptr 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::createCommand(const :: ::grpc::Status GetClickableAttributeCommand::execute() { - UiObject* obj = mObjMap->getElement(mRequest->elementid()); + std::shared_ptr 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::createCommand(const :: ::grpc::Status GetScrollableAttributeCommand::execute() { - UiObject* obj = mObjMap->getElement(mRequest->elementid()); + std::shared_ptr 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::createCommand(const :: ::grpc::Status GetSelectableAttributeCommand::execute() { - UiObject* obj = mObjMap->getElement(mRequest->elementid()); + std::shared_ptr 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::createCommand(const :: ::grpc::Status GetSelectedAttributeCommand::execute() { - UiObject* obj = mObjMap->getElement(mRequest->elementid()); + std::shared_ptr 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::createCommand(const :: ::grpc::Status GetShowingAttributeCommand::execute() { - UiObject* obj = mObjMap->getElement(mRequest->elementid()); + std::shared_ptr 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::createCommand(const :: ::grpc::Status GetActiveAttributeCommand::execute() { - UiObject* obj = mObjMap->getElement(mRequest->elementid()); + std::shared_ptr obj = mObjMap->getElement(mRequest->elementid()); if (!obj) { mResponse->set_boolvalue(false); mResponse->set_status(aurum::RspStatus::ERROR); diff --git a/org.tizen.aurum-bootstrap/src/Commands/GetDeviceTimeCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/GetDeviceTimeCommand.cc index a9f1142..ed71dcc 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/GetDeviceTimeCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/GetDeviceTimeCommand.cc @@ -88,7 +88,7 @@ public: { LOG_SCOPE_F(INFO, "GetDeviceTime --------------- "); - UiDevice* obj = UiDevice::getInstance(DeviceType::DEFAULT); + std::shared_ptr obj = UiDevice::getInstance(); ::aurum::ReqGetDeviceTime_TimeType type = mRequest->type(); long long utcStampMs; diff --git a/org.tizen.aurum-bootstrap/src/Commands/GetSizeCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/GetSizeCommand.cc index de77d0e..919c196 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/GetSizeCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/GetSizeCommand.cc @@ -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 obj = mObjMap->getElement(mRequest->elementid()); if (obj) { const Rect &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; diff --git a/org.tizen.aurum-bootstrap/src/Commands/GetValueCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/GetValueCommand.cc index 0eabcb5..ebe9c93 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/GetValueCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/GetValueCommand.cc @@ -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 obj = mObjMap->getElement(mRequest->elementid()); if (obj) { std::string text = obj->getText(); diff --git a/org.tizen.aurum-bootstrap/src/Commands/LongClickCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/LongClickCommand.cc index 6dcc5a1..6360c12 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/LongClickCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/LongClickCommand.cc @@ -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 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 obj = UiDevice::getInstance(); const ::aurum::Point& point = mRequest->coordination(); obj->click(point.x(), point.y(), LOGNCLICK_INTERVAL); mResponse->set_status(::aurum::RspStatus::OK); diff --git a/org.tizen.aurum-bootstrap/src/Commands/SendKeyCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/SendKeyCommand.cc index 2a113b8..6008d44 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/SendKeyCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/SendKeyCommand.cc @@ -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 mDevice = UiDevice::getInstance(); ::aurum::ReqKey_KeyType type = mRequest->type(); ::aurum::ReqKey_KeyActionType action_type = mRequest->actiontype(); KeyRequestType actionType = static_cast(action_type); diff --git a/org.tizen.aurum-bootstrap/src/Commands/SetValueCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/SetValueCommand.cc index 9f574ee..32cd476 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/SetValueCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/SetValueCommand.cc @@ -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 obj = mObjMap->getElement(mRequest->elementid()); if (obj) obj->setText(const_cast(mRequest->stringvalue())); return grpc::Status::OK; } \ No newline at end of file diff --git a/org.tizen.aurum-bootstrap/src/Commands/SyncCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/SyncCommand.cc index b84f700..70c4de6 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/SyncCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/SyncCommand.cc @@ -11,7 +11,7 @@ SyncCommand::SyncCommand(const ::aurum::ReqEmpty *request, ::grpc::Status SyncCommand::execute() { - UiDevice *obj = UiDevice::getInstance(DeviceType::DEFAULT); + std::shared_ptr obj = UiDevice::getInstance(); long long timeMs = obj->getSystemTime(TimeRequestType::WALLCLOCK); LOG_SCOPE_F(INFO, "Sync Command @ %f", timeMs/1000.0); // do post-command diff --git a/org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc index 47eb9d0..ad199b1 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc @@ -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 mDevice = UiDevice::getInstance(); mDevice->takeScreenshot(path, 1.0, 1); std::ifstream ifs(path, std::ifstream::binary); diff --git a/org.tizen.aurum-bootstrap/src/Commands/TouchDownCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/TouchDownCommand.cc index 5f3d45f..533f520 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/TouchDownCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/TouchDownCommand.cc @@ -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; diff --git a/org.tizen.aurum-bootstrap/src/Commands/TouchMoveCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/TouchMoveCommand.cc index 883199a..d31c771 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/TouchMoveCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/TouchMoveCommand.cc @@ -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 diff --git a/org.tizen.aurum-bootstrap/src/Commands/TouchUpCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/TouchUpCommand.cc index 0aa24a8..354ccad 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/TouchUpCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/TouchUpCommand.cc @@ -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 diff --git a/org.tizen.aurum-bootstrap/src/ObjectMapper.cc b/org.tizen.aurum-bootstrap/src/ObjectMapper.cc index 75bf956..e968875 100644 --- a/org.tizen.aurum-bootstrap/src/ObjectMapper.cc +++ b/org.tizen.aurum-bootstrap/src/ObjectMapper.cc @@ -1,6 +1,8 @@ #include "ObjectMapper.h" +#include +#include -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 object) +std::string ObjectMapper::addElement(std::shared_ptr 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 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(obj)->refresh(); + std::shared_ptr 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 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 obj = getElement(key); + if (obj) { + if (mObjectMap.erase(key) && mObjectMapReverse.erase(obj)) + return true; + } + return false; +} + +bool ObjectMapper::removeElement(std::shared_ptr object) +{ + std::string key = getElement(object); + if (key.empty()) return false; + return removeElement(key); +} \ No newline at end of file diff --git a/tests/ua_test.cpp b/tests/ua_test.cpp index 7e0c3e1..30fde1a 100644 --- a/tests/ua_test.cpp +++ b/tests/ua_test.cpp @@ -5,7 +5,27 @@ #include #include +#include "MockDeviceImpl.h" + +#include +#include + +#include + + +#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 mDevice1 = UiDevice::getInstance(nullptr); + ASSERT_NE(mDevice1, nullptr); } + TEST_F(UaTest, TextSelector) { std::shared_ptr 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(const_cast(watcher)); + + std::shared_ptr appNode = std::make_shared(nullptr, "text", "pkg", "application", "res","type","style", Rect{0,0,100,200}, 0, 0); + std::shared_ptr app = std::make_shared(appNode); + mockWatcher->addApplication(app); + + std::shared_ptr winNode = std::make_shared(nullptr, "text", "pkg", "window", "res","type","style", Rect{0,0,100,200}, 0, 0); + std::shared_ptr win = std::make_shared(app, winNode); + winNode->setFeatureProperty(8); + winNode->setFeatureProperty(9); + winNode->setFeatureProperty(10); + app->addWindow(win); + + std::shared_ptr node = std::make_shared(nullptr, "test", "pkg", "ahahah", "res","type","style", Rect{0,0,100,200}, 0, 0); + winNode->addChild(node); + + std::shared_ptr 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 -- 2.7.4