2 #include "AccessibleWatcher.h"
4 #include "DeviceImpl/TizenImpl.h"
10 UiDevice::UiDevice() : UiDevice(DeviceType::DEFAULT, nullptr) {}
12 UiDevice::UiDevice(DeviceType type, IDevice *impl)
13 : mType(type), mDeviceImpl(impl), mWaiter(new Waiter{this})
23 UiDevice *UiDevice::getInstance(DeviceType type)
25 static UiDevice *device = nullptr;
27 if (!device) device = new UiDevice(type, new TizenImpl());
32 std::vector<std::unique_ptr<AccessibleNode>> UiDevice::getWindowRoot() const
34 return AccessibleWatcher::getInstance()->getTopNode();
37 bool UiDevice::hasObject(const std::shared_ptr<UiSelector> selector) const
39 auto root = getWindowRoot();
40 for (auto it = root.begin(); it != root.end(); ++it) {
41 std::unique_ptr<AccessibleNode> node =
42 Comparer::findObject(this, selector, (*it).get());
43 if (node != nullptr) return true;
49 std::unique_ptr<UiObject> UiDevice::findObject(const std::shared_ptr<UiSelector> selector) const
51 auto root = getWindowRoot();
52 for (auto it = root.begin(); it != root.end(); ++it) {
53 std::unique_ptr<AccessibleNode> node =
54 Comparer::findObject(this, selector, (*it).get());
56 return std::make_unique<UiObject>(this, selector, std::move(node));
58 return std::unique_ptr<UiObject>{nullptr};
61 std::vector<std::unique_ptr<UiObject>> UiDevice::findObjects(
62 const std::shared_ptr<UiSelector> selector) const
64 std::vector<std::unique_ptr<UiObject>> ret{};
65 auto root = getWindowRoot();
66 for (auto it = root.begin(); it != root.end(); ++it) {
67 std::vector<std::unique_ptr<AccessibleNode>> nodes =
68 Comparer::findObjects(this, selector, (*it).get());
70 for (auto &node : nodes)
71 ret.push_back(std::make_unique<UiObject>(this, selector, std::move(node)));
75 bool UiDevice::waitFor(
76 const std::function<bool(const ISearchable *)> condition) const
78 return mWaiter->waitFor(condition);
81 std::unique_ptr<UiObject> UiDevice::waitFor(
82 const std::function<std::unique_ptr<UiObject>(const ISearchable *)>
85 return mWaiter->waitFor(condition);
88 bool UiDevice::click(const int x, const int y)
90 return mDeviceImpl->click(x, y);
93 bool UiDevice::click(const int x, const int y, const unsigned int intv)
95 return mDeviceImpl->click(x, y, intv);
98 bool UiDevice::drag(const int sx, const int sy, const int ex, const int ey,
101 return mDeviceImpl->drag(sx, sy, ex, ey, steps);
104 bool UiDevice::touchDown(const int x, const int y)
106 return mDeviceImpl->touchDown(x, y);
109 bool UiDevice::touchMove(const int x, const int y)
111 return mDeviceImpl->touchMove(x, y);
114 bool UiDevice::touchUp(const int x, const int y)
116 return mDeviceImpl->touchUp(x, y);
119 bool UiDevice::pressBack()
121 return mDeviceImpl->pressBack();
124 bool UiDevice::pressHome()
126 return mDeviceImpl->pressHome();
129 bool UiDevice::pressMenu()
131 return mDeviceImpl->pressMenu();
134 bool UiDevice::pressVolUp()
136 return mDeviceImpl->pressVolUp();
139 bool UiDevice::pressVolDown()
141 return mDeviceImpl->pressVolDown();
144 bool UiDevice::pressPower()
146 return mDeviceImpl->pressPower();
149 bool UiDevice::pressKeyCode(std::string keycode)
151 return mDeviceImpl->pressKeyCode(keycode);
154 bool UiDevice::takeScreenshot(std::string path, float scale, int quality)
156 return mDeviceImpl->takeScreenshot(path, scale, quality);
159 long long UiDevice::getSystemTime(TypeRequestType type)
161 return mDeviceImpl->getSystemTime(type);