2
* Copyright © 2012-2013 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Thomas Voß <thomas.voss@canonical.com>
18
#ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_CONNECTIVITY_NM_H
19
#define LOCATION_SERVICE_COM_UBUNTU_LOCATION_CONNECTIVITY_NM_H
21
#include <core/dbus/bus.h>
22
#include <core/dbus/object.h>
23
#include <core/dbus/property.h>
24
#include <core/dbus/service.h>
25
#include <core/dbus/types/object_path.h>
26
#include <core/dbus/types/struct.h>
27
#include <core/dbus/types/stl/map.h>
28
#include <core/dbus/types/stl/string.h>
29
#include <core/dbus/types/stl/tuple.h>
30
#include <core/dbus/types/stl/vector.h>
38
typedef std::shared_ptr<NetworkManager> Ptr;
42
static const std::string& name()
44
static const std::string s{"org.freedesktop.NetworkManager.AccessPoint"};
50
static const std::string& name()
52
static const std::string s{"Frequency"};
56
typedef AccessPoint Interface;
57
typedef std::uint32_t ValueType;
58
static const bool readable = true;
59
static const bool writable = false;
64
static const std::string& name()
66
static const std::string s{"LastSeen"};
70
typedef AccessPoint Interface;
71
typedef std::uint32_t ValueType;
72
static const bool readable = true;
73
static const bool writable = false;
86
static const std::string& name()
88
static const std::string s{"Mode"};
92
typedef AccessPoint Interface;
93
typedef std::uint32_t ValueType;
94
static const bool readable = true;
95
static const bool writable = false;
100
static const std::string& name()
102
static const std::string s{"HwAddress"};
106
typedef AccessPoint Interface;
107
typedef std::string ValueType;
108
static const bool readable = true;
109
static const bool writable = false;
114
static const std::string& name()
116
static const std::string s{"Ssid"};
120
typedef AccessPoint Interface;
121
typedef std::vector<std::int8_t> ValueType;
122
static const bool readable = true;
123
static const bool writable = false;
128
static const std::string& name()
130
static const std::string s{"Strength"};
134
typedef AccessPoint Interface;
135
typedef std::int8_t ValueType;
136
static const bool readable = true;
137
static const bool writable = false;
140
struct PropertiesChanged
142
inline static std::string name()
144
return "PropertiesChanged";
147
typedef AccessPoint Interface;
149
typedef std::map<std::string, core::dbus::types::Variant> ArgumentType;
152
AccessPoint(const std::shared_ptr<core::dbus::Object>& object)
154
frequency(object->get_property<Frequency>()),
155
last_seen(object->get_property<LastSeen>()),
156
mode(object->get_property<Mode>()),
157
hw_address(object->get_property<HwAddress>()),
158
ssid(object->get_property<Ssid>()),
159
strength(object->get_property<Strength>()),
160
properties_changed(object->get_signal<PropertiesChanged>())
164
std::shared_ptr<core::dbus::Object> object;
165
std::shared_ptr<core::dbus::Property<Frequency>> frequency;
166
std::shared_ptr<core::dbus::Property<LastSeen>> last_seen;
167
std::shared_ptr<core::dbus::Property<Mode>> mode;
168
std::shared_ptr<core::dbus::Property<HwAddress>> hw_address;
169
std::shared_ptr<core::dbus::Property<Ssid>> ssid;
170
std::shared_ptr<core::dbus::Property<Strength>> strength;
171
std::shared_ptr<core::dbus::Signal<PropertiesChanged, PropertiesChanged::ArgumentType>> properties_changed;
176
static const std::string& name()
178
static const std::string s{"org.freedesktop.NetworkManager.Device"};
202
static const std::string& name()
204
static const std::string s{"org.freedesktop.NetworkManager.Device.Wireless"};
208
struct GetAccessPoints
210
static const std::string& name()
212
static const std::string s{"GetAccessPoints"};
216
typedef Wireless Interface;
218
static std::chrono::milliseconds default_timeout()
220
return std::chrono::seconds{1};
226
static const std::string& name()
228
static const std::string s{"RequestScan"};
232
typedef Wireless Interface;
234
static std::chrono::milliseconds default_timeout()
236
return std::chrono::seconds{1};
244
inline static std::string name()
249
typedef Wireless Interface;
250
typedef void ArgumentType;
253
struct AccessPointAdded
255
inline static std::string name()
257
return "AccessPointAdded";
260
typedef Wireless Interface;
262
typedef core::dbus::types::ObjectPath ArgumentType;
265
struct AccessPointRemoved
267
inline static std::string name()
269
return "AccessPointRemoved";
272
typedef Wireless Interface;
274
typedef core::dbus::types::ObjectPath ArgumentType;
281
static const std::string& name()
283
static const std::string s{"DeviceType"};
287
typedef Device Interface;
288
typedef std::uint32_t ValueType;
289
static const bool readable = true;
290
static const bool writable = false;
293
Device(const std::shared_ptr<core::dbus::Service>& service,
294
const std::shared_ptr<core::dbus::Object>& object)
297
device_type(object->get_property<DeviceType>()),
300
object->get_signal<Wireless::Signals::ScanDone>(),
301
object->get_signal<Wireless::Signals::AccessPointAdded>(),
302
object->get_signal<Wireless::Signals::AccessPointRemoved>()
309
return static_cast<Type>(device_type->get());
312
void for_each_access_point(const std::function<void(const core::dbus::types::ObjectPath&)>& f) const
314
typedef std::vector<core::dbus::types::ObjectPath> ResultType;
315
auto result = object->transact_method<Wireless::GetAccessPoints, ResultType>();
317
if (result.is_error())
318
throw std::runtime_error(result.error().print());
320
for (const auto& path : result.value())
324
std::vector<AccessPoint> get_access_points() const
326
typedef std::vector<core::dbus::types::ObjectPath> ResultType;
327
auto result = object->invoke_method_synchronously<Wireless::GetAccessPoints, ResultType>();
329
if (result.is_error())
330
throw std::runtime_error(result.error().print());
332
std::vector<AccessPoint> aps;
334
for (const auto& path : result.value())
335
aps.push_back(AccessPoint(service->object_for_path(path)));
340
void request_scan() const
342
static const std::map<std::string, core::dbus::types::Variant> dictionary;
343
auto result = object->invoke_method_asynchronously<Wireless::RequestScan, void>(dictionary);
346
std::shared_ptr<core::dbus::Service> service;
347
std::shared_ptr<core::dbus::Object> object;
348
std::shared_ptr<core::dbus::Property<DeviceType>> device_type;
351
core::dbus::Signal<Wireless::Signals::ScanDone, Wireless::Signals::ScanDone::ArgumentType>::Ptr scan_done;
352
core::dbus::Signal<Wireless::Signals::AccessPointAdded, Wireless::Signals::AccessPointAdded::ArgumentType>::Ptr ap_added;
353
core::dbus::Signal<Wireless::Signals::AccessPointRemoved, Wireless::Signals::AccessPointRemoved::ArgumentType>::Ptr ap_removed;
357
static const std::string& name()
359
static const std::string s{"org.freedesktop.NetworkManager"};
365
static const std::string& name()
367
static const std::string s{"GetDevices"};
371
typedef NetworkManager Interface;
373
static std::chrono::milliseconds default_timeout()
375
return std::chrono::seconds{1};
392
static const std::string& name()
394
static const std::string s{"Connectivity"};
398
typedef NetworkManager Interface;
399
typedef std::uint32_t ValueType;
400
static const bool readable = true;
401
static const bool writable = false;
409
inline static std::string name()
411
return "DeviceAdded";
414
typedef NetworkManager Interface;
416
typedef core::dbus::types::ObjectPath ArgumentType;
421
inline static std::string name()
423
return "DeviceRemoved";
426
typedef NetworkManager Interface;
428
typedef core::dbus::types::ObjectPath ArgumentType;
431
struct PropertiesChanged
433
inline static std::string name()
435
return "PropertiesChanged";
438
typedef NetworkManager Interface;
440
typedef std::map<std::string, core::dbus::types::Variant> ArgumentType;
444
NetworkManager(const core::dbus::Bus::Ptr& bus)
445
: service(core::dbus::Service::use_service<NetworkManager>(bus)),
446
object(service->object_for_path(core::dbus::types::ObjectPath("/org/freedesktop/NetworkManager"))),
449
object->get_property<Properties::Connectivity>()
453
object->get_signal<Signals::DeviceAdded>(),
454
object->get_signal<Signals::DeviceRemoved>(),
455
object->get_signal<Signals::PropertiesChanged>()
460
void for_each_device(const std::function<void(const core::dbus::types::ObjectPath&)>& f)
463
object->transact_method<
464
NetworkManager::GetDevices,
465
std::vector<core::dbus::types::ObjectPath>
468
if (result.is_error())
469
throw std::runtime_error(result.error().print());
471
for (const auto& path : result.value())
475
Device device_for_path(const core::dbus::types::ObjectPath& path)
477
return Device(service, service->object_for_path(path));
480
std::vector<Device> get_devices()
483
object->invoke_method_synchronously<
484
NetworkManager::GetDevices,
485
std::vector<core::dbus::types::ObjectPath>>();
487
if (result.is_error())
488
throw std::runtime_error(result.error().print());
490
std::vector<Device> devices;
491
for (const auto& path : result.value())
493
devices.emplace_back(
496
service->object_for_path(path)));
502
std::shared_ptr<core::dbus::Service> service;
503
std::shared_ptr<core::dbus::Object> object;
507
std::shared_ptr<core::dbus::Property<Properties::Connectivity> > connectivity;
511
core::dbus::Signal<Signals::DeviceAdded, Signals::DeviceAdded::ArgumentType>::Ptr device_added;
512
core::dbus::Signal<Signals::DeviceRemoved, Signals::DeviceRemoved::ArgumentType>::Ptr device_removed;
513
core::dbus::Signal<Signals::PropertiesChanged, Signals::PropertiesChanged::ArgumentType>::Ptr properties_changed;
519
#endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_CONNECTIVITY_NM_H