libaurum: add a logic to wait for idle
[platform/core/uifw/aurum.git] / libaurum / inc / UiDevice.h
1 #ifndef UIDEVICE_H
2 #define UIDEVICE_H
3 #include "config.h"
4
5 #include "UiObject.h"
6 #include "UiSelector.h"
7
8 #include "IDevice.h"
9 #include "ISearchable.h"
10
11 #include "AccessibleNode.h"
12 #include "Waiter.h"
13
14 #include <functional>
15 #include <string>
16
17 enum class DeviceType {
18     DEFAULT,
19     NUM_DEVICETYPE,
20 };
21
22 class UiDevice : public IDevice, public ISearchable {
23 public:
24     bool click(const int x, const int y) override;
25     bool click(const int x, const int y, const unsigned int intv) override;
26
27     bool drag(const int sx, const int sy, const int ex, const int ey,
28               const int steps, const int durationMs) override;
29
30     bool touchDown(const int x, const int y) override;
31     bool touchMove(const int x, const int y) override;
32     bool touchUp(const int x, const int y) override;
33
34     bool pressBack() override;
35     bool pressHome() override;
36     bool pressMenu() override;
37     bool pressVolUp() override;
38     bool pressVolDown() override;
39     bool pressPower() override;
40
41     bool pressKeyCode(std::string keycode) override;
42     bool takeScreenshot(std::string path, float scale, int quality) override;
43     long long getSystemTime(TypeRequestType type) override;
44
45 public:
46     bool hasObject(const std::shared_ptr<UiSelector> selector) const override;
47     std::unique_ptr<UiObject> findObject(
48         const std::shared_ptr<UiSelector> selector) const override;
49     std::vector<std::unique_ptr<UiObject>> findObjects(
50         const std::shared_ptr<UiSelector> selector) const override;
51
52     bool waitFor(
53         const std::function<bool(const ISearchable *)> condition) const;
54     std::unique_ptr<UiObject> waitFor(
55         const std::function<std::unique_ptr<UiObject>(const ISearchable *)>
56             condition) const;
57
58 public:
59     static UiDevice *getInstance(DeviceType type);
60
61 private:
62     std::vector<std::unique_ptr<AccessibleNode>> getWindowRoot() const;
63     bool waitForIdle() const;
64 private:
65     UiDevice();
66     UiDevice(DeviceType type, IDevice *impl);
67     virtual ~UiDevice();
68
69 private:
70     DeviceType    mType;
71     IDevice *     mDeviceImpl;
72     const Waiter *mWaiter;
73 };
74
75 #endif