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_
39
Context(Context const&) = delete;
40
Context& operator=(Context const&) = delete;
42
std::shared_ptr<Device> device_from_syspath(std::string const& syspath);
47
::udev* const context;
53
virtual ~Device() = default;
55
Device(Device const&) = delete;
56
Device& operator=(Device const&) = delete;
58
virtual char const* subsystem() const = 0;
59
virtual char const* devtype() const = 0;
60
virtual char const* devpath() const = 0;
61
virtual char const* devnode() const = 0;
66
bool operator==(Device const& lhs, Device const& rhs);
67
bool operator!=(Device const& lhs, Device const& rhs);
72
Enumerator(std::shared_ptr<Context> const& ctx);
73
~Enumerator() noexcept;
75
Enumerator(Enumerator const&) = delete;
76
Enumerator& operator=(Enumerator const&) = delete;
80
void match_subsystem(std::string const& subsystem);
81
void match_parent(Device const& parent);
82
void match_sysname(std::string const& sysname);
85
public std::iterator<std::input_iterator_tag, Device>
88
iterator& operator++();
89
iterator operator++(int);
91
bool operator==(iterator const& rhs) const;
92
bool operator!=(iterator const& rhs) const;
94
Device const& operator*() const;
95
Device const* operator->() const;
97
friend class Enumerator;
100
iterator (std::shared_ptr<Context> const& ctx, udev_list_entry* entry);
104
std::shared_ptr<Context> ctx;
105
udev_list_entry* entry;
107
std::shared_ptr<Device> current;
114
std::shared_ptr<Context> const ctx;
115
udev_enumerate* const enumerator;
128
Monitor(const Context& ctx);
131
Monitor(Monitor const&) = delete;
132
Monitor& operator=(Monitor const&) = delete;
137
void filter_by_subsystem(std::string const& subsystem);
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_