DUDS
Distributed Update of Data from Something
EvdevInput.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2020 Jeff Jackowski
9  */
10 #include <duds/os/linux/Poller.hpp>
12 
13 namespace duds { namespace os { namespace linux {
14 
29 class EvdevInput :
30  boost::noncopyable,
31  public PollResponder,
32  public std::enable_shared_from_this<EvdevInput>
33 {
42  libevdev *dev = nullptr;
46  int fd;
47 public:
52  EvdevInput();
64  EvdevInput(const std::string &path);
70  EvdevInput(EvdevInput &&old);
81  static std::shared_ptr<EvdevInput> make(const std::string &path) {
82  return std::make_shared<EvdevInput>(path);
83  }
87  ~EvdevInput();
93  EvdevInput &operator = (EvdevInput &&old) noexcept;
107  void open(const std::string &path);
111  std::string name() const;
116  bool grab();
121  bool hasEventType(unsigned int et) const;
127  bool hasEvent(EventTypeCode etc) const;
134  bool hasEventCode(unsigned int et, unsigned int ec) const {
135  return hasEvent(EventTypeCode(et, ec));
136  }
144  int numMultitouchSlots() const;
148  bool hasMultitouchSlots() const {
149  return numMultitouchSlots() > 0;
150  }
157  int value(EventTypeCode etc) const;
165  int value(unsigned int et, unsigned int ec) const {
166  return value(EventTypeCode(et, ec));
167  }
172  bool eventsAvailable() const;
187  void respondToNextEvent();
191  void respond(Poller *, int);
198  void usePoller(Poller &p);
208  const input_absinfo *absInfo(unsigned int absEc) const;
216  boost::signals2::connection connect(const InputHandlersSptr &ihs);
230  boost::signals2::connection connect(
231  const InputSignal::slot_type &slot,
232  boost::signals2::connect_position at = boost::signals2::at_back
233  ) {
234  return defReceiver.connect(slot, at);
235  }
242  boost::signals2::connection connect(
243  const InputSignal::group_type &group,
244  const InputSignal::slot_type &slot,
245  boost::signals2::connect_position at = boost::signals2::at_back
246  ) {
247  return defReceiver.connect(group, slot, at);
248  }
255  boost::signals2::connection connectExtended(
256  const InputSignal::extended_slot_type &slot,
257  boost::signals2::connect_position at = boost::signals2::at_back
258  ) {
259  return defReceiver.connect_extended(slot, at);
260  }
267  boost::signals2::connection connectExtended(
268  const InputSignal::group_type &group,
269  const InputSignal::extended_slot_type &slot,
270  boost::signals2::connect_position at = boost::signals2::at_back
271  ) {
272  return defReceiver.connect_extended(group, slot, at);
273  }
281  const InputSignal::group_type &group
282  ) {
283  defReceiver.disconnect(group);
284  }
291  template<typename Slot>
292  void disconnect(const Slot &slotFunc) {
293  defReceiver.disconnect(slotFunc);
294  }
298  void disconnectAll() {
299  defReceiver.disconnect_all_slots();
300  }
301 };
302 
306 typedef std::shared_ptr<EvdevInput> EvdevInputSptr;
307 
308 } } }
bool grab()
Attempts to gain exclusive access to the input device.
Definition: EvdevInput.cpp:80
Responds to a poll event.
Definition: Poller.hpp:78
EvdevInput & operator=(EvdevInput &&old) noexcept
Move assignment.
Definition: EvdevInput.cpp:67
InputSignal defReceiver
Handles all input events.
Definition: EvdevInput.hpp:37
int value(unsigned int et, unsigned int ec) const
Returns the current input value for the given event.
Definition: EvdevInput.hpp:165
void respond(Poller *, int)
Same as calling respondToNextEvent(); used with Poller.
Definition: EvdevInput.cpp:129
bool hasEventType(unsigned int et) const
Returns true if the input device can produce events of the given type.
Definition: EvdevInput.cpp:84
void disconnect(const Slot &slotFunc)
Disconnect a slot from the input event signal.
Definition: EvdevInput.hpp:292
libevdev * dev
The object provided by libevdev that is needed to work with the input device.
Definition: EvdevInput.hpp:42
int fd
The file descriptor to the input device file.
Definition: EvdevInput.hpp:46
std::shared_ptr< EvdevInput > EvdevInputSptr
A shared pointer to a EvdevInput object.
Definition: EvdevInput.hpp:306
InputHandlersSptr makeConnectedHandlers()
Makes a new InputHandlers object, connects it to the input event signal for this device, and retruns the object.
Definition: EvdevInput.cpp:156
A simple C++ interface to using Linux&#39;s epoll functions.
Definition: Poller.hpp:117
boost::signals2::connection connectExtended(const InputSignal::group_type &group, const InputSignal::extended_slot_type &slot, boost::signals2::connect_position at=boost::signals2::at_back)
Make a connection to the input event signal.
Definition: EvdevInput.hpp:267
std::shared_ptr< InputHandlers > InputHandlersSptr
Shared pointer to a InputHandlers class.
bool hasEvent(EventTypeCode etc) const
Returns true if the input device can produce events of the given type and code.
Definition: EvdevInput.cpp:88
boost::signals2::signal< void(EventTypeCode etc, std::int32_t value)> InputSignal
The signal type that will handle input events.
Combines an event type and an event code, as defined by libevdev, for the purpose of using a combinat...
bool eventsAvailable() const
Returns true if there are events awaiting processing on this device.
Definition: EvdevInput.cpp:106
boost::signals2::connection connect(const InputSignal::group_type &group, const InputSignal::slot_type &slot, boost::signals2::connect_position at=boost::signals2::at_back)
Make a connection to the input event signal.
Definition: EvdevInput.hpp:242
boost::signals2::connection connect(const InputHandlersSptr &ihs)
Connect the given InputHandlers to the end of the input event signal.
Definition: EvdevInput.cpp:147
int numMultitouchSlots() const
Returns the number of slots supported by a multitouch input device.
Definition: EvdevInput.cpp:92
boost::signals2::connection connectExtended(const InputSignal::extended_slot_type &slot, boost::signals2::connect_position at=boost::signals2::at_back)
Make a connection to the input event signal.
Definition: EvdevInput.hpp:255
void open(const std::string &path)
Opens the given input device file.
Definition: EvdevInput.cpp:28
void disconnect(const InputSignal::group_type &group)
Disconnect a group from the input event signal.
Definition: EvdevInput.hpp:280
void usePoller(Poller &p)
Registers this object with the given Poller so that Poller::wait() will invoke respondToNextEvent().
Definition: EvdevInput.cpp:133
boost::signals2::connection connect(const InputSignal::slot_type &slot, boost::signals2::connect_position at=boost::signals2::at_back)
Make a connection to the input event signal.
Definition: EvdevInput.hpp:230
int value(EventTypeCode etc) const
Returns the current input value for the given event.
Definition: EvdevInput.cpp:96
std::string name() const
Reports the name of the device using libevdev_get_name().
Definition: EvdevInput.cpp:76
EvdevInput()
Constructs an EvdevInput object without opening a device file.
Definition: EvdevInput.cpp:22
void respondToNextEvent()
Responds to the next input event on the device.
Definition: EvdevInput.cpp:110
const input_absinfo * absInfo(unsigned int absEc) const
Provides information about a specified absolute axis.
Definition: EvdevInput.cpp:137
void disconnectAll()
Disconnects all slots from the input event signal.
Definition: EvdevInput.hpp:298
static std::shared_ptr< EvdevInput > make(const std::string &path)
Creates a EvdevInput object managed by a std::shared_ptr.
Definition: EvdevInput.hpp:81
bool hasMultitouchSlots() const
True if the input device has at least one multitouch slot.
Definition: EvdevInput.hpp:148
Handles getting input from a specific input device using libevdev.
Definition: EvdevInput.hpp:29
bool hasEventCode(unsigned int et, unsigned int ec) const
Returns true if the input device can produce events of the given type and code.
Definition: EvdevInput.hpp:134