summaryrefslogtreecommitdiff
path: root/src/components/qt_hmi
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/qt_hmi')
-rw-r--r--src/components/qt_hmi/References/Work/bananasnacks/main.cpp15
-rw-r--r--src/components/qt_hmi/References/Work/bananasnacks/qtquick2applicationviewer/qtquick2applicationviewer.cpp66
-rw-r--r--src/components/qt_hmi/References/Work/bananasnacks/qtquick2applicationviewer/qtquick2applicationviewer.h26
-rw-r--r--src/components/qt_hmi/References/Work/fordsdlcore/QtWebsocket/QWsServer.cpp764
-rw-r--r--src/components/qt_hmi/References/Work/fordsdlcore/QtWebsocket/QWsServer.h137
-rw-r--r--src/components/qt_hmi/References/Work/fordsdlcore/QtWebsocket/QWsSocket.cpp1477
-rw-r--r--src/components/qt_hmi/References/Work/fordsdlcore/QtWebsocket/QWsSocket.h325
-rw-r--r--src/components/qt_hmi/References/Work/fordsdlcore/fordsdlcore_plugin.cpp29
-rw-r--r--src/components/qt_hmi/References/Work/fordsdlcore/fordsdlcore_plugin.h16
-rw-r--r--src/components/qt_hmi/References/Work/fordsdlcore/sdlalert.cpp5
-rw-r--r--src/components/qt_hmi/References/Work/fordsdlcore/sdlalert.h18
-rw-r--r--src/components/qt_hmi/References/Work/fordsdlcore/sdlappslistmodel.cpp6
-rw-r--r--src/components/qt_hmi/References/Work/fordsdlcore/sdlappslistmodel.h74
-rw-r--r--src/components/qt_hmi/References/Work/fordsdlcore/smartdevicelink.cpp497
-rw-r--r--src/components/qt_hmi/References/Work/fordsdlcore/smartdevicelink.h111
-rw-r--r--src/components/qt_hmi/qml_plugins/dbus_adapter/dbus_controller.cc26
-rw-r--r--src/components/qt_hmi/qml_plugins/dbus_adapter/dbus_controller.h8
-rw-r--r--src/components/qt_hmi/qml_plugins/dbus_adapter/dbus_plugin.cc24
-rw-r--r--src/components/qt_hmi/qml_plugins/dbus_adapter/dbus_plugin.h13
-rw-r--r--src/components/qt_hmi/qml_plugins/dbus_adapter/hmi_proxy.cc3
-rw-r--r--src/components/qt_hmi/qml_plugins/dbus_adapter/hmi_proxy.h7
-rw-r--r--src/components/qt_hmi/qml_plugins/dbus_adapter/metatype.h10
-rw-r--r--src/components/qt_hmi/qml_plugins/dbus_adapter/optional_argument.h28
-rw-r--r--src/components/qt_hmi/qml_plugins/dbus_adapter/qml_dbus_common.h135
-rw-r--r--src/components/qt_hmi/qml_plugins/dbus_adapter/qt_version.h11
-rw-r--r--src/components/qt_hmi/qml_plugins/dbus_adapter/stream_qvariant.cc50
-rw-r--r--src/components/qt_hmi/qml_plugins/hw_buttons/attributed_mouse_event.cc4
-rw-r--r--src/components/qt_hmi/qml_plugins/hw_buttons/attributed_mouse_event.h10
-rw-r--r--src/components/qt_hmi/qml_plugins/hw_buttons/hmi_hwbuttons.cc8
-rw-r--r--src/components/qt_hmi/qml_plugins/hw_buttons/hmi_hwbuttons.h7
-rw-r--r--src/components/qt_hmi/qml_plugins/hw_buttons/masked_container.cc110
-rw-r--r--src/components/qt_hmi/qml_plugins/hw_buttons/masked_container.h18
-rw-r--r--src/components/qt_hmi/qml_plugins/hw_buttons/qt_version.h11
-rw-r--r--src/components/qt_hmi/qml_plugins/log4cxx/log4cxx_plugin.cc78
-rw-r--r--src/components/qt_hmi/qml_plugins/log4cxx/log4cxx_plugin.h23
-rw-r--r--src/components/qt_hmi/qml_plugins/named_pipe_notifier/named_pipe_notifier.cc9
-rw-r--r--src/components/qt_hmi/qml_plugins/named_pipe_notifier/named_pipe_notifier.h6
-rw-r--r--src/components/qt_hmi/qml_plugins/named_pipe_notifier/named_pipe_notifier_plugin.cc8
-rw-r--r--src/components/qt_hmi/qml_plugins/named_pipe_notifier/named_pipe_notifier_plugin.h4
-rw-r--r--src/components/qt_hmi/qml_plugins/named_pipe_notifier/qt_version.h11
40 files changed, 2144 insertions, 2044 deletions
diff --git a/src/components/qt_hmi/References/Work/bananasnacks/main.cpp b/src/components/qt_hmi/References/Work/bananasnacks/main.cpp
index faa3f175be..bb40110e13 100644
--- a/src/components/qt_hmi/References/Work/bananasnacks/main.cpp
+++ b/src/components/qt_hmi/References/Work/bananasnacks/main.cpp
@@ -2,16 +2,15 @@
#include <QQmlContext>
#include "qtquick2applicationviewer.h"
-int main(int argc, char *argv[])
-{
- QGuiApplication app(argc, argv);
+int main(int argc, char* argv[]) {
+ QGuiApplication app(argc, argv);
- QtQuick2ApplicationViewer viewer;
+ QtQuick2ApplicationViewer viewer;
- viewer.addImportPath(QStringLiteral("plugins"));
+ viewer.addImportPath(QStringLiteral("plugins"));
- viewer.setMainQmlFile(QStringLiteral("qml/Bananas/main.qml"));
- viewer.showExpanded();
+ viewer.setMainQmlFile(QStringLiteral("qml/Bananas/main.qml"));
+ viewer.showExpanded();
- return app.exec();
+ return app.exec();
}
diff --git a/src/components/qt_hmi/References/Work/bananasnacks/qtquick2applicationviewer/qtquick2applicationviewer.cpp b/src/components/qt_hmi/References/Work/bananasnacks/qtquick2applicationviewer/qtquick2applicationviewer.cpp
index 547602d83c..8fcc4a6d38 100644
--- a/src/components/qt_hmi/References/Work/bananasnacks/qtquick2applicationviewer/qtquick2applicationviewer.cpp
+++ b/src/components/qt_hmi/References/Work/bananasnacks/qtquick2applicationviewer/qtquick2applicationviewer.cpp
@@ -1,7 +1,8 @@
// checksum 0x56a9 version 0x80001
/*
This file was generated by the Qt Quick 2 Application wizard of Qt Creator.
- QtQuick2ApplicationViewer is a convenience class containing mobile device specific
+ QtQuick2ApplicationViewer is a convenience class containing mobile device
+ specific
code such as screen orientation handling. Also QML paths and debugging are
handled here.
It is recommended not to modify this file, since newer versions of Qt Creator
@@ -14,57 +15,50 @@
#include <QtCore/QDir>
#include <QtQml/QQmlEngine>
-class QtQuick2ApplicationViewerPrivate
-{
- QString mainQmlFile;
- friend class QtQuick2ApplicationViewer;
- static QString adjustPath(const QString &path);
+class QtQuick2ApplicationViewerPrivate {
+ QString mainQmlFile;
+ friend class QtQuick2ApplicationViewer;
+ static QString adjustPath(const QString& path);
};
-QString QtQuick2ApplicationViewerPrivate::adjustPath(const QString &path)
-{
+QString QtQuick2ApplicationViewerPrivate::adjustPath(const QString& path) {
#if defined(Q_OS_MAC)
- if (!QDir::isAbsolutePath(path))
- return QString::fromLatin1("%1/../Resources/%2")
- .arg(QCoreApplication::applicationDirPath(), path);
+ if (!QDir::isAbsolutePath(path))
+ return QString::fromLatin1("%1/../Resources/%2")
+ .arg(QCoreApplication::applicationDirPath(), path);
#elif defined(Q_OS_UNIX)
- const QString pathInInstallDir =
- QString::fromLatin1("%1/../%2").arg(QCoreApplication::applicationDirPath(), path);
- if (QFileInfo(pathInInstallDir).exists())
- return pathInInstallDir;
+ const QString pathInInstallDir =
+ QString::fromLatin1("%1/../%2")
+ .arg(QCoreApplication::applicationDirPath(), path);
+ if (QFileInfo(pathInInstallDir).exists())
+ return pathInInstallDir;
#endif
- return path;
+ return path;
}
-QtQuick2ApplicationViewer::QtQuick2ApplicationViewer(QWindow *parent)
- : QQuickView(parent)
- , d(new QtQuick2ApplicationViewerPrivate())
-{
- connect(engine(), SIGNAL(quit()), SLOT(close()));
- setResizeMode(QQuickView::SizeRootObjectToView);
+QtQuick2ApplicationViewer::QtQuick2ApplicationViewer(QWindow* parent)
+ : QQuickView(parent), d(new QtQuick2ApplicationViewerPrivate()) {
+ connect(engine(), SIGNAL(quit()), SLOT(close()));
+ setResizeMode(QQuickView::SizeRootObjectToView);
}
-QtQuick2ApplicationViewer::~QtQuick2ApplicationViewer()
-{
- delete d;
+QtQuick2ApplicationViewer::~QtQuick2ApplicationViewer() {
+ delete d;
}
-void QtQuick2ApplicationViewer::setMainQmlFile(const QString &file)
-{
- d->mainQmlFile = QtQuick2ApplicationViewerPrivate::adjustPath(file);
- setSource(QUrl::fromLocalFile(d->mainQmlFile));
+void QtQuick2ApplicationViewer::setMainQmlFile(const QString& file) {
+ d->mainQmlFile = QtQuick2ApplicationViewerPrivate::adjustPath(file);
+ setSource(QUrl::fromLocalFile(d->mainQmlFile));
}
-void QtQuick2ApplicationViewer::addImportPath(const QString &path)
-{
- engine()->addImportPath(QtQuick2ApplicationViewerPrivate::adjustPath(path));
+void QtQuick2ApplicationViewer::addImportPath(const QString& path) {
+ engine()->addImportPath(QtQuick2ApplicationViewerPrivate::adjustPath(path));
}
-void QtQuick2ApplicationViewer::showExpanded()
-{
+void QtQuick2ApplicationViewer::showExpanded() {
#if defined(Q_WS_SIMULATOR)
- showFullScreen();
+ showFullScreen();
#else
- show();
+ show();
#endif
}
diff --git a/src/components/qt_hmi/References/Work/bananasnacks/qtquick2applicationviewer/qtquick2applicationviewer.h b/src/components/qt_hmi/References/Work/bananasnacks/qtquick2applicationviewer/qtquick2applicationviewer.h
index bd6c50f54f..42287e8d79 100644
--- a/src/components/qt_hmi/References/Work/bananasnacks/qtquick2applicationviewer/qtquick2applicationviewer.h
+++ b/src/components/qt_hmi/References/Work/bananasnacks/qtquick2applicationviewer/qtquick2applicationviewer.h
@@ -1,7 +1,8 @@
// checksum 0xfde6 version 0x80001
/*
This file was generated by the Qt Quick 2 Application wizard of Qt Creator.
- QtQuick2ApplicationViewer is a convenience class containing mobile device specific
+ QtQuick2ApplicationViewer is a convenience class containing mobile device
+ specific
code such as screen orientation handling. Also QML paths and debugging are
handled here.
It is recommended not to modify this file, since newer versions of Qt Creator
@@ -13,21 +14,20 @@
#include <QtQuick/QQuickView>
-class QtQuick2ApplicationViewer : public QQuickView
-{
- Q_OBJECT
+class QtQuick2ApplicationViewer : public QQuickView {
+ Q_OBJECT
-public:
- explicit QtQuick2ApplicationViewer(QWindow *parent = 0);
- virtual ~QtQuick2ApplicationViewer();
+ public:
+ explicit QtQuick2ApplicationViewer(QWindow* parent = 0);
+ virtual ~QtQuick2ApplicationViewer();
- void setMainQmlFile(const QString &file);
- void addImportPath(const QString &path);
+ void setMainQmlFile(const QString& file);
+ void addImportPath(const QString& path);
- void showExpanded();
+ void showExpanded();
-private:
- class QtQuick2ApplicationViewerPrivate *d;
+ private:
+ class QtQuick2ApplicationViewerPrivate* d;
};
-#endif // QTQUICK2APPLICATIONVIEWER_H
+#endif // QTQUICK2APPLICATIONVIEWER_H
diff --git a/src/components/qt_hmi/References/Work/fordsdlcore/QtWebsocket/QWsServer.cpp b/src/components/qt_hmi/References/Work/fordsdlcore/QtWebsocket/QWsServer.cpp
index 5e86daa2f3..9c4eed8cc1 100644
--- a/src/components/qt_hmi/References/Work/fordsdlcore/QtWebsocket/QWsServer.cpp
+++ b/src/components/qt_hmi/References/Work/fordsdlcore/QtWebsocket/QWsServer.cpp
@@ -6,465 +6,451 @@
#include <QCryptographicHash>
#include <QDateTime>
-const QString QWsServer::regExpResourceNameStr( QLatin1String("^GET\\s(.*)\\sHTTP/1.1\r\n") );
-const QString QWsServer::regExpHostStr( QLatin1String("\r\nHost:\\s(.+(:\\d+)?)\r\n") );
-const QString QWsServer::regExpKeyStr( QLatin1String("\r\nSec-WebSocket-Key:\\s(.{24})\r\n") );
-const QString QWsServer::regExpKey1Str( QLatin1String("\r\nSec-WebSocket-Key1:\\s(.+)\r\n") );
-const QString QWsServer::regExpKey2Str( QLatin1String("\r\nSec-WebSocket-Key2:\\s(.+)\r\n") );
-const QString QWsServer::regExpKey3Str( QLatin1String("\r\n(.{8})$") );
-const QString QWsServer::regExpVersionStr( QLatin1String("\r\nSec-WebSocket-Version:\\s(\\d+)\r\n") );
-const QString QWsServer::regExpOriginStr( QLatin1String("\r\nSec-WebSocket-Origin:\\s(.+)\r\n") );
-const QString QWsServer::regExpOrigin2Str( QLatin1String("\r\nOrigin:\\s(.+)\r\n") );
-const QString QWsServer::regExpProtocolStr( QLatin1String("\r\nSec-WebSocket-Protocol:\\s(.+)\r\n") );
-const QString QWsServer::regExpExtensionsStr( QLatin1String("\r\nSec-WebSocket-Extensions:\\s(.+)\r\n") );
-
-QWsServer::QWsServer(QObject * parent)
- : QObject(parent)
-{
- tcpServer = new QTcpServer(this);
- connect( tcpServer, SIGNAL(newConnection()), this, SLOT(newTcpConnection()) );
- qsrand( QDateTime::currentMSecsSinceEpoch() );
+const QString QWsServer::regExpResourceNameStr(
+ QLatin1String("^GET\\s(.*)\\sHTTP/1.1\r\n"));
+const QString QWsServer::regExpHostStr(
+ QLatin1String("\r\nHost:\\s(.+(:\\d+)?)\r\n"));
+const QString QWsServer::regExpKeyStr(
+ QLatin1String("\r\nSec-WebSocket-Key:\\s(.{24})\r\n"));
+const QString QWsServer::regExpKey1Str(
+ QLatin1String("\r\nSec-WebSocket-Key1:\\s(.+)\r\n"));
+const QString QWsServer::regExpKey2Str(
+ QLatin1String("\r\nSec-WebSocket-Key2:\\s(.+)\r\n"));
+const QString QWsServer::regExpKey3Str(QLatin1String("\r\n(.{8})$"));
+const QString QWsServer::regExpVersionStr(
+ QLatin1String("\r\nSec-WebSocket-Version:\\s(\\d+)\r\n"));
+const QString QWsServer::regExpOriginStr(
+ QLatin1String("\r\nSec-WebSocket-Origin:\\s(.+)\r\n"));
+const QString QWsServer::regExpOrigin2Str(
+ QLatin1String("\r\nOrigin:\\s(.+)\r\n"));
+const QString QWsServer::regExpProtocolStr(
+ QLatin1String("\r\nSec-WebSocket-Protocol:\\s(.+)\r\n"));
+const QString QWsServer::regExpExtensionsStr(
+ QLatin1String("\r\nSec-WebSocket-Extensions:\\s(.+)\r\n"));
+
+QWsServer::QWsServer(QObject* parent) : QObject(parent) {
+ tcpServer = new QTcpServer(this);
+ connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newTcpConnection()));
+ qsrand(QDateTime::currentMSecsSinceEpoch());
}
-QWsServer::~QWsServer()
-{
- tcpServer->deleteLater();
+QWsServer::~QWsServer() {
+ tcpServer->deleteLater();
}
-bool QWsServer::listen(const QHostAddress & address, quint16 port)
-{
- return tcpServer->listen(address, port);
+bool QWsServer::listen(const QHostAddress& address, quint16 port) {
+ return tcpServer->listen(address, port);
}
-void QWsServer::close()
-{
- tcpServer->close();
+void QWsServer::close() {
+ tcpServer->close();
}
-QAbstractSocket::SocketError QWsServer::serverError()
-{
- return tcpServer->serverError();
+QAbstractSocket::SocketError QWsServer::serverError() {
+ return tcpServer->serverError();
}
-QString QWsServer::errorString()
-{
- return tcpServer->errorString();
+QString QWsServer::errorString() {
+ return tcpServer->errorString();
}
-void QWsServer::newTcpConnection()
-{
- QTcpSocket * tcpSocket = tcpServer->nextPendingConnection();
- connect( tcpSocket, SIGNAL(readyRead()), this, SLOT(dataReceived()) );
- headerBuffer.insert( tcpSocket, QStringList() );
+void QWsServer::newTcpConnection() {
+ QTcpSocket* tcpSocket = tcpServer->nextPendingConnection();
+ connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(dataReceived()));
+ headerBuffer.insert(tcpSocket, QStringList());
}
-void QWsServer::closeTcpConnection()
-{
- QTcpSocket * tcpSocket = qobject_cast<QTcpSocket*>( sender() );
- if (tcpSocket == 0)
- return;
+void QWsServer::closeTcpConnection() {
+ QTcpSocket* tcpSocket = qobject_cast<QTcpSocket*>(sender());
+ if (tcpSocket == 0)
+ return;
- tcpSocket->close();
+ tcpSocket->close();
}
-void QWsServer::dataReceived()
-{
- QTcpSocket * tcpSocket = qobject_cast<QTcpSocket*>( sender() );
- if (tcpSocket == 0)
- return;
-
- bool allHeadersFetched = false;
-
- const QLatin1String emptyLine("\r\n");
-
- while ( tcpSocket->canReadLine() )
- {
- QString line = tcpSocket->readLine();
-
- if (line == emptyLine)
- {
- allHeadersFetched = true;
- break;
- }
-
- headerBuffer[ tcpSocket ].append(line);
- }
-
- if (!allHeadersFetched)
- return;
-
- QString request( headerBuffer[ tcpSocket ].join("") );
-
- QRegExp regExp;
- regExp.setMinimal( true );
-
- // Extract mandatory datas
- // Version
- regExp.setPattern( QWsServer::regExpVersionStr );
- regExp.indexIn(request);
- QString versionStr = regExp.cap(1);
- EWebsocketVersion version;
- if ( ! versionStr.isEmpty() )
- {
- version = (EWebsocketVersion)versionStr.toInt();
- }
- else if ( tcpSocket->bytesAvailable() >= 8 )
- {
- version = WS_V0;
- request.append( tcpSocket->read(8) );
- }
- else
- {
- version = WS_VUnknow;
- }
-
- // Resource name
- regExp.setPattern( QWsServer::regExpResourceNameStr );
- regExp.indexIn(request);
- QString resourceName = regExp.cap(1);
-
- // Host (address & port)
- regExp.setPattern( QWsServer::regExpHostStr );
- regExp.indexIn(request);
- QString host = regExp.cap(1);
- QStringList hostTmp = host.split(':');
- QString hostAddress = hostTmp[0];
- QString hostPort;
- if ( hostTmp.size() > 1 )
- hostPort = hostTmp.last(); // fix for IPv6
-
- // Key
- QString key, key1, key2, key3;
- if ( version >= WS_V4 )
- {
- regExp.setPattern( QWsServer::regExpKeyStr );
- regExp.indexIn(request);
- key = regExp.cap(1);
- }
- else
- {
- regExp.setPattern( QWsServer::regExpKey1Str );
- regExp.indexIn(request);
- key1 = regExp.cap(1);
- regExp.setPattern( QWsServer::regExpKey2Str );
- regExp.indexIn(request);
- key2 = regExp.cap(1);
- regExp.setPattern( QWsServer::regExpKey3Str );
- regExp.indexIn(request);
- key3 = regExp.cap(1);
- }
-
- ////////////////////////////////////////////////////////////////////
-
- // If the mandatory fields are not specified, we abord the connection to the Websocket server
- if ( version == WS_VUnknow || resourceName.isEmpty() || hostAddress.isEmpty() || ( key.isEmpty() && ( key1.isEmpty() || key2.isEmpty() || key3.isEmpty() ) ) )
- {
- // Send bad request response
- QString response = QWsServer::composeBadRequestResponse( QList<EWebsocketVersion>() << WS_V6 << WS_V7 << WS_V8 << WS_V13 );
- tcpSocket->write( response.toUtf8() );
- tcpSocket->flush();
- return;
- }
-
- ////////////////////////////////////////////////////////////////////
-
- // Extract optional datas
-
- // Origin
- regExp.setPattern( QWsServer::regExpOriginStr );
- if ( regExp.indexIn(request) == -1 )
- {
- regExp.setPattern( QWsServer::regExpOrigin2Str );
- regExp.indexIn(request);
- }
- QString origin = regExp.cap(1);
-
- // Protocol
- regExp.setPattern( QWsServer::regExpProtocolStr );
- regExp.indexIn(request);
- QString protocol = regExp.cap(1);
-
- // Extensions
- regExp.setPattern( QWsServer::regExpExtensionsStr );
- regExp.indexIn(request);
- QString extensions = regExp.cap(1);
-
- ////////////////////////////////////////////////////////////////////
-
- // Compose opening handshake response
- QString response;
-
- if ( version >= WS_V6 )
- {
- QString accept = computeAcceptV4( key );
- response = QWsServer::composeOpeningHandshakeResponseV6( accept, protocol );
- }
- else if ( version >= WS_V4 )
- {
- QString accept = computeAcceptV4( key );
- QString nonce = generateNonce();
- response = QWsServer::composeOpeningHandshakeResponseV4( accept, nonce, protocol );
- }
- else
- {
- QString accept = computeAcceptV0( key1, key2, key3 );
- response = QWsServer::composeOpeningHandshakeResponseV0( accept, origin, hostAddress, hostPort, resourceName , protocol );
- }
-
- // Handshake OK, disconnect readyRead
- disconnect( tcpSocket, SIGNAL(readyRead()), this, SLOT(dataReceived()) );
-
- // Send opening handshake response
- if ( version == WS_V0 )
- tcpSocket->write( response.toLatin1() );
- else
- tcpSocket->write( response.toUtf8() );
- tcpSocket->flush();
-
- QWsSocket * wsSocket = new QWsSocket( this, tcpSocket, version );
- wsSocket->setResourceName( resourceName );
- wsSocket->setHost( host );
- wsSocket->setHostAddress( hostAddress );
- wsSocket->setHostPort( hostPort.toInt() );
- wsSocket->setOrigin( origin );
- wsSocket->setProtocol( protocol );
- wsSocket->setExtensions( extensions );
- wsSocket->serverSideSocket = true;
-
- // ORIGINAL CODE
- //int socketDescriptor = tcpSocket->socketDescriptor();
- //incomingConnection( socketDescriptor );
-
- // CHANGED CODE FOR LINUX COMPATIBILITY
- addPendingConnection( wsSocket );
- emit newConnection();
+void QWsServer::dataReceived() {
+ QTcpSocket* tcpSocket = qobject_cast<QTcpSocket*>(sender());
+ if (tcpSocket == 0)
+ return;
+
+ bool allHeadersFetched = false;
+
+ const QLatin1String emptyLine("\r\n");
+
+ while (tcpSocket->canReadLine()) {
+ QString line = tcpSocket->readLine();
+
+ if (line == emptyLine) {
+ allHeadersFetched = true;
+ break;
+ }
+
+ headerBuffer[tcpSocket].append(line);
+ }
+
+ if (!allHeadersFetched)
+ return;
+
+ QString request(headerBuffer[tcpSocket].join(""));
+
+ QRegExp regExp;
+ regExp.setMinimal(true);
+
+ // Extract mandatory datas
+ // Version
+ regExp.setPattern(QWsServer::regExpVersionStr);
+ regExp.indexIn(request);
+ QString versionStr = regExp.cap(1);
+ EWebsocketVersion version;
+ if (!versionStr.isEmpty()) {
+ version = (EWebsocketVersion)versionStr.toInt();
+ } else if (tcpSocket->bytesAvailable() >= 8) {
+ version = WS_V0;
+ request.append(tcpSocket->read(8));
+ } else {
+ version = WS_VUnknow;
+ }
+
+ // Resource name
+ regExp.setPattern(QWsServer::regExpResourceNameStr);
+ regExp.indexIn(request);
+ QString resourceName = regExp.cap(1);
+
+ // Host (address & port)
+ regExp.setPattern(QWsServer::regExpHostStr);
+ regExp.indexIn(request);
+ QString host = regExp.cap(1);
+ QStringList hostTmp = host.split(':');
+ QString hostAddress = hostTmp[0];
+ QString hostPort;
+ if (hostTmp.size() > 1)
+ hostPort = hostTmp.last(); // fix for IPv6
+
+ // Key
+ QString key, key1, key2, key3;
+ if (version >= WS_V4) {
+ regExp.setPattern(QWsServer::regExpKeyStr);
+ regExp.indexIn(request);
+ key = regExp.cap(1);
+ } else {
+ regExp.setPattern(QWsServer::regExpKey1Str);
+ regExp.indexIn(request);
+ key1 = regExp.cap(1);
+ regExp.setPattern(QWsServer::regExpKey2Str);
+ regExp.indexIn(request);
+ key2 = regExp.cap(1);
+ regExp.setPattern(QWsServer::regExpKey3Str);
+ regExp.indexIn(request);
+ key3 = regExp.cap(1);
+ }
+
+ ////////////////////////////////////////////////////////////////////
+
+ // If the mandatory fields are not specified, we abord the connection to the
+ // Websocket server
+ if (version == WS_VUnknow || resourceName.isEmpty() ||
+ hostAddress.isEmpty() ||
+ (key.isEmpty() && (key1.isEmpty() || key2.isEmpty() || key3.isEmpty()))) {
+ // Send bad request response
+ QString response = QWsServer::composeBadRequestResponse(
+ QList<EWebsocketVersion>() << WS_V6 << WS_V7 << WS_V8 << WS_V13);
+ tcpSocket->write(response.toUtf8());
+ tcpSocket->flush();
+ return;
+ }
+
+ ////////////////////////////////////////////////////////////////////
+
+ // Extract optional datas
+
+ // Origin
+ regExp.setPattern(QWsServer::regExpOriginStr);
+ if (regExp.indexIn(request) == -1) {
+ regExp.setPattern(QWsServer::regExpOrigin2Str);
+ regExp.indexIn(request);
+ }
+ QString origin = regExp.cap(1);
+
+ // Protocol
+ regExp.setPattern(QWsServer::regExpProtocolStr);
+ regExp.indexIn(request);
+ QString protocol = regExp.cap(1);
+
+ // Extensions
+ regExp.setPattern(QWsServer::regExpExtensionsStr);
+ regExp.indexIn(request);
+ QString extensions = regExp.cap(1);
+
+ ////////////////////////////////////////////////////////////////////
+
+ // Compose opening handshake response
+ QString response;
+
+ if (version >= WS_V6) {
+ QString accept = computeAcceptV4(key);
+ response = QWsServer::composeOpeningHandshakeResponseV6(accept, protocol);
+ } else if (version >= WS_V4) {
+ QString accept = computeAcceptV4(key);
+ QString nonce = generateNonce();
+ response =
+ QWsServer::composeOpeningHandshakeResponseV4(accept, nonce, protocol);
+ } else {
+ QString accept = computeAcceptV0(key1, key2, key3);
+ response = QWsServer::composeOpeningHandshakeResponseV0(
+ accept, origin, hostAddress, hostPort, resourceName, protocol);
+ }
+
+ // Handshake OK, disconnect readyRead
+ disconnect(tcpSocket, SIGNAL(readyRead()), this, SLOT(dataReceived()));
+
+ // Send opening handshake response
+ if (version == WS_V0)
+ tcpSocket->write(response.toLatin1());
+ else
+ tcpSocket->write(response.toUtf8());
+ tcpSocket->flush();
+
+ QWsSocket* wsSocket = new QWsSocket(this, tcpSocket, version);
+ wsSocket->setResourceName(resourceName);
+ wsSocket->setHost(host);
+ wsSocket->setHostAddress(hostAddress);
+ wsSocket->setHostPort(hostPort.toInt());
+ wsSocket->setOrigin(origin);
+ wsSocket->setProtocol(protocol);
+ wsSocket->setExtensions(extensions);
+ wsSocket->serverSideSocket = true;
+
+ // ORIGINAL CODE
+ // int socketDescriptor = tcpSocket->socketDescriptor();
+ // incomingConnection( socketDescriptor );
+
+ // CHANGED CODE FOR LINUX COMPATIBILITY
+ addPendingConnection(wsSocket);
+ emit newConnection();
}
-void QWsServer::incomingConnection( int socketDescriptor )
-{
- QTcpSocket * tcpSocket = new QTcpSocket( tcpServer );
- tcpSocket->setSocketDescriptor( socketDescriptor, QAbstractSocket::ConnectedState );
- QWsSocket * wsSocket = new QWsSocket( this, tcpSocket );
+void QWsServer::incomingConnection(int socketDescriptor) {
+ QTcpSocket* tcpSocket = new QTcpSocket(tcpServer);
+ tcpSocket->setSocketDescriptor(socketDescriptor,
+ QAbstractSocket::ConnectedState);
+ QWsSocket* wsSocket = new QWsSocket(this, tcpSocket);
- addPendingConnection( wsSocket );
- emit newConnection();
+ addPendingConnection(wsSocket);
+ emit newConnection();
}
-void QWsServer::addPendingConnection( QWsSocket * socket )
-{
- if ( pendingConnections.size() < maxPendingConnections() )
- pendingConnections.enqueue( socket );
+void QWsServer::addPendingConnection(QWsSocket* socket) {
+ if (pendingConnections.size() < maxPendingConnections())
+ pendingConnections.enqueue(socket);
}
-QWsSocket * QWsServer::nextPendingConnection()
-{
- return pendingConnections.dequeue();
+QWsSocket* QWsServer::nextPendingConnection() {
+ return pendingConnections.dequeue();
}
-bool QWsServer::hasPendingConnections()
-{
- if ( pendingConnections.size() > 0 )
- return true;
- return false;
+bool QWsServer::hasPendingConnections() {
+ if (pendingConnections.size() > 0)
+ return true;
+ return false;
}
-int QWsServer::maxPendingConnections()
-{
- return tcpServer->maxPendingConnections();
+int QWsServer::maxPendingConnections() {
+ return tcpServer->maxPendingConnections();
}
-bool QWsServer::isListening()
-{
- return tcpServer->isListening();
+bool QWsServer::isListening() {
+ return tcpServer->isListening();
}
-QNetworkProxy QWsServer::proxy()
-{
- return tcpServer->proxy();
+QNetworkProxy QWsServer::proxy() {
+ return tcpServer->proxy();
}
-QHostAddress QWsServer::serverAddress()
-{
- return tcpServer->serverAddress();
+QHostAddress QWsServer::serverAddress() {
+ return tcpServer->serverAddress();
}
-quint16 QWsServer::serverPort()
-{
- return tcpServer->serverPort();
+quint16 QWsServer::serverPort() {
+ return tcpServer->serverPort();
}
-void QWsServer::setMaxPendingConnections( int numConnections )
-{
- tcpServer->setMaxPendingConnections( numConnections );
+void QWsServer::setMaxPendingConnections(int numConnections) {
+ tcpServer->setMaxPendingConnections(numConnections);
}
-void QWsServer::setProxy( const QNetworkProxy & networkProxy )
-{
- tcpServer->setProxy( networkProxy );
+void QWsServer::setProxy(const QNetworkProxy& networkProxy) {
+ tcpServer->setProxy(networkProxy);
}
-bool QWsServer::setSocketDescriptor( int socketDescriptor )
-{
- return tcpServer->setSocketDescriptor( socketDescriptor );
+bool QWsServer::setSocketDescriptor(int socketDescriptor) {
+ return tcpServer->setSocketDescriptor(socketDescriptor);
}
-int QWsServer::socketDescriptor()
-{
- return tcpServer->socketDescriptor();
+int QWsServer::socketDescriptor() {
+ return tcpServer->socketDescriptor();
}
-bool QWsServer::waitForNewConnection( int msec, bool * timedOut )
-{
- return tcpServer->waitForNewConnection( msec, timedOut );
+bool QWsServer::waitForNewConnection(int msec, bool* timedOut) {
+ return tcpServer->waitForNewConnection(msec, timedOut);
}
-QString QWsServer::computeAcceptV0( QString key1, QString key2, QString key3 )
-{
- QString numStr1;
- QString numStr2;
+QString QWsServer::computeAcceptV0(QString key1, QString key2, QString key3) {
+ QString numStr1;
+ QString numStr2;
- QChar carac;
- for ( int i=0 ; i<key1.size() ; i++ )
- {
- carac = key1[ i ];
- if ( carac.isDigit() )
- numStr1.append( carac );
- }
- for ( int i=0 ; i<key2.size() ; i++ )
- {
- carac = key2[ i ];
- if ( carac.isDigit() )
- numStr2.append( carac );
- }
+ QChar carac;
+ for (int i = 0; i < key1.size(); i++) {
+ carac = key1[i];
+ if (carac.isDigit())
+ numStr1.append(carac);
+ }
+ for (int i = 0; i < key2.size(); i++) {
+ carac = key2[i];
+ if (carac.isDigit())
+ numStr2.append(carac);
+ }
- quint32 num1 = numStr1.toUInt();
- quint32 num2 = numStr2.toUInt();
+ quint32 num1 = numStr1.toUInt();
+ quint32 num2 = numStr2.toUInt();
- int numSpaces1 = key1.count( ' ' );
- int numSpaces2 = key2.count( ' ' );
+ int numSpaces1 = key1.count(' ');
+ int numSpaces2 = key2.count(' ');
- num1 /= numSpaces1;
- num2 /= numSpaces2;
+ num1 /= numSpaces1;
+ num2 /= numSpaces2;
- QString concat = serializeInt( num1 ) + serializeInt( num2 ) + key3;
+ QString concat = serializeInt(num1) + serializeInt(num2) + key3;
- QByteArray md5 = QCryptographicHash::hash( concat.toLatin1(), QCryptographicHash::Md5 );
+ QByteArray md5 =
+ QCryptographicHash::hash(concat.toLatin1(), QCryptographicHash::Md5);
- return QString( md5 );
+ return QString(md5);
}
-QString QWsServer::computeAcceptV4(QString key)
-{
- key += QLatin1String("258EAFA5-E914-47DA-95CA-C5AB0DC85B11");
- QByteArray hash = QCryptographicHash::hash ( key.toUtf8(), QCryptographicHash::Sha1 );
- return hash.toBase64();
+QString QWsServer::computeAcceptV4(QString key) {
+ key += QLatin1String("258EAFA5-E914-47DA-95CA-C5AB0DC85B11");
+ QByteArray hash =
+ QCryptographicHash::hash(key.toUtf8(), QCryptographicHash::Sha1);
+ return hash.toBase64();
}
-QString QWsServer::generateNonce()
-{
- qsrand( QDateTime::currentDateTime().toTime_t() );
+QString QWsServer::generateNonce() {
+ qsrand(QDateTime::currentDateTime().toTime_t());
- QByteArray nonce;
- int i = 16;
+ QByteArray nonce;
+ int i = 16;
- while( i-- )
- {
- nonce.append( qrand() % 0x100 );
- }
+ while (i--) {
+ nonce.append(qrand() % 0x100);
+ }
- return QString( nonce.toBase64() );
+ return QString(nonce.toBase64());
}
-QByteArray QWsServer::serializeInt( quint32 number, quint8 nbBytes )
-{
- QByteArray ba;
- quint8 currentNbBytes = 0;
- while (number > 0 && currentNbBytes < nbBytes)
- {
- char car = static_cast<char>(number & 0xFF);
- ba.prepend( car );
- number = number >> 8;
- currentNbBytes++;
- }
- char car = 0x00;
- while (currentNbBytes < nbBytes)
- {
- ba.prepend( car );
- currentNbBytes++;
- }
- return ba;
+QByteArray QWsServer::serializeInt(quint32 number, quint8 nbBytes) {
+ QByteArray ba;
+ quint8 currentNbBytes = 0;
+ while (number > 0 && currentNbBytes < nbBytes) {
+ char car = static_cast<char>(number & 0xFF);
+ ba.prepend(car);
+ number = number >> 8;
+ currentNbBytes++;
+ }
+ char car = 0x00;
+ while (currentNbBytes < nbBytes) {
+ ba.prepend(car);
+ currentNbBytes++;
+ }
+ return ba;
}
-QString QWsServer::composeOpeningHandshakeResponseV0( QString accept, QString origin, QString hostAddress, QString hostPort, QString resourceName, QString protocol )
-{
- QString response;
-
- response.append( QLatin1String("HTTP/1.1 101 WebSocket Protocol Handshake\r\n") );
- response.append( QLatin1String("Upgrade: Websocket\r\n") );
- response.append( QLatin1String("Connection: Upgrade\r\n") );
- response.append( QLatin1String("Sec-WebSocket-Origin: ") + origin + QLatin1String("\r\n") );
- response.append( QLatin1String("Sec-WebSocket-Location: ws://") + hostAddress);
- if (!hostPort.isEmpty())
- response.append(QLatin1String(":") + hostPort);
- response.append(resourceName + QLatin1String("\r\n"));
- if ( ! protocol.isEmpty() )
- response.append( QLatin1String("Sec-WebSocket-Protocol: ") + protocol + QLatin1String("\r\n") );
- response.append( QLatin1String("\r\n") );
- response.append( accept );
-
- return response;
+QString QWsServer::composeOpeningHandshakeResponseV0(QString accept,
+ QString origin,
+ QString hostAddress,
+ QString hostPort,
+ QString resourceName,
+ QString protocol) {
+ QString response;
+
+ response.append(
+ QLatin1String("HTTP/1.1 101 WebSocket Protocol Handshake\r\n"));
+ response.append(QLatin1String("Upgrade: Websocket\r\n"));
+ response.append(QLatin1String("Connection: Upgrade\r\n"));
+ response.append(QLatin1String("Sec-WebSocket-Origin: ") + origin +
+ QLatin1String("\r\n"));
+ response.append(QLatin1String("Sec-WebSocket-Location: ws://") + hostAddress);
+ if (!hostPort.isEmpty())
+ response.append(QLatin1String(":") + hostPort);
+ response.append(resourceName + QLatin1String("\r\n"));
+ if (!protocol.isEmpty())
+ response.append(QLatin1String("Sec-WebSocket-Protocol: ") + protocol +
+ QLatin1String("\r\n"));
+ response.append(QLatin1String("\r\n"));
+ response.append(accept);
+
+ return response;
}
-QString QWsServer::composeOpeningHandshakeResponseV4( QString accept, QString nonce, QString protocol, QString extensions )
-{
- QString response;
-
- response.append( QLatin1String("HTTP/1.1 101 Switching Protocols\r\n") );
- response.append( QLatin1String("Upgrade: websocket\r\n") );
- response.append( QLatin1String("Connection: Upgrade\r\n") );
- response.append( QLatin1String("Sec-WebSocket-Accept: ") + accept + QLatin1String("\r\n") );
- response.append( QLatin1String("Sec-WebSocket-Nonce: ") + nonce + QLatin1String("\r\n") );
- if ( ! protocol.isEmpty() )
- response.append( QLatin1String("Sec-WebSocket-Protocol: ") + protocol + QLatin1String("\r\n") );
- if ( ! extensions.isEmpty() )
- response.append( QLatin1String("Sec-WebSocket-Extensions: ") + extensions + QLatin1String("\r\n") );
- response.append( QLatin1String("\r\n") );
-
- return response;
+QString QWsServer::composeOpeningHandshakeResponseV4(QString accept,
+ QString nonce,
+ QString protocol,
+ QString extensions) {
+ QString response;
+
+ response.append(QLatin1String("HTTP/1.1 101 Switching Protocols\r\n"));
+ response.append(QLatin1String("Upgrade: websocket\r\n"));
+ response.append(QLatin1String("Connection: Upgrade\r\n"));
+ response.append(QLatin1String("Sec-WebSocket-Accept: ") + accept +
+ QLatin1String("\r\n"));
+ response.append(QLatin1String("Sec-WebSocket-Nonce: ") + nonce +
+ QLatin1String("\r\n"));
+ if (!protocol.isEmpty())
+ response.append(QLatin1String("Sec-WebSocket-Protocol: ") + protocol +
+ QLatin1String("\r\n"));
+ if (!extensions.isEmpty())
+ response.append(QLatin1String("Sec-WebSocket-Extensions: ") + extensions +
+ QLatin1String("\r\n"));
+ response.append(QLatin1String("\r\n"));
+
+ return response;
}
-QString QWsServer::composeOpeningHandshakeResponseV6( QString accept, QString protocol, QString extensions )
-{
- QString response;
-
- response.append( QLatin1String("HTTP/1.1 101 Switching Protocols\r\n") );
- response.append( QLatin1String("Upgrade: websocket\r\n") );
- response.append( QLatin1String("Connection: Upgrade\r\n") );
- response.append( QLatin1String("Sec-WebSocket-Accept: ") + accept + QLatin1String("\r\n") );
- if ( ! protocol.isEmpty() )
- response.append( QLatin1String("Sec-WebSocket-Protocol: ") + protocol + QLatin1String("\r\n") );
- if ( ! extensions.isEmpty() )
- response.append( QLatin1String("Sec-WebSocket-Extensions: ") + extensions + QLatin1String("\r\n") );
- response.append( QLatin1String("\r\n") );
-
- return response;
+QString QWsServer::composeOpeningHandshakeResponseV6(QString accept,
+ QString protocol,
+ QString extensions) {
+ QString response;
+
+ response.append(QLatin1String("HTTP/1.1 101 Switching Protocols\r\n"));
+ response.append(QLatin1String("Upgrade: websocket\r\n"));
+ response.append(QLatin1String("Connection: Upgrade\r\n"));
+ response.append(QLatin1String("Sec-WebSocket-Accept: ") + accept +
+ QLatin1String("\r\n"));
+ if (!protocol.isEmpty())
+ response.append(QLatin1String("Sec-WebSocket-Protocol: ") + protocol +
+ QLatin1String("\r\n"));
+ if (!extensions.isEmpty())
+ response.append(QLatin1String("Sec-WebSocket-Extensions: ") + extensions +
+ QLatin1String("\r\n"));
+ response.append(QLatin1String("\r\n"));
+
+ return response;
}
-QString QWsServer::composeBadRequestResponse( QList<EWebsocketVersion> versions )
-{
- QString response;
-
- response.append( QLatin1String("HTTP/1.1 400 Bad Request\r\n") );
- if ( ! versions.isEmpty() )
- {
- QString versionsStr = QString::number( (int)versions.takeLast() );
- int i = versions.size();
- while ( i-- )
- {
- versionsStr.append( QLatin1String(", ") + QString::number( (int)versions.takeLast() ) );
- }
- response.append( QLatin1String("Sec-WebSocket-Version: ") + versionsStr + QLatin1String("\r\n") );
- }
-
- return response;
+QString QWsServer::composeBadRequestResponse(
+ QList<EWebsocketVersion> versions) {
+ QString response;
+
+ response.append(QLatin1String("HTTP/1.1 400 Bad Request\r\n"));
+ if (!versions.isEmpty()) {
+ QString versionsStr = QString::number((int)versions.takeLast());
+ int i = versions.size();
+ while (i--) {
+ versionsStr.append(QLatin1String(", ") +
+ QString::number((int)versions.takeLast()));
+ }
+ response.append(QLatin1String("Sec-WebSocket-Version: ") + versionsStr +
+ QLatin1String("\r\n"));
+ }
+
+ return response;
}
diff --git a/src/components/qt_hmi/References/Work/fordsdlcore/QtWebsocket/QWsServer.h b/src/components/qt_hmi/References/Work/fordsdlcore/QtWebsocket/QWsServer.h
index c526c747ab..f37dd4b5b2 100644
--- a/src/components/qt_hmi/References/Work/fordsdlcore/QtWebsocket/QWsServer.h
+++ b/src/components/qt_hmi/References/Work/fordsdlcore/QtWebsocket/QWsServer.h
@@ -11,77 +11,88 @@
#include "QWsSocket.h"
-class QWsServer : public QObject
-{
- Q_OBJECT
+class QWsServer : public QObject {
+ Q_OBJECT
-public:
- // ctor
- QWsServer(QObject * parent = 0);
- // dtor
- virtual ~QWsServer();
+ public:
+ // ctor
+ QWsServer(QObject* parent = 0);
+ // dtor
+ virtual ~QWsServer();
- // public functions
- void close();
- QString errorString();
- bool hasPendingConnections();
- bool isListening();
- bool listen(const QHostAddress & address = QHostAddress::Any, quint16 port = 0);
- int maxPendingConnections();
- virtual QWsSocket * nextPendingConnection();
- QNetworkProxy proxy();
- QHostAddress serverAddress();
- QAbstractSocket::SocketError serverError();
- quint16 serverPort();
- void setMaxPendingConnections( int numConnections );
- void setProxy( const QNetworkProxy & networkProxy );
- bool setSocketDescriptor( int socketDescriptor );
- int socketDescriptor();
- bool waitForNewConnection( int msec = 0, bool * timedOut = 0 );
+ // public functions
+ void close();
+ QString errorString();
+ bool hasPendingConnections();
+ bool isListening();
+ bool listen(const QHostAddress& address = QHostAddress::Any,
+ quint16 port = 0);
+ int maxPendingConnections();
+ virtual QWsSocket* nextPendingConnection();
+ QNetworkProxy proxy();
+ QHostAddress serverAddress();
+ QAbstractSocket::SocketError serverError();
+ quint16 serverPort();
+ void setMaxPendingConnections(int numConnections);
+ void setProxy(const QNetworkProxy& networkProxy);
+ bool setSocketDescriptor(int socketDescriptor);
+ int socketDescriptor();
+ bool waitForNewConnection(int msec = 0, bool* timedOut = 0);
signals:
- void newConnection();
+ void newConnection();
-protected:
- // protected functions
- void addPendingConnection( QWsSocket * socket );
- virtual void incomingConnection( int socketDescriptor );
+ protected:
+ // protected functions
+ void addPendingConnection(QWsSocket* socket);
+ virtual void incomingConnection(int socketDescriptor);
-private slots:
- // private slots
- void newTcpConnection();
- void closeTcpConnection();
- void dataReceived();
+ private slots:
+ // private slots
+ void newTcpConnection();
+ void closeTcpConnection();
+ void dataReceived();
-private:
- // private attributes
- QTcpServer * tcpServer;
- QQueue<QWsSocket*> pendingConnections;
- QMap<const QTcpSocket*, QStringList> headerBuffer;
+ private:
+ // private attributes
+ QTcpServer* tcpServer;
+ QQueue<QWsSocket*> pendingConnections;
+ QMap<const QTcpSocket*, QStringList> headerBuffer;
-public:
- // public static functions
- static QByteArray serializeInt( quint32 number, quint8 nbBytes = 4 );
- static QString computeAcceptV0( QString key1, QString key2, QString thirdPart );
- static QString computeAcceptV4( QString key );
- static QString generateNonce();
- static QString composeOpeningHandshakeResponseV0( QString accept, QString origin, QString hostAddress, QString hostPort, QString resourceName, QString protocol = "" );
- static QString composeOpeningHandshakeResponseV4( QString accept, QString nonce, QString protocol = "", QString extensions = "" );
- static QString composeOpeningHandshakeResponseV6( QString accept, QString protocol = "", QString extensions = "" );
- static QString composeBadRequestResponse( QList<EWebsocketVersion> versions = QList<EWebsocketVersion>() );
+ public:
+ // public static functions
+ static QByteArray serializeInt(quint32 number, quint8 nbBytes = 4);
+ static QString computeAcceptV0(QString key1, QString key2, QString thirdPart);
+ static QString computeAcceptV4(QString key);
+ static QString generateNonce();
+ static QString composeOpeningHandshakeResponseV0(QString accept,
+ QString origin,
+ QString hostAddress,
+ QString hostPort,
+ QString resourceName,
+ QString protocol = "");
+ static QString composeOpeningHandshakeResponseV4(QString accept,
+ QString nonce,
+ QString protocol = "",
+ QString extensions = "");
+ static QString composeOpeningHandshakeResponseV6(QString accept,
+ QString protocol = "",
+ QString extensions = "");
+ static QString composeBadRequestResponse(
+ QList<EWebsocketVersion> versions = QList<EWebsocketVersion>());
- // public static vars
- static const QString regExpResourceNameStr;
- static const QString regExpHostStr;
- static const QString regExpKeyStr;
- static const QString regExpKey1Str;
- static const QString regExpKey2Str;
- static const QString regExpKey3Str;
- static const QString regExpVersionStr;
- static const QString regExpOriginStr;
- static const QString regExpOrigin2Str;
- static const QString regExpProtocolStr;
- static const QString regExpExtensionsStr;
+ // public static vars
+ static const QString regExpResourceNameStr;
+ static const QString regExpHostStr;
+ static const QString regExpKeyStr;
+ static const QString regExpKey1Str;
+ static const QString regExpKey2Str;
+ static const QString regExpKey3Str;
+ static const QString regExpVersionStr;
+ static const QString regExpOriginStr;
+ static const QString regExpOrigin2Str;
+ static const QString regExpProtocolStr;
+ static const QString regExpExtensionsStr;
};
-#endif // QWSSERVER_H
+#endif // QWSSERVER_H
diff --git a/src/components/qt_hmi/References/Work/fordsdlcore/QtWebsocket/QWsSocket.cpp b/src/components/qt_hmi/References/Work/fordsdlcore/QtWebsocket/QWsSocket.cpp
index 540b909e09..428f559517 100644
--- a/src/components/qt_hmi/References/Work/fordsdlcore/QtWebsocket/QWsSocket.cpp
+++ b/src/components/qt_hmi/References/Work/fordsdlcore/QtWebsocket/QWsSocket.cpp
@@ -6,787 +6,744 @@
#include "QWsServer.h"
int QWsSocket::maxBytesPerFrame = 1400;
-const QString QWsSocket::regExpAcceptStr(QLatin1String("Sec-WebSocket-Accept:\\s(.{28})\r\n"));
+const QString QWsSocket::regExpAcceptStr(
+ QLatin1String("Sec-WebSocket-Accept:\\s(.{28})\r\n"));
const QString QWsSocket::regExpUpgradeStr(QLatin1String("Upgrade:\\s(.+)\r\n"));
-const QString QWsSocket::regExpConnectionStr(QLatin1String("Connection:\\s(.+)\r\n"));
-
-QWsSocket::QWsSocket( QObject * parent, QTcpSocket * socket, EWebsocketVersion ws_v ) :
- QAbstractSocket( QAbstractSocket::UnknownSocketType, parent ),
- tcpSocket( socket ? socket : new QTcpSocket(this) ),
- _version( ws_v ),
- _hostPort( -1 ),
- closingHandshakeSent( false ),
- closingHandshakeReceived( false ),
- readingState( HeaderPending ),
- isFinalFragment( false ),
- hasMask( false ),
- payloadLength( 0 ),
- maskingKey( 4, 0 ),
- serverSideSocket( false )
-{
- tcpSocket->setParent( this );
-
- QAbstractSocket::setSocketState( tcpSocket->state() );
- QAbstractSocket::setPeerAddress( tcpSocket->peerAddress() );
- QAbstractSocket::setPeerPort( tcpSocket->peerPort() );
-
- if ( _version == WS_V0 )
- connect( tcpSocket, SIGNAL(readyRead()), this, SLOT(processDataV0()) );
- else if ( _version >= WS_V4 )
- connect( tcpSocket, SIGNAL(readyRead()), this, SLOT(processDataV4()) );
- connect( tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SIGNAL(error(QAbstractSocket::SocketError)) );
- connect( tcpSocket, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *)), this, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *)) );
- connect( tcpSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(processTcpStateChanged(QAbstractSocket::SocketState)) );
- connect( tcpSocket, SIGNAL(readChannelFinished()), this, SIGNAL(readChannelFinished()) );
- connect( tcpSocket, SIGNAL(hostFound()), this, SIGNAL(hostFound()) );
-}
-
-QWsSocket::~QWsSocket()
-{
- QAbstractSocket::SocketState state = QAbstractSocket::state();
- if ( state != QAbstractSocket::UnconnectedState )
- {
- qDebug() << "CloseAway, socket destroyed in server";
- close( CloseGoingAway, QLatin1String("The server destroyed the socket.") );
- tcpSocket->abort();
- QAbstractSocket::setSocketState( QAbstractSocket::UnconnectedState );
- QAbstractSocket::stateChanged( QAbstractSocket::UnconnectedState );
- emit QAbstractSocket::disconnected();
- }
-}
-
-void QWsSocket::connectToHost( const QString & hostName, quint16 port, OpenMode mode )
-{
- QWsSocket::connectToHost( QHostAddress(hostName), port, mode );
-}
-
-void QWsSocket::connectToHost( const QHostAddress &address, quint16 port, OpenMode mode )
-{
- handshakeResponse.clear();
- setPeerAddress( address );
- setPeerPort( port );
- setOpenMode( mode );
- tcpSocket->connectToHost( address, port, mode );
-}
-
-void QWsSocket::disconnectFromHost()
-{
- QWsSocket::close();
-}
-
-void QWsSocket::abort( QString reason )
-{
- QWsSocket::close( CloseAbnormalDisconnection, reason );
- tcpSocket->abort();
-}
-
-void QWsSocket::close( ECloseStatusCode closeStatusCode, QString reason )
-{
- if ( QAbstractSocket::state() == QAbstractSocket::UnconnectedState )
- return;
-
- if ( ! closingHandshakeSent )
- {
- switch ( _version )
- {
- case WS_V4:
- case WS_V5:
- case WS_V6:
- case WS_V7:
- case WS_V8:
- case WS_V13:
- {
- // Compose and send close frame
- QByteArray BA;
-
- // Body
- if ( closeStatusCode == NoCloseStatusCode )
- {
- // Header
- BA.append( QWsSocket::composeHeader( true, OpClose, 0 ) );
- }
- else
- {
- // Header
- QByteArray maskingKey;
- if ( ! serverSideSocket )
- maskingKey = QWsSocket::generateMaskingKey();
- BA.append( QWsSocket::composeHeader( true, OpClose, reason.size() + 2, maskingKey ) );
-
- QByteArray body;
-
- // Close status code (optional)
- body.append( QWsServer::serializeInt( (int)closeStatusCode, 2 ) );
-
- // Reason (optional)
- if ( reason.size() )
- {
- QByteArray reason_ba = reason.toUtf8();
- if ( ! serverSideSocket )
- {
- reason_ba = QWsSocket::mask( reason_ba, maskingKey );
- }
- body.append( reason_ba );
- }
-
- BA.append( body );
- }
-
- // Send closing handshake
- tcpSocket->write( BA );
-
- break;
- }
- case WS_V0:
- {
- QByteArray closeFrame;
- closeFrame.append( (char)0xFF );
- closeFrame.append( (char)0x00 );
- tcpSocket->write( closeFrame );
- break;
- }
- default:
- {
- break;
- }
- }
-
- closingHandshakeSent = true;
- }
-
- if ( QAbstractSocket::state() != QAbstractSocket::ClosingState )
- {
- QAbstractSocket::setSocketState( QAbstractSocket::ClosingState );
- emit QAbstractSocket::stateChanged( QAbstractSocket::ClosingState );
- emit QAbstractSocket::aboutToClose();
- }
-
- if ( closingHandshakeSent && closingHandshakeReceived )
- {
- QAbstractSocket::setSocketState( QAbstractSocket::UnconnectedState );
- emit stateChanged( QAbstractSocket::UnconnectedState );
- emit disconnected();
- tcpSocket->disconnectFromHost();
- }
-}
-
-qint64 QWsSocket::write( const QString & string )
-{
- if ( _version == WS_V0 )
- {
- return QWsSocket::write( string.toUtf8() );
- }
-
- const QList<QByteArray>& framesList = QWsSocket::composeFrames( string.toUtf8(), false, maxBytesPerFrame );
- return writeFrames( framesList );
-}
-
-qint64 QWsSocket::write( const QByteArray & byteArray )
-{
- if ( _version == WS_V0 )
- {
- QByteArray BA;
- BA.append( (char)0x00 );
- BA.append( byteArray );
- BA.append( (char)0xFF );
- return writeFrame( BA );
- }
-
- const QList<QByteArray>& framesList = QWsSocket::composeFrames( byteArray, true, maxBytesPerFrame );
-
- qint64 nbBytesWritten = writeFrames( framesList );
- emit bytesWritten( nbBytesWritten );
-
- return nbBytesWritten;
-}
-
-void QWsSocket::processHandshake()
-{
- //copy from QWsServer::dataReceived();
- QTcpSocket * tcpSocket = qobject_cast<QTcpSocket*>( sender() );
- if (tcpSocket == 0)
- return;
-
- bool allHeadersFetched = false;
-
- const QLatin1String emptyLine("\r\n");
-
- while ( tcpSocket->canReadLine() )
- {
- QString line = tcpSocket->readLine();
-
- if (line == emptyLine)
- {
- allHeadersFetched = true;
- break;
- }
-
- handshakeResponse.append(line);
- }
-
- if (!allHeadersFetched)
- return;
-
- QRegExp regExp;
- regExp.setMinimal( true );
-
- // check accept field
- regExp.setPattern(regExpAcceptStr);
- regExp.indexIn(handshakeResponse);
- QString acceptFromServer = regExp.cap(1);
-
- // check upgrade field
- regExp.setPattern(regExpUpgradeStr);
- regExp.indexIn(handshakeResponse);
- QString upgrade = regExp.cap(1);
-
- // check connection field
- regExp.setPattern(regExpConnectionStr);
- regExp.indexIn(handshakeResponse);
- QString connection = regExp.cap(1);
-
- // check extensions field
- regExp.setPattern(QWsServer::regExpExtensionsStr);
- regExp.indexIn(handshakeResponse);
- QString extensions = regExp.cap(1);
-
- //TODO: check extensions field
- // If the mandatory params are not setted, we abord the connection to the Websocket server
- if((acceptFromServer.isEmpty()) || (!upgrade.contains(QLatin1String("websocket"), Qt::CaseInsensitive)) ||
- (!connection.contains(QLatin1String("Upgrade"), Qt::CaseInsensitive)))
- {
- // emit error(QAbstractSocket::ConnectionRefusedError);
- // return;
- }
-
- //TODO: check HTTP code
-
- //TODO: check protocol field
-
- QString accept = QWsServer::computeAcceptV4(key);
- if(accept != acceptFromServer)
- {
- // emit error(QAbstractSocket::ConnectionRefusedError);
- // return;
- }
-
- // handshake procedure succeeded
- QAbstractSocket::setSocketState( QAbstractSocket::ConnectedState );
- emit QAbstractSocket::stateChanged( QAbstractSocket::ConnectedState );
- emit QAbstractSocket::connected();
-}
-
-void QWsSocket::processDataV0()
-{
- if( state() == QAbstractSocket::ConnectingState )
- {
- processHandshake();
- return;
- }
-
- QByteArray BA, buffer;
- quint8 type, b = 0x00;
-
- BA = tcpSocket->read(1); //TODO: refactor like processDataV4
- type = BA[0];
-
- if ( ( type & 0x80 ) == 0x00 ) // MSB of type not set
- {
- if ( type != 0x00 )
- {
- // ABORT CONNEXION
- tcpSocket->readAll();
- return;
- }
-
- // read data
- do
- {
- BA = tcpSocket->read(1);
- b = BA[0];
- if ( b != 0xFF )
- buffer.append( b );
- } while ( b != 0xFF );
-
- currentFrame.append( buffer );
- }
- else // MSB of type set
- {
- if ( type != 0xFF )
- {
- // ERROR, ABORT CONNEXION
- close();
- return;
- }
-
- quint8 length = 0x00;
-
- bool bIsNotZero = true;
- do
- {
- BA = tcpSocket->read(1);
- b = BA[0];
- bIsNotZero = ( b != 0x00 ? true : false );
- if ( bIsNotZero ) // b must be != 0
- {
- quint8 b_v = b & 0x7F;
- length *= 128;
- length += b_v;
- }
- } while ( ( ( b & 0x80 ) == 0x80 ) && bIsNotZero );
-
- BA = tcpSocket->read(length); // discard this bytes
- }
-
- if ( currentFrame.size() > 0 )
- {
- emit frameReceived( QString::fromUtf8(currentFrame) );
- currentFrame.clear();
- }
-
- if ( tcpSocket->bytesAvailable() )
- processDataV0();
-}
-
-void QWsSocket::processDataV4()
-{
- if( state() == QAbstractSocket::ConnectingState )
- {
- processHandshake();
- }
- else
- while (true)
- switch ( readingState ) {
- case HeaderPending: {
- if (tcpSocket->bytesAvailable() < 2)
- return;
-
- // END, RSV1-3, Opcode
- char header[2];
- tcpSocket->read(header, 2); // XXX: Handle return value
- isFinalFragment = (header[0] & 0x80) != 0;
- opcode = static_cast<EOpcode>(header[0] & 0x0F);
-
- // Mask, PayloadLength
- hasMask = (header[1] & 0x80) != 0;
- quint8 length = (header[1] & 0x7F);
-
- switch (length)
- {
- case 126:
- readingState = PayloadLengthPending;
- break;
- case 127:
- readingState = BigPayloadLenghPending;
- break;
- default:
- payloadLength = length;
- readingState = MaskPending;
- break;
- }
- }; break;
- case PayloadLengthPending: {
- if (tcpSocket->bytesAvailable() < 2)
- return;
-
- uchar length[2];
- tcpSocket->read(reinterpret_cast<char *>(length), 2); // XXX: Handle return value
- payloadLength = qFromBigEndian<quint16>(reinterpret_cast<const uchar *>(length));
- readingState = MaskPending;
- }; break;
- case BigPayloadLenghPending: {
- if (tcpSocket->bytesAvailable() < 8)
- return;
-
- uchar length[8];
- tcpSocket->read(reinterpret_cast<char *>(length), 8); // XXX: Handle return value
- // Most significant bit must be set to 0 as per http://tools.ietf.org/html/rfc6455#section-5.2
- // XXX: Check for that?
- payloadLength = qFromBigEndian<quint64>(length) & ~(1LL << 63);
- readingState = MaskPending;
- }; break;
- case MaskPending: {
- if (!hasMask) {
- readingState = PayloadBodyPending;
- break;
- }
-
- if (tcpSocket->bytesAvailable() < 4)
- return;
-
- tcpSocket->read(maskingKey.data(), 4); // XXX: Handle return value
-
- if ( opcode == OpClose )
- {
- readingState = CloseDataPending;
- }
- else
- {
- readingState = PayloadBodyPending;
- }
- }; /* Intentional fall-through */
- case PayloadBodyPending: {
- // TODO: Handle large payloads
- if (tcpSocket->bytesAvailable() < static_cast<qint32>(payloadLength))
- return;
-
- if ( opcode == OpClose )
- {
- if ( payloadLength >= 2 && tcpSocket->bytesAvailable() >= 2 )
- {
- uchar bytes[2];
- tcpSocket->read( reinterpret_cast<char *>(bytes), 2 );
- closeStatusCode = (ECloseStatusCode)qFromBigEndian<quint16>( reinterpret_cast<const uchar *>(bytes) );
- }
- else
- {
- closeStatusCode = NoCloseStatusCode;
- }
- }
-
- QByteArray ApplicationData = tcpSocket->read( payloadLength );
- if ( hasMask )
- ApplicationData = QWsSocket::mask( ApplicationData, maskingKey );
- currentFrame.append( ApplicationData );
-
- readingState = HeaderPending;
-
- if ( !isFinalFragment )
- break;
-
- switch ( opcode )
- {
- case OpBinary:
- emit frameReceived( currentFrame );
- break;
- case OpText:
- emit frameReceived( QString::fromUtf8(currentFrame) );
- break;
- case OpPing:
- write( QWsSocket::composeHeader( true, OpPong, 0 ) );
- break;
- case OpPong:
- emit pong( pingTimer.elapsed() );
- break;
- case OpClose:
- closingHandshakeReceived = true;
- close( closeStatusCode );
- break;
- default:
- // DO NOTHING
- break;
- }
-
- currentFrame.clear();
- }; break;
- case CloseDataPending:
- default:
- break;
- } /* while (true) switch */
-}
-
-qint64 QWsSocket::writeFrame ( const QByteArray & byteArray )
-{
- return tcpSocket->write( byteArray );
-}
-
-qint64 QWsSocket::writeFrames ( const QList<QByteArray> & framesList )
-{
- qint64 nbBytesWritten = 0;
- for ( int i=0 ; i<framesList.size() ; i++ )
- {
- nbBytesWritten += writeFrame( framesList[i] );
- }
- return nbBytesWritten;
-}
-
-void QWsSocket::processTcpStateChanged( QAbstractSocket::SocketState tcpSocketState )
-{
- QAbstractSocket::SocketState wsSocketState = QAbstractSocket::state();
- switch ( tcpSocketState )
- {
- case QAbstractSocket::HostLookupState:
- {
- QAbstractSocket::setSocketState( QAbstractSocket::HostLookupState );
- emit QAbstractSocket::stateChanged( QAbstractSocket::HostLookupState );
- break;
- }
- case QAbstractSocket::ConnectingState:
- {
- QAbstractSocket::setSocketState( QAbstractSocket::ConnectingState );
- emit QAbstractSocket::stateChanged( QAbstractSocket::ConnectingState );
- break;
- }
- case QAbstractSocket::ConnectedState:
- {
- if ( wsSocketState == QAbstractSocket::ConnectingState )
- {
- key = QWsServer::generateNonce();
- QString handshake = composeOpeningHandShake( QLatin1String("/"), QLatin1String("example.com"), QString(), QString(), key );
- tcpSocket->write( handshake.toUtf8() );
- }
- break;
- }
- case QAbstractSocket::ClosingState:
- {
- if ( wsSocketState == QAbstractSocket::ConnectedState )
- {
- QWsSocket::close( CloseGoingAway );
- QAbstractSocket::setSocketState( QAbstractSocket::ClosingState );
- emit QAbstractSocket::stateChanged( QAbstractSocket::ClosingState );
- emit QAbstractSocket::aboutToClose();
- }
- break;
- }
- case QAbstractSocket::UnconnectedState:
- {
- if ( wsSocketState != QAbstractSocket::UnconnectedState )
- {
- QAbstractSocket::setSocketError( QAbstractSocket::NetworkError );
- emit QAbstractSocket::error( QAbstractSocket::NetworkError );
- QAbstractSocket::setSocketState( QAbstractSocket::UnconnectedState );
- emit QAbstractSocket::stateChanged( QAbstractSocket::UnconnectedState );
- emit QAbstractSocket::disconnected();
- }
- closingHandshakeSent = false;
- closingHandshakeReceived = false;
- break;
- }
- default:
- break;
- }
-}
-
-QByteArray QWsSocket::generateMaskingKey()
-{
- QByteArray key;
- for ( int i=0 ; i<4 ; i++ )
- {
- key.append( qrand() % 0x100 );
- }
- return key;
-}
-
-QByteArray QWsSocket::generateMaskingKeyV4( QString key, QString nonce )
-{
- QString concat = key + nonce + QLatin1String("61AC5F19-FBBA-4540-B96F-6561F1AB40A8");
- QByteArray hash = QCryptographicHash::hash ( concat.toUtf8(), QCryptographicHash::Sha1 );
- return hash;
-}
-
-QByteArray QWsSocket::mask( QByteArray & data, QByteArray & maskingKey )
-{
- QByteArray result;
- result.reserve( data.size() );
-
- for ( int i=0 ; i<data.size() ; i++ )
- {
- result[i] = ( data[i] ^ maskingKey[ i % 4 ] );
- }
-
- return result;
-}
-
-QList<QByteArray> QWsSocket::composeFrames( QByteArray byteArray, bool asBinary, int maxFrameBytes )
-{
- if ( maxFrameBytes == 0 )
- maxFrameBytes = maxBytesPerFrame;
-
- QList<QByteArray> framesList;
-
- QByteArray maskingKey;
-
- int nbFrames = byteArray.size() / maxFrameBytes + 1;
-
- for ( int i=0 ; i<nbFrames ; i++ )
- {
- QByteArray BA;
-
- // end, size
- bool end = false;
- quint64 size = maxFrameBytes;
- EOpcode opcode = OpContinue;
- if ( i == nbFrames-1 ) // for multi-frames
- {
- end = true;
- size = byteArray.size();
- }
- if ( i == 0 )
- {
- if ( asBinary )
- opcode = OpBinary;
- else
- opcode = OpText;
- }
-
- // Header
- BA.append( QWsSocket::composeHeader( end, opcode, size, maskingKey ) );
-
- // Application Data
- QByteArray dataForThisFrame = byteArray.left( size );
- byteArray.remove( 0, size );
-
- //dataForThisFrame = QWsSocket::mask( dataForThisFrame, maskingKey );
- BA.append( dataForThisFrame );
-
- framesList << BA;
- }
-
- return framesList;
-}
-
-QByteArray QWsSocket::composeHeader( bool end, EOpcode opcode, quint64 payloadLength, QByteArray maskingKey )
-{
- QByteArray BA;
- quint8 byte;
-
- // end, RSV1-3, Opcode
- byte = 0x00;
- // end
- if ( end )
- byte = (byte | 0x80);
- // Opcode
- byte = (byte | opcode);
- BA.append( byte );
-
- // Mask, PayloadLength
- byte = 0x00;
- QByteArray BAsize;
- // Mask
- if ( maskingKey.size() == 4 )
- byte = (byte | 0x80);
- // PayloadLength
- if ( payloadLength <= 125 )
- {
- byte = (byte | payloadLength);
- }
- // Extended payloadLength
- else
- {
- // 2 bytes
- if ( payloadLength <= 0xFFFF )
- {
- byte = ( byte | 126 );
- BAsize.append( ( payloadLength >> 1*8 ) & 0xFF );
- BAsize.append( ( payloadLength >> 0*8 ) & 0xFF );
- }
- // 8 bytes
- else if ( payloadLength <= 0x7FFFFFFF )
- {
- byte = ( byte | 127 );
- BAsize.append( ( payloadLength >> 7*8 ) & 0xFF );
- BAsize.append( ( payloadLength >> 6*8 ) & 0xFF );
- BAsize.append( ( payloadLength >> 5*8 ) & 0xFF );
- BAsize.append( ( payloadLength >> 4*8 ) & 0xFF );
- BAsize.append( ( payloadLength >> 3*8 ) & 0xFF );
- BAsize.append( ( payloadLength >> 2*8 ) & 0xFF );
- BAsize.append( ( payloadLength >> 1*8 ) & 0xFF );
- BAsize.append( ( payloadLength >> 0*8 ) & 0xFF );
- }
- }
- BA.append( byte );
- BA.append( BAsize );
-
- // Masking
- if ( maskingKey.size() == 4 )
- BA.append( maskingKey );
-
- return BA;
-}
-
-void QWsSocket::ping()
-{
- pingTimer.restart();
- QByteArray pingFrame = QWsSocket::composeHeader( true, OpPing, 0 );
- writeFrame( pingFrame );
-}
-
-void QWsSocket::setResourceName( QString rn )
-{
- _resourceName = rn;
-}
-
-void QWsSocket::setHost( QString h )
-{
- _host = h;
-}
-
-void QWsSocket::setHostAddress( QString ha )
-{
- _hostAddress = ha;
-}
-
-void QWsSocket::setHostPort( int hp )
-{
- _hostPort = hp;
-}
-
-void QWsSocket::setOrigin( QString o )
-{
- _origin = o;
+const QString QWsSocket::regExpConnectionStr(
+ QLatin1String("Connection:\\s(.+)\r\n"));
+
+QWsSocket::QWsSocket(QObject* parent,
+ QTcpSocket* socket,
+ EWebsocketVersion ws_v)
+ : QAbstractSocket(QAbstractSocket::UnknownSocketType, parent)
+ , tcpSocket(socket ? socket : new QTcpSocket(this))
+ , _version(ws_v)
+ , _hostPort(-1)
+ , closingHandshakeSent(false)
+ , closingHandshakeReceived(false)
+ , readingState(HeaderPending)
+ , isFinalFragment(false)
+ , hasMask(false)
+ , payloadLength(0)
+ , maskingKey(4, 0)
+ , serverSideSocket(false) {
+ tcpSocket->setParent(this);
+
+ QAbstractSocket::setSocketState(tcpSocket->state());
+ QAbstractSocket::setPeerAddress(tcpSocket->peerAddress());
+ QAbstractSocket::setPeerPort(tcpSocket->peerPort());
+
+ if (_version == WS_V0)
+ connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(processDataV0()));
+ else if (_version >= WS_V4)
+ connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(processDataV4()));
+ connect(tcpSocket,
+ SIGNAL(error(QAbstractSocket::SocketError)),
+ this,
+ SIGNAL(error(QAbstractSocket::SocketError)));
+ connect(tcpSocket,
+ SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&,
+ QAuthenticator*)),
+ this,
+ SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&,
+ QAuthenticator*)));
+ connect(tcpSocket,
+ SIGNAL(stateChanged(QAbstractSocket::SocketState)),
+ this,
+ SLOT(processTcpStateChanged(QAbstractSocket::SocketState)));
+ connect(tcpSocket,
+ SIGNAL(readChannelFinished()),
+ this,
+ SIGNAL(readChannelFinished()));
+ connect(tcpSocket, SIGNAL(hostFound()), this, SIGNAL(hostFound()));
+}
+
+QWsSocket::~QWsSocket() {
+ QAbstractSocket::SocketState state = QAbstractSocket::state();
+ if (state != QAbstractSocket::UnconnectedState) {
+ qDebug() << "CloseAway, socket destroyed in server";
+ close(CloseGoingAway, QLatin1String("The server destroyed the socket."));
+ tcpSocket->abort();
+ QAbstractSocket::setSocketState(QAbstractSocket::UnconnectedState);
+ QAbstractSocket::stateChanged(QAbstractSocket::UnconnectedState);
+ emit QAbstractSocket::disconnected();
+ }
+}
+
+void QWsSocket::connectToHost(const QString& hostName,
+ quint16 port,
+ OpenMode mode) {
+ QWsSocket::connectToHost(QHostAddress(hostName), port, mode);
+}
+
+void QWsSocket::connectToHost(const QHostAddress& address,
+ quint16 port,
+ OpenMode mode) {
+ handshakeResponse.clear();
+ setPeerAddress(address);
+ setPeerPort(port);
+ setOpenMode(mode);
+ tcpSocket->connectToHost(address, port, mode);
+}
+
+void QWsSocket::disconnectFromHost() {
+ QWsSocket::close();
+}
+
+void QWsSocket::abort(QString reason) {
+ QWsSocket::close(CloseAbnormalDisconnection, reason);
+ tcpSocket->abort();
+}
+
+void QWsSocket::close(ECloseStatusCode closeStatusCode, QString reason) {
+ if (QAbstractSocket::state() == QAbstractSocket::UnconnectedState)
+ return;
+
+ if (!closingHandshakeSent) {
+ switch (_version) {
+ case WS_V4:
+ case WS_V5:
+ case WS_V6:
+ case WS_V7:
+ case WS_V8:
+ case WS_V13: {
+ // Compose and send close frame
+ QByteArray BA;
+
+ // Body
+ if (closeStatusCode == NoCloseStatusCode) {
+ // Header
+ BA.append(QWsSocket::composeHeader(true, OpClose, 0));
+ } else {
+ // Header
+ QByteArray maskingKey;
+ if (!serverSideSocket)
+ maskingKey = QWsSocket::generateMaskingKey();
+ BA.append(QWsSocket::composeHeader(
+ true, OpClose, reason.size() + 2, maskingKey));
+
+ QByteArray body;
+
+ // Close status code (optional)
+ body.append(QWsServer::serializeInt((int)closeStatusCode, 2));
+
+ // Reason (optional)
+ if (reason.size()) {
+ QByteArray reason_ba = reason.toUtf8();
+ if (!serverSideSocket) {
+ reason_ba = QWsSocket::mask(reason_ba, maskingKey);
+ }
+ body.append(reason_ba);
+ }
+
+ BA.append(body);
+ }
+
+ // Send closing handshake
+ tcpSocket->write(BA);
+
+ break;
+ }
+ case WS_V0: {
+ QByteArray closeFrame;
+ closeFrame.append((char)0xFF);
+ closeFrame.append((char)0x00);
+ tcpSocket->write(closeFrame);
+ break;
+ }
+ default: { break; }
+ }
+
+ closingHandshakeSent = true;
+ }
+
+ if (QAbstractSocket::state() != QAbstractSocket::ClosingState) {
+ QAbstractSocket::setSocketState(QAbstractSocket::ClosingState);
+ emit QAbstractSocket::stateChanged(QAbstractSocket::ClosingState);
+ emit QAbstractSocket::aboutToClose();
+ }
+
+ if (closingHandshakeSent && closingHandshakeReceived) {
+ QAbstractSocket::setSocketState(QAbstractSocket::UnconnectedState);
+ emit stateChanged(QAbstractSocket::UnconnectedState);
+ emit disconnected();
+ tcpSocket->disconnectFromHost();
+ }
+}
+
+qint64 QWsSocket::write(const QString& string) {
+ if (_version == WS_V0) {
+ return QWsSocket::write(string.toUtf8());
+ }
+
+ const QList<QByteArray>& framesList =
+ QWsSocket::composeFrames(string.toUtf8(), false, maxBytesPerFrame);
+ return writeFrames(framesList);
+}
+
+qint64 QWsSocket::write(const QByteArray& byteArray) {
+ if (_version == WS_V0) {
+ QByteArray BA;
+ BA.append((char)0x00);
+ BA.append(byteArray);
+ BA.append((char)0xFF);
+ return writeFrame(BA);
+ }
+
+ const QList<QByteArray>& framesList =
+ QWsSocket::composeFrames(byteArray, true, maxBytesPerFrame);
+
+ qint64 nbBytesWritten = writeFrames(framesList);
+ emit bytesWritten(nbBytesWritten);
+
+ return nbBytesWritten;
+}
+
+void QWsSocket::processHandshake() {
+ // copy from QWsServer::dataReceived();
+ QTcpSocket* tcpSocket = qobject_cast<QTcpSocket*>(sender());
+ if (tcpSocket == 0)
+ return;
+
+ bool allHeadersFetched = false;
+
+ const QLatin1String emptyLine("\r\n");
+
+ while (tcpSocket->canReadLine()) {
+ QString line = tcpSocket->readLine();
+
+ if (line == emptyLine) {
+ allHeadersFetched = true;
+ break;
+ }
+
+ handshakeResponse.append(line);
+ }
+
+ if (!allHeadersFetched)
+ return;
+
+ QRegExp regExp;
+ regExp.setMinimal(true);
+
+ // check accept field
+ regExp.setPattern(regExpAcceptStr);
+ regExp.indexIn(handshakeResponse);
+ QString acceptFromServer = regExp.cap(1);
+
+ // check upgrade field
+ regExp.setPattern(regExpUpgradeStr);
+ regExp.indexIn(handshakeResponse);
+ QString upgrade = regExp.cap(1);
+
+ // check connection field
+ regExp.setPattern(regExpConnectionStr);
+ regExp.indexIn(handshakeResponse);
+ QString connection = regExp.cap(1);
+
+ // check extensions field
+ regExp.setPattern(QWsServer::regExpExtensionsStr);
+ regExp.indexIn(handshakeResponse);
+ QString extensions = regExp.cap(1);
+
+ // TODO: check extensions field
+ // If the mandatory params are not setted, we abord the connection to the
+ // Websocket server
+ if ((acceptFromServer.isEmpty()) ||
+ (!upgrade.contains(QLatin1String("websocket"), Qt::CaseInsensitive)) ||
+ (!connection.contains(QLatin1String("Upgrade"), Qt::CaseInsensitive))) {
+ // emit error(QAbstractSocket::ConnectionRefusedError);
+ // return;
+ }
+
+ // TODO: check HTTP code
+
+ // TODO: check protocol field
+
+ QString accept = QWsServer::computeAcceptV4(key);
+ if (accept != acceptFromServer) {
+ // emit error(QAbstractSocket::ConnectionRefusedError);
+ // return;
+ }
+
+ // handshake procedure succeeded
+ QAbstractSocket::setSocketState(QAbstractSocket::ConnectedState);
+ emit QAbstractSocket::stateChanged(QAbstractSocket::ConnectedState);
+ emit QAbstractSocket::connected();
+}
+
+void QWsSocket::processDataV0() {
+ if (state() == QAbstractSocket::ConnectingState) {
+ processHandshake();
+ return;
+ }
+
+ QByteArray BA, buffer;
+ quint8 type, b = 0x00;
+
+ BA = tcpSocket->read(1); // TODO: refactor like processDataV4
+ type = BA[0];
+
+ if ((type & 0x80) == 0x00) // MSB of type not set
+ {
+ if (type != 0x00) {
+ // ABORT CONNEXION
+ tcpSocket->readAll();
+ return;
+ }
+
+ // read data
+ do {
+ BA = tcpSocket->read(1);
+ b = BA[0];
+ if (b != 0xFF)
+ buffer.append(b);
+ } while (b != 0xFF);
+
+ currentFrame.append(buffer);
+ } else // MSB of type set
+ {
+ if (type != 0xFF) {
+ // ERROR, ABORT CONNEXION
+ close();
+ return;
+ }
+
+ quint8 length = 0x00;
+
+ bool bIsNotZero = true;
+ do {
+ BA = tcpSocket->read(1);
+ b = BA[0];
+ bIsNotZero = (b != 0x00 ? true : false);
+ if (bIsNotZero) // b must be != 0
+ {
+ quint8 b_v = b & 0x7F;
+ length *= 128;
+ length += b_v;
+ }
+ } while (((b & 0x80) == 0x80) && bIsNotZero);
+
+ BA = tcpSocket->read(length); // discard this bytes
+ }
+
+ if (currentFrame.size() > 0) {
+ emit frameReceived(QString::fromUtf8(currentFrame));
+ currentFrame.clear();
+ }
+
+ if (tcpSocket->bytesAvailable())
+ processDataV0();
+}
+
+void QWsSocket::processDataV4() {
+ if (state() == QAbstractSocket::ConnectingState) {
+ processHandshake();
+ } else
+ while (true)
+ switch (readingState) {
+ case HeaderPending: {
+ if (tcpSocket->bytesAvailable() < 2)
+ return;
+
+ // END, RSV1-3, Opcode
+ char header[2];
+ tcpSocket->read(header, 2); // XXX: Handle return value
+ isFinalFragment = (header[0] & 0x80) != 0;
+ opcode = static_cast<EOpcode>(header[0] & 0x0F);
+
+ // Mask, PayloadLength
+ hasMask = (header[1] & 0x80) != 0;
+ quint8 length = (header[1] & 0x7F);
+
+ switch (length) {
+ case 126:
+ readingState = PayloadLengthPending;
+ break;
+ case 127:
+ readingState = BigPayloadLenghPending;
+ break;
+ default:
+ payloadLength = length;
+ readingState = MaskPending;
+ break;
+ }
+ }; break;
+ case PayloadLengthPending: {
+ if (tcpSocket->bytesAvailable() < 2)
+ return;
+
+ uchar length[2];
+ tcpSocket->read(reinterpret_cast<char*>(length),
+ 2); // XXX: Handle return value
+ payloadLength =
+ qFromBigEndian<quint16>(reinterpret_cast<const uchar*>(length));
+ readingState = MaskPending;
+ }; break;
+ case BigPayloadLenghPending: {
+ if (tcpSocket->bytesAvailable() < 8)
+ return;
+
+ uchar length[8];
+ tcpSocket->read(reinterpret_cast<char*>(length),
+ 8); // XXX: Handle return value
+ // Most significant bit must be set to 0 as per
+ // http://tools.ietf.org/html/rfc6455#section-5.2
+ // XXX: Check for that?
+ payloadLength = qFromBigEndian<quint64>(length) & ~(1LL << 63);
+ readingState = MaskPending;
+ }; break;
+ case MaskPending: {
+ if (!hasMask) {
+ readingState = PayloadBodyPending;
+ break;
+ }
+
+ if (tcpSocket->bytesAvailable() < 4)
+ return;
+
+ tcpSocket->read(maskingKey.data(), 4); // XXX: Handle return value
+
+ if (opcode == OpClose) {
+ readingState = CloseDataPending;
+ } else {
+ readingState = PayloadBodyPending;
+ }
+ }; /* Intentional fall-through */
+ case PayloadBodyPending: {
+ // TODO: Handle large payloads
+ if (tcpSocket->bytesAvailable() < static_cast<qint32>(payloadLength))
+ return;
+
+ if (opcode == OpClose) {
+ if (payloadLength >= 2 && tcpSocket->bytesAvailable() >= 2) {
+ uchar bytes[2];
+ tcpSocket->read(reinterpret_cast<char*>(bytes), 2);
+ closeStatusCode = (ECloseStatusCode)qFromBigEndian<quint16>(
+ reinterpret_cast<const uchar*>(bytes));
+ } else {
+ closeStatusCode = NoCloseStatusCode;
+ }
+ }
+
+ QByteArray ApplicationData = tcpSocket->read(payloadLength);
+ if (hasMask)
+ ApplicationData = QWsSocket::mask(ApplicationData, maskingKey);
+ currentFrame.append(ApplicationData);
+
+ readingState = HeaderPending;
+
+ if (!isFinalFragment)
+ break;
+
+ switch (opcode) {
+ case OpBinary:
+ emit frameReceived(currentFrame);
+ break;
+ case OpText:
+ emit frameReceived(QString::fromUtf8(currentFrame));
+ break;
+ case OpPing:
+ write(QWsSocket::composeHeader(true, OpPong, 0));
+ break;
+ case OpPong:
+ emit pong(pingTimer.elapsed());
+ break;
+ case OpClose:
+ closingHandshakeReceived = true;
+ close(closeStatusCode);
+ break;
+ default:
+ // DO NOTHING
+ break;
+ }
+
+ currentFrame.clear();
+ }; break;
+ case CloseDataPending:
+ default:
+ break;
+ } /* while (true) switch */
+}
+
+qint64 QWsSocket::writeFrame(const QByteArray& byteArray) {
+ return tcpSocket->write(byteArray);
+}
+
+qint64 QWsSocket::writeFrames(const QList<QByteArray>& framesList) {
+ qint64 nbBytesWritten = 0;
+ for (int i = 0; i < framesList.size(); i++) {
+ nbBytesWritten += writeFrame(framesList[i]);
+ }
+ return nbBytesWritten;
+}
+
+void QWsSocket::processTcpStateChanged(
+ QAbstractSocket::SocketState tcpSocketState) {
+ QAbstractSocket::SocketState wsSocketState = QAbstractSocket::state();
+ switch (tcpSocketState) {
+ case QAbstractSocket::HostLookupState: {
+ QAbstractSocket::setSocketState(QAbstractSocket::HostLookupState);
+ emit QAbstractSocket::stateChanged(QAbstractSocket::HostLookupState);
+ break;
+ }
+ case QAbstractSocket::ConnectingState: {
+ QAbstractSocket::setSocketState(QAbstractSocket::ConnectingState);
+ emit QAbstractSocket::stateChanged(QAbstractSocket::ConnectingState);
+ break;
+ }
+ case QAbstractSocket::ConnectedState: {
+ if (wsSocketState == QAbstractSocket::ConnectingState) {
+ key = QWsServer::generateNonce();
+ QString handshake =
+ composeOpeningHandShake(QLatin1String("/"),
+ QLatin1String("example.com"),
+ QString(),
+ QString(),
+ key);
+ tcpSocket->write(handshake.toUtf8());
+ }
+ break;
+ }
+ case QAbstractSocket::ClosingState: {
+ if (wsSocketState == QAbstractSocket::ConnectedState) {
+ QWsSocket::close(CloseGoingAway);
+ QAbstractSocket::setSocketState(QAbstractSocket::ClosingState);
+ emit QAbstractSocket::stateChanged(QAbstractSocket::ClosingState);
+ emit QAbstractSocket::aboutToClose();
+ }
+ break;
+ }
+ case QAbstractSocket::UnconnectedState: {
+ if (wsSocketState != QAbstractSocket::UnconnectedState) {
+ QAbstractSocket::setSocketError(QAbstractSocket::NetworkError);
+ emit QAbstractSocket::error(QAbstractSocket::NetworkError);
+ QAbstractSocket::setSocketState(QAbstractSocket::UnconnectedState);
+ emit QAbstractSocket::stateChanged(QAbstractSocket::UnconnectedState);
+ emit QAbstractSocket::disconnected();
+ }
+ closingHandshakeSent = false;
+ closingHandshakeReceived = false;
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+QByteArray QWsSocket::generateMaskingKey() {
+ QByteArray key;
+ for (int i = 0; i < 4; i++) {
+ key.append(qrand() % 0x100);
+ }
+ return key;
+}
+
+QByteArray QWsSocket::generateMaskingKeyV4(QString key, QString nonce) {
+ QString concat =
+ key + nonce + QLatin1String("61AC5F19-FBBA-4540-B96F-6561F1AB40A8");
+ QByteArray hash =
+ QCryptographicHash::hash(concat.toUtf8(), QCryptographicHash::Sha1);
+ return hash;
+}
+
+QByteArray QWsSocket::mask(QByteArray& data, QByteArray& maskingKey) {
+ QByteArray result;
+ result.reserve(data.size());
+
+ for (int i = 0; i < data.size(); i++) {
+ result[i] = (data[i] ^ maskingKey[i % 4]);
+ }
+
+ return result;
+}
+
+QList<QByteArray> QWsSocket::composeFrames(QByteArray byteArray,
+ bool asBinary,
+ int maxFrameBytes) {
+ if (maxFrameBytes == 0)
+ maxFrameBytes = maxBytesPerFrame;
+
+ QList<QByteArray> framesList;
+
+ QByteArray maskingKey;
+
+ int nbFrames = byteArray.size() / maxFrameBytes + 1;
+
+ for (int i = 0; i < nbFrames; i++) {
+ QByteArray BA;
+
+ // end, size
+ bool end = false;
+ quint64 size = maxFrameBytes;
+ EOpcode opcode = OpContinue;
+ if (i == nbFrames - 1) // for multi-frames
+ {
+ end = true;
+ size = byteArray.size();
+ }
+ if (i == 0) {
+ if (asBinary)
+ opcode = OpBinary;
+ else
+ opcode = OpText;
+ }
+
+ // Header
+ BA.append(QWsSocket::composeHeader(end, opcode, size, maskingKey));
+
+ // Application Data
+ QByteArray dataForThisFrame = byteArray.left(size);
+ byteArray.remove(0, size);
+
+ // dataForThisFrame = QWsSocket::mask( dataForThisFrame, maskingKey );
+ BA.append(dataForThisFrame);
+
+ framesList << BA;
+ }
+
+ return framesList;
+}
+
+QByteArray QWsSocket::composeHeader(bool end,
+ EOpcode opcode,
+ quint64 payloadLength,
+ QByteArray maskingKey) {
+ QByteArray BA;
+ quint8 byte;
+
+ // end, RSV1-3, Opcode
+ byte = 0x00;
+ // end
+ if (end)
+ byte = (byte | 0x80);
+ // Opcode
+ byte = (byte | opcode);
+ BA.append(byte);
+
+ // Mask, PayloadLength
+ byte = 0x00;
+ QByteArray BAsize;
+ // Mask
+ if (maskingKey.size() == 4)
+ byte = (byte | 0x80);
+ // PayloadLength
+ if (payloadLength <= 125) {
+ byte = (byte | payloadLength);
+ }
+ // Extended payloadLength
+ else {
+ // 2 bytes
+ if (payloadLength <= 0xFFFF) {
+ byte = (byte | 126);
+ BAsize.append((payloadLength >> 1 * 8) & 0xFF);
+ BAsize.append((payloadLength >> 0 * 8) & 0xFF);
+ }
+ // 8 bytes
+ else if (payloadLength <= 0x7FFFFFFF) {
+ byte = (byte | 127);
+ BAsize.append((payloadLength >> 7 * 8) & 0xFF);
+ BAsize.append((payloadLength >> 6 * 8) & 0xFF);
+ BAsize.append((payloadLength >> 5 * 8) & 0xFF);
+ BAsize.append((payloadLength >> 4 * 8) & 0xFF);
+ BAsize.append((payloadLength >> 3 * 8) & 0xFF);
+ BAsize.append((payloadLength >> 2 * 8) & 0xFF);
+ BAsize.append((payloadLength >> 1 * 8) & 0xFF);
+ BAsize.append((payloadLength >> 0 * 8) & 0xFF);
+ }
+ }
+ BA.append(byte);
+ BA.append(BAsize);
+
+ // Masking
+ if (maskingKey.size() == 4)
+ BA.append(maskingKey);
+
+ return BA;
+}
+
+void QWsSocket::ping() {
+ pingTimer.restart();
+ QByteArray pingFrame = QWsSocket::composeHeader(true, OpPing, 0);
+ writeFrame(pingFrame);
+}
+
+void QWsSocket::setResourceName(QString rn) {
+ _resourceName = rn;
+}
+
+void QWsSocket::setHost(QString h) {
+ _host = h;
+}
+
+void QWsSocket::setHostAddress(QString ha) {
+ _hostAddress = ha;
+}
+
+void QWsSocket::setHostPort(int hp) {
+ _hostPort = hp;
+}
+
+void QWsSocket::setOrigin(QString o) {
+ _origin = o;
}
-void QWsSocket::setProtocol( QString p )
-{
- _protocol = p;
+void QWsSocket::setProtocol(QString p) {
+ _protocol = p;
}
-void QWsSocket::setExtensions( QString e )
-{
- _extensions = e;
+void QWsSocket::setExtensions(QString e) {
+ _extensions = e;
}
-EWebsocketVersion QWsSocket::version()
-{
- return _version;
+EWebsocketVersion QWsSocket::version() {
+ return _version;
}
-QString QWsSocket::resourceName()
-{
- return _resourceName;
+QString QWsSocket::resourceName() {
+ return _resourceName;
}
-QString QWsSocket::host()
-{
- return _host;
+QString QWsSocket::host() {
+ return _host;
}
-QString QWsSocket::hostAddress()
-{
- return _hostAddress;
+QString QWsSocket::hostAddress() {
+ return _hostAddress;
}
-int QWsSocket::hostPort()
-{
- return _hostPort;
+int QWsSocket::hostPort() {
+ return _hostPort;
}
-QString QWsSocket::origin()
-{
- return _origin;
+QString QWsSocket::origin() {
+ return _origin;
}
-QString QWsSocket::protocol()
-{
- return _protocol;
+QString QWsSocket::protocol() {
+ return _protocol;
}
-QString QWsSocket::extensions()
-{
- return _extensions;
+QString QWsSocket::extensions() {
+ return _extensions;
}
-QString QWsSocket::composeOpeningHandShake( QString resourceName, QString host, QString origin, QString extensions, QString key )
-{
- QString hs;
- hs.append(QLatin1String("GET ") + resourceName + QLatin1String(" HTTP/1.1\r\n"));
- hs.append(QLatin1String("Host: ") + host + "\r\n");
- hs.append(QLatin1String("Upgrade: websocket\r\n"));
- hs.append(QLatin1String("Connection: Upgrade\r\n"));
- hs.append(QLatin1String("Sec-WebSocket-Key: ") + key + QLatin1String("\r\n"));
- hs.append(QLatin1String("Origin: ") + origin + QLatin1String("\r\n"));
- hs.append(QLatin1String("Sec-WebSocket-Extensions: ") + extensions + QLatin1String("\r\n"));
- hs.append(QLatin1String("Sec-WebSocket-Version: 13\r\n"));
- hs.append(QLatin1String("\r\n"));
- return hs;
+QString QWsSocket::composeOpeningHandShake(QString resourceName,
+ QString host,
+ QString origin,
+ QString extensions,
+ QString key) {
+ QString hs;
+ hs.append(QLatin1String("GET ") + resourceName +
+ QLatin1String(" HTTP/1.1\r\n"));
+ hs.append(QLatin1String("Host: ") + host + "\r\n");
+ hs.append(QLatin1String("Upgrade: websocket\r\n"));
+ hs.append(QLatin1String("Connection: Upgrade\r\n"));
+ hs.append(QLatin1String("Sec-WebSocket-Key: ") + key + QLatin1String("\r\n"));
+ hs.append(QLatin1String("Origin: ") + origin + QLatin1String("\r\n"));
+ hs.append(QLatin1String("Sec-WebSocket-Extensions: ") + extensions +
+ QLatin1String("\r\n"));
+ hs.append(QLatin1String("Sec-WebSocket-Version: 13\r\n"));
+ hs.append(QLatin1String("\r\n"));
+ return hs;
}
diff --git a/src/components/qt_hmi/References/Work/fordsdlcore/QtWebsocket/QWsSocket.h b/src/components/qt_hmi/References/Work/fordsdlcore/QtWebsocket/QWsSocket.h
index 4bc095aa19..cdd19db38a 100644
--- a/src/components/qt_hmi/References/Work/fordsdlcore/QtWebsocket/QWsSocket.h
+++ b/src/components/qt_hmi/References/Work/fordsdlcore/QtWebsocket/QWsSocket.h
@@ -5,166 +5,177 @@
#include <QHostAddress>
#include <QTime>
-enum EWebsocketVersion
-{
- WS_VUnknow = -1,
- WS_V0 = 0,
- WS_V4 = 4,
- WS_V5 = 5,
- WS_V6 = 6,
- WS_V7 = 7,
- WS_V8 = 8,
- WS_V13 = 13
+enum EWebsocketVersion {
+ WS_VUnknow = -1,
+ WS_V0 = 0,
+ WS_V4 = 4,
+ WS_V5 = 5,
+ WS_V6 = 6,
+ WS_V7 = 7,
+ WS_V8 = 8,
+ WS_V13 = 13
};
-class QWsSocket : public QAbstractSocket
-{
- Q_OBJECT
-
- friend class QWsServer;
-
-public:
- enum EOpcode
- {
- OpContinue = 0x0,
- OpText = 0x1,
- OpBinary = 0x2,
- OpReserved3 = 0x3,
- OpReserved4 = 0x4,
- OpReserved5 = 0x5,
- OpReserved6 = 0x6,
- OpReserved7 = 0x7,
- OpClose = 0x8,
- OpPing = 0x9,
- OpPong = 0xA,
- OpReservedB = 0xB,
- OpReservedV = 0xC,
- OpReservedD = 0xD,
- OpReservedE = 0xE,
- OpReservedF = 0xF
- };
- enum ECloseStatusCode
- {
- NoCloseStatusCode = 0,
- CloseNormal = 1000,
- CloseGoingAway = 1001,
- CloseProtocolError = 1002,
- CloseDataTypeNotSupported = 1003,
- CloseReserved1004 = 1004,
- CloseMissingStatusCode = 1005,
- CloseAbnormalDisconnection = 1006,
- CloseWrongDataType = 1007,
- ClosePolicyViolated = 1008,
- CloseTooMuchData = 1009,
- CloseMissingExtension = 1010,
- CloseBadOperation = 1011,
- CloseTLSHandshakeFailed = 1015
- };
-
-public:
- // ctor
- QWsSocket( QObject * parent = 0, QTcpSocket * socket = 0, EWebsocketVersion ws_v = WS_V13 );
- // dtor
- virtual ~QWsSocket();
-
- // Public methods
- EWebsocketVersion version();
- QString resourceName();
- QString host();
- QString hostAddress();
- int hostPort();
- QString origin();
- QString protocol();
- QString extensions();
-
- void setResourceName( QString rn );
- void setHost( QString h );
- void setHostAddress( QString ha );
- void setHostPort( int hp );
- void setOrigin( QString o );
- void setProtocol( QString p );
- void setExtensions( QString e );
-
- qint64 write( const QString & string ); // write data as text
- qint64 write( const QByteArray & byteArray ); // write data as binary
-
-public slots:
- void connectToHost( const QString & hostName, quint16 port, OpenMode mode = ReadWrite );
- void connectToHost( const QHostAddress & address, quint16 port, OpenMode mode = ReadWrite );
- void disconnectFromHost();
- void abort( QString reason = QString() );
- void ping();
+class QWsSocket : public QAbstractSocket {
+ Q_OBJECT
+
+ friend class QWsServer;
+
+ public:
+ enum EOpcode {
+ OpContinue = 0x0,
+ OpText = 0x1,
+ OpBinary = 0x2,
+ OpReserved3 = 0x3,
+ OpReserved4 = 0x4,
+ OpReserved5 = 0x5,
+ OpReserved6 = 0x6,
+ OpReserved7 = 0x7,
+ OpClose = 0x8,
+ OpPing = 0x9,
+ OpPong = 0xA,
+ OpReservedB = 0xB,
+ OpReservedV = 0xC,
+ OpReservedD = 0xD,
+ OpReservedE = 0xE,
+ OpReservedF = 0xF
+ };
+ enum ECloseStatusCode {
+ NoCloseStatusCode = 0,
+ CloseNormal = 1000,
+ CloseGoingAway = 1001,
+ CloseProtocolError = 1002,
+ CloseDataTypeNotSupported = 1003,
+ CloseReserved1004 = 1004,
+ CloseMissingStatusCode = 1005,
+ CloseAbnormalDisconnection = 1006,
+ CloseWrongDataType = 1007,
+ ClosePolicyViolated = 1008,
+ CloseTooMuchData = 1009,
+ CloseMissingExtension = 1010,
+ CloseBadOperation = 1011,
+ CloseTLSHandshakeFailed = 1015
+ };
+
+ public:
+ // ctor
+ QWsSocket(QObject* parent = 0,
+ QTcpSocket* socket = 0,
+ EWebsocketVersion ws_v = WS_V13);
+ // dtor
+ virtual ~QWsSocket();
+
+ // Public methods
+ EWebsocketVersion version();
+ QString resourceName();
+ QString host();
+ QString hostAddress();
+ int hostPort();
+ QString origin();
+ QString protocol();
+ QString extensions();
+
+ void setResourceName(QString rn);
+ void setHost(QString h);
+ void setHostAddress(QString ha);
+ void setHostPort(int hp);
+ void setOrigin(QString o);
+ void setProtocol(QString p);
+ void setExtensions(QString e);
+
+ qint64 write(const QString& string); // write data as text
+ qint64 write(const QByteArray& byteArray); // write data as binary
+
+ public slots:
+ void connectToHost(const QString& hostName,
+ quint16 port,
+ OpenMode mode = ReadWrite);
+ void connectToHost(const QHostAddress& address,
+ quint16 port,
+ OpenMode mode = ReadWrite);
+ void disconnectFromHost();
+ void abort(QString reason = QString());
+ void ping();
signals:
- void frameReceived(QString frame);
- void frameReceived(QByteArray frame);
- void pong(quint64 elapsedTime);
-
-protected:
- qint64 writeFrames ( const QList<QByteArray> & framesList );
- qint64 writeFrame ( const QByteArray & byteArray );
-
-protected slots:
- virtual void close( ECloseStatusCode closeStatusCode = NoCloseStatusCode, QString reason = QString() );
- void processDataV0();
- void processDataV4();
- void processHandshake();
- void processTcpStateChanged( QAbstractSocket::SocketState socketState );
-
-private:
- enum EReadingState
- {
- HeaderPending,
- PayloadLengthPending,
- BigPayloadLenghPending,
- MaskPending,
- PayloadBodyPending,
- CloseDataPending
- };
-
- // private vars
- QTcpSocket * tcpSocket;
- QByteArray currentFrame;
- QTime pingTimer;
-
- EWebsocketVersion _version;
- QString _resourceName;
- QString _host;
- QString _hostAddress;
- int _hostPort;
- QString _origin;
- QString _protocol;
- QString _extensions;
- bool serverSideSocket;
-
- bool closingHandshakeSent;
- bool closingHandshakeReceived;
-
- EReadingState readingState;
- EOpcode opcode;
- bool isFinalFragment;
- bool hasMask;
- quint64 payloadLength;
- QByteArray maskingKey;
- ECloseStatusCode closeStatusCode;
-
- static const QString regExpAcceptStr;
- static const QString regExpUpgradeStr;
- static const QString regExpConnectionStr;
- QString handshakeResponse;
- QString key;
-
-public:
- // Static functions
- static QByteArray generateMaskingKey();
- static QByteArray generateMaskingKeyV4( QString key, QString nonce );
- static QByteArray mask( QByteArray & data, QByteArray & maskingKey );
- static QList<QByteArray> composeFrames( QByteArray byteArray, bool asBinary = false, int maxFrameBytes = 0 );
- static QByteArray composeHeader( bool end, EOpcode opcode, quint64 payloadLength, QByteArray maskingKey = QByteArray() );
- static QString composeOpeningHandShake( QString resourceName, QString host, QString origin, QString extensions, QString key );
-
- // static vars
- static int maxBytesPerFrame;
+ void frameReceived(QString frame);
+ void frameReceived(QByteArray frame);
+ void pong(quint64 elapsedTime);
+
+ protected:
+ qint64 writeFrames(const QList<QByteArray>& framesList);
+ qint64 writeFrame(const QByteArray& byteArray);
+
+ protected slots:
+ virtual void close(ECloseStatusCode closeStatusCode = NoCloseStatusCode,
+ QString reason = QString());
+ void processDataV0();
+ void processDataV4();
+ void processHandshake();
+ void processTcpStateChanged(QAbstractSocket::SocketState socketState);
+
+ private:
+ enum EReadingState {
+ HeaderPending,
+ PayloadLengthPending,
+ BigPayloadLenghPending,
+ MaskPending,
+ PayloadBodyPending,
+ CloseDataPending
+ };
+
+ // private vars
+ QTcpSocket* tcpSocket;
+ QByteArray currentFrame;
+ QTime pingTimer;
+
+ EWebsocketVersion _version;
+ QString _resourceName;
+ QString _host;
+ QString _hostAddress;
+ int _hostPort;
+ QString _origin;
+ QString _protocol;
+ QString _extensions;
+ bool serverSideSocket;
+
+ bool closingHandshakeSent;
+ bool closingHandshakeReceived;
+
+ EReadingState readingState;
+ EOpcode opcode;
+ bool isFinalFragment;
+ bool hasMask;
+ quint64 payloadLength;
+ QByteArray maskingKey;
+ ECloseStatusCode closeStatusCode;
+
+ static const QString regExpAcceptStr;
+ static const QString regExpUpgradeStr;
+ static const QString regExpConnectionStr;
+ QString handshakeResponse;
+ QString key;
+
+ public:
+ // Static functions
+ static QByteArray generateMaskingKey();
+ static QByteArray generateMaskingKeyV4(QString key, QString nonce);
+ static QByteArray mask(QByteArray& data, QByteArray& maskingKey);
+ static QList<QByteArray> composeFrames(QByteArray byteArray,
+ bool asBinary = false,
+ int maxFrameBytes = 0);
+ static QByteArray composeHeader(bool end,
+ EOpcode opcode,
+ quint64 payloadLength,
+ QByteArray maskingKey = QByteArray());
+ static QString composeOpeningHandShake(QString resourceName,
+ QString host,
+ QString origin,
+ QString extensions,
+ QString key);
+
+ // static vars
+ static int maxBytesPerFrame;
};
-#endif // QWSSOCKET_H
+#endif // QWSSOCKET_H
diff --git a/src/components/qt_hmi/References/Work/fordsdlcore/fordsdlcore_plugin.cpp b/src/components/qt_hmi/References/Work/fordsdlcore/fordsdlcore_plugin.cpp
index a89d1efcb4..003b098d47 100644
--- a/src/components/qt_hmi/References/Work/fordsdlcore/fordsdlcore_plugin.cpp
+++ b/src/components/qt_hmi/References/Work/fordsdlcore/fordsdlcore_plugin.cpp
@@ -6,26 +6,25 @@
#include <QQmlEngine>
#include <QQmlContext>
-QObject* sdlSingleton(QQmlEngine * engine, QJSEngine * js) {
- Q_UNUSED(engine)
- Q_UNUSED(js)
+QObject* sdlSingleton(QQmlEngine* engine, QJSEngine* js) {
+ Q_UNUSED(engine)
+ Q_UNUSED(js)
- engine->rootContext()->setContextProperty("MediaApps", SmartDeviceLink::getInstance().getMediaApps());
+ engine->rootContext()->setContextProperty(
+ "MediaApps", SmartDeviceLink::getInstance().getMediaApps());
- return (QObject *) &SmartDeviceLink::getInstance();
+ return (QObject*)&SmartDeviceLink::getInstance();
}
-QObject* mediaAppsSingleton(QQmlEngine * engine, QJSEngine * js) {
- Q_UNUSED(engine)
- Q_UNUSED(js)
+QObject* mediaAppsSingleton(QQmlEngine* engine, QJSEngine* js) {
+ Q_UNUSED(engine)
+ Q_UNUSED(js)
- return (QObject *) SmartDeviceLink::getInstance().getMediaApps();
+ return (QObject*)SmartDeviceLink::getInstance().getMediaApps();
}
-void FordSdlCorePlugin::registerTypes(const char *uri)
-{
- qmlRegisterSingletonType<SdlAppsListModel>(uri, 1, 0, "MediaApps", mediaAppsSingleton);
- qmlRegisterSingletonType<SmartDeviceLink>(uri, 1, 0, "AppLink", sdlSingleton);
+void FordSdlCorePlugin::registerTypes(const char* uri) {
+ qmlRegisterSingletonType<SdlAppsListModel>(
+ uri, 1, 0, "MediaApps", mediaAppsSingleton);
+ qmlRegisterSingletonType<SmartDeviceLink>(uri, 1, 0, "AppLink", sdlSingleton);
}
-
-
diff --git a/src/components/qt_hmi/References/Work/fordsdlcore/fordsdlcore_plugin.h b/src/components/qt_hmi/References/Work/fordsdlcore/fordsdlcore_plugin.h
index 655dcb5178..2c8bf39d28 100644
--- a/src/components/qt_hmi/References/Work/fordsdlcore/fordsdlcore_plugin.h
+++ b/src/components/qt_hmi/References/Work/fordsdlcore/fordsdlcore_plugin.h
@@ -3,14 +3,12 @@
#include <QQmlExtensionPlugin>
-class FordSdlCorePlugin : public QQmlExtensionPlugin
-{
- Q_OBJECT
- Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
-
-public:
- void registerTypes(const char *uri);
-};
+class FordSdlCorePlugin : public QQmlExtensionPlugin {
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
-#endif // FORDSDLCORE_PLUGIN_H
+ public:
+ void registerTypes(const char* uri);
+};
+#endif // FORDSDLCORE_PLUGIN_H
diff --git a/src/components/qt_hmi/References/Work/fordsdlcore/sdlalert.cpp b/src/components/qt_hmi/References/Work/fordsdlcore/sdlalert.cpp
index f625c16b41..ec4350df77 100644
--- a/src/components/qt_hmi/References/Work/fordsdlcore/sdlalert.cpp
+++ b/src/components/qt_hmi/References/Work/fordsdlcore/sdlalert.cpp
@@ -1,6 +1,3 @@
#include "sdlalert.h"
-SdlAlert::SdlAlert(QObject *parent) :
- QQuickItem()
-{
-}
+SdlAlert::SdlAlert(QObject* parent) : QQuickItem() {}
diff --git a/src/components/qt_hmi/References/Work/fordsdlcore/sdlalert.h b/src/components/qt_hmi/References/Work/fordsdlcore/sdlalert.h
index cb46236db1..9c32718c56 100644
--- a/src/components/qt_hmi/References/Work/fordsdlcore/sdlalert.h
+++ b/src/components/qt_hmi/References/Work/fordsdlcore/sdlalert.h
@@ -3,16 +3,14 @@
#include <QQuickItem>
-class SdlAlert : public QQuickItem
-{
- Q_OBJECT
-public:
- explicit SdlAlert(QObject *parent = 0);
-
+class SdlAlert : public QQuickItem {
+ Q_OBJECT
+ public:
+ explicit SdlAlert(QObject* parent = 0);
+
signals:
-
-public slots:
-
+
+ public slots:
};
-#endif // SDLALERT_H
+#endif // SDLALERT_H
diff --git a/src/components/qt_hmi/References/Work/fordsdlcore/sdlappslistmodel.cpp b/src/components/qt_hmi/References/Work/fordsdlcore/sdlappslistmodel.cpp
index 104b31abe0..419908339e 100644
--- a/src/components/qt_hmi/References/Work/fordsdlcore/sdlappslistmodel.cpp
+++ b/src/components/qt_hmi/References/Work/fordsdlcore/sdlappslistmodel.cpp
@@ -1,6 +1,4 @@
#include "sdlappslistmodel.h"
-SdlAppsListModel::SdlAppsListModel(QObject *parent) :
- QAbstractListModel(parent)
-{
-}
+SdlAppsListModel::SdlAppsListModel(QObject* parent)
+ : QAbstractListModel(parent) {}
diff --git a/src/components/qt_hmi/References/Work/fordsdlcore/sdlappslistmodel.h b/src/components/qt_hmi/References/Work/fordsdlcore/sdlappslistmodel.h
index 9b213e666e..b78aeeec01 100644
--- a/src/components/qt_hmi/References/Work/fordsdlcore/sdlappslistmodel.h
+++ b/src/components/qt_hmi/References/Work/fordsdlcore/sdlappslistmodel.h
@@ -4,44 +4,44 @@
#include <QAbstractListModel>
#include <QStringList>
-class SdlAppsListModel : public QAbstractListModel
-{
- Q_OBJECT
-public:
- explicit SdlAppsListModel(QObject *parent = 0);
-
- int rowCount(const QModelIndex &parent) const { return m_data.size(); }
-
- QVariant data(const QModelIndex &index, int role) const {
- return m_data.values().at(index.row());
- }
-
- virtual QHash<int, QByteArray> roleNames() const {
- QHash<int, QByteArray> roles;
- roles['t'] = "text";
- return roles;
- }
-
- void append(int id, QString string) {
- beginResetModel();
- m_data.clear();
- m_data[id] = string;
- endResetModel();
- }
-
- void clear() {
- beginResetModel();
- m_data.clear();
- endResetModel();
- }
-
+class SdlAppsListModel : public QAbstractListModel {
+ Q_OBJECT
+ public:
+ explicit SdlAppsListModel(QObject* parent = 0);
+
+ int rowCount(const QModelIndex& parent) const {
+ return m_data.size();
+ }
+
+ QVariant data(const QModelIndex& index, int role) const {
+ return m_data.values().at(index.row());
+ }
+
+ virtual QHash<int, QByteArray> roleNames() const {
+ QHash<int, QByteArray> roles;
+ roles['t'] = "text";
+ return roles;
+ }
+
+ void append(int id, QString string) {
+ beginResetModel();
+ m_data.clear();
+ m_data[id] = string;
+ endResetModel();
+ }
+
+ void clear() {
+ beginResetModel();
+ m_data.clear();
+ endResetModel();
+ }
+
signals:
-
-public slots:
-private:
- QHash<int, QString> m_data;
-
+ public slots:
+
+ private:
+ QHash<int, QString> m_data;
};
-#endif // SDLAPPSLISTMODEL_H
+#endif // SDLAPPSLISTMODEL_H
diff --git a/src/components/qt_hmi/References/Work/fordsdlcore/smartdevicelink.cpp b/src/components/qt_hmi/References/Work/fordsdlcore/smartdevicelink.cpp
index 57cb8ac507..5ee8c455e9 100644
--- a/src/components/qt_hmi/References/Work/fordsdlcore/smartdevicelink.cpp
+++ b/src/components/qt_hmi/References/Work/fordsdlcore/smartdevicelink.cpp
@@ -5,259 +5,382 @@
#include <QJsonObject>
#include <unistd.h>
-SmartDeviceLink::SmartDeviceLink(QQuickItem *parent):
- QObject(parent)
-{
- connect(&m_ws_basic, SIGNAL(connected()), this, SLOT(basic_connected()));
- connect(&m_ws_basic, SIGNAL(frameReceived(QString)), this, SLOT(basic_receive(QString)));
- connect(&m_ws_basic, SIGNAL(disconnected()), this, SLOT(disconnected()));
-
- connect(&m_ws_buttons, SIGNAL(connected()), this, SLOT(buttons_connected()));
- connect(&m_ws_buttons, SIGNAL(frameReceived(QString)), this, SLOT(buttons_receive(QString)));
- connect(&m_ws_buttons, SIGNAL(disconnected()), this, SLOT(disconnected()));
-
- connect(&m_ws_tts, SIGNAL(connected()), this, SLOT(tts_connected()));
- connect(&m_ws_tts, SIGNAL(frameReceived(QString)), this, SLOT(tts_receive(QString)));
- connect(&m_ws_tts, SIGNAL(disconnected()), this, SLOT(disconnected()));
-
- connect(&m_ws_vehicle, SIGNAL(connected()), this, SLOT(vehicle_connected()));
- connect(&m_ws_vehicle, SIGNAL(frameReceived(QString)), this, SLOT(vehicle_receive(QString)));
- connect(&m_ws_vehicle, SIGNAL(disconnected()), this, SLOT(disconnected()));
-
- connect(&m_ws_ui, SIGNAL(connected()), this, SLOT(ui_connected()));
- connect(&m_ws_ui, SIGNAL(frameReceived(QString)), this, SLOT(ui_receive(QString)));
- connect(&m_ws_ui, SIGNAL(disconnected()), this, SLOT(disconnected()));
-
- connect(&m_ws_vr, SIGNAL(connected()), this, SLOT(vr_connected()));
- connect(&m_ws_vr, SIGNAL(frameReceived(QString)), this, SLOT(vr_receive(QString)));
- connect(&m_ws_vr, SIGNAL(disconnected()), this, SLOT(disconnected()));
-
- connect(this, SIGNAL(newAppAvailable(int, QString)), this, SLOT(registerApp(int,QString)));
-
- m_ws_buttons.connectToHost( QLatin1String("127.0.0.1"), 8087 );
- m_ws_tts.connectToHost( QLatin1String("127.0.0.1"), 8087 );
- m_ws_vr.connectToHost( QLatin1String("127.0.0.1"), 8087 );
- m_ws_basic.connectToHost( QLatin1String("127.0.0.1"), 8087 );
- m_ws_vehicle.connectToHost( QLatin1String("127.0.0.1"), 8087 );
- m_ws_ui.connectToHost( QLatin1String("127.0.0.1"), 8087 );
+SmartDeviceLink::SmartDeviceLink(QQuickItem* parent) : QObject(parent) {
+ connect(&m_ws_basic, SIGNAL(connected()), this, SLOT(basic_connected()));
+ connect(&m_ws_basic,
+ SIGNAL(frameReceived(QString)),
+ this,
+ SLOT(basic_receive(QString)));
+ connect(&m_ws_basic, SIGNAL(disconnected()), this, SLOT(disconnected()));
+
+ connect(&m_ws_buttons, SIGNAL(connected()), this, SLOT(buttons_connected()));
+ connect(&m_ws_buttons,
+ SIGNAL(frameReceived(QString)),
+ this,
+ SLOT(buttons_receive(QString)));
+ connect(&m_ws_buttons, SIGNAL(disconnected()), this, SLOT(disconnected()));
+
+ connect(&m_ws_tts, SIGNAL(connected()), this, SLOT(tts_connected()));
+ connect(&m_ws_tts,
+ SIGNAL(frameReceived(QString)),
+ this,
+ SLOT(tts_receive(QString)));
+ connect(&m_ws_tts, SIGNAL(disconnected()), this, SLOT(disconnected()));
+
+ connect(&m_ws_vehicle, SIGNAL(connected()), this, SLOT(vehicle_connected()));
+ connect(&m_ws_vehicle,
+ SIGNAL(frameReceived(QString)),
+ this,
+ SLOT(vehicle_receive(QString)));
+ connect(&m_ws_vehicle, SIGNAL(disconnected()), this, SLOT(disconnected()));
+
+ connect(&m_ws_ui, SIGNAL(connected()), this, SLOT(ui_connected()));
+ connect(&m_ws_ui,
+ SIGNAL(frameReceived(QString)),
+ this,
+ SLOT(ui_receive(QString)));
+ connect(&m_ws_ui, SIGNAL(disconnected()), this, SLOT(disconnected()));
+
+ connect(&m_ws_vr, SIGNAL(connected()), this, SLOT(vr_connected()));
+ connect(&m_ws_vr,
+ SIGNAL(frameReceived(QString)),
+ this,
+ SLOT(vr_receive(QString)));
+ connect(&m_ws_vr, SIGNAL(disconnected()), this, SLOT(disconnected()));
+
+ connect(this,
+ SIGNAL(newAppAvailable(int, QString)),
+ this,
+ SLOT(registerApp(int, QString)));
+
+ m_ws_buttons.connectToHost(QLatin1String("127.0.0.1"), 8087);
+ m_ws_tts.connectToHost(QLatin1String("127.0.0.1"), 8087);
+ m_ws_vr.connectToHost(QLatin1String("127.0.0.1"), 8087);
+ m_ws_basic.connectToHost(QLatin1String("127.0.0.1"), 8087);
+ m_ws_vehicle.connectToHost(QLatin1String("127.0.0.1"), 8087);
+ m_ws_ui.connectToHost(QLatin1String("127.0.0.1"), 8087);
}
-SmartDeviceLink::~SmartDeviceLink()
-{
- qDebug() << "SmartDeviceLink destroyed";
+SmartDeviceLink::~SmartDeviceLink() {
+ qDebug() << "SmartDeviceLink destroyed";
}
void SmartDeviceLink::basic_connected() {
- basic_send("{\"jsonrpc\":\"2.0\",\"id\":600,\"method\":\"MB.registerComponent\",\"params\":{\"componentName\":\"BasicCommunicationClient\"}}");
+ basic_send(
+ "{\"jsonrpc\":\"2.0\",\"id\":600,\"method\":\"MB.registerComponent\","
+ "\"params\":{\"componentName\":\"BasicCommunicationClient\"}}");
}
void SmartDeviceLink::buttons_connected() {
- buttons_send("{\"jsonrpc\":\"2.0\",\"id\":200,\"method\":\"MB.registerComponent\",\"params\":{\"componentName\":\"Buttons\"}}");
+ buttons_send(
+ "{\"jsonrpc\":\"2.0\",\"id\":200,\"method\":\"MB.registerComponent\","
+ "\"params\":{\"componentName\":\"Buttons\"}}");
}
void SmartDeviceLink::tts_connected() {
- tts_send("{\"jsonrpc\":\"2.0\",\"id\":300,\"method\":\"MB.registerComponent\",\"params\":{\"componentName\":\"TTS\"}}");
+ tts_send(
+ "{\"jsonrpc\":\"2.0\",\"id\":300,\"method\":\"MB.registerComponent\","
+ "\"params\":{\"componentName\":\"TTS\"}}");
}
void SmartDeviceLink::vehicle_connected() {
- vehicle_send("{\"jsonrpc\":\"2.0\",\"id\":700,\"method\":\"MB.registerComponent\",\"params\":{\"componentName\":\"VehicleInfo\"}}");
+ vehicle_send(
+ "{\"jsonrpc\":\"2.0\",\"id\":700,\"method\":\"MB.registerComponent\","
+ "\"params\":{\"componentName\":\"VehicleInfo\"}}");
}
void SmartDeviceLink::ui_connected() {
- ui_send("{\"jsonrpc\":\"2.0\",\"id\":400,\"method\":\"MB.registerComponent\",\"params\":{\"componentName\":\"UI\"}}");
+ ui_send(
+ "{\"jsonrpc\":\"2.0\",\"id\":400,\"method\":\"MB.registerComponent\","
+ "\"params\":{\"componentName\":\"UI\"}}");
}
void SmartDeviceLink::vr_connected() {
- vr_send("{\"jsonrpc\":\"2.0\",\"id\":500,\"method\":\"MB.registerComponent\",\"params\":{\"componentName\":\"VR\"}}");
+ vr_send(
+ "{\"jsonrpc\":\"2.0\",\"id\":500,\"method\":\"MB.registerComponent\","
+ "\"params\":{\"componentName\":\"VR\"}}");
}
void SmartDeviceLink::basic_send(QString message) {
- qDebug() << "Sending (basic):" << message;
- m_ws_basic.write(message.append('\n'));
+ qDebug() << "Sending (basic):" << message;
+ m_ws_basic.write(message.append('\n'));
}
void SmartDeviceLink::buttons_send(QString message) {
- qDebug() << "Sending (buttons):" << message;
- m_ws_buttons.write(message.append('\n'));
+ qDebug() << "Sending (buttons):" << message;
+ m_ws_buttons.write(message.append('\n'));
}
void SmartDeviceLink::tts_send(QString message) {
- qDebug() << "Sending (tts):" << message;
- m_ws_tts.write(message.append('\n'));
+ qDebug() << "Sending (tts):" << message;
+ m_ws_tts.write(message.append('\n'));
}
void SmartDeviceLink::vehicle_send(QString message) {
- qDebug() << "Sending (vehicle):" << message;
- m_ws_vehicle.write(message.append('\n'));
+ qDebug() << "Sending (vehicle):" << message;
+ m_ws_vehicle.write(message.append('\n'));
}
void SmartDeviceLink::ui_send(QString message) {
- qDebug() << "Sending (ui):" << message;
- m_ws_ui.write(message.append('\n'));
+ qDebug() << "Sending (ui):" << message;
+ m_ws_ui.write(message.append('\n'));
}
void SmartDeviceLink::vr_send(QString message) {
- qDebug() << "Sending (vr):" << message;
- m_ws_vr.write(message.append('\n'));
+ qDebug() << "Sending (vr):" << message;
+ m_ws_vr.write(message.append('\n'));
}
void SmartDeviceLink::basic_receive(QString message) {
- qDebug() << "Receiving(basic):" << message;
- QJsonObject root = QJsonDocument::fromJson(message.toLocal8Bit()).object();
- int id = root.value("id").toDouble();
- int result = root.value("result").toDouble();
- QString method = root.value("method").toString();
-
- if (id == 600) {
- char *reg, *unreg, *update;
-
- asprintf(&reg, "{\"jsonrpc\":\"2.0\",\"id\":%i,\"method\":\"MB.subscribeTo\",\"params\":{\"propertyName\":\"BasicCommunication.OnAppRegistered\"}}", result+1);
- basic_send(reg);
- free(reg);
-
- asprintf(&unreg, "{\"jsonrpc\":\"2.0\",\"id\":%i,\"method\":\"MB.subscribeTo\",\"params\":{\"propertyName\":\"BasicCommunication.OnAppUnregistered\"}}", result+2);
- basic_send(unreg);
- free(unreg);
-
- asprintf(&update, "{\"jsonrpc\":\"2.0\",\"id\":%i,\"method\":\"MB.subscribeTo\",\"params\":{\"propertyName\":\"BasicCommunication.OnDeviceListUpdated\"}} ", result+3);
- basic_send(update);
- free(update);
- }
- else if (method.compare("BasicCommunication.OnAppRegistered") == 0) {
- QJsonObject params = root.value("params").toObject();
- QJsonObject application = params.value("application").toObject();
- QString appName = application.value("appName").toString();
- int appId = application.value("appId").toDouble();
-
- char * update;
- asprintf(&update, "{\"jsonrpc\":\"2.0\",\"id\":3000,\"method\":\"BasicCommunication.ActivateApp\",\"params\":{\"appName\":\"%s\",\"appId\":%i}}", appName.toLocal8Bit().data(), appId);
- basic_send(update);
- free(update);
- emit newAppAvailable(appId, appName);
- }
- else if (method.compare("BasicCommunication.OnAppUnregistered") == 0) {
- m_media_apps.clear();
- }
+ qDebug() << "Receiving(basic):" << message;
+ QJsonObject root = QJsonDocument::fromJson(message.toLocal8Bit()).object();
+ int id = root.value("id").toDouble();
+ int result = root.value("result").toDouble();
+ QString method = root.value("method").toString();
+
+ if (id == 600) {
+ char* reg, *unreg, *update;
+
+ asprintf(&reg,
+ "{\"jsonrpc\":\"2.0\",\"id\":%i,\"method\":\"MB.subscribeTo\","
+ "\"params\":{\"propertyName\":\"BasicCommunication."
+ "OnAppRegistered\"}}",
+ result + 1);
+ basic_send(reg);
+ free(reg);
+
+ asprintf(&unreg,
+ "{\"jsonrpc\":\"2.0\",\"id\":%i,\"method\":\"MB.subscribeTo\","
+ "\"params\":{\"propertyName\":\"BasicCommunication."
+ "OnAppUnregistered\"}}",
+ result + 2);
+ basic_send(unreg);
+ free(unreg);
+
+ asprintf(&update,
+ "{\"jsonrpc\":\"2.0\",\"id\":%i,\"method\":\"MB.subscribeTo\","
+ "\"params\":{\"propertyName\":\"BasicCommunication."
+ "OnDeviceListUpdated\"}} ",
+ result + 3);
+ basic_send(update);
+ free(update);
+ } else if (method.compare("BasicCommunication.OnAppRegistered") == 0) {
+ QJsonObject params = root.value("params").toObject();
+ QJsonObject application = params.value("application").toObject();
+ QString appName = application.value("appName").toString();
+ int appId = application.value("appId").toDouble();
+
+ char* update;
+ asprintf(&update,
+ "{\"jsonrpc\":\"2.0\",\"id\":3000,\"method\":\"BasicCommunication."
+ "ActivateApp\",\"params\":{\"appName\":\"%s\",\"appId\":%i}}",
+ appName.toLocal8Bit().data(),
+ appId);
+ basic_send(update);
+ free(update);
+ emit newAppAvailable(appId, appName);
+ } else if (method.compare("BasicCommunication.OnAppUnregistered") == 0) {
+ m_media_apps.clear();
+ }
}
void SmartDeviceLink::buttons_receive(QString message) {
- qDebug() << "Receiving(buttons):" << message;
- QJsonObject root = QJsonDocument::fromJson(message.toLocal8Bit()).object();
- int id = root.value("id").toDouble();
- QString method = root.value("method").toString();
-
- if (method.compare("Buttons.GetCapabilities") == 0) {
- buttons_send("{\"jsonrpc\":\"2.0\",\"id\":19,\"result\":{\"capabilities\":[{\"name\":\"PRESET_0\",\"shortPressAvailable\":true,\"longPressAvailable\":true,\"upDownAvailable\":true},{\"name\":\"PRESET_1\",\"shortPressAvailable\":true,\"longPressAvailable\":true,\"upDownAvailable\":true},{\"name\":\"PRESET_2\",\"shortPressAvailable\":true,\"longPressAvailable\":true,\"upDownAvailable\":true},{\"name\":\"PRESET_3\",\"shortPressAvailable\":true,\"longPressAvailable\":true,\"upDownAvailable\":true},{\"name\":\"PRESET_4\",\"shortPressAvailable\":true,\"longPressAvailable\":true,\"upDownAvailable\":true},{\"name\":\"PRESET_5\",\"shortPressAvailable\":true,\"longPressAvailable\":true,\"upDownAvailable\":true},{\"name\":\"PRESET_6\",\"shortPressAvailable\":true,\"longPressAvailable\":true,\"upDownAvailable\":true},{\"name\":\"PRESET_7\",\"shortPressAvailable\":true,\"longPressAvailable\":true,\"upDownAvailable\":true},{\"name\":\"PRESET_8\",\"shortPressAvailable\":true,\"longPressAvailable\":true,\"upDownAvailable\":true},{\"name\":\"PRESET_9\",\"shortPressAvailable\":true,\"longPressAvailable\":true,\"upDownAvailable\":true},{\"name\":\"OK\",\"shortPressAvailable\":true,\"longPressAvailable\":true,\"upDownAvailable\":true},{\"name\":\"SEEKLEFT\",\"shortPressAvailable\":true,\"longPressAvailable\":true,\"upDownAvailable\":true},{\"name\":\"SEEKRIGHT\",\"shortPressAvailable\":true,\"longPressAvailable\":true,\"upDownAvailable\":true},{\"name\":\"TUNEUP\",\"shortPressAvailable\":true,\"longPressAvailable\":true,\"upDownAvailable\":true},{\"name\":\"TUNEDOWN\",\"shortPressAvailable\":true,\"longPressAvailable\":true,\"upDownAvailable\":true}],\"presetBankCapabilities\":{\"onScreenPresetsAvailable\":true},\"method\":\"Buttons.GetCapabilitiesResponse\",\"resultCode\":\"SUCCESS\"}}");
- }
+ qDebug() << "Receiving(buttons):" << message;
+ QJsonObject root = QJsonDocument::fromJson(message.toLocal8Bit()).object();
+ int id = root.value("id").toDouble();
+ QString method = root.value("method").toString();
+
+ if (method.compare("Buttons.GetCapabilities") == 0) {
+ buttons_send(
+ "{\"jsonrpc\":\"2.0\",\"id\":19,\"result\":{\"capabilities\":[{"
+ "\"name\":\"PRESET_0\",\"shortPressAvailable\":true,"
+ "\"longPressAvailable\":true,\"upDownAvailable\":true},{\"name\":"
+ "\"PRESET_1\",\"shortPressAvailable\":true,\"longPressAvailable\":true,"
+ "\"upDownAvailable\":true},{\"name\":\"PRESET_2\","
+ "\"shortPressAvailable\":true,\"longPressAvailable\":true,"
+ "\"upDownAvailable\":true},{\"name\":\"PRESET_3\","
+ "\"shortPressAvailable\":true,\"longPressAvailable\":true,"
+ "\"upDownAvailable\":true},{\"name\":\"PRESET_4\","
+ "\"shortPressAvailable\":true,\"longPressAvailable\":true,"
+ "\"upDownAvailable\":true},{\"name\":\"PRESET_5\","
+ "\"shortPressAvailable\":true,\"longPressAvailable\":true,"
+ "\"upDownAvailable\":true},{\"name\":\"PRESET_6\","
+ "\"shortPressAvailable\":true,\"longPressAvailable\":true,"
+ "\"upDownAvailable\":true},{\"name\":\"PRESET_7\","
+ "\"shortPressAvailable\":true,\"longPressAvailable\":true,"
+ "\"upDownAvailable\":true},{\"name\":\"PRESET_8\","
+ "\"shortPressAvailable\":true,\"longPressAvailable\":true,"
+ "\"upDownAvailable\":true},{\"name\":\"PRESET_9\","
+ "\"shortPressAvailable\":true,\"longPressAvailable\":true,"
+ "\"upDownAvailable\":true},{\"name\":\"OK\",\"shortPressAvailable\":"
+ "true,\"longPressAvailable\":true,\"upDownAvailable\":true},{\"name\":"
+ "\"SEEKLEFT\",\"shortPressAvailable\":true,\"longPressAvailable\":true,"
+ "\"upDownAvailable\":true},{\"name\":\"SEEKRIGHT\","
+ "\"shortPressAvailable\":true,\"longPressAvailable\":true,"
+ "\"upDownAvailable\":true},{\"name\":\"TUNEUP\","
+ "\"shortPressAvailable\":true,\"longPressAvailable\":true,"
+ "\"upDownAvailable\":true},{\"name\":\"TUNEDOWN\","
+ "\"shortPressAvailable\":true,\"longPressAvailable\":true,"
+ "\"upDownAvailable\":true}],\"presetBankCapabilities\":{"
+ "\"onScreenPresetsAvailable\":true},\"method\":\"Buttons."
+ "GetCapabilitiesResponse\",\"resultCode\":\"SUCCESS\"}}");
+ }
}
void SmartDeviceLink::tts_receive(QString message) {
- qDebug() << "Receiving(tts):" << message;
- QJsonObject root = QJsonDocument::fromJson(message.toLocal8Bit()).object();
- int id = root.value("id").toDouble();
- QString method = root.value("method").toString();
-
- if (method.compare("TTS.GetCapabilities") == 0) {
- tts_send("{\"jsonrpc\":\"2.0\",\"id\":18,\"result\":{\"capabilities\":[\"TEXT\"],\"resultCode\":\"SUCCESS\",\"method\":\"TTS.GetCapabilitiesResponse\"}}");
- }
- else if (method.compare("TTS.GetLanguage") == 0) {
- tts_send("{\"jsonrpc\":\"2.0\",\"id\":26,\"result\":{\"resultCode\":\"SUCCESS\",\"method\":\"TTS.GetLanguageResponse\",\"language\":\"EN-US\"}}");
- }
- else if (method.compare("TTS.GetSupportedLanguages") == 0) {
- tts_send("{\"jsonrpc\":\"2.0\",\"id\":22,\"result\":{\"resultCode\":\"SUCCESS\",\"method\":\"TTS.GetSupportedLanguagesResponse\",\"languages\":[\"EN-US\",\"ES-MX\",\"FR-CA\",\"DE-EU\",\"ES-EU\",\"EN-EU\",\"RU-RU\",\"TR-TR\",\"PL-EU\",\"FR-EU\",\"IT-EU\",\"SV-EU\",\"PT-EU\",\"NL-EU\",\"EN-AU\",\"ZH-CN\",\"ZH-TW\",\"JA-JP\",\"AR\",\"KO-KR\"]}}");
- }
-
+ qDebug() << "Receiving(tts):" << message;
+ QJsonObject root = QJsonDocument::fromJson(message.toLocal8Bit()).object();
+ int id = root.value("id").toDouble();
+ QString method = root.value("method").toString();
+
+ if (method.compare("TTS.GetCapabilities") == 0) {
+ tts_send(
+ "{\"jsonrpc\":\"2.0\",\"id\":18,\"result\":{\"capabilities\":[\"TEXT\"]"
+ ",\"resultCode\":\"SUCCESS\",\"method\":\"TTS."
+ "GetCapabilitiesResponse\"}}");
+ } else if (method.compare("TTS.GetLanguage") == 0) {
+ tts_send(
+ "{\"jsonrpc\":\"2.0\",\"id\":26,\"result\":{\"resultCode\":\"SUCCESS\","
+ "\"method\":\"TTS.GetLanguageResponse\",\"language\":\"EN-US\"}}");
+ } else if (method.compare("TTS.GetSupportedLanguages") == 0) {
+ tts_send(
+ "{\"jsonrpc\":\"2.0\",\"id\":22,\"result\":{\"resultCode\":\"SUCCESS\","
+ "\"method\":\"TTS.GetSupportedLanguagesResponse\",\"languages\":[\"EN-"
+ "US\",\"ES-MX\",\"FR-CA\",\"DE-EU\",\"ES-EU\",\"EN-EU\",\"RU-RU\",\"TR-"
+ "TR\",\"PL-EU\",\"FR-EU\",\"IT-EU\",\"SV-EU\",\"PT-EU\",\"NL-EU\",\"EN-"
+ "AU\",\"ZH-CN\",\"ZH-TW\",\"JA-JP\",\"AR\",\"KO-KR\"]}}");
+ }
}
void SmartDeviceLink::vehicle_receive(QString message) {
- qDebug() << "Receiving(vehicle):" << message;
- QJsonObject root = QJsonDocument::fromJson(message.toLocal8Bit()).object();
- int id = root.value("id").toDouble();
- QString method = root.value("method").toString();
-
- if (method.compare("VehicleInfo.GetVehicleType") == 0) {
- vehicle_send("{\"jsonrpc\":\"2.0\",\"id\":20,\"result\":{\"resultCode\":\"SUCCESS\",\"method\":\"VehicleInfo.GetVehicleTypeResponse\",\"vehicleType\":{\"make\":\"Ford\",\"model\":\"Fiesta\",\"modelYear\":\"2013\",\"trim\":\"SE\"}}}");
- }
+ qDebug() << "Receiving(vehicle):" << message;
+ QJsonObject root = QJsonDocument::fromJson(message.toLocal8Bit()).object();
+ int id = root.value("id").toDouble();
+ QString method = root.value("method").toString();
+
+ if (method.compare("VehicleInfo.GetVehicleType") == 0) {
+ vehicle_send(
+ "{\"jsonrpc\":\"2.0\",\"id\":20,\"result\":{\"resultCode\":\"SUCCESS\","
+ "\"method\":\"VehicleInfo.GetVehicleTypeResponse\",\"vehicleType\":{"
+ "\"make\":\"Ford\",\"model\":\"Fiesta\",\"modelYear\":\"2013\","
+ "\"trim\":\"SE\"}}}");
+ }
}
void SmartDeviceLink::ui_receive(QString message) {
- qDebug() << "Receiving(ui):" << message;
- QJsonObject root = QJsonDocument::fromJson(message.toLocal8Bit()).object();
- int id = root.value("id").toDouble();
- int result = root.value("result").toDouble();
- QString method = root.value("method").toString();
-
- if (id == 400) {
- char *onchoise;
- asprintf(&onchoise, "{\"jsonrpc\":\"2.0\",\"id\":%i,\"method\":\"MB.subscribeTo\",\"params\":{\"propertyName\":\"VR.OnChoise\"}}", result + 1);
- ui_send(onchoise);
- free(onchoise);
-
- ui_send("{\"jsonrpc\":\"2.0\",\"method\":\"UI.OnReady\"}");
- }
- else if (method.compare("UI.GetCapabilities") == 0) {
- ui_send("{\"jsonrpc\":\"2.0\",\"id\":16,\"result\":{\"displayCapabilities\":{\"displayType\":\"GEN2_8_DMA\",\"textFields\":[{\"name\":\"mainField1\",\"characterSet\":\"TYPE2SET\",\"width\":1,\"rows\":1},{\"name\":\"mainField2\",\"characterSet\":\"TYPE2SET\",\"width\":1,\"rows\":1},{\"name\":\"statusBar\",\"characterSet\":\"TYPE2SET\",\"width\":1,\"rows\":1},{\"name\":\"mediaClock\",\"characterSet\":\"TYPE2SET\",\"width\":1,\"rows\":1},{\"name\":\"mediaTrack\",\"characterSet\":\"TYPE2SET\",\"width\":1,\"rows\":1},{\"name\":\"alertText1\",\"characterSet\":\"TYPE2SET\",\"width\":1,\"rows\":1},{\"name\":\"alertText2\",\"characterSet\":\"TYPE2SET\",\"width\":1,\"rows\":1}],\"mediaClockFormats\":[\"CLOCK1\",\"CLOCK2\",\"CLOCKTEXT1\",\"CLOCKTEXT2\",\"CLOCKTEXT3\"]},\"hmiZoneCapabilities\":[\"FRONT\",\"BACK\"],\"softButtonCapabilities\":[{\"shortPressAvailable\":true,\"longPressAvailable\":true,\"upDownAvailable\":true,\"imageSupported\":true}],\"method\":\"UI.GetCapabilitiesResponse\",\"resultCode\":\"SUCCESS\"}}");
- }
- else if (method.compare("UI.GetSupportedLanguages") == 0) {
- ui_send("{\"jsonrpc\":\"2.0\",\"id\":21,\"result\":{\"resultCode\":\"SUCCESS\",\"method\":\"UI.GetSupportedLanguagesResponse\",\"languages\":[\"EN-US\",\"ES-MX\",\"FR-CA\",\"DE-EU\",\"ES-EU\",\"EN-EU\",\"RU-RU\",\"TR-TR\",\"PL-EU\",\"FR-EU\",\"IT-EU\",\"SV-EU\",\"PT-EU\",\"NL-EU\",\"EN-AU\",\"ZH-CN\",\"ZH-TW\",\"JA-JP\",\"AR\",\"KO-KR\"]}}");
- }
- else if (method.compare("UI.GetLanguage") == 0) {
- ui_send("{\"jsonrpc\":\"2.0\",\"id\":24,\"result\":{\"resultCode\":\"SUCCESS\",\"method\":\"UI.GetLanguageResponse\",\"hmiDisplayLanguage\":\"EN-US\"}}");
- }
- else if (method.compare("UI.Show") == 0) {
- QJsonObject params = root.value("params").toObject();
- setShow1(params.value("mainField1").toString());
- setShow2(params.value("mainField2").toString());
- char* response;
- asprintf(&response, "{\"jsonrpc\":\"2.0\",\"id\":%i,\"result\":{\"resultCode\":\"SUCCESS\",\"method\":\"UI.ShowResponse\"}}", id);
- ui_send(response);
- free(response);
- }
- else if (method.compare("UI.Alert") == 0) {
- QJsonObject params = root.value("params").toObject();
- QString message(params.value("AlertText1").toString());
- message.append("\n").append(params.value("AlertText2").toString());
- char * response;
- asprintf(&response, "{\"jsonrpc\":\"2.0\",\"id\":%i,\"result\":{\"resultCode\":\"SUCCESS\",\"method\":\"UI.AlertResponse\"}}", id);
- ui_send(response);
- free(response);
- emit alert(message);
- }
-
+ qDebug() << "Receiving(ui):" << message;
+ QJsonObject root = QJsonDocument::fromJson(message.toLocal8Bit()).object();
+ int id = root.value("id").toDouble();
+ int result = root.value("result").toDouble();
+ QString method = root.value("method").toString();
+
+ if (id == 400) {
+ char* onchoise;
+ asprintf(&onchoise,
+ "{\"jsonrpc\":\"2.0\",\"id\":%i,\"method\":\"MB.subscribeTo\","
+ "\"params\":{\"propertyName\":\"VR.OnChoise\"}}",
+ result + 1);
+ ui_send(onchoise);
+ free(onchoise);
+
+ ui_send("{\"jsonrpc\":\"2.0\",\"method\":\"UI.OnReady\"}");
+ } else if (method.compare("UI.GetCapabilities") == 0) {
+ ui_send(
+ "{\"jsonrpc\":\"2.0\",\"id\":16,\"result\":{\"displayCapabilities\":{"
+ "\"displayType\":\"GEN2_8_DMA\",\"textFields\":[{\"name\":"
+ "\"mainField1\",\"characterSet\":\"TYPE2SET\",\"width\":1,\"rows\":1},{"
+ "\"name\":\"mainField2\",\"characterSet\":\"TYPE2SET\",\"width\":1,"
+ "\"rows\":1},{\"name\":\"statusBar\",\"characterSet\":\"TYPE2SET\","
+ "\"width\":1,\"rows\":1},{\"name\":\"mediaClock\",\"characterSet\":"
+ "\"TYPE2SET\",\"width\":1,\"rows\":1},{\"name\":\"mediaTrack\","
+ "\"characterSet\":\"TYPE2SET\",\"width\":1,\"rows\":1},{\"name\":"
+ "\"alertText1\",\"characterSet\":\"TYPE2SET\",\"width\":1,\"rows\":1},{"
+ "\"name\":\"alertText2\",\"characterSet\":\"TYPE2SET\",\"width\":1,"
+ "\"rows\":1}],\"mediaClockFormats\":[\"CLOCK1\",\"CLOCK2\","
+ "\"CLOCKTEXT1\",\"CLOCKTEXT2\",\"CLOCKTEXT3\"]},"
+ "\"hmiZoneCapabilities\":[\"FRONT\",\"BACK\"],"
+ "\"softButtonCapabilities\":[{\"shortPressAvailable\":true,"
+ "\"longPressAvailable\":true,\"upDownAvailable\":true,"
+ "\"imageSupported\":true}],\"method\":\"UI.GetCapabilitiesResponse\","
+ "\"resultCode\":\"SUCCESS\"}}");
+ } else if (method.compare("UI.GetSupportedLanguages") == 0) {
+ ui_send(
+ "{\"jsonrpc\":\"2.0\",\"id\":21,\"result\":{\"resultCode\":\"SUCCESS\","
+ "\"method\":\"UI.GetSupportedLanguagesResponse\",\"languages\":[\"EN-"
+ "US\",\"ES-MX\",\"FR-CA\",\"DE-EU\",\"ES-EU\",\"EN-EU\",\"RU-RU\",\"TR-"
+ "TR\",\"PL-EU\",\"FR-EU\",\"IT-EU\",\"SV-EU\",\"PT-EU\",\"NL-EU\",\"EN-"
+ "AU\",\"ZH-CN\",\"ZH-TW\",\"JA-JP\",\"AR\",\"KO-KR\"]}}");
+ } else if (method.compare("UI.GetLanguage") == 0) {
+ ui_send(
+ "{\"jsonrpc\":\"2.0\",\"id\":24,\"result\":{\"resultCode\":\"SUCCESS\","
+ "\"method\":\"UI.GetLanguageResponse\",\"hmiDisplayLanguage\":\"EN-"
+ "US\"}}");
+ } else if (method.compare("UI.Show") == 0) {
+ QJsonObject params = root.value("params").toObject();
+ setShow1(params.value("mainField1").toString());
+ setShow2(params.value("mainField2").toString());
+ char* response;
+ asprintf(&response,
+ "{\"jsonrpc\":\"2.0\",\"id\":%i,\"result\":{\"resultCode\":"
+ "\"SUCCESS\",\"method\":\"UI.ShowResponse\"}}",
+ id);
+ ui_send(response);
+ free(response);
+ } else if (method.compare("UI.Alert") == 0) {
+ QJsonObject params = root.value("params").toObject();
+ QString message(params.value("AlertText1").toString());
+ message.append("\n").append(params.value("AlertText2").toString());
+ char* response;
+ asprintf(&response,
+ "{\"jsonrpc\":\"2.0\",\"id\":%i,\"result\":{\"resultCode\":"
+ "\"SUCCESS\",\"method\":\"UI.AlertResponse\"}}",
+ id);
+ ui_send(response);
+ free(response);
+ emit alert(message);
+ }
}
void SmartDeviceLink::vr_receive(QString message) {
- qDebug() << "Receiving(vr):" << message;
- QJsonObject root = QJsonDocument::fromJson(message.toLocal8Bit()).object();
- int id = root.value("id").toDouble();
- QString method = root.value("method").toString();
-
- if (method.compare("VR.GetCapabilities") == 0) {
- vr_send("{\"jsonrpc\":\"2.0\",\"id\":17,\"result\":{\"capabilities\":[\"TEXT\"],\"method\":\"VR.GetCapabilitiesResponse\",\"resultCode\":\"SUCCESS\"}}");
- }
- else if (method.compare("VR.GetSupportedLanguages") == 0) {
- vr_send("{\"jsonrpc\":\"2.0\",\"id\":23,\"result\":{\"resultCode\":\"SUCCESS\",\"method\":\"VR.GetSupportedLanguagesResponse\",\"languages\":[\"EN-US\",\"ES-MX\",\"FR-CA\",\"DE-EU\",\"ES-EU\",\"EN-EU\",\"RU-RU\",\"TR-TR\",\"PL-EU\",\"FR-EU\",\"IT-EU\",\"SV-EU\",\"PT-EU\",\"NL-EU\",\"EN-AU\",\"ZH-CN\",\"ZH-TW\",\"JA-JP\",\"AR\",\"KO-KR\"]}}");
- }
- else if (method.compare("VR.GetLanguage") == 0) {
- vr_send("{\"jsonrpc\":\"2.0\",\"id\":25,\"result\":{\"resultCode\":\"SUCCESS\",\"method\":\"VR.GetLanguageResponse\",\"language\":\"EN-US\"}}");
- }
+ qDebug() << "Receiving(vr):" << message;
+ QJsonObject root = QJsonDocument::fromJson(message.toLocal8Bit()).object();
+ int id = root.value("id").toDouble();
+ QString method = root.value("method").toString();
+
+ if (method.compare("VR.GetCapabilities") == 0) {
+ vr_send(
+ "{\"jsonrpc\":\"2.0\",\"id\":17,\"result\":{\"capabilities\":[\"TEXT\"]"
+ ",\"method\":\"VR.GetCapabilitiesResponse\",\"resultCode\":\"SUCCESS\"}"
+ "}");
+ } else if (method.compare("VR.GetSupportedLanguages") == 0) {
+ vr_send(
+ "{\"jsonrpc\":\"2.0\",\"id\":23,\"result\":{\"resultCode\":\"SUCCESS\","
+ "\"method\":\"VR.GetSupportedLanguagesResponse\",\"languages\":[\"EN-"
+ "US\",\"ES-MX\",\"FR-CA\",\"DE-EU\",\"ES-EU\",\"EN-EU\",\"RU-RU\",\"TR-"
+ "TR\",\"PL-EU\",\"FR-EU\",\"IT-EU\",\"SV-EU\",\"PT-EU\",\"NL-EU\",\"EN-"
+ "AU\",\"ZH-CN\",\"ZH-TW\",\"JA-JP\",\"AR\",\"KO-KR\"]}}");
+ } else if (method.compare("VR.GetLanguage") == 0) {
+ vr_send(
+ "{\"jsonrpc\":\"2.0\",\"id\":25,\"result\":{\"resultCode\":\"SUCCESS\","
+ "\"method\":\"VR.GetLanguageResponse\",\"language\":\"EN-US\"}}");
+ }
}
void SmartDeviceLink::registerApp(int appId, QString appName) {
- qDebug() << "New app registered:" << appName;
- m_media_apps.append(appId, appName);
+ qDebug() << "New app registered:" << appName;
+ m_media_apps.append(appId, appName);
}
void SmartDeviceLink::setShow1(QString show) {
- m_show1 = show;
- emit show1Changed(show);
+ m_show1 = show;
+ emit show1Changed(show);
}
void SmartDeviceLink::setShow2(QString show) {
- m_show2 = show;
- emit show2Changed(show);
+ m_show2 = show;
+ emit show2Changed(show);
}
void SmartDeviceLink::disconnected() {
- qDebug() << "Websocket disconnected";
+ qDebug() << "Websocket disconnected";
}
diff --git a/src/components/qt_hmi/References/Work/fordsdlcore/smartdevicelink.h b/src/components/qt_hmi/References/Work/fordsdlcore/smartdevicelink.h
index f2e7f1b2b4..18ad605f40 100644
--- a/src/components/qt_hmi/References/Work/fordsdlcore/smartdevicelink.h
+++ b/src/components/qt_hmi/References/Work/fordsdlcore/smartdevicelink.h
@@ -6,70 +6,75 @@
#include "QtWebsocket/QWsSocket.h"
#include "sdlappslistmodel.h"
-class SmartDeviceLink : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QString show1 READ getShow1 NOTIFY show1Changed)
- Q_PROPERTY(QString show2 READ getShow2 NOTIFY show2Changed)
+class SmartDeviceLink : public QObject {
+ Q_OBJECT
+ Q_PROPERTY(QString show1 READ getShow1 NOTIFY show1Changed)
+ Q_PROPERTY(QString show2 READ getShow2 NOTIFY show2Changed)
-public:
- SmartDeviceLink(QQuickItem *parent = 0);
- ~SmartDeviceLink();
+ public:
+ SmartDeviceLink(QQuickItem* parent = 0);
+ ~SmartDeviceLink();
- static SmartDeviceLink& getInstance() {
- static SmartDeviceLink instance;
- return instance;
- }
+ static SmartDeviceLink& getInstance() {
+ static SmartDeviceLink instance;
+ return instance;
+ }
- SdlAppsListModel* getMediaApps() { return &m_media_apps; }
- QString getShow1() { return m_show1; }
- QString getShow2() { return m_show2; }
+ SdlAppsListModel* getMediaApps() {
+ return &m_media_apps;
+ }
+ QString getShow1() {
+ return m_show1;
+ }
+ QString getShow2() {
+ return m_show2;
+ }
-private:
- QWsSocket m_ws_basic;
- QWsSocket m_ws_tts;
- QWsSocket m_ws_buttons;
- QWsSocket m_ws_vehicle;
- QWsSocket m_ws_ui;
- QWsSocket m_ws_vr;
+ private:
+ QWsSocket m_ws_basic;
+ QWsSocket m_ws_tts;
+ QWsSocket m_ws_buttons;
+ QWsSocket m_ws_vehicle;
+ QWsSocket m_ws_ui;
+ QWsSocket m_ws_vr;
- SdlAppsListModel m_media_apps;
+ SdlAppsListModel m_media_apps;
- QString m_show1;
- QString m_show2;
+ QString m_show1;
+ QString m_show2;
- void basic_send(QString message);
- void tts_send(QString message);
- void buttons_send(QString message);
- void vehicle_send(QString message);
- void ui_send(QString message);
- void vr_send(QString message);
- void setShow1(QString);
- void setShow2(QString);
+ void basic_send(QString message);
+ void tts_send(QString message);
+ void buttons_send(QString message);
+ void vehicle_send(QString message);
+ void ui_send(QString message);
+ void vr_send(QString message);
+ void setShow1(QString);
+ void setShow2(QString);
-public slots:
- void basic_connected();
- void tts_connected();
- void buttons_connected();
- void vehicle_connected();
- void ui_connected();
- void vr_connected();
+ public slots:
+ void basic_connected();
+ void tts_connected();
+ void buttons_connected();
+ void vehicle_connected();
+ void ui_connected();
+ void vr_connected();
- void basic_receive(QString);
- void tts_receive(QString);
- void buttons_receive(QString);
- void vehicle_receive(QString);
- void ui_receive(QString);
- void vr_receive(QString);
- void registerApp(int, QString);
+ void basic_receive(QString);
+ void tts_receive(QString);
+ void buttons_receive(QString);
+ void vehicle_receive(QString);
+ void ui_receive(QString);
+ void vr_receive(QString);
+ void registerApp(int, QString);
- void disconnected();
+ void disconnected();
signals:
- void show1Changed(QString);
- void show2Changed(QString);
- void newAppAvailable(int, QString);
- void alert(QString message);
+ void show1Changed(QString);
+ void show2Changed(QString);
+ void newAppAvailable(int, QString);
+ void alert(QString message);
};
-#endif // SMARTDEVICELINK_H
+#endif // SMARTDEVICELINK_H
diff --git a/src/components/qt_hmi/qml_plugins/dbus_adapter/dbus_controller.cc b/src/components/qt_hmi/qml_plugins/dbus_adapter/dbus_controller.cc
index d026f4bbb5..60f07783a9 100644
--- a/src/components/qt_hmi/qml_plugins/dbus_adapter/dbus_controller.cc
+++ b/src/components/qt_hmi/qml_plugins/dbus_adapter/dbus_controller.cc
@@ -36,11 +36,11 @@
#include "interfaces/QT_HMI_API.h"
#include <QtDBus/QDBusConnection>
-DBusController::DBusController(QObject *parent)
- : QObject(parent),
- message(NULL) {}
+DBusController::DBusController(QObject* parent)
+ : QObject(parent), message(NULL) {}
-void DBusController::addMessage(const QDBusMessage& message, fillRoutine fill,
+void DBusController::addMessage(const QDBusMessage& message,
+ fillRoutine fill,
int async_uid) {
delayedReply reply;
reply.message = message;
@@ -54,11 +54,11 @@ void DBusController::sendReply(QVariant asyncObject, QVariant data) {
if (it != replies_.end()) {
QDBusMessage msg = it->second.message.createReply();
if (!it->second.fill(msg, data.toMap())) {
- QDBusConnection::sessionBus()
- .send(it->second.message.createErrorReply(QDBusError::InternalError,
- QString::number(hmi_apis::Common_Result::INVALID_DATA)));
+ QDBusConnection::sessionBus().send(it->second.message.createErrorReply(
+ QDBusError::InternalError,
+ QString::number(hmi_apis::Common_Result::INVALID_DATA)));
} else {
- QDBusConnection::sessionBus().send(msg);
+ QDBusConnection::sessionBus().send(msg);
}
replies_.erase(it);
}
@@ -69,15 +69,17 @@ void DBusController::sendReply(QVariant data) {
return;
QDBusMessage msg = message->createReply();
if (!fill(msg, data.toMap())) {
- QDBusConnection::sessionBus()
- .send(message->createErrorReply(QDBusError::InternalError,
- QString::number(hmi_apis::Common_Result::INVALID_DATA)));
+ QDBusConnection::sessionBus().send(message->createErrorReply(
+ QDBusError::InternalError,
+ QString::number(hmi_apis::Common_Result::INVALID_DATA)));
} else {
QDBusConnection::sessionBus().send(msg);
}
}
-void DBusController::sendError(QVariant asyncObject, QVariant code, QVariant message) {
+void DBusController::sendError(QVariant asyncObject,
+ QVariant code,
+ QVariant message) {
int uid = asyncObject.toMap()["__async_uid"].toInt();
std::map<int, delayedReply>::iterator it = replies_.find(uid);
if (it != replies_.end()) {
diff --git a/src/components/qt_hmi/qml_plugins/dbus_adapter/dbus_controller.h b/src/components/qt_hmi/qml_plugins/dbus_adapter/dbus_controller.h
index ecda598670..937bab5f90 100644
--- a/src/components/qt_hmi/qml_plugins/dbus_adapter/dbus_controller.h
+++ b/src/components/qt_hmi/qml_plugins/dbus_adapter/dbus_controller.h
@@ -41,7 +41,7 @@
typedef bool (*fillRoutine)(QDBusMessage&, const QVariantMap&);
-class DBusController: public QObject {
+class DBusController : public QObject {
struct delayedReply {
QDBusMessage message;
fillRoutine fill;
@@ -49,12 +49,14 @@ class DBusController: public QObject {
Q_OBJECT
public:
- explicit DBusController(QObject *parent = 0);
+ explicit DBusController(QObject* parent = 0);
void addMessage(const QDBusMessage& message, fillRoutine fill, int async_uid);
Q_INVOKABLE void sendReply(QVariant asyncObject, QVariant data);
Q_INVOKABLE void sendReply(QVariant data);
Q_INVOKABLE void sendError(QVariant asyncObject, QVariant code);
- Q_INVOKABLE void sendError(QVariant asyncObject, QVariant code, QVariant message);
+ Q_INVOKABLE void sendError(QVariant asyncObject,
+ QVariant code,
+ QVariant message);
const QDBusMessage* message;
fillRoutine fill;
diff --git a/src/components/qt_hmi/qml_plugins/dbus_adapter/dbus_plugin.cc b/src/components/qt_hmi/qml_plugins/dbus_adapter/dbus_plugin.cc
index 0f41a28e73..5cc4dadb1e 100644
--- a/src/components/qt_hmi/qml_plugins/dbus_adapter/dbus_plugin.cc
+++ b/src/components/qt_hmi/qml_plugins/dbus_adapter/dbus_plugin.cc
@@ -48,18 +48,18 @@
#include <QtDBus/QDBusConnection>
#if QT_4
-# include <QtDeclarative/QDeclarativeContext>
-# include <QtDeclarative/QDeclarativeListReference>
-# include <QtDeclarative/QDeclarativeEngine>
+#include <QtDeclarative/QDeclarativeContext>
+#include <QtDeclarative/QDeclarativeListReference>
+#include <QtDeclarative/QDeclarativeEngine>
#elif QT_5
-# include <QtQml/QQmlContext>
-# include <QtQml/QQmlListReference>
-# include <QtQml/QQmlEngine>
+#include <QtQml/QQmlContext>
+#include <QtQml/QQmlListReference>
+#include <QtQml/QQmlEngine>
#endif // QT_VERSION
-log4cxx::LoggerPtr logger_ = log4cxx::LoggerPtr(
- log4cxx::Logger::getLogger("DBusPlugin"));
+log4cxx::LoggerPtr logger_ =
+ log4cxx::LoggerPtr(log4cxx::Logger::getLogger("DBusPlugin"));
-void DbusPlugin::registerTypes(const char *uri) {
+void DbusPlugin::registerTypes(const char* uri) {
log4cxx::PropertyConfigurator::configure("log4cxx.properties");
// @uri sdl.core.api
@@ -87,9 +87,9 @@ void DbusPlugin::registerTypes(const char *uri) {
HmiProxy::api_adaptors_.SetDBusController(dbusController_);
}
-void DbusPlugin::initializeEngine(Engine *engine, const char *uri) {
- engine->rootContext()->setContextProperty("DBus", dbusController_);
- engine->rootContext()->setContextProperty("RequestToSDL", requestToSDL_);
+void DbusPlugin::initializeEngine(Engine* engine, const char* uri) {
+ engine->rootContext()->setContextProperty("DBus", dbusController_);
+ engine->rootContext()->setContextProperty("RequestToSDL", requestToSDL_);
}
#if QT_4
diff --git a/src/components/qt_hmi/qml_plugins/dbus_adapter/dbus_plugin.h b/src/components/qt_hmi/qml_plugins/dbus_adapter/dbus_plugin.h
index ef2a925956..2b5bba6235 100644
--- a/src/components/qt_hmi/qml_plugins/dbus_adapter/dbus_plugin.h
+++ b/src/components/qt_hmi/qml_plugins/dbus_adapter/dbus_plugin.h
@@ -38,11 +38,11 @@
#include "qt_version.h"
#if QT_4
-# include <QtDeclarative/QDeclarativeExtensionPlugin>
+#include <QtDeclarative/QDeclarativeExtensionPlugin>
typedef QDeclarativeExtensionPlugin ExtensionPlugin;
typedef QDeclarativeEngine Engine;
#elif QT_5
-# include <QtQml/QQmlExtensionPlugin>
+#include <QtQml/QQmlExtensionPlugin>
typedef QQmlExtensionPlugin ExtensionPlugin;
typedef QQmlEngine Engine;
#endif // QT_VERSION
@@ -58,13 +58,12 @@ class DbusPlugin : public ExtensionPlugin, public QDBusContext {
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
#endif // QT_5
- DBusController *dbusController_;
- RequestToSDL *requestToSDL_;
+ DBusController* dbusController_;
+ RequestToSDL* requestToSDL_;
public:
- void registerTypes(const char *uri);
- void initializeEngine(Engine *engine, const char *uri);
+ void registerTypes(const char* uri);
+ void initializeEngine(Engine* engine, const char* uri);
};
#endif // SRC_COMPONENTS_QT_HMI_QML_PLUGINS_DBUS_ADAPTER_DBUS_PLUGIN_H_
-
diff --git a/src/components/qt_hmi/qml_plugins/dbus_adapter/hmi_proxy.cc b/src/components/qt_hmi/qml_plugins/dbus_adapter/hmi_proxy.cc
index 8b6cfd57d4..e196e5c5de 100644
--- a/src/components/qt_hmi/qml_plugins/dbus_adapter/hmi_proxy.cc
+++ b/src/components/qt_hmi/qml_plugins/dbus_adapter/hmi_proxy.cc
@@ -37,8 +37,7 @@
ApiAdaptors HmiProxy::api_adaptors_;
-HmiProxy::HmiProxy(Item *parent)
- : Item(parent) {}
+HmiProxy::HmiProxy(Item* parent) : Item(parent) {}
void HmiProxy::componentComplete() {
Item::componentComplete();
diff --git a/src/components/qt_hmi/qml_plugins/dbus_adapter/hmi_proxy.h b/src/components/qt_hmi/qml_plugins/dbus_adapter/hmi_proxy.h
index 886d523157..d7277d017b 100644
--- a/src/components/qt_hmi/qml_plugins/dbus_adapter/hmi_proxy.h
+++ b/src/components/qt_hmi/qml_plugins/dbus_adapter/hmi_proxy.h
@@ -39,10 +39,10 @@
#include "qml_dbus.h"
#if QT_4
-# include <QtDeclarative/QDeclarativeItem>
+#include <QtDeclarative/QDeclarativeItem>
typedef QDeclarativeItem Item;
#elif QT_5
-# include <QtQuick/QQuickItem>
+#include <QtQuick/QQuickItem>
typedef QQuickItem Item;
#endif // QT_VERSION
@@ -51,7 +51,7 @@ class HmiProxy : public Item {
Q_DISABLE_COPY(HmiProxy)
public:
- explicit HmiProxy(Item *parent = 0);
+ explicit HmiProxy(Item* parent = 0);
static ApiAdaptors api_adaptors_;
protected:
@@ -61,4 +61,3 @@ class HmiProxy : public Item {
QML_DECLARE_TYPE(HmiProxy)
#endif // SRC_COMPONENTS_QT_HMI_QML_PLUGINS_DBUS_ADAPTER_HMI_PROXY_H_
-
diff --git a/src/components/qt_hmi/qml_plugins/dbus_adapter/metatype.h b/src/components/qt_hmi/qml_plugins/dbus_adapter/metatype.h
index 5224da7f55..b127cea1a8 100644
--- a/src/components/qt_hmi/qml_plugins/dbus_adapter/metatype.h
+++ b/src/components/qt_hmi/qml_plugins/dbus_adapter/metatype.h
@@ -35,25 +35,25 @@
#include <QMetaType>
-template<typename T>
+template <typename T>
QMetaType::Type metatype();
-template<>
+template <>
inline QMetaType::Type metatype<int>() {
return QMetaType::Int;
}
-template<>
+template <>
inline QMetaType::Type metatype<QString>() {
return QMetaType::QString;
}
-template<>
+template <>
inline QMetaType::Type metatype<bool>() {
return QMetaType::Bool;
}
-template<>
+template <>
inline QMetaType::Type metatype<double>() {
return QMetaType::Double;
}
diff --git a/src/components/qt_hmi/qml_plugins/dbus_adapter/optional_argument.h b/src/components/qt_hmi/qml_plugins/dbus_adapter/optional_argument.h
index b9360c3eb4..ea6f68bb31 100644
--- a/src/components/qt_hmi/qml_plugins/dbus_adapter/optional_argument.h
+++ b/src/components/qt_hmi/qml_plugins/dbus_adapter/optional_argument.h
@@ -38,38 +38,34 @@
#include "qt_version.h"
#include <QtDBus/QDBusArgument>
-template<class T>
+template <class T>
struct OptionalArgument {
T val;
bool presence;
- explicit OptionalArgument(const T& value)
- : val(value),
- presence(true) {}
- OptionalArgument()
- : presence(false) {}
+ explicit OptionalArgument(const T& value) : val(value), presence(true) {}
+ OptionalArgument() : presence(false) {}
};
-template<class T>
-inline
-QDBusArgument& operator << (QDBusArgument& arg, const OptionalArgument<T>& o) {
+template <class T>
+inline QDBusArgument& operator<<(QDBusArgument& arg,
+ const OptionalArgument<T>& o) {
arg.beginStructure();
arg << o.presence << o.val;
arg.endStructure();
return arg;
}
-template<class T>
-inline
-const QDBusArgument& operator >> (const QDBusArgument& arg, OptionalArgument<T>& o) {
+template <class T>
+inline const QDBusArgument& operator>>(const QDBusArgument& arg,
+ OptionalArgument<T>& o) {
arg.beginStructure();
arg >> o.presence >> o.val;
arg.endStructure();
return arg;
}
-template<class T>
-inline
-bool VariantToValue(const QVariant& variant, OptionalArgument<T>& o) {
+template <class T>
+inline bool VariantToValue(const QVariant& variant, OptionalArgument<T>& o) {
if (variant.isNull()) {
o.presence = false;
return true;
@@ -80,7 +76,7 @@ bool VariantToValue(const QVariant& variant, OptionalArgument<T>& o) {
#if QT_4
Q_DECLARE_METATYPE(QList<int>)
-#endif // QT_4
+#endif // QT_4
Q_DECLARE_METATYPE(OptionalArgument<int>)
Q_DECLARE_METATYPE(OptionalArgument<QString>)
diff --git a/src/components/qt_hmi/qml_plugins/dbus_adapter/qml_dbus_common.h b/src/components/qt_hmi/qml_plugins/dbus_adapter/qml_dbus_common.h
index eb9b93929f..fa9692f9d9 100644
--- a/src/components/qt_hmi/qml_plugins/dbus_adapter/qml_dbus_common.h
+++ b/src/components/qt_hmi/qml_plugins/dbus_adapter/qml_dbus_common.h
@@ -70,8 +70,7 @@ enum ErrorCode {
inline void RaiseDbusError(QObject* adaptor, int code, const QString& message) {
QDBusContext* context = dynamic_cast<QDBusContext*>(adaptor->parent());
if (context) {
- context->sendErrorReply(QString::number(static_cast<int>(code)),
- message);
+ context->sendErrorReply(QString::number(static_cast<int>(code)), message);
}
}
@@ -79,31 +78,39 @@ inline void RaiseDbusError(QObject* adaptor, int code) {
RaiseDbusError(adaptor, code, "");
}
-template<typename T>
+template <typename T>
inline void PutArgToMap(QVariantMap& map, const char* name, const T& v) {
map.insert(name, QVariant::fromValue(v));
}
inline bool GetArgFromMap(const QVariantMap& map, const char* name, int& v) {
QVariantMap::const_iterator it = map.find(name);
- if (map.end() == it) return false;
- if (it->type() != QVariant::Int) return false;
+ if (map.end() == it)
+ return false;
+ if (it->type() != QVariant::Int)
+ return false;
v = it->toInt();
return true;
}
-inline bool GetArgFromMap(const QVariantMap& map, const char* name, QString& v) {
+inline bool GetArgFromMap(const QVariantMap& map,
+ const char* name,
+ QString& v) {
QVariantMap::const_iterator it = map.find(name);
- if (map.end() == it) return false;
- if (it->type() != QVariant::String) return false;
+ if (map.end() == it)
+ return false;
+ if (it->type() != QVariant::String)
+ return false;
v = it->toString();
return true;
}
inline bool GetArgFromMap(const QVariantMap& map, const char* name, bool& v) {
QVariantMap::const_iterator it = map.find(name);
- if (map.end() == it) return false;
- if (it->type() != QVariant::Bool) return false;
+ if (map.end() == it)
+ return false;
+ if (it->type() != QVariant::Bool)
+ return false;
v = it->toBool();
return true;
}
@@ -111,78 +118,87 @@ inline bool GetArgFromMap(const QVariantMap& map, const char* name, bool& v) {
inline bool isNumber(QVariant v) {
QVariant::Type t = v.type();
return (t == QVariant::Double) || (t == QVariant::Int) ||
- (t == QVariant::UInt) || (t == QVariant::LongLong) ||
+ (t == QVariant::UInt) || (t == QVariant::LongLong) ||
(t == QVariant::ULongLong);
}
inline bool GetArgFromMap(const QVariantMap& map, const char* name, double& v) {
QVariantMap::const_iterator it = map.find(name);
- if (map.end() == it) return false;
- if (!isNumber(*it)) return false;
+ if (map.end() == it)
+ return false;
+ if (!isNumber(*it))
+ return false;
v = it->toDouble();
return true;
}
inline bool VariantToValue(const QVariant& variant, int& v) {
- if (variant.type() != QVariant::Int) return false;
- v = variant.toInt();
- return true;
+ if (variant.type() != QVariant::Int)
+ return false;
+ v = variant.toInt();
+ return true;
}
inline bool VariantToValue(const QVariant& variant, QString& v) {
- if (variant.type() != QVariant::String) return false;
- v = variant.toString();
- return true;
+ if (variant.type() != QVariant::String)
+ return false;
+ v = variant.toString();
+ return true;
}
inline bool VariantToValue(const QVariant& variant, bool& v) {
- if (variant.type() != QVariant::Bool) return false;
- v = variant.toBool();
- return true;
+ if (variant.type() != QVariant::Bool)
+ return false;
+ v = variant.toBool();
+ return true;
}
inline bool VariantToValue(const QVariant& variant, double& v) {
- if (variant.type() != QVariant::Double) return false;
- v = variant.toDouble();
- return true;
+ if (variant.type() != QVariant::Double)
+ return false;
+ v = variant.toDouble();
+ return true;
}
inline bool VariantToValue(const QVariant& variant, QStringList& v) {
- if (variant.type() != QVariant::List) return false;
+ if (variant.type() != QVariant::List)
+ return false;
QList<QVariant> list = variant.toList();
for (QList<QVariant>::const_iterator i = list.begin(); i != list.end(); ++i) {
- if (i->type() != QVariant::String) return false;
+ if (i->type() != QVariant::String)
+ return false;
v.append(i->toString());
}
return true;
}
-template<typename T>
+template <typename T>
bool VariantToValue(const QVariant& variant, QList<T>& v) {
- if (variant.type() != QVariant::List) return false;
- QList<T> spare;
- QList<QVariant> list = variant.toList();
- for (QList<QVariant>::const_iterator i = list.begin(); i != list.end(); ++i) {
- QVariant::Type type = i->type();
-// Although this function is declared as returning QVariant::Type(obsolete),
-// the return value should be interpreted as QMetaType::Type.
-// (http://qt-project.org/doc/qt-5.0/qtcore/qvariant.html#type)
- QMetaType::Type type_casted = static_cast<QMetaType::Type>(type);
- if (type_casted != metatype<T>()) {
- return false;
- }
- spare.append(i->value<T>());
+ if (variant.type() != QVariant::List)
+ return false;
+ QList<T> spare;
+ QList<QVariant> list = variant.toList();
+ for (QList<QVariant>::const_iterator i = list.begin(); i != list.end(); ++i) {
+ QVariant::Type type = i->type();
+ // Although this function is declared as returning QVariant::Type(obsolete),
+ // the return value should be interpreted as QMetaType::Type.
+ // (http://qt-project.org/doc/qt-5.0/qtcore/qvariant.html#type)
+ QMetaType::Type type_casted = static_cast<QMetaType::Type>(type);
+ if (type_casted != metatype<T>()) {
+ return false;
}
- v.swap(spare);
- return true;
+ spare.append(i->value<T>());
+ }
+ v.swap(spare);
+ return true;
}
-template<typename T>
+template <typename T>
inline QVariant ValueToVariant(const T& v) {
- return QVariant::fromValue(v);
+ return QVariant::fromValue(v);
}
-template<typename T>
+template <typename T>
inline QVariant ValueToVariant(const QList<T>& v) {
QList<QVariant> list;
for (typename QList<T>::const_iterator i = v.begin(); i != v.end(); ++i)
@@ -190,7 +206,7 @@ inline QVariant ValueToVariant(const QList<T>& v) {
return QVariant::fromValue(list);
}
-template<typename T>
+template <typename T>
inline void PutArgToMap(QVariantMap& map, const char* name, const QList<T>& v) {
QList<QVariant> list;
for (typename QList<T>::const_iterator i = v.begin(); i != v.end(); ++i)
@@ -198,31 +214,38 @@ inline void PutArgToMap(QVariantMap& map, const char* name, const QList<T>& v) {
map.insert(name, QVariant::fromValue(list));
}
-template<typename T>
-inline bool GetArgFromMap(const QVariantMap& map, const char* name, QList<T>& v) {
+template <typename T>
+inline bool GetArgFromMap(const QVariantMap& map,
+ const char* name,
+ QList<T>& v) {
QVariantMap::const_iterator it = map.find(name);
- if (map.end() == it) return false;
+ if (map.end() == it)
+ return false;
const QVariant& variant = *it;
- if (variant.type() != QVariant::List) return false;
+ if (variant.type() != QVariant::List)
+ return false;
QList<QVariant> list = variant.toList();
for (QList<QVariant>::const_iterator i = list.begin(); i != list.end(); ++i) {
T t;
bool ok = VariantToValue(*i, t);
- if (!ok) return false;
+ if (!ok)
+ return false;
v.append(t);
}
return true;
}
-template<typename T>
-inline void PutArgToMap(QVariantMap& map, const char* name,
+template <typename T>
+inline void PutArgToMap(QVariantMap& map,
+ const char* name,
const OptionalArgument<T>& v) {
if (v.presence)
map.insert(name, ValueToVariant(v.val));
}
-template<typename T>
-inline bool GetArgFromMap(const QVariantMap& map, const char* name,
+template <typename T>
+inline bool GetArgFromMap(const QVariantMap& map,
+ const char* name,
OptionalArgument<T>& v) {
QVariantMap::const_iterator it = map.find(name);
if (map.end() == it || !it->isValid()) {
diff --git a/src/components/qt_hmi/qml_plugins/dbus_adapter/qt_version.h b/src/components/qt_hmi/qml_plugins/dbus_adapter/qt_version.h
index 4eff83bd5b..c41eea7403 100644
--- a/src/components/qt_hmi/qml_plugins/dbus_adapter/qt_version.h
+++ b/src/components/qt_hmi/qml_plugins/dbus_adapter/qt_version.h
@@ -37,11 +37,12 @@
#include <qglobal.h>
-#define QT_4 ((QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)) && \
- (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)))
+#define QT_4 \
+ ((QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)) && \
+ (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)))
-#define QT_5 ((QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) && \
- (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)))
+#define QT_5 \
+ ((QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) && \
+ (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)))
#endif // SRC_COMPONENTS_QT_HMI_QML_PLUGINS_DBUS_ADAPTER_QT_VERSION_H_
-
diff --git a/src/components/qt_hmi/qml_plugins/dbus_adapter/stream_qvariant.cc b/src/components/qt_hmi/qml_plugins/dbus_adapter/stream_qvariant.cc
index b60f5226c4..ec049b9533 100644
--- a/src/components/qt_hmi/qml_plugins/dbus_adapter/stream_qvariant.cc
+++ b/src/components/qt_hmi/qml_plugins/dbus_adapter/stream_qvariant.cc
@@ -35,33 +35,33 @@
std::basic_ostream<char>& operator<<(std::basic_ostream<char>& os,
const QVariant& value) {
switch (value.type()) {
- case QVariant::Map: {
- os << "{ ";
- QVariantMap structure = value.toMap();
- QMapIterator<QString, QVariant> i(structure);
- while (i.hasNext()) {
- i.next();
- os << i.key() << ":" << i.value();
- if (i.hasNext()) {
- os << ", ";
+ case QVariant::Map: {
+ os << "{ ";
+ QVariantMap structure = value.toMap();
+ QMapIterator<QString, QVariant> i(structure);
+ while (i.hasNext()) {
+ i.next();
+ os << i.key() << ":" << i.value();
+ if (i.hasNext()) {
+ os << ", ";
+ }
}
- }
- os << " }";
- } break;
- case QVariant::List: {
- os << "[ ";
- QVariantList array = value.toList();
- QListIterator<QVariant> i(array);
- while (i.hasNext()) {
- os << i.next();
- if (i.hasNext()) {
- os << ", ";
+ os << " }";
+ } break;
+ case QVariant::List: {
+ os << "[ ";
+ QVariantList array = value.toList();
+ QListIterator<QVariant> i(array);
+ while (i.hasNext()) {
+ os << i.next();
+ if (i.hasNext()) {
+ os << ", ";
+ }
}
- }
- os << " ]";
- } break;
- default:
- os << value.toString().toLatin1().data();
+ os << " ]";
+ } break;
+ default:
+ os << value.toString().toLatin1().data();
}
return os;
diff --git a/src/components/qt_hmi/qml_plugins/hw_buttons/attributed_mouse_event.cc b/src/components/qt_hmi/qml_plugins/hw_buttons/attributed_mouse_event.cc
index bcde90930f..899fc5b615 100644
--- a/src/components/qt_hmi/qml_plugins/hw_buttons/attributed_mouse_event.cc
+++ b/src/components/qt_hmi/qml_plugins/hw_buttons/attributed_mouse_event.cc
@@ -34,6 +34,6 @@
#include "attributed_mouse_event.h"
-Item *AttributedMouseEvent::item() const {
- return item_;
+Item* AttributedMouseEvent::item() const {
+ return item_;
}
diff --git a/src/components/qt_hmi/qml_plugins/hw_buttons/attributed_mouse_event.h b/src/components/qt_hmi/qml_plugins/hw_buttons/attributed_mouse_event.h
index 2d2babc29f..0486397058 100644
--- a/src/components/qt_hmi/qml_plugins/hw_buttons/attributed_mouse_event.h
+++ b/src/components/qt_hmi/qml_plugins/hw_buttons/attributed_mouse_event.h
@@ -38,10 +38,10 @@
#include <QtCore/QObject>
#if QT_4
-# include <QtDeclarative/QDeclarativeItem>
+#include <QtDeclarative/QDeclarativeItem>
typedef QDeclarativeItem Item;
#elif QT_5
-# include <QtQuick/QQuickItem>
+#include <QtQuick/QQuickItem>
typedef QQuickItem Item;
#endif // QT_VERSION
@@ -50,12 +50,12 @@ class AttributedMouseEvent : public QObject {
Q_PROPERTY(Item* item READ item)
public:
- explicit AttributedMouseEvent(Item *item) : item_(item) {}
+ explicit AttributedMouseEvent(Item* item) : item_(item) {}
- Item *item() const;
+ Item* item() const;
private:
- Item *item_;
+ Item* item_;
Q_DISABLE_COPY(AttributedMouseEvent)
};
diff --git a/src/components/qt_hmi/qml_plugins/hw_buttons/hmi_hwbuttons.cc b/src/components/qt_hmi/qml_plugins/hw_buttons/hmi_hwbuttons.cc
index bf63c12cb1..62a090a509 100644
--- a/src/components/qt_hmi/qml_plugins/hw_buttons/hmi_hwbuttons.cc
+++ b/src/components/qt_hmi/qml_plugins/hw_buttons/hmi_hwbuttons.cc
@@ -35,16 +35,16 @@
#include "hmi_hwbuttons.h"
#if QT_4
-# include <QtDeclarative/qdeclarative.h>
-# include <QtGui/QGraphicsColorizeEffect>
+#include <QtDeclarative/qdeclarative.h>
+#include <QtGui/QGraphicsColorizeEffect>
#elif QT_5
-# include <QtQml>
+#include <QtQml>
#endif // QT_VERSION
#include "masked_container.h"
#include "attributed_mouse_event.h"
-void HmiHWButtons::registerTypes(const char *uri) {
+void HmiHWButtons::registerTypes(const char* uri) {
// @uri com.ford.hmi_framework
qmlRegisterType<MaskedContainer>(uri, 1, 0, "MaskedContainer");
qmlRegisterType<AttributedMouseEvent>();
diff --git a/src/components/qt_hmi/qml_plugins/hw_buttons/hmi_hwbuttons.h b/src/components/qt_hmi/qml_plugins/hw_buttons/hmi_hwbuttons.h
index cf8f0b5f4b..0cf71807c4 100644
--- a/src/components/qt_hmi/qml_plugins/hw_buttons/hmi_hwbuttons.h
+++ b/src/components/qt_hmi/qml_plugins/hw_buttons/hmi_hwbuttons.h
@@ -38,10 +38,10 @@
#include "qt_version.h"
#if QT_4
-# include <QtDeclarative/QDeclarativeExtensionPlugin>
+#include <QtDeclarative/QDeclarativeExtensionPlugin>
typedef QDeclarativeExtensionPlugin ExtensionPlugin;
#elif QT_5
-# include <QtQml/QQmlExtensionPlugin>
+#include <QtQml/QQmlExtensionPlugin>
typedef QQmlExtensionPlugin ExtensionPlugin;
#endif // QT_VERSION
@@ -52,8 +52,7 @@ class HmiHWButtons : public ExtensionPlugin {
#endif // QT_5
public:
- void registerTypes(const char *uri);
+ void registerTypes(const char* uri);
};
#endif // SRC_COMPONENTS_QT_HMI_QML_PLUGINS_HW_BUTTONS_HMI_HWBUTTONS_H_
-
diff --git a/src/components/qt_hmi/qml_plugins/hw_buttons/masked_container.cc b/src/components/qt_hmi/qml_plugins/hw_buttons/masked_container.cc
index 0d144ff84c..f80e80907e 100644
--- a/src/components/qt_hmi/qml_plugins/hw_buttons/masked_container.cc
+++ b/src/components/qt_hmi/qml_plugins/hw_buttons/masked_container.cc
@@ -35,74 +35,73 @@
#include "masked_container.h"
#if QT_4
-# include <QtCore/QPointF>
-# include <QtGui/QGraphicsSceneMouseEvent>
-# define IMAGE "QDeclarativeImage"
+#include <QtCore/QPointF>
+#include <QtGui/QGraphicsSceneMouseEvent>
+#define IMAGE "QDeclarativeImage"
#elif QT_5
-# include <QtGui/QImage>
-# include <QtCore/QEvent>
-# define IMAGE "QQuickImage"
+#include <QtGui/QImage>
+#include <QtCore/QEvent>
+#define IMAGE "QQuickImage"
#endif // QT_VERSION
-MaskedContainer::MaskedContainer(Item *parent)
- : Item(parent),
- mask_(NULL) {
+MaskedContainer::MaskedContainer(Item* parent) : Item(parent), mask_(NULL) {
setAcceptedMouseButtons(Qt::LeftButton);
}
void MaskedContainer::componentComplete() {
- Item::componentComplete();
-
- for (QObjectList::ConstIterator it = children().begin();
- it != children().end(); ++it) {
- Item *item = qobject_cast<Item*>(*it);
- if (item && item->inherits(IMAGE) && item->isVisible()) {
- images_.push_back(item);
- }
+ Item::componentComplete();
+
+ for (QObjectList::ConstIterator it = children().begin();
+ it != children().end();
+ ++it) {
+ Item* item = qobject_cast<Item*>(*it);
+ if (item && item->inherits(IMAGE) && item->isVisible()) {
+ images_.push_back(item);
}
+ }
- int height = this->height();
- int width =this->width();
-
- for (size_t i = 0; i < images_.size(); ++i) {
- Item *item = images_[i];
- int itemWidth = item->width();
- int itemHeight = item->height();
- int itemX = item->x();
- int itemY = item->y();
- if (height < itemHeight + itemY)
- height = itemHeight + itemY;
- if (width < itemWidth + itemX)
- width = itemWidth + itemX;
- }
+ int height = this->height();
+ int width = this->width();
+
+ for (size_t i = 0; i < images_.size(); ++i) {
+ Item* item = images_[i];
+ int itemWidth = item->width();
+ int itemHeight = item->height();
+ int itemX = item->x();
+ int itemY = item->y();
+ if (height < itemHeight + itemY)
+ height = itemHeight + itemY;
+ if (width < itemWidth + itemX)
+ width = itemWidth + itemX;
+ }
- setHeight(height);
- setWidth(width);
-
- mask_ = new int[height * width];
- std::fill(mask_, mask_ + height * width, -1);
-
- for (size_t i = 0; i < images_.size(); ++i) {
- Item *item = images_[i];
- int itemWidth = item->width();
- int itemHeight = item->height();
- int itemX = item->x();
- int itemY = item->y();
-
- QUrl url = item->property("source").toUrl();
- QImage img(url.path());
- const QRgb* bits = reinterpret_cast<const QRgb*>(img.constBits());
- for (int x = 0; x < itemWidth; ++x) {
- for (int y = 0; y < itemHeight; ++y) {
- if (qAlpha(bits[y * itemWidth + x]) > 128) {
- mask_[(itemY + y) * width + (x + itemX)] = i;
- }
- }
+ setHeight(height);
+ setWidth(width);
+
+ mask_ = new int[height * width];
+ std::fill(mask_, mask_ + height * width, -1);
+
+ for (size_t i = 0; i < images_.size(); ++i) {
+ Item* item = images_[i];
+ int itemWidth = item->width();
+ int itemHeight = item->height();
+ int itemX = item->x();
+ int itemY = item->y();
+
+ QUrl url = item->property("source").toUrl();
+ QImage img(url.path());
+ const QRgb* bits = reinterpret_cast<const QRgb*>(img.constBits());
+ for (int x = 0; x < itemWidth; ++x) {
+ for (int y = 0; y < itemHeight; ++y) {
+ if (qAlpha(bits[y * itemWidth + x]) > 128) {
+ mask_[(itemY + y) * width + (x + itemX)] = i;
}
+ }
}
+ }
}
-void MaskedContainer::mousePressEvent(MouseEvent *mouse) {
+void MaskedContainer::mousePressEvent(MouseEvent* mouse) {
#if QT_4
qreal x = mouse->pos().x();
qreal y = mouse->pos().y();
@@ -126,7 +125,7 @@ void MaskedContainer::mousePressEvent(MouseEvent *mouse) {
}
}
-void MaskedContainer::mouseReleaseEvent(MouseEvent *mouse) {
+void MaskedContainer::mouseReleaseEvent(MouseEvent* mouse) {
#if QT_4
qreal x = mouse->pos().x();
qreal y = mouse->pos().y();
@@ -152,4 +151,3 @@ void MaskedContainer::mouseReleaseEvent(MouseEvent *mouse) {
MaskedContainer::~MaskedContainer() {
delete[] mask_;
}
-
diff --git a/src/components/qt_hmi/qml_plugins/hw_buttons/masked_container.h b/src/components/qt_hmi/qml_plugins/hw_buttons/masked_container.h
index 0048bdda2a..ae5303a693 100644
--- a/src/components/qt_hmi/qml_plugins/hw_buttons/masked_container.h
+++ b/src/components/qt_hmi/qml_plugins/hw_buttons/masked_container.h
@@ -41,11 +41,11 @@
#include "qt_version.h"
#if QT_4
-# include <QtDeclarative/QDeclarativeItem>
+#include <QtDeclarative/QDeclarativeItem>
typedef QDeclarativeItem Item;
typedef QGraphicsSceneMouseEvent MouseEvent;
#elif QT_5
-# include <QtQuick/QQuickItem>
+#include <QtQuick/QQuickItem>
typedef QQuickItem Item;
typedef QMouseEvent MouseEvent;
#endif
@@ -57,21 +57,21 @@ class MaskedContainer : public Item {
Q_DISABLE_COPY(MaskedContainer)
public:
- explicit MaskedContainer(Item *parent = 0);
+ explicit MaskedContainer(Item* parent = 0);
~MaskedContainer();
- signals:
- void pressed(AttributedMouseEvent *attr);
- void released(AttributedMouseEvent *attr);
+signals:
+ void pressed(AttributedMouseEvent* attr);
+ void released(AttributedMouseEvent* attr);
protected:
virtual void componentComplete();
- virtual void mousePressEvent(MouseEvent *event);
- virtual void mouseReleaseEvent(MouseEvent *event);
+ virtual void mousePressEvent(MouseEvent* event);
+ virtual void mouseReleaseEvent(MouseEvent* event);
private:
std::vector<Item*> images_;
- int *mask_;
+ int* mask_;
#if QT_4
int indexOfMask(qreal x, qreal y) const {
diff --git a/src/components/qt_hmi/qml_plugins/hw_buttons/qt_version.h b/src/components/qt_hmi/qml_plugins/hw_buttons/qt_version.h
index fb2751504d..a700a87919 100644
--- a/src/components/qt_hmi/qml_plugins/hw_buttons/qt_version.h
+++ b/src/components/qt_hmi/qml_plugins/hw_buttons/qt_version.h
@@ -37,11 +37,12 @@
#include <qglobal.h>
-#define QT_4 ((QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)) && \
- (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)))
+#define QT_4 \
+ ((QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)) && \
+ (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)))
-#define QT_5 ((QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) && \
- (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)))
+#define QT_5 \
+ ((QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) && \
+ (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)))
#endif // SRC_COMPONENTS_QT_HMI_QML_PLUGINS_HW_BUTTONS_QT_VERSION_H_
-
diff --git a/src/components/qt_hmi/qml_plugins/log4cxx/log4cxx_plugin.cc b/src/components/qt_hmi/qml_plugins/log4cxx/log4cxx_plugin.cc
index da863e2e26..8b7efe23d7 100644
--- a/src/components/qt_hmi/qml_plugins/log4cxx/log4cxx_plugin.cc
+++ b/src/components/qt_hmi/qml_plugins/log4cxx/log4cxx_plugin.cc
@@ -37,58 +37,58 @@
#include <log4cxx/log4cxx.h>
#include <log4cxx/propertyconfigurator.h>
-log4cxx::LoggerPtr logger_ = log4cxx::LoggerPtr(
- log4cxx::Logger::getLogger("Log4cxxPlugin"));
+log4cxx::LoggerPtr logger_ =
+ log4cxx::LoggerPtr(log4cxx::Logger::getLogger("Log4cxxPlugin"));
#if QT_4
-void smartLogger(QtMsgType type, const char *msg) {
+void smartLogger(QtMsgType type, const char* msg) {
log4cxx::spi::LocationInfo location("", "", -1);
switch (type) {
- case QtDebugMsg:
- (*logger_).debug(msg, location);
- break;
- case QtWarningMsg:
- (*logger_).warn(msg, location);
- break;
- case QtCriticalMsg:
- (*logger_).error(msg, location);
- break;
- case QtFatalMsg:
- (*logger_).fatal(msg, location);
- break;
- default:
- (*logger_).info(msg, location);
- break;
+ case QtDebugMsg:
+ (*logger_).debug(msg, location);
+ break;
+ case QtWarningMsg:
+ (*logger_).warn(msg, location);
+ break;
+ case QtCriticalMsg:
+ (*logger_).error(msg, location);
+ break;
+ case QtFatalMsg:
+ (*logger_).fatal(msg, location);
+ break;
+ default:
+ (*logger_).info(msg, location);
+ break;
}
}
#elif QT_5
-void smartLogger(QtMsgType type, const QMessageLogContext &context,
- const QString &msg) {
- log4cxx::spi::LocationInfo location(context.file,
- context.function ? context.function : "",
- context.line);
+void smartLogger(QtMsgType type,
+ const QMessageLogContext& context,
+ const QString& msg) {
+ log4cxx::spi::LocationInfo location(
+ context.file, context.function ? context.function : "", context.line);
switch (type) {
- case QtDebugMsg:
- (*logger_).debug(msg.toStdString(), location);
- break;
- case QtWarningMsg:
- (*logger_).warn(msg.toStdString(), location);
- break;
- case QtCriticalMsg:
- (*logger_).error(msg.toStdString(), location);
- break;
- case QtFatalMsg:
- (*logger_).fatal(msg.toStdString(), location);
- break;
- default:
- (*logger_).info(msg.toStdString(), location);
- break;
+ case QtDebugMsg:
+ (*logger_).debug(msg.toStdString(), location);
+ break;
+ case QtWarningMsg:
+ (*logger_).warn(msg.toStdString(), location);
+ break;
+ case QtCriticalMsg:
+ (*logger_).error(msg.toStdString(), location);
+ break;
+ case QtFatalMsg:
+ (*logger_).fatal(msg.toStdString(), location);
+ break;
+ default:
+ (*logger_).info(msg.toStdString(), location);
+ break;
}
}
#endif // QT_VERSION
-void Log4cxxPlugin::registerTypes(const char *uri) {
+void Log4cxxPlugin::registerTypes(const char* uri) {
log4cxx::PropertyConfigurator::configure("log4cxx.properties");
#if QT_4
diff --git a/src/components/qt_hmi/qml_plugins/log4cxx/log4cxx_plugin.h b/src/components/qt_hmi/qml_plugins/log4cxx/log4cxx_plugin.h
index fc82352f0c..e8d1ff3347 100644
--- a/src/components/qt_hmi/qml_plugins/log4cxx/log4cxx_plugin.h
+++ b/src/components/qt_hmi/qml_plugins/log4cxx/log4cxx_plugin.h
@@ -37,19 +37,21 @@
#include <qglobal.h>
-#define QT_4 ((QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)) && \
- (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)))
+#define QT_4 \
+ ((QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)) && \
+ (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)))
-#define QT_5 ((QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) && \
- (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)))
+#define QT_5 \
+ ((QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) && \
+ (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)))
#if QT_4
-# include <QtDeclarative/qdeclarative.h>
-# include <QtDeclarative/QDeclarativeExtensionPlugin>
+#include <QtDeclarative/qdeclarative.h>
+#include <QtDeclarative/QDeclarativeExtensionPlugin>
typedef QDeclarativeExtensionPlugin ExtensionPlugin;
#elif QT_5
-# include <QtQml/qqml.h>
-# include <QtQml/QQmlExtensionPlugin>
+#include <QtQml/qqml.h>
+#include <QtQml/QQmlExtensionPlugin>
typedef QQmlExtensionPlugin ExtensionPlugin;
#endif // QT_VERSION
@@ -58,7 +60,7 @@ class Logger : public QObject {
Q_DISABLE_COPY(Logger)
public:
- explicit Logger(QObject *parent = 0) : QObject(parent) {}
+ explicit Logger(QObject* parent = 0) : QObject(parent) {}
};
class Log4cxxPlugin : public ExtensionPlugin {
@@ -68,10 +70,9 @@ class Log4cxxPlugin : public ExtensionPlugin {
#endif // QT_5
public:
- void registerTypes(const char *uri);
+ void registerTypes(const char* uri);
};
QML_DECLARE_TYPE(Logger)
#endif // SRC_COMPONENTS_QT_HMI_QML_PLUGINS_LOG4CXX_LOG4CXX_PLUGIN_H_
-
diff --git a/src/components/qt_hmi/qml_plugins/named_pipe_notifier/named_pipe_notifier.cc b/src/components/qt_hmi/qml_plugins/named_pipe_notifier/named_pipe_notifier.cc
index f51db76b99..46b057dcca 100644
--- a/src/components/qt_hmi/qml_plugins/named_pipe_notifier/named_pipe_notifier.cc
+++ b/src/components/qt_hmi/qml_plugins/named_pipe_notifier/named_pipe_notifier.cc
@@ -41,10 +41,11 @@
void NamedPipeNotifier::run() {
int fd = ::open(name_.toLocal8Bit().constData(), O_RDONLY);
- if (-1 == fd) { // if open() fails
+ if (-1 == fd) { // if open() fails
if ((errno != ENOENT) // we can only manage lack of pipe
- || (-1 == ::mkfifo(name_.toLocal8Bit().constData(), 0666))
- || (-1 == (fd = ::open(name_.toLocal8Bit().constData(), O_RDONLY)))) {
+ ||
+ (-1 == ::mkfifo(name_.toLocal8Bit().constData(), 0666)) ||
+ (-1 == (fd = ::open(name_.toLocal8Bit().constData(), O_RDONLY)))) {
emit openFailed();
return;
}
@@ -52,7 +53,7 @@ void NamedPipeNotifier::run() {
::fd_set readfds;
FD_ZERO(&readfds);
FD_SET(fd, &readfds);
-// this select() is supposed to block till pipe is empty
+ // this select() is supposed to block till pipe is empty
if (::select(fd + 1, &readfds, 0, 0, 0) > 0) {
emit readyRead();
}
diff --git a/src/components/qt_hmi/qml_plugins/named_pipe_notifier/named_pipe_notifier.h b/src/components/qt_hmi/qml_plugins/named_pipe_notifier/named_pipe_notifier.h
index 993bb3cb31..cdca06466f 100644
--- a/src/components/qt_hmi/qml_plugins/named_pipe_notifier/named_pipe_notifier.h
+++ b/src/components/qt_hmi/qml_plugins/named_pipe_notifier/named_pipe_notifier.h
@@ -45,7 +45,9 @@ class NamedPipeNotifier : public QThread {
public:
explicit NamedPipeNotifier(QObject* parent = 0) : QThread(parent) {}
- const QString& name() const { return name_; }
+ const QString& name() const {
+ return name_;
+ }
void set_name(const QString& name) {
if (name_ != name) {
name_ = name;
@@ -56,7 +58,7 @@ class NamedPipeNotifier : public QThread {
protected:
virtual void run();
- signals:
+signals:
void nameChanged();
void readyRead();
void openFailed();
diff --git a/src/components/qt_hmi/qml_plugins/named_pipe_notifier/named_pipe_notifier_plugin.cc b/src/components/qt_hmi/qml_plugins/named_pipe_notifier/named_pipe_notifier_plugin.cc
index 8aa2b4cf76..dacb11ad93 100644
--- a/src/components/qt_hmi/qml_plugins/named_pipe_notifier/named_pipe_notifier_plugin.cc
+++ b/src/components/qt_hmi/qml_plugins/named_pipe_notifier/named_pipe_notifier_plugin.cc
@@ -35,16 +35,16 @@
#include "named_pipe_notifier_plugin.h"
#if QT_4
-# include <QtDeclarative/qdeclarative.h>
+#include <QtDeclarative/qdeclarative.h>
#elif QT_5
-# include <QtQml/qqml.h>
+#include <QtQml/qqml.h>
#endif // QT_VERSION
#include "named_pipe_notifier.h"
void NamedPipeNotifierPlugin::registerTypes(const char* uri) {
- // @uri com.ford.sdl.hmi.named_pipe_notifier
- qmlRegisterType<NamedPipeNotifier>(uri, 1, 0, "NamedPipeNotifier");
+ // @uri com.ford.sdl.hmi.named_pipe_notifier
+ qmlRegisterType<NamedPipeNotifier>(uri, 1, 0, "NamedPipeNotifier");
}
#if QT_4
diff --git a/src/components/qt_hmi/qml_plugins/named_pipe_notifier/named_pipe_notifier_plugin.h b/src/components/qt_hmi/qml_plugins/named_pipe_notifier/named_pipe_notifier_plugin.h
index 6c64d531ac..426df483a2 100644
--- a/src/components/qt_hmi/qml_plugins/named_pipe_notifier/named_pipe_notifier_plugin.h
+++ b/src/components/qt_hmi/qml_plugins/named_pipe_notifier/named_pipe_notifier_plugin.h
@@ -38,10 +38,10 @@
#include "qt_version.h"
#if QT_4
-# include <QtDeclarative/QDeclarativeExtensionPlugin>
+#include <QtDeclarative/QDeclarativeExtensionPlugin>
typedef QDeclarativeExtensionPlugin ExtensionPlugin;
#elif QT_5
-# include <QtQml/QQmlExtensionPlugin>
+#include <QtQml/QQmlExtensionPlugin>
typedef QQmlExtensionPlugin ExtensionPlugin;
#endif // QT_5
diff --git a/src/components/qt_hmi/qml_plugins/named_pipe_notifier/qt_version.h b/src/components/qt_hmi/qml_plugins/named_pipe_notifier/qt_version.h
index 91533346c0..0e2456d732 100644
--- a/src/components/qt_hmi/qml_plugins/named_pipe_notifier/qt_version.h
+++ b/src/components/qt_hmi/qml_plugins/named_pipe_notifier/qt_version.h
@@ -37,11 +37,12 @@
#include <qglobal.h>
-#define QT_4 ((QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)) && \
- (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)))
+#define QT_4 \
+ ((QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)) && \
+ (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)))
-#define QT_5 ((QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) && \
- (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)))
+#define QT_5 \
+ ((QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) && \
+ (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)))
#endif // SRC_COMPONENTS_QT_HMI_QML_PLUGINS_NAMED_PIPE_NOTIFIER_QT_VERSION_H_
-