neighbor/udisks: move code to class UDisks2::ParseObjects(ODBus::Message)
This commit is contained in:
parent
9626523420
commit
7eee79c145
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "UDisks2.hxx"
|
#include "UDisks2.hxx"
|
||||||
|
#include "Message.hxx"
|
||||||
#include "ReadIter.hxx"
|
#include "ReadIter.hxx"
|
||||||
#include "ObjectManager.hxx"
|
#include "ObjectManager.hxx"
|
||||||
#include "util/StringAPI.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
|
} // namespace UDisks2
|
||||||
|
|
|
@ -26,7 +26,10 @@
|
||||||
#define UDISKS2_PATH "/org/freedesktop/UDisks2"
|
#define UDISKS2_PATH "/org/freedesktop/UDisks2"
|
||||||
#define UDISKS2_INTERFACE "org.freedesktop.UDisks2"
|
#define UDISKS2_INTERFACE "org.freedesktop.UDisks2"
|
||||||
|
|
||||||
namespace ODBus { class ReadMessageIter; }
|
namespace ODBus {
|
||||||
|
class Message;
|
||||||
|
class ReadMessageIter;
|
||||||
|
}
|
||||||
|
|
||||||
namespace UDisks2 {
|
namespace UDisks2 {
|
||||||
|
|
||||||
|
@ -66,6 +69,16 @@ void
|
||||||
ParseObjects(ODBus::ReadMessageIter &&i,
|
ParseObjects(ODBus::ReadMessageIter &&i,
|
||||||
std::function<void(Object &&o)> callback);
|
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
|
} // namespace UDisks2
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
#include "event/Call.hxx"
|
#include "event/Call.hxx"
|
||||||
#include "thread/Mutex.hxx"
|
#include "thread/Mutex.hxx"
|
||||||
#include "thread/SafeSingleton.hxx"
|
#include "thread/SafeSingleton.hxx"
|
||||||
#include "util/Domain.hxx"
|
|
||||||
#include "util/Manual.hxx"
|
#include "util/Manual.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
|
@ -43,8 +42,6 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
static constexpr Domain udisks_domain("udisks");
|
|
||||||
|
|
||||||
static NeighborInfo
|
static NeighborInfo
|
||||||
ToNeighborInfo(const UDisks2::Object &o) noexcept
|
ToNeighborInfo(const UDisks2::Object &o) noexcept
|
||||||
{
|
{
|
||||||
|
@ -216,24 +213,15 @@ UdisksNeighborExplorer::Remove(const std::string &path) noexcept
|
||||||
inline void
|
inline void
|
||||||
UdisksNeighborExplorer::OnListNotify(ODBus::Message reply) noexcept
|
UdisksNeighborExplorer::OnListNotify(ODBus::Message reply) noexcept
|
||||||
{
|
{
|
||||||
using namespace ODBus;
|
try{
|
||||||
|
ParseObjects(reply,
|
||||||
try {
|
std::bind(&UdisksNeighborExplorer::Insert,
|
||||||
reply.CheckThrowError();
|
this, std::placeholders::_1));
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
LogError(std::current_exception());
|
LogError(std::current_exception(),
|
||||||
|
"Failed to parse GetManagedObjects reply");
|
||||||
return;
|
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
|
inline DBusHandlerResult
|
||||||
|
|
Loading…
Reference in New Issue