Skip to content

Commit

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

#include <simpledbus/base/Connection.h>
#include <string>
#include <memory>

namespace SimpleDBus {

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

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

#include <simpledbus/advanced/RemoteInterface.h>
#include <simpledbus/advanced/ProxyBase.h>
#include <simpledbus/external/kvn_safe_callback.hpp>
#include <simpledbus/base/Path.h>

Expand All @@ -10,14 +11,11 @@

namespace SimpleDBus {

class RemoteProxy {
class RemoteProxy : public ProxyBase {
public:
RemoteProxy(std::shared_ptr<Connection> 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<RemoteProxy> path_get(const std::string& path);

Expand Down Expand Up @@ -91,4 +89,4 @@ class RemoteProxy {
std::recursive_mutex _child_access_mutex;
};

} // namespace SimpleDBus
} // namespace SimpleDBus
12 changes: 12 additions & 0 deletions simpledbus/src/advanced/ProxyBase.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "simpledbus/advanced/ProxyBase.h"

using namespace SimpleDBus;

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

RemoteProxy::RemoteProxy(std::shared_ptr<Connection> 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();
Expand All @@ -22,10 +22,6 @@ std::shared_ptr<RemoteProxy> RemoteProxy::path_create(const std::string& path) {
return std::make_shared<RemoteProxy>(_conn, _bus_name, path);
}

bool RemoteProxy::valid() const { return _valid; }

std::string RemoteProxy::path() const { return _path; }

const std::map<std::string, std::shared_ptr<RemoteProxy>>& RemoteProxy::children() { return _children; }

const std::map<std::string, std::shared_ptr<RemoteInterface>>& RemoteProxy::interfaces() { return _interfaces; }
Expand Down

0 comments on commit 56207d7

Please sign in to comment.