2
* Copyright © 2013 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
19
#ifndef MIR_UDEV_WRAPPER_H_
20
#define MIR_UDEV_WRAPPER_H_
24
#include <mir/graphics/event_handler_register.h>
40
Context(Context const&) = delete;
41
Context& operator=(Context const&) = delete;
43
std::shared_ptr<Device> device_from_syspath(std::string const& syspath);
48
::udev* const context;
54
virtual ~Device() = default;
56
Device(Device const&) = delete;
57
Device& operator=(Device const&) = delete;
59
virtual char const* subsystem() const = 0;
60
virtual char const* devtype() const = 0;
61
virtual char const* devpath() const = 0;
62
virtual char const* devnode() const = 0;
67
bool operator==(Device const& lhs, Device const& rhs);
68
bool operator!=(Device const& lhs, Device const& rhs);
73
Enumerator(std::shared_ptr<Context> const& ctx);
74
~Enumerator() noexcept;
76
Enumerator(Enumerator const&) = delete;
77
Enumerator& operator=(Enumerator const&) = delete;
81
void match_subsystem(std::string const& subsystem);
82
void match_parent(Device const& parent);
83
void match_sysname(std::string const& sysname);
86
public std::iterator<std::input_iterator_tag, Device>
89
iterator& operator++();
90
iterator operator++(int);
92
bool operator==(iterator const& rhs) const;
93
bool operator!=(iterator const& rhs) const;
95
Device const& operator*() const;
98
friend class Enumerator;
101
iterator (std::shared_ptr<Context> const& ctx, udev_list_entry* entry);
105
std::shared_ptr<Context> ctx;
106
udev_list_entry* entry;
108
std::shared_ptr<Device> current;
115
std::shared_ptr<Context> const ctx;
116
udev_enumerate* const enumerator;
129
Monitor(const Context& ctx);
132
Monitor(Monitor const&) = delete;
133
Monitor& operator=(Monitor const&) = delete;
138
void filter_by_subsystem_and_type(std::string const& subsystem, std::string const& devtype);
140
void process_events(std::function<void(EventType, Device const&)> const& handler) const;
143
udev_monitor* const monitor;
149
#endif // MIR_UDEV_WRAPPER_H_