11#pragma once
22#include < amarula/dbus/gproxy.hpp>
3- #include < any>
4- #include < functional>
5- #include < map>
6- #include < memory>
7- #include < mutex>
8- #include < optional>
9- #include < vector>
10- namespace Amarula ::DBus {
3+ #include < string>
4+ namespace Amarula ::DBus::G {
115class Connman ;
126
13- class ConnmanService {
14- public:
15- struct IPv4 {
16- std::string method;
17- std::string address;
18- std::string netmask;
19- std::string gateway;
20- IPv4 () = default ;
21- IPv4 (GVariant*);
22- };
23- struct IPv6 {
24- std::string method;
25- std::string address;
26- std::string gateway;
27- std::string privacy;
28- uint8_t PrefixLength{0U };
29- IPv6 () = default ;
30- IPv6 (GVariant*);
31- };
32- struct Ethernet {
33- std::string Method;
34- std::string Interface;
35- std::string Address;
36- uint16_t MTU{0U };
37- Ethernet () = default ;
38- Ethernet (GVariant* variant);
39- };
40- struct Provider {
41- std::string host;
42- std::string domain;
43- std::string name;
44- std::string type;
45- Provider () = default ;
46- Provider (GVariant* variant);
47- };
48- struct Proxy {
49- std::string method;
50- std::string url;
51- std::vector<std::string> servers;
52- std::vector<std::string> excludes;
53- Proxy () = default ;
54- Proxy (GVariant* variant);
55- };
7+ struct IPv4 {
8+ std::string method;
9+ std::string address;
10+ std::string netmask;
11+ std::string gateway;
12+ IPv4 () = default ;
13+ IPv4 (GVariant*);
14+ };
15+ struct IPv6 {
16+ std::string method;
17+ std::string address;
18+ std::string gateway;
19+ std::string privacy;
20+ uint8_t PrefixLength{0U };
21+ IPv6 () = default ;
22+ IPv6 (GVariant*);
23+ };
24+ struct Ethernet {
25+ std::string Method;
26+ std::string Interface;
27+ std::string Address;
28+ uint16_t MTU{0U };
29+ Ethernet () = default ;
30+ Ethernet (GVariant* variant);
31+ };
32+ struct Provider {
33+ std::string host;
34+ std::string domain;
35+ std::string name;
36+ std::string type;
37+ Provider () = default ;
38+ Provider (GVariant* variant);
39+ };
40+ struct Proxy {
41+ std::string method;
42+ std::string url;
43+ std::vector<std::string> servers;
44+ std::vector<std::string> excludes;
45+ Proxy () = default ;
46+ Proxy (GVariant* variant);
47+ };
5648
57- struct Properties {
58- std::string state;
59- std::string error;
60- std::string name;
61- std::string type;
62- std::vector<std::string> security;
63- std::vector<std::string> nameservers;
64- std::vector<std::string> domains;
65- std::vector<std::string> timeservers;
66- bool autoconnect{false };
67- bool mDns {false };
68- bool favorite{false };
69- bool immutable{false };
70- bool roaming{false };
71- uint8_t strength{0U };
72- IPv4 ipv4;
73- IPv6 ipv6;
74- Ethernet ethernet;
75- Provider provider;
76- Proxy proxy;
77- };
78- using PropertiesSetCallback = std::function<void (bool success)>;
79- using PropertiesCallback = std::function<void (Properties&)>;
49+ struct ServProperties {
50+ std::string state;
51+ std::string error;
52+ std::string name;
53+ std::string type;
54+ std::vector<std::string> security;
55+ std::vector<std::string> nameservers;
56+ std::vector<std::string> domains;
57+ std::vector<std::string> timeservers;
58+ bool autoconnect{false };
59+ bool mDns {false };
60+ bool favorite{false };
61+ bool immutable{false };
62+ bool roaming{false };
63+ uint8_t strength{0U };
64+ IPv4 ipv4;
65+ IPv6 ipv6;
66+ Ethernet ethernet;
67+ Provider provider;
68+ Proxy proxy;
69+ };
8070
71+ class ConnmanService : public DBusProxy <ServProperties> {
8172 private:
8273 using Self = ConnmanService;
83- size_t callback_counter_{0U };
84- std::mutex mtx_;
85- gpointer proxy_{nullptr };
86- GProxy* gproxy_{nullptr };
87- std::map<size_t , std::any> properties_callbacks_;
88- template <typename T>
89- auto prepareCallback (T callback) {
90- std::unique_lock<std::mutex> const lock (mtx_);
91- gproxy_->on_any_async_start ();
92- std::optional<size_t > call_counter = std::nullopt ;
93- if (callback != nullptr ) {
94- size_t index = ++callback_counter_;
95- call_counter = index;
96- properties_callbacks_[index] = std::move (callback);
97- }
98- return call_counter;
99- }
100- template <auto FinishFunc>
101- static void finishAsyncCall (GObject* proxy, GAsyncResult* res,
102- gpointer user_data);
103- void updateProperties (GVariant* properties,
104- const std::optional<size_t >& counter);
105- static void get_property_cb (GObject* proxy, GAsyncResult* res,
106- gpointer user_data);
107- static void set_property_cb (GObject* proxy, GAsyncResult* res,
108- gpointer user_data);
109- static void on_properties_changed_cb (
110- GDBusProxy* proxy, GVariant* changed_properties,
111- const gchar* const * invalidated_properties, gpointer user_data);
112- explicit ConnmanService (GProxy* proxy, gchar* obj_path);
113- static void connect_cb (GObject* proxy, GAsyncResult* res,
114- gpointer user_data);
115- static void disconnect_cb (GObject* proxy, GAsyncResult* res,
116- gpointer user_data);
11774
118- public:
119- ConnmanService (const ConnmanService&) = delete ;
120- auto operator =(const ConnmanService&) = delete ;
121- ConnmanService (ConnmanService&&) = delete ;
122- auto operator =(ConnmanService&&) = delete ;
75+ explicit ConnmanService (DBus* dbus, const gchar* obj_path);
12376
124- ~ConnmanService ();
125- void getProperties (PropertiesCallback callback);
77+ auto updateProperties (GVariant* properties) const -> ServProperties final ;
78+ using DBusProxy::DBusProxy;
79+
80+ public:
12681 void connect (PropertiesSetCallback callback = nullptr );
12782 void disconnect (PropertiesSetCallback callback = nullptr );
12883 void remove (PropertiesSetCallback callback = nullptr );
@@ -132,4 +87,4 @@ class ConnmanService {
13287 friend class Connman ;
13388};
13489
135- } // namespace Amarula::DBus
90+ } // namespace Amarula::DBus::G
0 commit comments