diff options
author | Max Kellermann <max@musicpd.org> | 2018-06-04 21:41:51 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-06-04 21:41:51 +0200 |
commit | 9626523420e390dc826e56946ec6307ba3c4e2f1 (patch) | |
tree | 048bd9e715fa12ba96e67e369de85ba4766d986f /src | |
parent | 01501319847e2a9edcffec108567be4a5e38feab (diff) |
neighbor/udisks: move code to class UDisks2::ParseObjects(ReadMessageIter)
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/dbus/UDisks2.cxx | 15 | ||||
-rw-r--r-- | src/lib/dbus/UDisks2.hxx | 9 | ||||
-rw-r--r-- | src/neighbor/plugins/UdisksNeighborPlugin.cxx | 9 |
3 files changed, 27 insertions, 6 deletions
diff --git a/src/lib/dbus/UDisks2.cxx b/src/lib/dbus/UDisks2.cxx index 1cb231951..3c3f0c5c4 100644 --- a/src/lib/dbus/UDisks2.cxx +++ b/src/lib/dbus/UDisks2.cxx @@ -19,6 +19,7 @@ #include "UDisks2.hxx" #include "ReadIter.hxx" +#include "ObjectManager.hxx" #include "util/StringAPI.hxx" #include "Compiler.h" @@ -98,4 +99,18 @@ ParseObject(Object &o, ODBus::ReadMessageIter &&i) noexcept }); } +void +ParseObjects(ODBus::ReadMessageIter &&i, + std::function<void(Object &&o)> callback) +{ + using namespace ODBus; + + ForEachInterface(std::move(i), [&callback](const char *path, auto &&j){ + Object o(path); + ParseObject(o, std::move(j)); + if (o.IsValid()) + callback(std::move(o)); + }); +} + } // namespace UDisks2 diff --git a/src/lib/dbus/UDisks2.hxx b/src/lib/dbus/UDisks2.hxx index 23d7fe599..b0a068fd1 100644 --- a/src/lib/dbus/UDisks2.hxx +++ b/src/lib/dbus/UDisks2.hxx @@ -21,6 +21,7 @@ #define UDISKS2_HXX #include <string> +#include <functional> #define UDISKS2_PATH "/org/freedesktop/UDisks2" #define UDISKS2_INTERFACE "org.freedesktop.UDisks2" @@ -57,6 +58,14 @@ struct Object { void ParseObject(Object &o, ODBus::ReadMessageIter &&i) noexcept; +/** + * Parse objects from an array/dictionary and invoke the callback for + * each. + */ +void +ParseObjects(ODBus::ReadMessageIter &&i, + std::function<void(Object &&o)> callback); + } // namespace UDisks2 #endif diff --git a/src/neighbor/plugins/UdisksNeighborPlugin.cxx b/src/neighbor/plugins/UdisksNeighborPlugin.cxx index 43e7fb056..dc809062d 100644 --- a/src/neighbor/plugins/UdisksNeighborPlugin.cxx +++ b/src/neighbor/plugins/UdisksNeighborPlugin.cxx @@ -231,12 +231,9 @@ UdisksNeighborExplorer::OnListNotify(ODBus::Message reply) noexcept return; } - ForEachInterface(i.Recurse(), [this](const char *path, auto &&j){ - UDisks2::Object o(path); - UDisks2::ParseObject(o, std::move(j)); - if (o.IsValid()) - Insert(std::move(o)); - }); + ParseObjects(i.Recurse(), + std::bind(&UdisksNeighborExplorer::Insert, + this, std::placeholders::_1)); } inline DBusHandlerResult |