2 #include "AccessibleWatcher.h"
4 #include "DeviceImpl/TizenImpl.h"
12 UiDevice::UiDevice() : UiDevice(DeviceType::DEFAULT, nullptr) {}
14 UiDevice::UiDevice(DeviceType type, IDevice *impl)
15 : mType(type), mDeviceImpl(impl), mWaiter(new Waiter{this})
25 UiDevice *UiDevice::getInstance(DeviceType type)
27 static UiDevice *device = nullptr;
29 if (!device) device = new UiDevice(type, new TizenImpl());
34 std::vector<std::unique_ptr<AccessibleNode>> UiDevice::getWindowRoot() const
36 return AccessibleWatcher::getInstance()->getTopNode();
39 bool UiDevice::hasObject(const std::shared_ptr<UiSelector> selector) const
41 auto root = getWindowRoot();
42 for (auto it = root.begin(); it != root.end(); ++it) {
43 std::unique_ptr<AccessibleNode> node =
44 Comparer::findObject(this, selector, (*it).get());
45 if (node != nullptr) return true;
51 std::unique_ptr<UiObject> UiDevice::findObject(const std::shared_ptr<UiSelector> selector) const
53 auto root = getWindowRoot();
54 for (auto it = root.begin(); it != root.end(); ++it) {
55 std::unique_ptr<AccessibleNode> node =
56 Comparer::findObject(this, selector, (*it).get());
58 return std::make_unique<UiObject>(this, selector, std::move(node));
60 return std::unique_ptr<UiObject>{nullptr};
63 std::vector<std::unique_ptr<UiObject>> UiDevice::findObjects(
64 const std::shared_ptr<UiSelector> selector) const
66 std::vector<std::unique_ptr<UiObject>> ret{};
67 auto root = getWindowRoot();
68 for (auto it = root.begin(); it != root.end(); ++it) {
69 std::vector<std::unique_ptr<AccessibleNode>> nodes =
70 Comparer::findObjects(this, selector, (*it).get());
72 for (auto &node : nodes)
73 ret.push_back(std::make_unique<UiObject>(this, selector, std::move(node)));
77 bool UiDevice::waitFor(
78 const std::function<bool(const ISearchable *)> condition) const
80 return mWaiter->waitFor(condition);
83 std::unique_ptr<UiObject> UiDevice::waitFor(
84 const std::function<std::unique_ptr<UiObject>(const ISearchable *)>
87 return mWaiter->waitFor(condition);
89 bool UiDevice::waitForIdle() const
91 std::this_thread::sleep_for(std::chrono::milliseconds{167});
95 bool UiDevice::click(const int x, const int y)
97 bool result = mDeviceImpl->click(x, y);
102 bool UiDevice::click(const int x, const int y, const unsigned int intv)
104 bool result = mDeviceImpl->click(x, y, intv);
109 bool UiDevice::drag(const int sx, const int sy, const int ex, const int ey,
110 const int steps, const int durationMs)
112 bool result = mDeviceImpl->drag(sx, sy, ex, ey, steps, durationMs);
117 bool UiDevice::touchDown(const int x, const int y)
119 bool result = mDeviceImpl->touchDown(x, y);
124 bool UiDevice::touchMove(const int x, const int y)
126 bool result = mDeviceImpl->touchMove(x, y);
130 bool UiDevice::touchUp(const int x, const int y)
132 bool result = mDeviceImpl->touchUp(x, y);
137 bool UiDevice::pressBack()
139 bool result = mDeviceImpl->pressBack();
144 bool UiDevice::pressHome()
146 bool result = mDeviceImpl->pressHome();
151 bool UiDevice::pressMenu()
153 bool result = mDeviceImpl->pressMenu();
158 bool UiDevice::pressVolUp()
160 bool result = mDeviceImpl->pressVolUp();
165 bool UiDevice::pressVolDown()
167 bool result = mDeviceImpl->pressVolDown();
172 bool UiDevice::pressPower()
174 bool result = mDeviceImpl->pressPower();
179 bool UiDevice::pressKeyCode(std::string keycode)
181 bool result = mDeviceImpl->pressKeyCode(keycode);
186 bool UiDevice::takeScreenshot(std::string path, float scale, int quality)
188 return mDeviceImpl->takeScreenshot(path, scale, quality);
191 long long UiDevice::getSystemTime(TypeRequestType type)
193 return mDeviceImpl->getSystemTime(type);