Skip to content

Commit

Permalink
Removed unused functions in production code.
Browse files Browse the repository at this point in the history
  • Loading branch information
kdewald committed Sep 27, 2024
1 parent 56207d7 commit f9d1222
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 61 deletions.
8 changes: 0 additions & 8 deletions simpledbus/include/simpledbus/advanced/RemoteProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ class RemoteProxy : public ProxyBase {
std::string introspect();

// ----- INTERFACE HANDLING -----
size_t interfaces_count();
bool interfaces_loaded();
void interfaces_load(Holder managed_interfaces);
void interfaces_reload(Holder managed_interfaces);
void interfaces_unload(Holder removed_interfaces);

// ----- CHILD HANDLING -----
Expand Down Expand Up @@ -76,12 +74,6 @@ class RemoteProxy : public ProxyBase {
}

protected:
bool _valid;
std::string _path;
std::string _bus_name;

std::shared_ptr<Connection> _conn;

std::map<std::string, std::shared_ptr<RemoteInterface>> _interfaces;
std::map<std::string, std::shared_ptr<RemoteProxy>> _children;

Expand Down
20 changes: 0 additions & 20 deletions simpledbus/src/advanced/RemoteProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,6 @@ std::shared_ptr<RemoteInterface> RemoteProxy::interface_get(const std::string& n
return _interfaces[name];
}

size_t RemoteProxy::interfaces_count() {
size_t count = 0;
std::scoped_lock lock(_interface_access_mutex);
for (auto& [iface_name, interface] : _interfaces) {
if (interface->is_loaded()) {
count++;
}
}
return count;
}

void RemoteProxy::interfaces_load(Holder managed_interfaces) {
auto managed_interface = managed_interfaces.get_dict_string();

Expand All @@ -73,15 +62,6 @@ void RemoteProxy::interfaces_load(Holder managed_interfaces) {
}
}

void RemoteProxy::interfaces_reload(Holder managed_interfaces) {
std::scoped_lock lock(_interface_access_mutex);
for (auto& [iface_name, interface] : _interfaces) {
interface->unload();
}

interfaces_load(managed_interfaces);
}

void RemoteProxy::interfaces_unload(SimpleDBus::Holder removed_interfaces) {
std::scoped_lock lock(_interface_access_mutex);
for (auto& option : removed_interfaces.get_array()) {
Expand Down
24 changes: 17 additions & 7 deletions simpledbus/test/src/test_proxy_children.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@

using namespace SimpleDBus;

TEST(ProxyChildren, AppendChild) {
static size_t count_interfaces(RemoteProxy& proxy) {
size_t count = 0;
for (auto& [iface_name, interface] : proxy.interfaces()) {
if (interface->is_loaded()) {
count++;
}
}
return count;
}

TEST(RemoteProxyChildren, AppendChild) {
RemoteProxy p = RemoteProxy(nullptr, "", "/a/b");

p.path_add("/a/b/c", Holder());
Expand All @@ -13,7 +23,7 @@ TEST(ProxyChildren, AppendChild) {
EXPECT_EQ("/a/b/c", p.children().at("/a/b/c")->path());
}

TEST(ProxyChildren, AppendRepeatedChild) {
TEST(RemoteProxyChildren, AppendRepeatedChild) {
RemoteProxy p = RemoteProxy(nullptr, "", "/a/b");
p.path_add("/a/b/c", Holder());

Expand All @@ -22,7 +32,7 @@ TEST(ProxyChildren, AppendRepeatedChild) {
EXPECT_EQ(1, p.children().size());
}

TEST(ProxyChildren, AppendExtendedChild) {
TEST(RemoteProxyChildren, AppendExtendedChild) {
RemoteProxy p = RemoteProxy(nullptr, "", "/");
p.path_add("/a/b/c/d", Holder());

Expand All @@ -42,7 +52,7 @@ TEST(ProxyChildren, AppendExtendedChild) {
ASSERT_EQ(1, p_a_b_c->children().count("/a/b/c/d"));
}

TEST(ProxyChildren, RemoveSelf) {
TEST(RemoteProxyChildren, RemoveSelf) {
RemoteProxy p = RemoteProxy(nullptr, "", "/");

// Should notify that the proxy can be safely deleted, as nothing worth keeping is left
Expand All @@ -64,7 +74,7 @@ TEST(ProxyChildren, RemoveSelf) {
ASSERT_EQ(0, p.children().size());
}

TEST(ProxyChildren, RemoveChildNoInterfaces) {
TEST(RemoteProxyChildren, RemoveChildNoInterfaces) {
RemoteProxy p = RemoteProxy(nullptr, "", "/");
p.path_add("/a", Holder());

Expand All @@ -81,7 +91,7 @@ TEST(ProxyChildren, RemoveChildNoInterfaces) {
ASSERT_EQ(0, p.children().size());
}

TEST(ProxyChildren, RemoveChildWithInterfaces) {
TEST(RemoteProxyChildren, RemoveChildWithInterfaces) {
RemoteProxy p = RemoteProxy(nullptr, "", "/");

Holder managed_interfaces = Holder::create_dict();
Expand All @@ -97,7 +107,7 @@ TEST(ProxyChildren, RemoveChildWithInterfaces) {
ASSERT_EQ(1, p.children().size());
{
std::shared_ptr<RemoteProxy> p_a = std::dynamic_pointer_cast<RemoteProxy>(p.children().at("/a"));
ASSERT_EQ(1, p_a->interfaces_count());
ASSERT_EQ(1, count_interfaces(*p_a));
ASSERT_EQ(1, p_a->interfaces().count("i.1"));
}

Expand Down
42 changes: 17 additions & 25 deletions simpledbus/test/src/test_proxy_interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@

using namespace SimpleDBus;

TEST(ProxyInterfaces, LoadInterfaces) {
static size_t count_interfaces(RemoteProxy& proxy) {
size_t count = 0;
for (auto& [iface_name, interface] : proxy.interfaces()) {
if (interface->is_loaded()) {
count++;
}
}
return count;
}

TEST(RemoteProxyInterfaces, LoadInterfaces) {
Holder managed_interfaces = Holder::create_dict();
managed_interfaces.dict_append(Holder::STRING, "i.1", Holder());

Expand All @@ -20,55 +30,37 @@ TEST(ProxyInterfaces, LoadInterfaces) {
EXPECT_EQ(1, h.interfaces().count("i.1"));
}

TEST(ProxyInterfaces, UnloadInterfaces) {
TEST(RemoteProxyInterfaces, UnloadInterfaces) {
Holder managed_interfaces = Holder::create_dict();
managed_interfaces.dict_append(Holder::STRING, "i.1", Holder());
managed_interfaces.dict_append(Holder::STRING, "i.2", Holder());
managed_interfaces.dict_append(Holder::STRING, "i.3", Holder());

RemoteProxy h = RemoteProxy(nullptr, "", "/");
h.interfaces_load(managed_interfaces);
EXPECT_EQ(3, h.interfaces_count());
EXPECT_EQ(3, count_interfaces(h));

Holder removed_interfaces = Holder::create_array();
removed_interfaces.array_append(Holder::create_string("i.3"));
h.interfaces_unload(removed_interfaces);

EXPECT_EQ(2, h.interfaces_count());
EXPECT_EQ(2, count_interfaces(h));
EXPECT_TRUE(h.interfaces_loaded());
EXPECT_FALSE(h.interfaces().at("i.3")->is_loaded());

removed_interfaces = Holder::create_array();
removed_interfaces.array_append(Holder::create_string("i.2"));
h.interfaces_unload(removed_interfaces);

EXPECT_EQ(1, h.interfaces_count());
EXPECT_EQ(1, count_interfaces(h));
EXPECT_TRUE(h.interfaces_loaded());
EXPECT_FALSE(h.interfaces().at("i.2")->is_loaded());

removed_interfaces = Holder::create_array();
removed_interfaces.array_append(Holder::create_string("i.1"));
h.interfaces_unload(removed_interfaces);

EXPECT_EQ(0, h.interfaces_count());
EXPECT_EQ(0, count_interfaces(h));
EXPECT_FALSE(h.interfaces_loaded());
EXPECT_FALSE(h.interfaces().at("i.1")->is_loaded());
}

TEST(ProxyInterfaces, ReloadInterfaces) {
Holder managed_interfaces = Holder::create_dict();
managed_interfaces.dict_append(Holder::STRING, "i.1", Holder());
managed_interfaces.dict_append(Holder::STRING, "i.2", Holder());
managed_interfaces.dict_append(Holder::STRING, "i.3", Holder());

RemoteProxy h = RemoteProxy(nullptr, "", "/");
h.interfaces_load(managed_interfaces);
EXPECT_EQ(3, h.interfaces_count());

managed_interfaces = Holder::create_dict();
managed_interfaces.dict_append(Holder::STRING, "i.1", Holder());
managed_interfaces.dict_append(Holder::STRING, "i.3", Holder());
h.interfaces_reload(managed_interfaces);

EXPECT_EQ(2, h.interfaces_count());
}
}
2 changes: 1 addition & 1 deletion simpledbus/test/src/test_proxy_lifetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using namespace SimpleDBus;

TEST(ProxyLifetime, Validity) {
TEST(RemoteProxyLifetime, Validity) {
RemoteProxy p = RemoteProxy(nullptr, "", "/");

// A newly created proxy should always be valid.
Expand Down

0 comments on commit f9d1222

Please sign in to comment.