From 9ec14db5a9f735eb4286984f934568f089627bd7 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 25 Mar 2020 15:18:09 +0100 Subject: cmake: Document qt5_generate_repc Task-number: QTBUG-82461 Change-Id: I30b30847d5ad8dd893393095c91c51d85390d90c Reviewed-by: Leena Miettinen Reviewed-by: Alexandru Croitor --- .../doc/snippets/cmake-macros/CMakeLists.txt | 26 +++++++ .../doc/snippets/cmake-macros/main.cpp | 64 +++++++++++++++++ .../doc/snippets/cmake-macros/simpleswitch.cpp | 83 ++++++++++++++++++++++ .../doc/snippets/cmake-macros/simpleswitch.h | 69 ++++++++++++++++++ .../doc/snippets/cmake-macros/simpleswitch.rep | 7 ++ src/remoteobjects/doc/src/cmake-macros.qdoc | 54 ++++++++++++++ 6 files changed, 303 insertions(+) create mode 100644 src/remoteobjects/doc/snippets/cmake-macros/CMakeLists.txt create mode 100644 src/remoteobjects/doc/snippets/cmake-macros/main.cpp create mode 100644 src/remoteobjects/doc/snippets/cmake-macros/simpleswitch.cpp create mode 100644 src/remoteobjects/doc/snippets/cmake-macros/simpleswitch.h create mode 100644 src/remoteobjects/doc/snippets/cmake-macros/simpleswitch.rep create mode 100644 src/remoteobjects/doc/src/cmake-macros.qdoc diff --git a/src/remoteobjects/doc/snippets/cmake-macros/CMakeLists.txt b/src/remoteobjects/doc/snippets/cmake-macros/CMakeLists.txt new file mode 100644 index 0000000..42a5e28 --- /dev/null +++ b/src/remoteobjects/doc/snippets/cmake-macros/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.1.0) + +project(directconnectserver) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +if(CMAKE_VERSION VERSION_LESS "3.7.0") + set(CMAKE_INCLUDE_CURRENT_DIR ON) +endif() + + +#! [qt5_generate_repc] +find_package(Qt5 COMPONENTS RemoteObjects REQUIRED) + +set(SOURCES + main.cpp + simpleswitch.cpp +) + +qt5_generate_repc(SOURCES simpleswitch.rep SOURCE) + +add_executable(directconnectserver ${SOURCES}) +target_link_libraries(directconnectserver Qt5::RemoteObjects) +#! [qt5_generate_repc] diff --git a/src/remoteobjects/doc/snippets/cmake-macros/main.cpp b/src/remoteobjects/doc/snippets/cmake-macros/main.cpp new file mode 100644 index 0000000..18532b6 --- /dev/null +++ b/src/remoteobjects/doc/snippets/cmake-macros/main.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Ford Motor Company +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtRemoteObjects module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt 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. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "simpleswitch.h" + +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + + SimpleSwitch srcSwitch; // create simple switch + + QRemoteObjectHost srcNode(QUrl(QStringLiteral("local:replica"))); // create host node without Registry + srcNode.enableRemoting(&srcSwitch); // enable remoting/Sharing + + return a.exec(); +} diff --git a/src/remoteobjects/doc/snippets/cmake-macros/simpleswitch.cpp b/src/remoteobjects/doc/snippets/cmake-macros/simpleswitch.cpp new file mode 100644 index 0000000..a5ab3e0 --- /dev/null +++ b/src/remoteobjects/doc/snippets/cmake-macros/simpleswitch.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Ford Motor Company +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtRemoteObjects module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt 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. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "simpleswitch.h" + +// constructor +SimpleSwitch::SimpleSwitch(QObject *parent) : SimpleSwitchSimpleSource(parent) +{ + stateChangeTimer = new QTimer(this); // Initialize timer + QObject::connect(stateChangeTimer, SIGNAL(timeout()), this, SLOT(timeout_slot())); // connect timeout() signal from stateChangeTimer to timeout_slot() of simpleSwitch + stateChangeTimer->start(2000); // Start timer and set timout to 2 seconds + qDebug() << "Source Node Started"; +} + +//destructor +SimpleSwitch::~SimpleSwitch() +{ + stateChangeTimer->stop(); +} + +void SimpleSwitch::server_slot(bool clientState) +{ + qDebug() << "Replica state is " << clientState; // print switch state echoed back by client +} + +void SimpleSwitch::timeout_slot(void) +{ + // slot called on timer timeout + if (currState()) // check if current state is true, currState() is defined in repc generated rep_simpleswitch_source.h + setCurrState(false); // set state to false + else + setCurrState(true); // set state to true + qDebug() << "Source State is "< + +class SimpleSwitch +{ + PROP(bool currState=false); + SLOT(void server_slot(bool clientState)); +}; diff --git a/src/remoteobjects/doc/src/cmake-macros.qdoc b/src/remoteobjects/doc/src/cmake-macros.qdoc new file mode 100644 index 0000000..ef6eb30 --- /dev/null +++ b/src/remoteobjects/doc/src/cmake-macros.qdoc @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt 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 Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! +\page qtremoteobjects-cmake-qt5-generate-repc.html +\ingroup cmake-macros-qtremoteobjects + +\title qt5_generate_repc + +\brief Creates a C++ type from a Qt Remote Objects .rep file. + +\section1 Synopsis + +\badcode +qt5_generate_repc( rep_file output_type) +\endcode + +\section1 Description + +Creates rules for calling \l{repc} on \c{rep_file}. +\c{output_type} must be either \c{SOURCE} or \c{REPLICA}. +The paths of the generated files are added to \c{}. + +Depending on the \c{output_type} argument, the generated code will either implement +a \l{Qt Remote Objects Source} or a \l{Qt Remote Objects Replica} type in C++. + +\section1 Examples + +\snippet cmake-macros/CMakeLists.txt qt5_generate_repc +*/ -- cgit v1.2.3