diff options
author | Max Kellermann <max@musicpd.org> | 2018-06-04 21:48:39 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-06-04 21:50:34 +0200 |
commit | 7eee79c14570cea5ae2a890bb443cbbf6c05d657 (patch) | |
tree | 773e33f960c8c65680126b79f9db916ebb100b49 /src | |
parent | 9626523420e390dc826e56946ec6307ba3c4e2f1 (diff) |
neighbor/udisks: move code to class UDisks2::ParseObjects(ODBus::Message)
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/dbus/UDisks2.cxx | 16 | ||||
-rw-r--r-- | src/lib/dbus/UDisks2.hxx | 15 | ||||
-rw-r--r-- | src/neighbor/plugins/UdisksNeighborPlugin.cxx | 24 |
3 files changed, 36 insertions, 19 deletions
diff --git a/src/lib/dbus/UDisks2.cxx b/src/lib/dbus/UDisks2.cxx index 3c3f0c5c4..18610ecb7 100644 --- a/src/lib/dbus/UDisks2.cxx +++ b/src/lib/dbus/UDisks2.cxx @@ -18,6 +18,7 @@ */ #include "UDisks2.hxx" +#include "Message.hxx" #include "ReadIter.hxx" #include "ObjectManager.hxx" #include "util/StringAPI.hxx" @@ -113,4 +114,19 @@ ParseObjects(ODBus::ReadMessageIter &&i, }); } +void +ParseObjects(ODBus::Message &reply, + std::function<void(Object &&o)> callback) +{ + using namespace ODBus; + + reply.CheckThrowError(); + + ReadMessageIter i(*reply.Get()); + if (i.GetArgType() != DBUS_TYPE_ARRAY) + throw std::runtime_error("Malformed response"); + + ParseObjects(i.Recurse(), std::move(callback)); +} + } // namespace UDisks2 diff --git a/src/lib/dbus/UDisks2.hxx b/src/lib/dbus/UDisks2.hxx index b0a068fd1..a3675ad62 100644 --- a/src/lib/dbus/UDisks2.hxx +++ b/src/lib/dbus/UDisks2.hxx @@ -26,7 +26,10 @@ #define UDISKS2_PATH "/org/freedesktop/UDisks2" #define UDISKS2_INTERFACE "org.freedesktop.UDisks2" -namespace ODBus { class ReadMessageIter; } +namespace ODBus { +class Message; +class ReadMessageIter; +} namespace UDisks2 { @@ -66,6 +69,16 @@ void ParseObjects(ODBus::ReadMessageIter &&i, std::function<void(Object &&o)> callback); +/** + * Parse objects from a GetManagedObjects reply and invoke the + * callback for each. + * + * Throws on error. + */ +void +ParseObjects(ODBus::Message &reply, + std::function<void(Object &&o)> callback); + } // namespace UDisks2 #endif diff --git a/src/neighbor/plugins/UdisksNeighborPlugin.cxx b/src/neighbor/plugins/UdisksNeighborPlugin.cxx index dc809062d..a161346ec 100644 --- a/src/neighbor/plugins/UdisksNeighborPlugin.cxx +++ b/src/neighbor/plugins/UdisksNeighborPlugin.cxx @@ -34,7 +34,6 @@ #include "event/Call.hxx" #include "thread/Mutex.hxx" #include "thread/SafeSingleton.hxx" -#include "util/Domain.hxx" #include "util/Manual.hxx" #include "Log.hxx" @@ -43,8 +42,6 @@ #include <list> #include <map> -static constexpr Domain udisks_domain("udisks"); - static NeighborInfo ToNeighborInfo(const UDisks2::Object &o) noexcept { @@ -216,24 +213,15 @@ UdisksNeighborExplorer::Remove(const std::string &path) noexcept inline void UdisksNeighborExplorer::OnListNotify(ODBus::Message reply) noexcept { - using namespace ODBus; - - try { - reply.CheckThrowError(); + try{ + ParseObjects(reply, + std::bind(&UdisksNeighborExplorer::Insert, + this, std::placeholders::_1)); } catch (...) { - LogError(std::current_exception()); + LogError(std::current_exception(), + "Failed to parse GetManagedObjects reply"); return; } - - ReadMessageIter i(*reply.Get()); - if (i.GetArgType() != DBUS_TYPE_ARRAY) { - LogError(udisks_domain, "Malformed response"); - return; - } - - ParseObjects(i.Recurse(), - std::bind(&UdisksNeighborExplorer::Insert, - this, std::placeholders::_1)); } inline DBusHandlerResult |