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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
#ifndef BT_HH
#define BT_HH
#include <cstdint>
#include <functional>
#include <memory>
#include <optional>
#include <string>
#include <vector>
namespace logger {
class Logger;
} // namespace logger
namespace looper {
class Looper;
} // namespace looper
namespace cfg {
class Config;
} // namespace cfg
namespace bt {
class Device;
class Player;
class Adapter {
public:
virtual ~Adapter() = default;
[[nodiscard]]
virtual std::string const& address() const = 0;
[[nodiscard]]
virtual std::string const& name() const = 0;
[[nodiscard]]
virtual bool discoverable() const = 0;
[[nodiscard]]
virtual uint32_t discoverable_timeout_seconds() const = 0;
[[nodiscard]]
virtual bool pairable() const = 0;
[[nodiscard]]
virtual uint32_t pairable_timeout_seconds() const = 0;
[[nodiscard]]
virtual bool pairing() const = 0;
[[nodiscard]]
virtual bool powered() const = 0;
[[nodiscard]]
virtual bool connectable() const = 0;
[[nodiscard]]
virtual std::vector<Device*> devices() const = 0;
virtual void set_discoverable(bool discoverable) = 0;
virtual void set_discoverable_timeout_seconds(uint32_t timeout) = 0;
virtual void set_pairable_timeout_seconds(uint32_t timeout) = 0;
protected:
Adapter() = default;
Adapter(Adapter const&) = delete;
Adapter& operator=(Adapter const&) = delete;
};
class Device {
public:
virtual ~Device() = default;
[[nodiscard]]
virtual std::string const& address() const = 0;
[[nodiscard]]
virtual std::string const& name() const = 0;
[[nodiscard]]
virtual bool paired() const = 0;
[[nodiscard]]
virtual bool connected() const = 0;
// Returns null if there are no players.
// Otherwise, returns the "primary" player.
[[nodiscard]]
virtual Player* player() const = 0;
protected:
Device() = default;
Device(Device const&) = delete;
Device& operator=(Device const&) = delete;
};
class Player {
public:
virtual ~Player() = default;
enum class Status : uint8_t {
kPlaying,
kStopped,
kPaused,
kForwardSeek,
kReverseSeek,
kError,
};
[[nodiscard]]
virtual Status status() const = 0;
[[nodiscard]]
virtual std::string const& track_title() const = 0;
[[nodiscard]]
virtual std::string const& track_artist() const = 0;
[[nodiscard]]
virtual std::string const& track_album() const = 0;
virtual void play() = 0;
virtual void pause() = 0;
protected:
Player() = default;
Player(Player const&) = delete;
Player& operator=(Player const&) = delete;
};
class Manager {
public:
virtual ~Manager() = default;
class Delegate {
public:
virtual ~Delegate() = default;
// Called when "primary" adapter changes from one to another.
virtual void new_adapter(Adapter* /* adapter */) {}
// Called when "primary" adapter changes a property.
virtual void updated_adapter(Adapter& /* adapter */) {}
// Called when a new device is added to adapter.
virtual void added_device(Device& /* device */) {}
// Called when a device was removed from adapter.
virtual void removed_device(std::string const& /* address */) {}
// Called when device changes a property.
virtual void updated_device(Device& /* device */) {}
// Called when a new player is added to a device.
virtual void added_player(Device& /* device */, Player& /* player */) {}
// Called when a player was removed from a device.
virtual void removed_player(Device& /* device */) {}
// Called when a device player changes a property.
virtual void updated_player(Device& /* device */, Player& /* player */) {}
virtual void agent_request_pincode(
Device& device,
std::function<void(std::optional<std::string>)> callback) = 0;
virtual void agent_display_pincode(Device& device,
std::string const& pincode) = 0;
virtual void agent_request_passkey(
Device& device,
std::function<void(std::optional<uint32_t>)> callback) = 0;
virtual void agent_display_passkey(Device& device, uint32_t passkey,
uint16_t entered) = 0;
virtual void agent_request_confirmation(
Device& device, uint32_t passkey,
std::function<void(bool)> callback) = 0;
virtual void agent_request_authorization(
Device& device, std::function<void(bool)> callback) = 0;
virtual void agent_authorize_service(
Device& device, std::string const& uuid,
std::function<void(bool)> callback) = 0;
virtual void agent_cancel() = 0;
protected:
Delegate() = default;
};
// Returns null if there are no adapters.
// Otherwise, returns the "primary" adapter.
virtual Adapter* adapter() = 0;
protected:
Manager() = default;
Manager(Manager const&) = delete;
Manager& operator=(Manager const&) = delete;
};
std::unique_ptr<Manager> create_manager(logger::Logger& logger,
cfg::Config const& cfg,
looper::Looper& looper,
Manager::Delegate& delegate);
} // namespace bt
#endif // BT_HH
|