Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize facelift dbus communication #303

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions codegen/facelift/facelift-codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,23 @@ def referencedTypes(self):
insertUniqueType(param, types)
return types

def appendTypeIfStructure(symbol, list):
def appendTypeIfStructureAndUnique(symbol, unique_list):
type = symbol.type.nested if symbol.type.nested else symbol.type
if type.is_struct:
list.append(type)
if type.is_struct and type.name not in (t.name for t in unique_list):
unique_list.append(type)

def referencedStructureTypes(self):
interfaces = []
for property in self.properties:
appendTypeIfStructure(property, interfaces)
appendTypeIfStructureAndUnique(property, interfaces)
for m in self.operations:
for param in m.parameters:
appendTypeIfStructure(param, interfaces)
appendTypeIfStructureAndUnique(param, interfaces)
if m.hasReturnValue:
appendTypeIfStructureAndUnique(m.type, interfaces)
for m in self.signals:
for param in m.parameters:
appendTypeIfStructure(param, interfaces)
appendTypeIfStructureAndUnique(param, interfaces)
return interfaces

def appendTypeIfInterface(symbol, list):
Expand Down Expand Up @@ -201,6 +203,9 @@ def isQMLImplementationEnabled(self):
def isSerializable(self):
return True if self.tags.get('serializable') else generateAll

def toByteArrayOverDBus(self):
return True if self.tags.get('toByteArrayOverDBus') else generateAll

def isQObjectWrapperEnabled(self):
return True if self.tags.get('qml-component') else False

Expand Down Expand Up @@ -299,6 +304,7 @@ def cppMethodArgumentType(self):

setattr(qface.idl.domain.Struct, 'verifyStruct', property(verifyStruct))
setattr(qface.idl.domain.Struct, 'isSerializable', property(isSerializable))
setattr(qface.idl.domain.Struct, 'toByteArrayOverDBus', property(toByteArrayOverDBus))
setattr(qface.idl.domain.Struct, 'isQObjectWrapperEnabled', property(isQObjectWrapperEnabled))
setattr(qface.idl.domain.Struct, 'isQObjectWrapperDeprecated', property(isQObjectWrapperDeprecated))

Expand Down
13 changes: 0 additions & 13 deletions codegen/facelift/templates/IPCCommon.template.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,12 @@ class {{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<int>(facelift::CommonSignalID::firstSpecific),
{% for signal in interface.signals %}
{{signal.name}},
{% endfor %}
{% for property in interface.properties %}
{{property.name}},
{% endfor %}
};

};

{{module.namespaceCppClose}}
2 changes: 2 additions & 0 deletions codegen/facelift/templates/IPCDBusProxyAdapter.template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@
****************************************************************************/
{% set baseClass = "::facelift::dbus::DBusIPCProxy<" + interfaceName + ">" %}
{% set proxyTypeNameSuffix = "IPCDBusProxy" %}
{% set proxyType = "DBus" %}

{% include "IPCProxyAdapter.template.cpp" %}
1 change: 1 addition & 0 deletions codegen/facelift/templates/IPCDBusProxyAdapter.template.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
****************************************************************************/
{% set baseClass = "::facelift::dbus::DBusIPCProxy<" + interfaceName + ">" %}
{% set proxyTypeNameSuffix = "IPCDBusProxy" %}
{% set proxyType = "DBus" %}

#include "DBusIPCProxy.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@
****************************************************************************/
{% set baseClass = "::facelift::dbus::IPCDBusServiceAdapter<" + interfaceName + ">" %}
{% set proxyTypeNameSuffix = "IPCDBusAdapter" %}
{% set proxyType = "DBus" %}
{% include "IPCServiceAdapter.template.cpp" %}

17 changes: 9 additions & 8 deletions codegen/facelift/templates/IPCDBusServiceAdapter.template.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "IPCDBusServiceAdapter.h"
#include "IPCAdapterModelPropertyHandler.h"
#include "DBusManager.h"
#include "FaceliftDBusMarshaller.h"

