diff options
author | Dominik Holland <dominik.holland@pelagicore.com> | 2013-05-24 16:55:58 +0200 |
---|---|---|
committer | Robert Griebl <robert.griebl@pelagicore.com> | 2016-04-14 13:46:16 +0000 |
commit | 631cbba46cf1d2c02eccf7c3960e6f934d0323f0 (patch) | |
tree | 31464d4c0605246cb1c6df39af23f04934dccc3e /tests/testserver/testserver.cpp | |
parent | 169f9ceb6f020082cd36954753651fd2b31fc661 (diff) |
Initial version of a QML DBus Plugin
Change-Id: I6382467d87e8597988fe8cbdb676b2f8ce234186
Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
Diffstat (limited to 'tests/testserver/testserver.cpp')
-rw-r--r-- | tests/testserver/testserver.cpp | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/tests/testserver/testserver.cpp b/tests/testserver/testserver.cpp new file mode 100644 index 0000000..324b954 --- /dev/null +++ b/tests/testserver/testserver.cpp @@ -0,0 +1,157 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Pelagicore AG +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the qmldpusplugin of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT-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 General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testserver.h" + +TestServer::TestServer(QObject *parent) : + QObject(parent) , + m_testProperty(false) +{ +} + +bool TestServer::testProperty() const +{ + qDebug() << __PRETTY_FUNCTION__; + return m_testProperty; +} + +void TestServer::setTestProperty(bool arg) +{ + qDebug() << __PRETTY_FUNCTION__ << arg; + m_testProperty = arg; + emit testPropertyChanged(); + notifyPropertyChanged("testProperty"); +} + +void TestServer::userError() +{ + qDebug() << __PRETTY_FUNCTION__; + sendErrorReply("com.userError", "This is a user error"); +} + +void TestServer::systemError() +{ + qDebug() << __PRETTY_FUNCTION__; + sendErrorReply(QDBusError::InternalError, "Internal error"); +} + +void TestServer::testMethod() +{ + qDebug() << __PRETTY_FUNCTION__; + emit testMethodCalled(); +} + +void TestServer::testMethodWithArguments(const QString &argument) +{ + qDebug() << __PRETTY_FUNCTION__; + emit testMethodWithArgumentsCalled(argument); +} + +bool TestServer::testMethodWithReturnValue() +{ + qDebug() << __PRETTY_FUNCTION__; + return true; +} + +void TestServer::asyncUserError(const QDBusMessage &message) +{ + qDebug() << __PRETTY_FUNCTION__; + createReply(message); + m_pendingReply = message.createErrorReply("com.userError", "This is a user error"); + + QTimer::singleShot(2000, this, SLOT(sendAsyncResult())); +} + +void TestServer::asyncSystemError(const QDBusMessage &message) +{ + qDebug() << __PRETTY_FUNCTION__; + createReply(message); + m_pendingReply = message.createErrorReply(QDBusError::InternalError, "Internal error"); + + QTimer::singleShot(2000, this, SLOT(sendAsyncResult())); +} + +void TestServer::asyncTestMethod(const QDBusMessage &message) +{ + qDebug() << __PRETTY_FUNCTION__; + createReply(message); + + emit asyncTestMethodCalled(); + + QTimer::singleShot(2000, this, SLOT(sendAsyncResult())); +} + +void TestServer::asyncTestMethodWithArguments(const QString &argument, const QDBusMessage &message) +{ + qDebug() << __PRETTY_FUNCTION__; + createReply(message); + + emit asyncTestMethodWithArgumentsCalled(argument); + + QTimer::singleShot(2000, this, SLOT(sendAsyncResult())); +} + +bool TestServer::asyncTestMethodWithReturnValue(const QDBusMessage &message) +{ + qDebug() << __PRETTY_FUNCTION__; + createReply(message); + m_pendingReply << true; + + QTimer::singleShot(2000, this, SLOT(sendAsyncResult())); + + return false; +} + +void TestServer::sendAsyncResult() +{ + qDebug() << "send Async Result" << m_pendingReply; + + QDBusConnection::sessionBus().send(m_pendingReply); +} + +void TestServer::createReply(const QDBusMessage &message) +{ + message.setDelayedReply(true); + m_pendingReply = message.createReply(); +} + +void TestServer::notifyPropertyChanged(const QString& propertyName ) +{ + qDebug() << "notify Property changes" << propertyName; + + QDBusMessage signal = QDBusMessage::createSignal( + "/object/path", + "org.freedesktop.DBus.Properties", + "PropertiesChanged"); + signal << "org.pelagicore.TestServer"; + QVariantMap changedProps; + changedProps.insert(propertyName, property(qPrintable(propertyName))); + signal << changedProps; + signal << QStringList(); + QDBusConnection::sessionBus().send(signal); +} |