summaryrefslogtreecommitdiffstats
path: root/examples/remoteobjects/cbor_python/qt_source
diff options
context:
space:
mode:
authorBrett Stottlemyer <bstottle@ford.com>2021-03-07 10:51:50 -0500
committerBrett Stottlemyer <bstottle@ford.com>2021-07-15 14:44:24 -0400
commit0ab10b008f4b713b7a58206b796668e05e80c2c6 (patch)
tree6795aadfd8e9d74d962ccd8709342dc414fd6065 /examples/remoteobjects/cbor_python/qt_source
parentd8b6dce0d2cf91e20905856aef06c77c8659da98 (diff)
Add example of reading CBOR data from pythonwip/serialization
This is currently a test harness that will expand as the CBOR functionality is prototyped. A start at changes to repc to autogenerate python code for Replica types is also included. Change-Id: I97c3ad4c62c7d747c1918f88be41fb7643bbb46d Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Michael Brasser <michael.brasser@live.com>
Diffstat (limited to 'examples/remoteobjects/cbor_python/qt_source')
-rw-r--r--examples/remoteobjects/cbor_python/qt_source/CMakeLists.txt58
-rw-r--r--examples/remoteobjects/cbor_python/qt_source/Simple.rep9
-rw-r--r--examples/remoteobjects/cbor_python/qt_source/main.cpp98
-rw-r--r--examples/remoteobjects/cbor_python/qt_source/qt_source.pro26
-rw-r--r--examples/remoteobjects/cbor_python/qt_source/simple.cpp70
-rw-r--r--examples/remoteobjects/cbor_python/qt_source/simple.h72
6 files changed, 333 insertions, 0 deletions
diff --git a/examples/remoteobjects/cbor_python/qt_source/CMakeLists.txt b/examples/remoteobjects/cbor_python/qt_source/CMakeLists.txt
new file mode 100644
index 0000000..11c31c6
--- /dev/null
+++ b/examples/remoteobjects/cbor_python/qt_source/CMakeLists.txt
@@ -0,0 +1,58 @@
+# Generated from qt_source.pro.
+
+cmake_minimum_required(VERSION 3.14)
+project(QtSource LANGUAGES CXX)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_AUTORCC ON)
+set(CMAKE_AUTOUIC ON)
+
+if(NOT DEFINED INSTALL_EXAMPLESDIR)
+ set(INSTALL_EXAMPLESDIR "examples")
+endif()
+
+set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/remoteobjects/cbor_python/qt_source")
+
+find_package(Qt6 COMPONENTS Core)
+find_package(Qt6 COMPONENTS Gui)
+find_package(Qt6 COMPONENTS RemoteObjects)
+
+qt_add_executable(QtSource
+ main.cpp
+ simple.cpp simple.h
+)
+set_target_properties(QtSource PROPERTIES
+ WIN32_EXECUTABLE FALSE
+ MACOSX_BUNDLE FALSE
+)
+target_link_libraries(QtSource PUBLIC
+ Qt::Core
+ Qt::Gui
+ Qt::RemoteObjects
+)
+
+qt6_add_repc_sources(QtSource
+ Simple.rep
+)
+
+install(TARGETS QtSource
+ RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
+ LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+)
+
+# special case begin
+add_custom_command(
+ TARGET QtSource POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
+ ${CMAKE_CURRENT_SOURCE_DIR}/../py_replica/py_replica.py
+ $<TARGET_FILE_DIR:QtSource>/../py_replica/py_replica.py
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
+ ${CMAKE_CURRENT_SOURCE_DIR}/Simple.rep
+ $<TARGET_FILE_DIR:QtSource>/Simple.rep
+ )
+install(FILES ../py_replica/py_replica.py DESTINATION "${INSTALL_EXAMPLEDIR}/../py_replica")
+install(FILES Simple.rep DESTINATION "${INSTALL_EXAMPLEDIR}")
+# special case end
diff --git a/examples/remoteobjects/cbor_python/qt_source/Simple.rep b/examples/remoteobjects/cbor_python/qt_source/Simple.rep
new file mode 100644
index 0000000..1757ae6
--- /dev/null
+++ b/examples/remoteobjects/cbor_python/qt_source/Simple.rep
@@ -0,0 +1,9 @@
+#include <QtCore>
+
+class Simple
+{
+ PROP(int i = 2);
+ PROP(float f = -1. READWRITE);
+ SIGNAL(random(int i));
+ SLOT(void reset());
+};
diff --git a/examples/remoteobjects/cbor_python/qt_source/main.cpp b/examples/remoteobjects/cbor_python/qt_source/main.cpp
new file mode 100644
index 0000000..db04ea4
--- /dev/null
+++ b/examples/remoteobjects/cbor_python/qt_source/main.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 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 <QCoreApplication>
+#include <QDebug>
+#include <QRemoteObjectHost>
+
+#include "simple.h"
+
+void SigIntHandler()
+{
+ qDebug()<<"Ctrl-C received. Quitting.";
+ qApp->quit();
+}
+#if defined(Q_OS_UNIX) || defined(Q_OS_LINUX) || defined(Q_OS_QNX)
+ #include <signal.h>
+ void unix_handler(int s)
+ {
+ if (s==SIGINT)
+ SigIntHandler();
+ }
+#elif defined(Q_OS_WIN32)
+ #include <windows.h>
+ BOOL WINAPI WinHandler(DWORD CEvent)
+ {
+ switch (CEvent)
+ {
+ case CTRL_C_EVENT:
+ SigIntHandler();
+ break;
+ }
+ return TRUE;
+ }
+#endif
+
+int main(int argc, char *argv[])
+{
+ QLoggingCategory::setFilterRules("qt.remoteobjects*=true");
+ QCoreApplication app(argc, argv);
+#if defined(Q_OS_UNIX) || defined(Q_OS_LINUX) || defined(Q_OS_QNX)
+ signal(SIGINT, &unix_handler);
+#elif defined(Q_OS_WIN32)
+ SetConsoleCtrlHandler((PHANDLER_ROUTINE)WinHandler, TRUE);
+#endif
+ QRemoteObjectHost node(QUrl(QLatin1String("tcp://127.0.0.1:5005")));
+ Simple simple;
+ simple.setF(3.14);
+ node.enableRemoting(&simple, "DifferentName");
+ Q_UNUSED(simple);
+ return app.exec();
+}
diff --git a/examples/remoteobjects/cbor_python/qt_source/qt_source.pro b/examples/remoteobjects/cbor_python/qt_source/qt_source.pro
new file mode 100644
index 0000000..16895ee
--- /dev/null
+++ b/examples/remoteobjects/cbor_python/qt_source/qt_source.pro
@@ -0,0 +1,26 @@
+QT += remoteobjects
+
+TARGET = QtSource
+CONFIG += cmdline
+CONFIG -= app_bundle
+
+REPC_SOURCE += Simple.rep
+
+DISTFILES += \
+ Simple.rep
+
+SOURCES += main.cpp \
+ simple.cpp
+
+HEADERS += simple.h
+
+OTHER_FILES += $$REPC_SOURCE
+
+repfiles.files = $$REPC_SOURCE
+repfiles.path += $$[QT_INSTALL_EXAMPLES]/remoteobjects/cbor_python/qt_source
+pythonfiles.files = py_replica/py_replica.py
+pythonfiles.path += $$[QT_INSTALL_EXAMPLES]/remoteobjects/cbor_python/py_replica
+
+target.path = $$[QT_INSTALL_EXAMPLES]/remoteobjects/cbor_python/qt_source
+
+INSTALLS += target repfiles pythonfiles
diff --git a/examples/remoteobjects/cbor_python/qt_source/simple.cpp b/examples/remoteobjects/cbor_python/qt_source/simple.cpp
new file mode 100644
index 0000000..78f7995
--- /dev/null
+++ b/examples/remoteobjects/cbor_python/qt_source/simple.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 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 "simple.h"
+
+Simple::Simple(QObject *parent) : SimpleSimpleSource(parent)
+{
+}
+
+void Simple::reset()
+{
+ setI(0);
+ m_timerId = startTimer(500);
+}
+
+void Simple::timerEvent(QTimerEvent *)
+{
+ auto count = i();
+ setI(count + 1);
+ if (count >= 3) {
+ killTimer(m_timerId);
+ }
+}
diff --git a/examples/remoteobjects/cbor_python/qt_source/simple.h b/examples/remoteobjects/cbor_python/qt_source/simple.h
new file mode 100644
index 0000000..c69934b
--- /dev/null
+++ b/examples/remoteobjects/cbor_python/qt_source/simple.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 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$
+**
+****************************************************************************/
+
+#ifndef SIMPLE_H
+#define SIMPLE_H
+
+#include "rep_Simple_source.h"
+
+class Simple : public SimpleSimpleSource
+{
+ Q_OBJECT
+public:
+ explicit Simple(QObject *parent = nullptr);
+
+signals:
+
+public slots:
+ void reset() override;
+ void timerEvent(QTimerEvent *) override;
+
+private:
+ int m_timerId;
+};
+
+#endif // SIMPLE_H