summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@pelagicore.com>2019-02-28 16:02:01 +0100
committerRobert Griebl <robert.griebl@pelagicore.com>2019-03-14 10:10:27 +0000
commit3611624f97c0b11afb2ddfd6c28ee75b63e26cff (patch)
treebf69f334fbb892265642ee4bfdc4475aa2f864c0 /src
parent8bc29da8b94d929b9c59f2516c1013372263b48f (diff)
downloadqtivi-3611624f97c0b11afb2ddfd6c28ee75b63e26cff.tar.gz
ivigenerator: Add model support to the "backend_qtro" template
Fixes: AUTOSUITE-599 Change-Id: I45e8a00146556b0df159479f703e4bf74cf0c9c6 Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
Diffstat (limited to 'src')
-rw-r--r--src/tools/ivigenerator/common/interface.rep.tpl5
-rw-r--r--src/tools/ivigenerator/common/pagingmodel.rep.tpl61
-rw-r--r--src/tools/ivigenerator/ivigenerator.pro5
-rw-r--r--src/tools/ivigenerator/templates_backend_qtro.yaml2
-rw-r--r--src/tools/ivigenerator/templates_backend_qtro/backend.cpp.tpl25
-rw-r--r--src/tools/ivigenerator/templates_backend_qtro/backend.h.tpl13
-rw-r--r--src/tools/ivigenerator/templates_backend_qtro/pagingmodel.cpp.tpl117
-rw-r--r--src/tools/ivigenerator/templates_backend_qtro/pagingmodel.h.tpl72
-rw-r--r--src/tools/ivigenerator/templates_backend_qtro/plugin.pri.tpl1
-rw-r--r--src/tools/ivigenerator/templates_server_qtro.yaml2
-rw-r--r--src/tools/ivigenerator/templates_server_qtro/server.pri.tpl3
11 files changed, 293 insertions, 13 deletions
diff --git a/src/tools/ivigenerator/common/interface.rep.tpl b/src/tools/ivigenerator/common/interface.rep.tpl
index 6991953..25592d0 100644
--- a/src/tools/ivigenerator/common/interface.rep.tpl
+++ b/src/tools/ivigenerator/common/interface.rep.tpl
@@ -50,11 +50,6 @@
{% for inc in interface|struct_includes %}
{{inc}}
{% endfor %}
-{% for property in interface.properties %}
-{% if property.type.is_model %}
-#include "{{property|model_type|lower}}.h"
-{% endif %}
-{% endfor %}
class {{class}}
{
diff --git a/src/tools/ivigenerator/common/pagingmodel.rep.tpl b/src/tools/ivigenerator/common/pagingmodel.rep.tpl
new file mode 100644
index 0000000..0ccda70
--- /dev/null
+++ b/src/tools/ivigenerator/common/pagingmodel.rep.tpl
@@ -0,0 +1,61 @@
+{#
+# Copyright (C) 2019 Luxoft Sweden AB
+# Copyright (C) 2018 Pelagicore AG.
+# Contact: https://www.qt.io/licensing/
+#
+# This file is part of the QtIvi module of the Qt Toolkit.
+#
+# $QT_BEGIN_LICENSE:LGPL-QTAS$
+# Commercial License Usage
+# Licensees holding valid commercial Qt Automotive Suite licenses may use
+# this file in accordance with the commercial license agreement provided
+# with the Software or, alternatively, in accordance with the terms
+# contained in a written agreement between you and The Qt Company. For
+# licensing terms and conditions see https://www.qt.io/terms-conditions.
+# For further information use the contact form at https://www.qt.io/contact-us.
+#
+# GNU Lesser General Public License Usage
+# Alternatively, this file may be used under the terms of the GNU Lesser
+# General Public License version 3 as published by the Free Software
+# Foundation and appearing in the file LICENSE.LGPL3 included in the
+# packaging of this file. Please review the following information to
+# ensure the GNU Lesser General Public License version 3 requirements
+# will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+#
+# GNU General Public License Usage
+# Alternatively, this file may be used under the terms of the GNU
+# General Public License version 2.0 or (at your option) the GNU General
+# Public license version 3 or any later version approved by the KDE Free
+# Qt Foundation. The licenses are as published by the Free Software
+# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+# included in the packaging of this file. Please review the following
+# information to ensure the GNU General Public License requirements will
+# be met: https://www.gnu.org/licenses/gpl-2.0.html and
+# https://www.gnu.org/licenses/gpl-3.0.html.
+#
+# $QT_END_LICENSE$
+#
+# SPDX-License-Identifier: LGPL-3.0
+#}
+/////////////////////////////////////////////////////////////////////////////
+// Generated from '{{module}}.qface'
+//
+// Created by: The QFace generator (QtAS {{qtASVersion}})
+//
+// WARNING! All changes made in this file will be lost!
+/////////////////////////////////////////////////////////////////////////////
+
+#include <QtIviCore/QtIviCoreModule>
+#include <QUuid>
+
+class PagingModel
+{
+ SLOT(void registerInstance(const QUuid &identifier))
+ SLOT(void unregisterInstance(const QUuid &identifier))
+ SLOT(void fetchData(const QUuid &identifier, int start, int count))
+
+ SIGNAL(supportedCapabilitiesChanged(const QUuid &identifier, QtIviCoreModule::ModelCapabilities capabilities))
+ SIGNAL(countChanged(const QUuid &identifier, int newLength))
+ SIGNAL(dataFetched(const QUuid &identifier, const QList<QVariant> &data, int start, bool moreAvailable))
+ SIGNAL(dataChanged(const QUuid &identifier, const QList<QVariant> &data, int start, int count))
+};
diff --git a/src/tools/ivigenerator/ivigenerator.pro b/src/tools/ivigenerator/ivigenerator.pro
index 35b1389..c128685 100644
--- a/src/tools/ivigenerator/ivigenerator.pro
+++ b/src/tools/ivigenerator/ivigenerator.pro
@@ -17,7 +17,8 @@ common.files += \
common/simulation.qmltypes.tpl \
common/plugins.qmltypes.tpl \
common/qmldir.tpl \
- common/interface.rep.tpl
+ common/interface.rep.tpl \
+ common/pagingmodel.rep.tpl
common.path = $$[QT_HOST_BINS]/ivigenerator/common
templates_frontend.files += \
@@ -82,6 +83,8 @@ templates_control_panel.path = $$[QT_HOST_BINS]/ivigenerator/templates_control_p
templates_backend_qtro.files += \
templates_backend_qtro/backend.cpp.tpl \
templates_backend_qtro/backend.h.tpl \
+ templates_backend_qtro/pagingmodel.h.tpl \
+ templates_backend_qtro/pagingmodel.cpp.tpl \
templates_backend_qtro/plugin.cpp.tpl \
templates_backend_qtro/plugin.h.tpl \
templates_backend_qtro/plugin.json \
diff --git a/src/tools/ivigenerator/templates_backend_qtro.yaml b/src/tools/ivigenerator/templates_backend_qtro.yaml
index 37a26dd..9d50fe4 100644
--- a/src/tools/ivigenerator/templates_backend_qtro.yaml
+++ b/src/tools/ivigenerator/templates_backend_qtro.yaml
@@ -8,6 +8,8 @@ generate_rules:
template_file: "plugin.json"
- dest_file: "{{srcBase|lower}}.pri"
template_file: "plugin.pri.tpl"
+ - dest_file: "pagingmodel.rep"
+ template_file: "pagingmodel.rep.tpl"
interface_rules:
- dest_file: '{{interface|lower}}backend.h'
template_file: 'backend.h.tpl'
diff --git a/src/tools/ivigenerator/templates_backend_qtro/backend.cpp.tpl b/src/tools/ivigenerator/templates_backend_qtro/backend.cpp.tpl
index 029363d..6918b93 100644
--- a/src/tools/ivigenerator/templates_backend_qtro/backend.cpp.tpl
+++ b/src/tools/ivigenerator/templates_backend_qtro/backend.cpp.tpl
@@ -44,16 +44,16 @@
{% set interface_zoned = interface.tags.config and interface.tags.config.zoned %}
#include "{{class|lower}}.h"
-{% for property in interface.properties %}
-{% if property.type.is_model %}
-#include "{{property|model_type|lower}}.h"
-{% endif %}
-{% endfor %}
-
#include <QDebug>
#include <QSettings>
#include "{{module.module_name|lower}}module.h"
+{% for property in interface.properties %}
+{% if property.type.is_model %}
+{% include "pagingmodel.cpp.tpl" %}
+{% endif %}
+{% endfor %}
+
QT_BEGIN_NAMESPACE
{% if interface_zoned %}
@@ -118,6 +118,11 @@ void {{zone_class}}::emitCurrentState()
{{class}}::{{class}}(QObject *parent)
: {{class}}Interface(parent)
+{% for property in interface.properties %}
+{% if property.type.is_model %}
+ , m_{{property}}(new {{property|upperfirst}}ModelBackend(this))
+{% endif %}
+{% endfor %}
{% if interface_zoned %}
, m_synced(false)
{% endif %}
@@ -151,6 +156,12 @@ void {{zone_class}}::emitCurrentState()
void {{class}}::initialize()
{
+{% for property in interface.properties %}
+{% if property.type.is_model %}
+ emit {{property}}Changed(m_{{property}});
+{% endif %}
+{% endfor %}
+
{% if interface_zoned %}
if (m_synced)
onZoneSyncDone();
@@ -202,6 +213,7 @@ QStringList {{class}}::availableZones() const
{% for property in interface.properties %}
{% if not property.readonly and not property.const %}
+{% if not property.is_model %}
{{ivi.prop_setter(property, class, zoned=interface_zoned)}}
{
{% if not property.type.is_model %}
@@ -215,6 +227,7 @@ QStringList {{class}}::availableZones() const
{% endif %}
}
+{% endif %}
{% endif %}
{% endfor %}
diff --git a/src/tools/ivigenerator/templates_backend_qtro/backend.h.tpl b/src/tools/ivigenerator/templates_backend_qtro/backend.h.tpl
index 0123677..c0ebb61 100644
--- a/src/tools/ivigenerator/templates_backend_qtro/backend.h.tpl
+++ b/src/tools/ivigenerator/templates_backend_qtro/backend.h.tpl
@@ -54,6 +54,12 @@
{% endif %}
#include "rep_{{interface|lower}}_replica.h"
+{% for property in interface.properties %}
+{% if property.type.is_model %}
+{% include "pagingmodel.h.tpl" %}
+{% endif %}
+{% endfor %}
+
QT_BEGIN_NAMESPACE
{% if interface_zoned %}
@@ -107,7 +113,9 @@ public:
public Q_SLOTS:
{% for property in interface.properties %}
{% if not property.readonly and not property.const %}
+{% if not property.is_model %}
virtual {{ivi.prop_setter(property, zoned=interface_zoned)}} override;
+{% endif %}
{% endif %}
{% endfor %}
@@ -134,6 +142,11 @@ protected:
QSharedPointer<{{interface}}Replica> m_replica;
QRemoteObjectNode* m_node= nullptr;
QUrl m_url;
+{% for property in interface.properties %}
+{% if property.type.is_model %}
+ QIviPagingModelInterface *m_{{property}};
+{% endif %}
+{% endfor %}
{% if interface_zoned %}
bool m_synced;
QHash<QString, {{zone_class}}*> m_zoneMap;
diff --git a/src/tools/ivigenerator/templates_backend_qtro/pagingmodel.cpp.tpl b/src/tools/ivigenerator/templates_backend_qtro/pagingmodel.cpp.tpl
new file mode 100644
index 0000000..a98aaf9
--- /dev/null
+++ b/src/tools/ivigenerator/templates_backend_qtro/pagingmodel.cpp.tpl
@@ -0,0 +1,117 @@
+{#
+# Copyright (C) 2019 Luxoft Sweden AB
+# Contact: https://www.qt.io/licensing/
+#
+# This file is part of the QtIvi module of the Qt Toolkit.
+#
+# $QT_BEGIN_LICENSE:LGPL-QTAS$
+# Commercial License Usage
+# Licensees holding valid commercial Qt Automotive Suite licenses may use
+# this file in accordance with the commercial license agreement provided
+# with the Software or, alternatively, in accordance with the terms
+# contained in a written agreement between you and The Qt Company. For
+# licensing terms and conditions see https://www.qt.io/terms-conditions.
+# For further information use the contact form at https://www.qt.io/contact-us.
+#
+# GNU Lesser General Public License Usage
+# Alternatively, this file may be used under the terms of the GNU Lesser
+# General Public License version 3 as published by the Free Software
+# Foundation and appearing in the file LICENSE.LGPL3 included in the
+# packaging of this file. Please review the following information to
+# ensure the GNU Lesser General Public License version 3 requirements
+# will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+#
+# GNU General Public License Usage
+# Alternatively, this file may be used under the terms of the GNU
+# General Public License version 2.0 or (at your option) the GNU General
+# Public license version 3 or any later version approved by the KDE Free
+# Qt Foundation. The licenses are as published by the Free Software
+# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+# included in the packaging of this file. Please review the following
+# information to ensure the GNU General Public License requirements will
+# be met: https://www.gnu.org/licenses/gpl-2.0.html and
+# https://www.gnu.org/licenses/gpl-3.0.html.
+#
+# $QT_END_LICENSE$
+#
+# SPDX-License-Identifier: LGPL-3.0
+#}
+{% set class = '{0}ModelBackend'.format(property|upperfirst) %}
+
+{{class}}::{{class}}(QObject* parent)
+ : QIviPagingModelInterface(parent)
+{
+ qRegisterMetaType<QIviPagingModelInterface*>();
+
+ QString configPath(QStringLiteral("./server.conf"));
+ if (qEnvironmentVariableIsSet("SERVER_CONF_PATH"))
+ configPath = QString::fromLocal8Bit(qgetenv("SERVER_CONF_PATH"));
+ else
+ qDebug() << "Environment variable SERVER_CONF_PATH not defined, using " << configPath;
+ QSettings settings(configPath, QSettings::IniFormat);
+ settings.beginGroup(QStringLiteral("{{module.module_name|lower}}"));
+ m_url = QUrl(settings.value(QStringLiteral("Registry"), QStringLiteral("local:{{module.module_name|lower}}")).toString());
+ m_node = new QRemoteObjectNode(m_url);
+ connect(m_node, &QRemoteObjectNode::error, this, &{{class}}::onNodeError);
+ m_replica = m_node->acquire<PagingModelReplica>(QStringLiteral("{{interface.qualified_name}}.{{property}}"));
+ setupConnections();
+}
+
+/*! \internal */
+{{class}}::~{{class}}()
+{
+ delete m_node;
+}
+
+void {{class}}::initialize()
+{
+ if (m_replica->isInitialized())
+ emit initializationDone();
+}
+
+void {{class}}::registerInstance(const QUuid &identifier)
+{
+ m_replica->registerInstance(identifier);
+}
+
+void {{class}}::unregisterInstance(const QUuid &identifier)
+{
+ m_replica->unregisterInstance(identifier);
+}
+
+void {{class}}::fetchData(const QUuid &identifier, int start, int count)
+{
+ m_replica->fetchData(identifier, start, count);
+}
+
+void {{class}}::setupConnections()
+{
+ connect(m_replica.data(), &QRemoteObjectReplica::initialized, this, &QIviFeatureInterface::initializationDone);
+ connect(m_replica.data(), &QRemoteObjectReplica::stateChanged, this, &{{class}}::onReplicaStateChanged);
+ connect(m_replica.data(), &PagingModelReplica::supportedCapabilitiesChanged, this, &{{class}}::supportedCapabilitiesChanged);
+ connect(m_replica.data(), &PagingModelReplica::countChanged, this, &{{class}}::countChanged);
+ connect(m_replica.data(), &PagingModelReplica::dataFetched, this, &{{class}}::dataFetched);
+ connect(m_replica.data(), &PagingModelReplica::dataChanged, this, &{{class}}::dataChanged);
+}
+
+void {{class}}::onReplicaStateChanged(QRemoteObjectReplica::State newState,
+ QRemoteObjectReplica::State oldState)
+{
+ if (newState == QRemoteObjectReplica::Suspect) {
+ qDebug() << "{{class}}, QRemoteObjectReplica error, connection to the source lost";
+ emit errorChanged(QIviAbstractFeature::Unknown,
+ "QRemoteObjectReplica error, connection to the source lost");
+ } else if (newState == QRemoteObjectReplica::SignatureMismatch) {
+ qDebug() << "{{class}}, QRemoteObjectReplica error, signature mismatch";
+ emit errorChanged(QIviAbstractFeature::Unknown,
+ "QRemoteObjectReplica error, signature mismatch");
+ } else if (newState == QRemoteObjectReplica::Valid) {
+ emit errorChanged(QIviAbstractFeature::NoError, "");
+ }
+}
+
+void {{class}}::onNodeError(QRemoteObjectNode::ErrorCode code)
+{
+ qDebug() << "{{class}}, QRemoteObjectNode error, code: " << code;
+ emit errorChanged(QIviAbstractFeature::Unknown, "QRemoteObjectNode error, code: " + code);
+}
diff --git a/src/tools/ivigenerator/templates_backend_qtro/pagingmodel.h.tpl b/src/tools/ivigenerator/templates_backend_qtro/pagingmodel.h.tpl
new file mode 100644
index 0000000..32ac478
--- /dev/null
+++ b/src/tools/ivigenerator/templates_backend_qtro/pagingmodel.h.tpl
@@ -0,0 +1,72 @@
+{#
+# Copyright (C) 2019 Luxoft Sweden AB
+# Contact: https://www.qt.io/licensing/
+#
+# This file is part of the QtIvi module of the Qt Toolkit.
+#
+# $QT_BEGIN_LICENSE:LGPL-QTAS$
+# Commercial License Usage
+# Licensees holding valid commercial Qt Automotive Suite licenses may use
+# this file in accordance with the commercial license agreement provided
+# with the Software or, alternatively, in accordance with the terms
+# contained in a written agreement between you and The Qt Company. For
+# licensing terms and conditions see https://www.qt.io/terms-conditions.
+# For further information use the contact form at https://www.qt.io/contact-us.
+#
+# GNU Lesser General Public License Usage
+# Alternatively, this file may be used under the terms of the GNU Lesser
+# General Public License version 3 as published by the Free Software
+# Foundation and appearing in the file LICENSE.LGPL3 included in the
+# packaging of this file. Please review the following information to
+# ensure the GNU Lesser General Public License version 3 requirements
+# will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+#
+# GNU General Public License Usage
+# Alternatively, this file may be used under the terms of the GNU
+# General Public License version 2.0 or (at your option) the GNU General
+# Public license version 3 or any later version approved by the KDE Free
+# Qt Foundation. The licenses are as published by the Free Software
+# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+# included in the packaging of this file. Please review the following
+# information to ensure the GNU General Public License requirements will
+# be met: https://www.gnu.org/licenses/gpl-2.0.html and
+# https://www.gnu.org/licenses/gpl-3.0.html.
+#
+# $QT_END_LICENSE$
+#
+# SPDX-License-Identifier: LGPL-3.0
+#}
+{% set class = '{0}ModelBackend'.format(property|upperfirst) %}
+
+#include <QIviPagingModelInterface>
+#include "{{property.type.nested|lower}}.h"
+
+#include "rep_pagingmodel_replica.h"
+
+class {{class}} : public QIviPagingModelInterface
+{
+ Q_OBJECT
+public:
+ explicit {{class}}(QObject *parent = nullptr);
+ ~{{class}}();
+
+ void initialize() override;
+ void registerInstance(const QUuid &identifier) override;
+ void unregisterInstance(const QUuid &identifier) override;
+
+ void fetchData(const QUuid &identifier, int start, int count) override;
+
+protected Q_SLOTS:
+ void onReplicaStateChanged(QRemoteObjectReplica::State newState,
+ QRemoteObjectReplica::State oldState);
+ void onNodeError(QRemoteObjectNode::ErrorCode code);
+
+private:
+ void setupConnections();
+
+ QPointer<PagingModelReplica> m_replica;
+ QRemoteObjectNode *m_node= nullptr;
+ QUrl m_url;
+ QVariantList m_list;
+};
+
diff --git a/src/tools/ivigenerator/templates_backend_qtro/plugin.pri.tpl b/src/tools/ivigenerator/templates_backend_qtro/plugin.pri.tpl
index 78fb414..7fc99c2 100644
--- a/src/tools/ivigenerator/templates_backend_qtro/plugin.pri.tpl
+++ b/src/tools/ivigenerator/templates_backend_qtro/plugin.pri.tpl
@@ -57,6 +57,7 @@ SOURCES += \
$$PWD/{{module.module_name|lower}}plugin.cpp
REPC_REPLICA += \
+ $$PWD/pagingmodel.rep \
{% for interface in module.interfaces %}
$$PWD/{{interface|lower}}.rep \
{% endfor %}
diff --git a/src/tools/ivigenerator/templates_server_qtro.yaml b/src/tools/ivigenerator/templates_server_qtro.yaml
index d2e94ad..e6db906 100644
--- a/src/tools/ivigenerator/templates_server_qtro.yaml
+++ b/src/tools/ivigenerator/templates_server_qtro.yaml
@@ -6,6 +6,8 @@ generate_rules:
template_file: "core.h.tpl"
- dest_file: "{{srcBase|lower}}.pri"
template_file: "server.pri.tpl"
+ - dest_file: "pagingmodel.rep"
+ template_file: "pagingmodel.rep.tpl"
interface_rules:
- dest_file: "{{interface|lower}}.rep"
template_file: "interface.rep.tpl"
diff --git a/src/tools/ivigenerator/templates_server_qtro/server.pri.tpl b/src/tools/ivigenerator/templates_server_qtro/server.pri.tpl
index aff935c..aca2f24 100644
--- a/src/tools/ivigenerator/templates_server_qtro/server.pri.tpl
+++ b/src/tools/ivigenerator/templates_server_qtro/server.pri.tpl
@@ -42,13 +42,14 @@
## Do not edit! All changes made to it will be lost.
#############################################################################
-QT += remoteobjects
+QT += ivicore remoteobjects
HEADERS += $$PWD/core.h
SOURCES += $$PWD/core.cpp
REPC_SOURCE += \
+ $$PWD/pagingmodel.rep \
{% for interface in module.interfaces %}
$$PWD/{{interface|lower}}.rep \
{% endfor %}