summaryrefslogtreecommitdiff
path: root/gtest/src/inputtest-driver-connection.h
blob: af17cac5e9c7d6d2575fba90b5d940db649468fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*******************************************************************************
 *
 * X testing environment - Google Test environment feat. dummy x server
 *
 * Copyright (C) 2020 Povilas Kanapickas <povilas@radix.lt>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 ******************************************************************************/

#ifndef XORG_INPUTTEST_DRIVER_CONNECTION_H_
#define XORG_INPUTTEST_DRIVER_CONNECTION_H_

#include <memory>
#include <string>
#include "xorg/gtest/inputtest/xorg-gtest-valuators.h"

namespace xorg {
namespace testing {
namespace inputtest {

/**
 * A connection to replay events through the xf86-input-inputtest input driver
 */

class DriverConnection {
public:
    /**
     * Create a new driver connection.
     *
     * @param [in] socket_path Path to the domain socket that will be used to communicate with the
     *             driver
    */
    explicit DriverConnection(const std::string& socket_path);
    ~DriverConnection();

    /**
     * Returns the events input path
    */
    const std::string& SocketPath() const;

    /**
     * Waits for the connection to the driver being established.
     * Throws an exception if this can not be achieved within 10 seconds.
    */
    void WaitForDriver();

    /**
     * Closes the connection if it is open
    */
    void Close();

    /**
     * Synchronizes with the X server. Sends a synchronization event and waits for response.
     * This is done after all input events and is thus unnecessary in regular circumstances.
    */
    void Sync();

    /**
     * All of the functions below result in one input event being sent to the X server
     * via the FIFO files. If the files are not open yet, an exception is thrown.
    */
    void RelMotion(const Valuators& valuators);

    void AbsMotion(const Valuators& valuators);

    void ProximityIn(const Valuators& valuators);
    void ProximityOut(const Valuators& valuators);

    void ButtonDownAbs(std::int32_t button, const Valuators& valuators);
    void ButtonDownRel(std::int32_t button, const Valuators& valuators);

    void ButtonUpAbs(std::int32_t button, const Valuators& valuators);
    void ButtonUpRel(std::int32_t button, const Valuators& valuators);

    void KeyDown(std::int32_t key_code);
    void KeyUp(std::int32_t key_code);

    void TouchBegin(std::uint32_t id, const Valuators& valuators);
    void TouchUpdate(std::uint32_t id, const Valuators& valuators);
    void TouchEnd(std::uint32_t id, const Valuators& valuators);

private:
    struct Private;
    std::unique_ptr<Private> d_;

    bool TryConnectToDriver();
    void EnsureConnectedToDriver();
};

} // namespace inputtest
} // namespace testing
} // namespace xorg

#endif // XORG_INPUTTEST_DRIVER_CONNECTION_H_