From 218c38c4dba3b143e80a1590f17eb9e5d41e3339 Mon Sep 17 00:00:00 2001 From: Kevin Dewald Date: Thu, 26 Sep 2024 23:46:18 -0700 Subject: [PATCH] Added InterfaceBase class for SimpleDBus --- simpledbus/CMakeLists.txt | 1 + .../simpledbus/advanced/InterfaceBase.h | 29 +++++++++++++++++++ .../simpledbus/advanced/RemoteInterface.h | 9 ++---- simpledbus/src/advanced/InterfaceBase.cpp | 7 +++++ simpledbus/src/advanced/RemoteInterface.cpp | 2 +- 5 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 simpledbus/include/simpledbus/advanced/InterfaceBase.h create mode 100644 simpledbus/src/advanced/InterfaceBase.cpp diff --git a/simpledbus/CMakeLists.txt b/simpledbus/CMakeLists.txt index 72e60739..036bf121 100644 --- a/simpledbus/CMakeLists.txt +++ b/simpledbus/CMakeLists.txt @@ -33,6 +33,7 @@ endif() 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/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/InterfaceBase.h b/simpledbus/include/simpledbus/advanced/InterfaceBase.h new file mode 100644 index 00000000..38ff846c --- /dev/null +++ b/simpledbus/include/simpledbus/advanced/InterfaceBase.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +#include +#include +#include +#include +#include + +namespace SimpleDBus { + +class InterfaceBase { + public: + InterfaceBase(std::shared_ptr conn, const std::string& bus_name, const std::string& path, + const std::string& interface_name); + + virtual ~InterfaceBase() = default; + + virtual void message_handle(Message& msg) = 0; + + protected: + std::string _path; + std::string _bus_name; + std::string _interface_name; + std::shared_ptr _conn; +}; + +} // namespace SimpleDBus diff --git a/simpledbus/include/simpledbus/advanced/RemoteInterface.h b/simpledbus/include/simpledbus/advanced/RemoteInterface.h index b4bb3bd0..ebffccad 100644 --- a/simpledbus/include/simpledbus/advanced/RemoteInterface.h +++ b/simpledbus/include/simpledbus/advanced/RemoteInterface.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include @@ -10,7 +10,7 @@ namespace SimpleDBus { -class RemoteInterface { +class RemoteInterface : public InterfaceBase { public: RemoteInterface(std::shared_ptr conn, const std::string& bus_name, const std::string& path, const std::string& interface_name); @@ -42,11 +42,6 @@ class RemoteInterface { protected: std::atomic_bool _loaded{true}; - std::string _path; - std::string _bus_name; - std::string _interface_name; - std::shared_ptr _conn; - std::recursive_mutex _property_update_mutex; std::map _property_valid_map; diff --git a/simpledbus/src/advanced/InterfaceBase.cpp b/simpledbus/src/advanced/InterfaceBase.cpp new file mode 100644 index 00000000..ac06ae7c --- /dev/null +++ b/simpledbus/src/advanced/InterfaceBase.cpp @@ -0,0 +1,7 @@ +#include + +using namespace SimpleDBus; + +InterfaceBase::InterfaceBase(std::shared_ptr conn, const std::string& bus_name, const std::string& path, + const std::string& interface_name) + : _conn(conn), _bus_name(bus_name), _path(path), _interface_name(interface_name) {} diff --git a/simpledbus/src/advanced/RemoteInterface.cpp b/simpledbus/src/advanced/RemoteInterface.cpp index d1d1b059..092201fc 100644 --- a/simpledbus/src/advanced/RemoteInterface.cpp +++ b/simpledbus/src/advanced/RemoteInterface.cpp @@ -5,7 +5,7 @@ using namespace SimpleDBus; RemoteInterface::RemoteInterface(std::shared_ptr conn, const std::string& bus_name, const std::string& path, const std::string& interface_name) - : _conn(conn), _bus_name(bus_name), _path(path), _interface_name(interface_name), _loaded(true) {} + : InterfaceBase(conn, bus_name, path, interface_name), _loaded(true) {} // ----- LIFE CYCLE -----