Commit 96265234 authored by Max Kellermann's avatar Max Kellermann

neighbor/udisks: move code to class UDisks2::ParseObjects(ReadMessageIter)

parent 01501319
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "UDisks2.hxx" #include "UDisks2.hxx"
#include "ReadIter.hxx" #include "ReadIter.hxx"
#include "ObjectManager.hxx"
#include "util/StringAPI.hxx" #include "util/StringAPI.hxx"
#include "Compiler.h" #include "Compiler.h"
...@@ -98,4 +99,18 @@ ParseObject(Object &o, ODBus::ReadMessageIter &&i) noexcept ...@@ -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 } // namespace UDisks2
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#define UDISKS2_HXX #define UDISKS2_HXX
#include <string> #include <string>
#include <functional>
#define UDISKS2_PATH "/org/freedesktop/UDisks2" #define UDISKS2_PATH "/org/freedesktop/UDisks2"
#define UDISKS2_INTERFACE "org.freedesktop.UDisks2" #define UDISKS2_INTERFACE "org.freedesktop.UDisks2"
...@@ -57,6 +58,14 @@ struct Object { ...@@ -57,6 +58,14 @@ struct Object {
void void
ParseObject(Object &o, ODBus::ReadMessageIter &&i) noexcept; 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 } // namespace UDisks2
#endif #endif
...@@ -231,12 +231,9 @@ UdisksNeighborExplorer::OnListNotify(ODBus::Message reply) noexcept ...@@ -231,12 +231,9 @@ UdisksNeighborExplorer::OnListNotify(ODBus::Message reply) noexcept
return; return;
} }
ForEachInterface(i.Recurse(), [this](const char *path, auto &&j){ ParseObjects(i.Recurse(),
UDisks2::Object o(path); std::bind(&UdisksNeighborExplorer::Insert,
UDisks2::ParseObject(o, std::move(j)); this, std::placeholders::_1));
if (o.IsValid())
Insert(std::move(o));
});
} }
inline DBusHandlerResult inline DBusHandlerResult
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment