-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
executable file
·66 lines (53 loc) · 1.6 KB
/
main.cpp
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
#include "bluetooth/rfcomm_server.hpp"
#include "bluetooth/bluez/adapter.hpp"
#include "bluetooth/bluez/device.hpp"
#include <dbus-glue/bindings/busy_loop.hpp>
#include <iostream>
int main()
{
using namespace Bluetooth;
using namespace std::string_literals;
auto bus = DBusGlue::open_system_bus();
ServerSpawnInfo info
{
1,
"/bla/bluetooth",
"SerialServer",
true
// requires modified rights as documented in README under 3)
// "de.blabla.cpp"s
};
Server server{&bus, info};
Bluetooth::Adapter driver(&bus);
driver.alias("device-3.0T");
std::cout << "power status: " << driver.power() << "\n";
std::cout << "discover timeout: " << driver.discoverTimeout() << "\n";
// for discovery and paring, do this someplace else:
/*
driver.discoverable(true);
driver.pairable(true);
*/
auto phone = driver.getPairedByName("HUAWEI P20");
if (phone)
{
phone->api().Trusted = true;
}
server.start(
// on connect:
[](std::string const& path, int fd){
std::cout << "new connection " << path << " with fd " << fd << "\n";
},
// on data:
[](int fd, std::string const& data){
std::cout << "Data received from " << fd << ": " << data << "\n";
::write(fd, "ok", 2);
},
// on disconnect:
[](int fd) {
std::cout << fd << " disconnected\n";
}
);
DBusGlue::make_busy_loop(&bus);
std::cin.get();
return 0;
}