├── qtcloudmessaging.pro ├── examples ├── kaltiot │ ├── kaltiot.pro │ └── smartiot │ │ ├── main.qrc │ │ ├── doc │ │ ├── images │ │ │ └── smartiot-example.png │ │ └── src │ │ │ └── qtcloudmessaging-kaltiot-smartiot.qdoc │ │ ├── smartiot.pro │ │ ├── smartiot.h │ │ ├── main.cpp │ │ ├── qml │ │ └── main.qml │ │ └── smartiot.cpp ├── firebase │ ├── firebase.pro │ └── pushnotification │ │ ├── main.qrc │ │ ├── android-sources │ │ ├── google-services.json │ │ ├── res │ │ │ └── drawable │ │ │ │ └── icon.png │ │ ├── build.gradle │ │ ├── src │ │ │ └── org │ │ │ │ └── qtproject │ │ │ │ └── example │ │ │ │ └── pushnotification │ │ │ │ └── NotificationActivity.java │ │ └── AndroidManifest.xml │ │ ├── doc │ │ ├── images │ │ │ └── pushnotification-example.png │ │ └── src │ │ │ └── qtcloudmessaging-firebase-pushnotification.qdoc │ │ ├── pushnotification.pro │ │ ├── pushnotification.h │ │ ├── main.cpp │ │ ├── qml │ │ └── main.qml │ │ └── pushnotification.cpp ├── examples.pro └── README.md ├── .qmake.conf ├── .gitignore ├── src ├── src.pro ├── cloudmessaging │ ├── doc │ │ ├── README.md │ │ └── qtcloudmessaging.qdocconf │ ├── cloudmessaging.pro │ ├── qtcloudmessagingglobal.h │ ├── qcloudmessagingclient_p.h │ ├── qcloudmessagingprovider_p.h │ ├── qcloudmessaging_p.h │ ├── qcloudmessagingrestapi_p.h │ ├── qcloudmessagingclient.h │ ├── qcloudmessaging.h │ ├── qcloudmessagingrestapi.h │ ├── qcloudmessagingprovider.h │ ├── qcloudmessagingclient.cpp │ └── qcloudmessaging.cpp ├── cloudmessagingembeddedkaltiot │ ├── cloudmessagingembeddedkaltiot.pro │ ├── qcloudmessagingembeddedkaltiotprovider_p.h │ ├── qcloudmessagingembeddedkaltiotclient_p.h │ ├── qcloudmessagingembeddedkaltiotclient.h │ ├── qcloudmessagingembeddedkaltiotprovider.h │ ├── qcloudmessagingembeddedkaltiotrest.cpp │ ├── qcloudmessagingembeddedkaltiotrest.h │ ├── android │ │ └── ks_gw_client_android.h │ └── qcloudmessagingembeddedkaltiotclient.cpp └── cloudmessagingfirebase │ ├── cloudmessagingfirebase.pro │ ├── qcloudmessagingfirebaseprovider_p.h │ ├── qcloudmessagingfirebaseclient_p.h │ ├── qcloudmessagingfirebaserest.h │ ├── qcloudmessagingfirebaseclient.h │ ├── qcloudmessagingfirebaseprovider.h │ ├── qcloudmessagingfirebaserest.cpp │ ├── qcloudmessagingfirebaseprovider.cpp │ └── qcloudmessagingfirebaseclient.cpp ├── tests ├── tests.pro └── tst_qcloudmessaging.cpp ├── sync.profile ├── dist └── changes-1.0.0 └── README.md /qtcloudmessaging.pro: -------------------------------------------------------------------------------- 1 | load(qt_parts) 2 | -------------------------------------------------------------------------------- /examples/kaltiot/kaltiot.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | SUBDIRS += smartiot 3 | -------------------------------------------------------------------------------- /examples/firebase/firebase.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | SUBDIRS += pushnotification 3 | -------------------------------------------------------------------------------- /.qmake.conf: -------------------------------------------------------------------------------- 1 | load(qt_build_config) 2 | 3 | MODULE_VERSION = 5.11.0 4 | CMAKE_MODULE_TESTS = - 5 | -------------------------------------------------------------------------------- /examples/kaltiot/smartiot/main.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | qml/main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | build* 3 | *.pro.* 4 | .qmake.stash 5 | *.autosave 6 | Makefile.* 7 | /mkspecs* 8 | .moc/ 9 | .pch/ 10 | .obj/ 11 | -------------------------------------------------------------------------------- /examples/firebase/pushnotification/main.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | qml/main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /examples/kaltiot/smartiot/doc/images/smartiot-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtcloudmessaging/master/examples/kaltiot/smartiot/doc/images/smartiot-example.png -------------------------------------------------------------------------------- /examples/firebase/pushnotification/android-sources/google-services.json: -------------------------------------------------------------------------------- 1 | # YOU SHOULD REPLACE THIS WITH YOUR OWN GOOGLE-SERVICES.JSON FILE! 2 | # See https://firebase.google.com/docs/cpp/setup 3 | -------------------------------------------------------------------------------- /examples/firebase/pushnotification/android-sources/res/drawable/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtcloudmessaging/master/examples/firebase/pushnotification/android-sources/res/drawable/icon.png -------------------------------------------------------------------------------- /examples/firebase/pushnotification/doc/images/pushnotification-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtcloudmessaging/master/examples/firebase/pushnotification/doc/images/pushnotification-example.png -------------------------------------------------------------------------------- /src/src.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | SUBDIRS = cloudmessaging 3 | 4 | embedded-kaltiot { SUBDIRS += cloudmessagingembeddedkaltiot } 5 | firebase { SUBDIRS += cloudmessagingfirebase } 6 | 7 | DISTFILES += \ 8 | ../README.md 9 | -------------------------------------------------------------------------------- /examples/examples.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | 3 | # Example of Firebase (Cloud Messaging) Push Notification 4 | firebase: SUBDIRS += firebase 5 | 6 | # Example of Kaltiot (SmartIoT) Push Notification 7 | embedded-kaltiot: SUBDIRS += kaltiot 8 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | QT CLOUD MESSAGING API EXAMPLES ARE IN GITHUB: 2 | 3 | Cloud messaging API examples are in the following address in github: 4 | https://github.com/snowgrains/qtcloudmessaging-examples 5 | 6 | See more instructions from the README.md 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/tests.pro: -------------------------------------------------------------------------------- 1 | QT += testlib cloudmessaging 2 | QT -= gui 3 | 4 | TARGET = tst_qcloudmessaging 5 | CONFIG += console 6 | CONFIG -= app_bundle 7 | 8 | TEMPLATE = app 9 | 10 | DEFINES += QT_DEPRECATED_WARNINGS 11 | 12 | SOURCES += \ 13 | tst_qcloudmessaging.cpp 14 | 15 | DEFINES += SRCDIR=\\\"$$PWD/\\\" 16 | -------------------------------------------------------------------------------- /src/cloudmessaging/doc/README.md: -------------------------------------------------------------------------------- 1 | QT CLOUD MESSAGING DOC GENERATION: 2 | 3 | define following exports in command prompt / terminal: 4 | BUILDDIR="." 5 | QT_VER="5.11" 6 | QT_VERSION="5.11" 7 | QT_VERSION_TAG="5.11" 8 | QT_INSTALL_DOCS="/Qt/Docs/Qt-5.9.2" 9 | 10 | Then run command: 11 | /Qt/5.9.2//bin/qdoc qtcloudmessaging.qdocconf 12 | -------------------------------------------------------------------------------- /sync.profile: -------------------------------------------------------------------------------- 1 | %modules = ( # path to module name map 2 | "QtCloudMessaging" => "$basedir/src/cloudmessaging", 3 | "QtCloudMessagingEmbeddedKaltiot" => "$basedir/src/cloudmessagingembeddedkaltiot", 4 | "QtCloudMessagingFirebase" => "$basedir/src/cloudmessagingfirebase" 5 | ); 6 | %moduleheaders = ( # restrict the module headers to those found in relative path 7 | ); 8 | -------------------------------------------------------------------------------- /examples/kaltiot/smartiot/smartiot.pro: -------------------------------------------------------------------------------- 1 | QT += quick cloudmessagingembeddedkaltiot 2 | 3 | SOURCES += \ 4 | main.cpp \ 5 | smartiot.cpp 6 | 7 | OTHER_FILES += \ 8 | qml/main.qml 9 | 10 | RESOURCES += \ 11 | main.qrc 12 | 13 | HEADERS += \ 14 | smartiot.h 15 | 16 | KALTIOT_SDK = $$(KALTIOT_SDK) 17 | !isEmpty(KALTIOT_SDK): INCLUDEPATH += $${KALTIOT_SDK}/src 18 | 19 | target.path = $$[QT_INSTALL_EXAMPLES]/kaltiot/smartiot 20 | INSTALLS += target 21 | -------------------------------------------------------------------------------- /dist/changes-1.0.0: -------------------------------------------------------------------------------- 1 | Qt Cloud Messaging 1.0 2 | 3 | Qt Cloud Messaging 1.0 is supported from Qt 5.x onwards. 4 | 5 | For more details on the features and fixes, refer to the online documentation 6 | included in this distribution. The documentation is also available online: 7 | 8 | http://doc.qt.io/QtCloudMessaging 9 | 10 | General Improvements 11 | -------------------- 12 | Introducing new component for Qt 13 | 14 | API changes (source break) 15 | -------------------------- 16 | 17 | 18 | New features 19 | ------------ 20 | - Introducing new component for Qt 21 | 22 | Fixed issues 23 | ------------ 24 | -------------------------------------------------------------------------------- /src/cloudmessaging/cloudmessaging.pro: -------------------------------------------------------------------------------- 1 | TARGET = QtCloudMessaging 2 | 3 | QT = core network 4 | 5 | QMAKE_DOCS = $$PWD/doc/qtcloudmessaging.qdocconf 6 | 7 | HEADERS += \ 8 | $$PWD/qcloudmessaging.h \ 9 | $$PWD/qcloudmessagingclient.h \ 10 | $$PWD/qcloudmessagingprovider.h \ 11 | $$PWD/qtcloudmessagingglobal.h \ 12 | $$PWD/qcloudmessaging_p.h \ 13 | $$PWD/qcloudmessagingclient_p.h \ 14 | $$PWD/qcloudmessagingprovider_p.h \ 15 | $$PWD/qcloudmessagingrestapi_p.h \ 16 | $$PWD/qcloudmessagingrestapi.h 17 | 18 | SOURCES += \ 19 | $$PWD/qcloudmessaging.cpp \ 20 | $$PWD/qcloudmessagingclient.cpp \ 21 | $$PWD/qcloudmessagingprovider.cpp \ 22 | $$PWD/qcloudmessagingrestapi.cpp 23 | 24 | load(qt_module) 25 | -------------------------------------------------------------------------------- /examples/firebase/pushnotification/pushnotification.pro: -------------------------------------------------------------------------------- 1 | QT += quick cloudmessagingfirebase 2 | 3 | ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android-sources 4 | 5 | SOURCES += \ 6 | main.cpp \ 7 | pushnotification.cpp 8 | 9 | OTHER_FILES += \ 10 | qml/main.qml \ 11 | android-sources/src/org/qtproject/example/pushnotification/NotificationActivity.java \ 12 | android-sources/AndroidManifest.xml \ 13 | android-sources/build.gradle \ 14 | android-sources/google-services.json \ 15 | android-sources/res/drawable/icon.png 16 | 17 | RESOURCES += \ 18 | main.qrc 19 | 20 | HEADERS += \ 21 | pushnotification.h 22 | 23 | GOOGLE_FIREBASE_SDK = $$(GOOGLE_FIREBASE_SDK) 24 | !isEmpty(GOOGLE_FIREBASE_SDK): INCLUDEPATH += $${GOOGLE_FIREBASE_SDK}/include 25 | 26 | target.path = $$[QT_INSTALL_EXAMPLES]/firebase/pushnotification 27 | INSTALLS += target 28 | -------------------------------------------------------------------------------- /src/cloudmessagingembeddedkaltiot/cloudmessagingembeddedkaltiot.pro: -------------------------------------------------------------------------------- 1 | TARGET = QtCloudMessagingEmbeddedKaltiot 2 | QT = core cloudmessaging 3 | 4 | # Check for KALTIOT_SDK environment 5 | ENV_KALTIOT_SDK = $$(KALTIOT_SDK) 6 | 7 | # Or define KALTIOT_SDK path here 8 | KALTIOT_SDK = 9 | 10 | isEmpty(ENV_KALTIOT_SDK) { 11 | isEmpty(KALTIOT_SDK) { 12 | message("KALTIOT_SDK" environment variable or define in radardemo.pro file not detected!) 13 | } 14 | } 15 | 16 | INCLUDEPATH += $$(KALTIOT_SDK) 17 | INCLUDEPATH += $$(KALTIOT_SDK)/src 18 | 19 | HEADERS += \ 20 | qcloudmessagingembeddedkaltiotclient.h \ 21 | qcloudmessagingembeddedkaltiotprovider.h \ 22 | qcloudmessagingembeddedkaltiotclient_p.h \ 23 | qcloudmessagingembeddedkaltiotprovider_p.h \ 24 | qcloudmessagingembeddedkaltiotrest.h 25 | 26 | SOURCES += \ 27 | qcloudmessagingembeddedkaltiotclient.cpp \ 28 | qcloudmessagingembeddedkaltiotprovider.cpp \ 29 | qcloudmessagingembeddedkaltiotrest.cpp 30 | 31 | android { 32 | DEFINES += ANDROID_OS 33 | QT += androidextras 34 | HEADERS += \ 35 | $$PWD/android/ks_gw_client_android.h 36 | } else { 37 | 38 | DEFINES += EMBEDDED_AND_DESKTOP_OS 39 | HEADERS += \ 40 | $$(KALTIOT_SDK)/src/ks_gw_client.h 41 | 42 | LIBS += $$(KALTIOT_SDK)/libks_gw_client.a 43 | } 44 | 45 | load(qt_module) 46 | 47 | DISTFILES += \ 48 | README.md 49 | -------------------------------------------------------------------------------- /src/cloudmessaging/qtcloudmessagingglobal.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #ifndef QTCLOUDMESSAGINGGLOBAL_H 30 | #define QTCLOUDMESSAGINGGLOBAL_H 31 | #include 32 | 33 | QT_BEGIN_NAMESPACE 34 | 35 | #ifndef QT_STATIC 36 | # if defined(QT_BUILD_CLOUDMESSAGING_LIB) 37 | # define Q_CLOUDMESSAGING_EXPORT Q_DECL_EXPORT 38 | # else 39 | # define Q_CLOUDMESSAGING_EXPORT Q_DECL_IMPORT 40 | # endif 41 | #else 42 | # define Q_CLOUDMESSAGING_EXPORT 43 | #endif 44 | 45 | QT_END_NAMESPACE 46 | 47 | #endif // QTCLOUDMESSAGINGGLOBAL_H 48 | -------------------------------------------------------------------------------- /src/cloudmessagingfirebase/cloudmessagingfirebase.pro: -------------------------------------------------------------------------------- 1 | TARGET = QtCloudMessagingFirebase 2 | QT = core cloudmessaging 3 | CONFIG += static 4 | HEADERS += \ 5 | qcloudmessagingfirebaseclient.h \ 6 | qcloudmessagingfirebaseprovider.h \ 7 | qcloudmessagingfirebaseclient_p.h \ 8 | qcloudmessagingfirebaseprovider_p.h \ 9 | qcloudmessagingfirebaserest.h 10 | 11 | SOURCES += \ 12 | $$PWD/qcloudmessagingfirebaseclient.cpp \ 13 | $$PWD/qcloudmessagingfirebaseprovider.cpp \ 14 | qcloudmessagingfirebaserest.cpp 15 | 16 | # Check for GOOGLE_FIREBASE_SDK environment variable 17 | ENV_GOOGLE_FIREBASE_SDK = $$(GOOGLE_FIREBASE_SDK) 18 | 19 | # Or define GOOGLE_FIREBASE_SDK path here 20 | GOOGLE_FIREBASE_SDK = 21 | 22 | isEmpty(ENV_GOOGLE_FIREBASE_SDK) { 23 | isEmpty(GOOGLE_FIREBASE_SDK) { 24 | message("GOOGLE_FIREBASE_SDK" environment variable not detected!) 25 | } 26 | } 27 | 28 | INCLUDEPATH += $$(GOOGLE_FIREBASE_SDK) 29 | INCLUDEPATH += $$(GOOGLE_FIREBASE_SDK)/include 30 | 31 | android { 32 | QT += androidextras 33 | equals(ANDROID_TARGET_ARCH, x86) { 34 | LIBS += $$(GOOGLE_FIREBASE_SDK)/libs/android/x86/gnustl/libmessaging.a 35 | LIBS += $$(GOOGLE_FIREBASE_SDK)/libs/android/x86/gnustl/libapp.a 36 | } else { 37 | LIBS += $$(GOOGLE_FIREBASE_SDK)/libs/android/armeabi-v7a/gnustl/libmessaging.a 38 | LIBS += $$(GOOGLE_FIREBASE_SDK)/libs/android/armeabi-v7a/gnustl/libapp.a 39 | } 40 | } else: macos { 41 | LIBS += -F$$(GOOGLE_FIREBASE_SDK)/frameworks/darwin \ 42 | -framework firebase \ 43 | -framework firebase_messaging 44 | } else: ios { 45 | LIBS += -F$$(GOOGLE_FIREBASE_SDK)/frameworks/ios/universal \ 46 | -framework firebase_messaging \ 47 | -framework firebase \ 48 | -framework Foundation \ 49 | -framework UserNotifications \ 50 | -framework UIKit \ 51 | -framework CoreGraphics 52 | } 53 | 54 | load(qt_module) 55 | -------------------------------------------------------------------------------- /tests/tst_qcloudmessaging.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #include 30 | #include 31 | 32 | class QCloudmessaging : public QObject 33 | { 34 | Q_OBJECT 35 | 36 | public: 37 | QCloudmessaging(); 38 | 39 | private Q_SLOTS: 40 | void initTestCase(); 41 | void cleanupTestCase(); 42 | void testCase1(); 43 | }; 44 | 45 | QCloudmessaging::QCloudmessaging() 46 | { 47 | } 48 | 49 | void QCloudmessaging::initTestCase() 50 | { 51 | } 52 | 53 | void QCloudmessaging::cleanupTestCase() 54 | { 55 | } 56 | 57 | void QCloudmessaging::testCase1() 58 | { 59 | } 60 | 61 | QTEST_APPLESS_MAIN(QCloudmessaging) 62 | 63 | #include "tst_qcloudmessaging.moc" 64 | -------------------------------------------------------------------------------- /src/cloudmessaging/doc/qtcloudmessaging.qdocconf: -------------------------------------------------------------------------------- 1 | include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf) 2 | 3 | 4 | project = QtCloudMessaging 5 | description = Qt Cloud Messaging Documentation 6 | version = $QT_VERSION 7 | 8 | qhp.projects = QtCloudMessaging 9 | 10 | qhp.QtCloudMessaging.file = QtCloudMessaging.qhp 11 | qhp.QtCloudMessaging.namespace = org.qt-project.qtcloudmessaging.$QT_VERSION_TAG 12 | qhp.QtCloudMessaging.virtualFolder = qtcloudmessaging 13 | qhp.QtCloudMessaging.indexTitle = Qt CloudMessaging 14 | qhp.QtCloudMessaging.indexRoot = 15 | 16 | qhp.QtCloudMessaging.filterAttributes = qcloudmessaging $QT_VERSION qtrefdoc 17 | qhp.QtCloudMessaging.customFilters.Qt.name = QtCloudMessaging $QT_VERSION 18 | qhp.QtCloudMessaging.customFilters.Qt.filterAttributes = qcloudmessaging $QT_VERSION 19 | 20 | qhp.QtCloudMessaging.subprojects = classes 21 | qhp.QtCloudMessaging.subprojects.classes.title = C++ Classes 22 | qhp.QtCloudMessaging.subprojects.classes.indexTitle = Qt CloudMessaging C++ Classes 23 | qhp.QtCloudMessaging.subprojects.classes.selectors = class fake:headerfile 24 | qhp.QtCloudMessaging.subprojects.classes.sortPages = true 25 | 26 | # The outputdir variable specifies the directory 27 | # where QDoc will put the generated documentation. 28 | 29 | outputdir = html 30 | 31 | # The headerdirs variable specifies the directories 32 | # containing the header files associated 33 | # with the .cpp source files used in the documentation. 34 | 35 | headerdirs += .. 36 | 37 | # The sourcedirs variable specifies the 38 | # directories containing the .cpp or .qdoc 39 | # files used in the documentation. 40 | 41 | sourcedirs += .. 42 | 43 | # The exampledirs variable specifies the directories containing 44 | # the source code of the example files. 45 | 46 | #exampledirs += . 47 | 48 | # The imagedirs variable specifies the 49 | # directories containing the images used in the documentation. 50 | 51 | #imagedirs += ./images 52 | -------------------------------------------------------------------------------- /examples/firebase/pushnotification/android-sources/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | google() 4 | jcenter() 5 | } 6 | 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:3.0.1' 9 | classpath 'com.google.gms:google-services:3.2.0' 10 | } 11 | } 12 | 13 | repositories { 14 | google() 15 | jcenter() 16 | maven { 17 | url "https://maven.google.com" 18 | } 19 | flatDir { 20 | dirs "$System.env.GOOGLE_FIREBASE_SDK" + "/libs/android" 21 | } 22 | } 23 | 24 | apply plugin: 'com.android.application' 25 | 26 | dependencies { 27 | compile fileTree(dir: 'libs', include: ['*.jar']) 28 | compile 'com.google.android.gms:play-services-base:12.0.1' 29 | compile 'com.google.firebase:firebase-messaging:12.0.1' 30 | compile 'com.google.firebase.messaging.cpp:firebase_messaging_cpp@aar' 31 | } 32 | 33 | apply plugin: 'com.google.gms.google-services' 34 | 35 | android { 36 | /******************************************************* 37 | * The following variables: 38 | * - androidBuildToolsVersion, 39 | * - androidCompileSdkVersion 40 | * - qt5AndroidDir - holds the path to qt android files 41 | * needed to build any Qt application 42 | * on Android. 43 | * 44 | * are defined in gradle.properties file. This file is 45 | * updated by QtCreator and androiddeployqt tools. 46 | * Changing them manually might break the compilation! 47 | *******************************************************/ 48 | 49 | compileSdkVersion androidCompileSdkVersion.toInteger() 50 | 51 | buildToolsVersion androidBuildToolsVersion 52 | 53 | sourceSets { 54 | main { 55 | manifest.srcFile 'AndroidManifest.xml' 56 | java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java'] 57 | aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl'] 58 | res.srcDirs = [qt5AndroidDir + '/res', 'res'] 59 | resources.srcDirs = ['src'] 60 | renderscript.srcDirs = ['src'] 61 | assets.srcDirs = ['assets'] 62 | jniLibs.srcDirs = ['libs'] 63 | } 64 | } 65 | 66 | lintOptions { 67 | abortOnError false 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/cloudmessaging/qcloudmessagingclient_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #ifndef QCLOUDMESSAGINGCLIENT_P_H 30 | #define QCLOUDMESSAGINGCLIENT_P_H 31 | // 32 | // W A R N I N G 33 | // ------------- 34 | // 35 | // This file is not part of the Qt API. It exists purely as an 36 | // implementation detail. This header file may change from version to 37 | // version without notice, or even be removed. 38 | // 39 | // We mean it. 40 | // 41 | 42 | #include 43 | #include 44 | 45 | QT_BEGIN_NAMESPACE 46 | 47 | 48 | class QCloudMessagingClient; 49 | 50 | class QCloudMessagingClientPrivate 51 | { 52 | public: 53 | QCloudMessagingClientPrivate() 54 | : m_clientState(0) 55 | { 56 | } 57 | 58 | ~QCloudMessagingClientPrivate() = default; 59 | 60 | QString m_clientId; 61 | QString m_providerId; 62 | int m_clientState; 63 | QVariantMap m_client_parameters; 64 | 65 | }; 66 | 67 | QT_END_NAMESPACE 68 | 69 | #endif // QCLOUDMESSAGINGCLIENT_P_H 70 | -------------------------------------------------------------------------------- /src/cloudmessagingfirebase/qcloudmessagingfirebaseprovider_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #ifndef QCLOUDMESSAGINGFIREBASEPROVIDER_P_H 30 | #define QCLOUDMESSAGINGFIREBASEPROVIDER_P_H 31 | 32 | // 33 | // W A R N I N G 34 | // ------------- 35 | // 36 | // This file is not part of the Qt API. It exists purely as an 37 | // implementation detail. This header file may change from version to 38 | // version without notice, or even be removed. 39 | // 40 | // We mean it. 41 | // 42 | 43 | #include 44 | #include "qcloudmessagingfirebaseprovider.h" 45 | #include "qcloudmessagingfirebaserest.h" 46 | 47 | QT_BEGIN_NAMESPACE 48 | 49 | class QCloudMessaging; 50 | 51 | class QCloudMessagingFirebaseProviderPrivate 52 | { 53 | public: 54 | QCloudMessagingFirebaseProviderPrivate() 55 | { 56 | } 57 | 58 | ~QCloudMessagingFirebaseProviderPrivate() = default; 59 | 60 | QStringList m_channels; 61 | QString m_key; 62 | FirebaseRestServer m_restInterface; 63 | }; 64 | 65 | QT_END_NAMESPACE 66 | 67 | #endif // QCLOUDMESSAGINGFIREBASEPROVIDER_P_H 68 | -------------------------------------------------------------------------------- /src/cloudmessaging/qcloudmessagingprovider_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #ifndef QCLOUDMESSAGINGCLIENT_P_H 30 | #define QCLOUDMESSAGINGCLIENT_P_H 31 | // 32 | // W A R N I N G 33 | // ------------- 34 | // 35 | // This file is not part of the Qt API. It exists purely as an 36 | // implementation detail. This header file may change from version to 37 | // version without notice, or even be removed. 38 | // 39 | // We mean it. 40 | // 41 | 42 | #include 43 | #include 44 | #include 45 | 46 | QT_BEGIN_NAMESPACE 47 | 48 | class QCloudMessagingClient; 49 | class QCloudMessagingProvider; 50 | 51 | class QCloudMessagingProviderPrivate 52 | { 53 | public: 54 | QCloudMessagingProviderPrivate() 55 | : m_serviceState(0) 56 | { 57 | } 58 | 59 | ~QCloudMessagingProviderPrivate() = default; 60 | 61 | QString m_providerId; 62 | int m_serviceState; 63 | 64 | QVariantMap m_provider_parameters; 65 | QMap m_QtCloudMessagingClients; 66 | 67 | }; 68 | 69 | QT_END_NAMESPACE 70 | 71 | #endif // QCLOUDMESSAGINGCLIENT_P_H 72 | -------------------------------------------------------------------------------- /src/cloudmessagingfirebase/qcloudmessagingfirebaseclient_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #ifndef QCLOUDMESSAGINGFIREBASECLIENT_P_H 30 | #define QCLOUDMESSAGINGFIREBASECLIENT_P_H 31 | 32 | // 33 | // W A R N I N G 34 | // ------------- 35 | // 36 | // This file is not part of the Qt API. It exists purely as an 37 | // implementation detail. This header file may change from version to 38 | // version without notice, or even be removed. 39 | // 40 | // We mean it. 41 | // 42 | 43 | #include 44 | #include "qcloudmessagingfirebaseclient.h" 45 | #include "qcloudmessagingfirebaserest.h" 46 | #include "firebase/app.h" 47 | #include "firebase/messaging.h" 48 | #include "firebase/util.h" 49 | 50 | 51 | QT_BEGIN_NAMESPACE 52 | 53 | class QCloudMessaging; 54 | 55 | class QCloudMessagingFirebaseClientPrivate 56 | { 57 | public: 58 | QCloudMessagingFirebaseClientPrivate() 59 | { 60 | } 61 | 62 | ~QCloudMessagingFirebaseClientPrivate() = default; 63 | 64 | QString m_uuid; 65 | QString m_token; 66 | 67 | ::firebase::App *m_firebaseApp; 68 | ::firebase::ModuleInitializer m_firebase_initializer; 69 | ::firebase::messaging::Message m_last_firebase_message; 70 | 71 | }; 72 | 73 | QT_END_NAMESPACE 74 | 75 | #endif // QCLOUDMESSAGINGFIREBASECLIENT_P_H 76 | -------------------------------------------------------------------------------- /src/cloudmessaging/qcloudmessaging_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #ifndef QCLOUDMESSAGING_P_H 30 | #define QCLOUDMESSAGING_P_H 31 | // 32 | // W A R N I N G 33 | // ------------- 34 | // 35 | // This file is not part of the Qt API. It exists purely as an 36 | // implementation detail. This header file may change from version to 37 | // version without notice, or even be removed. 38 | // 39 | // We mean it. 40 | // 41 | #include 42 | #include 43 | #include 44 | 45 | QT_BEGIN_NAMESPACE 46 | 47 | class QCloudMessagingProvider; 48 | 49 | class QCloudMessagingPrivate 50 | { 51 | 52 | public: 53 | QCloudMessagingPrivate() 54 | : m_serviceState(0) 55 | { 56 | } 57 | 58 | ~QCloudMessagingPrivate() 59 | { 60 | m_serviceState = 0; 61 | 62 | // To verify that all providers and clients are removed 63 | // without memory leaks 64 | QMapIterator i(m_cloudProviders); 65 | while (i.hasNext()) { 66 | i.next(); 67 | m_cloudProviders[i.key()]->deregisterProvider(); 68 | m_cloudProviders.remove(i.key()); 69 | } 70 | } 71 | 72 | int m_serviceState; 73 | QMap m_cloudProviders; 74 | 75 | }; 76 | 77 | QT_END_NAMESPACE 78 | 79 | #endif // QCLOUDMESSAGING_P_H 80 | -------------------------------------------------------------------------------- /src/cloudmessagingfirebase/qcloudmessagingfirebaserest.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | #ifndef QCLOUDMESSAGINGFIREBASEREST_H 29 | #define QCLOUDMESSAGINGFIREBASEREST_H 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | QT_BEGIN_NAMESPACE 37 | 38 | class FirebaseRestServer : public QCloudMessagingRestApi 39 | { 40 | Q_OBJECT 41 | public: 42 | enum FirebaseRESTRequests { 43 | REQ_NO_REQ, 44 | REQ_GET_DEVICES_BY_CUSTOMER_ID, 45 | REQ_GET_ALL_DEVICES, 46 | REQ_SEND_DATA_TO_DEVICE, 47 | REQ_SEND_BROADCAST_DATA_TO_CHANNEL, 48 | REQ_GET_DEVICE_INFO 49 | }; 50 | Q_ENUM(FirebaseRESTRequests) 51 | 52 | void setAuthKey(const QString &key) 53 | { 54 | m_auth_key = key; 55 | } 56 | 57 | // Response function 58 | void xmlHttpRequestReply(QNetworkReply *reply); 59 | 60 | bool sendToDevice(const QString &token, const QByteArray &data); 61 | bool sendBroadcast(const QString &channel, const QByteArray &data); 62 | 63 | Q_SIGNALS: 64 | void xmlHttpRequestReplyData(const QByteArray &data); 65 | 66 | private: 67 | QString m_auth_key; 68 | }; 69 | 70 | QT_END_NAMESPACE 71 | 72 | #endif // QCLOUDMESSAGINGFIREBASEREST_H 73 | -------------------------------------------------------------------------------- /src/cloudmessagingembeddedkaltiot/qcloudmessagingembeddedkaltiotprovider_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #ifndef QCLOUDMESSAGINGEMBEDDEDKALTIOTPROVIDER_P_H 30 | #define QCLOUDMESSAGINGEMBEDDEDKALTIOTPROVIDER_P_H 31 | 32 | // 33 | // W A R N I N G 34 | // ------------- 35 | // 36 | // This file is not part of the Qt API. It exists purely as an 37 | // implementation detail. This header file may change from version to 38 | // version without notice, or even be removed. 39 | // 40 | // We mean it. 41 | // 42 | #include 43 | #include 44 | 45 | #include 46 | 47 | #ifndef ANDROID_OS 48 | #include "ks_gw_client.h" 49 | #else 50 | #include "ks_gw_client_android.h" 51 | #endif 52 | 53 | QT_BEGIN_NAMESPACE 54 | 55 | class QCloudMessaging; 56 | 57 | class QCloudMessagingEmbeddedKaltiotProviderPrivate 58 | { 59 | public: 60 | QCloudMessagingEmbeddedKaltiotProviderPrivate() 61 | { 62 | } 63 | 64 | ~QCloudMessagingEmbeddedKaltiotProviderPrivate() = default; 65 | 66 | QStringList m_channels; 67 | QString m_serviceID; 68 | QString m_key; 69 | 70 | QCloudMessagingEmbeddedKaltiotRest m_restInterface; 71 | ks_gw_client_instance_t *m_kaltiot_engine_instance; 72 | 73 | }; 74 | 75 | QT_END_NAMESPACE 76 | 77 | #endif // QCLOUDMESSAGINGEMBEDDEDKALTIOTPROVIDER_P_H 78 | -------------------------------------------------------------------------------- /src/cloudmessagingembeddedkaltiot/qcloudmessagingembeddedkaltiotclient_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #ifndef QCLOUDMESSAGINGCLIENT_P_H 30 | #define QCLOUDMESSAGINGCLIENT_P_H 31 | // 32 | // W A R N I N G 33 | // ------------- 34 | // 35 | // This file is not part of the Qt API. It exists purely as an 36 | // implementation detail. This header file may change from version to 37 | // version without notice, or even be removed. 38 | // 39 | // We mean it. 40 | // 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | #ifndef ANDROID_OS 49 | #include "ks_gw_client.h" 50 | #else 51 | #include "ks_gw_client_android.h" 52 | #endif 53 | 54 | QT_BEGIN_NAMESPACE 55 | 56 | class QCloudMessaging; 57 | class QCloudMessagingEmbeddedKaltiotClient; 58 | 59 | class QCloudMessagingEmbeddedKaltiotClientPrivate 60 | { 61 | public: 62 | QCloudMessagingEmbeddedKaltiotClientPrivate() 63 | { 64 | m_running = false; 65 | } 66 | 67 | ~QCloudMessagingEmbeddedKaltiotClientPrivate() = default; 68 | 69 | bool m_running; 70 | QString m_uuid; 71 | QString m_address; 72 | QString m_version; 73 | QString m_customer_id; 74 | QStringList m_channels; 75 | QString m_rid; 76 | QSettings m_client_settings; 77 | QThread m_clientThread; 78 | QTimer m_threadTimer; 79 | ks_gw_client_instance_t m_kaltiot_client_instance; 80 | QString daemonIpcPath; 81 | }; 82 | 83 | QT_END_NAMESPACE 84 | 85 | #endif // QCLOUDMESSAGINGCLIENT_P_H 86 | -------------------------------------------------------------------------------- /examples/firebase/pushnotification/doc/src/qtcloudmessaging-firebase-pushnotification.qdoc: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2018 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the documentation of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:FDL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** GNU Free Documentation License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Free 19 | ** Documentation License version 1.3 as published by the Free Software 20 | ** Foundation and appearing in the file included in the packaging of 21 | ** this file. Please review the following information to ensure 22 | ** the GNU Free Documentation License version 1.3 requirements 23 | ** will be met: https://www.gnu.org/licenses/fdl-1.3.html. 24 | ** $QT_END_LICENSE$ 25 | ** 26 | ****************************************************************************/ 27 | 28 | /*! 29 | \example firebase/pushnotification 30 | \title Firebase Push Notification Example 31 | \ingroup examples-qtcloudmessaging 32 | \brief Demonstrates Firebase Cloud Messaging support with Qt. 33 | 34 | \image pushnotification-example.png Screenshot of the example 35 | 36 | \e {Firebase Cloud Messaging (FCM)} is a messaging solution. It reliably 37 | delivers messages via the \e FCM servers. Using \e FCM, you can send 38 | notification messages to notify a client app that a new message is available 39 | to sync. To learn more, visit \l 40 | {https://firebase.google.com/docs/cloud-messaging}. 41 | 42 | This example demonstrates receiving push notifications from the \e {Firebase 43 | Console}, and then displays the content on the screen in JSON format. You 44 | can send push notifications to devices running this example by using the 45 | notifications composer in the \e {Firebase Console}. The fields such as \e 46 | message-text and \e custom-data are sent to this application in a payload 47 | composed of key/value pairs. 48 | 49 | To use this example, the user must install \e {Firebase SDK} to their 50 | environment. See https://firebase.google.com/docs/android/setup 51 | \note Set environment variable \e GOOGLE_FIREBASE_SDK to the root directory 52 | of \e {Firebase C++ SDK}. 53 | \note Download the registered \c google-service.json from the \e {Firebase 54 | Console} and save it as \c android-sources/google-services.json, replacing 55 | the sample file. 56 | 57 | \include examples-run.qdocinc 58 | */ 59 | -------------------------------------------------------------------------------- /src/cloudmessaging/qcloudmessagingrestapi_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #ifndef QTCLOUDMESSAGINGRESTAPI_P_H 30 | #define QTCLOUDMESSAGINGRESTAPI_P_H 31 | // 32 | // W A R N I N G 33 | // ------------- 34 | // 35 | // This file is not part of the Qt API. It exists purely as an 36 | // implementation detail. This header file may change from version to 37 | // version without notice, or even be removed. 38 | // 39 | // We mean it. 40 | // 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | #ifndef QT_NO_BEARERMANAGEMENT 48 | #include 49 | #endif 50 | 51 | QT_BEGIN_NAMESPACE 52 | 53 | class QCloudMessagingNetworkMessage; 54 | 55 | class QCloudMessagingRestApiPrivate 56 | { 57 | public: 58 | QCloudMessagingRestApiPrivate() 59 | { 60 | m_online_state = false; 61 | m_server_message_timer = 800; 62 | m_server_wait_for_response_counter = 10; 63 | m_server_message_retry_count = 1; 64 | } 65 | 66 | ~QCloudMessagingRestApiPrivate() = default; 67 | 68 | void setServerTimers(int messageTimer, int waitForResponseCounter, int messageRetryCount) 69 | { 70 | m_server_message_timer = messageTimer; 71 | m_server_wait_for_response_counter = waitForResponseCounter; 72 | m_server_message_retry_count = messageRetryCount; 73 | } 74 | 75 | QNetworkAccessManager m_manager; 76 | bool m_wait_for_last_request_response; 77 | QTimer m_msgTimer; 78 | bool m_online_state; 79 | QList m_network_requests; 80 | #ifndef QT_NO_BEARERMANAGEMENT 81 | QNetworkConfigurationManager m_network_info; 82 | #endif 83 | int m_waiting_counter; 84 | int m_server_message_timer; 85 | int m_server_wait_for_response_counter; 86 | int m_server_message_retry_count; 87 | 88 | }; 89 | 90 | QT_END_NAMESPACE 91 | 92 | #endif // QTCLOUDMESSAGINGRESTAPI_P_H 93 | -------------------------------------------------------------------------------- /examples/kaltiot/smartiot/doc/src/qtcloudmessaging-kaltiot-smartiot.qdoc: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2018 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the documentation of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:FDL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** GNU Free Documentation License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Free 19 | ** Documentation License version 1.3 as published by the Free Software 20 | ** Foundation and appearing in the file included in the packaging of 21 | ** this file. Please review the following information to ensure 22 | ** the GNU Free Documentation License version 1.3 requirements 23 | ** will be met: https://www.gnu.org/licenses/fdl-1.3.html. 24 | ** $QT_END_LICENSE$ 25 | ** 26 | ****************************************************************************/ 27 | 28 | /*! 29 | \example kaltiot/smartiot 30 | \title Kaltiot Push Notification Example 31 | \ingroup examples-qtcloudmessaging 32 | \brief Demonstrates Kaltiot Smart IoT support with Qt. 33 | 34 | \image smartiot-example.png Screenshot of the example 35 | 36 | \e {Kaltiot Smart IoT} is a bi-directional messaging solution. It provides 37 | battery optimized communication for resource-constrained devices in lossy 38 | wireless networks. Using \e {Kaltiot Smart IoT}, you can send notification 39 | messages to notify a client app that a new message is available to sync. To 40 | learn more, visit \l {https://kaltiot.com/iot}. 41 | 42 | This example works on both \e Linux64 and \e {Raspberry Pi} devices. It 43 | demonstrates receiving push notifications from the \e {Kaltiot IoT Cloud}, 44 | and then displays the content on the screen. You can send push notifications 45 | to the devices running this example by using the \e IoT-Devices service in 46 | the \e {Kaltiot Console} or \e {Kaltiot HTTP Rest API} with \e curl or \e 47 | wget. Filter children by the \c providerId (\e KaltiotSmartIoT) and look for 48 | one with the same \e RID (resource ID) as the \c onClientTokenReceived 49 | callback reports. 50 | 51 | To use this example, the user must install \e {Kaltiot Smart IoT SDK} in 52 | their environment. Register and download via the \e {Kaltiot Console} \l 53 | {https://console.torqhub.io?iot} 54 | \note Set environment variable \e KALTIOT_SDK to the root directory of \e 55 | {Kaltiot Smart IoT SDK}. 56 | \note Copy the \e {IoT-Credentials API Key} from the \e {Kaltiot Console} 57 | and replace the value of \e SERVER_API_KEY in \c smartiot.cpp. 58 | \note Start the gateway daemon of \e {Kaltiot Smart IoT} and run it in the 59 | background before this application starts (\c {$KALTIOT_SDK/ks_gw 60 | --ipc-socket-path=0.0.0.0:50000 &}). 61 | 62 | \include examples-run.qdocinc 63 | */ 64 | -------------------------------------------------------------------------------- /examples/firebase/pushnotification/android-sources/src/org/qtproject/example/pushnotification/NotificationActivity.java: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2018 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | package org.qtproject.qt5.android.pushnotification; 52 | 53 | import android.content.Intent; 54 | import com.google.firebase.messaging.MessageForwardingService; 55 | 56 | public class NotificationActivity extends org.qtproject.qt5.android.bindings.QtActivity 57 | { 58 | @Override 59 | protected void onNewIntent(Intent intent) 60 | { 61 | Intent message = new Intent(this, MessageForwardingService.class); 62 | message.setAction(MessageForwardingService.ACTION_REMOTE_INTENT); 63 | message.putExtras(intent); 64 | message.setData(intent.getData()); 65 | startService(message); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /examples/kaltiot/smartiot/smartiot.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2018 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | #ifndef SMARTIOT_H 52 | #define SMARTIOT_H 53 | 54 | #include 55 | #include 56 | #include 57 | 58 | class PushNotification: public QObject 59 | { 60 | Q_OBJECT 61 | public: 62 | PushNotification(const QString &provider, const QString &client, QObject *parent = nullptr); 63 | ~PushNotification(); 64 | 65 | bool startService(); 66 | QCloudMessaging *service() {return &cloudMessage;} 67 | 68 | private: 69 | Q_DISABLE_COPY(PushNotification) 70 | 71 | const QString providerId; 72 | const QString clientId; 73 | 74 | QCloudMessaging cloudMessage; 75 | QCloudMessagingEmbeddedKaltiotProvider kaltiotProvider; 76 | }; 77 | 78 | #endif // SMARTIOT_H 79 | -------------------------------------------------------------------------------- /examples/firebase/pushnotification/pushnotification.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2018 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | #ifndef PUSHNOTIFICATION_H 52 | #define PUSHNOTIFICATION_H 53 | 54 | #include 55 | #include 56 | #include 57 | 58 | class PushNotification: public QObject 59 | { 60 | Q_OBJECT 61 | public: 62 | PushNotification(const QString &provider, const QString &client, QObject *parent = nullptr); 63 | ~PushNotification(); 64 | 65 | bool startService(); 66 | QCloudMessaging *getService() {return &cloudMessage;} 67 | 68 | private: 69 | Q_DISABLE_COPY(PushNotification) 70 | 71 | const QString providerId; 72 | const QString clientId; 73 | 74 | QCloudMessaging cloudMessage; 75 | QCloudMessagingFirebaseProvider firebaseProvider; 76 | }; 77 | 78 | #endif // PUSHNOTIFICATION_H 79 | -------------------------------------------------------------------------------- /src/cloudmessagingfirebase/qcloudmessagingfirebaseclient.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #ifndef QCloudMessagingFirebaseClient_H 30 | #define QCloudMessagingFirebaseClient_H 31 | 32 | #include 33 | #include "firebase/app.h" 34 | #include "firebase/messaging.h" 35 | #include "firebase/util.h" 36 | #include 37 | #include 38 | #include 39 | 40 | QT_BEGIN_NAMESPACE 41 | 42 | class QCloudMessagingFirebaseClientPrivate; 43 | 44 | class QCloudMessagingFirebaseClient: public QCloudMessagingClient, firebase::messaging::Listener 45 | { 46 | 47 | public: 48 | 49 | explicit QCloudMessagingFirebaseClient(QObject *parent = nullptr); 50 | 51 | ~QCloudMessagingFirebaseClient(); 52 | 53 | //! Firebase virtual functions 54 | 55 | virtual void OnMessage(const ::firebase::messaging::Message &message) override; 56 | 57 | virtual void OnTokenReceived(const char *token) override; 58 | 59 | 60 | //! Qt Cloud messaging client virtual functions 61 | 62 | virtual bool flushMessageQueue() override; 63 | 64 | virtual QString connectClient(const QString &clientId, 65 | const QVariantMap ¶meters = QVariantMap()) override; 66 | 67 | virtual void disconnectClient() override; 68 | 69 | virtual bool subscribeToChannel(const QString &channel) override; 70 | 71 | virtual bool unsubscribeFromChannel(const QString &channel) override; 72 | 73 | QString clientToken() override; 74 | 75 | QString clientUuid(); 76 | 77 | bool sendMessage(const QByteArray &msg, 78 | const QString &clientToken = QString(), 79 | const QString &channel = QString()) override; 80 | 81 | void cloudMessageReceived(const QString &client, 82 | const QByteArray &message) override; 83 | 84 | void setClientToken(const QString &uuid) override; 85 | 86 | private: 87 | QString parseMessage(firebase::messaging::Message msg_map); 88 | 89 | QScopedPointer d; 90 | }; 91 | 92 | QT_END_NAMESPACE 93 | 94 | #endif // QCloudMessagingFirebaseClient_H 95 | -------------------------------------------------------------------------------- /examples/firebase/pushnotification/main.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2018 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | #include 52 | #include 53 | 54 | #include "pushnotification.h" 55 | 56 | int main(int argc, char **argv) 57 | { 58 | QGuiApplication app(argc, argv); 59 | QQuickView view; 60 | 61 | PushNotification notifications(QStringLiteral("GoogleFireBase"), QStringLiteral("MobileClient"), 62 | &view); 63 | 64 | QQmlContext *ctxt = view.rootContext(); 65 | ctxt->setContextProperty(QStringLiteral("notifications"), notifications.getService()); 66 | 67 | view.setResizeMode(QQuickView::SizeRootObjectToView); 68 | view.setSource(QUrl(QStringLiteral("qrc:/qml/main.qml"))); 69 | view.show(); 70 | 71 | if (!notifications.startService()) { 72 | if (QObject *message = view.rootObject()->findChild("firebase_message")) 73 | message->setProperty("text", "Starting service of PushNotification fails!"); 74 | } 75 | 76 | return app.exec(); 77 | } 78 | -------------------------------------------------------------------------------- /src/cloudmessagingembeddedkaltiot/qcloudmessagingembeddedkaltiotclient.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #ifndef QCloudMessagingEmbeddedKaltiotClient_H 30 | #define QCloudMessagingEmbeddedKaltiotClient_H 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #ifndef ANDROID_OS 41 | #include "ks_gw_client.h" 42 | #else 43 | #include "ks_gw_client_android.h" 44 | #endif 45 | 46 | QT_BEGIN_NAMESPACE 47 | 48 | class QCloudMessagingEmbeddedKaltiotClientPrivate; 49 | 50 | class Q_CLOUDMESSAGING_EXPORT QCloudMessagingEmbeddedKaltiotClient : public QCloudMessagingClient 51 | { 52 | Q_OBJECT 53 | public: 54 | 55 | explicit QCloudMessagingEmbeddedKaltiotClient(QObject *parent = nullptr); 56 | ~QCloudMessagingEmbeddedKaltiotClient(); 57 | 58 | // Qt Cloud messaging client virtual functions 59 | virtual QString connectClient(const QString &clientId, 60 | const QVariantMap ¶meters = QVariantMap()) override; 61 | 62 | virtual void disconnectClient() override; 63 | 64 | virtual void cloudMessageReceived(const QString &client, const QByteArray &message) override; 65 | 66 | virtual QString clientToken() override; 67 | 68 | virtual void setClientToken(const QString &token) override; 69 | 70 | virtual bool sendMessage(const QByteArray &msg, 71 | const QString &clientToken = QString(), 72 | const QString &channel = QString()) override; 73 | 74 | 75 | virtual bool flushMessageQueue() override; 76 | 77 | virtual bool subscribeToChannel(const QString &channel) override; 78 | 79 | virtual bool unsubscribeFromChannel(const QString &channel) override; 80 | 81 | void kaltiotMessageReceived(const QString &client, const QString &message); 82 | 83 | ks_gw_client_instance_t *getKaltiotEngineInstance(); 84 | 85 | private: 86 | bool make_kaltiot_client_registration(); 87 | void runBackgroundThread(); 88 | 89 | QScopedPointer d; 90 | 91 | }; 92 | 93 | QT_END_NAMESPACE 94 | 95 | #endif // QCloudMessagingEmbeddedKaltiotClient_H 96 | -------------------------------------------------------------------------------- /examples/firebase/pushnotification/qml/main.qml: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2018 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | import QtQuick 2.0 52 | 53 | Rectangle { 54 | width: 500 55 | height: 500 56 | color: "white" 57 | 58 | Column { 59 | anchors.fill: parent 60 | Text { 61 | id: title 62 | color: "black" 63 | font.pixelSize: parent.width / 20 64 | text: "Qt Push Notification" 65 | width: parent.width 66 | horizontalAlignment: Text.AlignHCenter 67 | } 68 | Text { 69 | id: firebase_message 70 | objectName: "firebase_message" 71 | color: "black" 72 | text: "Waiting for the message from Firebase" 73 | wrapMode: Text.WrapAtWordBoundaryOrAnywhere 74 | width: parent.width 75 | } 76 | } 77 | Connections { 78 | target: notifications 79 | onMessageReceived: { 80 | console.log(message) 81 | firebase_message.text = message 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /examples/kaltiot/smartiot/main.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2018 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | #include 52 | #include 53 | 54 | #include "smartiot.h" 55 | 56 | int main(int argc, char **argv) 57 | { 58 | QGuiApplication app(argc, argv); 59 | QQuickView view; 60 | 61 | PushNotification notifications(QStringLiteral("KaltiotSmartIoT"), QStringLiteral("IoTClient"), 62 | &view); 63 | 64 | QQmlContext *ctxt = view.rootContext(); 65 | ctxt->setContextProperty(QStringLiteral("notifications"), notifications.service()); 66 | 67 | view.setResizeMode(QQuickView::SizeRootObjectToView); 68 | view.setSource(QUrl(QStringLiteral("qrc:/qml/main.qml"))); 69 | view.show(); 70 | 71 | if (!notifications.startService()) { 72 | if (QObject *message = view.rootObject()->findChild("kaltiot_message")) 73 | message->setProperty("text", "Starting service of PushNotification fails!\n" 74 | "Ensure Kaltiot daemon ($KALTIOT_SDK/ks_gw) is running."); 75 | } 76 | 77 | return app.exec(); 78 | } 79 | -------------------------------------------------------------------------------- /examples/kaltiot/smartiot/qml/main.qml: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2018 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | import QtQuick 2.0 52 | 53 | Rectangle { 54 | width: 500 55 | height: 500 56 | color: "white" 57 | 58 | Column { 59 | anchors.fill: parent 60 | Text { 61 | id: title 62 | color: "black" 63 | font.pixelSize: parent.width / 20 64 | text: "Qt Push Notification" 65 | width: parent.width 66 | horizontalAlignment: Text.AlignHCenter 67 | } 68 | Text { 69 | id: kaltiot_message 70 | objectName: "kaltiot_message" 71 | color: "black" 72 | text: "Waiting for the message from Kaltiot SmartIoT" 73 | wrapMode: Text.WrapAtWordBoundaryOrAnywhere 74 | width: parent.width 75 | } 76 | } 77 | Connections { 78 | target: notifications 79 | onMessageReceived: { 80 | console.log(message) 81 | kaltiot_message.text = message 82 | } 83 | onClientTokenReceived: { 84 | console.log("RID: " + token) 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/cloudmessagingfirebase/qcloudmessagingfirebaseprovider.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #ifndef FIREBASESERVICE_H 30 | #define FIREBASESERVICE_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include "firebase/app.h" 36 | #include "firebase/messaging.h" 37 | #include "firebase/util.h" 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | QT_BEGIN_NAMESPACE 44 | 45 | class QCloudMessagingFirebaseProviderPrivate; 46 | 47 | class QCloudMessagingFirebaseProvider : public QCloudMessagingProvider 48 | { 49 | Q_OBJECT 50 | public: 51 | 52 | explicit QCloudMessagingFirebaseProvider(QObject *parent = nullptr); 53 | 54 | ~QCloudMessagingFirebaseProvider(); 55 | 56 | virtual bool registerProvider(const QString &providerId, const QVariantMap ¶meters = QVariantMap()) override; 57 | 58 | virtual void deregisterProvider() override; 59 | 60 | virtual QCloudMessagingProvider::CloudMessagingProviderState setServiceState( 61 | QCloudMessagingProvider::CloudMessagingProviderState state) override; 62 | 63 | virtual QString connectClient(const QString &clientId, const QVariantMap ¶meters = QVariantMap()) override; 64 | 65 | virtual void disconnectClient(const QString &clientId, const QVariantMap ¶meters = QVariantMap()) override; 66 | 67 | virtual bool sendMessage(const QByteArray &msg, const QString &clientId = QString(), 68 | const QString &clientToken = QString(), 69 | const QString &channel = QString()) override; 70 | 71 | 72 | virtual bool subscribeToChannel(const QString &channel, const QString &clientId = QString()) override; 73 | 74 | virtual bool unsubscribeFromChannel(const QString &channel, const QString &clientId = QString()) override; 75 | 76 | QMap *clients() override; 77 | 78 | // Firefox server API tbd. 79 | bool remoteClients() override; 80 | 81 | QString clientToken(const QString &clientId); 82 | 83 | void setClientToken(const QString &clientId, const QString &uuid); 84 | 85 | 86 | private Q_SLOTS: 87 | void cloudMessageReceived(const QString &clientId, const QByteArray &message); 88 | 89 | private: 90 | QScopedPointer d; 91 | }; 92 | 93 | QT_END_NAMESPACE 94 | 95 | #endif // FIREBASESERVICE_H 96 | -------------------------------------------------------------------------------- /src/cloudmessaging/qcloudmessagingclient.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #ifndef QTCLOUDMESSAGINGCLIENT_H 30 | #define QTCLOUDMESSAGINGCLIENT_H 31 | 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | QT_BEGIN_NAMESPACE 40 | 41 | class QCloudMessagingClientPrivate; 42 | 43 | class Q_CLOUDMESSAGING_EXPORT QCloudMessagingClient : public QObject 44 | { 45 | Q_OBJECT 46 | 47 | public: 48 | 49 | enum CloudMessagingClientState { 50 | QtCloudMessgingClientDisconnected = 0, 51 | QtCloudMessagingClientConnecting, 52 | QtCloudMessagingClientDisconnecting, 53 | QtCloudMessagingClientOffline, 54 | QtCloudMessagingClientOnline 55 | }; 56 | Q_ENUM(CloudMessagingClientState) 57 | 58 | explicit QCloudMessagingClient(QObject *parent = nullptr); 59 | 60 | virtual ~QCloudMessagingClient(); 61 | 62 | virtual QString connectClient( 63 | const QString &clientId, 64 | const QVariantMap ¶meters = QVariantMap()); 65 | 66 | virtual void disconnectClient(); 67 | 68 | virtual void cloudMessageReceived(const QString &client, 69 | const QByteArray &message) = 0; 70 | 71 | virtual QString clientToken() = 0; 72 | 73 | virtual void setClientToken(const QString &token) = 0; 74 | 75 | virtual bool sendMessage( 76 | const QByteArray &msg, 77 | const QString &clientToken = QString(), 78 | const QString &channel = QString()) = 0; 79 | 80 | virtual bool flushMessageQueue() = 0; 81 | 82 | virtual bool subscribeToChannel(const QString &channel) = 0; 83 | 84 | virtual bool unsubscribeFromChannel(const QString &channel) = 0; 85 | 86 | void setClientState(int state); 87 | 88 | int clientState(); 89 | 90 | QString clientId(); 91 | 92 | QString providerId(); 93 | 94 | void setClientId(const QString &clientid); 95 | 96 | void setProviderId(const QString &providerId); 97 | 98 | QVariantMap clientParameters(); 99 | 100 | Q_SIGNALS: 101 | void clientStateChanged(const QString &clientId, int state); 102 | 103 | void messageReceived(const QString &clientId, const QByteArray &msg); 104 | 105 | void clientTokenReceived(const QString &token); 106 | 107 | private: 108 | 109 | QScopedPointer d; 110 | 111 | }; 112 | 113 | QT_END_NAMESPACE 114 | 115 | #endif // QTCLOUDMESSAGINGCLIENT_H 116 | -------------------------------------------------------------------------------- /examples/firebase/pushnotification/pushnotification.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2018 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | #include "pushnotification.h" 52 | 53 | PushNotification::PushNotification(const QString &provider, const QString &client, QObject *parent) 54 | : QObject(parent), providerId(provider), clientId(client) {} 55 | 56 | PushNotification::~PushNotification() 57 | { 58 | // Disconnect the clients from the registered provider. 59 | for (const auto &clientId : cloudMessage.localClients(providerId)) 60 | cloudMessage.disconnectClient(providerId, clientId); 61 | 62 | // Deregister the service provider and remove the provider id. 63 | // It will return immediately if the providerId is unregistered. 64 | cloudMessage.deregisterProvider(providerId); 65 | } 66 | 67 | bool PushNotification::startService() 68 | { 69 | // A SERVER_API_KEY that authorizes your app for access to Google services, 70 | // including sending topic messages via the Firebase Cloud Messaging 71 | // protocols. You can get it in the Cloud Messaging tab of the Firebase 72 | // console settings. 73 | QVariantMap params; 74 | params[QStringLiteral("SERVER_API_KEY")] = "Get your API key from the Firebase console"; 75 | 76 | // Registering the Google firebase service component. 77 | if (cloudMessage.registerProvider(providerId, &firebaseProvider, params)) 78 | return !cloudMessage.connectClient(providerId, clientId).isEmpty(); 79 | 80 | return false; 81 | } 82 | -------------------------------------------------------------------------------- /src/cloudmessagingembeddedkaltiot/qcloudmessagingembeddedkaltiotprovider.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #ifndef KALTIOTPUSHSERVICE_H 30 | #define KALTIOTPUSHSERVICE_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | QT_BEGIN_NAMESPACE 42 | 43 | class QCloudMessagingEmbeddedKaltiotProviderPrivate; 44 | class Q_CLOUDMESSAGING_EXPORT QCloudMessagingEmbeddedKaltiotProvider : public 45 | QCloudMessagingProvider 46 | { 47 | Q_OBJECT 48 | public: 49 | 50 | explicit QCloudMessagingEmbeddedKaltiotProvider(QObject *parent = nullptr); 51 | ~QCloudMessagingEmbeddedKaltiotProvider(); 52 | 53 | //! Qt Cloud messaging client virtual functions 54 | virtual bool registerProvider(const QString &providerId, 55 | const QVariantMap ¶meters = QVariantMap()) override; 56 | 57 | virtual void deregisterProvider() override; 58 | 59 | virtual QString connectClient(const QString &clientId, 60 | const QVariantMap ¶meters = QVariantMap()) override; 61 | 62 | virtual void disconnectClient(const QString &clientId, 63 | const QVariantMap ¶meters = QVariantMap()) override; 64 | 65 | virtual bool sendMessage(const QByteArray &msg, const QString &clientId = QString(), 66 | const QString &clientToken = QString(), 67 | const QString &channel = QString()) override; 68 | 69 | virtual QCloudMessagingProvider::CloudMessagingProviderState setServiceState( 70 | QCloudMessagingProvider::CloudMessagingProviderState state) override; 71 | 72 | virtual QMap *clients() override; 73 | 74 | virtual bool subscribeToChannel(const QString &channel, 75 | const QString &clientId = QString()) override; 76 | 77 | virtual bool unsubscribeFromChannel(const QString &channel, 78 | const QString &clientId = QString()) override; 79 | 80 | virtual bool remoteClients() override; 81 | 82 | /* KALTIOT SPECIFIC FUNCTIONS */ 83 | void cloudMessageReceived(const QString &client, const QByteArray &message); 84 | QCloudMessagingEmbeddedKaltiotClient *getKaltiotClient(const QString &clientId); 85 | 86 | void setClientToken(const QString &client, const QString &uuid); 87 | 88 | private: 89 | QScopedPointer d; 90 | 91 | }; 92 | 93 | QT_END_NAMESPACE 94 | 95 | #endif // KALTIOTPUSHSERVICE_H 96 | -------------------------------------------------------------------------------- /examples/firebase/pushnotification/android-sources/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 15 | 16 | 17 | 18 | 19 | 21 | 23 | 24 | 26 | 28 | 29 | 31 | 33 | 35 | 36 | 38 | 40 | 42 | 44 | 46 | 47 | 49 | 51 | 53 | 54 | 55 | 59 | 60 | 61 | 63 | 64 | 65 | 66 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /src/cloudmessagingfirebase/qcloudmessagingfirebaserest.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #include 30 | #include "qtcloudmessagingglobal.h" 31 | #include "qcloudmessagingfirebaserest.h" 32 | 33 | #include 34 | 35 | /* REST API INTERFACE */ 36 | const QString SERVER_ADDRESS = QStringLiteral("https://fcm.googleapis.com/fcm/send"); 37 | 38 | /*! 39 | * \brief FirebaseRestServer::sendToDevice 40 | * \param token 41 | * \param data 42 | * \return 43 | */ 44 | bool FirebaseRestServer::sendToDevice(const QString &token, const QByteArray &data) 45 | { 46 | QString data_to_send = "{\"to\":\"" + token + "\",\"data\":" + QString::fromUtf8(data) + "}"; 47 | QString url = SERVER_ADDRESS; 48 | QUrl uri(url); 49 | m_auth_key = "key=" + m_auth_key; 50 | QNetworkRequest request(uri); 51 | QString authHeader = QString::fromLatin1("Authorization"); 52 | request.setHeader(QNetworkRequest::ContentTypeHeader, QString::fromLatin1("application/json")); 53 | request.setRawHeader(authHeader.toLocal8Bit(), m_auth_key.toLocal8Bit()); 54 | 55 | return sendMessage(POST_MSG, 56 | REQ_SEND_BROADCAST_DATA_TO_CHANNEL, 57 | request, 58 | data_to_send.toUtf8(), 59 | true, 60 | QString()); 61 | } 62 | 63 | /*! 64 | * \brief FirebaseRestServer::sendBroadcast 65 | * \param channel 66 | * \param data 67 | * \return 68 | */ 69 | bool FirebaseRestServer::sendBroadcast(const QString &channel, const QByteArray &data) 70 | { 71 | QString mod_data = QString::fromUtf8(data); 72 | if (mod_data[0] == '{') 73 | mod_data.remove(0, 1); 74 | if (mod_data[mod_data.length() - 1] == '}') 75 | mod_data.remove(mod_data.length() - 1, 1); 76 | 77 | QString data_to_send = "{\"to\":\"/topics/" + channel + "\"," + mod_data + "}"; 78 | 79 | QString url = SERVER_ADDRESS; 80 | QUrl uri(url); 81 | QString auth = "key=" + m_auth_key; 82 | QNetworkRequest request(uri); 83 | QString authHeader = QString::fromLatin1("Authorization"); 84 | request.setHeader(QNetworkRequest::ContentTypeHeader, QString::fromLatin1("application/json")); 85 | request.setRawHeader(authHeader.toLocal8Bit(), auth.toLocal8Bit()); 86 | 87 | return sendMessage(POST_MSG, 88 | REQ_SEND_BROADCAST_DATA_TO_CHANNEL, 89 | request, 90 | data_to_send.toUtf8(), 91 | true, 92 | QString()); 93 | 94 | } 95 | 96 | /*! 97 | * \brief FirebaseRestServer::xmlHttpRequestReply 98 | * \param reply 99 | */ 100 | void FirebaseRestServer::xmlHttpRequestReply(QNetworkReply *reply) 101 | { 102 | getNetworkManager()->disconnect(SIGNAL(finished(QNetworkReply *))); 103 | QString m_msg_uuid = reply->property("uuid").toString(); 104 | int req_id = reply->property("req_id").toInt(); 105 | 106 | if (reply->error()) { 107 | emit xmlHttpRequestError(reply->errorString()); 108 | 109 | } 110 | 111 | // Ok message, lets proceed. 112 | 113 | QByteArray data(reply->readAll()); 114 | 115 | emit xmlHttpRequestReplyData(data); 116 | 117 | reply->deleteLater(); 118 | clearMessage(m_msg_uuid); 119 | } 120 | -------------------------------------------------------------------------------- /examples/kaltiot/smartiot/smartiot.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2018 The Qt Company Ltd. 4 | ** Contact: https://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see https://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at https://www.qt.io/contact-us. 16 | ** 17 | ** BSD License Usage 18 | ** Alternatively, you may use this file under the terms of the BSD license 19 | ** as follows: 20 | ** 21 | ** "Redistribution and use in source and binary forms, with or without 22 | ** modification, are permitted provided that the following conditions are 23 | ** met: 24 | ** * Redistributions of source code must retain the above copyright 25 | ** notice, this list of conditions and the following disclaimer. 26 | ** * Redistributions in binary form must reproduce the above copyright 27 | ** notice, this list of conditions and the following disclaimer in 28 | ** the documentation and/or other materials provided with the 29 | ** distribution. 30 | ** * Neither the name of The Qt Company Ltd nor the names of its 31 | ** contributors may be used to endorse or promote products derived 32 | ** from this software without specific prior written permission. 33 | ** 34 | ** 35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 | ** 47 | ** $QT_END_LICENSE$ 48 | ** 49 | ****************************************************************************/ 50 | 51 | #include "smartiot.h" 52 | 53 | PushNotification::PushNotification(const QString &provider, const QString &client, QObject *parent) 54 | : QObject(parent), providerId(provider), clientId(client) {} 55 | 56 | PushNotification::~PushNotification() 57 | { 58 | // Disconnect the clients from the registered provider. 59 | for (const auto &clientId : cloudMessage.localClients(providerId)) 60 | cloudMessage.disconnectClient(providerId, clientId); 61 | 62 | // Deregister the service provider and remove the provider id. 63 | // It will return immediately if the providerId is unregistered. 64 | cloudMessage.deregisterProvider(providerId); 65 | } 66 | 67 | bool PushNotification::startService() 68 | { 69 | // A SERVER_API_KEY that authorizes your app for access to Kaltiot services 70 | // when sending messages via the Kaltiot Smart IoT SDK. 71 | // You can get it in the IoT-Credentials tab of the Kaltiot console. 72 | QVariantMap params; 73 | params[QStringLiteral("SERVER_API_KEY")] = "Get your API key from the Kaltiot console"; 74 | 75 | QVariantMap clientParams; 76 | clientParams[QStringLiteral("version")] = QStringLiteral("1.0"); 77 | 78 | // Unique identifier of the device registering to the Kaltiot daemon. 79 | clientParams[QStringLiteral("address")] = clientId; 80 | 81 | // Unique identifier of the application registering to Kaltiot gateway. 82 | clientParams[QStringLiteral("customer_id")] = providerId; 83 | 84 | // The "--ipc-socket-path ip:port" option tells the daemon 85 | // ($KALTIOT_SDK/ks_gw) to listen for connections by device applications. 86 | // For example, here's how to have the Kaltiot daemon bind on port 50000. 87 | // $KALTIOT_SDK/ks_gw --ipc-socket-path=0.0.0.0:50000 88 | clientParams[QStringLiteral("kaltiot_daemon_path")] = QStringLiteral("127.0.0.1:50000"); 89 | 90 | // Creating default channels to listen 91 | QVariantList channels; 92 | channels.append(QStringLiteral("QtCloudMessaging")); 93 | clientParams[QStringLiteral("channels")] = channels; 94 | 95 | // Registering the Kaltiot SmartIoT service component. 96 | if (cloudMessage.registerProvider(providerId, &kaltiotProvider, params)) 97 | return !cloudMessage.connectClient(providerId, clientId, clientParams).isEmpty(); 98 | 99 | return false; 100 | } 101 | -------------------------------------------------------------------------------- /src/cloudmessaging/qcloudmessaging.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #ifndef QTCLOUDMESSAGING_H 30 | #define QTCLOUDMESSAGING_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | QT_BEGIN_NAMESPACE 39 | 40 | /*! 41 | * \class QCloudMessaging 42 | * \brief The QCloudMessaging class 43 | * 44 | * This is the Qt Cloud Messaging Class. 45 | */ 46 | class QCloudMessagingPrivate; 47 | 48 | 49 | class Q_CLOUDMESSAGING_EXPORT QCloudMessaging : public QObject 50 | { 51 | Q_OBJECT 52 | 53 | public: 54 | 55 | explicit QCloudMessaging(QObject *parent = nullptr); 56 | ~QCloudMessaging(); 57 | 58 | Q_INVOKABLE bool registerProvider(const QString &providerId, 59 | QCloudMessagingProvider *provider, 60 | const QVariantMap ¶meters = QVariantMap()); 61 | 62 | Q_INVOKABLE void deregisterProvider(const QString &providerId); 63 | 64 | Q_INVOKABLE QString connectClient(const QString &providerId, 65 | const QString &clientId, 66 | const QVariantMap ¶meters = 67 | QVariantMap()); 68 | 69 | Q_INVOKABLE void disconnectClient(const QString &providerId, 70 | const QString &clientId, 71 | const QVariantMap ¶meters = 72 | QVariantMap()); 73 | 74 | Q_INVOKABLE const QStringList localClients(const QString &providerId); 75 | 76 | Q_INVOKABLE bool requestRemoteClients(const QString &providerId); 77 | 78 | Q_INVOKABLE void removeClient(const QString &providerId, 79 | const QString &clientId); 80 | 81 | Q_INVOKABLE QString clientToken(const QString &providerId, 82 | const QString &clientId); 83 | 84 | Q_INVOKABLE void setClientToken(const QString &providerId, 85 | const QString &clientId, 86 | const QString &token); 87 | 88 | Q_INVOKABLE bool sendMessage(const QByteArray &msg, 89 | const QString &providerId = QString(), 90 | const QString &clientId = QString(), 91 | const QString &clientToken = QString(), 92 | const QString &channel = QString()) ; 93 | 94 | Q_INVOKABLE bool subscribeToChannel(const QString &channel, 95 | const QString &providerId = QString(), 96 | const QString &clientId = QString()); 97 | 98 | Q_INVOKABLE bool unsubscribeFromChannel(const QString &channel, 99 | const QString &providerId = QString(), 100 | const QString &clientId = QString()); 101 | 102 | Q_INVOKABLE void flushMessageQueue(const QString &providerId); 103 | 104 | Q_SIGNALS: 105 | void clientTokenReceived(const QString &token); 106 | 107 | void messageReceived(const QString &providerId, 108 | const QString &clientId, 109 | const QByteArray &message); 110 | 111 | void remoteClientsReceived(const QString &clients); 112 | 113 | void serviceStateUpdated(int state); 114 | 115 | private: 116 | QScopedPointer d; 117 | 118 | }; 119 | 120 | QT_END_NAMESPACE 121 | 122 | #endif // QTCLOUDMESSAGING_H 123 | -------------------------------------------------------------------------------- /src/cloudmessaging/qcloudmessagingrestapi.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #ifndef QTCLOUDMESSAGINGRESTAPI_H 30 | #define QTCLOUDMESSAGINGRESTAPI_H 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | QT_BEGIN_NAMESPACE 40 | 41 | class QNetworkAccessManager; 42 | class QAuthenticator; 43 | class QNetworkReply; 44 | 45 | 46 | class QCloudMessagingNetworkMessage 47 | { 48 | public: 49 | int type; 50 | int req_id; 51 | QString uuid; 52 | QNetworkRequest request; 53 | QByteArray data; 54 | QString related_uuid; 55 | QString info; 56 | int retry_count; 57 | 58 | }; 59 | 60 | class QCloudMessagingRestApiPrivate; 61 | 62 | class Q_CLOUDMESSAGING_EXPORT QCloudMessagingRestApi : public QObject 63 | { 64 | Q_OBJECT 65 | 66 | public: 67 | 68 | enum MessageType{ 69 | NO_TYPE = 0, 70 | POST_MSG, 71 | GET_MSG, 72 | PUT_MSG, 73 | DELETE_MSG 74 | }; 75 | Q_ENUM(MessageType) 76 | 77 | explicit QCloudMessagingRestApi(QObject *parent = nullptr); 78 | 79 | ~QCloudMessagingRestApi(); 80 | 81 | 82 | bool sendMessage(MessageType type, int req_id, QNetworkRequest request, 83 | QByteArray data, int immediate, 84 | const QString &related_uuid); 85 | 86 | void sendNetworkMessage(const QCloudMessagingNetworkMessage &msg, 87 | int immediate); 88 | 89 | void clearMessageBuffer(); 90 | 91 | int getNetworkRequestCount(); 92 | 93 | bool getOnlineState(); 94 | 95 | QNetworkAccessManager *getNetworkManager(); 96 | 97 | void setServerTimers(int messageTimer, 98 | int messageRetryCount, 99 | int messageNoResponseTimer); 100 | 101 | void clearMessage(const QString &msg_uuid); 102 | 103 | QNetworkReply *xmlHttpPostRequest(QNetworkRequest request, 104 | QByteArray data, 105 | int req_id, 106 | const QString &uuid, 107 | const QString &info); 108 | 109 | QNetworkReply *xmlHttpGetRequest(QNetworkRequest request, 110 | int req_id, 111 | const QString &uuid, 112 | const QString &info); 113 | 114 | QNetworkReply *xmlHttpPutRequest(QNetworkRequest request, 115 | QByteArray data, 116 | int req_id, 117 | const QString &uuid, 118 | const QString &info); 119 | 120 | QNetworkReply *xmlHttpDeleteRequest(QNetworkRequest request, 121 | int req_id, 122 | const QString &uuid, 123 | const QString &info); 124 | Q_SIGNALS: 125 | void xmlHttpRequestError(const QString &errorString); 126 | 127 | public Q_SLOTS: 128 | virtual void xmlHttpRequestReply(QNetworkReply *reply) = 0; 129 | virtual void provideAuthentication(QNetworkReply *reply, QAuthenticator *authenticator); 130 | 131 | private Q_SLOTS: 132 | void networkMsgTimerTriggered(); 133 | void onlineStateChanged(bool online); 134 | 135 | private: 136 | void append_network_request(int req_id, const QString ¶m, QVariant data); 137 | 138 | QScopedPointer d; 139 | 140 | }; 141 | 142 | QT_END_NAMESPACE 143 | 144 | #endif // QTCLOUDMESSAGINGRESTAPI_H 145 | -------------------------------------------------------------------------------- /src/cloudmessaging/qcloudmessagingprovider.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #ifndef QTCLOUDMESSAGINGPROVIDER_H 30 | #define QTCLOUDMESSAGINGPROVIDER_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | QT_BEGIN_NAMESPACE 41 | 42 | /*! 43 | * \brief The QtCloudMessagingProvider class 44 | */ 45 | class QCloudMessagingProviderPrivate; 46 | 47 | class Q_CLOUDMESSAGING_EXPORT QCloudMessagingProvider : public QObject 48 | { 49 | Q_OBJECT 50 | 51 | public: 52 | 53 | enum CloudMessagingProviderState { 54 | QtCloudMessagingProviderNotRegistered, 55 | QtCloudMessagingProviderRegistering, 56 | QtCloudMessagingProviderRegistered 57 | }; 58 | Q_ENUM(CloudMessagingProviderState) 59 | 60 | explicit QCloudMessagingProvider(QObject *parent = nullptr); 61 | ~QCloudMessagingProvider(); 62 | 63 | virtual bool registerProvider( 64 | const QString &providerId, 65 | const QVariantMap ¶meters = QVariantMap()); 66 | 67 | virtual void deregisterProvider(); 68 | 69 | virtual QString connectClient( 70 | const QString &clientId, 71 | const QVariantMap ¶meters = QVariantMap()) = 0; 72 | 73 | virtual void disconnectClient( 74 | const QString &clientId, 75 | const QVariantMap ¶meters = QVariantMap()); 76 | 77 | virtual bool sendMessage( 78 | const QByteArray &msg, 79 | const QString &clientId = QString(), 80 | const QString &clientToken = QString(), 81 | const QString &channel = QString()) = 0; 82 | 83 | virtual CloudMessagingProviderState setServiceState(QCloudMessagingProvider::CloudMessagingProviderState state); 84 | 85 | virtual QMap *clients(); 86 | 87 | QString clientToken(const QString &clientId); 88 | 89 | virtual bool remoteClients() = 0; 90 | 91 | QCloudMessagingClient *client(const QString &clientId); 92 | 93 | QString providerId(); 94 | 95 | void setProviderId(const QString &providerId); 96 | 97 | QCloudMessagingProvider::CloudMessagingProviderState getServiceState(); 98 | 99 | bool removeClient(const QString &clientId); 100 | 101 | virtual bool subscribeToChannel( 102 | const QString &channel, 103 | const QString &clientId = QString()) = 0; 104 | 105 | virtual bool unsubscribeFromChannel( 106 | const QString &channel, 107 | const QString &clientId = QString()) = 0; 108 | 109 | 110 | bool flushMessageQueue(); 111 | 112 | QString connectClientToProvider( 113 | const QString &clientId, 114 | const QVariantMap ¶meters = QVariantMap(), 115 | QCloudMessagingClient *serviceClient = nullptr); 116 | 117 | private Q_SLOTS: 118 | void messageReceivedSlot(const QString &clientId, 119 | const QByteArray &message); 120 | 121 | Q_SIGNALS: 122 | void clientTokenReceived(const QString &token); 123 | 124 | void messageReceived(const QString &providerId, 125 | const QString &clientId, 126 | const QByteArray &message); 127 | 128 | void remoteClientsReceived(const QString &clients); 129 | 130 | void serviceStateUpdated(int state); 131 | 132 | void clientStateChanged(const QString &clientId, 133 | int status); 134 | 135 | 136 | private: 137 | QScopedPointer d; 138 | }; 139 | 140 | QT_END_NAMESPACE 141 | 142 | #endif // QTCLOUDMESSAGINGPROVIDER_H 143 | -------------------------------------------------------------------------------- /src/cloudmessagingembeddedkaltiot/qcloudmessagingembeddedkaltiotrest.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | #include 29 | #include "qtcloudmessagingglobal.h" 30 | #include "qcloudmessagingembeddedkaltiotrest.h" 31 | 32 | #include 33 | #include 34 | 35 | QT_BEGIN_NAMESPACE 36 | 37 | /* REST API INTERFACE */ 38 | const QString SERVER_ADDRESS = QStringLiteral("https://restapi.torqhub.io"); 39 | 40 | /*! 41 | * \brief QCloudMessagingEmbeddedKaltiotRest::getAllDevices 42 | * \return 43 | */ 44 | bool QCloudMessagingEmbeddedKaltiotRest::getAllDevices() 45 | { 46 | QString url = SERVER_ADDRESS + "/rids/identities" + "?ApiKey=" + m_auth_key; 47 | QUrl uri(url); 48 | QNetworkRequest request(uri); 49 | 50 | request.setHeader(QNetworkRequest::ContentTypeHeader, "text/plain; charset=ISO-8859-1"); 51 | 52 | return sendMessage(GET_MSG, REQ_GET_ALL_DEVICES, request, "", true, ""); 53 | } 54 | 55 | /*! 56 | * \brief QCloudMessagingEmbeddedKaltiotRest::sendDataToDevice 57 | * \param rid 58 | * \param data 59 | * \return 60 | */ 61 | bool QCloudMessagingEmbeddedKaltiotRest::sendDataToDevice(const QString &rid, const QByteArray &data) 62 | { 63 | 64 | QString url = SERVER_ADDRESS + "/rids/" + rid + "?ApiKey=" + m_auth_key; 65 | QUrl uri(url); 66 | QNetworkRequest request(uri); 67 | 68 | request.setHeader(QNetworkRequest::ContentTypeHeader, "text/plain; charset=ISO-8859-1"); 69 | 70 | return sendMessage(POST_MSG, REQ_SEND_DATA_TO_DEVICE, request, data, true, ""); 71 | } 72 | 73 | /*! 74 | * \brief QCloudMessagingEmbeddedKaltiotRest::sendBroadcast 75 | * \param channel 76 | * \param data 77 | * \return 78 | */ 79 | bool QCloudMessagingEmbeddedKaltiotRest::sendBroadcast(const QString &channel, const QByteArray &data) 80 | { 81 | 82 | QString url = SERVER_ADDRESS + "/rids/channel/" + channel + "?ApiKey=" + m_auth_key; 83 | QUrl uri(url); 84 | QNetworkRequest request(uri); 85 | request.setHeader(QNetworkRequest::ContentTypeHeader, "text/plain; charset=ISO-8859-1"); 86 | 87 | return sendMessage(POST_MSG, REQ_SEND_BROADCAST_DATA_TO_CHANNEL, request, data, true, ""); 88 | 89 | } 90 | 91 | /*! 92 | * \brief QCloudMessagingEmbeddedKaltiotRest::xmlHttpRequestReply 93 | * \param reply 94 | */ 95 | void QCloudMessagingEmbeddedKaltiotRest::xmlHttpRequestReply(QNetworkReply *reply) 96 | { 97 | 98 | getNetworkManager()->disconnect(SIGNAL(finished(QNetworkReply *))); 99 | QString m_msg_uuid = reply->property("uuid").toString(); 100 | int req_id = reply->property("req_id").toInt(); 101 | 102 | if (reply->error()) { 103 | emit xmlHttpRequestError(reply->errorString()); 104 | 105 | } 106 | 107 | // Ok message, lets proceed. 108 | 109 | QByteArray data(reply->readAll()); 110 | 111 | switch (req_id) { 112 | case REQ_GET_DEVICES_BY_CUSTOMER_ID: 113 | 114 | break; 115 | case REQ_GET_ALL_DEVICES: { 116 | Q_EMIT remoteClientsReceived(QString::fromUtf8(data)); 117 | } 118 | break; 119 | case REQ_SEND_DATA_TO_DEVICE: 120 | 121 | break; 122 | case REQ_SEND_BROADCAST_DATA_TO_CHANNEL: 123 | 124 | break; 125 | case REQ_GET_DEVICE_INFO: 126 | 127 | break; 128 | } 129 | 130 | reply->deleteLater(); 131 | clearMessage(m_msg_uuid); 132 | 133 | } 134 | 135 | // Signals documentation 136 | /*! 137 | \fn QCloudMessagingEmbeddedKaltiotRest::remoteClientsReceived(const QString &clients) 138 | This signal is triggered when the return value for requestRemoteClients 139 | function is is received 140 | . 141 | \param response 142 | Response data is based on the service and can be e.g. a list 143 | of client tokens in QString format. 144 | */ 145 | QT_END_NAMESPACE 146 | -------------------------------------------------------------------------------- /src/cloudmessagingembeddedkaltiot/qcloudmessagingembeddedkaltiotrest.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | #ifndef QCLOUDMESSAGINGEMBEDDEDKALTIOTREST_H 29 | #define QCLOUDMESSAGINGEMBEDDEDKALTIOTREST_H 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | QT_BEGIN_NAMESPACE 38 | 39 | class QCloudMessagingEmbeddedKaltiotRest : public QCloudMessagingRestApi 40 | { 41 | Q_OBJECT 42 | public: 43 | enum KaltiotRESTRequests { 44 | REQ_NO_REQ, 45 | REQ_GET_DEVICES_BY_CUSTOMER_ID, 46 | REQ_GET_ALL_DEVICES, 47 | REQ_SEND_DATA_TO_DEVICE, 48 | REQ_SEND_BROADCAST_DATA_TO_CHANNEL, 49 | REQ_GET_DEVICE_INFO 50 | }; 51 | Q_ENUM(KaltiotRESTRequests) 52 | 53 | void setAuthKey(QString key) 54 | { 55 | m_auth_key = key; 56 | } 57 | 58 | /* KALTIOT REST API 59 | * 60 | * Get Identities 61 | * GET /rids/identities/customerId/:cust_id - Your device identities by customer id 62 | * GET /rids/identities/paginStart/:paginStart/paginCount/:paginCount - Your devices identities with pagination 63 | * GET /rids/identities/timeFrom/:timeFrom/timeTo/:timeTo - Your device identities by creation timestamps 64 | * GET /rids/identities - All your devices identities 65 | * 66 | * Create persistence sessions 67 | * POST /cn/:cn/data_stream - Create persistent web socket session to all your devices 68 | * POST /rids/:rid/data_stream - Create persistent web socket session to single device 69 | * 70 | * Get data from devices 71 | * GET /cn/:cn/data_stream/sessionId/:sessionId - Use persistent web socket to all your devices 72 | * GET /cn/:cn/data_stream - Use non persistent web socket to all your devices 73 | * GET /rids/:rid/data_stream/sessionId/:sessionId - Use Persistent web socket to single device 74 | * GET /rids/:rid/data_stream - Use non persistent web socket to single device 75 | * 76 | * Send data to devices 77 | * POST /rids/:rid - Send data to single device 78 | * POST /rids/channel/:channel - Send data to group of devices 79 | * 80 | * Get Device Information 81 | * GET /rids/:rid/presence - Get your device presence information 82 | * 83 | */ 84 | 85 | 86 | /* getAllDevices implements 87 | * GET /rids/identities - All your devices identities 88 | */ 89 | bool getAllDevices(); 90 | 91 | /* Implements 92 | * POST /rids/:rid - Send data to single device 93 | */ 94 | bool sendDataToDevice(const QString &rid, const QByteArray &data); 95 | 96 | /* Implements 97 | * POST /rids/channel/:channel - Send data to group of devices 98 | */ 99 | bool sendBroadcast(const QString &channel, const QByteArray &data); 100 | 101 | /* Error codes for requests */ 102 | /** 103 | * {"result": ""} 104 | * 1 - InvalidJSON Json used in request was not valid 105 | * 2 - RidNotFound RID used in request was not connected 106 | * 3 - HandshakeFailure WebSocket handshake was unsuccessful 107 | * 4 - MessageLost Message received by RestApi was lost, delivery to client cannot be guaranteed 108 | * 5 - NoRoute Message received by RestApi was not able to deliver to client 109 | * 6 - MalformedRequest Request received by RestApi was not properly formatted 110 | * 7 - UriNotFound Request to URI which was made is not existing 111 | * 8 - MethodNotAllowed Http method which was used to access URI is not allowed 112 | * 9 - DeliveryFailure Message received by RestApi was not able to deliver to client 113 | * 10 - UnAuthorized Apikey which was used was not accepted 114 | */ 115 | 116 | void xmlHttpRequestReply(QNetworkReply *reply); 117 | 118 | Q_SIGNALS: 119 | void remoteClientsReceived(const QString &clients); 120 | 121 | private: 122 | QString m_auth_key; 123 | }; 124 | 125 | QT_END_NAMESPACE 126 | 127 | #endif // QCLOUDMESSAGINGEMBEDDEDKALTIOTREST_H 128 | -------------------------------------------------------------------------------- /src/cloudmessagingfirebase/qcloudmessagingfirebaseprovider.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #include "qcloudmessagingfirebaseprovider.h" 30 | #include "qcloudmessagingfirebaseprovider_p.h" 31 | 32 | #include "firebase/app.h" 33 | #include "firebase/messaging.h" 34 | #include "firebase/util.h" 35 | 36 | QT_BEGIN_NAMESPACE 37 | 38 | static QCloudMessagingFirebaseProvider *m_FirebaseServiceProvider; 39 | 40 | /*! 41 | * \brief LogMessage 42 | * \param format 43 | */ 44 | void LogMessage(const char *format, ...) 45 | { 46 | static const int kLineBufferSize = 100; 47 | char buffer[kLineBufferSize + 2]; 48 | 49 | va_list list; 50 | va_start(list, format); 51 | int string_len = vsnprintf(buffer, kLineBufferSize, format, list); 52 | string_len = string_len < kLineBufferSize ? string_len : kLineBufferSize; 53 | // append a linebreak to the buffer: 54 | buffer[string_len] = '\n'; 55 | buffer[string_len + 1] = '\0'; 56 | va_end(list); 57 | } 58 | 59 | /*! 60 | * \brief QCloudMessagingFirebaseProvider::QCloudMessagingFirebaseProvider 61 | */ 62 | QCloudMessagingFirebaseProvider::QCloudMessagingFirebaseProvider(QObject *parent) : 63 | QCloudMessagingProvider(parent), 64 | d(new QCloudMessagingFirebaseProviderPrivate) 65 | { 66 | m_FirebaseServiceProvider = this; 67 | } 68 | 69 | /*! 70 | * \brief QCloudMessagingFirebaseProvider::~QCloudMessagingFirebaseProvider 71 | */ 72 | QCloudMessagingFirebaseProvider::~QCloudMessagingFirebaseProvider() 73 | { 74 | deregisterProvider(); 75 | } 76 | 77 | /*! 78 | * \brief QCloudMessagingFirebaseProvider::registerProvider 79 | * \param providerId 80 | * \param parameters 81 | * \return 82 | */ 83 | bool QCloudMessagingFirebaseProvider::registerProvider(const QString &providerId, 84 | const QVariantMap ¶meters) 85 | { 86 | 87 | QCloudMessagingProvider::registerProvider(providerId, parameters); 88 | 89 | setServiceState(QtCloudMessagingProviderRegistered); 90 | 91 | // Get the API key for HTTP communication 92 | d->m_key = parameters.value(QStringLiteral("SERVER_API_KEY")).toString(); 93 | d->m_restInterface.setAuthKey(d->m_key); 94 | 95 | return true; 96 | } 97 | 98 | /*! 99 | * \brief QCloudMessagingFirebaseProvider::deregisterProvider 100 | * \return 101 | */ 102 | void QCloudMessagingFirebaseProvider::deregisterProvider() 103 | { 104 | ::firebase::messaging::Terminate(); 105 | QCloudMessagingProvider::deregisterProvider(); 106 | } 107 | 108 | /*! 109 | * \brief QCloudMessagingFirebaseProvider::setServiceState 110 | * \param service_mode 111 | * \return 112 | */ 113 | QCloudMessagingProvider::CloudMessagingProviderState QCloudMessagingFirebaseProvider::setServiceState(QCloudMessagingProvider::CloudMessagingProviderState service_mode) 114 | { 115 | if (getServiceState() != QtCloudMessagingProviderNotRegistered) { 116 | return QCloudMessagingProvider::setServiceState(service_mode); 117 | } 118 | 119 | return QCloudMessagingProvider::QtCloudMessagingProviderNotRegistered; 120 | } 121 | 122 | /*! 123 | * \brief QCloudMessagingFirebaseProvider::connectClient 124 | * \param clientId 125 | * \param parameters 126 | * \return 127 | */ 128 | QString QCloudMessagingFirebaseProvider::connectClient(const QString &clientId, 129 | const QVariantMap ¶meters) 130 | { 131 | if (!providerId().isEmpty()) { 132 | QCloudMessagingFirebaseClient *serviceClient = new QCloudMessagingFirebaseClient(); 133 | QString retval = connectClientToProvider(clientId, parameters, serviceClient); 134 | return retval; 135 | } 136 | return QString(); 137 | } 138 | 139 | 140 | /*! 141 | * \brief QCloudMessagingFirebaseProvider::sendMessage 142 | * \param msg 143 | * \param clientId 144 | * \param send_to_device 145 | * \param send_to_channel 146 | * \return 147 | */ 148 | bool QCloudMessagingFirebaseProvider::sendMessage(const QByteArray &msg, const QString &clientId, 149 | const QString &clientToken, const QString &channel) 150 | { 151 | //! Sending to internal client 152 | if (!clientId.isEmpty() && clientToken.isEmpty() && channel.isEmpty()) { 153 | 154 | if (client(clientId)) { 155 | client(clientId)->messageReceived(clientId, msg); 156 | return true; 157 | } 158 | } else 159 | //! Sending to device or channel out there, by using the client (e.g. in mobile) 160 | if (!clientId.isEmpty() && (!clientToken.isEmpty() && !channel.isEmpty())) { 161 | 162 | if (client(clientId)) { 163 | return client(clientId)->sendMessage(msg, clientToken, channel); 164 | } 165 | 166 | } else { 167 | //! Sending via rest api interface (SERVER side) 168 | if (!channel.isEmpty()) 169 | return d->m_restInterface.sendBroadcast(channel, msg); 170 | 171 | if (!clientToken.isEmpty()) 172 | return d->m_restInterface.sendToDevice(clientToken, msg); 173 | } 174 | return false; 175 | } 176 | 177 | /*! 178 | * \brief QCloudMessagingFirebaseProvider::disconnectClient 179 | * \param clientId 180 | * \param parameters 181 | * \return 182 | */ 183 | void QCloudMessagingFirebaseProvider::disconnectClient(const QString &clientId, 184 | const QVariantMap ¶meters) 185 | { 186 | return QCloudMessagingProvider::disconnectClient(clientId, parameters); 187 | } 188 | 189 | /*! 190 | * \brief QCloudMessagingFirebaseProvider::clients 191 | * \return 192 | */ 193 | QMap *QCloudMessagingFirebaseProvider::clients() 194 | { 195 | return QCloudMessagingProvider::clients(); 196 | } 197 | 198 | /*! 199 | * \brief QCloudMessagingFirebaseProvider::setClientToken 200 | * \param client 201 | * \param uuid 202 | */ 203 | void QCloudMessagingFirebaseProvider::setClientToken(const QString &clientId, const QString &uuid) 204 | { 205 | client(clientId)->setClientToken(uuid); 206 | } 207 | 208 | /*! 209 | * \brief QCloudMessagingFirebaseProvider::cloudMessageReceived 210 | * \param client 211 | * \param message 212 | */ 213 | void QCloudMessagingFirebaseProvider::cloudMessageReceived(const QString &clientId, 214 | const QByteArray &message) 215 | { 216 | client(clientId)->messageReceived(clientId, message); 217 | } 218 | 219 | /*! 220 | * \brief QCloudMessagingFirebaseProvider::subscribeToChannel 221 | * \param channel 222 | * \param clientId 223 | * \return 224 | */ 225 | bool QCloudMessagingFirebaseProvider::subscribeToChannel(const QString &channel, 226 | const QString &clientId) 227 | { 228 | if (!clientId.isEmpty()) 229 | return client(clientId)->subscribeToChannel(channel); 230 | 231 | return true; 232 | } 233 | 234 | /*! 235 | * \brief QCloudMessagingFirebaseProvider::unsubscribeFromChannel 236 | * \param channel 237 | * \param clientId 238 | * \return 239 | */ 240 | bool QCloudMessagingFirebaseProvider::unsubscribeFromChannel(const QString &channel, 241 | const QString &clientId) 242 | { 243 | if (!clientId.isEmpty()) 244 | return client(clientId)->unsubscribeFromChannel(channel); 245 | 246 | return true; 247 | } 248 | 249 | /*! 250 | * \brief QCloudMessagingFirebaseProvider::clientToken 251 | * \param clientId 252 | * \return 253 | */ 254 | QString QCloudMessagingFirebaseProvider::clientToken(const QString &clientId) 255 | { 256 | return client(clientId)->clientToken(); 257 | } 258 | 259 | /*! 260 | * \brief QCloudMessagingFirebaseProvider::remoteClients 261 | * \return 262 | */ 263 | bool QCloudMessagingFirebaseProvider::remoteClients() 264 | { 265 | return false; 266 | } 267 | 268 | QT_END_NAMESPACE 269 | 270 | 271 | 272 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | QT CLOUD MESSAGING API INSTALLATION: 2 | 3 | 1. To install with available backend add following to qmake script: 4 | qmake "CONFIG += embedded-kaltiot" 5 | or 6 | qmake "CONFIG += firebase" 7 | 8 | e.g.: 9 | qmake "CONFIG += embedded-kaltiot firebase" 10 | make qmake_all 11 | make 12 | make install 13 | 14 | Google Firebase requirements: 15 | 2. Download and unzip google firebase c++ SDK: 16 | https://firebase.google.com/docs/cpp/setup 17 | 18 | 3. To use firebase as backend, define the following ENVIRONMENT variable 19 | GOOGLE_FIREBASE_SDK = 20 | and make it to point to your firebase sdk root 21 | 22 | Embedded-Kaltiot requirements: 23 | 4. To use in embedded Kaltiot backend: 24 | 3.1. Register your app in 25 | https://console.torqhub.io/signin 26 | 27 | 3.2. Download platform SDK from the console download page 28 | 29 | 3.3. Add environment variable to pointing to downloaded and unzipped SDK root: 30 | KALTIOT_SDK = ../../../_RasperryPi_SDK_1.0.17 31 | 32 | 33 | 5. Install first the QtCloudMessaging from command line with: 34 | 35 | qmake "CONFIG += embedded-kaltiot firebase" 36 | make 37 | make install 38 | 39 | 6. Now you can use the QtCloudMessaging in your app with 40 | 41 | Just API wrapper (e.g. creating new service providers) 42 | QT += cloudmessaging 43 | 44 | With Firebase backend: 45 | QT += cloudmessagingfirebase 46 | 47 | With Embedded devices & Kaltiot 48 | QT += cloudmessagingembeddedkaltiot 49 | 50 | See more from the example apps. 51 | NOTE: Examples are in Github: 52 | https://github.com/snowgrains/qtcloudmessaging-examples 53 | 54 | 7. Usage basics: 55 | 56 | main.cpp: 57 | 58 | // Using QCloudMessaging: 59 | #include 60 | #include 61 | 62 | // Depending on your backend provider, add: 63 | 64 | // For Embedded systems 65 | #include 66 | 67 | // for Google firebase 68 | #include 69 | 70 | #include 71 | #include 72 | #include 73 | 74 | int main(int argc, char *argv[]) 75 | { 76 | QGuiApplication app(argc, argv); 77 | 78 | QQmlApplicationEngine engine; 79 | 80 | //*** QTCLOUDMSG DEFINITIONS 81 | QCloudMessaging *pushServices = new QCloudMessaging(); 82 | 83 | //***** For Kaltiot Embedded systems 84 | QCloudMessagingEmbeddedKaltiotProvider *kaltiotPushService = new QCloudMessagingEmbeddedKaltiotProvider() 85 | 86 | // Provider based init parameters are given with QVariantMap 87 | QVariantMap provider_params; 88 | provider_params["SERVER_API_KEY"] = "Your API key from the Kaltiot console for server communication"; 89 | 90 | // Creating name for provider which can be used cross your app. 91 | pushServices->registerProvider("KaltiotService", kaltiotPushService, provider_params); 92 | 93 | QVariantMap client_params; 94 | client_params["address"] = "IOTSensor1"; 95 | client_params["version"] = "1.0"; 96 | client_params["customer_id"] = "Kaltiot"; 97 | clientParams[QStringLiteral("kaltiot_daemon_path")] = QStringLiteral("127.0.0.1:50000"); 98 | 99 | QVariantList channels; 100 | channels.append("Temperatures"); 101 | client_params["channels"] = channels; 102 | 103 | /*! Connected client for the device. 104 | \param Service name "KaltiotService" 105 | \param Client identifier name to be used inside the application 106 | \param Parameters for the client specific for the provider API 107 | */ 108 | pushServices->connectClient("KaltiotService", "IOTSensor1", client_params); 109 | 110 | //***** OR For Firebase mobile systems: 111 | QCloudMessagingFirebaseProvider *m_firebaseService = new QCloudMessagingFirebaseProvider(); 112 | 113 | QVariantMap provider_params; 114 | 115 | // Server API key is not recommended to store inside to the application code due security reasons. 116 | // But if you do, make sure it is inside compiled C file or if you are doing a server side implementation with C++ & Qt. 117 | // SERVER_API_KEY Is needed to be able to send topic messages from the client without Firebase application server. 118 | 119 | provider_params["SERVER_API_KEY"] = "Get your SERVER API KEY from the google firebase console"; 120 | 121 | // Registering the Google firebase service component. 122 | pushServices->registerProvider("GoogleFireBase", m_firebaseService, provider_params); 123 | 124 | /*! Connected client is needed for mobile device. 125 | \param Service name "GoogleFireBase" 126 | \param Client identifier name to be used inside the demo application 127 | \param Parameters for the client. No params for firebase client. 128 | */ 129 | pushServices->connectClient("GoogleFireBase", "MobileClient", QVariantMap()); 130 | 131 | //! Automatically subscribe to listen one example topic 132 | pushServices->subscribeToChannel("ChatRoom", "GoogleFireBase", "MobileClient"); 133 | 134 | //*** END OF QTCLOUD MSG DEFINITIONS 135 | 136 | // these are needed for keeping the received RID in memory after restart (in Android) 137 | QCoreApplication::setOrganizationName("MyOrganisation"); 138 | QCoreApplication::setOrganizationDomain("MyOrganisation.com"); 139 | QCoreApplication::setApplicationName("QtCloudMessagingDemo"); 140 | 141 | 142 | // To Give QML the push service context: 143 | engine.rootContext()->setContextProperty("pushServices", pushServices); 144 | 145 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 146 | 147 | return app.exec(); 148 | } 149 | 150 | main.qml: 151 | 152 | import QtQuick 2.6 153 | import QtQuick.Window 2.2 154 | 155 | 156 | Window { 157 | visible: true 158 | width: 640 159 | height: 480 160 | title: qsTr("Qt Cloud Messaging Demo") 161 | 162 | 163 | // NOTIFICATIONS FROM THE ALL PROVIDERS: 164 | Connections { 165 | target:pushServices 166 | onMessageReceived:{ 167 | console.log("Message to " + providerId + " service to " + clientId + " client.") 168 | console.log("Message: " + message) 169 | 170 | var msg_in_json = JSON.parse(decodeURI(message)); 171 | 172 | // Example to respond to embedded system request: 173 | if (msg_in_json.command === "REQUESTING_TEMPERATURE") 174 | embeddedPublishTemperatureToServer(msg_in_json.serverID, mydevicecommand.getTemperature()); 175 | 176 | // Or firebase the message itself is a container of the info. 177 | updateGameNotification(message); 178 | } 179 | 180 | // Own Uuid to be used or broadcasted to server. 181 | onClientTokenReceived: { 182 | 183 | console.log("MY Uuid:"+rid) 184 | 185 | // Id this is server code: 186 | serverUuid = rid; 187 | 188 | // Id this is client code: 189 | clientUuid = rid; 190 | 191 | } 192 | } 193 | Component.onCompleted { 194 | // In case android app and firebase sdk gets started fast and token is needed, it can be requested with: 195 | clientUuid = pushServices.clientToken("GoogleFireBase", "MobileClient"); 196 | } 197 | 198 | //***** EMBEDDED DEVICES 199 | 200 | // Function to send msg as server with Kaltiot provider to all clients as broadcast 201 | property string serverUuid: "" 202 | 203 | function sendKaltiotEmbeddedServerMessage(command_msg, msg) { 204 | 205 | var payload = {command: command_msg, server_id : serverUuid}; // e.g. "REQUESTING_TEMPERATURE" 206 | var payload_array = [{"payload_type": "STRING","payload": encodeURI(JSON.stringify(payload))}] 207 | var p = "payload=" + JSON.stringify( payload_array ); 208 | 209 | pushServices.sendMessage(p, "KaltiotService", "", "", "Temperatures"); 210 | } 211 | 212 | // Function to send temperature status message from the embedded client to Kaltiot server: 213 | property string clientUuid :"" 214 | 215 | function embeddedPublishTemperatureToServer(serverUuid, temperature) { 216 | var payload = {command: "TEMPERATURE_INFO", clientId: clientUuid} 217 | var payload_array = [{"payload_type": "STRING","payload": encodeURI(JSON.stringify(payload))}] 218 | var p = "payload=" + JSON.stringify( payload_array ); 219 | 220 | pushServices.sendMessage(p, "KaltiotService", "IOTSensor1", serverUuid,""); 221 | } 222 | //***** FIREBASE 223 | // Function to post msg as a server and broadcast it to all clients in the same room 224 | function sendFirebaseServerMessage(msg){ 225 | var data = {"data": {"message": {"text": msg } }, 226 | "notification": {"body": msg, "title": "Qt Cloud Messaging Chat"}} 227 | 228 | /*! 229 | * \brief SendMessage 230 | * \param msg Message as text which needs to be modified to the provider specific JSON. 231 | * \param providerId Provider name specified at config 232 | * \param localclientId clientId spefied at startup 233 | * \param send_to_device Device Uuid (rid) to send for one known device 234 | * \param send_to_channel Channel name to broadcast message to channel 235 | * \return 236 | */ 237 | 238 | pushServices.sendMessage(JSON.stringify(data), "GoogleFireBase", "MobileClient", "", "ChatRoom"); 239 | } 240 | } 241 | -------------------------------------------------------------------------------- /src/cloudmessagingembeddedkaltiot/android/ks_gw_client_android.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (c) by Kaltiot Oy 2017 4 | ** Copyright (C) 2015 The Qt Company Ltd. 5 | ** Contact: http://www.qt.io/licensing/ 6 | ** 7 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 8 | ** 9 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 10 | ** Commercial License Usage 11 | ** Licensees holding valid commercial Qt licenses may use this file in 12 | ** accordance with the commercial license agreement provided with the 13 | ** Software or, alternatively, in accordance with the terms contained in 14 | ** a written agreement between you and The Qt Company. For licensing terms 15 | ** and conditions see http://www.qt.io/terms-conditions. For further 16 | ** information use the contact form at http://www.qt.io/contact-us. 17 | ** 18 | ** GNU Lesser General Public License Usage 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser 20 | ** General Public License version 3 as published by the Free Software 21 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 22 | ** packaging of this file. Please review the following information to 23 | ** ensure the GNU Lesser General Public License version 3 requirements 24 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 25 | ** 26 | ** $QT_END_LICENSE$ 27 | ** 28 | ****************************************************************************/ 29 | 30 | #ifndef __STATIC_LIBRARY_KS_GW_CLIENT_H__ 31 | #define __STATIC_LIBRARY_KS_GW_CLIENT_H__ 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | #include 38 | #include 39 | 40 | typedef enum { 41 | KS_STATE_OFFLINE, 42 | KS_STATE_DISCONNECTING, 43 | KS_STATE_CONNECTING, 44 | KS_STATE_ONLINE 45 | } KaltiotSmartState; 46 | 47 | typedef enum { 48 | KS_ERROR_NO_ERROR = 0, 49 | KS_ERROR_CONNECT_ERROR, 50 | KS_ERROR_GATEWAY_DISCONNECT, 51 | KS_ERROR_UNKNOWN, 52 | KS_ERROR_CLIENT_DISCONNECT 53 | } KaltiotSmartError; 54 | 55 | typedef enum { 56 | KS_GW_CLIENT_PAYLOAD_BINARY = 1, 57 | KS_GW_CLIENT_PAYLOAD_INT, 58 | KS_GW_CLIENT_PAYLOAD_STRING, 59 | KS_GW_CLIENT_PAYLOAD_PING, 60 | KS_GW_CLIENT_PAYLOAD_PONG 61 | } payload_type_t; 62 | 63 | typedef enum { 64 | NETWORK_STATE_DISABLED, 65 | NETWORK_STATE_MOBILE_2G, 66 | NETWORK_STATE_MOBILE_3G, 67 | NETWORK_STATE_MOBILE_4G, 68 | NETWORK_STATE_MOBILE_5G, 69 | NETWORK_STATE_WIFI, 70 | NETWORK_STATE_COUNT 71 | } network_state_e; 72 | 73 | typedef struct { 74 | void* userdata; 75 | bool connected; 76 | int32_t socket_fd; 77 | void* old_info; 78 | } ks_gw_client_instance_t; 79 | 80 | 81 | /** 82 | * Callback function that is called when a notification is received. You 83 | * should implement this. 84 | * 85 | * If payload_type is KS_CLIENT_PAYLOAD_STRING, KS_CLIENT_PAYLOAD_PING or 86 | * KS_CLIENT_PAYLOAD_PONG, payload and length will include the null 87 | * terminator of the string. 88 | * 89 | * @param address Null-terminated string. 90 | * @param payload Byte data. 91 | * @param payload_length Length of the payload. 92 | * @param payload_type Type of the payload. 93 | * @param msg_id Message id 94 | * @param msg_id_length Message id length 95 | 96 | */ 97 | void ks_gw_client_notification_cb(const char *address, const char *payload, 98 | const uint16_t payload_length, 99 | const payload_type_t payload_type, 100 | const char *msg_id, 101 | const uint16_t msg_id_length); 102 | 103 | /** 104 | * Callback function that is called when a rid is received. You should 105 | * implement this. 106 | * 107 | * @param address Null-terminated string. 108 | * @param rid Null-terminated string. 109 | Unique resource identifier for every iot application 110 | registered to the service. Using this identifier you are 111 | able to send notifications to the application. 112 | * @param secret Null-terminated string. 113 | */ 114 | void ks_gw_client_rid_cb(const char *address, const char *rid, 115 | const char *secret); 116 | 117 | /** 118 | * Callback function that is called when the state of the daemon changes. You 119 | * should implement this. 120 | * 121 | * @param state Status code that tells the new state. 122 | * @param error Possible error code associated with the state. 123 | */ 124 | void ks_gw_client_state_changed_cb(KaltiotSmartState state, KaltiotSmartError error); 125 | 126 | 127 | /** 128 | * Initialize the client instance. Must be the first function to call for new client. 129 | */ 130 | void ks_gw_client_init(ks_gw_client_instance_t *inst); 131 | 132 | /** 133 | * Connects to the daemon. Call this before registering. Returns true if the 134 | * connection has been successfully established. 135 | * 136 | * @param path The path or address to connect to. It is treated as a unix 137 | * domain socket path unless it has a colon in it, in which case 138 | * the IPC will use local TCP on ip:port. You can also leave it 139 | * NULL, then the default path (/tmp/ks_gw_socket) will be 140 | * used. 141 | */ 142 | extern bool ks_gw_client_connect(ks_gw_client_instance_t *inst, const char *path); 143 | 144 | /** 145 | * Disconnects from the daemon. 146 | */ 147 | extern void ks_gw_client_disconnect(ks_gw_client_instance_t *inst); 148 | 149 | /** 150 | * Registers with the daemon. App will start receiving notifications and other 151 | * events. 152 | * 153 | * NOTE: If you need to update the channels, you have to first unregister 154 | * and then register again, with the different channels. 155 | * 156 | * @param address Alphanumeric, null-terminated string. 157 | * @param version Alphanumeric, null-terminated string. 158 | * @param customer_id Alphanumeric, null-terminated string. 159 | Identifier given by customer to the IoT application 160 | registering to Kaltiot Smart Iot. Use this field to identify your 161 | iot application on gateway. It has to be unique for a 162 | given gateway. For example "sensor1". 163 | * @param channels Array of alphanumeric, null-terminated strings that 164 | * represent the channels such as "temperature" or 165 | * "motion". 166 | * @param num_channels The number of channels in the array. 167 | */ 168 | extern void ks_gw_client_register_iot(ks_gw_client_instance_t *inst, 169 | const char *address, 170 | const char *version, 171 | const char *customer_id, 172 | const char **channels, 173 | uint16_t num_channels); 174 | 175 | /** 176 | * Unregisters from the daemon. 177 | * 178 | * @param address Alphanumeric, null-terminated string. 179 | * @param version Alphanumeric, null-terminated string. 180 | * @param customer_id Alphanumeric, null-terminated string. 181 | */ 182 | extern void ks_gw_client_unregister_iot(ks_gw_client_instance_t *inst, 183 | const char *address, 184 | const char *version, 185 | const char *customer_id); 186 | 187 | /** 188 | * Publishes a message to the server. 189 | * 190 | * If payload_type is KS_CLIENT_PAYLOAD_STRING, KS_CLIENT_PAYLOAD_PING or 191 | * KS_CLIENT_PAYLOAD_PONG, payload and length should include the null 192 | * terminator of the string. 193 | * 194 | * @param payload Byte data. 195 | * @param payload_len Length of the payload. 196 | * @param payload_type Type of the payload. 197 | * @param tag Tag of the payload. maximum size could be MAX_TAG_LENGTH 198 | * @return bool true if the parameters are valid else false 199 | */ 200 | extern bool ks_gw_client_publish_message(ks_gw_client_instance_t *inst, 201 | const uint8_t *payload, 202 | const uint16_t payload_len, 203 | const payload_type_t payload_type, 204 | const char* tag); 205 | 206 | /** 207 | * Should be called periodically. It checks whether there is any data waiting 208 | * to be read in the buffer, and based on said data calls the above callbacks. 209 | */ 210 | extern void ks_gw_client_task(ks_gw_client_instance_t *inst); 211 | 212 | /** 213 | * Forces state_changed_cb to be called with the current state. 214 | */ 215 | extern void ks_gw_client_request_state(ks_gw_client_instance_t *inst); 216 | 217 | /** 218 | * Forces rid_cb to be called with the current rid info. 219 | */ 220 | extern void ks_gw_client_request_rid(ks_gw_client_instance_t *inst); 221 | 222 | typedef void (*ks_app_id_callback) (const char *app_id, void *arg); 223 | 224 | /** 225 | * Requests the application id from the daemon. The callback is called with 226 | * the application id and an optional argument that the user can specify. 227 | * 228 | * @param callback Callback function. 229 | * @param arg Optional argument passed to the callback. 230 | */ 231 | extern void ks_gw_client_request_app_id(ks_gw_client_instance_t *inst, 232 | ks_app_id_callback callback, 233 | void *arg); 234 | 235 | /** 236 | * Enables or disables the entire engine. Equivalent to closing the daemon. 237 | * 238 | * @param enabled 239 | */ 240 | extern void ks_gw_client_set_engine_enabled(ks_gw_client_instance_t *inst, bool enabled); 241 | 242 | /** 243 | * Sets the network status. MCC and MNC can be included with a mobile network 244 | * state. 245 | * 246 | * @param state 247 | * @param mcc Can be an empty null-terminated string, not NULL. 248 | * @param mnc Can be an empty null-terminated string, not NULL. 249 | */ 250 | extern void ks_gw_client_set_network_available(ks_gw_client_instance_t *inst, 251 | network_state_e state, 252 | const char *mcc, const char *mnc); 253 | 254 | #ifdef __cplusplus 255 | } 256 | #endif 257 | 258 | #endif 259 | -------------------------------------------------------------------------------- /src/cloudmessaging/qcloudmessagingclient.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #include "qcloudmessagingclient.h" 30 | #include "qcloudmessagingclient_p.h" 31 | 32 | /*! 33 | \class QCloudMessagingClient 34 | \inmodule QtCloudMessaging 35 | \since 5.11 36 | 37 | \brief The QCloudMessagingClient class is a single IoT/embedded or mobile device 38 | providing way to received and send messages either by broadcasting or 39 | by direct connect to other client with known token. 40 | 41 | Implementing specific cloud messaging service client needs inherit this 42 | QCloudMessagingClient class and implement the virtual functions defined in the 43 | header. 44 | 45 | */ 46 | 47 | QT_BEGIN_NAMESPACE 48 | 49 | /*! 50 | * \brief QCloudMessagingClient::QCloudMessagingClient 51 | * QCloudMessagingClient constructor 52 | * 53 | * \param parent 54 | * Parent is QObject 55 | */ 56 | QCloudMessagingClient::QCloudMessagingClient(QObject *parent) : 57 | QObject(parent), 58 | d(new QCloudMessagingClientPrivate) 59 | { 60 | } 61 | 62 | /*! 63 | * \brief QCloudMessagingClient::~QCloudMessagingClient 64 | * Desctructor 65 | */ 66 | QCloudMessagingClient::~QCloudMessagingClient() 67 | { 68 | disconnectClient(); 69 | } 70 | 71 | /*! 72 | * \brief QCloudMessagingClient::connectClient 73 | * Attaches the client into the provider. This is virtual function 74 | * and should be re-implemented in the inheritance for connecting 75 | * the client to real service. 76 | * 77 | * \param clientId 78 | * Mobile or IoT client identification string (defined by user) added for the 79 | * provider 80 | * 81 | * \param parameters 82 | * Client specific parameters in a variant map. 83 | * 84 | * \return 85 | * return given ClientId when successful, empty string if not. 86 | * 87 | */ 88 | QString QCloudMessagingClient::connectClient(const QString &clientId, 89 | const QVariantMap ¶meters) 90 | { 91 | d->m_clientId = clientId; 92 | d->m_clientState = QtCloudMessagingClientConnecting; 93 | d->m_client_parameters = parameters; 94 | 95 | return QString(); 96 | } 97 | 98 | /*! 99 | * \brief QCloudMessagingClient::disconnectClient 100 | * Virtual function to disconnect the client from the service. 101 | * 102 | * \return 103 | * returns the client specific state as integer 104 | */ 105 | void QCloudMessagingClient::disconnectClient() 106 | { 107 | d->m_clientState = QtCloudMessagingClientDisconnecting; 108 | } 109 | 110 | /*! 111 | * \brief QCloudMessagingClient::setClientState 112 | * Sets the client state. This is virtual function and can be 113 | * re-implemented in the inheritance 114 | * 115 | * \param state 116 | * Setting client specific state as integer. 117 | */ 118 | void QCloudMessagingClient::setClientState(int state) 119 | { 120 | d->m_clientState = state; 121 | } 122 | 123 | /*! 124 | * \brief QCloudMessagingClient::clientState 125 | * Gets the client specific state 126 | * 127 | * \return 128 | * Returns clients specific state value as integer. 129 | */ 130 | int QCloudMessagingClient::clientState() 131 | { 132 | return (CloudMessagingClientState) d->m_clientState; 133 | } 134 | 135 | /*! 136 | * \brief QCloudMessagingClient::clientId 137 | * Gets the client id. 138 | * 139 | * \return 140 | * Returns client id as QString 141 | */ 142 | QString QCloudMessagingClient::clientId() 143 | { 144 | return d->m_clientId; 145 | } 146 | 147 | /*! 148 | * \brief QCloudMessagingClient::providerId 149 | * Gets the client's service provider id. 150 | * 151 | * \return 152 | * Returns the provider id as QString. 153 | */ 154 | QString QCloudMessagingClient::providerId() 155 | { 156 | return d->m_providerId; 157 | } 158 | 159 | /*! 160 | * \brief QCloudMessagingClient::setClientId 161 | * Sets the client id 162 | * 163 | * \param clientid 164 | * Client id as QString 165 | * 166 | * \return 167 | * Returns new client id as QString 168 | */ 169 | void QCloudMessagingClient::setClientId(const QString &clientid) 170 | { 171 | d->m_clientId = clientid; 172 | } 173 | 174 | /*! 175 | * \brief QCloudMessagingClient::setProviderId 176 | * Gets the client's service provider id. 177 | * 178 | * \return 179 | * Returns new provider id as QString. 180 | */ 181 | void QCloudMessagingClient::setProviderId(const QString &providerId) 182 | { 183 | d->m_providerId = providerId; 184 | } 185 | 186 | /*! 187 | * \brief QCloudMessagingClient::clientParameters 188 | * Gets the client parameters 189 | * 190 | * \return 191 | * Returns client parameters as QVariantMap 192 | */ 193 | QVariantMap QCloudMessagingClient::clientParameters() 194 | { 195 | return d->m_client_parameters; 196 | } 197 | 198 | // Pure Virtual functions documentation 199 | 200 | /*! 201 | \fn QCloudMessagingClient::flushMessageQueue() 202 | When receiving push messages they can be stored by clients internally. 203 | This function gives developers possibility to do flush commnand for them. 204 | 205 | This is pure virtual function and needs to be implemented in the 206 | inheritance. 207 | 208 | \return 209 | return true when successful, false otherwise. 210 | */ 211 | /*! 212 | \fn QCloudMessagingClient::sendMessage( 213 | const QByteArray &msg, 214 | const QString &clientToken = QString(), 215 | const QString &channel = QString()) 216 | Sends a message to one single client or to subscribed channel. 217 | This is pure virtual function and needs to be implemented in the inheritance. 218 | 219 | \param msg 220 | Message as string which is interpreted to the service specific message 221 | type e.g. json 222 | 223 | \param clientToken 224 | By providing client token, message is targeted straight to client 225 | 226 | \param channel 227 | Channel name if broadcasting the message to channel 228 | 229 | \return 230 | return true when successful, false otherwise. 231 | */ 232 | 233 | /*! 234 | \fn QCloudMessagingClient::setClientToken(const QString &token) 235 | Sets the client token for the client. 236 | This can be used in case of client 237 | token is received otherwise or defined by 238 | API user separately. 239 | 240 | 241 | \param token 242 | Token value as string 243 | */ 244 | 245 | /*! 246 | \fn QCloudMessagingClient::clientToken() 247 | Gets client token (uuid / rid received from the provider services) 248 | 249 | \return 250 | If found returns client token as QString. Returns empty QString otherwise. 251 | */ 252 | 253 | /*! 254 | \fn QCloudMessagingClient::subscribeToChannel( 255 | const QString &channel) 256 | Subscribes client to broadcast channel of the provider service. 257 | This is pure virtual function and needs to be implemented in the 258 | inheritance. 259 | 260 | \param channnel 261 | Channel name as QString 262 | 263 | \return 264 | return true when successful, false otherwise. 265 | */ 266 | 267 | /*! 268 | \fn QCloudMessagingClient::unsubscribeFromChannel( 269 | const QString &channel) 270 | Unsubscribes client from the broadcast channel of the provider service. 271 | This is pure virtual function and needs to be implemented in the 272 | inheritance. 273 | 274 | \param channnel 275 | Channel name as QString 276 | 277 | \return 278 | return true when successful, false otherwise. 279 | */ 280 | 281 | // Signals documentation 282 | /*! 283 | \fn QCloudMessagingClient::clientStateChanged( 284 | const QString &clientId, 285 | int state) 286 | This signal is triggered when the client state has changed 287 | 288 | \param clientId 289 | Client idenfitication string 290 | 291 | \param state 292 | Client State can be either enum from QCloudMessagingClient::CloudMessagingClientState 293 | or it can be client backend specific state. 294 | 295 | */ 296 | 297 | /*! 298 | \fn QCloudMessagingClient::messageReceived(const QString &clientId, 299 | const QByteArray &message) 300 | This signal is triggered when a message is received from the network to client. 301 | 302 | \param clientId 303 | Receiving clientId string 304 | 305 | \param message 306 | Received message as QByteArray. Message content is service specific. 307 | */ 308 | 309 | /*! 310 | \fn QCloudMessagingClient::clientTokenReceived(const QString &token) 311 | This signal is triggered when connected gets the client 312 | token from the service provider. 313 | 314 | \param token 315 | Received token as a QString. 316 | Token is unique identification value used for straight communication 317 | and identification with the client. 318 | */ 319 | 320 | // Enums 321 | /*! 322 | \enum QCloudMessagingClient::CloudMessagingClientState 323 | 324 | This enum type describes types of QCloudMessagingClient connection states. 325 | 326 | \value QtCloudMessgingClientDisconnected Client is disconnected. 327 | \value QtCloudMessagingClientConnecting Client connection started. 328 | \value QtCloudMessagingClientDisconnecting Client disconnection started. 329 | \value QtCloudMessagingClientOffline Client is connected but offline. 330 | \value QtCloudMessagingClientOnline Client is connected and online. 331 | 332 | */ 333 | QT_END_NAMESPACE 334 | -------------------------------------------------------------------------------- /src/cloudmessagingfirebase/qcloudmessagingfirebaseclient.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #include "qcloudmessagingfirebaseclient.h" 30 | #include "qcloudmessagingfirebaseclient_p.h" 31 | 32 | #if defined(Q_OS_ANDROID) 33 | #include 34 | #include 35 | #include 36 | #elif defined(Q_OS_DARWIN) 37 | extern "C" { 38 | #include 39 | } // extern "C" 40 | #endif // __ANDROID__ 41 | 42 | QT_BEGIN_NAMESPACE 43 | 44 | extern void LogMessage(const char *format, ...); 45 | static QCloudMessagingFirebaseClient *m_client_pointer; 46 | 47 | /*! 48 | * \brief QCloudMessagingFirebaseClient::QCloudMessagingFirebaseClient 49 | */ 50 | QCloudMessagingFirebaseClient::QCloudMessagingFirebaseClient(QObject *parent) : 51 | QCloudMessagingClient(parent), 52 | d(new QCloudMessagingFirebaseClientPrivate) 53 | { 54 | } 55 | 56 | /*! 57 | * \brief QCloudMessagingFirebaseClient::~QCloudMessagingFirebaseClient 58 | */ 59 | QCloudMessagingFirebaseClient::~QCloudMessagingFirebaseClient() 60 | { 61 | } 62 | 63 | /*! 64 | * \brief QCloudMessagingFirebaseClient::connectClient 65 | * \param clientId 66 | * \param parameters 67 | * \return 68 | */ 69 | QString QCloudMessagingFirebaseClient::connectClient(const QString &clientId, 70 | const QVariantMap ¶meters) 71 | { 72 | QCloudMessagingClient::connectClient(clientId, parameters); 73 | // Call parent function to setup service ids and states. 74 | 75 | // Setup Firebase app for the client. 76 | #if defined(__ANDROID__) 77 | d->m_firebaseApp = ::firebase::App::Create(::firebase::AppOptions(), QAndroidJniEnvironment(), 78 | QtAndroid::androidActivity().object()); 79 | 80 | #endif 81 | #if defined(__APPLE__) 82 | d->m_firebaseApp = ::firebase::App::Create(::firebase::AppOptions()); 83 | 84 | #endif // defined(__ANDROID__) 85 | m_client_pointer = this; 86 | 87 | d->m_firebase_initializer.Initialize(d->m_firebaseApp, 88 | nullptr, [](::firebase::App * fapp, void *) { 89 | LogMessage("Try to initialize Firebase Messaging"); 90 | return ::firebase::messaging::Initialize( 91 | *fapp, 92 | (::firebase::messaging::Listener *)m_client_pointer); 93 | }); 94 | 95 | while (d->m_firebase_initializer.InitializeLastResult().status() != 96 | firebase::kFutureStatusComplete) { 97 | 98 | LogMessage("Firebase: InitializeLastResult wait..."); 99 | } 100 | 101 | setClientId(clientId); 102 | return clientId; 103 | } 104 | 105 | /*! 106 | * \brief QCloudMessagingFirebaseClient::sendMessage 107 | * \param msg 108 | * \param send_to_device 109 | * \param send_to_channel 110 | * \return 111 | */ 112 | bool QCloudMessagingFirebaseClient::sendMessage(const QByteArray &msg, const QString &clientToken, 113 | const QString &channel) 114 | { 115 | Q_UNUSED(channel) 116 | 117 | ::firebase::messaging::Message message; 118 | 119 | QString message_to = clientToken + "@gcm.googleapis.com"; 120 | 121 | message.to = message_to.toStdString(); 122 | 123 | //TODO: USE Uuid Qt generator 124 | message.message_id = QString("uniqueId" + QString::number(rand() * 10000)).toStdString(); 125 | 126 | //TODO: QString to std map conversion from the input message 127 | Q_UNUSED(msg); 128 | // message.data 129 | 130 | // TODO: Use specific client parameters for time to live 131 | message.time_to_live = 1000000 ;//TIME_TO_LIVE; 132 | ::firebase::messaging::Send(message); 133 | 134 | return true; 135 | } 136 | 137 | /*! 138 | * \brief QCloudMessagingFirebaseClient::disconnectClient 139 | * \return 140 | */ 141 | void QCloudMessagingFirebaseClient::disconnectClient() 142 | { 143 | QCloudMessagingClient::disconnectClient(); 144 | } 145 | 146 | /*! 147 | * \brief QCloudMessagingFirebaseClient::cloudMessageReceived 148 | * \param client 149 | * \param message 150 | */ 151 | void QCloudMessagingFirebaseClient::cloudMessageReceived(const QString &client, 152 | const QByteArray &message) 153 | { 154 | emit messageReceived(client, message); 155 | } 156 | 157 | /*! 158 | * \brief QCloudMessagingFirebaseClient::OnTokenReceived 159 | * \param token 160 | */ 161 | void QCloudMessagingFirebaseClient::OnTokenReceived(const char *token) 162 | { 163 | d->m_token = QString::fromLatin1(token); 164 | } 165 | 166 | /*! 167 | * \brief QCloudMessagingFirebaseClient::OnMessage 168 | * \param message 169 | */ 170 | void QCloudMessagingFirebaseClient::OnMessage(const::firebase::messaging::Message &message) 171 | { 172 | d->m_last_firebase_message = message; 173 | emit messageReceived(clientId(), parseMessage(d->m_last_firebase_message).toUtf8()); 174 | } 175 | 176 | /*! 177 | * \brief QCloudMessagingFirebaseClient::setClientToken 178 | * \param uuid 179 | */ 180 | void QCloudMessagingFirebaseClient::setClientToken(const QString &uuid) 181 | { 182 | d->m_token = uuid; 183 | emit clientTokenReceived(d->m_token); 184 | } 185 | 186 | /*! 187 | * \brief QCloudMessagingFirebaseClient::parseMessage 188 | * \param msg_map 189 | * \return 190 | */ 191 | QString QCloudMessagingFirebaseClient::parseMessage(::firebase::messaging::Message msg_map) 192 | { 193 | QString msg; 194 | msg = QString::fromLatin1("{"); 195 | bool dotSign = false; 196 | 197 | if (!msg_map.from.empty()) { 198 | if (dotSign) msg += QString::fromLatin1(","); 199 | msg += QString::fromLatin1("\"from\":\"") + QString::fromLatin1(msg_map.from.c_str()) + "\""; 200 | dotSign = true; 201 | } 202 | if (!msg_map.error.empty()) { 203 | if (dotSign) msg += QString::fromLatin1(","); 204 | msg += QString::fromLatin1("\"error\":\"") + QString::fromLatin1(msg_map.error.c_str()) + "\""; 205 | dotSign = true; 206 | } 207 | if (!msg_map.message_id.empty()) { 208 | if (dotSign) msg += QString::fromLatin1(","); 209 | msg += QString::fromLatin1("\"message_id\":\"") + QString::fromLatin1( 210 | msg_map.message_id.c_str()) + "\""; 211 | dotSign = true; 212 | } 213 | 214 | if (msg_map.notification) { 215 | 216 | if (dotSign) msg += QString::fromLatin1(","); 217 | 218 | msg += QString::fromLatin1("\"notification\":{"); 219 | 220 | if (msg_map.notification_opened) 221 | msg += QString::fromLatin1("\"notification_opened\":true"); 222 | else 223 | msg += QString::fromLatin1("\"notification_opened\":false"); 224 | 225 | if (!msg_map.notification->title.empty()) 226 | msg += QString::fromLatin1(",\"title\":\"") + QString::fromLatin1( 227 | msg_map.notification->title.c_str()) + QString::fromLatin1("\""); 228 | 229 | if (!msg_map.notification->body.empty()) 230 | msg += QString::fromLatin1(",\"body\":\"") + QString::fromLatin1(msg_map.notification->body.c_str()) 231 | + QString::fromLatin1("\""); 232 | 233 | if (!msg_map.notification->icon.empty()) 234 | msg += QString::fromLatin1(",\"icon\":\"") + QString::fromLatin1(msg_map.notification->icon.c_str()) 235 | + QString::fromLatin1("\""); 236 | 237 | if (!msg_map.notification->tag.empty()) 238 | msg += QString::fromLatin1(",\"tag\":\"") + QString::fromLatin1(msg_map.notification->tag.c_str()) + 239 | QString::fromLatin1("\""); 240 | 241 | if (!msg_map.notification->color.empty()) 242 | msg += QString::fromLatin1(",\"color\":\"") + QString::fromLatin1( 243 | msg_map.notification->color.c_str()) + QString::fromLatin1("\""); 244 | 245 | if (!msg_map.notification->sound.empty()) 246 | msg += QString::fromLatin1(",\"sound\":\"") + QString::fromLatin1( 247 | msg_map.notification->sound.c_str()) + QString::fromLatin1("\""); 248 | 249 | if (!msg_map.notification->click_action.empty()) 250 | msg += QString::fromLatin1(",\"click_action\":\"") + QString::fromLatin1( 251 | msg_map.notification->click_action.c_str()) + QString::fromLatin1("\""); 252 | 253 | msg += QString::fromLatin1("}"); 254 | 255 | dotSign = true; 256 | } 257 | if (msg_map.data.size() > 0) { 258 | if (dotSign) msg += QString::fromLatin1(","); 259 | 260 | dotSign = false; 261 | 262 | msg += QString::fromLatin1("\"data\":{"); 263 | 264 | for (const auto &field : msg_map.data) { 265 | 266 | if (!field.first.empty() && !field.second.empty()) { 267 | if (dotSign) msg += QString::fromLatin1(","); 268 | 269 | msg += QString::fromLatin1("\"") + QString::fromStdString(field.first) + QString::fromLatin1("\":") 270 | + QString::fromStdString(field.second); 271 | 272 | dotSign = true; 273 | } 274 | } 275 | msg += QString::fromLatin1("}"); 276 | } 277 | msg += QString::fromLatin1("}"); 278 | return msg; 279 | } 280 | 281 | /*! 282 | * \brief QCloudMessagingFirebaseClient::flushMessageQueue 283 | * \return 284 | */ 285 | bool QCloudMessagingFirebaseClient::flushMessageQueue() 286 | { 287 | if (!d->m_last_firebase_message.message_id.empty()) { 288 | emit messageReceived(clientId(), parseMessage(d->m_last_firebase_message).toUtf8()); 289 | } 290 | return true; 291 | } 292 | 293 | /*! 294 | * \brief QCloudMessagingFirebaseClient::subscribeToChannel 295 | * \param channel 296 | * \return 297 | */ 298 | bool QCloudMessagingFirebaseClient::subscribeToChannel(const QString &channel) 299 | { 300 | ::firebase::messaging::Subscribe(channel.toLatin1()); 301 | return true; 302 | } 303 | 304 | /*! 305 | * \brief QCloudMessagingFirebaseClient::unsubscribeFromChannel 306 | * \param channel 307 | * \return 308 | */ 309 | bool QCloudMessagingFirebaseClient::unsubscribeFromChannel(const QString &channel) 310 | { 311 | ::firebase::messaging::Unsubscribe(channel.toLatin1()); 312 | return true; 313 | } 314 | 315 | /*! 316 | * \brief QCloudMessagingFirebaseClient::clientToken 317 | * \return 318 | */ 319 | QString QCloudMessagingFirebaseClient::clientToken() 320 | { 321 | return d->m_token; 322 | } 323 | 324 | /*! 325 | * \brief QCloudMessagingFirebaseClient::clientUuid 326 | * \return 327 | */ 328 | QString QCloudMessagingFirebaseClient::clientUuid() 329 | { 330 | return d->m_token; 331 | } 332 | 333 | // Provide link to main - which will be in the app using this service. 334 | extern int main(int argc, char *argv[]); 335 | 336 | QT_END_NAMESPACE 337 | -------------------------------------------------------------------------------- /src/cloudmessagingembeddedkaltiot/qcloudmessagingembeddedkaltiotclient.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #include "qcloudmessagingembeddedkaltiotclient.h" 30 | #include 31 | 32 | #include 33 | 34 | #ifdef ANDROID_OS 35 | #include 36 | #include "jni.h" 37 | #endif 38 | 39 | QT_BEGIN_NAMESPACE 40 | 41 | /*! 42 | * \brief QCloudMessagingEmbeddedKaltiotClient::QCloudMessagingEmbeddedKaltiotClient 43 | * Kaltiot client constructor 44 | */ 45 | QCloudMessagingEmbeddedKaltiotClient::QCloudMessagingEmbeddedKaltiotClient(QObject *parent) : 46 | QCloudMessagingClient(parent), 47 | d(new QCloudMessagingEmbeddedKaltiotClientPrivate) 48 | { 49 | } 50 | 51 | /*! 52 | * \brief QCloudMessagingEmbeddedKaltiotClient::~QCloudMessagingEmbeddedKaltiotClient 53 | * Desctructor 54 | */ 55 | QCloudMessagingEmbeddedKaltiotClient::~QCloudMessagingEmbeddedKaltiotClient() 56 | { 57 | // if thread is running, ask for exit it first and then terminate thread 58 | if (d->m_running && d->m_clientThread.isRunning()) { 59 | d->m_running = false; 60 | d->m_clientThread.quit(); 61 | d->m_clientThread.terminate(); 62 | } 63 | } 64 | 65 | /*! 66 | * \brief QCloudMessagingEmbeddedKaltiotClient::connectClient 67 | * \param clientId 68 | * \param parameters 69 | * \return 70 | */ 71 | QString QCloudMessagingEmbeddedKaltiotClient::connectClient(const QString &clientId, 72 | const QVariantMap ¶meters) 73 | { 74 | // Call parent function to setup service ids and states. 75 | QCloudMessagingClient::connectClient(clientId, parameters); 76 | 77 | QStringList channels; 78 | QVariantMap params = parameters; 79 | d->m_address = params.value(QStringLiteral("address")).toString(); 80 | d->m_version = params.value(QStringLiteral("version")).toString(); 81 | d->m_customer_id = params.value(QStringLiteral("customer_id")).toString(); 82 | d->daemonIpcPath = params.value(QStringLiteral("kaltiot_daemon_path")).toString(); 83 | 84 | channels = params.value(QStringLiteral("channels")).toStringList(); 85 | 86 | for (int i = 0; i < channels.count(); i++) { 87 | bool new_channel = true; 88 | for (int j = 0; j < d->m_channels.count(); j++) { 89 | if (channels[i] == d->m_channels[j]) 90 | new_channel = false; 91 | } 92 | if (new_channel) { 93 | d->m_channels.append(channels[i]); 94 | } 95 | } 96 | 97 | setClientToken(clientId); 98 | 99 | if (!make_kaltiot_client_registration()) 100 | return QString(); 101 | 102 | runBackgroundThread(); 103 | return d->m_address; 104 | } 105 | 106 | /*! 107 | * \brief QCloudMessagingEmbeddedKaltiotClient::runBackgroundThread 108 | */ 109 | void QCloudMessagingEmbeddedKaltiotClient::runBackgroundThread() 110 | { 111 | this->moveToThread(&d->m_clientThread); 112 | d->m_clientThread.start(); 113 | 114 | // Run service task in the thread. 115 | connect(&(d->m_threadTimer), &QTimer::timeout, [ = ] { 116 | 117 | if (!d->m_running) d->m_running = true; 118 | #ifdef EMBEDDED_AND_DESKTOP_OS 119 | ks_gw_client_task(&d->m_kaltiot_client_instance); 120 | #endif 121 | d->m_threadTimer.start(); 122 | }); 123 | 124 | d->m_threadTimer.setInterval(1); 125 | d->m_threadTimer.start(); 126 | } 127 | 128 | /*! 129 | * \brief QCloudMessagingEmbeddedKaltiotClient::make_kaltiot_client_registration 130 | */ 131 | bool QCloudMessagingEmbeddedKaltiotClient::make_kaltiot_client_registration() 132 | { 133 | #ifdef EMBEDDED_AND_DESKTOP_OS 134 | 135 | char const *channels[d->m_channels.count()]; 136 | QList constChannels; 137 | 138 | for (int i = 0; i < d->m_channels.count(); i++) { 139 | constChannels.append(d->m_channels[i].toLatin1()); 140 | channels[i] = constChannels[constChannels.count()-1].constData(); 141 | } 142 | 143 | uint16_t num_channels = d->m_channels.count(); 144 | 145 | ks_gw_client_init(&d->m_kaltiot_client_instance); 146 | 147 | const char *connectPath = nullptr; 148 | QByteArray daemonIpcByteArray = d->daemonIpcPath.toLatin1(); 149 | if (!daemonIpcByteArray.isEmpty()) 150 | connectPath = daemonIpcByteArray.constData(); 151 | 152 | if (!ks_gw_client_connect(&d->m_kaltiot_client_instance, connectPath)) 153 | return false; // Failed to connect!; 154 | 155 | if (d->m_rid.isEmpty()) { 156 | d->m_rid = d->m_client_settings.value("clients/" + d->m_address + "/rid").toString(); 157 | } 158 | 159 | if (!d->m_rid.isEmpty()) 160 | setClientToken(d->m_rid); 161 | 162 | ks_gw_client_set_engine_enabled(&d->m_kaltiot_client_instance, true); 163 | 164 | ks_gw_client_set_network_available(&d->m_kaltiot_client_instance, 165 | NETWORK_STATE_MOBILE_2G, "123","45"); 166 | 167 | ks_gw_client_register_iot(&d->m_kaltiot_client_instance, 168 | d->m_address.toLatin1().constData(), 169 | d->m_version.toLatin1().constData(), 170 | d->m_customer_id.toLatin1().constData(), 171 | channels, num_channels); 172 | 173 | ks_gw_client_request_rid(&d->m_kaltiot_client_instance); 174 | 175 | constChannels.clear(); 176 | 177 | #endif 178 | 179 | #ifdef ANDROID_OS 180 | 181 | QAndroidJniObject j_rid = QtAndroid::androidActivity().callObjectMethod("get_rid"); 182 | 183 | d->m_rid = j_rid.toString(); 184 | if (d->m_rid.isEmpty()) { 185 | d->m_rid = d->m_client_settings.value("clients/" + d->m_address + "/rid").toString(); 186 | 187 | } 188 | if (!d->m_rid.isEmpty()) 189 | setClientToken(d->m_rid); 190 | 191 | #endif 192 | return true; 193 | } 194 | 195 | /*! 196 | * \brief QCloudMessagingEmbeddedKaltiotClient::sendMessage 197 | * \param msg 198 | * \param send_to_device 199 | * \param send_to_channel 200 | * \return 201 | */ 202 | bool QCloudMessagingEmbeddedKaltiotClient::sendMessage(const QByteArray &msg, 203 | const QString &clientToken, 204 | const QString &channel) 205 | { 206 | // In Kaltiot client send message goes via client daemon and channel or 207 | // clientToken attributes are not used. 208 | Q_UNUSED(channel); 209 | Q_UNUSED(clientToken); 210 | 211 | 212 | #ifdef EMBEDDED_AND_DESKTOP_OS 213 | // TAG NOT USED ATM. 214 | ks_gw_client_publish_message(&d->m_kaltiot_client_instance, 215 | (const uint8_t *)msg.constData(), 216 | msg.size(), 217 | KS_GW_CLIENT_PAYLOAD_STRING, 218 | nullptr); 219 | #endif 220 | 221 | return true; 222 | } 223 | 224 | /*! 225 | * \brief QCloudMessagingEmbeddedKaltiotClient::disconnectClient 226 | * \return 227 | */ 228 | void QCloudMessagingEmbeddedKaltiotClient::disconnectClient() 229 | { 230 | QCloudMessagingClient::disconnectClient(); 231 | 232 | d->m_running = false; 233 | #ifdef EMBEDDED_AND_DESKTOP_OS 234 | ks_gw_client_unregister_iot(&d->m_kaltiot_client_instance, d->m_address.toLatin1(), 235 | d->m_version.toLatin1(), clientToken().toLatin1()); 236 | ks_gw_client_disconnect(&d->m_kaltiot_client_instance); 237 | ks_gw_client_set_engine_enabled(&d->m_kaltiot_client_instance, false); 238 | #endif 239 | } 240 | 241 | /*! 242 | * \brief QCloudMessagingEmbeddedKaltiotClient::cloudMessageReceived 243 | * \param client 244 | * \param message 245 | */ 246 | void QCloudMessagingEmbeddedKaltiotClient::cloudMessageReceived(const QString &client, 247 | const QByteArray &message) 248 | { 249 | emit messageReceived(client, message); 250 | } 251 | 252 | /*! 253 | * \brief QCloudMessagingEmbeddedKaltiotClient::setClientToken 254 | * \param token 255 | */ 256 | void QCloudMessagingEmbeddedKaltiotClient::setClientToken(const QString &token) 257 | { 258 | d->m_rid = token; 259 | if (!d->m_rid.isEmpty()) 260 | d->m_client_settings.setValue("clients/" + d->m_address + "/rid", d->m_rid); 261 | 262 | emit clientTokenReceived(d->m_rid); 263 | } 264 | 265 | /*! 266 | * \brief QCloudMessagingEmbeddedKaltiotClient::clientToken 267 | * \return 268 | */ 269 | QString QCloudMessagingEmbeddedKaltiotClient::clientToken() 270 | { 271 | return d->m_rid; 272 | } 273 | 274 | /*! 275 | * \brief QCloudMessagingEmbeddedKaltiotClient::getKaltiotEngineInstance 276 | * \return 277 | */ 278 | ks_gw_client_instance_t *QCloudMessagingEmbeddedKaltiotClient::getKaltiotEngineInstance() 279 | { 280 | return &d->m_kaltiot_client_instance; 281 | } 282 | 283 | /*! 284 | * \brief QCloudMessagingEmbeddedKaltiotClient::subscribeToChannel 285 | * * Unsubscribes client from the channel 286 | * 287 | * \param channel 288 | * * Channel name QString 289 | * 290 | * \return 291 | * false if channel not found, true if found and updated 292 | */ 293 | bool QCloudMessagingEmbeddedKaltiotClient::subscribeToChannel(const QString &channel) 294 | { 295 | 296 | for (int i = 0; i < d->m_channels.count(); i++) { 297 | if (channel == d->m_channels[i]) 298 | return false; // Already subscribed 299 | } 300 | 301 | // Not found, lets add new channel and restart client. 302 | d->m_channels.append(channel); 303 | 304 | disconnectClient(); 305 | connectClient(clientToken(), clientParameters()); 306 | 307 | return true; 308 | } 309 | 310 | /*! 311 | * \brief QCloudMessagingEmbeddedKaltiotClient::unsubscribeFromChannel 312 | * Unsubscribes client from the channel 313 | * 314 | * \param channel 315 | * Channel name QString 316 | * 317 | * \return 318 | * false if channel not found, true if found and updated 319 | */ 320 | bool QCloudMessagingEmbeddedKaltiotClient::unsubscribeFromChannel(const QString &channel) 321 | { 322 | 323 | for (int i = 0; i < d->m_channels.count(); i++) { 324 | if (channel == d->m_channels[i]) { 325 | d->m_channels.removeAt(i); 326 | 327 | disconnectClient(); 328 | connectClient(clientToken(), clientParameters()); 329 | 330 | return true; 331 | } 332 | } 333 | return false; // Not found 334 | 335 | 336 | } 337 | 338 | /*! 339 | * \brief QCloudMessagingEmbeddedKaltiotClient::flushMessageQueue 340 | * \return 341 | */ 342 | bool QCloudMessagingEmbeddedKaltiotClient::flushMessageQueue() 343 | { 344 | return true; 345 | } 346 | 347 | // Provide link to main - which will be in the app using this service. 348 | extern int main(int argc, char *argv[]); 349 | 350 | QT_END_NAMESPACE 351 | -------------------------------------------------------------------------------- /src/cloudmessaging/qcloudmessaging.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the QtCloudMessaging module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL3-COMM$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 3 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 3 requirements 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. 24 | ** 25 | ** $QT_END_LICENSE$ 26 | ** 27 | ****************************************************************************/ 28 | 29 | #include "qcloudmessaging.h" 30 | #include "qcloudmessaging_p.h" 31 | #include 32 | 33 | 34 | /*! 35 | \class QCloudMessaging 36 | \inmodule QtCloudMessaging 37 | \since 5.11 38 | 39 | \brief The QtCloudMessaging module implements Qt wrapper API for multiple 40 | cloud messaging and cloud service providers. The QtCloudMessaging module 41 | can be easily extended to support private clouds or existing cloud 42 | providers. 43 | 44 | The QtCloudMessaging module currently has Google 45 | Firebase Cloud Messaging and Kaltiot IoT push messaging backends to 46 | get started with IoT or mobile cloud development. 47 | 48 | QCloudMessaging class enables registering of cloud messaging 49 | provider backends and backend clients. 50 | 51 | Cloud messaging providers and clients implement virtual functions which 52 | subscribe or unsubscribe to cloud messaging channels and receive or send 53 | messages to servers and to other clients. 54 | 55 | \list 56 | \li To create new cloud messaging service provider and client: 57 | \list 58 | \li Inherit the QCloudMessagingProvider class and implement the virtual 59 | functions. 60 | \li Inherit the QCloudMessagingClient class and implement the virtual 61 | functions. 62 | \endlist 63 | \endlist 64 | 65 | */ 66 | 67 | QT_BEGIN_NAMESPACE 68 | 69 | /*! 70 | * \brief QCloudMessaging::QCloudMessaging 71 | * QCloudMessaging constructor 72 | * 73 | * \param parent 74 | * Parent is QObject 75 | */ 76 | QCloudMessaging::QCloudMessaging(QObject *parent) : 77 | QObject(parent), d(new QCloudMessagingPrivate) 78 | { 79 | } 80 | /*! 81 | * \brief QCloudMessaging::~QCloudMessaging 82 | */ 83 | QCloudMessaging::~QCloudMessaging() 84 | { 85 | } 86 | 87 | /*! 88 | * \brief registerProvider 89 | * Registers the service provider that handles service clients and can be used 90 | * for server side development. 91 | * 92 | * \param providerId 93 | * Provider identification string that is defined by the user when using the 94 | * API. 95 | * 96 | * \param provider 97 | * Use case specific provider object that can handle the communication as a 98 | * server and can have multiple internal and external clients. 99 | * 100 | * \param parameters 101 | * Provider specific parameters in a variant map. 102 | * 103 | * \return 104 | * true if register succeeds, false if fails. 105 | */ 106 | bool QCloudMessaging::registerProvider(const QString &providerId, 107 | QCloudMessagingProvider *provider, 108 | const QVariantMap ¶meters) 109 | { 110 | bool return_value = false; 111 | // If this is duplicate service name 112 | if (!d->m_cloudProviders.contains(providerId)) { 113 | d->m_cloudProviders.insert(providerId, provider); 114 | 115 | connect(provider, &QCloudMessagingProvider::messageReceived, 116 | this, &QCloudMessaging::messageReceived); 117 | 118 | connect(provider, &QCloudMessagingProvider::serviceStateUpdated, 119 | this, &QCloudMessaging::serviceStateUpdated); 120 | 121 | connect(provider, &QCloudMessagingProvider::remoteClientsReceived, 122 | this, &QCloudMessaging::remoteClientsReceived); 123 | 124 | connect(provider, &QCloudMessagingProvider::clientTokenReceived, 125 | this, &QCloudMessaging::clientTokenReceived); 126 | 127 | return_value = d->m_cloudProviders[providerId]-> 128 | registerProvider(providerId,parameters); 129 | } else { 130 | return_value = d->m_cloudProviders[providerId]->getServiceState(); 131 | } 132 | 133 | return return_value; 134 | } 135 | 136 | /*! 137 | * \brief connectClient 138 | * Attaches the client into the provider 139 | * 140 | * \param providerId 141 | * Provider identification string that is defined by the user when using the 142 | * API 143 | * 144 | * \param clientId 145 | * Mobile or IoT client identification string (defined by user) added for the 146 | * provider 147 | * 148 | * \param parameters 149 | * Client specific parameters in a variant map. 150 | * 151 | * \return 152 | * return given ClientId when succeeds, empty string if not. 153 | * 154 | */ 155 | QString QCloudMessaging::connectClient(const QString &providerId, 156 | const QString &clientId, 157 | const QVariantMap ¶meters) 158 | { 159 | if (d->m_cloudProviders.contains(providerId)) 160 | return d->m_cloudProviders[providerId]->connectClient(clientId, 161 | parameters); 162 | 163 | return QString(); 164 | } 165 | 166 | /*! 167 | * \brief sendMessage 168 | * Sends a message to one single client or or to a subscribed channel 169 | * 170 | * \param msg 171 | * Service specific message. Usually JSON string. 172 | * 173 | * \param providerId 174 | * Provider identification string that is defined by the user when using 175 | * the API 176 | * 177 | * \param clientId 178 | * Mobile or IoT client identification string (defined by user) added for 179 | * the provider 180 | * 181 | * \param clientToken 182 | * By providing client token, message is targeted straight to client 183 | * 184 | * \param channel 185 | * Channel name if broadcasting the message to channel 186 | * 187 | * \return 188 | * return true when succeeds, false otherwise. 189 | */ 190 | bool QCloudMessaging::sendMessage(const QByteArray &msg, 191 | const QString &providerId, 192 | const QString &clientId, 193 | const QString &clientToken, 194 | const QString &channel) 195 | { 196 | 197 | if (d->m_cloudProviders.contains(providerId)) 198 | return d->m_cloudProviders[providerId]->sendMessage(msg, 199 | clientId, 200 | clientToken, 201 | channel); 202 | 203 | return false; 204 | } 205 | 206 | 207 | /*! 208 | * \brief disconnectClient 209 | * Disconnects the client from the provider 210 | * 211 | * \param providerId 212 | * Provider identification string that is defined by the user when using the 213 | * API 214 | * 215 | * \param clientId 216 | * Mobile or IoT client identification string (defined by user) added for the 217 | * provider 218 | * 219 | * \param parameters 220 | * Client specific parameters in a variant map. 221 | */ 222 | void QCloudMessaging::disconnectClient(const QString &providerId, 223 | const QString &clientId, 224 | const QVariantMap ¶meters) 225 | { 226 | if (d->m_cloudProviders.contains(providerId)) 227 | d->m_cloudProviders[providerId]->disconnectClient(clientId, 228 | parameters); 229 | } 230 | 231 | /*! 232 | * \brief removeClient 233 | * Removes client from the provider 234 | * 235 | * \param providerId 236 | * Provider identification string that is defined by the user when using the 237 | * API 238 | * 239 | * \param clientId 240 | * Mobile or IoT client identification string (defined by user) added for the 241 | * provider 242 | */ 243 | void QCloudMessaging::removeClient(const QString &providerId, 244 | const QString &clientId) 245 | { 246 | if (d->m_cloudProviders.contains(providerId)) 247 | d->m_cloudProviders[providerId]->removeClient(clientId); 248 | 249 | } 250 | 251 | /*! 252 | * \brief deRegisterProvider 253 | * Closes down the provider and disconnects clients. 254 | * 255 | * \param providerId 256 | * Povider identification string that is defined by the user when using the 257 | * API 258 | */ 259 | void QCloudMessaging::deregisterProvider(const QString &providerId) 260 | { 261 | if (d->m_cloudProviders.contains(providerId)) { 262 | disconnect(d->m_cloudProviders[providerId]); 263 | 264 | d->m_cloudProviders[providerId]->deregisterProvider(); 265 | d->m_cloudProviders.remove(providerId); 266 | 267 | } 268 | } 269 | 270 | /*! 271 | * \brief localClients 272 | * If system has multiple clients connected at the same app process, one can 273 | * request the 274 | * list of available clientIds from the provider class. 275 | * 276 | * \param providerId 277 | * Provider identification string that is defined by the user when using the 278 | * API 279 | * 280 | * \return 281 | * List of ClientIds as QStringList. 282 | */ 283 | const QStringList QCloudMessaging::localClients(const QString &providerId) 284 | { 285 | if (d->m_cloudProviders.contains(providerId)) 286 | return d->m_cloudProviders[providerId]->clients()->keys(); 287 | 288 | return QStringList(); 289 | } 290 | 291 | /*! 292 | * \brief requestRemoteClients 293 | * Uses provider rest api interface to request all the remote clients 294 | * connected to provider service. 295 | * This can be used e.g. in server implementation or if creating 296 | * client dashboard etc. 297 | * 298 | * \param providerId 299 | * Provider identification string that is defined by the user when 300 | * using the API 301 | * 302 | * \return 303 | * true if sending request via rest api succeeds, fail if not. 304 | */ 305 | bool QCloudMessaging::requestRemoteClients(const QString &providerId) 306 | { 307 | if (d->m_cloudProviders.contains(providerId)) { 308 | return d->m_cloudProviders[providerId]->remoteClients(); 309 | } 310 | 311 | return false; 312 | } 313 | 314 | /*! 315 | * \brief clientToken 316 | * Gets client token (uuid / rid received from the provider services) 317 | * 318 | * \param providerI 319 | * Provider identification string that is defined by the user when using 320 | * the API 321 | * 322 | * \param clientId 323 | * Mobile or IoT client identification string (defined by user) added for 324 | * the provider 325 | * 326 | * \return 327 | * If found returns client token as QString. Returns empty QString otherwise. 328 | */ 329 | QString QCloudMessaging::clientToken(const QString &providerId, 330 | const QString &clientId) 331 | { 332 | if (d->m_cloudProviders.contains(providerId)) 333 | return d->m_cloudProviders[providerId]->clientToken(clientId); 334 | 335 | return QString(); 336 | } 337 | 338 | /*! 339 | * \brief setClientToken 340 | * Sets the client token for the client. 341 | * This can be used in case of client 342 | * token is received otherwise or defined by 343 | * API user separately. 344 | * 345 | * \param providerId 346 | * Provider identification string that is defined by the user when using the 347 | * API 348 | * 349 | * \param clientId 350 | * Mobile or IoT client identification string (defined by user) added for the 351 | * provider 352 | * 353 | * \param token 354 | * Token value as string 355 | */ 356 | void QCloudMessaging::setClientToken(const QString &providerId, 357 | const QString &clientId, 358 | const QString &token) 359 | { 360 | if (d->m_cloudProviders.contains(providerId)) 361 | return d->m_cloudProviders[providerId]-> 362 | client(clientId)->setClientToken(token); 363 | } 364 | 365 | /*! 366 | * \brief QCloudMessaging::subscribeToChannel 367 | * Subscribing the client to the channel 368 | * 369 | * \param channel 370 | * Channel name as string, cannot be empty 371 | * 372 | * \param providerId 373 | * Provider identification string that is defined by the user when using the API 374 | * 375 | * \param clientId 376 | * Mobile or IoT client identification string (defined by user) added for 377 | * the provider 378 | * 379 | * \return 380 | * true if succeeds, false if not. 381 | */ 382 | bool QCloudMessaging::subscribeToChannel(const QString &channel, 383 | const QString &providerId, 384 | const QString &clientId) 385 | { 386 | if (!d->m_cloudProviders.contains(providerId)) 387 | return false; 388 | 389 | if (!clientId.isEmpty()) 390 | { 391 | return d->m_cloudProviders[providerId]->client(clientId)-> 392 | subscribeToChannel(channel); 393 | } else 394 | { 395 | return d->m_cloudProviders[providerId]->subscribeToChannel(channel, 396 | clientId); 397 | } 398 | } 399 | 400 | /*! 401 | * \brief unsubscribeFromChannel 402 | * Unsubscribing the client from the channel 403 | * 404 | * \param channel 405 | * Channel name as string, cannot be empty 406 | * 407 | * \param providerId 408 | * Provider identification string that is defined by the user when using the 409 | * API 410 | * 411 | * \param clientId 412 | * Mobile or IoT client identification string (defined by user) added for the 413 | * provider 414 | * 415 | * \return 416 | * true if succeeds, false if not. 417 | */ 418 | bool QCloudMessaging::unsubscribeFromChannel(const QString &channel, 419 | const QString &providerId, 420 | const QString &clientId) 421 | { 422 | if (!d->m_cloudProviders.contains(providerId)) 423 | return false; 424 | 425 | if (!clientId.isEmpty()) 426 | { 427 | return d->m_cloudProviders[providerId]->client(clientId)-> 428 | unsubscribeFromChannel(channel); 429 | } else 430 | { 431 | return d->m_cloudProviders[providerId]->unsubscribeFromChannel(channel, 432 | clientId); 433 | } 434 | } 435 | 436 | /*! 437 | * \brief flushMessageQueue 438 | * When receiving push messages they can be stored by clients internally. 439 | * This function gives developers possibility to do flush commnand for them . 440 | * 441 | * \param providerId 442 | * Provider identification string that is defined by the user when using the 443 | * API 444 | * 445 | * \return 446 | * true if succeeds, false if not 447 | */ 448 | void QCloudMessaging::flushMessageQueue(const QString &providerId) 449 | { 450 | if (d->m_cloudProviders.contains(providerId)) 451 | d->m_cloudProviders[providerId]->flushMessageQueue(); 452 | } 453 | 454 | // Signals documentation 455 | /*! 456 | \fn QCloudMessaging::clientTokenReceived(const QString &token) 457 | This signal is triggered when connected gets the client 458 | token from the service provider. 459 | 460 | \param token 461 | Received token as a QString. 462 | Token is unique identification value used for straight communication 463 | and identification with the client. 464 | */ 465 | 466 | /*! 467 | \fn QCloudMessaging::messageReceived(const QString &providerId, 468 | const QString &clientId, 469 | const QByteArray &message) 470 | This signal is triggered when a message is received from the network to client. 471 | 472 | \param providerId 473 | Receiving Provider identification string 474 | 475 | \param clientId 476 | Receiving clientId string 477 | 478 | \param message 479 | Received message as QByteArray. Message is service specific. 480 | */ 481 | 482 | /*! 483 | \fn QCloudMessaging::remoteClientsReceived(const QString &clients) 484 | This signal is triggered when the return value for requestRemoteClients 485 | function is is received. 486 | \param response 487 | Response data is based on the service and can be e.g. a list 488 | of client tokens in QString format. 489 | */ 490 | 491 | /*! 492 | \fn QCloudMessaging::serviceStateUpdated(int state) 493 | This signal is triggered when the service provider registered 494 | state has changed. 495 | 496 | \param state 497 | State can be one of the enums from the QCloudMessagingProvider 498 | 499 | */ 500 | 501 | QT_END_NAMESPACE 502 | --------------------------------------------------------------------------------