diff --git a/libs/dbus/bin/dbusgen.py b/libs/dbus/bin/dbusgen.py index 69ba7b793..2a8e2b1d3 100644 --- a/libs/dbus/bin/dbusgen.py +++ b/libs/dbus/bin/dbusgen.py @@ -79,10 +79,10 @@ def symbol_int(self): def sig(self): return self.type_sig - def value_to_internal(s): + def value_to_internal(self, s): return s - def value_from_internal(s): + def value_from_internal(self, s): return s class QStringTypeNode(TypeNode): @@ -93,12 +93,40 @@ def __init__(self): self.type_sig = 's' self.top_node = None - def to_internal(s): + def value_to_internal(self, s): return 'QString::fromStdString(' + s + ')' - def from_internal(s): + def value_from_internal(self, s): return s + '.toStdString()' +class QUInt64TypeNode(TypeNode): + def __init__(self): + TypeNode.__init__(self) + self.csymbol = "uint64_t" + self.csymbol_internal = "unsigned long long" + self.type_sig = 't' + self.top_node = None + + def value_to_internal(self, s): + return 'static_cast(' + s + ')' + + def value_from_internal(self, s): + return 'static_cast(' + s + ')' + +class QInt64TypeNode(TypeNode): + def __init__(self): + TypeNode.__init__(self) + self.csymbol = "int64_t" + self.csymbol_internal = "long long" + self.type_sig = 'x' + self.top_node = None + + def value_to_internal(self, s): + return 'static_cast(' + s + ')' + + def value_from_internal(self, s): + return 'static_cast(' + s + ')' + class UserTypeNode(TypeNode): def __init__(self, top_node): TypeNode.__init__(self) @@ -193,15 +221,17 @@ def add_default_types(self): self.types['uint16']= TypeNode('uint16_t','q') self.types['int32']= TypeNode('int32_t','i') self.types['uint32']= TypeNode('uint32_t','u') - self.types['int64']= TypeNode('int64_t','x') - self.types['uint64']= TypeNode('uint64_t','t') self.types['bool']= TypeNode('bool','b') self.types['double']= TypeNode('double','d') if self.backend == 'qt': self.types['string']= QStringTypeNode() + self.types['int64']= QInt64TypeNode() + self.types['uint64']= QUInt64TypeNode() else: self.types['string']= TypeNode('std::string','s') + self.types['int64']= TypeNode('int64_t','x') + self.types['uint64']= TypeNode('uint64_t','t') def get_type(self, typename): if typename in self.types: @@ -565,7 +595,7 @@ def handle_namespace(self, node): base = os.path.splitext(os.path.basename(args[2]))[0] loader = jinja2.FileSystemLoader(directory, followlinks=True) - environment = jinja2.Environment(loader=loader, trim_blocks=True) + environment = jinja2.Environment(loader=loader, trim_blocks=True, lstrip_blocks=True) template = environment.get_template(filename) binding = TopNode(args[0], base, backend) diff --git a/libs/dbus/data/qt-cc.jinja b/libs/dbus/data/qt-cc.jinja index 335226e1c..8b849d02f 100644 --- a/libs/dbus/data/qt-cc.jinja +++ b/libs/dbus/data/qt-cc.jinja @@ -2,135 +2,73 @@ #include "config.h" #endif +#include #include -#include -#include - -#include -#include +#include #include "dbus/DBusBindingQt.hh" #include "dbus/DBusException.hh" #include "{{ model.include_filename }}.hh" -using namespace std; using namespace workrave::dbus; // // Marshaller // -class {{ model.name }}_Marshall : public DBusMarshallQt -{ -public: -{% for enum in model.enums %} -{% if enum.condition != '' %} -#if {{ enum.condition }} -{% endif %} - void get_{{ enum.qname }}(const QVariant &variant, {{ enum.symbol() }} &result); - QVariant put_{{ enum.qname }}(const {{ enum.symbol() }} &result); -{% if enum.condition %} -#endif // {{ enum.condition }} -{% endif %} -{% endfor %} - -{% for struct in model.structs %} -{% if struct.condition %} -#if {{ struct.condition }} -{% endif %} - void get_{{ struct.qname }}(const QVariant &variant, {{ struct.symbol() }} &result); - QVariant put_{{ struct.qname }}(const {{ struct.symbol() }} &result); -{% if struct.condition %} -#endif // {{ struct.condition }} -{% endif %} -{% endfor %} - -{% for seq in model.sequences %} -{% if seq.condition %} -#if {{ seq.condition }} -{% endif %} - void get_{{ seq.qname }}(const QVariant &variant, {{ seq.symbol() }} &result); - QVariant put_{{ seq.qname }}(const {{ seq.symbol() }} &result); -{% if seq.condition %} -#endif // {{ seq.condition }} -{% endif %} -{% endfor %} - -{% for dict in model.dictionaries %} -{% if dict.condition %} -#if {{ dict.condition }} -{% endif %} - void get_{{ dict.qname }}(const QVariant &variant, {{ dict.symbol() }} &result); - QVariant put_{{ dict.qname }}(const {{ dict.symbol() }} &result); -{% if dict.condition %} -#endif // {{ dict.condition }} -{% endif %} -{% endfor %} -}; - -// -// Enums -// - {% for enum in model.enums %} {% if enum.condition != '' %} #if {{ enum.condition }} {% endif %} -void -{{ model.name }}_Marshall::get_{{ enum.qname }}(const QVariant &variant, {{ enum.symbol() }} &result) +[[maybe_unused]] static QDBusArgument & +operator<<(QDBusArgument &arg, const {{ enum.symbol() }} &data) { std::string value; - try + switch (data) { - get_string(variant, value); - } - catch (const DBusRemoteException &e) - { - e << field_info("{{ enum.name }}"); - throw; - } - {% for e in enum.values %} - {%- if loop.first -%} - if - {%- else -%} - else if - {%- endif -%} - ("{{ e.name }}" == value) - { - result = {{ e.symbol() }}; - } + case {{ e.symbol() }}: + value = "{{ e.name }}"; + break; {% endfor %} - else - { + default: throw DBusRemoteException() << message_info("Type error in enum") << error_code_info(DBUS_ERROR_INVALID_ARGS) << actual_type_info("{{ enum.name }}"); } + + arg << QString::fromStdString(value); + return arg; } -QVariant -{{ model.name }}_Marshall::put_{{ enum.qname }}(const {{ enum.symbol() }} &result) +[[maybe_unused]] static const QDBusArgument & +operator>>(const QDBusArgument &arg, {{ enum.symbol() }} &data) { - string value; - switch (result) + QString value; + arg >> value; + +{% for e in enum.values %} + {% if loop.first %} + if + {%- else %} + else if + {%- endif %} + ("{{ e.name }}" == value) + { + data = {{ e.symbol() }}; + } +{% endfor %} + else { - {% for e in enum.values %} - case {{ e.symbol() }}: - value = "{{ e.name }}"; - break; - {% endfor %} - default: throw DBusRemoteException() << message_info("Type error in enum") << error_code_info(DBUS_ERROR_INVALID_ARGS) << actual_type_info("{{ enum.name }}"); } - - return put_string(value); + return arg; } {% if enum.condition %} @@ -139,68 +77,38 @@ QVariant {% endfor %} -// -// Structs -// {% for struct in model.structs %} {% if struct.condition %} #if {{ struct.condition }} {% endif %} - -void -{{ model.name }}_Marshall::get_{{ struct.qname }}(const QVariant &variant, {{ struct.symbol() }} &result) +[[maybe_unused]] static QDBusArgument & +operator<<(QDBusArgument &arg, const {{ struct.symbol() }} &data) { -{% set num_expected_fields = struct.fields | length %} - - const QDBusArgument arg = variant.value(); - - if (arg.currentType() != QDBusArgument::StructureType) - { - throw DBusRemoteException() - << message_info("Incorrect type") - << error_code_info(DBUS_ERROR_INVALID_ARGS) - << expected_type_info("{{ struct.name }}"); - } - arg.beginStructure(); {% for p in struct.fields %} - if (arg.atEnd()) - { - throw DBusRemoteException() - << message_info("Incorrect number of member in struct") - << error_code_info(DBUS_ERROR_INVALID_ARGS) - << actual_type_info("{{ struct.name }}"); - } - - try - { - QVariant {{ p.name }} = arg.asVariant(); - get_{{ p.type }}({{ p.name }}, result.{{ p.name }}); - } - catch (const DBusRemoteException &e) - { - e << field_info("{{ p.name }}"); - throw; - } + arg.appendVariant({{ model.get_type(p.type).value_to_internal('data.' + p.name) }}); {% endfor %} arg.endStructure(); + return arg; } - -QVariant -{{ model.name }}_Marshall::put_{{ struct.qname }}(const {{ struct.symbol() }} &result) +[[maybe_unused]] static const QDBusArgument & +operator>>(const QDBusArgument &arg, {{ struct.symbol() }} &data) { - QDBusArgument arg; - arg.beginStructure(); {% for p in struct.fields %} - arg.appendVariant(put_{{ p.type }}(result.{{ p.name }})); +{% if model.get_type(p.type).value_from_internal('x') == 'x' %} + arg >> data.{{ p.name }}; +{% else %} + {{ model.get_type(p.type).symbol_int() }} t_{{ p.name }} {}; + arg >> t_{{ p.name }}; + data.{{ p.name }} = {{ model.get_type(p.type).value_from_internal('t_' + p.name) }}; +{% endif %} {% endfor %} arg.endStructure(); - - return QVariant::fromValue(arg); + return arg; } {% if struct.condition %} @@ -209,145 +117,6 @@ QVariant {% endfor %} -// -// Sequences -// - -{% for seq in model.sequences %} - -{% if seq.condition %} -#if {{ seq.condition }} -{% endif %} - -void -{{ model.name }}_Marshall::get_{{ seq.qname }}(const QVariant &variant, {{ seq.symbol() }} &result) -{ - const QDBusArgument arg = variant.value(); - - if (arg.currentType() != QDBusArgument::ArrayType) - { - throw DBusRemoteException() - << message_info("Incorrect type") - << error_code_info(DBUS_ERROR_INVALID_ARGS) - << expected_type_info("{{ seq.name }}"); - } - - arg.beginArray(); - - while (!arg.atEnd()) - { - {{ model.get_type(seq.data_type).symbol() }} tmp; - try - { - get_{{ seq.data_type }}(arg.asVariant(), tmp); - } - catch (const DBusRemoteException &e) - { - e << field_info(string("[") + boost::lexical_cast(result.size()) + "]"); - throw; - } - - result.push_back(tmp); - } - - arg.endArray(); -} - -QVariant -{{ model.name }}_Marshall::put_{{ seq.qname }}(const {{ seq.symbol() }} &result) -{ - QDBusArgument arg; - - arg.beginArray(qMetaTypeId<{{ model.get_type(seq.data_type).symbol_int()}}>()); - for (auto &i : result) - { - arg.appendVariant(put_{{ seq.data_type }}(i)); - } - arg.endArray(); - - return QVariant::fromValue(arg); -} - -{% if seq.condition %} -#endif // {{ seq.condition }} -{% endif %} -{% endfor %} - -// -// Dictionaries -// - -{% for dict in model.dictionaries %} - -{% if dict.condition %} -#if {{ dict.condition }} -{% endif %} -void -{{ model.name }}_Marshall::get_{{ dict.qname }}(const QVariant &variant, {{ dict.symbol() }} &result) -{ - const QDBusArgument arg = variant.value(); - - if (arg.currentType() != QDBusArgument::MapType) - { - throw DBusRemoteException() - << message_info("Incorrect type") - << error_code_info(DBUS_ERROR_INVALID_ARGS) - << expected_type_info("{{ dict.name }}"); - } - - arg.beginMap(); - - while (!arg.atEnd()) - { - {{ model.get_type(dict.key_type).symbol() }} key; - {{ model.get_type(dict.value_type).symbol() }} value; - - arg.beginMapEntry(); - try - { - get_{{ dict.key_type }}(arg.asVariant(), key); - get_{{ dict.value_type }}(arg.asVariant(), value); - } - catch (const DBusRemoteException &e) - { - e << field_info(key); - throw; - } - arg.endMapEntry(); - - (result)[key] = value; - } - - arg.endMap(); -} - - -QVariant -{{ model.name }}_Marshall::put_{{ dict.qname }}(const {{ dict.symbol() }} &result) -{ - QDBusArgument arg; - - arg.beginMap(qMetaTypeId<{{ model.get_type(dict.key_type).symbol_int() }}>(), - qMetaTypeId<{{ model.get_type(dict.value_type).symbol_int() }}>()); - - for (auto &it : result) - { - arg.beginMapEntry(); - arg.appendVariant(put_{{ dict.key_type }}(it.first)); - arg.appendVariant(put_{{ dict.value_type }}(it.second)); - arg.endMapEntry(); - } - arg.endMap(); - - return QVariant::fromValue(arg); -} - -{% if dict.condition %} -#endif // {{ dict.condition }} -{% endif %} - -{% endfor %} - // // Interfaces // @@ -359,38 +128,38 @@ QVariant // {% if interface.condition != '' %} -#if {{ interface.condition }} +#if {{ interface.fcondition }} {% endif %} -{% for ns in interface.namespace_list %} -namespace {{ ns }} // interface {{ interface.name }} namespace +{% if interface.namespace_list | length > 0 %} +namespace {{ interface.namespace_list | join("::") }} // interface {{ interface.name }} namespace { -{% endfor %} +{% endif -%} -class {{ interface.qname }}_Stub : public DBusBindingQt, public {{ interface.qname }}, public {{ model.name }}_Marshall +class {{ interface.qname }}_Stub : public DBusBindingQt, public {{ interface.qname }} { private: - typedef void ({{ interface.qname }}_Stub::*DBusMethodPointer)(void *object, const QDBusMessage &message, const QDBusConnection &connection); + using DBusMethodPointer = void ({{ interface.qname }}_Stub::*)(void *object, const QDBusMessage &message, const QDBusConnection &connection); struct DBusMethod { - const string name; + std::string_view name; DBusMethodPointer fn; }; - virtual bool call(void *object, const QDBusMessage &message, const QDBusConnection &connection); + bool call(void *object, const QDBusMessage &message, const QDBusConnection &connection) override; - virtual const char *get_interface_introspect() + std::string_view get_interface_introspect() override { return interface_introspect; } public: - {{ interface.qname }}_Stub(IDBus::Ptr dbus); - virtual ~{{ interface.qname }}_Stub(); + explicit {{ interface.qname }}_Stub(IDBus::Ptr dbus); + ~{{ interface.qname }}_Stub() override = default; {% for m in interface.signals %} - void {{ m.qname }}(const string &path + void {{ m.qname }}(const std::string &path {% for p in m.params %} {% if p.hint == [] %} , {{ interface.get_type(p.type).symbol() }} {{ p.name }} @@ -400,7 +169,7 @@ public: , {{ interface.get_type(p.type).symbol() }} &{{ p.name }} {% endif %} {% endfor %} - ); + ) override; {% endfor %} @@ -409,17 +178,40 @@ private: void {{ m.qname }}(void *object, const QDBusMessage &message, const QDBusConnection &connection); {% endfor %} - static const DBusMethod method_table[]; - static const char *interface_introspect; + static constexpr std::array method_table = + { { +{% for method in interface.methods %} + {.name="{{ method.name }}", .fn=&{{ interface.qname }}_Stub::{{ method.qname }}} , +{% endfor %} + } }; + static constexpr std::string_view interface_introspect = + " \n" +{% for method in interface.methods %} + " \n" + {% for p in method.params %} + {% if p.direction == 'in' or p.direction == 'out' %} + " \n" + {% endif %} + {% endfor %} + " \n" +{% endfor %} + {% for signal in interface.signals %} + " \n" + {% for p in signal.params %} + " \n" + {% endfor %} + " \n" + {% endfor %} + " \n"; }; -{{ interface.qname }} *{{ interface.qname }}::instance(const ::workrave::dbus::IDBus::Ptr dbus) +{{ interface.qname }} *{{ interface.qname }}::instance(std::shared_ptr<::workrave::dbus::IDBus> dbus) { - {{ interface.qname }}_Stub *iface = NULL; + {{ interface.qname }}_Stub *iface = nullptr; DBusBinding *binding = dbus->find_binding("{{ interface.name }}"); - if (binding != NULL) + if (binding != nullptr) { iface = dynamic_cast<{{ interface.qname }}_Stub *>(binding); } @@ -432,27 +224,22 @@ private: { } -{{ interface.qname }}_Stub::~{{ interface.qname }}_Stub() -{ -} - bool {{ interface.qname }}_Stub::call(void *object, const QDBusMessage &message, const QDBusConnection &connection) { - string method_name = message.member().toStdString(); - const DBusMethod *table = method_table; - while (table->fn != NULL) + std::string method_name = message.member().toStdString(); + constexpr std::array table = method_table; + for (const auto &method : table) { - if (method_name == table->name) + if (method_name == method.name) { - DBusMethodPointer ptr = table->fn; - if (ptr != NULL) + DBusMethodPointer ptr = method.fn; + if (ptr != nullptr) { (this->*ptr)(object, message, connection); } return true; } - table++; } throw DBusRemoteException() << message_info("Unknown method") @@ -477,26 +264,26 @@ void {% if method.condition != '' %} #if {{ method.condition }} {% endif %} - try { {% if method.symbol() != "" %} - {{ interface.symbol() }} *dbus_object = static_cast<{{ interface.symbol() }} *>(object); + auto *dbus_object = static_cast<{{ interface.symbol() }} *>(object); {% else %} (void) object; {% endif %} {% for p in method.params %} - {{ interface.get_type(p.type).symbol() }} p_{{ p.name }} - {% if p.direction == 'bind' %} - = {{ p.bind }} - {% elif p.direction == 'sender' %} - = sender + {{ interface.get_type(p.type).symbol() }} p_{{ p.name }} + {%- if p.direction == 'bind' %} + = {{ p.bind }}; + {%- elif p.direction == 'sender' %} + = sender; + {%- else -%} + {}; {% endif %} - ; {% endfor %} - int num_in_args = message.arguments().size(); + auto num_in_args = message.arguments().size(); if (num_in_args != {{ method.num_in_args }}) { throw DBusRemoteException() @@ -507,42 +294,33 @@ void } {% for arg in method.params if arg.direction == 'in' %} - try - { - get_{{ arg.type }}(message.arguments().at({{ loop.index0 }}), p_{{ arg.name }}); - } - catch (const DBusRemoteException &e) - { - e << parameter_info("{{ arg.name }}"); - throw; - } + p_{{ arg.name }} = variant_to_value<{{ interface.get_type(arg.type).symbol() }}> (message.arguments().at({{ loop.index0 }})); {% endfor %} {% if method.symbol() != "" %} {% if method.return_type() != 'void' %} - p_{{ method.return_name() }} = - {% endif %} - dbus_object->{{ method.symbol() }}( - + p_{{ method.return_name() }} = + {%- endif %} + dbus_object->{{ method.symbol() }}( {% set comma = joiner(",") %} {% for p in method.params %} {% if 'return' not in p.hint %} {% if 'ptr' in p.hint %} - {{ comma() }} &p_{{ p.name }} + {{ comma() }} &p_{{ p.name }} {% else %} - {{ comma() }} p_{{ p.name }} + {{ comma() }} p_{{ p.name }} {% endif %} {% endif %} {% endfor %} ); {% endif %} - QDBusMessage reply = message.createReply(); + QDBusMessage reply = message.createReply(); {% if method.num_out_args > 0 %} {% for arg in method.params: %} {% if arg.direction == 'out' %} - reply << put_{{ arg.type }}(p_{{ arg.name }}); + reply << value_to_variant<{{ interface.get_type(arg.type).symbol() }}> (p_{{ arg.name }}); {% endif %} {% endfor %} {% endif %} @@ -577,7 +355,7 @@ void // Interface {{ interface.name }} signal {{ signal.name }} // -void {{ interface.qname }}_Stub::{{ signal.qname }}(const string &path +void {{ interface.qname }}_Stub::{{ signal.qname }}(const std::string &path {% for p in signal.params %} {% if p.hint == [] %} , {{ interface.get_type(p.type).symbol() }} p_{{ p.name }} @@ -594,9 +372,9 @@ void {{ interface.qname }}_Stub::{{ signal.qname }}(const string &path {% if signal.params|length > 0 %} {% for arg in signal.params: %} {% if 'ptr' in arg.hint %} - sig << = put_{{ arg.type }}(* p_{{ arg.name }}); + sig << value_to_variant<{{ interface.get_type(arg.type).symbol() }}> (* p_{{ arg.name }}); {% else %} - sig << put_{{ arg.type }}(p_{{ arg.name }}); + sig << value_to_variant<{{ interface.get_type(arg.type).symbol() }}> (p_{{ arg.name }}); {% endif %} {% endfor %} {% endif %} @@ -607,37 +385,9 @@ void {{ interface.qname }}_Stub::{{ signal.qname }}(const string &path {% endfor %} -const {{ interface.qname }}_Stub::DBusMethod {{ interface.qname }}_Stub::method_table[] = { -{% for method in interface.methods %} - { "{{ method.name }}", &{{ interface.qname }}_Stub::{{ method.qname }} }, -{% endfor %} - { "", NULL } -}; - -const char * -{{ interface.qname }}_Stub::interface_introspect = - " \n" -{% for method in interface.methods %} - " \n" - {% for p in method.params %} - {% if p.direction == 'in' or p.direction == 'out' %} - " \n" - {% endif %} - {% endfor %} - " \n" -{% endfor %} - {% for signal in interface.signals %} - " \n" - {% for p in signal.params %} - " \n" - {% endfor %} - " \n" - {% endfor %} - " \n"; - -{% for ns in interface.namespace_list|reverse %} -} // namespace {{ ns }} -{% endfor %} +{% if interface.namespace_list | length > 0%} +} // namespace {{ interface.namespace_list | join("::") }} +{% endif %} {% if interface.condition != '' %} #endif // {{ interface.condition }} @@ -656,6 +406,26 @@ void init_{{ model.name }}(IDBus::Ptr dbus) #endif // {{ interface.condition }} {% endif %} {% endfor %} + +{% for struct in model.structs %} +{% if struct.condition %} +#if {{ struct.condition }} +{% endif %} + qDBusRegisterMetaType<{{ struct.symbol() }}>(); +{% if struct.condition %} +#endif // {{ struct.condition }} +{% endif %} +{% endfor %} + +{% for enum in model.enums %} +{% if enum.condition != '' %} +#if {{ enum.condition }} +{% endif %} + qDBusRegisterMetaType<{{ enum.symbol() }}>(); +{% if enum.condition %} +#endif // {{ enum.condition }} +{% endif %} +{% endfor %} } {% for ns in model.namespace_list|reverse %} diff --git a/libs/dbus/data/qt-hh.jinja b/libs/dbus/data/qt-hh.jinja index a7a83612b..8d2359717 100644 --- a/libs/dbus/data/qt-hh.jinja +++ b/libs/dbus/data/qt-hh.jinja @@ -1,7 +1,9 @@ #ifndef DBUS_{{ model.guard }}_HH #define DBUS_{{ model.guard }}_HH -#include "dbus/DBusBindingQt.hh" +#include + +#include "dbus/IDBus.hh" // // Imports @@ -39,7 +41,6 @@ using namespace {{ ns }}; // {% for interface in model.interfaces %} - {% if interface.condition != '' %} #if {{ interface.condition }} {% endif %} @@ -62,20 +63,18 @@ using namespace {{ ns }}; {% endif %} {% endfor %} -{% for ns in interface.namespace_list %} -namespace {{ ns }} // interface {{ interface.name }} namespace +{% if interface.namespace_list | length > 0 %} +namespace {{ interface.namespace_list | join("::") }} // interface {{ interface.name }} namespace { -{% endfor %} +{% endif -%} class {{ interface.qname }} { public: - virtual ~{{ interface.qname }}() { } - - static {{ interface.qname }} *instance(const ::workrave::dbus::IDBus::Ptr dbus); - + virtual ~{{ interface.qname }}() = default; + static {{ interface.qname }} *instance(std::shared_ptr<::workrave::dbus::IDBus> dbus); {% for m in interface.signals %} - virtual void {{ m.qname }}(const std::string &path + virtual void {{ m.qname }}(const std::string &path {% for p in m.params %} {% if p.hint == [] %} , {{ interface.get_type(p.type).symbol() }} {{ p.name }} @@ -89,13 +88,13 @@ public: {% endfor %} }; -{% for ns in interface.namespace_list|reverse %} -} // namespace {{ ns }} -{% endfor %} +{% if interface.namespace_list | length > 0%} +} // namespace {{ interface.namespace_list | join("::") }} +{% endif %} {% if interface.condition != '' %} #endif // {{ interface.condition }} {% endif %} -{% endfor %} +{% endfor %} #endif // DBUS_{{ model.guard }}_HH diff --git a/libs/dbus/include/dbus/DBusBindingQt.hh b/libs/dbus/include/dbus/DBusBindingQt.hh index 9d33ff963..d9471c484 100644 --- a/libs/dbus/include/dbus/DBusBindingQt.hh +++ b/libs/dbus/include/dbus/DBusBindingQt.hh @@ -19,73 +19,184 @@ #define WORKRAVE_DBUS_DBUSBINDINGQT_HH #include +#include #include #include "dbus/DBusBinding.hh" #include "dbus/IDBus.hh" -namespace workrave +namespace workrave::dbus { - namespace dbus + class DBus; + + class IDBusPrivateQt + { + public: + using Ptr = std::shared_ptr; + virtual ~IDBusPrivateQt() = default; + IDBusPrivateQt() = default; + IDBusPrivateQt(const IDBusPrivateQt &) = delete; + IDBusPrivateQt &operator=(const IDBusPrivateQt &) = delete; + IDBusPrivateQt(IDBusPrivateQt &&) = delete; + IDBusPrivateQt &operator=(IDBusPrivateQt &&) = delete; + + virtual QDBusConnection get_connection() = 0; + }; + + class DBusBindingQt : public DBusBinding + { + public: + explicit DBusBindingQt(IDBus::Ptr dbus); + ~DBusBindingQt() override = default; + + virtual std::string_view get_interface_introspect() = 0; + virtual bool call(void *object, const QDBusMessage &message, const QDBusConnection &connection) = 0; + + protected: + IDBus::Ptr dbus; + }; + + template + struct QtCppTypeMap + { + static QMetaType::Type qtType() + { + return static_cast(QMetaType::fromType().id()); + } + static const char *qtName() + { + // return QMetaType::typeName(qtType()); + return QMetaType::fromType().name(); + } + static T convert(const QVariant &variant) + { + return variant.value(); + } + static QVariant convert(const T &value) + { + return QVariant::fromValue(value); + } + }; + + template<> + struct QtCppTypeMap + { + static QMetaType::Type qtType() + { + return QMetaType::QString; + } + static const char *qtName() + { + return "QString"; + } + static std::string convert(const QVariant &variant) + { + return variant.toString().toStdString(); + } + static QVariant convert(const std::string &value) + { + return QString::fromStdString(value); + } + }; + ; + + template<> + struct QtCppTypeMap { - class DBus; + static QMetaType::Type qtType() + { + return QMetaType::LongLong; + } + static const char *qtName() + { + return "qlonglong"; + } + static int64_t convert(const QVariant &variant) + { + return static_cast(variant.value()); + } + static QVariant convert(int64_t value) + { + return static_cast(value); + } + }; - class IDBusPrivateQt + template<> + struct QtCppTypeMap + { + static QMetaType::Type qtType() + { + return QMetaType::ULongLong; + } + static const char *qtName() { - public: - typedef std::shared_ptr Ptr; + return "qulonglong"; + } + static uint64_t convert(const QVariant &variant) + { + return static_cast(variant.value()); + } + static QVariant convert(int64_t value) + { + return static_cast(value); + } + }; + + template + T variant_to_value(const QVariant &variant) + { + if (static_cast(variant.typeId()) != QtCppTypeMap::qtType()) + { + throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) + << expected_type_info(QtCppTypeMap::qtName()) << actual_type_info(variant.typeName()); + } + return QtCppTypeMap::convert(variant); + } - virtual ~IDBusPrivateQt() + template + QVariant value_to_variant(const T &value) + { + if (static_cast(QMetaType::fromType().id()) != QtCppTypeMap::qtType()) { + throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) + << expected_type_info(QtCppTypeMap::qtName()) + << actual_type_info(QMetaType::fromType().name()); } + QVariant variant; + variant.setValue(QtCppTypeMap::convert(value)); + return variant; + } + + // class DBusMarshallQt + // { + // public: + // void get_int(const QVariant &variant, int &value); + // void get_uint8(const QVariant &variant, uint8_t &value); + // void get_uint16(const QVariant &variant, uint16_t &value); + // void get_int16(const QVariant &variant, int16_t &value); + // void get_uint32(const QVariant &variant, uint32_t &value); + // void get_int32(const QVariant &variant, int32_t &value); + // void get_uint64(const QVariant &variant, uint64_t &value); + // void get_int64(const QVariant &variant, int64_t &value); + // void get_bool(const QVariant &variant, bool &value); + // void get_double(const QVariant &variant, double &value); + // void get_string(const QVariant &variant, std::string &value); + // void get_string(const QVariant &variant, QString &value); - virtual QDBusConnection get_connection() = 0; - }; - - class DBusBindingQt : public DBusBinding - { - public: - explicit DBusBindingQt(IDBus::Ptr dbus); - ~DBusBindingQt() override = default; - - virtual const char *get_interface_introspect() = 0; - virtual bool call(void *object, const QDBusMessage &message, const QDBusConnection &connection) = 0; - - protected: - IDBus::Ptr dbus; - }; - - class DBusMarshallQt - { - public: - void get_int(const QVariant &variant, int &value); - void get_uint8(const QVariant &variant, uint8_t &value); - void get_uint16(const QVariant &variant, uint16_t &value); - void get_int16(const QVariant &variant, int16_t &value); - void get_uint32(const QVariant &variant, uint32_t &value); - void get_int32(const QVariant &variant, int32_t &value); - void get_uint64(const QVariant &variant, uint64_t &value); - void get_int64(const QVariant &variant, int64_t &value); - void get_bool(const QVariant &variant, bool &value); - void get_double(const QVariant &variant, double &value); - void get_string(const QVariant &variant, std::string &value); - void get_string(const QVariant &variant, QString &value); - - QVariant put_uint8(const uint8_t &value); - QVariant put_int(const int &value); - QVariant put_uint16(const uint16_t &value); - QVariant put_int16(const int16_t &value); - QVariant put_uint32(const uint32_t &value); - QVariant put_int32(const int32_t &value); - QVariant put_uint64(const uint64_t &value); - QVariant put_int64(const int64_t &value); - QVariant put_bool(const bool &value); - QVariant put_double(const double &value); - QVariant put_string(const std::string &value); - QVariant put_string(const QString &value); - }; - } // namespace dbus -} // namespace workrave + // QVariant put_uint8(const uint8_t &value); + // QVariant put_int(const int &value); + // QVariant put_uint16(const uint16_t &value); + // QVariant put_int16(const int16_t &value); + // QVariant put_uint32(const uint32_t &value); + // QVariant put_int32(const int32_t &value); + // QVariant put_uint64(const uint64_t &value); + // QVariant put_int64(const int64_t &value); + // QVariant put_bool(const bool &value); + // QVariant put_double(const double &value); + // QVariant put_string(const std::string &value); + // QVariant put_string(const QString &value); + // }; +} // namespace workrave::dbus #endif // WORKRAVE_DBUS_DBUSBINDINGQT_HH diff --git a/libs/dbus/src/DBusBindingQt.cc b/libs/dbus/src/DBusBindingQt.cc index d868210db..4b74c5f58 100644 --- a/libs/dbus/src/DBusBindingQt.cc +++ b/libs/dbus/src/DBusBindingQt.cc @@ -33,218 +33,234 @@ DBusBindingQt::DBusBindingQt(IDBus::Ptr dbus) { } -void -DBusMarshallQt::get_uint8(const QVariant &variant, uint8_t &value) -{ - if (static_cast(variant.typeId()) != QMetaType::UChar) - { - throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) - << expected_type_info(QVariant::fromValue(value).typeName()) - << actual_type_info(variant.typeName()); - } - value = variant.value(); -} +// // Template to map a QMetaType to a C++ type -void -DBusMarshallQt::get_int(const QVariant &variant, int &value) -{ - if (static_cast(variant.typeId()) != QMetaType::Int) - { - throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) - << expected_type_info(QVariant::fromValue(value).typeName()) - << actual_type_info(variant.typeName()); - } - value = variant.value(); -} +// template<> +// uint8_t +// checked_value(const QVariant &variant) +// { +// if (static_cast(variant.typeId()) != QMetaType::UChar) +// { +// throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) +// << expected_type_info(QVariant::fromValue(variant).typeName()) +// << actual_type_info(variant.typeName()); +// } +// return variant.value(); +// } -void -DBusMarshallQt::get_uint16(const QVariant &variant, uint16_t &value) -{ - if (static_cast(variant.typeId()) != QMetaType::UShort) - { - throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) - << expected_type_info(QVariant::fromValue(value).typeName()) - << actual_type_info(variant.typeName()); - } - value = variant.value(); -} +// template<> +// int +// checked_value(const QVariant &variant) +// { +// if (static_cast(variant.typeId()) != QMetaType::Int) +// { +// throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) +// << expected_type_info(QVariant::fromValue(variant).typeName()) +// << actual_type_info(variant.typeName()); +// } +// return variant.value(); +// } -void -DBusMarshallQt::get_int16(const QVariant &variant, int16_t &value) -{ - if (static_cast(variant.typeId()) != QMetaType::Short) - { - throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) - << expected_type_info(QVariant::fromValue(value).typeName()) - << actual_type_info(variant.typeName()); - } - value = variant.value(); -} +// void +// DBusMarshallQt::get_int(const QVariant &variant, int &value) +// { +// if (static_cast(variant.typeId()) != QMetaType::Int) +// { +// throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) +// << expected_type_info(QVariant::fromValue(value).typeName()) +// << actual_type_info(variant.typeName()); +// } +// value = variant.value(); +// } -void -DBusMarshallQt::get_uint32(const QVariant &variant, uint32_t &value) -{ - if (static_cast(variant.typeId()) != QMetaType::UInt) - { - throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) - << expected_type_info(QVariant::fromValue(value).typeName()) - << actual_type_info(variant.typeName()); - } - value = variant.value(); -} +// void +// DBusMarshallQt::get_uint16(const QVariant &variant, uint16_t &value) +// { +// if (static_cast(variant.typeId()) != QMetaType::UShort) +// { +// throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) +// << expected_type_info(QVariant::fromValue(value).typeName()) +// << actual_type_info(variant.typeName()); +// } +// value = variant.value(); +// } -void -DBusMarshallQt::get_int32(const QVariant &variant, int32_t &value) -{ - if (static_cast(variant.typeId()) != QMetaType::Int) - { - throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) - << expected_type_info(QVariant::fromValue(value).typeName()) - << actual_type_info(variant.typeName()); - } - value = variant.value(); -} +// void +// DBusMarshallQt::get_int16(const QVariant &variant, int16_t &value) +// { +// if (static_cast(variant.typeId()) != QMetaType::Short) +// { +// throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) +// << expected_type_info(QVariant::fromValue(value).typeName()) +// << actual_type_info(variant.typeName()); +// } +// value = variant.value(); +// } -void -DBusMarshallQt::get_uint64(const QVariant &variant, uint64_t &value) -{ - if (static_cast(variant.typeId()) != QMetaType::ULongLong) - { - throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) - << expected_type_info(QVariant::fromValue(value).typeName()) - << actual_type_info(variant.typeName()); - } - value = variant.value(); -} +// void +// DBusMarshallQt::get_uint32(const QVariant &variant, uint32_t &value) +// { +// if (static_cast(variant.typeId()) != QMetaType::UInt) +// { +// throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) +// << expected_type_info(QVariant::fromValue(value).typeName()) +// << actual_type_info(variant.typeName()); +// } +// value = variant.value(); +// } -void -DBusMarshallQt::get_int64(const QVariant &variant, int64_t &value) -{ - if (static_cast(variant.typeId()) != QMetaType::LongLong) - { - throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) - << expected_type_info(QVariant::fromValue(value).typeName()) - << actual_type_info(variant.typeName()); - } - value = variant.value(); -} +// void +// DBusMarshallQt::get_int32(const QVariant &variant, int32_t &value) +// { +// if (static_cast(variant.typeId()) != QMetaType::Int) +// { +// throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) +// << expected_type_info(QVariant::fromValue(value).typeName()) +// << actual_type_info(variant.typeName()); +// } +// value = variant.value(); +// } -void -DBusMarshallQt::get_bool(const QVariant &variant, bool &value) -{ - if (static_cast(variant.typeId()) != QMetaType::Bool) - { - throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) - << expected_type_info(QVariant::fromValue(value).typeName()) - << actual_type_info(variant.typeName()); - } - value = variant.value(); -} +// void +// DBusMarshallQt::get_uint64(const QVariant &variant, uint64_t &value) +// { +// if (static_cast(variant.typeId()) != QMetaType::ULongLong) +// { +// throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) +// << expected_type_info(QVariant::fromValue(value).typeName()) +// << actual_type_info(variant.typeName()); +// } +// value = variant.value(); +// } -void -DBusMarshallQt::get_double(const QVariant &variant, double &value) -{ - if (static_cast(variant.typeId()) != QMetaType::Double) - { - throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) - << expected_type_info(QVariant::fromValue(value).typeName()) - << actual_type_info(variant.typeName()); - } - value = variant.value(); -} +// void +// DBusMarshallQt::get_int64(const QVariant &variant, int64_t &value) +// { +// if (static_cast(variant.typeId()) != QMetaType::LongLong) +// { +// throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) +// << expected_type_info(QVariant::fromValue(value).typeName()) +// << actual_type_info(variant.typeName()); +// } +// value = variant.value(); +// } -void -DBusMarshallQt::get_string(const QVariant &variant, std::string &value) -{ - if (static_cast(variant.typeId()) != QMetaType::QString) - { - throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) - << expected_type_info(QVariant::fromValue(QString()).typeName()) - << actual_type_info(variant.typeName()); - } - value = variant.value().toStdString(); -} +// void +// DBusMarshallQt::get_bool(const QVariant &variant, bool &value) +// { +// if (static_cast(variant.typeId()) != QMetaType::Bool) +// { +// throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) +// << expected_type_info(QVariant::fromValue(value).typeName()) +// << actual_type_info(variant.typeName()); +// } +// value = variant.value(); +// } -void -DBusMarshallQt::get_string(const QVariant &variant, QString &value) -{ - if (static_cast(variant.typeId()) != QMetaType::QString) - { - throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) - << expected_type_info(QVariant::fromValue(value).typeName()) - << actual_type_info(variant.typeName()); - } - value = variant.value(); -} +// void +// DBusMarshallQt::get_double(const QVariant &variant, double &value) +// { +// if (static_cast(variant.typeId()) != QMetaType::Double) +// { +// throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) +// << expected_type_info(QVariant::fromValue(value).typeName()) +// << actual_type_info(variant.typeName()); +// } +// value = variant.value(); +// } -QVariant -DBusMarshallQt::put_int(const int &value) -{ - return QVariant(value); -} +// void +// DBusMarshallQt::get_string(const QVariant &variant, std::string &value) +// { +// if (static_cast(variant.typeId()) != QMetaType::QString) +// { +// throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) +// << expected_type_info(QVariant::fromValue(QString()).typeName()) +// << actual_type_info(variant.typeName()); +// } +// value = variant.value().toStdString(); +// } -QVariant -DBusMarshallQt::put_uint8(const uint8_t &value) -{ - return QVariant(value); -} +// void +// DBusMarshallQt::get_string(const QVariant &variant, QString &value) +// { +// if (static_cast(variant.typeId()) != QMetaType::QString) +// { +// throw DBusRemoteException() << message_info("Type error") << error_code_info(DBUS_ERROR_INVALID_ARGS) +// << expected_type_info(QVariant::fromValue(value).typeName()) +// << actual_type_info(variant.typeName()); +// } +// value = variant.value(); +// } -QVariant -DBusMarshallQt::put_uint16(const uint16_t &value) -{ - return QVariant(value); -} +// QVariant +// DBusMarshallQt::put_int(const int &value) +// { +// return QVariant(value); +// } -QVariant -DBusMarshallQt::put_int16(const int16_t &value) -{ - return QVariant(value); -} +// QVariant +// DBusMarshallQt::put_uint8(const uint8_t &value) +// { +// return QVariant(value); +// } -QVariant -DBusMarshallQt::put_uint32(const uint32_t &value) -{ - return QVariant(value); -} +// QVariant +// DBusMarshallQt::put_uint16(const uint16_t &value) +// { +// return QVariant(value); +// } -QVariant -DBusMarshallQt::put_int32(const int32_t &value) -{ - return QVariant(value); -} +// QVariant +// DBusMarshallQt::put_int16(const int16_t &value) +// { +// return QVariant(value); +// } -QVariant -DBusMarshallQt::put_uint64(const uint64_t &value) -{ - return QVariant(static_cast(value)); -} +// QVariant +// DBusMarshallQt::put_uint32(const uint32_t &value) +// { +// return QVariant(value); +// } -QVariant -DBusMarshallQt::put_int64(const int64_t &value) -{ - return QVariant(static_cast(value)); -} +// QVariant +// DBusMarshallQt::put_int32(const int32_t &value) +// { +// return QVariant(value); +// } -QVariant -DBusMarshallQt::put_double(const double &value) -{ - return QVariant(value); -} +// QVariant +// DBusMarshallQt::put_uint64(const uint64_t &value) +// { +// return QVariant(static_cast(value)); +// } -QVariant -DBusMarshallQt::put_bool(const bool &value) -{ - return QVariant(value); -} +// QVariant +// DBusMarshallQt::put_int64(const int64_t &value) +// { +// return QVariant(static_cast(value)); +// } -QVariant -DBusMarshallQt::put_string(const std::string &value) -{ - return QVariant(QString::fromStdString(value)); -} +// QVariant +// DBusMarshallQt::put_double(const double &value) +// { +// return QVariant(value); +// } -QVariant -DBusMarshallQt::put_string(const QString &value) -{ - return QVariant(value); -} +// QVariant +// DBusMarshallQt::put_bool(const bool &value) +// { +// return QVariant(value); +// } + +// QVariant +// DBusMarshallQt::put_string(const std::string &value) +// { +// return QVariant(QString::fromStdString(value)); +// } + +// QVariant +// DBusMarshallQt::put_string(const QString &value) +// { +// return QVariant(value); +// } diff --git a/libs/dbus/src/DBusQt.cc b/libs/dbus/src/DBusQt.cc index 4ca5d1a2c..fcd1423e3 100644 --- a/libs/dbus/src/DBusQt.cc +++ b/libs/dbus/src/DBusQt.cc @@ -103,13 +103,13 @@ DBusQt::introspect(const QString &path) const { string str; - ObjectCIter object_it = objects.find(path.toStdString()); + auto object_it = objects.find(path.toStdString()); if (object_it != objects.end()) { - for (auto &interface: object_it->second) + for (const auto &interface: object_it->second) { string interface_name = interface.first; - DBusBindingQt *binding = dynamic_cast(find_binding(interface_name)); + auto *binding = dynamic_cast(find_binding(interface_name)); if (binding != nullptr) { str += binding->get_interface_introspect(); @@ -132,7 +132,7 @@ DBusQt::handleMessage(const QDBusMessage &message, const QDBusConnection &connec void *cobject = find_object(path, interface_name); if (cobject != nullptr) { - DBusBindingQt *binding = dynamic_cast(find_binding(interface_name)); + auto *binding = dynamic_cast(find_binding(interface_name)); if (binding != nullptr) { success = binding->call(cobject, message, connection); diff --git a/libs/dbus/src/DBusQt.hh b/libs/dbus/src/DBusQt.hh index cec47d29a..3ca962ced 100644 --- a/libs/dbus/src/DBusQt.hh +++ b/libs/dbus/src/DBusQt.hh @@ -40,7 +40,7 @@ namespace workrave , public QDBusVirtualObject { public: - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; public: DBusQt(); @@ -76,17 +76,10 @@ namespace workrave bool seen; }; - typedef std::map Watched; - typedef Watched::iterator WatchIter; - typedef Watched::const_iterator WatchCIter; + using Watched = std::map; - //! Connection to the DBus. QDBusConnection connection; - - //! QDBusServiceWatcher watcher; - - //! Watched watched; }; } // namespace dbus diff --git a/libs/dbus/test/CMakeLists.txt b/libs/dbus/test/CMakeLists.txt index 45bfad7b5..d80f97af5 100644 --- a/libs/dbus/test/CMakeLists.txt +++ b/libs/dbus/test/CMakeLists.txt @@ -5,7 +5,6 @@ if (HAVE_DBUS AND HAVE_QT AND HAVE_TESTS) dbus_generate_source(${CMAKE_CURRENT_SOURCE_DIR}/test.xml ${CMAKE_CURRENT_BINARY_DIR} DBusTestGio gio) set(SERVER_QT_SRC ${SERVER_QT_SRC} - DBusTestData.cc DBusTestServer.cc DBusTestServerQt.cc DBusTestQt.cc @@ -16,7 +15,6 @@ if (HAVE_DBUS AND HAVE_QT AND HAVE_TESTS) ) set(TEST_SRC ${TEST_SRC} ${MOC_SRC} - DBusTestData.cc Test.cc ) diff --git a/libs/dbus/test/DBusTestData.hh b/libs/dbus/test/DBusTestData.hh index 788c5b63a..d90189485 100644 --- a/libs/dbus/test/DBusTestData.hh +++ b/libs/dbus/test/DBusTestData.hh @@ -19,7 +19,6 @@ #define DBUSTESTDATA_HH #include -#include #if defined(DBUS_BACKEND_QT) # include @@ -158,19 +157,4 @@ public: virtual ~DBusTestData() = default; }; -#if defined(DBUS_BACKEND_QT) -Q_DECLARE_METATYPE(DBusTestData::StructWithAllBasicTypes) -Q_DECLARE_METATYPE(DBusTestData::StructWithAllBasicTypesReorder) -Q_DECLARE_METATYPE(DBusTestData::Data) - -QDBusArgument &operator<<(QDBusArgument &argument, const DBusTestData::StructWithAllBasicTypes &message); -const QDBusArgument &operator>>(const QDBusArgument &argument, DBusTestData::StructWithAllBasicTypes &message); - -QDBusArgument &operator<<(QDBusArgument &argument, const DBusTestData::StructWithAllBasicTypesReorder &message); -const QDBusArgument &operator>>(const QDBusArgument &argument, DBusTestData::StructWithAllBasicTypesReorder &message); - -QDBusArgument &operator<<(QDBusArgument &argument, const DBusTestData::Data &message); -const QDBusArgument &operator>>(const QDBusArgument &argument, DBusTestData::Data &message); -#endif - #endif // DBUSTESTDATA_HH diff --git a/libs/dbus/test/DBusTestData.cc b/libs/dbus/test/DBusTestDataMeta.hh similarity index 93% rename from libs/dbus/test/DBusTestData.cc rename to libs/dbus/test/DBusTestDataMeta.hh index f4480c42d..56fd263d2 100644 --- a/libs/dbus/test/DBusTestData.cc +++ b/libs/dbus/test/DBusTestDataMeta.hh @@ -15,17 +15,20 @@ // along with this program. If not, see . // -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "debug.hh" +#ifndef DBUSTESTDATAMETA_HH +#define DBUSTESTDATAMETA_HH #include "DBusTestData.hh" -#include "dbus/IDBus.hh" - #if defined(DBUS_BACKEND_QT) +# include +# include +#endif + +Q_DECLARE_METATYPE(DBusTestData::StructWithAllBasicTypes) +Q_DECLARE_METATYPE(DBusTestData::StructWithAllBasicTypesReorder) +Q_DECLARE_METATYPE(DBusTestData::Data) + QDBusArgument & operator<<(QDBusArgument &argument, const DBusTestData::StructWithAllBasicTypes &message) { @@ -152,4 +155,4 @@ operator>>(const QDBusArgument &argument, DBusTestData::Data &message) return argument; } -#endif +#endif // DBUSTESTDATA_HH diff --git a/libs/dbus/test/DBusTestServerQt.cc b/libs/dbus/test/DBusTestServerQt.cc index 7486fc626..0a0526cfa 100644 --- a/libs/dbus/test/DBusTestServerQt.cc +++ b/libs/dbus/test/DBusTestServerQt.cc @@ -26,6 +26,7 @@ #include "DBusTestServerQt.hh" #include "DBusTestQt.hh" +#include "DBusTestDataMeta.hh" #include "dbus/IDBus.hh" @@ -98,7 +99,7 @@ DBusTestServerQt::test_fire_signal() DBusTestData::DataList l; DBusTestData::DataMap m; - l.push_back(DBusTestData::Data(1, 2)); + l.emplace_back(1, 2); m["1"] = DBusTestData::Data(1, 2); if (test != nullptr) @@ -154,7 +155,7 @@ DBusTestServerQt::test_fire_signal_with_ref() DBusTestData::DataList l; DBusTestData::DataMap m; - l.push_back(DBusTestData::Data(1, 2)); + l.emplace_back(1, 2); m["1"] = DBusTestData::Data(1, 2); if (test != nullptr) diff --git a/libs/dbus/test/Test.cc b/libs/dbus/test/Test.cc index a9f18e0be..8ea696f9f 100644 --- a/libs/dbus/test/Test.cc +++ b/libs/dbus/test/Test.cc @@ -36,11 +36,13 @@ #include "dbus/IDBus.hh" #include "DBusTestData.hh" +#include "DBusTestDataMeta.hh" #include "Test.hh" using namespace std; using namespace workrave::utils; + struct Fixture { Fixture()