Skip to content

Commit

Permalink
Added InterfaceBase class for SimpleDBus
Browse files Browse the repository at this point in the history
  • Loading branch information
kdewald committed Sep 27, 2024
1 parent 7cb0bdd commit 218c38c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
1 change: 1 addition & 0 deletions simpledbus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions simpledbus/include/simpledbus/advanced/InterfaceBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <simpledbus/base/Connection.h>

#include <atomic>
#include <map>
#include <memory>
#include <mutex>
#include <string>

namespace SimpleDBus {

class InterfaceBase {
public:
InterfaceBase(std::shared_ptr<Connection> 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<Connection> _conn;
};

} // namespace SimpleDBus
9 changes: 2 additions & 7 deletions simpledbus/include/simpledbus/advanced/RemoteInterface.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <simpledbus/base/Connection.h>
#include <simpledbus/advanced/InterfaceBase.h>

#include <atomic>
#include <map>
Expand All @@ -10,7 +10,7 @@

namespace SimpleDBus {

class RemoteInterface {
class RemoteInterface : public InterfaceBase {
public:
RemoteInterface(std::shared_ptr<Connection> conn, const std::string& bus_name, const std::string& path,
const std::string& interface_name);
Expand Down Expand Up @@ -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<Connection> _conn;

std::recursive_mutex _property_update_mutex;
std::map<std::string, bool> _property_valid_map;

Expand Down
7 changes: 7 additions & 0 deletions simpledbus/src/advanced/InterfaceBase.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <simpledbus/advanced/InterfaceBase.h>

using namespace SimpleDBus;

InterfaceBase::InterfaceBase(std::shared_ptr<Connection> 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) {}
2 changes: 1 addition & 1 deletion simpledbus/src/advanced/RemoteInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using namespace SimpleDBus;

RemoteInterface::RemoteInterface(std::shared_ptr<Connection> 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 -----

Expand Down

0 comments on commit 218c38c

Please sign in to comment.