Antkeeper  0.0.1
device.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_INPUT_DEVICE_HPP
21 #define ANTKEEPER_INPUT_DEVICE_HPP
22 
26 #include <engine/utility/uuid.hpp>
27 #include <optional>
28 #include <string>
29 
30 namespace input {
31 
35 class device
36 {
37 public:
41  void connect();
42 
48  void disconnect();
49 
51  [[nodiscard]] inline bool is_connected() const noexcept
52  {
53  return connected;
54  }
55 
61  void set_uuid(const ::uuid& id);
62 
64  [[nodiscard]] inline const ::uuid& get_uuid() const noexcept
65  {
66  return uuid;
67  }
68 
70  [[nodiscard]] inline ::event::channel<device_connected_event>& get_connected_channel() noexcept
71  {
72  return connected_publisher.channel();
73  }
74 
76  [[nodiscard]] inline ::event::channel<device_disconnected_event>& get_disconnected_channel() noexcept
77  {
78  return disconnected_publisher.channel();
79  }
80 
82  [[nodiscard]] virtual constexpr device_type get_device_type() const noexcept = 0;
83 
84 private:
85  ::uuid uuid;
86  bool connected{false};
87 
89  ::event::publisher<device_disconnected_event> disconnected_publisher;
90 };
91 
92 } // namespace input
93 
94 #endif // ANTKEEPER_INPUT_DEVICE_HPP
Publishes messages to subscribers.
Definition: publisher.hpp:36
Abstract base class for virtual devices that generate input events.
Definition: device.hpp:36
const ::uuid & get_uuid() const noexcept
Returns the universally unique identifier (UUID) of this input device.
Definition: device.hpp:64
void connect()
Simulates the device being connected.
Definition: device.cpp:24
virtual constexpr device_type get_device_type() const noexcept=0
Returns the input device type.
bool is_connected() const noexcept
Returns true if the device is currently connected.
Definition: device.hpp:51
void set_uuid(const ::uuid &id)
Sets the universally unique identifier (UUID) of this input device.
Definition: device.cpp:36
void disconnect()
Simulates the device being disconnected.
Definition: device.cpp:30
::event::channel< device_connected_event > & get_connected_channel() noexcept
Returns the channel through which device connected events are published.
Definition: device.hpp:70
::event::channel< device_disconnected_event > & get_disconnected_channel() noexcept
Returns the channel through which device disconnected events are published.
Definition: device.hpp:76
Input devices, events, and mapping.
device_type
Input device types.
Definition: device-type.hpp:29
128-bit universally unique identifier (UUID).
Definition: uuid.hpp:32