-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdevice.cpp
More file actions
101 lines (76 loc) · 3.19 KB
/
Copy pathdevice.cpp
File metadata and controls
101 lines (76 loc) · 3.19 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
#include "device.hpp"
#include "iwd.hpp"
#include "network.hpp"
#include <iostream>
#include <optional>
#include <sdbus-c++/Types.h>
void device::scan() {
auto proxy = sdbus::createProxy(*this->manager->system_bus,
this->manager->service_name,
this->path
);
try {
auto call = proxy->createMethodCall(sdbus::InterfaceName{iwd_constants::STATION_IFACE}, sdbus::MethodName{"Scan"});
proxy->callMethod(call);
} catch(...) {
std::cout << "[Warning] Scan in progress\n";
}
}
std::vector<network> device::get_networks() {
std::vector<network> out;
auto proxy = sdbus::createProxy(*this->manager->system_bus,
this->manager->service_name,
this->path
);
auto call = proxy->createMethodCall(sdbus::InterfaceName{iwd_constants::STATION_IFACE}, sdbus::MethodName{"GetOrderedNetworks"});
std::vector<sdbus::Struct<sdbus::ObjectPath, int16_t>> nets;
auto reply = proxy->callMethod(call);
reply >> nets;
managed_objects all_objects = this->manager->get_objects();
for(const auto &entry: nets) {
auto path = entry.get<0>();
auto signal = entry.get<1>();
auto data = all_objects[path][iwd_constants::NETWORK_IFACE];
out.push_back(network{
{data.at("Name").get<std::string>(), data.at("Type").get<std::string>(), path},
data.at("Connected").get<bool>(),
signal
});
}
return out;
}
std::unique_ptr<sdbus::IProxy> device::connect(const network &in, std::function<void(std::optional<sdbus::Error>)> f) {
auto proxy = sdbus::createProxy(*this->manager->system_bus,
this->manager->service_name,
in.path
);
proxy->callMethodAsync(sdbus::MethodName{"Connect"})
.onInterface(sdbus::InterfaceName{iwd_constants::NETWORK_IFACE})
.uponReplyInvoke(f);
// we can't have this blocking or else we won't be able to show a dialog
return proxy;
}
void device::connect(const network &in) {
auto callback = [](std::optional<sdbus::Error> e) {};
this->connect(in, callback);
}
void device::disconnect() {
auto proxy = sdbus::createProxy(*this->manager->system_bus,
this->manager->service_name,
this->path
);
auto call = proxy->createMethodCall(sdbus::InterfaceName{iwd_constants::STATION_IFACE}, sdbus::MethodName{"Disconnect"});
proxy->callMethod(call);
}
std::optional<sdbus::ObjectPath> device::get_connected_network(){
auto proxy = sdbus::createProxy(*this->manager->system_bus,
this->manager->service_name,
this->path
);
try{
auto prop = proxy->getProperty("ConnectedNetwork").onInterface(iwd_constants::STATION_IFACE);
return prop.get<sdbus::ObjectPath>();
} catch(...){
return std::nullopt;
}
}