Skip to content

Commit da3b17d

Browse files
committed
Align technology and service proxy
Align technology and service proxy class using the DBusProxy class. Improve naming and namespaces. Signed-off-by: Eduardo Gonzalez <eduardo.gonzalez@amarulasolutions.com>
1 parent 0edb068 commit da3b17d

17 files changed

Lines changed: 350 additions & 665 deletions

CMakeLists.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
1919
set(CMAKE_CXX_EXTENSIONS OFF)
2020
include(GNUInstallDirs)
2121

22-
add_library(GDbusProxy include/amarula/dbus/gproxy.hpp src/dbus/gproxy.cpp)
22+
add_library(GDbusProxy include/amarula/dbus/gdbus.hpp
23+
include/amarula/dbus/gproxy.hpp src/dbus/gdbus.cpp)
2324
add_library(Amarula::GDbusProxy ALIAS GDbusProxy)
2425
target_include_directories(
2526
GDbusProxy PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
@@ -44,16 +45,17 @@ if(BUILD_CONNMAN)
4445
add_library(
4546
GConnmanDbus
4647
$<TARGET_OBJECTS:gconnmanproxy>
47-
src/dbus/gconnman_definitions.hpp
48-
src/dbus/gconnman_definitions.cpp
48+
src/dbus/gconnman_private.hpp
4949
include/amarula/dbus/gconnman.hpp
50+
src/dbus/gconnman.cpp
5051
include/amarula/dbus/gconnman_clock.hpp
51-
include/amarula/dbus/gconnman_technology.hpp
52-
include/amarula/dbus/gconnman_service.hpp
5352
src/dbus/gconnman_clock.cpp
54-
src/dbus/gconnman.cpp
53+
include/amarula/dbus/gconnman_technology.hpp
5554
src/dbus/gconnman_technology.cpp
56-
src/dbus/gconnman_service.cpp)
55+
include/amarula/dbus/gconnman_service.hpp
56+
src/dbus/gconnman_service.cpp
57+
src/dbus/gdbus_private.hpp
58+
src/dbus/gdbus_private.cpp)
5759

5860
add_library(Amarula::GConnmanDbus ALIAS GConnmanDbus)
5961
get_target_property(CONNMAN_PROXY_INCLUDES gconnmanproxy

include/amarula/dbus/gconnman.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#include <amarula/dbus/gconnman_clock.hpp>
33
#include <amarula/dbus/gdbus.hpp>
44

5-
namespace Amarula::DBus {
5+
namespace Amarula::DBus::G {
66

7-
class Connman : public GDBus {
7+
class Connman : public DBus {
88
ConnmanClock* clock_{nullptr};
99

1010
void cleanup() override { delete clock_; }
@@ -16,4 +16,4 @@ class Connman : public GDBus {
1616
[[nodiscard]] auto clock() const -> ConnmanClock* { return clock_; }
1717
};
1818

19-
} // namespace Amarula::DBus
19+
} // namespace Amarula::DBus::G

include/amarula/dbus/gconnman_clock.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <string>
44
#include <vector>
55

6-
namespace Amarula::DBus {
6+
namespace Amarula::DBus::G {
77
class Connman;
88

99
struct ClockProperties {
@@ -15,17 +15,17 @@ struct ClockProperties {
1515
bool timeServerSynced;
1616
};
1717

18-
class ConnmanClock : public GProxy<ClockProperties> {
18+
class ConnmanClock : public DBusProxy<ClockProperties> {
1919
private:
2020
using Self = ConnmanClock;
2121

22-
explicit ConnmanClock(GDBus* dbus);
22+
explicit ConnmanClock(DBus* dbus);
2323

2424
auto updateProperties(GVariant* properties) const -> ClockProperties final;
2525

26-
public:
27-
using GProxy::GProxy;
26+
using DBusProxy::DBusProxy;
2827

28+
public:
2929
void setTime(unsigned int time, PropertiesSetCallback callback = nullptr);
3030
void setTimeZone(const std::string& timezone,
3131
PropertiesSetCallback callback = nullptr);
@@ -39,4 +39,4 @@ class ConnmanClock : public GProxy<ClockProperties> {
3939
friend class Connman;
4040
};
4141

42-
} // namespace Amarula::DBus
42+
} // namespace Amarula::DBus::G
Lines changed: 71 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,83 @@
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 {
115
class 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
Lines changed: 15 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,31 @@
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 {
115
class Connman;
126

13-
class ConnmanTechnology {
14-
public:
15-
struct Properties {
16-
bool powered = false;
17-
bool connected = false;
18-
bool tethering = false;
19-
std::string name;
20-
std::string type;
21-
};
22-
using PropertiesSetCallback = std::function<void(bool success)>;
23-
using PropertiesCallback = std::function<void(Properties&)>;
7+
struct TechProperties {
8+
bool powered = false;
9+
bool connected = false;
10+
bool tethering = false;
11+
std::string name;
12+
std::string type;
13+
};
2414

15+
class ConnmanTechnology : public DBusProxy<TechProperties> {
2516
private:
2617
using Self = ConnmanTechnology;
27-
size_t callback_counter_{0U};
28-
std::mutex mtx_;
29-
gpointer proxy_{nullptr};
30-
GProxy* gproxy_{nullptr};
31-
std::map<size_t, std::any> properties_callbacks_;
32-
template <typename T>
33-
auto prepareCallback(T callback) {
34-
std::unique_lock<std::mutex> const lock(mtx_);
35-
gproxy_->on_any_async_start();
36-
std::optional<size_t> call_counter = std::nullopt;
37-
if (callback != nullptr) {
38-
size_t index = ++callback_counter_;
39-
call_counter = index;
40-
properties_callbacks_[index] = std::move(callback);
41-
}
42-
return call_counter;
43-
}
44-
template <auto FinishFunc>
45-
static void finishAsyncCall(GObject* proxy, GAsyncResult* res,
46-
gpointer user_data);
4718

48-
void updateProperties(GVariant* properties,
49-
const std::optional<size_t>& counter);
50-
static void get_property_cb(GObject* proxy, GAsyncResult* res,
51-
gpointer user_data);
52-
static void on_properties_changed_cb(
53-
GDBusProxy* proxy, GVariant* changed_properties,
54-
const gchar* const* invalidated_properties, gpointer user_data);
55-
explicit ConnmanTechnology(GProxy* proxy, gchar* obj_path);
19+
explicit ConnmanTechnology(DBus* dbus, const gchar* obj_path);
5620

57-
public:
58-
ConnmanTechnology(const ConnmanTechnology&) = delete;
59-
auto operator=(const ConnmanTechnology&) = delete;
60-
ConnmanTechnology(ConnmanTechnology&&) = delete;
61-
auto operator=(ConnmanTechnology&&) = delete;
62-
63-
~ConnmanTechnology();
21+
auto updateProperties(GVariant* properties) const -> TechProperties final;
22+
using DBusProxy::DBusProxy;
6423

24+
public:
6525
void setPowered(bool powered, PropertiesSetCallback callback = nullptr);
6626
void scan(PropertiesSetCallback callback = nullptr);
67-
void getProperties(PropertiesCallback callback = nullptr);
6827

6928
friend class Connman;
7029
};
7130

72-
} // namespace Amarula::DBus
31+
} // namespace Amarula::DBus::G

0 commit comments

Comments
 (0)