summaryrefslogtreecommitdiff
path: root/src/intent-server-lib/intent.cpp
diff options
context:
space:
mode:
authorRobert Griebl <robert.griebl@pelagicore.com>2018-10-08 18:22:12 +0200
committerDominik Holland <dominik.holland@pelagicore.com>2018-10-12 09:44:35 +0000
commita54b61a7b17c0dc94441dba10243f364a57bcbb6 (patch)
tree6d6e649faa4542456e54266f9aea7cf5dc28be8d /src/intent-server-lib/intent.cpp
parent8ced28c4c8d96be151fbb646d9bf08265f29249b (diff)
downloadqtapplicationmanager-a54b61a7b17c0dc94441dba10243f364a57bcbb6.tar.gz
Add support for Intents for both single- and multi-process mode
This commit adds support for Intents, aka. a loosely coupled IPC between arbitrary applications in the AM system. (please read https://wiki.qt.io/QtAppMan-Intents for same background information). The core implementation on both server and client side in this patch is not dependent on the AM itself (apart from the common-lib for convenience sake, but this dependency could easily be removed). There are 2 interfaces that are implemented in the manager-lib and launcher-lib that connect the Intent core to the actual AM and AM's qml runtime launcher. Missing features: - updating the list of intents on app installation and removal - support for background services in the AM itself - support for "file-handles" in the request and reply part - documentation - an example that is better focused on intents themselves Change-Id: Ia7cab2bb569fb2cdb8e5ab7e8167e477cff3068c Reviewed-by: Dominik Holland <dominik.holland@pelagicore.com>
Diffstat (limited to 'src/intent-server-lib/intent.cpp')
-rw-r--r--src/intent-server-lib/intent.cpp133
1 files changed, 133 insertions, 0 deletions
diff --git a/src/intent-server-lib/intent.cpp b/src/intent-server-lib/intent.cpp
new file mode 100644
index 00000000..fedb998e
--- /dev/null
+++ b/src/intent-server-lib/intent.cpp
@@ -0,0 +1,133 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Pelagicore Application Manager.
+**
+** $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
+**
+****************************************************************************/
+
+#include "intent.h"
+
+#include <QRegularExpression>
+#include <QVariant>
+
+QT_BEGIN_NAMESPACE_AM
+
+QString Intent::id() const
+{
+ return m_id;
+}
+
+Intent::Visibility Intent::visibility() const
+{
+ return m_visibility;
+}
+
+QStringList Intent::requiredCapabilities() const
+{
+ return m_requiredCapabilities;
+}
+
+QVariantMap Intent::parameterMatch() const
+{
+ return m_parameterMatch;
+}
+
+QString Intent::applicationId() const
+{
+ return m_applicationId;
+}
+
+QString Intent::backgroundServiceId() const
+{
+ return m_backgroundServiceId;
+}
+
+bool Intent::checkParameterMatch(const QVariantMap &parameters) const
+{
+ QMapIterator<QString, QVariant> rit(m_parameterMatch);
+ while (rit.hasNext()) {
+ rit.next();
+ const QString &paramName = rit.key();
+ auto pit = parameters.find(paramName);
+ if (pit == parameters.cend())
+ return false;
+
+ const QVariant requiredValue = rit.value();
+ const QVariant actualValue = pit.value();
+
+ switch (requiredValue.type()) {
+ case QVariant::String: {
+ QRegularExpression regexp(requiredValue.toString());
+ auto match = regexp.match(actualValue.toString());
+ if (!match.hasMatch())
+ return false;
+ break;
+ }
+ case QVariant::List: {
+ bool foundMatch = false;
+ const QVariantList rvlist = requiredValue.toList();
+ for (const QVariant &rv2 : rvlist) {
+ if (actualValue.canConvert(rv2.type()) && actualValue == rv2) {
+ foundMatch = true;
+ break;
+ }
+ }
+ if (!foundMatch)
+ return false;
+ break;
+ }
+ default: {
+ if (requiredValue != actualValue)
+ return false;
+ break;
+ }
+ }
+ }
+ return true;
+}
+
+Intent::Intent(const QString &id, const QString &applicationId, const QString &backgroundHandlerId,
+ const QStringList &capabilities, Intent::Visibility visibility, const QVariantMap &parameterMatch)
+ : m_id(id)
+ , m_visibility(visibility)
+ , m_requiredCapabilities(capabilities)
+ , m_parameterMatch(parameterMatch)
+ , m_applicationId(applicationId)
+ , m_backgroundServiceId(backgroundHandlerId)
+{ }
+
+QT_END_NAMESPACE_AM