-
-
Notifications
You must be signed in to change notification settings - Fork 393
Expand file tree
/
Copy pathAdapter.cpp
More file actions
112 lines (82 loc) · 3.1 KB
/
Adapter.cpp
File metadata and controls
112 lines (82 loc) · 3.1 KB
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
#include <simpleble/Adapter.h>
#include "AdapterBase.h"
#include "AdapterBuilder.h"
#include "LoggingInternal.h"
using namespace SimpleBLE;
std::vector<Adapter> Adapter::get_adapters() {
std::vector<Adapter> available_adapters;
auto internal_adapters = AdapterBase::get_adapters();
for (auto& internal_adapter : internal_adapters) {
AdapterBuilder adapter(internal_adapter);
available_adapters.push_back(adapter);
}
return available_adapters;
}
bool Adapter::bluetooth_enabled() { return AdapterBase::bluetooth_enabled(); }
bool Adapter::initialized() const { return internal_ != nullptr; }
void* Adapter::underlying() const {
if (!initialized()) throw Exception::NotInitialized();
return internal_->underlying();
}
std::string Adapter::identifier() {
if (!initialized()) throw Exception::NotInitialized();
return internal_->identifier();
}
BluetoothAddress Adapter::address() {
if (!initialized()) throw Exception::NotInitialized();
return internal_->address();
}
void Adapter::scan_start() {
if (!initialized()) throw Exception::NotInitialized();
if (!bluetooth_enabled()) {
SIMPLEBLE_LOG_WARN(fmt::format("Bluetooth is not enabled."));
#if defined(_WIN32) && !defined(_WIN64)
return;
#endif
}
internal_->scan_start();
}
void Adapter::scan_stop() {
if (!initialized()) throw Exception::NotInitialized();
if (!bluetooth_enabled()) {
SIMPLEBLE_LOG_WARN(fmt::format("Bluetooth is not enabled."));
return;
}
internal_->scan_stop();
}
void Adapter::scan_for(int timeout_ms) {
if (!initialized()) throw Exception::NotInitialized();
if (!bluetooth_enabled()) {
SIMPLEBLE_LOG_WARN(fmt::format("Bluetooth is not enabled."));
return;
}
internal_->scan_for(timeout_ms);
}
bool Adapter::scan_is_active() {
if (!initialized()) throw Exception::NotInitialized();
return internal_->scan_is_active();
}
std::vector<Peripheral> Adapter::scan_get_results() {
if (!initialized()) throw Exception::NotInitialized();
return internal_->scan_get_results();
}
std::vector<Peripheral> Adapter::get_paired_peripherals() {
if (!initialized()) throw Exception::NotInitialized();
return internal_->get_paired_peripherals();
}
void Adapter::set_callback_on_scan_start(std::function<void()> on_scan_start) {
if (!initialized()) throw Exception::NotInitialized();
internal_->set_callback_on_scan_start(std::move(on_scan_start));
}
void Adapter::set_callback_on_scan_stop(std::function<void()> on_scan_stop) {
if (!initialized()) throw Exception::NotInitialized();
internal_->set_callback_on_scan_stop(std::move(on_scan_stop));
}
void Adapter::set_callback_on_scan_updated(std::function<void(Peripheral)> on_scan_updated) {
if (!initialized()) throw Exception::NotInitialized();
internal_->set_callback_on_scan_updated(std::move(on_scan_updated));
}
void Adapter::set_callback_on_scan_found(std::function<void(Peripheral)> on_scan_found) {
if (!initialized()) throw Exception::NotInitialized();
internal_->set_callback_on_scan_found(std::move(on_scan_found));
}