neighbor/udisks: move code to ForEachInterface()

This commit is contained in:
Max Kellermann
2018-06-03 14:47:12 +02:00
parent 24874b8286
commit 6c81fa1ec5
2 changed files with 43 additions and 18 deletions

View File

@@ -20,6 +20,8 @@
#ifndef ODBUS_OBJECT_MANAGER_HXX
#define ODBUS_OBJECT_MANAGER_HXX
#include "ReadIter.hxx"
#include <dbus/dbus.h>
#define DBUS_OM_INTERFACE "org.freedesktop.DBus.ObjectManager"
@@ -47,4 +49,32 @@
DBUS_TYPE_ARRAY_AS_STRING \
DBUS_TYPE_STRING_AS_STRING
namespace ODBus {
template<typename F>
inline void
RecurseInterfaceDictEntry(ReadMessageIter &&i, F &&f)
{
if (i.GetArgType() != DBUS_TYPE_OBJECT_PATH)
return;
const char *path = i.GetString();
i.Next();
if (i.GetArgType() != DBUS_TYPE_ARRAY)
return;
f(path, i.Recurse());
}
template<typename F>
inline void
ForEachInterface(ReadMessageIter &&i, F &&f)
{
i.ForEach(DBUS_TYPE_DICT_ENTRY, [&f](auto &&j){
RecurseInterfaceDictEntry(j.Recurse(), f);
});
}
}
#endif