#include "{{module.fullyQualifiedPath}}/{{interfaceName}}.h"
#include "{{module.fullyQualifiedPath}}/{{interfaceName}}QMLAdapter.h"
Expand All @@ -65,7 +66,6 @@ class {{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) :
Expand All @@ -85,7 +85,13 @@ class {{className}}: public {{baseClass}}

void connectSignals() override;

void serializePropertyValues(OutputIPCMessage& msg, bool isCompleteSnapshot) override;
QVariantMap dirtyProperties();

QVariantMap marshalProperties() override;

QVariant marshalProperty(const QString& propertyName) override;

void setProperty(const QString& propertyName, const QVariant& value) override;

{% for event in interface.signals %}
void {{event}}(
Expand All @@ -94,7 +100,7 @@ class {{className}}: public {{baseClass}}
{{ comma() }}{{parameter.interfaceCppType}} {{parameter.name}}
{%- endfor -%} )
{
sendSignal(SignalID::{{event}}
sendSignal(QLatin1String("{{event}}")
{%- for parameter in event.parameters -%}
, {{parameter.name}}
{%- endfor -%} );
Expand All @@ -105,14 +111,9 @@ class {{className}}: public {{baseClass}}
{% for property in interface.properties %}
{% if property.type.is_model %}
::facelift::IPCAdapterModelPropertyHandler<ThisType, {{property.nestedType.interfaceCppType}}> m_{{property.name}}Handler;
{% elif property.type.is_interface %}
QString m_previous{{property.name}}ObjectPath;
{% else %}
{{property.interfaceCppType}} m_previous{{property.name}} {};
{% endif %}
{% if property.type.is_interface %}
InterfacePropertyIPCAdapterHandler<{{property.cppType}}, {{property.cppType}}{{proxyTypeNameSuffix}}> m_{{property.name}};
{% endif %}
{% endfor %}
};

Expand Down
99 changes: 58 additions & 41 deletions codegen/facelift/templates/IPCProxyAdapter.template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,10 @@
{% set className = interfaceName + proxyTypeNameSuffix %}

#include "{{className}}.h"

{{module.namespaceCppOpen}}

{{className}}::{{className}}(QObject *parent) : BaseType(parent)
{% for property in interface.properties %}
{% if property.type.is_interface %}
, m_{{property.name}}Proxy(*this)
{% endif %}
{% if property.type.is_model %}
, m_{{property.name}}(*this)
{% endif %}
Expand All @@ -55,36 +51,34 @@
{% endif %}
}

void {{className}}::deserializePropertyValues(InputIPCMessage &msg, bool isCompleteSnapshot)
void {{className}}::unmarshalProperties(const QVariantMap& values)
idleroamer marked this conversation as resolved.
Show resolved Hide resolved
{
{% 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;
}
if (values.contains(QLatin1String("{{property.name}}"))) {
{% if property.type.is_interface %}
const {{property.interfaceCppType}} previous_{{property.name}}_Value = m_{{property.name}};
m_{{property.name}} = castFromQVariant<{{property.interfaceCppType}}>(values[QLatin1String("{{property.name}}")]);
emit_{{property.name}}ChangeSignal = ((previous_{{property.name}}_Value != m_{{property.name}}));
{% elif property.type.is_model %}
bool emit_{{property.name}}ChangeSignal = false;
if (isCompleteSnapshot) {
int {{property.name}}Size;
deserializeValue(msg, {{property.name}}Size);
int {{property.name}}Size = castFromQVariant<int>(values[QLatin1String("{{property.name}}")]);
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}}));
const auto previous_{{property.name}}_Value = m_{{property.name}};
m_{{property.name}} = castFromQVariant<{{property.interfaceCppType}}>(values[QLatin1String("{{property.name}}")]);
emit_{{property.name}}ChangeSignal = ((previous_{{property.name}}_Value != m_{{property.name}}));
{% endif %}
}
{% endfor %}

bool emit_ReadyChangeSignal = deserializeReadyValue(msg, isCompleteSnapshot) && isCompleteSnapshot;
bool emit_ReadyChangeSignal = false;
if (values.contains(QLatin1String("ready"))) {
bool previousIsReady = this->ready();
m_serviceReady = castFromQVariant<bool>(values[QLatin1String("ready")]);
emit_ReadyChangeSignal = (previousIsReady != m_serviceReady);
}

{% for property in interface.properties %}
if (emit_{{property.name}}ChangeSignal)
Expand All @@ -93,39 +87,63 @@ void {{className}}::deserializePropertyValues(InputIPCMessage &msg, bool isCompl

if (emit_ReadyChangeSignal)
emit readyChanged();

}

