Skip to content

Commit

Permalink
Fix consistency of the interface in case of multiple property change
Browse files Browse the repository at this point in the history
  • Loading branch information
😎 Mostafa Emami committed Sep 20, 2020
1 parent 2cf600d commit a3e6151
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 15 deletions.
4 changes: 4 additions & 0 deletions codegen/facelift/templates/IPCDBusServiceAdapter.template.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class {{classExport}} {{className}}: public {{baseClass}}

void connectSignals() override;

QMap<QString, QDBusVariant> changedProperties();

void marshalPropertyValues(const QList<QVariant>& arguments, OutputIPCMessage& msg) override;

void marshalProperty(const QList<QVariant>& arguments, OutputIPCMessage& msg) override;
Expand All @@ -110,6 +112,8 @@ class {{classExport}} {{className}}: public {{baseClass}}
{% for property in interface.properties %}
{% if property.type.is_model %}
::facelift::IPCAdapterModelPropertyHandler<ThisType, {{property.nestedType.interfaceCppType}}> m_{{property.name}}Handler;
{% else %}
{{property.interfaceCppType}} m_previous{{property.name}} {};
{% endif %}
{% endfor %}
};
Expand Down
10 changes: 9 additions & 1 deletion codegen/facelift/templates/IPCProxyAdapter.template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,15 @@ void {{className}}::unmarshalPropertiesChanged(InputIPCMessage &msg)
{% else %}
m_{{property.name}} = castFromDBusVariant<{{property.interfaceCppType}}>(changedProperties[propertyName]);
{% endif %}
emit {{property.name}}Changed(); // trust the propertiesChanged signal and emit without checking
}
{% endfor %}
}
for (const QString &propertyName: changedProperties.keys()) {
{% for property in interface.properties %}
if (propertyName == QStringLiteral("{{property.name}}")) {
{% if not property.type.is_model %}
emit {{property.name}}Changed();
{% endif %}
}
{% endfor %}
}
Expand Down
23 changes: 20 additions & 3 deletions codegen/facelift/templates/IPCServiceAdapter.template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,22 @@ void {{className}}::connectSignals()
{% for property in interface.properties %}
{% if property.type.is_model %}
m_{{property.name}}Handler.connectModel(QStringLiteral("{{property.name}}"), theService->{{property.name}}());
{% elif property.type.is_interface %}
{% else %}
m_previous{{property.name}} = theService->{{property.name}}();
{% endif %}
{% endfor %}

// Properties
{% for property in interface.properties %}
{% if (not property.type.is_model) %}
QObject::connect(theService, &ServiceType::{{property.name}}Changed, this, [this, theService] () {
this->sendPropertiesChanged("{{property.name}}", theService->{{property.name}}());
this->sendPropertiesChanged(changedProperties());
});
{% endif %}
{% endfor %}

QObject::connect(theService, &ServiceType::readyChanged, this, [this, theService] () {
this->sendPropertiesChanged("ready", theService->ready());
this->sendPropertiesChanged(QMap<QString, QDBusVariant>{ {"ready", castToDBusVariant(theService->ready())} });
});

// Signals
Expand All @@ -173,6 +174,22 @@ void {{className}}::connectSignals()
{% endfor %}
}

QMap<QString, QDBusVariant> {{className}}::changedProperties()
{
QMap<QString, QDBusVariant> ret;
auto theService = service();
Q_UNUSED(theService);
{% for property in interface.properties %}
{% if not property.type.is_model %}
if (m_previous{{property.name}} != theService->{{property.name}}()) {
ret[QStringLiteral("{{property.name}}")] = castToDBusVariant(theService->{{property.name}}());
m_previous{{property.name}} = theService->{{property.name}}();
}
{% endif %}
{% endfor %}
return ret;
}

