diff --git a/src/blackmisc/dbus.h b/src/blackmisc/dbus.h index 440898f86..79be3d19e 100644 --- a/src/blackmisc/dbus.h +++ b/src/blackmisc/dbus.h @@ -15,6 +15,7 @@ #include "blackmisc/blackmiscexport.h" #include "blackmisc/metaclass.h" #include "blackmisc/inheritancetraits.h" +#include "blackmisc/typetraits.h" #include #include @@ -22,6 +23,23 @@ namespace BlackMisc { class CEmpty; + namespace Private + { + //! \cond PRIVATE + template ::value, int> = 0> + void marshallMember(QDBusArgument &arg, const T &value) { value.marshallToDbus(arg); } + + template ::value, int> = 0> + void marshallMember(QDBusArgument &arg, const T &value) { arg << value; } + + template ::value, int> = 0> + void unmarshallMember(const QDBusArgument &arg, T &value) { value.unmarshallFromDbus(arg); } + + template ::value, int> = 0> + void unmarshallMember(const QDBusArgument &arg, T &value) { arg >> value; } + //! \endcond + } + namespace Mixin { /*! @@ -66,7 +84,7 @@ namespace BlackMisc { baseMarshall(static_cast *>(derived()), arg); auto meta = introspect().without(MetaFlags()); - meta.forEachMember(*derived(), [ & ](const auto &member) { arg << member; }); + meta.forEachMember(*derived(), [ & ](const auto &member) { Private::marshallMember(arg, member); }); } //! Unmarshall without begin/endStructure, for when composed within another object @@ -74,7 +92,7 @@ namespace BlackMisc { baseUnmarshall(static_cast *>(derived()), arg); auto meta = introspect().without(MetaFlags()); - meta.forEachMember(*derived(), [ & ](auto &member) { arg >> member; }); + meta.forEachMember(*derived(), [ & ](auto &member) { Private::unmarshallMember(arg, member); }); } private: diff --git a/src/blackmisc/typetraits.h b/src/blackmisc/typetraits.h index bcfd79d82..539a14cd9 100644 --- a/src/blackmisc/typetraits.h +++ b/src/blackmisc/typetraits.h @@ -19,6 +19,8 @@ #define BLACK_HAS_FIXED_CWG1558 #endif +class QDBusArgument; + namespace BlackMisc { @@ -181,6 +183,17 @@ namespace BlackMisc struct TIsEqualityComparable() == std::declval())>> : public std::true_type {}; //! \endcond + /*! + * Trait which is true if T has methods marshallToDbus and unmarshallFromDbus. + */ + template > + struct THasMarshallMethods : public std::false_type {}; + //! \cond + template + struct THasMarshallMethods().marshallToDbus(std::declval()), + std::declval().unmarshallFromDbus(std::declval()))>> : public std::true_type {}; + //! \endcond + /*! * Trait that detects if a type is a member of a parameter pack. */