void {{className}}::deserializeSignal(InputIPCMessage &msg)
void {{className}}::handleSignals(InputIPCMessage& msg)
{
SignalID member;
deserializeValue(msg, member);

Q_UNUSED(msg)
{% for event in interface.signals %}
if (member == SignalID::{{event}})
{
if (msg.member() == QLatin1String("{{event}}")) {
QListIterator<QVariant> argumentsIterator(msg.arguments());
{% for parameter in event.parameters %}
{{parameter.interfaceCppType}} param_{{parameter.name}};
deserializeValue(msg, param_{{parameter.name}});
param_{{parameter.name}} = (argumentsIterator.hasNext() ? castFromQVariant<{{parameter.interfaceCppType}}>(argumentsIterator.next()):{% if not parameter.type.is_interface %}{{parameter.interfaceCppType}}(){% else %}nullptr{% endif %});
{% endfor %}
emit {{event}}(
{%- set comma = joiner(", ") -%}
{%- for parameter in event.parameters -%}
{{ comma() }}param_{{parameter.name}}
{%- endfor -%} );
} else
idleroamer marked this conversation as resolved.
Show resolved Hide resolved
}
{% endfor %}

{% if interface.hasModelProperty %}
this->onModelUpdateEvent(msg);
{% endif %}
}
{% if proxyType and proxyType == "DBus" %}
const QList<QString>& {{className}}::getSignals() const
idleroamer marked this conversation as resolved.
Show resolved Hide resolved
{
static QList<QString> allSignals{
{% for event in interface.signals %}
"{{event}}",
{% endfor %}
{% if interface.hasModelProperty %}
facelift::IPCCommon::MODEL_DATA_CHANGED_MESSAGE_NAME,
facelift::IPCCommon::MODEL_INSERT_MESSAGE_NAME,
facelift::IPCCommon::MODEL_REMOVE_MESSAGE_NAME,
facelift::IPCCommon::MODEL_MOVE_MESSAGE_NAME,
facelift::IPCCommon::MODEL_RESET_MESSAGE_NAME,
{% endif %}
};

return allSignals;
}
{% endif %}
{% if interface.hasModelProperty %}
void {{className}}::onModelUpdateEvent(const InputIPCMessage& msg)
{
QListIterator<QVariant> argumentsIterator(msg.arguments());
const QString& modelPropertyName = (argumentsIterator.hasNext() ? castFromQVariant<QString>(argumentsIterator.next()): QString());
{% for property in interface.properties %}
if (member == SignalID::{{property.name}}) {
{% if property.type.is_model %}
if (modelPropertyName == QLatin1String("{{property.name}}")) {
m_{{property.name}}.handleSignal(msg);
{% else %}
emit {{property.name}}Changed();
}
{% endif %}
} else
{% endfor %}
BaseType::deserializeCommonSignal(static_cast<facelift::CommonSignalID>(member), this);
}
{% endif %}

{% for property in interface.properties %}

Expand All @@ -134,7 +152,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(QLatin1String("{{property.name}}"), newValue);
{% else %}
Q_ASSERT(false); // Writable interface properties are unsupported
{% endif %}
Expand Down Expand Up @@ -168,12 +186,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<QVariant> args = ipc()->sendMethodCallWithReturn(memberID(MethodID::{{operation.name}}, "{{operation.name}}")
{%- for parameter in operation.parameters -%}
, {{parameter.name}}
{%- endfor -%} );
return returnValue;
return (!args.isEmpty() ? castFromQVariant<{{operation.interfaceCppType}}>(args.first()):{% if not (operation.type.is_interface) %}{{operation.cppType}}(){% else %}nullptr{% endif %});
{% else %}
ipc()->sendMethodCall(memberID(MethodID::{{operation.name}}, "{{operation.name}}")
{%- for parameter in operation.parameters -%}
Expand Down
23 changes: 16 additions & 7 deletions codegen/facelift/templates/IPCProxyAdapter.template.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ class {{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
using QMLAdapterType = {{className}}QMLAdapterType;

{{className}}(QObject *parent = nullptr);

void deserializePropertyValues(InputIPCMessage &msg, bool isCompleteSnapshot) override;
void unmarshalProperties(const QVariantMap& values) override;

{% if interface.hasModelProperty %}
void setServiceRegistered(bool isRegistered) override
Expand All @@ -83,7 +82,11 @@ class {{className}} : public {{baseClass}}

{% endif %}

void deserializeSignal(InputIPCMessage &msg) override;
void handleSignals(InputIPCMessage& msg) override;

{% if proxyType and proxyType == "DBus" %}
const QList<QString>& getSignals() const override;
{% endif %}

{% for operation in interface.operations %}

Expand Down Expand Up @@ -120,7 +123,6 @@ class {{className}} : public {{baseClass}}
}

{% elif property.type.is_list %}

const {{property.interfaceCppType}}& {{property}}() const override
{
return m_{{property.name}};
Expand Down Expand Up @@ -148,15 +150,22 @@ class {{className}} : public {{baseClass}}
{% endif %}
{% endfor %}

{% if interface.hasModelProperty %}
void onModelUpdateEvent(const InputIPCMessage& msg);

Q_SIGNAL void ModelUpdateEventDataChanged(const InputIPCMessage& msg);
Q_SIGNAL void ModelUpdateEventInsert(const InputIPCMessage& msg);
Q_SIGNAL void ModelUpdateEventRemove(const InputIPCMessage& msg);
Q_SIGNAL void ModelUpdateEventMove(const InputIPCMessage& msg);
Q_SIGNAL void ModelUpdateEventReset(const InputIPCMessage& msg);
{% endif %}
private:
{% for property in interface.properties %}
{% if property.type.is_interface %}
InterfacePropertyIPCProxyHandler<{{property.cppType}}{{proxyTypeNameSuffix}}> m_{{property.name}}Proxy;
{% endif %}
{% if property.type.is_model %}
facelift::IPCProxyModelProperty<ThisType, {{property.nestedType.interfaceCppType}}> m_{{property.name}};
{% endif %}
{% endfor %}

};


Expand Down
Loading