From 56207d79617163e022d5a3b1d40a80c27ead2d9e Mon Sep 17 00:00:00 2001 From: Kevin Dewald Date: Thu, 26 Sep 2024 23:56:12 -0700 Subject: [PATCH] Added ProxyBase class for SimpleDBus --- simpledbus/CMakeLists.txt | 1 + .../include/simpledbus/advanced/ProxyBase.h | 25 +++++++++++++++++++ .../include/simpledbus/advanced/RemoteProxy.h | 8 +++--- simpledbus/src/advanced/ProxyBase.cpp | 12 +++++++++ simpledbus/src/advanced/RemoteProxy.cpp | 6 +---- 5 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 simpledbus/include/simpledbus/advanced/ProxyBase.h create mode 100644 simpledbus/src/advanced/ProxyBase.cpp diff --git a/simpledbus/CMakeLists.txt b/simpledbus/CMakeLists.txt index 036bf121..dc4ce8db 100644 --- a/simpledbus/CMakeLists.txt +++ b/simpledbus/CMakeLists.txt @@ -34,6 +34,7 @@ set(SIMPLEDBUS_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/include) set(SIMPLEDBUS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/advanced/InterfaceBase.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/advanced/ProxyBase.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/advanced/RemoteInterface.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/advanced/RemoteProxy.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/base/Connection.cpp diff --git a/simpledbus/include/simpledbus/advanced/ProxyBase.h b/simpledbus/include/simpledbus/advanced/ProxyBase.h new file mode 100644 index 00000000..835590a5 --- /dev/null +++ b/simpledbus/include/simpledbus/advanced/ProxyBase.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include +#include + +namespace SimpleDBus { + +class ProxyBase : public std::enable_shared_from_this { + public: + ProxyBase(std::shared_ptr conn, const std::string& bus_name, const std::string& path); + virtual ~ProxyBase(); + + bool valid() const; + std::string path() const; + + protected: + bool _valid; + + std::string _path; + std::string _bus_name; + std::shared_ptr _conn; +}; + +} // namespace SimpleDBus \ No newline at end of file diff --git a/simpledbus/include/simpledbus/advanced/RemoteProxy.h b/simpledbus/include/simpledbus/advanced/RemoteProxy.h index e8f9936d..409207ee 100644 --- a/simpledbus/include/simpledbus/advanced/RemoteProxy.h +++ b/simpledbus/include/simpledbus/advanced/RemoteProxy.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -10,14 +11,11 @@ namespace SimpleDBus { -class RemoteProxy { +class RemoteProxy : public ProxyBase { public: RemoteProxy(std::shared_ptr conn, const std::string& bus_name, const std::string& path); virtual ~RemoteProxy(); - bool valid() const; - std::string path() const; - bool path_exists(const std::string& path); std::shared_ptr path_get(const std::string& path); @@ -91,4 +89,4 @@ class RemoteProxy { std::recursive_mutex _child_access_mutex; }; -} // namespace SimpleDBus +} // namespace SimpleDBus \ No newline at end of file diff --git a/simpledbus/src/advanced/ProxyBase.cpp b/simpledbus/src/advanced/ProxyBase.cpp new file mode 100644 index 00000000..5c5cedd8 --- /dev/null +++ b/simpledbus/src/advanced/ProxyBase.cpp @@ -0,0 +1,12 @@ +#include "simpledbus/advanced/ProxyBase.h" + +using namespace SimpleDBus; + +ProxyBase::ProxyBase(std::shared_ptr conn, const std::string& bus_name, const std::string& path) + : _conn(conn), _bus_name(bus_name), _path(path), _valid(true) {} + +ProxyBase::~ProxyBase() {} + +bool ProxyBase::valid() const { return _valid; } + +std::string ProxyBase::path() const { return _path; } diff --git a/simpledbus/src/advanced/RemoteProxy.cpp b/simpledbus/src/advanced/RemoteProxy.cpp index 6d5c9f2b..378550be 100644 --- a/simpledbus/src/advanced/RemoteProxy.cpp +++ b/simpledbus/src/advanced/RemoteProxy.cpp @@ -7,7 +7,7 @@ using namespace SimpleDBus; RemoteProxy::RemoteProxy(std::shared_ptr conn, const std::string& bus_name, const std::string& path) - : _conn(conn), _bus_name(bus_name), _path(path), _valid(true) {} + : ProxyBase(conn, bus_name, path) {} RemoteProxy::~RemoteProxy() { on_child_created.unload(); @@ -22,10 +22,6 @@ std::shared_ptr RemoteProxy::path_create(const std::string& path) { return std::make_shared(_conn, _bus_name, path); } -bool RemoteProxy::valid() const { return _valid; } - -std::string RemoteProxy::path() const { return _path; } - const std::map>& RemoteProxy::children() { return _children; } const std::map>& RemoteProxy::interfaces() { return _interfaces; }