void {{className}}::marshalPropertyValues(const QList<QVariant>& arguments, OutputIPCMessage& msg)
{
QListIterator<QVariant> argumentsIterator(arguments);
Expand Down
4 changes: 4 additions & 0 deletions codegen/facelift/templates/IPCServiceAdapter.template.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class {{classExport}} {{className}}: public {{baseClass}}

void connectSignals() override;

QMap<QString, QDBusVariant> changedProperties();

void marshalPropertyValues(const QList<QVariant>& arguments, OutputIPCMessage& msg) override;

void marshalProperty(const QList<QVariant>& arguments, OutputIPCMessage& msg) override;
Expand All @@ -106,6 +108,8 @@ class {{classExport}} {{className}}: public {{baseClass}}
{% for property in interface.properties %}
{% if property.type.is_model %}
::facelift::IPCAdapterModelPropertyHandler<ThisType, {{property.nestedType.interfaceCppType}}> m_{{property.name}}Handler;
{% else %}
{{property.interfaceCppType}} m_previous{{property.name}} {};
{% endif %}
{% endfor %}
};
Expand Down
9 changes: 3 additions & 6 deletions src/ipc/dbus/IPCDBusServiceAdapterBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ class FaceliftIPCLibDBus_EXPORT IPCDBusServiceAdapterBase : public IPCServiceAda

bool handleMessage(const QDBusMessage &dbusMsg);


template<typename Value>
inline void sendPropertiesChanged(const QString& property , const Value & value);
inline void sendPropertiesChanged(const QMap<QString, QDBusVariant>& changedProperties);

template<typename ... Args>
void sendSignal(const QString& signalName, Args && ... args);
Expand Down Expand Up @@ -235,12 +233,11 @@ class FaceliftIPCLibDBus_EXPORT IPCDBusServiceAdapterBase : public IPCServiceAda
}
};

template<typename Value>
inline void IPCDBusServiceAdapterBase::sendPropertiesChanged(const QString& property, const Value &value)
inline void IPCDBusServiceAdapterBase::sendPropertiesChanged(const QMap<QString, QDBusVariant> &changedProperties)
{
DBusIPCMessage reply(objectPath(), DBusIPCCommon::PROPERTIES_INTERFACE_NAME, DBusIPCCommon::PROPERTIES_CHANGED_SIGNAL_NAME);
reply << interfaceName();
reply << QVariant::fromValue(QMap<QString, QDBusVariant>{{property, castToDBusVariant(value)}});
reply << QVariant::fromValue(changedProperties);
this->send(reply);
}

Expand Down
8 changes: 3 additions & 5 deletions src/ipc/local/LocalIPCServiceAdapterBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ class FaceliftIPCLocalLib_EXPORT LocalIPCServiceAdapterBase : public IPCServiceA

IPCHandlingResult handleMessage(LocalIPCMessage &message);

template<typename Value>
inline void sendPropertiesChanged(const QString& property , const Value & value);
inline void sendPropertiesChanged(const QMap<QString, QDBusVariant> &changedProperties);

template<typename ... Args>
void sendSignal(const QString& signalName, Args && ... args);
Expand Down Expand Up @@ -170,12 +169,11 @@ class FaceliftIPCLocalLib_EXPORT LocalIPCServiceAdapterBase : public IPCServiceA
bool m_alreadyInitialized = false;
};

template<typename Value>
inline void LocalIPCServiceAdapterBase::sendPropertiesChanged(const QString& property , const Value & value)
inline void LocalIPCServiceAdapterBase::sendPropertiesChanged(const QMap<QString, QDBusVariant> &changedProperties )
{
LocalIPCMessage reply(FaceliftIPCCommon::PROPERTIES_INTERFACE_NAME, FaceliftIPCCommon::PROPERTIES_CHANGED_SIGNAL_NAME);
reply << interfaceName();
reply << QVariant::fromValue(QMap<QString, QDBusVariant>{{property, castToDBusVariant(value)}});
reply << QVariant::fromValue(changedProperties);
this->send(reply);
}

Expand Down

0 comments on commit a3e6151

Please sign in to comment.