lib/dbus/ObjectManager: use TypeTraits instead of CPP macro

This commit is contained in:
Max Kellermann 2018-06-03 20:26:15 +02:00
parent d3793dfe5b
commit aea6d354b7
2 changed files with 18 additions and 25 deletions

View File

@ -21,36 +21,29 @@
#define ODBUS_OBJECT_MANAGER_HXX
#include "ReadIter.hxx"
#include "Types.hxx"
#include <dbus/dbus.h>
#define DBUS_OM_INTERFACE "org.freedesktop.DBus.ObjectManager"
#define DBUS_OM_PROPERTIES_SIGNATURE \
DBUS_TYPE_ARRAY_AS_STRING \
DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING \
DBUS_TYPE_STRING_AS_STRING \
DBUS_TYPE_VARIANT_AS_STRING \
DBUS_DICT_ENTRY_END_CHAR_AS_STRING
#define DBUS_OM_INTERFACES_SIGNATURE \
DBUS_TYPE_ARRAY_AS_STRING \
DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING \
DBUS_TYPE_STRING_AS_STRING \
DBUS_OM_PROPERTIES_SIGNATURE \
DBUS_DICT_ENTRY_END_CHAR_AS_STRING
#define DBUS_OM_INTERFACES_ADDED_SIGNATURE \
DBUS_TYPE_OBJECT_PATH_AS_STRING \
DBUS_OM_INTERFACES_SIGNATURE
#define DBUS_OM_INTERFACES_REMOVED_SIGNATURE \
DBUS_TYPE_OBJECT_PATH_AS_STRING \
DBUS_TYPE_ARRAY_AS_STRING \
DBUS_TYPE_STRING_AS_STRING
namespace ODBus {
using PropertiesType =
ArrayTypeTraits<DictEntryTypeTraits<StringTypeTraits,
VariantTypeTraits>>;
using InterfacesType =
ArrayTypeTraits<DictEntryTypeTraits<StringTypeTraits,
PropertiesType>>;
using InterfacesAddedType =
ConcatTypeAsString<ObjectPathTypeTraits,
InterfacesType>;
using InterfacesRemovedType = ConcatTypeAsString<ObjectPathTypeTraits,
ArrayTypeTraits<StringTypeTraits>>;
template<typename F>
inline void
RecurseInterfaceDictEntry(ReadMessageIter &&i, F &&f)

View File

@ -353,7 +353,7 @@ UdisksNeighborExplorer::HandleMessage(DBusConnection *, DBusMessage *message) no
if (dbus_message_is_signal(message, DBUS_OM_INTERFACE,
"InterfacesAdded") &&
dbus_message_has_signature(message, DBUS_OM_INTERFACES_ADDED_SIGNATURE)) {
dbus_message_has_signature(message, InterfacesAddedType::value)) {
RecurseInterfaceDictEntry(ReadMessageIter(*message), [this](const char *path, auto &&i){
UdisksObject o(path);
if (ParseObject(o, std::move(i)) && o.IsValid())
@ -363,7 +363,7 @@ UdisksNeighborExplorer::HandleMessage(DBusConnection *, DBusMessage *message) no
return DBUS_HANDLER_RESULT_HANDLED;
} else if (dbus_message_is_signal(message, DBUS_OM_INTERFACE,
"InterfacesRemoved") &&
dbus_message_has_signature(message, DBUS_OM_INTERFACES_REMOVED_SIGNATURE)) {
dbus_message_has_signature(message, InterfacesRemovedType::value)) {
Remove(ReadMessageIter(*message).GetString());
return DBUS_HANDLER_RESULT_HANDLED;
} else