diff --git a/codegen/facelift/templates/IPCAdapter.template.cpp b/codegen/facelift/templates/IPCAdapter.template.cpp index 331dacf7..11844c8a 100644 --- a/codegen/facelift/templates/IPCAdapter.template.cpp +++ b/codegen/facelift/templates/IPCAdapter.template.cpp @@ -39,7 +39,12 @@ #include "InterfaceManager.h" #ifdef DBUS_IPC_ENABLED +#include #include "{{module.fullyQualifiedPath}}/{{interfaceName}}IPCDBusAdapter.h" +{% for struct in module.structs %} +#include "{{struct.fullyQualifiedPath}}.h" +{% endfor %} + {% for property in interface.referencedInterfaceTypes %} #include "{{property.fullyQualifiedPath}}{% if generateAsyncProxy %}Async{% endif %}IPCDBusAdapter.h" {% endfor %} @@ -80,6 +85,11 @@ struct {{interfaceName}}IPCAdapter::Impl { {{interfaceName}}IPCAdapter::{{interfaceName}}IPCAdapter(QObject* parent) : BaseType(facelift::InterfaceManager::instance(), parent) { +#ifdef DBUS_IPC_ENABLED + {% for struct in module.structs %} + qDBusRegisterMetaType<{{struct.fullyQualifiedCppType}}>(); + {% endfor %} +#endif } {{interfaceName}}IPCAdapter::~{{interfaceName}}IPCAdapter() { diff --git a/codegen/facelift/templates/IPCCommon.template.h b/codegen/facelift/templates/IPCCommon.template.h index 345988c0..cfb8db42 100644 --- a/codegen/facelift/templates/IPCCommon.template.h +++ b/codegen/facelift/templates/IPCCommon.template.h @@ -47,25 +47,12 @@ class {{classExport}} {{interfaceName}}IPCCommon {{operation.name}}, {% endfor %} {% for property in interface.properties %} - {% if (not property.readonly) %} - set{{property.name}}, - {% endif %} {% if (property.type.is_model) %} {{property.name}}, // model {% endif %} {% endfor %} }; - enum class SignalID { - invalid = static_cast(facelift::CommonSignalID::firstSpecific), - {% for signal in interface.signals %} - {{signal.name}}, - {% endfor %} - {% for property in interface.properties %} - {{property.name}}, - {% endfor %} - }; - }; {{module.namespaceCppClose}} diff --git a/codegen/facelift/templates/IPCDBusServiceAdapter.template.h b/codegen/facelift/templates/IPCDBusServiceAdapter.template.h index 8441e5c6..0fdcec71 100644 --- a/codegen/facelift/templates/IPCDBusServiceAdapter.template.h +++ b/codegen/facelift/templates/IPCDBusServiceAdapter.template.h @@ -67,7 +67,6 @@ class {{classExport}} {{className}}: public {{baseClass}} using ServiceType = {{interfaceName}}; using BaseType = {{baseClass}}; using ThisType = {{className}}; - using SignalID = {{interface}}IPCCommon::SignalID; using MethodID = {{interface}}IPCCommon::MethodID; {{className}}(QObject* parent = nullptr) : @@ -87,7 +86,11 @@ class {{classExport}} {{className}}: public {{baseClass}} void connectSignals() override; - void serializePropertyValues(OutputIPCMessage& msg, bool isCompleteSnapshot) override; + void marshalPropertyValues(const QList& arguments, OutputIPCMessage& msg) override; + + void marshalProperty(const QList& arguments, OutputIPCMessage& msg) override; + + void setProperty(const QList& arguments) override; {% for event in interface.signals %} void {{event}}( @@ -96,7 +99,7 @@ class {{classExport}} {{className}}: public {{baseClass}} {{ comma() }}{{parameter.interfaceCppType}} {{parameter.name}} {%- endfor -%} ) { - sendSignal(SignalID::{{event}} + sendSignal("{{event}}" {%- for parameter in event.parameters -%} , {{parameter.name}} {%- endfor -%} ); diff --git a/codegen/facelift/templates/IPCProxyAdapter.template.cpp b/codegen/facelift/templates/IPCProxyAdapter.template.cpp index e7d50b71..1955d547 100644 --- a/codegen/facelift/templates/IPCProxyAdapter.template.cpp +++ b/codegen/facelift/templates/IPCProxyAdapter.template.cpp @@ -36,6 +36,7 @@ {% set className = interfaceName + proxyTypeNameSuffix %} #include "{{className}}.h" +#include "FaceliftEnum.h" {{module.namespaceCppOpen}} @@ -55,76 +56,108 @@ {% endif %} } -void {{className}}::deserializePropertyValues(InputIPCMessage &msg, bool isCompleteSnapshot) +void {{className}}::unmarshalPropertyValues(InputIPCMessage &msg) { - {% for property in interface.properties %} - {% if property.type.is_interface %} - bool emit_{{property.name}}ChangeSignal = false; - QString {{property.name}}_objectPath; - if (deserializeOptionalValue(msg, {{property.name}}_objectPath, isCompleteSnapshot)) - { - m_{{property.name}}Proxy.update({{property.name}}_objectPath); - m_{{property.name}} = m_{{property.name}}Proxy.getValue(); - emit_{{property.name}}ChangeSignal = true; + QListIterator argumentsIterator(msg.arguments()); + if (argumentsIterator.hasNext()) { + QMap values = qdbus_cast>(argumentsIterator.next()); + for (const QString &propertyName: values.keys()) { + {% for property in interface.properties %} + {% if property.type.is_interface %} + if (propertyName == QStringLiteral("{{property.name}}")) { + bool emit_{{property.name}}ChangeSignal = false; + QString {{property.name}}_objectPath = qvariant_cast(values[propertyName].variant()); + m_{{property.name}}Proxy.update({{property.name}}_objectPath); + m_{{property.name}} = m_{{property.name}}Proxy.getValue(); + emit_{{property.name}}ChangeSignal = true; + if (emit_{{property.name}}ChangeSignal) + emit {{property.name}}Changed(); + } + {% elif property.type.is_model %} + if (propertyName == QStringLiteral("{{property.name}}")) { + bool emit_{{property.name}}ChangeSignal = false; + int {{property.name}}Size = qvariant_cast(values[propertyName].variant()); + m_{{property.name}}.beginResetModel(); + m_{{property.name}}.reset({{property.name}}Size, std::bind(&ThisType::{{property.name}}Data, this, std::placeholders::_1)); + m_{{property.name}}.endResetModel(); + emit_{{property.name}}ChangeSignal = true; + if (emit_{{property.name}}ChangeSignal) + emit {{property.name}}Changed(); + } + {% else %} + if (propertyName == QStringLiteral("{{property.name}}")) { + const auto previous_{{property.name}}_Value = m_{{property.name}}; + m_{{property.name}} = qvariant_cast<{{property.interfaceCppType}}>(values[propertyName].variant()); + bool emit_{{property.name}}ChangeSignal = ((previous_{{property.name}}_Value != m_{{property.name}})); + if (emit_{{property.name}}ChangeSignal) + emit {{property.name}}Changed(); + } + {% endif %} + {% endfor %} + if (propertyName == QStringLiteral("ready")) { + bool previousIsReady = this->ready(); + m_serviceReady = qvariant_cast(values[propertyName].variant()); + bool emit_ReadyChangeSignal = (previousIsReady != m_serviceReady); + if (emit_ReadyChangeSignal) + emit readyChanged(); + } + } } - {% elif property.type.is_model %} - bool emit_{{property.name}}ChangeSignal = false; - if (isCompleteSnapshot) { - int {{property.name}}Size; - deserializeValue(msg, {{property.name}}Size); - m_{{property.name}}.beginResetModel(); - m_{{property.name}}.reset({{property.name}}Size, std::bind(&ThisType::{{property.name}}Data, this, std::placeholders::_1)); - m_{{property.name}}.endResetModel(); - emit_{{property.name}}ChangeSignal = true; - } - {% else %} - const auto previous_{{property.name}}_Value = m_{{property.name}}; - deserializeOptionalValue(msg, m_{{property.name}}, isCompleteSnapshot); - bool emit_{{property.name}}ChangeSignal = isCompleteSnapshot && ((previous_{{property.name}}_Value != m_{{property.name}})); - {% endif %} - {% endfor %} - - bool emit_ReadyChangeSignal = deserializeReadyValue(msg, isCompleteSnapshot) && isCompleteSnapshot; +} - {% for property in interface.properties %} - if (emit_{{property.name}}ChangeSignal) - emit {{property.name}}Changed(); +QMap {{className}}::getSignals() +{ + static QMap rawSignals{ + {%- set comma = joiner(", ") -%} + {% for event in interface.signals %} + {{comma()}}{"{{event}}", SIGNAL({{event}}Raw(const InputIPCMessage& msg))} {% endfor %} - - if (emit_ReadyChangeSignal) - emit readyChanged(); - + }; + return rawSignals; } -void {{className}}::deserializeSignal(InputIPCMessage &msg) +void {{className}}::connectSignals() { - SignalID member; - deserializeValue(msg, member); - {% for event in interface.signals %} - if (member == SignalID::{{event}}) - { + connect(this, &{{className}}::{{event}}Raw, this, [this](const InputIPCMessage& msg) { + QListIterator argumentsIterator(msg.arguments()); {% for parameter in event.parameters %} {{parameter.interfaceCppType}} param_{{parameter.name}}; - deserializeValue(msg, param_{{parameter.name}}); + param_{{parameter.name}} = (argumentsIterator.hasNext() ? qdbus_cast<{{parameter.interfaceCppType}}>(argumentsIterator.next()): {{parameter.interfaceCppType}}()); {% endfor %} emit {{event}}( {%- set comma = joiner(", ") -%} {%- for parameter in event.parameters -%} {{ comma() }}param_{{parameter.name}} {%- endfor -%} ); - } else + }); {% endfor %} - {% for property in interface.properties %} - if (member == SignalID::{{property.name}}) { - {% if property.type.is_model %} - m_{{property.name}}.handleSignal(msg); - {% else %} - emit {{property.name}}Changed(); - {% endif %} - } else +} + +void {{className}}::disconnectSignals() +{ + {% for event in interface.signals %} + disconnect(this, &{{className}}::{{event}}Raw, this, nullptr); {% endfor %} - BaseType::deserializeCommonSignal(static_cast(member), this); +} + +void {{className}}::unmarshalPropertiesChanged(InputIPCMessage &msg) +{ + QListIterator argumentsIterator(msg.arguments()); + QString interfaceName = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): QString()); + QVariantMap changedProperties = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): QVariantMap()); + for (const QString &propertyName: changedProperties.keys()) { + {% for property in interface.properties %} + {% if property.type.is_interface %} + {% elif property.type.is_model %} + {% else %} + if (propertyName == QStringLiteral("{{property.name}}")) { + m_{{property.name}} = qdbus_cast<{{property.cppType}}>(changedProperties[propertyName]); + emit {{property.name}}Changed(); // trust the propertiesChanged signal and emit without checking + } + {% endif %} + {% endfor %} + } } {% for property in interface.properties %} @@ -134,7 +167,7 @@ void {{className}}::deserializeSignal(InputIPCMessage &msg) void {{className}}::set{{property}}({{property.cppMethodArgumentType}} newValue) { {% if (not property.type.is_interface) %} - ipc()->sendSetterCall(memberID(MethodID::set{{property.name}}, "set{{property.name}}"), newValue); + ipc()->sendSetterCall("{{property.name}}", newValue); {% else %} Q_ASSERT(false); // Writable interface properties are unsupported {% endif %} @@ -168,12 +201,11 @@ void {{className}}::{{operation.name}}( {%- endfor -%} ){% if operation.is_const %} const{% endif %} { {% if (operation.hasReturnValue) %} - {{operation.interfaceCppType}} returnValue; - ipc()->sendMethodCallWithReturn(memberID(MethodID::{{operation.name}}, "{{operation.name}}"), returnValue + QList args = ipc()->sendMethodCallWithReturn(memberID(MethodID::{{operation.name}}, "{{operation.name}}") {%- for parameter in operation.parameters -%} , {{parameter.name}} {%- endfor -%} ); - return returnValue; + return (!args.isEmpty() ? qdbus_cast<{{operation.interfaceCppType}}>(args[0]): {{operation.interfaceCppType}}()); {% else %} ipc()->sendMethodCall(memberID(MethodID::{{operation.name}}, "{{operation.name}}") {%- for parameter in operation.parameters -%} diff --git a/codegen/facelift/templates/IPCProxyAdapter.template.h b/codegen/facelift/templates/IPCProxyAdapter.template.h index 8731a5b3..d88fb06b 100644 --- a/codegen/facelift/templates/IPCProxyAdapter.template.h +++ b/codegen/facelift/templates/IPCProxyAdapter.template.h @@ -60,7 +60,6 @@ class {{classExport}} {{className}} : public {{baseClass}} using ThisType = {{className}}; using BaseType = {{baseClass}}; - using SignalID = {{interface}}IPCCommon::SignalID; using MethodID = {{interface}}IPCCommon::MethodID; // override the default QMLAdapter type to add the IPC related properties @@ -68,7 +67,7 @@ class {{classExport}} {{className}} : public {{baseClass}} {{className}}(QObject *parent = nullptr); - void deserializePropertyValues(InputIPCMessage &msg, bool isCompleteSnapshot) override; + void unmarshalPropertyValues(InputIPCMessage &msg) override; {% if interface.hasModelProperty %} void setServiceRegistered(bool isRegistered) override @@ -85,7 +84,11 @@ class {{classExport}} {{className}} : public {{baseClass}} {% endif %} - void deserializeSignal(InputIPCMessage &msg) override; + QMap getSignals() override; + void connectSignals() override; + void disconnectSignals() override; + + void unmarshalPropertiesChanged(InputIPCMessage &msg) override; {% for operation in interface.operations %} @@ -122,7 +125,6 @@ class {{classExport}} {{className}} : public {{baseClass}} } {% elif property.type.is_list %} - const {{property.interfaceCppType}}& {{property}}() const override { return m_{{property.name}}; @@ -159,6 +161,10 @@ class {{classExport}} {{className}} : public {{baseClass}} facelift::IPCProxyModelProperty m_{{property.name}}; {% endif %} {% endfor %} + + {% for event in interface.signals %} + Q_SIGNAL void {{event}}Raw(const InputIPCMessage& msg); + {% endfor %} }; diff --git a/codegen/facelift/templates/IPCServiceAdapter.template.cpp b/codegen/facelift/templates/IPCServiceAdapter.template.cpp index 068ed434..1c4f8499 100644 --- a/codegen/facelift/templates/IPCServiceAdapter.template.cpp +++ b/codegen/facelift/templates/IPCServiceAdapter.template.cpp @@ -35,9 +35,9 @@ {% set className = interfaceName + proxyTypeNameSuffix %} +#include #include "{{className}}.h" - {{module.namespaceCppOpen}} facelift::IPCHandlingResult {{className}}::handleMethodCallMessage(InputIPCMessage &requestMessage, @@ -45,7 +45,7 @@ facelift::IPCHandlingResult {{className}}::handleMethodCallMessage(InputIPCMessa { Q_UNUSED(replyMessage); // Since we do not always have return values Q_UNUSED(requestMessage); - + QListIterator argumentsIterator(requestMessage.arguments()); const auto &member = requestMessage.member(); Q_UNUSED(member); // In case there are no methods auto theService = service(); @@ -56,8 +56,7 @@ facelift::IPCHandlingResult {{className}}::handleMethodCallMessage(InputIPCMessa {% for operation in interface.operations %} if (member == memberID(MethodID::{{operation.name}}, "{{operation.name}}")) { {% for parameter in operation.parameters %} - {{parameter.cppType}} param_{{parameter.name}}; - deserializeValue(requestMessage, param_{{parameter.name}}); + {{parameter.cppType}} param_{{parameter.name}} = (argumentsIterator.hasNext() ? qdbus_cast<{{parameter.cppType}}>(argumentsIterator.next()): {{parameter.cppType}}()); {% endfor %} {% if operation.isAsync %} theService->{{operation.name}}({% for parameter in operation.parameters %} param_{{parameter.name}}, {%- endfor -%} @@ -75,7 +74,7 @@ facelift::IPCHandlingResult {{className}}::handleMethodCallMessage(InputIPCMessa {{ comma() }}param_{{parameter.name}} {%- endfor -%}); {% if operation.hasReturnValue %} - serializeValue(replyMessage, returnValue); + replyMessage << QVariant::fromValue(returnValue); {% endif %} {% endif %} } else @@ -86,17 +85,6 @@ facelift::IPCHandlingResult {{className}}::handleMethodCallMessage(InputIPCMessa m_{{property.name}}Handler.handleModelRequest(requestMessage, replyMessage); } else {% endif %} - {% if (not property.readonly) %} - if (member == memberID(MethodID::set{{property.name}}, "set{{property.name}}")) { - {% if (not property.type.is_interface) %} - {{property.cppType}} value; - deserializeValue(requestMessage, value); - theService->set{{property.name}}(value); - {% else %} - Q_ASSERT(false); // Writable interface properties are unsupported - {% endif %} - } else - {% endif %} {% endfor %} { return facelift::IPCHandlingResult::INVALID; @@ -109,39 +97,39 @@ void {{className}}::appendDBUSIntrospectionData(QTextStream &s) const { Q_UNUSED(s); // For empty interfaces {% for property in interface.properties %} - ::facelift::DBusSignatureHelper::addPropertySignature(s, "{{property.name}}", {{ property.readonly | cppBool }}); + {% if not property.type.is_model %} + s << QStringLiteral("").arg(QDBusMetaType::typeToSignature(qMetaTypeId<{{property.type.interfaceCppType}}>()), + {{ property.readonly | cppBool }} ? QStringLiteral("read"): QStringLiteral("readwrite")); + {% endif %} {% endfor %} - {% for operation in interface.operations %} + s << QStringLiteral(""); - { - std::array argumentNames = { { - {%- for parameter in operation.parameters -%} - "{{parameter}}", - {%- endfor -%} - } }; - ::facelift::DBusSignatureHelper::addMethodSignature< - {%- set comma = joiner(", ") -%} - {%- for parameter in operation.parameters -%} - {{ comma() }}{{parameter.cppType}} - {%- endfor -%} - >(s, "{{operation.name}}", argumentNames); - } + {% for operation in interface.operations %} + s << ""; + {%- for parameter in operation.parameters -%} + s << "()); + s << "\" direction=\"in\"/>"; + {%- endfor -%} + + {% if operation.hasReturnValue %} + s << "()); + s << "\" direction=\"out\"/>"; + {% endif %}; + s << ""; {% endfor %} // signals {% for signal in interface.signals %} { - std::array argumentNames = { { - {%- for parameter in signal.parameters -%} - "{{parameter}}", - {%- endfor -%} - }}; - ::facelift::DBusSignatureHelper::addSignalSignature< - {%- set comma = joiner(", ") -%} + s << ""; {%- for parameter in signal.parameters -%} - {{ comma() }}{{parameter.interfaceCppType}} + s << "()); + s << "\" direction=\"out\"/>"; {%- endfor -%} - >(s, "{{signal.name}}", argumentNames); + s << ""; } {% endfor %} @@ -154,7 +142,7 @@ void {{className}}::connectSignals() {% for property in interface.properties %} {% if property.type.is_model %} - m_{{property.name}}Handler.connectModel(SignalID::{{property.name}}, theService->{{property.name}}()); + //m_{{property.name}}Handler.connectModel(SignalID::{{property.name}}, theService->{{property.name}}()); {% elif property.type.is_interface %} {% else %} m_previous{{property.name}} = theService->{{property.name}}(); @@ -169,39 +157,89 @@ void {{className}}::connectSignals() m_{{property.name}}.update(this, theService->{{property.name}}()); }); {% endif %} - QObject::connect(theService, &ServiceType::{{property.name}}Changed, this, [this] () { - this->sendSignal(SignalID::{{property.name}}); + QObject::connect(theService, &ServiceType::{{property.name}}Changed, this, [this, theService] () { + this->sendPropertiesChanged("{{property.name}}", theService->{{property.name}}()); }); {% endfor %} + QObject::connect(theService, &ServiceType::readyChanged, this, [this, theService] () { + this->sendPropertiesChanged("ready", theService->ready()); + }); + // Signals {% for signal in interface.signals %} QObject::connect(theService, &ServiceType::{{signal}}, this, &ThisType::{{signal}}); {% endfor %} } -void {{className}}::serializePropertyValues(OutputIPCMessage& msg, bool isCompleteSnapshot) +void {{className}}::marshalPropertyValues(const QList& arguments, OutputIPCMessage& msg) { - auto theService = service(); - {#% if (not interface.properties) %#} - Q_UNUSED(theService); - {#% endif %#} + QListIterator argumentsIterator(arguments); + auto msgInterfaceName = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): QString()); + if (msgInterfaceName == interfaceName()) { + auto theService = service(); + QMap ret; + {#% if (not interface.properties) %#} + Q_UNUSED(theService); + {#% endif %#} + + {% for property in interface.properties %} + {% if property.type.is_interface %} + ret["{{property.name}}"] = QDBusVariant(QVariant::fromValue(m_{{property.name}}.objectPath())); + {% elif property.type.is_model %} + ret["{{property.name}}"] = QDBusVariant(QVariant::fromValue(theService->{{property.name}}().size())); + {% else %} + ret["{{property.name}}"] = QDBusVariant(QVariant::fromValue(theService->{{property.name}}())); + {% endif %} + {% endfor %} + ret["ready"] = QDBusVariant(QVariant::fromValue(theService->ready())); + msg << QVariant::fromValue(ret); + } +} - {% for property in interface.properties %} - {% if property.type.is_interface %} +void {{className}}::marshalProperty(const QList& arguments, OutputIPCMessage& msg) +{ + QListIterator argumentsIterator(arguments); + auto msgInterfaceName = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): QString()); + if (msgInterfaceName == interfaceName()) { + auto propertyName = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): QString()); + {% for property in interface.properties %} + {% if property.type.is_interface %} - serializeOptionalValue(msg, m_{{property.name}}.objectPath(), m_previous{{property.name}}ObjectPath, isCompleteSnapshot); + {% elif property.type.is_model %} - {% elif property.type.is_model %} - if (isCompleteSnapshot) { - serializeValue(msg, theService->{{property.name}}().size()); + {% else %} + if (propertyName == QStringLiteral("{{property.name}}")) { + msg << QVariant::fromValue(service()->{{property.name}}()); + } + {% endif %} + {% endfor %} + if (propertyName == QStringLiteral("ready")) { + msg << QVariant::fromValue(service()->ready()); + } } - {% else %} - serializeOptionalValue(msg, theService->{{property.name}}(), m_previous{{property.name}}, isCompleteSnapshot); - {% endif %} - {% endfor %} +} - BaseType::serializePropertyValues(msg, isCompleteSnapshot); +void {{className}}::setProperty(const QList& arguments) +{ + QListIterator argumentsIterator(arguments); + auto msgInterfaceName = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): QString()); + if (msgInterfaceName == interfaceName()) { + auto propertyName = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): QString()); + if (argumentsIterator.hasNext()) { + {% for property in interface.properties %} + {% if property.type.is_interface %} + + {% elif property.type.is_model %} + + {% elif (not property.readonly) %} + if (propertyName == QStringLiteral("{{property.name}}")) { + service()->set{{property.name}}(qvariant_cast<{{property.cppType}}>(qdbus_cast(argumentsIterator.next()).variant())); + } + {% endif %} + {% endfor %} + } + } } {{module.namespaceCppClose}} diff --git a/codegen/facelift/templates/IPCServiceAdapter.template.h b/codegen/facelift/templates/IPCServiceAdapter.template.h index 4551f550..10cd513c 100644 --- a/codegen/facelift/templates/IPCServiceAdapter.template.h +++ b/codegen/facelift/templates/IPCServiceAdapter.template.h @@ -64,7 +64,6 @@ class {{classExport}} {{className}}: public {{baseClass}} using ServiceType = {{interfaceName}}; using BaseType = {{baseClass}}; using ThisType = {{className}}; - using SignalID = {{interface}}IPCCommon::SignalID; using MethodID = {{interface}}IPCCommon::MethodID; {{className}}(QObject* parent = nullptr) : BaseType(parent) @@ -83,7 +82,11 @@ class {{classExport}} {{className}}: public {{baseClass}} void connectSignals() override; - void serializePropertyValues(OutputIPCMessage& msg, bool isCompleteSnapshot) override; + void marshalPropertyValues(const QList& arguments, OutputIPCMessage& msg) override; + + void marshalProperty(const QList& arguments, OutputIPCMessage& msg) override; + + void setProperty(const QList& arguments) override; {% for event in interface.signals %} void {{event}}( @@ -92,7 +95,7 @@ class {{classExport}} {{className}}: public {{baseClass}} {{ comma() }}{{parameter.interfaceCppType}} {{parameter.name}} {%- endfor -%} ) { - sendSignal(SignalID::{{event}} + sendSignal("{{event}}" {%- for parameter in event.parameters -%} , {{parameter.name}} {%- endfor -%} ); diff --git a/codegen/facelift/templates/ImplementationBase.template.h b/codegen/facelift/templates/ImplementationBase.template.h index 6f9a23e5..9ee36edb 100644 --- a/codegen/facelift/templates/ImplementationBase.template.h +++ b/codegen/facelift/templates/ImplementationBase.template.h @@ -91,6 +91,7 @@ class {{classExport}} {{interfaceName}}ImplementationBase : public {{interfaceNa {% endif %} {% endfor %} + Q_PROPERTY(bool ready READ ready) bool ready() const override { return m_ready.value(); diff --git a/codegen/facelift/templates/Module.template.cpp b/codegen/facelift/templates/Module.template.cpp index 6dea4e1c..d0474ac9 100644 --- a/codegen/facelift/templates/Module.template.cpp +++ b/codegen/facelift/templates/Module.template.cpp @@ -76,13 +76,6 @@ void Module::registerTypes() if (!alreadyRegistered) { alreadyRegistered = true; - {% for enum in module.enums %} - facelift::qRegisterMetaType<{{enum.fullyQualifiedCppType}}>(); - {% endfor %} - {% for struct in module.structs %} - qRegisterMetaType<{{struct.fullyQualifiedCppType}}>(); - {% endfor %} - #ifdef ENABLE_DESKTOP_TOOLS ModuleMonitor::registerTypes(); #endif diff --git a/codegen/facelift/templates/Service.template.cpp b/codegen/facelift/templates/Service.template.cpp index 23b1a86b..82728d66 100644 --- a/codegen/facelift/templates/Service.template.cpp +++ b/codegen/facelift/templates/Service.template.cpp @@ -58,6 +58,7 @@ constexpr const char* {{interfaceName}}::FULLY_QUALIFIED_INTERFACE_NAME; }); } #endif + registerTypes(""); } {{module.namespaceCppClose}} diff --git a/codegen/facelift/templates/Service.template.h b/codegen/facelift/templates/Service.template.h index 8f87f979..553cabc6 100644 --- a/codegen/facelift/templates/Service.template.h +++ b/codegen/facelift/templates/Service.template.h @@ -40,6 +40,7 @@ {{classExportDefines}} #include "FaceliftModel.h" +#include // Dependencies {% for type in interface.referencedTypes %} @@ -104,6 +105,25 @@ class {{classExport}} {{interfaceName}} : public facelift::InterfaceBase static void registerTypes(const char* uri) { Q_UNUSED( uri); + {% for operation in interface.operations %} + {%- for parameter in operation.parameters -%} + qRegisterMetaType<{{parameter.interfaceCppType}}>(); + qDBusRegisterMetaType<{{parameter.interfaceCppType}}>(); + {% endfor %} + {% if (operation.hasReturnValue) %} + qRegisterMetaType<{{operation.interfaceCppType}}>(); + qDBusRegisterMetaType<{{operation.interfaceCppType}}>(); + {% endif %} + {% endfor %} + + {% for property in interface.properties %} + {% if (not property.type.is_model) %} + {% if (not property.type.is_interface) %} + qRegisterMetaType<{{property.interfaceCppType}}>(); + qDBusRegisterMetaType<{{property.cppType}}>(); + {% endif %} + {% endif %} + {% endfor %} } {% for property in interface.properties %} @@ -122,9 +142,6 @@ class {{classExport}} {{interfaceName}} : public facelift::InterfaceBase { return facelift::ServicePropertyInterface(this, &ThisType::{{property}}, &ThisType::{{property}}Changed); } - {% if (not property.readonly) %} - virtual void set{{property}}( {{property.cppMethodArgumentType}} newValue) = 0; - {% endif %} {% else %} using PropertyType_{{property}} = {{property.interfaceCppType}}; virtual const {{property.interfaceCppType}}& {{property}}() const = 0; diff --git a/codegen/facelift/templates/Struct.template.h b/codegen/facelift/templates/Struct.template.h index b50bae7e..299cc80f 100644 --- a/codegen/facelift/templates/Struct.template.h +++ b/codegen/facelift/templates/Struct.template.h @@ -39,6 +39,8 @@ {{classExportDefines}} +#include + #include "Structure.h" #include "FaceliftQMLUtils.h" @@ -84,6 +86,9 @@ class {{classExport}} {{struct.name}} : public facelift::Structure< {{struct.name}}& operator=(const {{struct.name}} &right); + friend QDBusArgument &operator<<(QDBusArgument &argument, const {{struct.name}} &{{struct.name|lower}}); + friend const QDBusArgument &operator>>(const QDBusArgument &argument, {{struct.name}} &{{struct.name|lower}}); + Q_INVOKABLE {{struct.fullyQualifiedCppType}} clone() const; {% if struct.isSerializable %} @@ -126,6 +131,26 @@ class {{classExport}} {{struct.name}} : public facelift::Structure< {% endfor -%} }; +inline QDBusArgument &operator<<(QDBusArgument &argument, const {{struct.name}} &{{struct.name|lower}}) +{ + argument.beginStructure(); + {% for field in struct.fields %} + argument << {{struct.name|lower}}.m_{{field}}; + {% endfor -%} + argument.endStructure(); + return argument; +} + +inline const QDBusArgument &operator>>(const QDBusArgument &argument, {{struct.name}} &{{struct.name|lower}}) +{ + argument.beginStructure(); + {% for field in struct.fields %} + argument >> {{struct.name|lower}}.m_{{field}}; + {% endfor -%} + argument.endStructure(); + + return argument; +} {{module.namespaceCppClose}} @@ -145,7 +170,8 @@ inline QDebug operator<< (QDebug d, const {{struct.fullyQualifiedCppType}} &f) } Q_DECLARE_METATYPE(QList<{{struct.fullyQualifiedCppType}}>) // Needed for list properties -//Q_DECLARE_METATYPE(QMap) // TODO: Needed for map properties? +//Q_DECLARE_METATYPE(QMapOf{{struct.name}}) +//Q_DECLARE_METATYPE(facelift::Model<{{struct.fullyQualifiedCppType}}>) // Needed for model properties Q_DECLARE_METATYPE({{struct.fullyQualifiedCppType}}) diff --git a/src/ipc/dbus/DBusIPCCommon.h b/src/ipc/dbus/DBusIPCCommon.h index 9f3280aa..ea1cfd84 100644 --- a/src/ipc/dbus/DBusIPCCommon.h +++ b/src/ipc/dbus/DBusIPCCommon.h @@ -41,10 +41,10 @@ namespace dbus { using namespace facelift; struct FaceliftIPCLibDBus_EXPORT DBusIPCCommon { - static constexpr const char *GET_PROPERTIES_MESSAGE_NAME = "GetAllProperties"; + static constexpr const char *GET_ALL_PROPERTIES = "GetAll"; + static constexpr const char *GET_PROPERTY = "Get"; + static constexpr const char *SET_PROPERTY = "Set"; static constexpr const char *PROPERTIES_CHANGED_SIGNAL_NAME = "PropertiesChanged"; - static constexpr const char *SIGNAL_TRIGGERED_SIGNAL_NAME = "SignalTriggered"; - static constexpr const char *SET_PROPERTY_MESSAGE_NAME = "SetProperty"; static constexpr const char *INTROSPECTABLE_INTERFACE_NAME = "org.freedesktop.DBus.Introspectable"; static constexpr const char *PROPERTIES_INTERFACE_NAME = "org.freedesktop.DBus.Properties"; static constexpr const char *DEFAULT_SERVICE_NAME = "facelift.registry"; diff --git a/src/ipc/dbus/DBusIPCMessage.cpp b/src/ipc/dbus/DBusIPCMessage.cpp index cd7b6056..8387df1b 100644 --- a/src/ipc/dbus/DBusIPCMessage.cpp +++ b/src/ipc/dbus/DBusIPCMessage.cpp @@ -67,6 +67,17 @@ DBusIPCMessage::DBusIPCMessage(const QString &path, const QString &interface, co m_message = QDBusMessage::createSignal(path, interface, signal); } +QList DBusIPCMessage::arguments() const +{ + return m_message.arguments(); +} + +DBusIPCMessage &DBusIPCMessage::operator<<(const QVariant &arg) +{ + m_message << arg; + return *this; +} + QString DBusIPCMessage::member() const { return m_message.member(); @@ -119,28 +130,7 @@ bool DBusIPCMessage::isErrorMessage() const return (m_message.type() == QDBusMessage::ErrorMessage); } -OutputPayLoad &DBusIPCMessage::outputPayLoad() -{ - if (m_outputPayload == nullptr) { - m_outputPayload = std::make_unique(m_payload); - } - return *m_outputPayload; -} - -InputPayLoad &DBusIPCMessage::inputPayLoad() -{ - if (m_inputPayload == nullptr) { - m_payload = m_message.arguments()[0].value(); - m_inputPayload = std::make_unique(m_payload); - } - return *m_inputPayload; -} - QDBusMessage& DBusIPCMessage::outputMessage() { - if (m_outputPayload) { - m_message << m_outputPayload->getContent(); - m_outputPayload.reset(); - } return m_message; } diff --git a/src/ipc/dbus/DBusIPCMessage.h b/src/ipc/dbus/DBusIPCMessage.h index 0198bd36..e517d322 100644 --- a/src/ipc/dbus/DBusIPCMessage.h +++ b/src/ipc/dbus/DBusIPCMessage.h @@ -60,20 +60,17 @@ class FaceliftIPCLibDBus_EXPORT DBusIPCMessage QString member() const; QString toString() const; + QList arguments() const; + DBusIPCMessage &operator<<(const QVariant &arg); DBusIPCMessage createReply(); DBusIPCMessage createErrorReply(const QString &msg, const QString &member); QString signature() const; bool isReplyMessage() const; bool isErrorMessage() const; - OutputPayLoad &outputPayLoad(); - InputPayLoad &inputPayLoad(); QDBusMessage& outputMessage(); private: QDBusMessage m_message; - QByteArray m_payload; - std::unique_ptr m_outputPayload; - std::unique_ptr m_inputPayload; }; } // end namespace dbus diff --git a/src/ipc/dbus/DBusIPCProxy.h b/src/ipc/dbus/DBusIPCProxy.h index 8111ad4d..2236adef 100644 --- a/src/ipc/dbus/DBusIPCProxy.h +++ b/src/ipc/dbus/DBusIPCProxy.h @@ -78,42 +78,6 @@ class DBusIPCProxy : public IPCProxyBase, protected DBusRequestHa return memberName; } - template - void serializeValue(DBusIPCMessage &msg, const Type &v) - { - typedef typename IPCTypeRegisterHandler::SerializedType SerializedType; - IPCTypeHandler::write(msg, IPCTypeRegisterHandler::convertToSerializedType(v, *this)); - } - - template - void deserializeValue(DBusIPCMessage &msg, Type &v) - { - typedef typename IPCTypeRegisterHandler::SerializedType SerializedType; - SerializedType serializedValue; - IPCTypeHandler::read(msg.inputPayLoad(), serializedValue); - IPCTypeRegisterHandler::convertToDeserializedType(v, serializedValue, *this); - } - - template - bool deserializeOptionalValue(DBusIPCMessage &msg, Type &value, bool isCompleteSnapshot) - { - bool b = true; - if (!isCompleteSnapshot) { - msg.inputPayLoad().readNextParameter(b); - } - if (b) { - this->deserializeValue(msg, value); - } - return b; - } - - bool deserializeReadyValue(DBusIPCMessage &msg, bool isCompleteSnapshot) - { - bool previousIsReady = this->ready(); - deserializeOptionalValue(msg, this->m_serviceReady, isCompleteSnapshot); - return (this->ready() != previousIsReady); - } - void setServiceRegistered(bool isRegistered) override { bool oldReady = this->ready(); diff --git a/src/ipc/dbus/DBusIPCProxyBinder.cpp b/src/ipc/dbus/DBusIPCProxyBinder.cpp index 636fbb0b..313e216e 100644 --- a/src/ipc/dbus/DBusIPCProxyBinder.cpp +++ b/src/ipc/dbus/DBusIPCProxyBinder.cpp @@ -60,25 +60,18 @@ void DBusIPCProxyBinder::setInterfaceName(const QString &name) checkInit(); } -void DBusIPCProxyBinder::onServerNotAvailableError(const char *methodName) const +void DBusIPCProxyBinder::onServerNotAvailableError(const QString &propertyName) const { qCCritical(LogIpc, "Error message received when calling method '%s' on service at path '%s'. " "This likely indicates that the server you are trying to access is not available yet", - qPrintable(methodName), qPrintable(objectPath())); + qPrintable(propertyName), qPrintable(objectPath())); } void DBusIPCProxyBinder::onPropertiesChanged(const QDBusMessage &dbusMessage) { DBusIPCMessage msg(dbusMessage); - m_serviceObject->deserializePropertyValues(msg, false); -} - -void DBusIPCProxyBinder::onSignalTriggered(const QDBusMessage &dbusMessage) -{ - DBusIPCMessage msg(dbusMessage); - m_serviceObject->deserializePropertyValues(msg, false); - m_serviceObject->deserializeSignal(msg); + m_serviceObject->unmarshalPropertiesChanged(msg); } void DBusIPCProxyBinder::setHandler(DBusRequestHandler *handler) @@ -90,11 +83,11 @@ void DBusIPCProxyBinder::setHandler(DBusRequestHandler *handler) void DBusIPCProxyBinder::requestPropertyValues() { - DBusIPCMessage msg(serviceName(), objectPath(), interfaceName(), DBusIPCCommon::GET_PROPERTIES_MESSAGE_NAME); - + DBusIPCMessage msg(serviceName(), objectPath(), DBusIPCCommon::PROPERTIES_INTERFACE_NAME, DBusIPCCommon::GET_ALL_PROPERTIES); + msg << QVariant::fromValue(interfaceName()); auto replyHandler = [this](DBusIPCMessage &replyMessage) { if (replyMessage.isReplyMessage()) { - m_serviceObject->deserializePropertyValues(replyMessage, true); + m_serviceObject->unmarshalPropertyValues(replyMessage); m_serviceObject->setServiceRegistered(true); } else { qCDebug(LogIpc) << "Service not yet available : " << objectPath(); @@ -115,16 +108,18 @@ void DBusIPCProxyBinder::onServiceNameKnown() auto& connection = m_dbusManager.connection(); auto successPropertyChangeSignal = connection.connect(m_serviceName, - objectPath(), m_interfaceName, DBusIPCCommon::PROPERTIES_CHANGED_SIGNAL_NAME, this, + objectPath(), DBusIPCCommon::PROPERTIES_INTERFACE_NAME, DBusIPCCommon::PROPERTIES_CHANGED_SIGNAL_NAME, this, SLOT(onPropertiesChanged(const QDBusMessage&))); Q_UNUSED(successPropertyChangeSignal); // TODO: check - auto successSignalTriggeredSignal = connection.connect(m_serviceName, - objectPath(), m_interfaceName, DBusIPCCommon::SIGNAL_TRIGGERED_SIGNAL_NAME, this, - SLOT(onSignalTriggered(const QDBusMessage&))); + for (const char* key: m_serviceObject->getSignals()) { + auto signalConnected = connection.connect(m_serviceName, + objectPath(), interfaceName(), key, this, m_serviceObject->getSignals()[key]); - Q_UNUSED(successSignalTriggeredSignal); // TODO: check + Q_UNUSED(signalConnected); // TODO: check + } + m_serviceObject->connectSignals(); m_busWatcher.addWatchedService(m_serviceName); m_busWatcher.setConnection(connection); @@ -155,12 +150,10 @@ void DBusIPCProxyBinder::checkRegistry() auto& connection = m_dbusManager.connection(); connection.disconnect(m_serviceName, - objectPath(), m_interfaceName, DBusIPCCommon::PROPERTIES_CHANGED_SIGNAL_NAME, this, + objectPath(), DBusIPCCommon::PROPERTIES_INTERFACE_NAME, DBusIPCCommon::PROPERTIES_CHANGED_SIGNAL_NAME, this, SLOT(onPropertiesChanged(const QDBusMessage&))); - connection.disconnect(m_serviceName, - objectPath(), m_interfaceName, DBusIPCCommon::SIGNAL_TRIGGERED_SIGNAL_NAME, this, - SLOT(onSignalTriggered(const QDBusMessage&))); + m_serviceObject->disconnectSignals(); setServiceAvailable(false); m_serviceName.clear(); diff --git a/src/ipc/dbus/DBusIPCProxyBinder.h b/src/ipc/dbus/DBusIPCProxyBinder.h index ddbe67ef..6cdbae7b 100644 --- a/src/ipc/dbus/DBusIPCProxyBinder.h +++ b/src/ipc/dbus/DBusIPCProxyBinder.h @@ -36,10 +36,12 @@ # define FaceliftIPCLibDBus_EXPORT Q_DECL_IMPORT #endif +#include #include #include "IPCProxyBinderBase.h" #include "DBusIPCMessage.h" -#include "ipc-serialization.h" +#include "FaceliftUtils.h" +#include "DBusIPCCommon.h" #include "DBusManagerInterface.h" class QDBusMessage; @@ -72,8 +74,6 @@ class FaceliftIPCLibDBus_EXPORT DBusIPCProxyBinder : public IPCProxyBinderBase Q_SLOT void onPropertiesChanged(const QDBusMessage &dbusMessage); - Q_SLOT void onSignalTriggered(const QDBusMessage &dbusMessage); - void bindToIPC() override; void onServiceNameKnown(); @@ -91,16 +91,10 @@ class FaceliftIPCLibDBus_EXPORT DBusIPCProxyBinder : public IPCProxyBinderBase void asyncCall(DBusIPCMessage &message, const QObject *context, std::function callback); - template - void serializeValue(DBusIPCMessage &msg, const Type &v); - - template - void deserializeValue(DBusIPCMessage &msg, Type &v); - - void onServerNotAvailableError(const char *methodName) const; + void onServerNotAvailableError(const QString &propertyName) const; template - void sendSetterCall(const char *methodName, const PropertyType &value); + void sendSetterCall(const QString& property, const PropertyType &value); template DBusIPCMessage sendMethodCall(const char *methodName, const Args & ... args) const; @@ -111,8 +105,8 @@ class FaceliftIPCLibDBus_EXPORT DBusIPCProxyBinder : public IPCProxyBinderBase template void sendAsyncMethodCall(const char *methodName, facelift::AsyncAnswer answer, const Args & ... args); - template - void sendMethodCallWithReturn(const char *methodName, ReturnType &returnValue, const Args & ... args) const; + template + QList sendMethodCallWithReturn(const char *methodName, const Args & ... args) const; void setHandler(DBusRequestHandler *handler); @@ -127,29 +121,12 @@ class FaceliftIPCLibDBus_EXPORT DBusIPCProxyBinder : public IPCProxyBinderBase }; -template -inline void DBusIPCProxyBinder::serializeValue(DBusIPCMessage &msg, const Type &v) -{ - typedef typename IPCTypeRegisterHandler::SerializedType SerializedType; - IPCTypeHandler::write(msg.outputPayLoad(), IPCTypeRegisterHandler::convertToSerializedType(v, *this)); -} - -template -inline void DBusIPCProxyBinder::deserializeValue(DBusIPCMessage &msg, Type &v) -{ - typedef typename IPCTypeRegisterHandler::SerializedType SerializedType; - SerializedType serializedValue; - IPCTypeHandler::read(msg.inputPayLoad(), serializedValue); - IPCTypeRegisterHandler::convertToDeserializedType(v, serializedValue, *this); -} - - template inline DBusIPCMessage DBusIPCProxyBinder::sendMethodCall(const char *methodName, const Args & ... args) const { DBusIPCMessage msg(m_serviceName, objectPath(), m_interfaceName, methodName); auto argTuple = std::make_tuple(args ...); - for_each_in_tuple(argTuple, SerializeParameterFunction(msg.outputPayLoad(), *this)); + for_each_in_tuple(argTuple, [&msg](const auto &v){msg << QVariant::fromValue(v);}); auto replyMessage = this->call(msg); if (replyMessage.isErrorMessage()) { onServerNotAvailableError(methodName); @@ -162,11 +139,11 @@ inline void DBusIPCProxyBinder::sendAsyncMethodCall(const char *methodName, face { DBusIPCMessage msg(m_serviceName, objectPath(), m_interfaceName, methodName); auto argTuple = std::make_tuple(args ...); - for_each_in_tuple(argTuple, SerializeParameterFunction(msg.outputPayLoad(), *this)); + for_each_in_tuple(argTuple, [&msg](const auto &v){msg << QVariant::fromValue(v);}); asyncCall(msg, this, [this, answer](DBusIPCMessage &msg) { ReturnType returnValue; if (msg.isReplyMessage()) { - deserializeValue(msg, returnValue); + returnValue = (!msg.arguments().isEmpty() ? qdbus_cast(msg.arguments()[0]): ReturnType()); answer(returnValue); } else { qCWarning(LogIpc) << "Error received" << msg.toString(); @@ -179,39 +156,41 @@ inline void DBusIPCProxyBinder::sendAsyncMethodCall(const char *methodName, face { DBusIPCMessage msg(m_serviceName, objectPath(), m_interfaceName, methodName); auto argTuple = std::make_tuple(args ...); - for_each_in_tuple(argTuple, SerializeParameterFunction(msg.outputPayLoad(), *this)); + for_each_in_tuple(argTuple, [&msg](const auto &v){msg << QVariant::fromValue(v);}); asyncCall(msg, this, [answer](DBusIPCMessage &msg) { Q_UNUSED(msg); answer(); }); } -template -inline void DBusIPCProxyBinder::sendMethodCallWithReturn(const char *methodName, ReturnType &returnValue, const Args & ... args) const +template +inline QList DBusIPCProxyBinder::sendMethodCallWithReturn(const char *methodName, const Args & ... args) const { DBusIPCMessage msg = sendMethodCall(methodName, args ...); + QList ret; if (msg.isReplyMessage()) { - const_cast(this)->deserializeValue(msg, returnValue); - } else { - assignDefaultValue(returnValue); + ret = msg.arguments(); } + return ret; } template -inline void DBusIPCProxyBinder::sendSetterCall(const char *methodName, const PropertyType &value) +inline void DBusIPCProxyBinder::sendSetterCall(const QString &property, const PropertyType &value) { - DBusIPCMessage msg(m_serviceName, objectPath(), m_interfaceName, methodName); - serializeValue(msg, value); + DBusIPCMessage msg(m_serviceName, objectPath(), DBusIPCCommon::PROPERTIES_INTERFACE_NAME, DBusIPCCommon::SET_PROPERTY); + msg << QVariant::fromValue(m_interfaceName); + msg << QVariant::fromValue(property); + msg << QVariant::fromValue(QDBusVariant(QVariant::fromValue(value))); if (isSynchronous()) { auto replyMessage = call(msg); if (replyMessage.isErrorMessage()) { - onServerNotAvailableError(methodName); + onServerNotAvailableError(property); } } else { - asyncCall(msg, this, [this, methodName](const DBusIPCMessage &replyMessage) { + asyncCall(msg, this, [this, property](const DBusIPCMessage &replyMessage) { if (replyMessage.isErrorMessage()) { - onServerNotAvailableError(methodName); + onServerNotAvailableError(property); } }); } diff --git a/src/ipc/dbus/DBusManager.cpp b/src/ipc/dbus/DBusManager.cpp index 2a8189a1..678123d2 100644 --- a/src/ipc/dbus/DBusManager.cpp +++ b/src/ipc/dbus/DBusManager.cpp @@ -44,6 +44,7 @@ DBusManager::DBusManager() : m_busConnection(QDBusConnection::sessionBus()) DBusManager &DBusManager::instance() { + qDBusRegisterMetaType>(); static auto i = new DBusManager(); // TODO solve memory leak return *i; } diff --git a/src/ipc/dbus/DBusObjectRegistry.cpp b/src/ipc/dbus/DBusObjectRegistry.cpp index d91a4ccc..d07c490f 100644 --- a/src/ipc/dbus/DBusObjectRegistry.cpp +++ b/src/ipc/dbus/DBusObjectRegistry.cpp @@ -122,7 +122,7 @@ void DBusObjectRegistry::syncObjects() ObjectRegistryIPCDBusProxy objectRegistryProxy; objectRegistryProxy.ipc()->setServiceName(m_serviceName); objectRegistryProxy.connectToServer(); - Q_ASSERT(objectRegistryProxy.ready()); + // Q_ASSERT(objectRegistryProxy.ready()); updateObjects(objectRegistryProxy.getObjects()); } diff --git a/src/ipc/dbus/DBusRequestHandler.h b/src/ipc/dbus/DBusRequestHandler.h index 8a57f669..f1ba6834 100644 --- a/src/ipc/dbus/DBusRequestHandler.h +++ b/src/ipc/dbus/DBusRequestHandler.h @@ -45,8 +45,11 @@ class FaceliftIPCLibDBus_EXPORT DBusRequestHandler { public: - virtual void deserializePropertyValues(DBusIPCMessage &msg, bool isCompleteSnapshot) = 0; - virtual void deserializeSignal(DBusIPCMessage &msg) = 0; + virtual void unmarshalPropertyValues(DBusIPCMessage &msg) = 0; + virtual void unmarshalPropertiesChanged(DBusIPCMessage &msg) = 0; + virtual QMap getSignals() = 0; + virtual void connectSignals() = 0; + virtual void disconnectSignals() = 0; virtual void setServiceRegistered(bool isRegistered) = 0; }; diff --git a/src/ipc/dbus/IPCDBusServiceAdapterBase.cpp b/src/ipc/dbus/IPCDBusServiceAdapterBase.cpp index bd3e21ed..616dffb5 100644 --- a/src/ipc/dbus/IPCDBusServiceAdapterBase.cpp +++ b/src/ipc/dbus/IPCDBusServiceAdapterBase.cpp @@ -57,29 +57,6 @@ namespace facelift { namespace dbus { -constexpr const char *DBusIPCCommon::SIGNAL_TRIGGERED_SIGNAL_NAME; - -void IPCDBusServiceAdapterBase::initOutgoingSignalMessage() { - m_pendingOutgoingMessage = std::make_unique(objectPath(), interfaceName(), DBusIPCCommon::SIGNAL_TRIGGERED_SIGNAL_NAME); - - // Send property value updates before the signal itself so that they are set before the signal is triggered on the client side. - this->serializePropertyValues(*m_pendingOutgoingMessage, false); -} - -void IPCDBusServiceAdapterBase::serializePropertyValues(DBusIPCMessage &msg, bool isCompleteSnapshot) -{ - Q_ASSERT(service()); - serializeOptionalValue(msg, service()->ready(), m_previousReadyState, isCompleteSnapshot); -} - -void IPCDBusServiceAdapterBase::flush() -{ - if (m_pendingOutgoingMessage) { - this->send(*m_pendingOutgoingMessage); - m_pendingOutgoingMessage.reset(); - } -} - bool IPCDBusServiceAdapterBase::handleMessage(const QDBusMessage &dbusMsg) { DBusIPCMessage requestMessage(dbusMsg); @@ -89,29 +66,33 @@ bool IPCDBusServiceAdapterBase::handleMessage(const QDBusMessage &dbusMsg) qCDebug(LogIpc) << "Handling incoming message: " << requestMessage.toString(); if (dbusMsg.interface() == DBusIPCCommon::INTROSPECTABLE_INTERFACE_NAME) { - // TODO + // is handled via the QDBusVirtualObject } else if (dbusMsg.interface() == DBusIPCCommon::PROPERTIES_INTERFACE_NAME) { - // TODO - } else { + if (!m_signalsConnected) { + m_signalsConnected = true; + qCDebug(LogIpc) << "Enabling IPCDBusServiceAdapter for" << this->service(); + connectSignals(); + } + if (dbusMsg.member() == DBusIPCCommon::GET_ALL_PROPERTIES) { + marshalPropertyValues(dbusMsg.arguments(), replyMessage); + send(replyMessage); + } + else if (dbusMsg.member() == DBusIPCCommon::GET_PROPERTY) { + marshalProperty(dbusMsg.arguments(), replyMessage); + send(replyMessage); + } + else if (dbusMsg.member() == DBusIPCCommon::SET_PROPERTY) { + setProperty(dbusMsg.arguments()); + send(replyMessage); + } + } else if (dbusMsg.interface() == interfaceName()) { if (service()) { bool sendReply = true; - if (requestMessage.member() == DBusIPCCommon::GET_PROPERTIES_MESSAGE_NAME) { - if (!m_signalsConnected) { - m_signalsConnected = true; - QObject::connect(service(), &InterfaceBase::readyChanged, this, [this]() { - this->sendSignal(CommonSignalID::readyChanged); - }); - qCDebug(LogIpc) << "Enabling IPCDBusServiceAdapter for" << this->service(); - connectSignals(); - } - serializePropertyValues(replyMessage, true); - } else { - auto handlingResult = handleMethodCallMessage(requestMessage, replyMessage); - if (handlingResult == IPCHandlingResult::INVALID) { - replyMessage = requestMessage.createErrorReply("Invalid arguments", "TODO"); - } else if (handlingResult == IPCHandlingResult::OK_ASYNC) { - sendReply = false; - } + auto handlingResult = handleMethodCallMessage(requestMessage, replyMessage); + if (handlingResult == IPCHandlingResult::INVALID) { + replyMessage = requestMessage.createErrorReply("Invalid arguments", "TODO"); + } else if (handlingResult == IPCHandlingResult::OK_ASYNC) { + sendReply = false; } if (sendReply) { send(replyMessage); diff --git a/src/ipc/dbus/IPCDBusServiceAdapterBase.h b/src/ipc/dbus/IPCDBusServiceAdapterBase.h index f6d2f988..6a7c4830 100644 --- a/src/ipc/dbus/IPCDBusServiceAdapterBase.h +++ b/src/ipc/dbus/IPCDBusServiceAdapterBase.h @@ -39,8 +39,9 @@ #include #include "IPCServiceAdapterBase.h" #include "DBusIPCMessage.h" +#include "DBusIPCCommon.h" #include "ipc-common.h" -#include "ipc-serialization.h" +#include "FaceliftUtils.h" #include "DBusManagerInterface.h" namespace facelift { @@ -87,18 +88,12 @@ class FaceliftIPCLibDBus_EXPORT IPCDBusServiceAdapterBase : public IPCServiceAda bool handleMessage(const QDBusMessage &dbusMsg); - void flush(); - template - void serializeValue(DBusIPCMessage &msg, const Type &v); - - template - void deserializeValue(DBusIPCMessage &msg, Type &v); + template + inline void sendPropertiesChanged(const QString& property , const Value & value); - void initOutgoingSignalMessage(); - - template - void sendSignal(MemberID signalID, const Args & ... args); + template + void sendSignal(const QString& signalName, const Args & ... args); template void sendAsyncCallAnswer(DBusIPCMessage &replyMessage, const ReturnType returnValue); @@ -109,17 +104,15 @@ class FaceliftIPCLibDBus_EXPORT IPCDBusServiceAdapterBase : public IPCServiceAda virtual IPCHandlingResult handleMethodCallMessage(DBusIPCMessage &requestMessage, DBusIPCMessage &replyMessage) = 0; - virtual void serializePropertyValues(DBusIPCMessage &msg, bool isCompleteSnapshot); + virtual void marshalPropertyValues(const QList& arguments, DBusIPCMessage &msg) = 0; - void registerService() override; + virtual void marshalProperty(const QList& arguments, DBusIPCMessage &msg) = 0; - void unregisterService() override; + virtual void setProperty(const QList& arguments) = 0; - template - void serializeOptionalValue(DBusIPCMessage &msg, const Type ¤tValue, Type &previousValue, bool isCompleteSnapshot); + void registerService() override; - template - void serializeOptionalValue(DBusIPCMessage &msg, const Type ¤tValue, bool isCompleteSnapshot); + void unregisterService() override; virtual void appendDBUSIntrospectionData(QTextStream &s) const = 0; @@ -134,7 +127,6 @@ class FaceliftIPCLibDBus_EXPORT IPCDBusServiceAdapterBase : public IPCServiceAda } protected: - std::unique_ptr m_pendingOutgoingMessage; DBusVirtualObject m_dbusVirtualObject; QString m_introspectionData; @@ -147,64 +139,30 @@ class FaceliftIPCLibDBus_EXPORT IPCDBusServiceAdapterBase : public IPCServiceAda DBusManagerInterface& m_dbusManager; }; -template -inline void IPCDBusServiceAdapterBase::serializeValue(DBusIPCMessage &msg, const Type &v) +template +inline void IPCDBusServiceAdapterBase::sendPropertiesChanged(const QString& property, const Value &value) { - typedef typename IPCTypeRegisterHandler::SerializedType SerializedType; - IPCTypeHandler::write(msg.outputPayLoad(), IPCTypeRegisterHandler::convertToSerializedType(v, *this)); + DBusIPCMessage reply(objectPath(), DBusIPCCommon::PROPERTIES_INTERFACE_NAME, DBusIPCCommon::PROPERTIES_CHANGED_SIGNAL_NAME); + reply << interfaceName(); + reply << QVariantMap{{property, QVariant::fromValue(value)}}; + this->send(reply); } -template -inline void IPCDBusServiceAdapterBase::deserializeValue(DBusIPCMessage &msg, Type &v) +template +inline void IPCDBusServiceAdapterBase::sendSignal(const QString& signalName, const Args & ... args) { - typedef typename IPCTypeRegisterHandler::SerializedType SerializedType; - SerializedType serializedValue; - IPCTypeHandler::read(msg.inputPayLoad(), serializedValue); - IPCTypeRegisterHandler::convertToDeserializedType(v, serializedValue, *this); -} - -template -inline void IPCDBusServiceAdapterBase::sendSignal(MemberID signalID, const Args & ... args) -{ - if (m_pendingOutgoingMessage == nullptr) { - initOutgoingSignalMessage(); - auto argTuple = std::make_tuple(signalID, args ...); - for_each_in_tuple(argTuple, SerializeParameterFunction(m_pendingOutgoingMessage->outputPayLoad(), *this)); - flush(); - } + DBusIPCMessage signal(objectPath(), interfaceName(), signalName); + auto argTuple = std::make_tuple(args ...); + for_each_in_tuple(argTuple, [this, &signal](const auto &v){signal << QVariant::fromValue(v);}); + this->send(signal); } template inline void IPCDBusServiceAdapterBase::sendAsyncCallAnswer(DBusIPCMessage &replyMessage, const ReturnType returnValue) { - serializeValue(replyMessage, returnValue); + replyMessage << QVariant::fromValue(returnValue); send(replyMessage); } -template -inline void IPCDBusServiceAdapterBase::serializeOptionalValue(DBusIPCMessage &msg, const Type ¤tValue, Type &previousValue, bool isCompleteSnapshot) -{ - if (isCompleteSnapshot) { - serializeValue(msg, currentValue); - } else { - if (previousValue == currentValue) { - msg.outputPayLoad().writeSimple(false); - } else { - msg.outputPayLoad().writeSimple(true); - serializeValue(msg, currentValue); - previousValue = currentValue; - } - } -} - -template -inline void IPCDBusServiceAdapterBase::serializeOptionalValue(DBusIPCMessage &msg, const Type ¤tValue, bool isCompleteSnapshot) -{ - msg.outputPayLoad().writeSimple(isCompleteSnapshot); - if (isCompleteSnapshot) { - serializeValue(msg, currentValue); - } -} - } // end namespace dbus } // end namespace facelift diff --git a/src/ipc/ipc-common/AppendDBUSSignatureFunction.h b/src/ipc/ipc-common/AppendDBUSSignatureFunction.h deleted file mode 100644 index c24408df..00000000 --- a/src/ipc/ipc-common/AppendDBUSSignatureFunction.h +++ /dev/null @@ -1,68 +0,0 @@ -/********************************************************************** -** -** Copyright (C) 2020 Luxoft Sweden AB -** -** This file is part of the FaceLift project -** -** Permission is hereby granted, free of charge, to any person -** obtaining a copy of this software and associated documentation files -** (the "Software"), to deal in the Software without restriction, -** including without limitation the rights to use, copy, modify, merge, -** publish, distribute, sublicense, and/or sell copies of the Software, -** and to permit persons to whom the Software is furnished to do so, -** subject to the following conditions: -** -** The above copyright notice and this permission notice shall be -** included in all copies or substantial portions of the Software. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -** ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -** SOFTWARE. -** -** SPDX-License-Identifier: MIT -** -**********************************************************************/ - -#pragma once - -#if defined(FaceliftIPCCommonLib_LIBRARY) -# define FaceliftIPCCommonLib_EXPORT Q_DECL_EXPORT -#else -# define FaceliftIPCCommonLib_EXPORT Q_DECL_IMPORT -#endif - - -#include - -#include - -#include "FaceliftUtils.h" - -namespace facelift { - -struct FaceliftIPCCommonLib_EXPORT AppendDBUSSignatureFunction -{ - AppendDBUSSignatureFunction(QTextStream &s) : - s(s) - { - } - - QTextStream &s; - - template - void operator()(T &&t) - { - Q_UNUSED(t); - typedef typename std::decay::type TupleType; - std::tuple dummyTuple; - appendDBUSTypeSignature(s, dummyTuple); - } -}; - - -} diff --git a/src/ipc/ipc-common/CMakeLists.txt b/src/ipc/ipc-common/CMakeLists.txt index e85b58a6..0a8287e7 100644 --- a/src/ipc/ipc-common/CMakeLists.txt +++ b/src/ipc/ipc-common/CMakeLists.txt @@ -2,9 +2,7 @@ facelift_add_library(FaceliftIPCCommonLib SOURCES ipc-common.cpp - IPCProxyBaseBase.cpp ModuleIPCBase.cpp - ipc-serialization.cpp IPCServiceAdapterBase.cpp NotAvailableImplBase.cpp IPCAdapterFactoryManager.cpp @@ -13,8 +11,6 @@ facelift_add_library(FaceliftIPCCommonLib InterfaceManager.cpp IPCProxyNewBase.cpp NewIPCServiceAdapterBase.cpp - OutputPayLoad.cpp - InputPayLoad.cpp LocalProviderBinderBase.cpp HEADERS ipc-common.h @@ -24,10 +20,8 @@ facelift_add_library(FaceliftIPCCommonLib LocalProviderBinder.h LocalProviderBinderBase.h StaticArrayReference.h - IPCProxyBaseBase.h IPCProxyBase.h IPCProxy.h - IPCTypeHandler.h InterfaceManager.h InterfaceManagerInterface.h IPCProxyModelProperty.h @@ -36,17 +30,10 @@ facelift_add_library(FaceliftIPCCommonLib IPCServiceAdapterBase.h NewIPCServiceAdapterBase.h ModuleIPCBase.h - ipc-serialization.h IPCAdapterFactoryManager.h IPCAttachedPropertyFactory.h IPCServiceAdapter.h Registry.h - InputPayLoad.h - OutputPayLoad.h - DBusSignatureHelper.h - IPCTypeRegisterHandler.h - AppendDBUSSignatureFunction.h - SerializeParameterFunction.h LINK_LIBRARIES FaceliftModelLib FaceliftCommonLib MONOLITHIC_SUPPORTED ) diff --git a/src/ipc/ipc-common/DBusSignatureHelper.h b/src/ipc/ipc-common/DBusSignatureHelper.h deleted file mode 100644 index 7fa042dc..00000000 --- a/src/ipc/ipc-common/DBusSignatureHelper.h +++ /dev/null @@ -1,141 +0,0 @@ -/********************************************************************** -** -** Copyright (C) 2020 Luxoft Sweden AB -** -** This file is part of the FaceLift project -** -** Permission is hereby granted, free of charge, to any person -** obtaining a copy of this software and associated documentation files -** (the "Software"), to deal in the Software without restriction, -** including without limitation the rights to use, copy, modify, merge, -** publish, distribute, sublicense, and/or sell copies of the Software, -** and to permit persons to whom the Software is furnished to do so, -** subject to the following conditions: -** -** The above copyright notice and this permission notice shall be -** included in all copies or substantial portions of the Software. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -** ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -** SOFTWARE. -** -** SPDX-License-Identifier: MIT -** -**********************************************************************/ - -#pragma once - -#if defined(FaceliftIPCCommonLib_LIBRARY) -# define FaceliftIPCCommonLib_EXPORT Q_DECL_EXPORT -#else -# define FaceliftIPCCommonLib_EXPORT Q_DECL_IMPORT -#endif - -#include "IPCTypeHandler.h" -#include - -namespace facelift { - -class FaceliftIPCCommonLib_EXPORT DBusSignatureHelper { - - public: - - template - typename std::enable_if::type - static appendDBUSMethodArgumentsSignature(QTextStream &s, std::tuple &t, const std::array &argNames) - { - Q_UNUSED(s); - Q_UNUSED(t); - Q_UNUSED(argNames); - } - - template - typename std::enable_if < I::type - static appendDBUSMethodArgumentsSignature(QTextStream &s, std::tuple &t, const std::array &argNames) - { - using Type = decltype(std::get(t)); - s << "::writeDBUSSignature(s); - s << "\" direction=\"in\"/>"; - appendDBUSMethodArgumentsSignature(s, t, argNames); - } - - - template - typename std::enable_if::type - static appendDBUSSignalArgumentsSignature(QTextStream &s, std::tuple &t, const std::array &argNames) - { - Q_UNUSED(s); - Q_UNUSED(t); - Q_UNUSED(argNames); - } - - template - typename std::enable_if < I::type - static appendDBUSSignalArgumentsSignature(QTextStream &s, std::tuple &t, const std::array &argNames) - { - using Type = decltype(std::get(t)); - s << "::writeDBUSSignature(s); - s << "\"/>"; - appendDBUSSignalArgumentsSignature(s, t, argNames); - } - - template - typename std::enable_if::type - static appendDBUSTypeSignature(QTextStream &s, std::tuple &t) - { - Q_UNUSED(s); - Q_UNUSED(t); - } - - template - typename std::enable_if < I::type - static appendDBUSTypeSignature(QTextStream &s, std::tuple &t) - { - using Type = decltype(std::get(t)); - IPCTypeHandler::writeDBUSSignature(s); - appendDBUSTypeSignature(s, t); - } - - template - static void addPropertySignature(QTextStream &s, const char *propertyName, bool isReadonly) - { - s << " dummyTuple; - appendDBUSTypeSignature(s, dummyTuple); - s << "\" access=\"" << (isReadonly ? "read" : "readwrite") << "\"/>"; - } - - template - static void addMethodSignature(QTextStream &s, const char *methodName, - const std::array &argNames) - { - s << ""; - std::tuple t; // TODO : get rid of the tuple - appendDBUSMethodArgumentsSignature(s, t, argNames); - s << ""; - } - - template - static void addSignalSignature(QTextStream &s, const char *methodName, - const std::array &argNames) - { - s << ""; - std::tuple t; // TODO : get rid of the tuple - appendDBUSSignalArgumentsSignature(s, t, argNames); - s << ""; - } - -}; - -} diff --git a/src/ipc/ipc-common/IPCAdapterModelPropertyHandler.h b/src/ipc/ipc-common/IPCAdapterModelPropertyHandler.h index 72481e98..1dcb0827 100644 --- a/src/ipc/ipc-common/IPCAdapterModelPropertyHandler.h +++ b/src/ipc/ipc-common/IPCAdapterModelPropertyHandler.h @@ -30,6 +30,7 @@ #pragma once #include +#include #include "ipc-common.h" #if defined(FaceliftIPCCommonLib_LIBRARY) @@ -110,12 +111,10 @@ class IPCAdapterModelPropertyHandler void handleModelRequest(typename IPCAdapterType::InputIPCMessage &requestMessage, typename IPCAdapterType::OutputIPCMessage &replyMessage) { - std::tuple> requestResult; - int & first = std::get<0>(requestResult); - auto & list = std::get<1>(requestResult); - int last; - m_adapter.deserializeValue(requestMessage, first); - m_adapter.deserializeValue(requestMessage, last); + QListIterator argumentsIterator(requestMessage.arguments()); + int first = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): int()); + int last = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): int()); + QList list; // Make sure we do not request items which are out of range first = qMax(first, 0); @@ -125,7 +124,8 @@ class IPCAdapterModelPropertyHandler list.append(m_model->elementAt(i)); } - m_adapter.serializeValue(replyMessage, requestResult); + replyMessage << QVariant::fromValue(first); + replyMessage << QVariant::fromValue(list); } private: diff --git a/src/ipc/ipc-common/IPCProxyBase.h b/src/ipc/ipc-common/IPCProxyBase.h index 25701b8d..1903a109 100644 --- a/src/ipc/ipc-common/IPCProxyBase.h +++ b/src/ipc/ipc-common/IPCProxyBase.h @@ -31,7 +31,6 @@ #pragma once #include "ipc-common.h" -#include "IPCProxyBaseBase.h" #include "IPCProxyBinderBase.h" @@ -44,7 +43,7 @@ namespace facelift { template -class IPCProxyBase : public AdapterType, protected IPCProxyBaseBase +class IPCProxyBase : public AdapterType { public: diff --git a/src/ipc/ipc-common/IPCProxyBaseBase.cpp b/src/ipc/ipc-common/IPCProxyBaseBase.cpp deleted file mode 100644 index b2dbbc9d..00000000 --- a/src/ipc/ipc-common/IPCProxyBaseBase.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/********************************************************************** -** -** Copyright (C) 2020 Luxoft Sweden AB -** -** This file is part of the FaceLift project -** -** Permission is hereby granted, freIPCServiceAdapterBasee of charge, to any person -** obtaining a copy of this software and associated documentation files -** (the "Software"), to deal in the Software without restriction, -** including without limitation the rights to use, copy, modify, merge, -** publish, distribute, sublicense, and/or sell copies of the Software, -** and to permit persons to whom the Software is furnished to do so, -** subject to the following conditions: -** -** The above copyright notice and this permission notice shall be -** included in all copies or substantial portions of the Software. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -** ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -** SOFTWARE. -** -** SPDX-License-Identifier: MIT -** -**********************************************************************/ - -#include "IPCProxyBase.h" -#include "FaceliftModel.h" - -namespace facelift { - -void IPCProxyBaseBase::deserializeCommonSignal(facelift::CommonSignalID signalID, InterfaceBase* i) -{ - switch (signalID) { - case facelift::CommonSignalID::readyChanged: - emit i->readyChanged(); - break; - default: - qFatal("Unknown signal ID"); - } -} - -} diff --git a/src/ipc/ipc-common/IPCProxyBaseBase.h b/src/ipc/ipc-common/IPCProxyBaseBase.h deleted file mode 100644 index d2f63ab3..00000000 --- a/src/ipc/ipc-common/IPCProxyBaseBase.h +++ /dev/null @@ -1,51 +0,0 @@ -/********************************************************************** -** -** Copyright (C) 2020 Luxoft Sweden AB -** -** This file is part of the FaceLift project -** -** Permission is hereby granted, freIPCServiceAdapterBasee of charge, to any person -** obtaining a copy of this software and associated documentation files -** (the "Software"), to deal in the Software without restriction, -** including without limitation the rights to use, copy, modify, merge, -** publish, distribute, sublicense, and/or sell copies of the Software, -** and to permit persons to whom the Software is furnished to do so, -** subject to the following conditions: -** -** The above copyright notice and this permission notice shall be -** included in all copies or substantial portions of the Software. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -** ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -** SOFTWARE. -** -** SPDX-License-Identifier: MIT -** -**********************************************************************/ - -#pragma once - -#include "ipc-common.h" - -#if defined(FaceliftIPCCommonLib_LIBRARY) -# define FaceliftIPCCommonLib_EXPORT Q_DECL_EXPORT -#else -# define FaceliftIPCCommonLib_EXPORT Q_DECL_IMPORT -#endif - -namespace facelift { - -class FaceliftIPCCommonLib_EXPORT IPCProxyBaseBase { - -public: - - void deserializeCommonSignal(facelift::CommonSignalID signalID, InterfaceBase* i); - -}; - -} diff --git a/src/ipc/ipc-common/IPCProxyModelProperty.h b/src/ipc/ipc-common/IPCProxyModelProperty.h index 28aa5807..6db43c65 100644 --- a/src/ipc/ipc-common/IPCProxyModelProperty.h +++ b/src/ipc/ipc-common/IPCProxyModelProperty.h @@ -30,6 +30,9 @@ #pragma once #include +#include +#include "FaceliftUtils.h" +#include "ModelProperty.h" #if defined(FaceliftIPCCommonLib_LIBRARY) # define FaceliftIPCCommonLib_EXPORT Q_DECL_EXPORT @@ -52,16 +55,15 @@ class IPCProxyModelProperty : public facelift::ModelProperty void handleSignal(typename IPCProxyType::InputIPCMessage &msg) { - ModelUpdateEvent event; - m_proxy.deserializeValue(msg, event); + QListIterator argumentsIterator(msg.arguments()); + ModelUpdateEvent event = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): ModelUpdateEvent()); switch (event) { case ModelUpdateEvent::DataChanged: { - int first; - QList list; - m_proxy.deserializeValue(msg, first); - m_proxy.deserializeValue(msg, list); + int first = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): int()); + QList list = (argumentsIterator.hasNext() ? qdbus_cast>(argumentsIterator.next()): QList()); + int last = first + list.size() - 1; for (int i = first; i <= last; ++i) { m_cache.insert(i, list.at(i - first)); @@ -71,9 +73,8 @@ class IPCProxyModelProperty : public facelift::ModelProperty case ModelUpdateEvent::Insert: { - int first, last; - m_proxy.deserializeValue(msg, first); - m_proxy.deserializeValue(msg, last); + int first = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): int()); + int last = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): int()); emit this->beginInsertElements(first, last); clear(); // TODO: insert elements in cache without clear() emit this->endInsertElements(); @@ -81,9 +82,8 @@ class IPCProxyModelProperty : public facelift::ModelProperty case ModelUpdateEvent::Remove: { - int first, last; - m_proxy.deserializeValue(msg, first); - m_proxy.deserializeValue(msg, last); + int first = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): int()); + int last = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): int()); emit this->beginRemoveElements(first, last); m_cache.clear(); // TODO: remove elements from cache without clear() emit this->endRemoveElements(); @@ -91,10 +91,9 @@ class IPCProxyModelProperty : public facelift::ModelProperty case ModelUpdateEvent::Move: { - int sourceFirstIndex, sourceLastIndex, destinationIndex; - m_proxy.deserializeValue(msg, sourceFirstIndex); - m_proxy.deserializeValue(msg, sourceLastIndex); - m_proxy.deserializeValue(msg, destinationIndex); + int sourceFirstIndex = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): int()); + int sourceLastIndex = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): int()); + int destinationIndex = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): int()); emit this->beginMoveElements(sourceFirstIndex, sourceLastIndex, destinationIndex); m_cache.clear(); // TODO: move elements in cache without clear() emit this->endMoveElements(); @@ -103,8 +102,7 @@ class IPCProxyModelProperty : public facelift::ModelProperty case ModelUpdateEvent::Reset: { emit this->beginResetModel(); - int size; - m_proxy.deserializeValue(msg, size); + int size = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): int()); this->setSize(size); clear(); emit this->endResetModel(); @@ -135,11 +133,10 @@ class IPCProxyModelProperty : public facelift::ModelProperty --last; } - std::tuple> requestResult; - m_proxy.ipc()->sendMethodCallWithReturn(requestMemberID, requestResult, first, last); - - first = std::get<0>(requestResult); - auto &list = std::get<1>(requestResult); + QList args = m_proxy.ipc()->sendMethodCallWithReturn(requestMemberID, first, last); + QListIterator argumentsIterator(args); + first = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): int()); + QList list = (argumentsIterator.hasNext() ? qdbus_cast>(argumentsIterator.next()): QList()); last = first + list.size() - 1; for (int i = first; i <= last; ++i) { @@ -187,10 +184,11 @@ class IPCProxyModelProperty : public facelift::ModelProperty } if (first <= last) { - m_proxy.ipc()->sendAsyncMethodCall(requestMemberID, facelift::AsyncAnswer>>(&m_proxy, [this](std::tuple> result) { + m_proxy.ipc()->sendAsyncMethodCall(requestMemberID, facelift::AsyncAnswer>(&m_proxy, [this](QList arguments) { // qCDebug(LogIpc) << "Received model items " << first << "-" << last; - auto & first = std::get<0>(result); - auto & list = std::get<1>(result); + QListIterator argumentsIterator(arguments); + auto first = (argumentsIterator.hasNext() ? qdbus_cast(argumentsIterator.next()): int()); + auto list = (argumentsIterator.hasNext() ? qdbus_cast>(argumentsIterator.next()): QList()); auto last = first + list.size() - 1; for (int i = first; i <= last; ++i) { auto &newItem = list[i - first]; diff --git a/src/ipc/ipc-common/IPCTypeHandler.h b/src/ipc/ipc-common/IPCTypeHandler.h deleted file mode 100644 index ac1d1169..00000000 --- a/src/ipc/ipc-common/IPCTypeHandler.h +++ /dev/null @@ -1,262 +0,0 @@ -/********************************************************************** -** -** Copyright (C) 2020 Luxoft Sweden AB -** -** This file is part of the FaceLift project -** -** Permission is hereby granted, free of charge, to any person -** obtaining a copy of this software and associated documentation files -** (the "Software"), to deal in the Software without restriction, -** including without limitation the rights to use, copy, modify, merge, -** publish, distribute, sublicense, and/or sell copies of the Software, -** and to permit persons to whom the Software is furnished to do so, -** subject to the following conditions: -** -** The above copyright notice and this permission notice shall be -** included in all copies or substantial portions of the Software. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -** ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -** SOFTWARE. -** -** SPDX-License-Identifier: MIT -** -**********************************************************************/ - -#pragma once - -#if defined(FaceliftIPCCommonLib_LIBRARY) -# define FaceliftIPCCommonLib_EXPORT Q_DECL_EXPORT -#else -# define FaceliftIPCCommonLib_EXPORT Q_DECL_IMPORT -#endif - -#include "ipc-common.h" -#include "ModelProperty.h" -#include "OutputPayLoad.h" -#include "InputPayLoad.h" -#include "AppendDBUSSignatureFunction.h" - -namespace facelift { - -template -struct IPCTypeHandler -{ - static void writeDBUSSignature(QTextStream &s) - { - s << "i"; - } - - static void write(OutputPayLoad &msg, const Type &v) - { - msg.writeSimple(v); - } - - static void read(InputPayLoad &msg, Type &v) - { - msg.readNextParameter(v); - } - -}; - - -template<> -struct IPCTypeHandler -{ - static void writeDBUSSignature(QTextStream &s) - { - s << "d"; - } - - static void write(OutputPayLoad &msg, const double &v) - { - msg.writeSimple(v); - } - - static void read(InputPayLoad &msg, double &v) - { - double d; - msg.readNextParameter(d); - v = d; - } - -}; - - -template<> -struct IPCTypeHandler -{ - static void writeDBUSSignature(QTextStream &s) - { - s << "b"; - } - - static void write(OutputPayLoad &msg, const bool &v) - { - msg.writeSimple(v); - } - - static void read(InputPayLoad &msg, bool &v) - { - msg.readNextParameter(v); - } - -}; - - -template<> -struct IPCTypeHandler -{ - static void writeDBUSSignature(QTextStream &s) - { - s << "s"; - } - - static void write(OutputPayLoad &msg, const QString &v) - { - msg.writeSimple(v); - } - - static void read(InputPayLoad &msg, QString &v) - { - msg.readNextParameter(v); - } - -}; - -template -struct IPCTypeHandler::value>::type> -{ - - static void writeDBUSSignature(QTextStream &s) - { - typename Type::FieldTupleTypes t; // TODO : get rid of that tuple - s << "("; - for_each_in_tuple(t, AppendDBUSSignatureFunction(s)); - s << ")"; - } - - static void write(OutputPayLoad &msg, const Type ¶m) - { - IPCTypeHandler::write(msg, param.asTuple()); - } - - static void read(InputPayLoad &msg, Type ¶m) - { - IPCTypeHandler::read(msg, param.asTuple()); - } - -}; - - -template -struct IPCTypeHandler> -{ - static void write(OutputPayLoad &msg, const std::tuple ¶m) - { - for_each_in_tuple_const(param, StreamWriteFunction(msg)); - } - - static void read(InputPayLoad &msg, std::tuple ¶m) - { - for_each_in_tuple(param, StreamReadFunction(msg)); - } - -}; - - -template -struct IPCTypeHandler::value>::type> -{ - static void writeDBUSSignature(QTextStream &s) - { - s << "i"; - } - - static void write(OutputPayLoad &msg, const Type ¶m) - { - msg.writeSimple(static_cast(param)); - } - - static void read(InputPayLoad &msg, Type ¶m) - { - int i; - msg.readNextParameter(i); - param = static_cast(i); - } -}; - - -template -struct IPCTypeHandler> -{ - static void writeDBUSSignature(QTextStream &s) - { - s << "a"; - IPCTypeHandler::writeDBUSSignature(s); - } - - static void write(OutputPayLoad &msg, const QList &list) - { - int count = list.size(); - msg.writeSimple(count); - for (const auto &e : list) { - IPCTypeHandler::write(msg, e); - } - } - - static void read(InputPayLoad &msg, QList &list) - { - list.clear(); - int count; - msg.readNextParameter(count); - for (int i = 0; i < count; i++) { - ElementType e; - IPCTypeHandler::read(msg, e); - list.append(e); - } - } - -}; - - -template -struct IPCTypeHandler> -{ - static void writeDBUSSignature(QTextStream &s) - { - s << "a{sv}"; // TODO: is it so? - IPCTypeHandler::writeDBUSSignature(s); - } - - static void write(OutputPayLoad &msg, const QMap &map) - { - int count = map.size(); - msg.writeSimple(count); - for (auto i = map.constBegin(); i != map.constEnd(); ++i) { - IPCTypeHandler::write(msg, i.key()); - IPCTypeHandler::write(msg, i.value()); - } - } - - static void read(InputPayLoad &msg, QMap &map) - { - map.clear(); - int count; - msg.readNextParameter(count); - for (int i = 0; i < count; i++) { - QString key; - ElementType value; - IPCTypeHandler::read(msg, key); - IPCTypeHandler::read(msg, value); - map.insert(key, value); - } - } -}; - -} diff --git a/src/ipc/ipc-common/IPCTypeRegisterHandler.h b/src/ipc/ipc-common/IPCTypeRegisterHandler.h deleted file mode 100644 index 7e5c3162..00000000 --- a/src/ipc/ipc-common/IPCTypeRegisterHandler.h +++ /dev/null @@ -1,149 +0,0 @@ -/********************************************************************** -** -** Copyright (C) 2020 Luxoft Sweden AB -** -** This file is part of the FaceLift project -** -** Permission is hereby granted, free of charge, to any person -** obtaining a copy of this software and associated documentation files -** (the "Software"), to deal in the Software without restriction, -** including without limitation the rights to use, copy, modify, merge, -** publish, distribute, sublicense, and/or sell copies of the Software, -** and to permit persons to whom the Software is furnished to do so, -** subject to the following conditions: -** -** The above copyright notice and this permission notice shall be -** included in all copies or substantial portions of the Software. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -** ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -** SOFTWARE. -** -** SPDX-License-Identifier: MIT -** -**********************************************************************/ - -#pragma once - -#if defined(FaceliftIPCCommonLib_LIBRARY) -# define FaceliftIPCCommonLib_EXPORT Q_DECL_EXPORT -#else -# define FaceliftIPCCommonLib_EXPORT Q_DECL_IMPORT -#endif - -#include - -#include "FaceliftModel.h" - -namespace facelift { - -template -struct IPCTypeRegisterHandler -{ - typedef Type SerializedType; - - template - static const Type &convertToSerializedType(const Type &v, OwnerType &adapter) - { - Q_UNUSED(adapter); - return v; - } - - template - static void convertToDeserializedType(Type &v, const SerializedType &serializedValue, OwnerType &adapter) - { - Q_UNUSED(adapter); - v = serializedValue; - } - -}; - - -template -struct IPCTypeRegisterHandler > -{ - typedef QList::SerializedType> SerializedType; - - template - static SerializedType convertToSerializedType(const QList &v, OwnerType &adapter) - { - Q_UNUSED(v); - Q_UNUSED(adapter); - SerializedType convertedValue; - for (const auto &e : v) { - convertedValue.append(IPCTypeRegisterHandler::convertToSerializedType(e, adapter)); - } - return convertedValue; - } - - template - static void convertToDeserializedType(QList &v, const SerializedType &serializedValue, OwnerType &adapter) - { - v.clear(); - for (const auto &e : serializedValue) { - Type c; - IPCTypeRegisterHandler::convertToDeserializedType(c, e, adapter); - v.append(c); - } - } - -}; - - -template -struct IPCTypeRegisterHandler > -{ - typedef QMap::SerializedType> SerializedType; - - template - static SerializedType convertToSerializedType(const QMap &v, OwnerType &adapter) - { - SerializedType convertedValue; - for (const auto &key : v.keys()) { - convertedValue.insert(key, IPCTypeRegisterHandler::convertToSerializedType(v[key], adapter)); - } - return convertedValue; - } - - template - static void convertToDeserializedType(QMap &v, const SerializedType &serializedValue, OwnerType &adapter) - { - v.clear(); - for (const auto &key : serializedValue.keys()) { - Type c; - IPCTypeRegisterHandler::convertToDeserializedType(c, serializedValue[key], adapter); - v.insert(key, c); - } - } - -}; - - -template -struct IPCTypeRegisterHandler::value>::type> -{ - typedef QString SerializedType; - - template - static SerializedType convertToSerializedType(Type *const &v, OwnerType &adapter) - { - using IPCAdapterType = typename OwnerType::template IPCAdapterType; - return adapter.template getOrCreateAdapter< IPCAdapterType >(v)->objectPath(); - } - - template - static void convertToDeserializedType(Type * &v, const SerializedType &serializedValue, OwnerType &owner) - { - using IPCProxyType = typename OwnerType::template IPCProxyType; - v = owner.template getOrCreateSubProxy(serializedValue); - } - -}; - -} - diff --git a/src/ipc/ipc-common/InputPayLoad.cpp b/src/ipc/ipc-common/InputPayLoad.cpp deleted file mode 100644 index eb13413c..00000000 --- a/src/ipc/ipc-common/InputPayLoad.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/********************************************************************** -** -** Copyright (C) 2020 Luxoft Sweden AB -** -** This file is part of the FaceLift project -** -** Permission is hereby granted, free of charge, to any person -** obtaining a copy of this software and associated documentation files -** (the "Software"), to deal in the Software without restriction, -** including without limitation the rights to use, copy, modify, merge, -** publish, distribute, sublicense, and/or sell copies of the Software, -** and to permit persons to whom the Software is furnished to do so, -** subject to the following conditions: -** -** The above copyright notice and this permission notice shall be -** included in all copies or substantial portions of the Software. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -** ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -** SOFTWARE. -** -** SPDX-License-Identifier: MIT -** -**********************************************************************/ -#include "InputPayLoad.h" - -namespace facelift { - -InputPayLoad::InputPayLoad(const QByteArray &payloadArray) : - m_payloadArray(payloadArray), - m_dataStream(m_payloadArray) -{ -} - -InputPayLoad::~InputPayLoad() = default; - - -} diff --git a/src/ipc/ipc-common/InputPayLoad.h b/src/ipc/ipc-common/InputPayLoad.h deleted file mode 100644 index 56c637ce..00000000 --- a/src/ipc/ipc-common/InputPayLoad.h +++ /dev/null @@ -1,69 +0,0 @@ -/********************************************************************** -** -** Copyright (C) 2020 Luxoft Sweden AB -** -** This file is part of the FaceLift project -** -** Permission is hereby granted, free of charge, to any person -** obtaining a copy of this software and associated documentation files -** (the "Software"), to deal in the Software without restriction, -** including without limitation the rights to use, copy, modify, merge, -** publish, distribute, sublicense, and/or sell copies of the Software, -** and to permit persons to whom the Software is furnished to do so, -** subject to the following conditions: -** -** The above copyright notice and this permission notice shall be -** included in all copies or substantial portions of the Software. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -** ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -** SOFTWARE. -** -** SPDX-License-Identifier: MIT -** -**********************************************************************/ -#pragma once - -#if defined(FaceliftIPCCommonLib_LIBRARY) -# define FaceliftIPCCommonLib_EXPORT Q_DECL_EXPORT -#else -# define FaceliftIPCCommonLib_EXPORT Q_DECL_IMPORT -#endif - -#include -#include - -namespace facelift { - -class FaceliftIPCCommonLib_EXPORT InputPayLoad -{ - -public: - InputPayLoad(const QByteArray &payloadArray); - - ~InputPayLoad(); - - template - void readNextParameter(Type &v) - { - m_dataStream >> v; - // qCDebug(LogIpc) << "Read from message : " << v; - } - - const QByteArray &getContent() const - { - return m_payloadArray; - } - -private: - const QByteArray& m_payloadArray; - QDataStream m_dataStream; -}; - -} - diff --git a/src/ipc/ipc-common/OutputPayLoad.cpp b/src/ipc/ipc-common/OutputPayLoad.cpp deleted file mode 100644 index f9930d71..00000000 --- a/src/ipc/ipc-common/OutputPayLoad.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/********************************************************************** -** -** Copyright (C) 2020 Luxoft Sweden AB -** -** This file is part of the FaceLift project -** -** Permission is hereby granted, free of charge, to any person -** obtaining a copy of this software and associated documentation files -** (the "Software"), to deal in the Software without restriction, -** including without limitation the rights to use, copy, modify, merge, -** publish, distribute, sublicense, and/or sell copies of the Software, -** and to permit persons to whom the Software is furnished to do so, -** subject to the following conditions: -** -** The above copyright notice and this permission notice shall be -** included in all copies or substantial portions of the Software. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -** ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -** SOFTWARE. -** -** SPDX-License-Identifier: MIT -** -**********************************************************************/ -#include "OutputPayLoad.h" - -namespace facelift { - -OutputPayLoad::OutputPayLoad(QByteArray &payloadArray) : m_payloadArray(payloadArray), m_dataStream(&m_payloadArray, QIODevice::WriteOnly) -{ -} - - -} diff --git a/src/ipc/ipc-common/OutputPayLoad.h b/src/ipc/ipc-common/OutputPayLoad.h deleted file mode 100644 index 436aca87..00000000 --- a/src/ipc/ipc-common/OutputPayLoad.h +++ /dev/null @@ -1,69 +0,0 @@ -/********************************************************************** -** -** Copyright (C) 2020 Luxoft Sweden AB -** -** This file is part of the FaceLift project -** -** Permission is hereby granted, free of charge, to any person -** obtaining a copy of this software and associated documentation files -** (the "Software"), to deal in the Software without restriction, -** including without limitation the rights to use, copy, modify, merge, -** publish, distribute, sublicense, and/or sell copies of the Software, -** and to permit persons to whom the Software is furnished to do so, -** subject to the following conditions: -** -** The above copyright notice and this permission notice shall be -** included in all copies or substantial portions of the Software. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -** ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -** SOFTWARE. -** -** SPDX-License-Identifier: MIT -** -**********************************************************************/ -#pragma once - -#include -#include - -#if defined(FaceliftIPCCommonLib_LIBRARY) -# define FaceliftIPCCommonLib_EXPORT Q_DECL_EXPORT -#else -# define FaceliftIPCCommonLib_EXPORT Q_DECL_IMPORT -#endif - -namespace facelift { - -class FaceliftIPCCommonLib_EXPORT OutputPayLoad -{ - -public: - OutputPayLoad(QByteArray &payloadArray); - - template - void writeSimple(const Type &v) - { - // qCDebug(LogIpc) << "Writing to message : " << v; - m_dataStream << v; - } - - const QByteArray &getContent() const - { - return m_payloadArray; - } - - -private: - QByteArray& m_payloadArray; - QDataStream m_dataStream; -}; - -} - - diff --git a/src/ipc/ipc-common/SerializeParameterFunction.h b/src/ipc/ipc-common/SerializeParameterFunction.h deleted file mode 100644 index 89a9c757..00000000 --- a/src/ipc/ipc-common/SerializeParameterFunction.h +++ /dev/null @@ -1,67 +0,0 @@ -/********************************************************************** -** -** Copyright (C) 2020 Luxoft Sweden AB -** -** This file is part of the FaceLift project -** -** Permission is hereby granted, free of charge, to any person -** obtaining a copy of this software and associated documentation files -** (the "Software"), to deal in the Software without restriction, -** including without limitation the rights to use, copy, modify, merge, -** publish, distribute, sublicense, and/or sell copies of the Software, -** and to permit persons to whom the Software is furnished to do so, -** subject to the following conditions: -** -** The above copyright notice and this permission notice shall be -** included in all copies or substantial portions of the Software. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -** ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -** SOFTWARE. -** -** SPDX-License-Identifier: MIT -** -**********************************************************************/ - -#pragma once - -#if defined(FaceliftIPCCommonLib_LIBRARY) -# define FaceliftIPCCommonLib_EXPORT Q_DECL_EXPORT -#else -# define FaceliftIPCCommonLib_EXPORT Q_DECL_IMPORT -#endif - -#include - -#include "OutputPayLoad.h" -#include "IPCTypeHandler.h" -#include "IPCTypeRegisterHandler.h" - -namespace facelift { - -template -struct SerializeParameterFunction -{ - SerializeParameterFunction(OutputPayLoad &msg, const ParentType &parent) : - m_msg(msg), - m_parent(parent) - { - } - - OutputPayLoad &m_msg; - const ParentType &m_parent; - - template - void operator()(const Type &v) - { - IPCTypeHandler::SerializedType>::write(m_msg, - IPCTypeRegisterHandler::convertToSerializedType(v, m_parent)); - } -}; - -} diff --git a/src/ipc/ipc-common/ipc-common.h b/src/ipc/ipc-common/ipc-common.h index 81878ff4..69d89fd0 100644 --- a/src/ipc/ipc-common/ipc-common.h +++ b/src/ipc/ipc-common/ipc-common.h @@ -39,20 +39,11 @@ #include #include "FaceliftModel.h" -#include "InputPayLoad.h" -#include "OutputPayLoad.h" -#include "DBusSignatureHelper.h" -#include "IPCTypeRegisterHandler.h" namespace facelift { FaceliftIPCCommonLib_EXPORT Q_DECLARE_LOGGING_CATEGORY(LogIpc) -enum class CommonSignalID { - readyChanged, - firstSpecific -}; - typedef int ASyncRequestID; enum class IPCHandlingResult { @@ -69,12 +60,6 @@ enum class ModelUpdateEvent { Reset }; -template -inline void assignDefaultValue(Type &v) -{ - v = Type {}; -} - - } +Q_DECLARE_METATYPE(facelift::ModelUpdateEvent) diff --git a/src/ipc/ipc-common/ipc-serialization.cpp b/src/ipc/ipc-common/ipc-serialization.cpp deleted file mode 100644 index 8a42c4c4..00000000 --- a/src/ipc/ipc-common/ipc-serialization.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/********************************************************************** -** -** Copyright (C) 2019 Luxoft Sweden AB -** -** This file is part of the FaceLift project -** -** Permission is hereby granted, free of charge, to any person -** obtaining a copy of this software and associated documentation files -** (the "Software"), to deal in the Software without restriction, -** including without limitation the rights to use, copy, modify, merge, -** publish, distribute, sublicense, and/or sell copies of the Software, -** and to permit persons to whom the Software is furnished to do so, -** subject to the following conditions: -** -** The above copyright notice and this permission notice shall be -** included in all copies or substantial portions of the Software. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -** ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -** SOFTWARE. -** -** SPDX-License-Identifier: MIT -** -**********************************************************************/ - -#include "ipc-serialization.h" diff --git a/src/ipc/ipc-common/ipc-serialization.h b/src/ipc/ipc-common/ipc-serialization.h deleted file mode 100644 index 62c269e2..00000000 --- a/src/ipc/ipc-common/ipc-serialization.h +++ /dev/null @@ -1,78 +0,0 @@ -/********************************************************************** -** -** Copyright (C) 2020 Luxoft Sweden AB -** -** This file is part of the FaceLift project -** -** Permission is hereby granted, free of charge, to any person -** obtaining a copy of this software and associated documentation files -** (the "Software"), to deal in the Software without restriction, -** including without limitation the rights to use, copy, modify, merge, -** publish, distribute, sublicense, and/or sell copies of the Software, -** and to permit persons to whom the Software is furnished to do so, -** subject to the following conditions: -** -** The above copyright notice and this permission notice shall be -** included in all copies or substantial portions of the Software. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -** ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -** SOFTWARE. -** -** SPDX-License-Identifier: MIT -** -**********************************************************************/ - -#pragma once - -#if defined(FaceliftIPCCommonLib_LIBRARY) -# define FaceliftIPCCommonLib_EXPORT Q_DECL_EXPORT -#else -# define FaceliftIPCCommonLib_EXPORT Q_DECL_IMPORT -#endif - -#include - -#include "ipc-common.h" -#include "InputPayLoad.h" -#include "OutputPayLoad.h" -#include "Structure.h" -#include "FaceliftUtils.h" -#include "ModelProperty.h" -#include "IPCTypeHandler.h" -#include "SerializeParameterFunction.h" - -namespace facelift { - -template -OutputPayLoad &operator<<(OutputPayLoad &msg, const Type &v) -{ - IPCTypeHandler::write(msg, v); - return msg; -} - - -template -InputPayLoad &operator>>(InputPayLoad &msg, Type &v) -{ - IPCTypeHandler::read(msg, v); - return msg; -} - - -template -InputPayLoad &operator>>(InputPayLoad &msg, Property &property) -{ - Type v; - IPCTypeHandler::read(msg, v); - property.setValue(v); - return msg; -} - - -} diff --git a/src/ipc/local/FaceliftIPCCommon.h b/src/ipc/local/FaceliftIPCCommon.h index 8942adc1..374b3962 100644 --- a/src/ipc/local/FaceliftIPCCommon.h +++ b/src/ipc/local/FaceliftIPCCommon.h @@ -42,14 +42,12 @@ namespace local { struct FaceliftIPCLocalLib_EXPORT FaceliftIPCCommon { - static constexpr const char *GET_PROPERTIES_MESSAGE_NAME = "GetAllProperties"; + static constexpr const char *GET_ALL_PROPERTIES = "GetAll"; + static constexpr const char *GET_PROPERTY = "Get"; static constexpr const char *PROPERTIES_CHANGED_SIGNAL_NAME = "PropertiesChanged"; - static constexpr const char *SIGNAL_TRIGGERED_SIGNAL_NAME = "SignalTriggered"; - static constexpr const char *SET_PROPERTY_MESSAGE_NAME = "SetProperty"; + static constexpr const char *PROPERTIES_INTERFACE_NAME = "org.freedesktop.DBus.Properties"; }; -constexpr const char *FaceliftIPCCommon::SIGNAL_TRIGGERED_SIGNAL_NAME; - } } diff --git a/src/ipc/local/LocalIPC-serialization.h b/src/ipc/local/LocalIPC-serialization.h index fdd626d7..9812a865 100644 --- a/src/ipc/local/LocalIPC-serialization.h +++ b/src/ipc/local/LocalIPC-serialization.h @@ -36,8 +36,8 @@ # define FaceliftIPCLocalLib_EXPORT Q_DECL_IMPORT #endif +#include #include "LocalIPCMessage.h" -#include "ipc-serialization.h" #include "LocalIPCProxy.h" #include "LocalIPCServiceAdapter.h" @@ -45,47 +45,12 @@ namespace facelift { namespace local { - -template -inline void LocalIPCServiceAdapterBase::serializeValue(LocalIPCMessage &msg, const Type &v) -{ - typedef typename IPCTypeRegisterHandler::SerializedType SerializedType; - IPCTypeHandler::write(msg.outputPayLoad(), IPCTypeRegisterHandler::convertToSerializedType(v, *this)); -} - -template -inline void LocalIPCServiceAdapterBase::deserializeValue(LocalIPCMessage &msg, Type &v) -{ - typedef typename IPCTypeRegisterHandler::SerializedType SerializedType; - SerializedType serializedValue; - IPCTypeHandler::read(msg.inputPayLoad(), serializedValue); - IPCTypeRegisterHandler::convertToDeserializedType(v, serializedValue, *this); -} - - -template -inline void LocalIPCProxyBinder::serializeValue(LocalIPCMessage &msg, const Type &v) -{ - typedef typename IPCTypeRegisterHandler::SerializedType SerializedType; - IPCTypeHandler::write(msg.outputPayLoad(), IPCTypeRegisterHandler::convertToSerializedType(v, *this)); -} - -template -inline void LocalIPCProxyBinder::deserializeValue(LocalIPCMessage &msg, Type &v) -{ - typedef typename IPCTypeRegisterHandler::SerializedType SerializedType; - SerializedType serializedValue; - IPCTypeHandler::read(msg.inputPayLoad(), serializedValue); - IPCTypeRegisterHandler::convertToDeserializedType(v, serializedValue, *this); -} - - template inline LocalIPCMessage LocalIPCProxyBinder::sendMethodCall(const char *methodName, const Args & ... args) const { LocalIPCMessage msg(methodName); auto argTuple = std::make_tuple(args ...); - for_each_in_tuple(argTuple, SerializeParameterFunction(msg.outputPayLoad(), *this)); + for_each_in_tuple(argTuple, [&msg](const auto &v){msg << QVariant::fromValue(v);}); auto replyMessage = call(msg); if (replyMessage.isErrorMessage()) { onServerNotAvailableError(methodName); @@ -98,11 +63,11 @@ inline void LocalIPCProxyBinder::sendAsyncMethodCall(const char *methodName, fac { LocalIPCMessage msg(methodName); auto argTuple = std::make_tuple(args ...); - for_each_in_tuple(argTuple, SerializeParameterFunction(msg.outputPayLoad(), *this)); + for_each_in_tuple(argTuple, [&msg](const auto &v){msg << QVariant::fromValue(v);}); asyncCall(msg, this, [this, answer](LocalIPCMessage &msg) { ReturnType returnValue; if (msg.isReplyMessage()) { - deserializeValue(msg, returnValue); + returnValue = (!msg.arguments().isEmpty() ? qdbus_cast(msg.arguments()[0]): ReturnType()); answer(returnValue); } else { qCWarning(LogIpc) << "Error received" << msg.toString(); @@ -115,88 +80,52 @@ inline void LocalIPCProxyBinder::sendAsyncMethodCall(const char *methodName, fac { LocalIPCMessage msg(methodName); auto argTuple = std::make_tuple(args ...); - for_each_in_tuple(argTuple, SerializeParameterFunction(msg.outputPayLoad(), *this)); + for_each_in_tuple(argTuple, [&msg](const auto &v){msg << QVariant::fromValue(v);}); asyncCall(msg, this, [answer](LocalIPCMessage &msg) { Q_UNUSED(msg); answer(); }); } -template -inline void LocalIPCProxyBinder::sendMethodCallWithReturn(const char *methodName, ReturnType &returnValue, const Args & ... args) const -{ - LocalIPCMessage msg = sendMethodCall(methodName, args ...); - if (msg.isReplyMessage()) { - const_cast(this)->deserializeValue(msg, returnValue); - } else { - assignDefaultValue(returnValue); - } -} - - template -inline void LocalIPCProxyBinder::sendSetterCall(const char *methodName, const PropertyType &value) +inline void LocalIPCProxyBinder::sendSetterCall(const QString& property, const PropertyType &value) { - LocalIPCMessage msg(methodName); - serializeValue(msg, value); + LocalIPCMessage msg; + msg << QVariant::fromValue(m_interfaceName); + msg << QVariant::fromValue(property); + msg << QVariant::fromValue(value); if (isSynchronous()) { auto replyMessage = call(msg); if (replyMessage.isErrorMessage()) { - onServerNotAvailableError(methodName); + onServerNotAvailableError(property); } } else { - asyncCall(msg, this, [this, methodName](const LocalIPCMessage &replyMessage) { + asyncCall(msg, this, [this, property](const LocalIPCMessage &replyMessage) { if (replyMessage.isErrorMessage()) { - onServerNotAvailableError(methodName); + onServerNotAvailableError(property); } }); } } -template -inline void LocalIPCServiceAdapterBase::sendSignal(MemberID signalID, const Args & ... args) +template +inline void LocalIPCServiceAdapterBase::sendSignal(const QString& signalName, const Args & ... args) { - if (m_pendingOutgoingMessage == nullptr) { - initOutgoingSignalMessage(); - auto argTuple = std::make_tuple(signalID, args ...); - for_each_in_tuple(argTuple, SerializeParameterFunction(m_pendingOutgoingMessage->outputPayLoad(), *this)); - flush(); - } + LocalIPCMessage signal; + auto argTuple = std::make_tuple(args ...); + signal << signalName; + for_each_in_tuple(argTuple, [this, &signal](const auto &v){signal << QVariant::fromValue(v);}); + this->send(signal); } template inline void LocalIPCServiceAdapterBase::sendAsyncCallAnswer(LocalIPCMessage &replyMessage, const ReturnType returnValue) { - serializeValue(replyMessage, returnValue); + replyMessage << QVariant::fromValue(returnValue); sendReply(replyMessage); } -template -inline void LocalIPCServiceAdapterBase::serializeOptionalValue(LocalIPCMessage &msg, const Type ¤tValue, Type &previousValue, - bool isCompleteSnapshot) -{ - if (isCompleteSnapshot) { - serializeValue(msg, currentValue); - } else { - if (previousValue == currentValue) { - msg.outputPayLoad().writeSimple(false); - } else { - msg.outputPayLoad().writeSimple(true); - serializeValue(msg, currentValue); - previousValue = currentValue; - } - } -} - -template -inline void LocalIPCServiceAdapterBase::serializeOptionalValue(LocalIPCMessage &msg, const Type ¤tValue, bool isCompleteSnapshot) -{ - msg.outputPayLoad().writeSimple(isCompleteSnapshot); - if (isCompleteSnapshot) { - serializeValue(msg, currentValue); - } -} } } diff --git a/src/ipc/local/LocalIPCMessage.cpp b/src/ipc/local/LocalIPCMessage.cpp index 411ed953..e8626bdd 100644 --- a/src/ipc/local/LocalIPCMessage.cpp +++ b/src/ipc/local/LocalIPCMessage.cpp @@ -45,26 +45,10 @@ QString LocalIPCMessage::toString() const s << "Local IPC message "; s << " member:" << m_data.m_member; - s << m_data.m_payload; + s << m_data.m_arguments; return str; } -OutputPayLoad &LocalIPCMessage::outputPayLoad() -{ - if (m_outputPayload == nullptr) { - m_outputPayload = std::make_unique(m_data.m_payload); - } - return *m_outputPayload; -} - -InputPayLoad &LocalIPCMessage::inputPayLoad() -{ - if (m_inputPayload == nullptr) { - m_inputPayload = std::make_unique(m_data.m_payload); - } - return *m_inputPayload; -} - LocalIPCMessage::LocalIPCMessage() { } @@ -96,6 +80,17 @@ void LocalIPCMessage::copyRequestMessage(const LocalIPCMessage &other) } } +QList LocalIPCMessage::arguments() const +{ + return m_data.m_arguments; +} + +LocalIPCMessage &LocalIPCMessage::operator<<(const QVariant &arg) +{ + m_data.m_arguments.append(arg); + return *this; +} + LocalIPCMessage LocalIPCMessage::createReply() const { LocalIPCMessage reply; diff --git a/src/ipc/local/LocalIPCMessage.h b/src/ipc/local/LocalIPCMessage.h index 7d2a68d1..84000530 100644 --- a/src/ipc/local/LocalIPCMessage.h +++ b/src/ipc/local/LocalIPCMessage.h @@ -84,6 +84,14 @@ class FaceliftIPCLocalLib_EXPORT LocalIPCMessage return m_data.m_member; } + QString interface() const + { + return m_data.m_interface; + } + + QList arguments() const; + + LocalIPCMessage &operator<<(const QVariant &arg); LocalIPCMessage createReply() const; @@ -101,10 +109,6 @@ class FaceliftIPCLocalLib_EXPORT LocalIPCMessage return (m_data.m_messageType == MessageType::Error); } - OutputPayLoad &outputPayLoad(); - - InputPayLoad &inputPayLoad(); - void addListener(const QObject *context, ReplyFunction function); void notifyListener(); @@ -112,15 +116,14 @@ class FaceliftIPCLocalLib_EXPORT LocalIPCMessage private: struct { + QString m_interface; QString m_member; - QByteArray m_payload; MessageType m_messageType = MessageType::Request; ReplyFunction m_listener; QPointer m_listenerContext; + QList m_arguments; } m_data; - std::unique_ptr m_outputPayload; - std::unique_ptr m_inputPayload; std::unique_ptr m_requestMessage; }; diff --git a/src/ipc/local/LocalIPCProxy.h b/src/ipc/local/LocalIPCProxy.h index 947f7a3a..94ad87ef 100644 --- a/src/ipc/local/LocalIPCProxy.h +++ b/src/ipc/local/LocalIPCProxy.h @@ -75,35 +75,6 @@ class LocalIPCProxy : public IPCProxyBase, protected LocalIPCProx return memberName; } - template - void serializeValue(LocalIPCMessage &msg, const Type &v) - { - typedef typename IPCTypeRegisterHandler::SerializedType SerializedType; - IPCTypeHandler::write(msg, IPCTypeRegisterHandler::convertToSerializedType(v, *this)); - } - - template - void deserializeValue(LocalIPCMessage &msg, Type &v) - { - typedef typename IPCTypeRegisterHandler::SerializedType SerializedType; - SerializedType serializedValue; - IPCTypeHandler::read(msg.inputPayLoad(), serializedValue); - IPCTypeRegisterHandler::convertToDeserializedType(v, serializedValue, *this); - } - - template - bool deserializeOptionalValue(LocalIPCMessage &msg, Type &value, bool isCompleteSnapshot) - { - bool b = true; - if (!isCompleteSnapshot) { - msg.inputPayLoad().readNextParameter(b); - } - if (b) { - this->deserializeValue(msg, value); - } - return b; - } - void setServiceRegistered(bool isRegistered) override { bool oldReady = this->ready(); @@ -115,13 +86,6 @@ class LocalIPCProxy : public IPCProxyBase, protected LocalIPCProx m_ipcBinder.setServiceAvailable(isRegistered); } - bool deserializeReadyValue(LocalIPCMessage &msg, bool isCompleteSnapshot) - { - bool previousIsReady = this->ready(); - deserializeOptionalValue(msg, this->m_serviceReady, isCompleteSnapshot); - return (this->ready() != previousIsReady); - } - LocalIPCProxyBinder *ipc() { return &m_ipcBinder; diff --git a/src/ipc/local/LocalIPCProxyBinder.cpp b/src/ipc/local/LocalIPCProxyBinder.cpp index eaff415f..562cc9d8 100644 --- a/src/ipc/local/LocalIPCProxyBinder.cpp +++ b/src/ipc/local/LocalIPCProxyBinder.cpp @@ -61,7 +61,7 @@ void LocalIPCProxyBinder::checkServiceAvailability() if (!isServiceAvailable()) { m_serviceAdapter = adapter; m_signalConnection = QObject::connect(adapter, &LocalIPCServiceAdapterBase::messageSent, this, [this] (LocalIPCMessage &message) { - this->onSignalTriggered(message); + //this->onSignalTriggered(message); }); requestPropertyValues(); } @@ -110,7 +110,7 @@ void LocalIPCProxyBinder::setInterfaceName(const QString &name) checkInit(); } -void LocalIPCProxyBinder::onServerNotAvailableError(const char *methodName) const +void LocalIPCProxyBinder::onServerNotAvailableError(const QString& methodName) const { qCCritical(LogIpc, "Error message received when calling method '%s' on service at path '%s'. " @@ -120,13 +120,7 @@ void LocalIPCProxyBinder::onServerNotAvailableError(const char *methodName) cons void LocalIPCProxyBinder::onPropertiesChanged(LocalIPCMessage &msg) { - m_serviceObject->deserializePropertyValues(msg, false); -} - -void LocalIPCProxyBinder::onSignalTriggered(LocalIPCMessage &msg) -{ - m_serviceObject->deserializePropertyValues(msg, false); - m_serviceObject->deserializeSignal(msg); + m_serviceObject->unmarshalPropertiesChanged(msg); } LocalIPCMessage LocalIPCProxyBinder::call(LocalIPCMessage &message) const @@ -150,11 +144,11 @@ void LocalIPCProxyBinder::asyncCall(LocalIPCMessage &requestMessage, QObject *co void LocalIPCProxyBinder::requestPropertyValues() { - LocalIPCMessage msg(FaceliftIPCCommon::GET_PROPERTIES_MESSAGE_NAME); + LocalIPCMessage msg(FaceliftIPCCommon::GET_ALL_PROPERTIES); auto replyHandler = [this](LocalIPCMessage &replyMessage) { if (replyMessage.isReplyMessage()) { - m_serviceObject->deserializePropertyValues(replyMessage, true); + m_serviceObject->unmarshalPropertyValues(replyMessage); m_serviceObject->setServiceRegistered(true); emit serviceAvailableChanged(); } else { diff --git a/src/ipc/local/LocalIPCProxyBinder.h b/src/ipc/local/LocalIPCProxyBinder.h index 3818b260..39704733 100644 --- a/src/ipc/local/LocalIPCProxyBinder.h +++ b/src/ipc/local/LocalIPCProxyBinder.h @@ -67,8 +67,6 @@ class FaceliftIPCLocalLib_EXPORT LocalIPCProxyBinder : public IPCProxyBinderBase void onPropertiesChanged(LocalIPCMessage &message); - void onSignalTriggered(LocalIPCMessage &message); - void bindToIPC() override; void setServiceAvailable(bool isRegistered); @@ -81,16 +79,10 @@ class FaceliftIPCLocalLib_EXPORT LocalIPCProxyBinder : public IPCProxyBinderBase void requestPropertyValues(); - template - void serializeValue(LocalIPCMessage &msg, const Type &v); - - template - void deserializeValue(LocalIPCMessage &msg, Type &v); - - void onServerNotAvailableError(const char *methodName) const; + void onServerNotAvailableError(const QString &methodName) const; template - void sendSetterCall(const char *methodName, const PropertyType &value); + void sendSetterCall(const QString &property, const PropertyType &value); template LocalIPCMessage sendMethodCall(const char *methodName, const Args & ... args) const; diff --git a/src/ipc/local/LocalIPCRequestHandler.h b/src/ipc/local/LocalIPCRequestHandler.h index 8296467d..8a4943de 100644 --- a/src/ipc/local/LocalIPCRequestHandler.h +++ b/src/ipc/local/LocalIPCRequestHandler.h @@ -43,7 +43,6 @@ #include "FaceliftModel.h" #include "FaceliftUtils.h" #include "ModelProperty.h" - #include "ipc-common.h" namespace facelift { @@ -61,8 +60,11 @@ class FaceliftIPCLocalLib_EXPORT LocalIPCRequestHandler { public: - virtual void deserializePropertyValues(LocalIPCMessage &msg, bool isCompleteSnapshot) = 0; - virtual void deserializeSignal(LocalIPCMessage &msg) = 0; + virtual void unmarshalPropertyValues(LocalIPCMessage &msg) = 0; + virtual void unmarshalPropertiesChanged(LocalIPCMessage &msg) = 0; + virtual QMap getSignals() = 0; + virtual void connectSignals() = 0; + virtual void disconnectSignals() = 0; virtual void setServiceRegistered(bool isRegistered) = 0; }; diff --git a/src/ipc/local/LocalIPCServiceAdapterBase.cpp b/src/ipc/local/LocalIPCServiceAdapterBase.cpp index 60f8bdc5..7442ff11 100644 --- a/src/ipc/local/LocalIPCServiceAdapterBase.cpp +++ b/src/ipc/local/LocalIPCServiceAdapterBase.cpp @@ -40,28 +40,6 @@ namespace facelift { namespace local { -void LocalIPCServiceAdapterBase::initOutgoingSignalMessage() -{ - m_pendingOutgoingMessage = std::make_unique(FaceliftIPCCommon::SIGNAL_TRIGGERED_SIGNAL_NAME); - - // Send property value updates before the signal itself so that they are set before the signal is triggered on the client side. - this->serializePropertyValues(*m_pendingOutgoingMessage, false); -} - -void LocalIPCServiceAdapterBase::serializePropertyValues(LocalIPCMessage &msg, bool isCompleteSnapshot) -{ - Q_ASSERT(service()); - serializeOptionalValue(msg, service()->ready(), m_previousReadyState, isCompleteSnapshot); -} - -void LocalIPCServiceAdapterBase::flush() -{ - if (m_pendingOutgoingMessage) { - this->send(*m_pendingOutgoingMessage); - m_pendingOutgoingMessage.reset(); - } -} - IPCHandlingResult LocalIPCServiceAdapterBase::handleMessage(LocalIPCMessage &requestMessage) { LocalIPCMessage replyMessage = requestMessage.createReply(); @@ -71,9 +49,16 @@ IPCHandlingResult LocalIPCServiceAdapterBase::handleMessage(LocalIPCMessage &req auto handlingResult = IPCHandlingResult::OK; bool sendReply = true; - if (requestMessage.member() == FaceliftIPCCommon::GET_PROPERTIES_MESSAGE_NAME) { - serializePropertyValues(replyMessage, true); - } else { + if (requestMessage.interface() == FaceliftIPCCommon::PROPERTIES_INTERFACE_NAME) { + if (requestMessage.member() == FaceliftIPCCommon::GET_ALL_PROPERTIES) { + marshalPropertyValues(requestMessage.arguments(), replyMessage); + send(replyMessage); + } + else if (requestMessage.member() == FaceliftIPCCommon::GET_PROPERTY) { + marshalProperty(requestMessage.arguments(), replyMessage); + } + } + else { handlingResult = handleMethodCallMessage(requestMessage, replyMessage); if (handlingResult == IPCHandlingResult::INVALID) { replyMessage = requestMessage.createErrorReply(); @@ -126,9 +111,6 @@ void LocalIPCServiceAdapterBase::registerService() m_alreadyInitialized = true; qCDebug(LogIpc) << "Registering local IPC object at " << objectPath(); if (m_alreadyInitialized) { - QObject::connect(service(), &InterfaceBase::readyChanged, this, [this]() { - this->sendSignal(CommonSignalID::readyChanged); - }); connectSignals(); } else { qFatal("Could not register service at object path '%s'", qPrintable(objectPath())); diff --git a/src/ipc/local/LocalIPCServiceAdapterBase.h b/src/ipc/local/LocalIPCServiceAdapterBase.h index 4911cec6..ec733e93 100644 --- a/src/ipc/local/LocalIPCServiceAdapterBase.h +++ b/src/ipc/local/LocalIPCServiceAdapterBase.h @@ -61,18 +61,11 @@ class FaceliftIPCLocalLib_EXPORT LocalIPCServiceAdapterBase : public IPCServiceA IPCHandlingResult handleMessage(LocalIPCMessage &message); - void flush(); + template + inline void sendPropertiesChanged(const QString& property , const Value & value); - template - void serializeValue(LocalIPCMessage &msg, const Type &v); - - template - void deserializeValue(LocalIPCMessage &msg, Type &v); - - void initOutgoingSignalMessage(); - - template - void sendSignal(MemberID signalID, const Args & ... args); + template + void sendSignal(const QString& signalName, const Args & ... args); template void sendAsyncCallAnswer(LocalIPCMessage &replyMessage, const ReturnType returnValue); @@ -81,7 +74,11 @@ class FaceliftIPCLocalLib_EXPORT LocalIPCServiceAdapterBase : public IPCServiceA virtual IPCHandlingResult handleMethodCallMessage(LocalIPCMessage &requestMessage, LocalIPCMessage &replyMessage) = 0; - virtual void serializePropertyValues(LocalIPCMessage &msg, bool isCompleteSnapshot); + virtual void marshalPropertyValues(const QList& arguments, LocalIPCMessage &msg) = 0; + + virtual void marshalProperty(const QList& arguments, LocalIPCMessage &msg) = 0; + + virtual void setProperty(const QList& arguments) = 0; void registerService() override; @@ -93,12 +90,6 @@ class FaceliftIPCLocalLib_EXPORT LocalIPCServiceAdapterBase : public IPCServiceA void sendReply(LocalIPCMessage &message); - template - void serializeOptionalValue(LocalIPCMessage &msg, const Type ¤tValue, Type &previousValue, bool isCompleteSnapshot); - - template - void serializeOptionalValue(LocalIPCMessage &msg, const Type ¤tValue, bool isCompleteSnapshot); - virtual void appendDBUSIntrospectionData(QTextStream &s) const = 0; QString introspect(const QString &path) const; @@ -122,6 +113,14 @@ class FaceliftIPCLocalLib_EXPORT LocalIPCServiceAdapterBase : public IPCServiceA bool m_alreadyInitialized = false; }; +template +inline void LocalIPCServiceAdapterBase::sendPropertiesChanged(const QString& property , const Value & value) +{ + LocalIPCMessage reply; + reply << interfaceName(); + reply << QVariantMap{{property, QVariant::fromValue(value)}}; + this->send(reply); +} } diff --git a/src/model/CMakeLists.txt b/src/model/CMakeLists.txt index 83131aeb..d14ff1aa 100644 --- a/src/model/CMakeLists.txt +++ b/src/model/CMakeLists.txt @@ -81,6 +81,7 @@ facelift_add_library(FaceliftModelLib LINK_LIBRARIES Qt5::Qml Qt5::Quick + Qt5::DBus FaceliftCommonLib MONOLITHIC_SUPPORTED ) diff --git a/src/model/FaceliftEnum.h b/src/model/FaceliftEnum.h index df45946d..2d46dff6 100644 --- a/src/model/FaceliftEnum.h +++ b/src/model/FaceliftEnum.h @@ -39,6 +39,47 @@ #include "FaceliftCommon.h" #include #include +#include + +template +class QDBusEnumMarshal; + +template +class QDBusEnumMarshal::value>::type> +{ +public: + static QDBusArgument& marshal(QDBusArgument &argument, const T& source) + { + argument.beginStructure(); + argument << static_cast(source); + argument.endStructure(); + return argument; + } + + static const QDBusArgument& unmarshal(const QDBusArgument &argument, T &source) + { + int a; + argument.beginStructure(); + argument >> a; + argument.endStructure(); + + source = static_cast(a); + + return argument; + } +}; + +template +QDBusArgument& operator<<(QDBusArgument &argument, const T& source) +{ + return QDBusEnumMarshal::marshal(argument, source); +} + +template +const QDBusArgument& operator>>(const QDBusArgument &argument, T &source) +{ + return QDBusEnumMarshal::unmarshal(argument, source); +} namespace facelift {