From aea6d354b7f0843a93ce52af2a5608e4708eee4c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 3 Jun 2018 20:26:15 +0200 Subject: [PATCH] lib/dbus/ObjectManager: use TypeTraits instead of CPP macro --- src/lib/dbus/ObjectManager.hxx | 39 ++++++++----------- src/neighbor/plugins/UdisksNeighborPlugin.cxx | 4 +- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/lib/dbus/ObjectManager.hxx b/src/lib/dbus/ObjectManager.hxx index e37ee28e8..e0a83e2d0 100644 --- a/src/lib/dbus/ObjectManager.hxx +++ b/src/lib/dbus/ObjectManager.hxx @@ -21,36 +21,29 @@ #define ODBUS_OBJECT_MANAGER_HXX #include "ReadIter.hxx" +#include "Types.hxx" #include #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>; + +using InterfacesType = + ArrayTypeTraits>; + +using InterfacesAddedType = + ConcatTypeAsString; + +using InterfacesRemovedType = ConcatTypeAsString>; + template inline void RecurseInterfaceDictEntry(ReadMessageIter &&i, F &&f) diff --git a/src/neighbor/plugins/UdisksNeighborPlugin.cxx b/src/neighbor/plugins/UdisksNeighborPlugin.cxx index b5927fd6c..658ecc39a 100644 --- a/src/neighbor/plugins/UdisksNeighborPlugin.cxx +++ b/src/neighbor/plugins/UdisksNeighborPlugin.cxx @@ -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