diff options
author | Dominik Holland <dominik.holland@pelagicore.com> | 2018-10-11 10:20:54 +0200 |
---|---|---|
committer | Dominik Holland <dominik.holland@pelagicore.com> | 2018-10-15 12:50:08 +0000 |
commit | 272517c7b9a9ef3221eed7a08fa26b37c0e81722 (patch) | |
tree | f3ee8dbd29bbaca9451f083c4a3056321b60ed4a /src | |
parent | 3e7ea35e21e17b443926574a4b1ce877b8395760 (diff) | |
download | qtivi-272517c7b9a9ef3221eed7a08fa26b37c0e81722.tar.gz |
Update the generator templates to use the new QIviSimulationEngine
Task-number: AUTOSUITE-627
Change-Id: I0bd49c420c3b60ba70a67f509cb819d9c116d599
Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
Diffstat (limited to 'src')
10 files changed, 161 insertions, 32 deletions
diff --git a/src/ivicore/doc/src/ivigenerator/generator-usage.qdoc b/src/ivicore/doc/src/ivigenerator/generator-usage.qdoc index d83a47e..aedbd29 100644 --- a/src/ivicore/doc/src/ivigenerator/generator-usage.qdoc +++ b/src/ivicore/doc/src/ivigenerator/generator-usage.qdoc @@ -230,6 +230,17 @@ annotations used for defining various aspects of the generation of the backend-s \li \code config_simulator: + simulationFile: ":/qrc/simulation.qml" + \endcode + \li Accompanying YAML file + \li Module + \li Defines which simulation QML file should be loaded by the simulation backend. The + provided snippet loads the QML file from the resource system, which needs to be embedded + by the developer. + \row + \li + \code + config_simulator: zones: { left : FrontLeft, right : FrontRight, rear: Rear } \endcode \li Accompanying YAML file diff --git a/src/tools/ivigenerator/common/qtivi_macros.j2 b/src/tools/ivigenerator/common/qtivi_macros.j2 index b8acf54..8f18ddd 100644 --- a/src/tools/ivigenerator/common/qtivi_macros.j2 +++ b/src/tools/ivigenerator/common/qtivi_macros.j2 @@ -48,8 +48,12 @@ {# join operation parameters, with type and name, into a comma separated list, # optionally including the zone. #} -{% macro join_params(operation, zoned = false) %} -{% set params = operation.parameters|map('parameter_type')|join(', ') %} +{% macro join_params(operation, zoned = false, default_values = false) %} +{% if default_values %} +{% set params = operation.parameters|map('parameter_type_default')|join(', ') %} +{% else %} +{% set params = operation.parameters|map('parameter_type')|join(', ') %} +{% endif %} {% if zoned %} {% if params|length %} {% set params = params + ', const QString &zone' %} @@ -98,7 +102,7 @@ Q_PROPERTY({{property|return_type}} {{property}} READ {{property|getter_name}}{{ # pass the class parameter in order to add the scope:: -specifier. # use zoned to add the zone-specifier #} -{% macro prop_setter(property, class = '', zoned = false) %} +{% macro prop_setter(property, class = '', zoned = false, model_interface = false) %} {% if class|count %} {% set scope = class+'::' %} {% else %} @@ -109,27 +113,37 @@ Q_PROPERTY({{property|return_type}} {{property}} READ {{property|getter_name}}{{ {% else %} {% set zone = '' %} {% endif %} -void {{scope}}{{property|setter_name}}({{property|parameter_type}}{{zone}}) +{% if property.type.is_model and model_interface %} +{% set type = 'QIviPagingModelInterface *'+property.name %} +{% else %} +{% set type = property|parameter_type %} +{% endif %} +void {{scope}}{{property|setter_name}}({{type}}{{zone}}) {%- endmacro %} {# function header for a property getter. # pass the class parameter in order to add the scope:: -specifier. #} -{% macro prop_getter(property, class = '') %} +{% macro prop_getter(property, class = '', model_interface = false) %} {% if class|count %} {% set scope = class+'::' %} {% else %} {% set scope = '' %} {% endif %} -{{property|return_type}} {{scope}}{{property|getter_name}}() const +{% if property.type.is_model and model_interface %} +{% set type = 'QIviPagingModelInterface *' %} +{% else %} +{% set type = property|return_type %} +{% endif %} +{{type}} {{scope}}{{property|getter_name}}() const {%- endmacro %} {# helper macro for defining a property notifier and a corresponding callback. # This is an internal function and not intended to be used inside a template. #} -{% macro _prop_notify(property, class, zoned, prefix, model_interface) %} +{% macro _prop_notify(property, class, zoned, prefix, model_interface, default_values = false) %} {% if prefix|count %} {% set prop = prefix + property|upperfirst %} {% else %} @@ -141,14 +155,23 @@ void {{scope}}{{property|setter_name}}({{property|parameter_type}}{{zone}}) {% set scope = '' %} {% endif %} {% if zoned %} -{% set zone = ', const QString &zone' %} +{% if default_values %} +{% set zone = ', const QString &zone=QString()' %} +{% else %} +{% set zone = ', const QString &zone' %} +{% endif %} {% else %} {% set zone = '' %} {% endif %} {% if property.type.is_model and model_interface %} {% set type = 'QIviPagingModelInterface *'+property.name %} +{% set default_value = type + '=nullptr'%} {% else %} {% set type = property|parameter_type %} +{% set default_value = property|parameter_type_default %} +{% endif %} +{% if default_values %} +{% set type = default_value %} {% endif %} void {{scope}}{{prop}}Changed({{type}}{{zone}}) {%- endmacro %} @@ -157,8 +180,8 @@ void {{scope}}{{prop}}Changed({{type}}{{zone}}) # pass the class parameter in order to add the scope:: -specifier. # use zoned to add the zone-specifier #} -{% macro prop_notify(property, class = '', zoned = false, model_interface = false) %} -{{_prop_notify(property, class, zoned, '', model_interface)}} +{% macro prop_notify(property, class = '', zoned = false, model_interface = false, default_values = false) %} +{{_prop_notify(property, class, zoned, '', model_interface, default_values)}} {%- endmacro %} {# callback slot declaration for property notifier. @@ -173,7 +196,7 @@ void {{scope}}{{prop}}Changed({{type}}{{zone}}) {# helper macro for defining a signal and a corresponding callback. # This is an internal function and not intended to be used inside a template. #} -{% macro _signal(signal, class, zoned, prefix) %} +{% macro _signal(signal, class, zoned, prefix, default_values = false) %} {% if prefix|count %} {% set sig = prefix + signal|upperfirst %} {% else %} @@ -184,7 +207,7 @@ void {{scope}}{{prop}}Changed({{type}}{{zone}}) {% else %} {% set scope = '' %} {% endif %} -void {{scope}}{{sig}}({{join_params(signal, zoned)}}) +void {{scope}}{{sig}}({{join_params(signal, zoned, default_values)}}) {%- endmacro %} {# custom signal declaration diff --git a/src/tools/ivigenerator/generate.py b/src/tools/ivigenerator/generate.py index ccb232b..39bf994 100755 --- a/src/tools/ivigenerator/generate.py +++ b/src/tools/ivigenerator/generate.py @@ -122,7 +122,8 @@ def default_type_value(symbol): value = next(iter(t.reference.members)) return '{0}{1}Module::{2}'.format(prefix, upper_first(module_name), value) elif t.is_flag: - return '0' + module_name = t.reference.module.module_name + return '{0}{1}Module::{2}()'.format(prefix, upper_first(module_name), flag_type(symbol)) elif symbol.type.is_list: nested = Filters.returnType(symbol.type.nested) return 'QVariantList()'.format(nested) @@ -221,6 +222,33 @@ def default_value(symbol, zone='='): return res +def parameter_type_default(symbol): + """ + Return the parameter declaration for properties, handle camel case module name + """ + prefix = Filters.classPrefix + if symbol.type.is_enum or symbol.type.is_flag: + return '{0}{1}Module::{2} {3}={4}'.format(prefix, upper_first(symbol.module.module_name), flag_type(symbol), symbol, default_type_value(symbol)) + if symbol.type.is_void or symbol.type.is_primitive: + if symbol.type.name == 'string': + return 'const QString &{0}=QString()'.format(symbol) + if symbol.type.name == 'var': + return 'const QVariant &{0}=QVariant()'.format(symbol) + if symbol.type.name == 'real': + return 'qreal {0}=qreal()'.format(symbol) + return '{0} {1}={2}'.format(symbol.type, symbol, default_type_value(symbol)) + elif symbol.type.is_list: + nested = return_type(symbol.type.nested) + return 'const QVariantList &{1}=QVariantList()'.format(nested, symbol) + elif symbol.type.is_model: + nested = symbol.type.nested + if nested.is_primitive: + return '{0}VariantModel *{1}=QVariantModel'.format(prefix, symbol) + elif nested.is_complex: + return 'QIviPagingModel *{0}=nullptr'.format(symbol) + else: + return 'const {0}{1} &{2}={0}{1}()'.format(prefix, symbol.type, symbol) + return 'QFace Error: Unknown parameter {0} of type {1}'.format(symbol, symbol.type) def parameter_type(symbol): """ @@ -597,6 +625,7 @@ def generate(tplconfig, moduleConfig, annotations, src, dst): FileSystem.merge_annotations(system, Path(annotations_file)) generator = Generator(search_path=[tplconfig, here / "common"]) generator.register_filter('return_type', return_type) + generator.register_filter('parameter_type_default', parameter_type_default) generator.register_filter('parameter_type', parameter_type) generator.register_filter('getter_name', getter_name) generator.register_filter('setter_name', setter_name) diff --git a/src/tools/ivigenerator/templates_backend_simulator/backend.cpp.tpl b/src/tools/ivigenerator/templates_backend_simulator/backend.cpp.tpl index a184d48..90df932 100644 --- a/src/tools/ivigenerator/templates_backend_simulator/backend.cpp.tpl +++ b/src/tools/ivigenerator/templates_backend_simulator/backend.cpp.tpl @@ -44,6 +44,7 @@ #include "{{class|lower}}.h" #include <QDebug> +#include <QtIviCore/QIviSimulationEngine> {% if 'simulator' in features %} #include <QtSimulator> @@ -63,12 +64,15 @@ QT_BEGIN_NAMESPACE {{ ivi.format_comments(interface.comment) }} */ {{class}}::{{class}}(QObject *parent) + : {{class}}(nullptr, parent) +{ +} + +{{class}}::{{class}}(QIviSimulationEngine *engine, QObject *parent) : {{class}}Interface(parent) {% for property in interface.properties %} {% if not property.tags.config_simulator or not property.tags.config_simulator.zoned %} -{% if property.type.is_model %} - , m_{{ property }}(new {{property|upperfirst}}Model(this)) -{% else %} +{% if not property.type.is_model %} , m_{{ property }}({{property|default_value}}) {% endif %} {% endif %} @@ -77,6 +81,18 @@ QT_BEGIN_NAMESPACE , mWorker(nullptr) {% endif %} { + //In some cases the engine is unused, this doesn't do any harm if it is still used + Q_UNUSED(engine) + +{% for property in interface.properties %} +{% if not property.tags.config_simulator or not property.tags.config_simulator.zoned %} +{% if property.type.is_model %} + auto {{ property }}Model = (new {{property|upperfirst}}ModelBackend(this)); + m_{{ property }} = {{ property }}Model; + engine->registerSimulationInstance({{ property }}Model, "{{module.name|lower}}.simulation", 1, 0, "{{property|upperfirst}}ModelBackend"); +{% endif %} +{% endif %} +{% endfor %} {{module.module_name|upperfirst}}Module::registerTypes(); {% set zones = interface.tags.config_simulator.zones if interface.tags.config_simulator and interface.tags.config_simulator.zones else {} %} @@ -129,6 +145,7 @@ QStringList {{class}}::availableZones() const */ void {{class}}::initialize() { + QIVI_SIMULATION_TRY_CALL({{class}}, "initialize", void); {% for property in interface.properties %} {% if not interface_zoned %} emit {{property}}Changed(m_{{property}}); @@ -169,15 +186,23 @@ void {{class}}::initialize() emit initializationDone(); } + {% for property in interface.properties %} -{% if not property.readonly and not property.const and not property.type.is_model %} +{% if not interface_zoned %} +{{ivi.prop_getter(property, class, model_interface = true)}} +{ + return m_{{property}}; +} +{% endif %} + /*! \fn virtual {{ivi.prop_setter(property, class, interface_zoned)}} {{ ivi.format_comments(property.comment) }} */ -{{ivi.prop_setter(property, class, interface_zoned)}} +{{ivi.prop_setter(property, class, interface_zoned, model_interface = true)}} { + QIVI_SIMULATION_TRY_CALL({{class}}, "{{property|setter_name}}", void, {{property}}); {% if property.tags.config_simulator and property.tags.config_simulator.unsupported %} Q_UNUSED({{ property }}); {% if interface_zoned %} @@ -219,7 +244,6 @@ void {{class}}::initialize() {% endif %} } -{% endif %} {% endfor %} {% for operation in interface.operations %} @@ -230,12 +254,6 @@ void {{class}}::initialize() */ {{ivi.operation(operation, class, interface_zoned)}} { -{% for operation_parameter in operation.parameters %} - Q_UNUSED({{operation_parameter.name}}); -{% endfor %} -{% if interface_zoned %} - Q_UNUSED(zone); -{% endif %} {% set function_parameters = operation.parameters|join(', ') %} {% if interface_zoned %} {% if operation.parameters|length %} @@ -243,6 +261,12 @@ void {{class}}::initialize() {% endif %} {% set function_parameters = function_parameters + 'zone' %} {% endif%} + QIviPendingReply<{{operation|return_type}}> pendingReply; + QIVI_SIMULATION_TRY_CALL_FUNC({{class}}, "{{operation}}", return pendingReply, QIviPendingReplyBase(pendingReply){% if function_parameters is not equalto "" %}, {{function_parameters}} {% endif %}); + +{% if interface_zoned %} + Q_UNUSED(zone); +{% endif %} {% if 'simulator' in features %} if (mWorker) diff --git a/src/tools/ivigenerator/templates_backend_simulator/backend.h.tpl b/src/tools/ivigenerator/templates_backend_simulator/backend.h.tpl index 2276a2c..38c7490 100644 --- a/src/tools/ivigenerator/templates_backend_simulator/backend.h.tpl +++ b/src/tools/ivigenerator/templates_backend_simulator/backend.h.tpl @@ -65,23 +65,45 @@ class QSimulatorConnection; class QSimulatorConnectionWorker; {% endif %} +class QIviSimulationEngine; + class {{class}} : public {{class}}Interface { Q_OBJECT +{% for property in interface.properties %} +{% if not interface_zoned %} +{% if property.type.is_model %} +{% set type = 'QIviPagingModelInterface *' %} +{% else %} +{% set type = property|return_type %} +{% endif %} + Q_PROPERTY({{type}} {{property}} READ {{property|getter_name}} WRITE {{property|setter_name}} NOTIFY {{property.name}}Changed FINAL) +{% endif %} +{% endfor %} public: explicit {{class}}(QObject *parent = nullptr); + explicit {{class}}(QIviSimulationEngine *engine, QObject *parent = nullptr); ~{{class}}(); {% if interface_zoned %} QStringList availableZones() const override; {% endif %} - void initialize() override; + Q_INVOKABLE void initialize() override; + +{% for property in interface.properties %} +{% if not interface_zoned %} + {{ivi.prop_getter(property, model_interface = true)}}; +{% endif %} +{% endfor %} + public Q_SLOTS: {% for property in interface.properties %} {% if not property.readonly and not property.const and not property.type.is_model %} virtual {{ivi.prop_setter(property, zoned = interface_zoned)}} override; +{% else %} + {{ivi.prop_setter(property, zoned = interface_zoned, model_interface = true)}}; {% endif %} {% endfor %} @@ -93,9 +115,9 @@ protected: {% for property in interface.properties %} {% if not property.tags.config_simulator or not property.tags.config_simulator.zoned %} {% if property.type.is_model %} -QIviPagingModelInterface *m_{{ property }}; + QIviPagingModelInterface *m_{{ property }}; {% else %} -{{ property|return_type }} m_{{ property }}; + {{ property|return_type }} m_{{ property }}; {% endif %} {% endif %} {% endfor %} diff --git a/src/tools/ivigenerator/templates_backend_simulator/pagingmodel.cpp.tpl b/src/tools/ivigenerator/templates_backend_simulator/pagingmodel.cpp.tpl index c80a0fd..060a377 100644 --- a/src/tools/ivigenerator/templates_backend_simulator/pagingmodel.cpp.tpl +++ b/src/tools/ivigenerator/templates_backend_simulator/pagingmodel.cpp.tpl @@ -37,7 +37,7 @@ # # SPDX-License-Identifier: LGPL-3.0 #} -{% set class = '{0}Model'.format(property|upperfirst) %} +{% set class = '{0}ModelBackend'.format(property|upperfirst) %} {{class}}::{{class}}(QObject* parent) : QIviPagingModelInterface(parent) @@ -52,11 +52,14 @@ void {{class}}::initialize() { + QIVI_SIMULATION_TRY_CALL({{class}}, "initialize", void); + emit initializationDone(); } void {{class}}::registerInstance(const QUuid &identifier) { + QIVI_SIMULATION_TRY_CALL({{class}}, "registerInstance", void, identifier); qCritical() << "REGISTER" << identifier; emit countChanged(identifier, 100); @@ -64,11 +67,15 @@ void {{class}}::registerInstance(const QUuid &identifier) void {{class}}::unregisterInstance(const QUuid &identifier) { + QIVI_SIMULATION_TRY_CALL({{class}}, "unregisterInstance", void, identifier); + qCritical() << "UNREGISTER" << identifier; } void {{class}}::fetchData(const QUuid &identifier, int start, int count) { + QIVI_SIMULATION_TRY_CALL({{class}}, "fetchData", void, identifier, start, count); + qCritical() << "FETCH" << identifier << start << count; QVariantList list; diff --git a/src/tools/ivigenerator/templates_backend_simulator/pagingmodel.h.tpl b/src/tools/ivigenerator/templates_backend_simulator/pagingmodel.h.tpl index 8057630..5d664bf 100644 --- a/src/tools/ivigenerator/templates_backend_simulator/pagingmodel.h.tpl +++ b/src/tools/ivigenerator/templates_backend_simulator/pagingmodel.h.tpl @@ -37,7 +37,7 @@ # # SPDX-License-Identifier: LGPL-3.0 #} -{% set class = '{0}Model'.format(property|upperfirst) %} +{% set class = '{0}ModelBackend'.format(property|upperfirst) %} #include <QIviPagingModelInterface> #include "{{property.type.nested|lower}}.h" diff --git a/src/tools/ivigenerator/templates_backend_simulator/plugin.cpp.tpl b/src/tools/ivigenerator/templates_backend_simulator/plugin.cpp.tpl index 570110f..fef7b01 100644 --- a/src/tools/ivigenerator/templates_backend_simulator/plugin.cpp.tpl +++ b/src/tools/ivigenerator/templates_backend_simulator/plugin.cpp.tpl @@ -47,6 +47,7 @@ {% endfor %} #include <QStringList> +#include <QtIviCore/QIviSimulationEngine> QT_BEGIN_NAMESPACE @@ -62,14 +63,23 @@ extern {{class}}::InterfaceBuilder {{module.tags.config.interfaceBuilder}}; /*! \internal */ {{class}}::{{class}}(QObject *parent) : QObject(parent) + , m_simulationEngine(new QIviSimulationEngine(this)) { {% if module.tags.config.interfaceBuilder %} m_interfaces = {{module.tags.config.interfaceBuilder}}(this); Q_ASSERT(m_interfaces.size() == interfaces().size()); {% else %} {% for interface in module.interfaces %} - m_interfaces << new {{interface}}Backend(this); + auto {{interface}}Instance = new {{interface}}Backend(m_simulationEngine, this); + m_simulationEngine->registerSimulationInstance({{interface}}Instance, "{{module.name|lower}}.simulation", 1, 0, "{{interface}}Backend"); + m_interfaces << {{interface}}Instance; {% endfor %} +{% if module.tags.config_simulator and module.tags.config_simulator.simulationFile %} +{% set simulationFile = module.tags.config_simulator.simulationFile %} +{% else %} +{% set simulationFile = module.module_name|lower + '_simulation.qml' %} +{% endif %} + m_simulationEngine->loadSimulation(QStringLiteral("{{simulationFile}}")); {% endif %} } diff --git a/src/tools/ivigenerator/templates_backend_simulator/plugin.h.tpl b/src/tools/ivigenerator/templates_backend_simulator/plugin.h.tpl index 4a32655..0186747 100644 --- a/src/tools/ivigenerator/templates_backend_simulator/plugin.h.tpl +++ b/src/tools/ivigenerator/templates_backend_simulator/plugin.h.tpl @@ -49,6 +49,8 @@ QT_BEGIN_NAMESPACE +class QIviSimulationEngine; + class {{class}} : public QObject, QIviServiceInterface { Q_OBJECT @@ -65,6 +67,7 @@ public: private: QVector<QIviFeatureInterface *> m_interfaces; + QIviSimulationEngine *m_simulationEngine; }; QT_END_NAMESPACE diff --git a/src/tools/ivigenerator/templates_frontend/backendinterface.h.tpl b/src/tools/ivigenerator/templates_frontend/backendinterface.h.tpl index b30301e..09fc71c 100644 --- a/src/tools/ivigenerator/templates_frontend/backendinterface.h.tpl +++ b/src/tools/ivigenerator/templates_frontend/backendinterface.h.tpl @@ -87,7 +87,7 @@ Q_SIGNALS: {{ivi.signal(signal, zoned = interface.tags.config.zoned)}}; {% endfor %} {% for property in interface.properties %} - {{ivi.prop_notify(property, zoned = interface.tags.config.zoned, model_interface = true)}}; + {{ivi.prop_notify(property, zoned = interface.tags.config.zoned, model_interface = true, default_values = true)}}; {% endfor %} }; |