2 * Copyright (C) 2016, 2017 Mentor Graphics Development (Deutschland) GmbH
3 * Copyright (c) 2018 TOYOTA MOTOR CORPORATION
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <QGuiApplication>
19 #include <QCommandLineParser>
20 #include <QtCore/QUrlQuery>
21 #include <QtGui/QGuiApplication>
22 #include <QtQml/QQmlApplicationEngine>
23 #include <QtQml/QQmlContext>
24 #include <QtQml/qqml.h>
25 #include <QQuickWindow>
28 #include <qlibwindowmanager.h>
29 #include "applicationmodel.h"
31 #include "homescreenhandler.h"
32 #include "hmi-debug.h"
34 int main(int argc, char *argv[])
36 QString myname = QString("launcher");
37 QGuiApplication a(argc, argv);
39 QCoreApplication::setOrganizationDomain("LinuxFoundation");
40 QCoreApplication::setOrganizationName("AutomotiveGradeLinux");
41 QCoreApplication::setApplicationName(myname);
42 QCoreApplication::setApplicationVersion("0.1.0");
44 QCommandLineParser parser;
45 parser.addPositionalArgument("port", a.translate("main", "port for binding"));
46 parser.addPositionalArgument("secret", a.translate("main", "secret for binding"));
47 parser.addHelpOption();
48 parser.addVersionOption();
50 QStringList positionalArguments = parser.positionalArguments();
55 if (positionalArguments.length() == 2) {
56 port = positionalArguments.takeFirst().toInt();
57 token = positionalArguments.takeFirst();
60 HMI_DEBUG("launcher","port = %d, token = %s", port, token.toStdString().c_str());
62 // import C++ class to QML
63 qmlRegisterType<ApplicationModel>("AppModel", 1, 0, "ApplicationModel");
65 QLibWindowmanager* layoutHandler = new QLibWindowmanager();
66 if(layoutHandler->init(port,token) != 0){
70 AGLScreenInfo screenInfo(layoutHandler->get_scale_factor());
72 if (layoutHandler->requestSurface(myname) != 0) {
76 layoutHandler->set_event_handler(QLibWindowmanager::Event_SyncDraw, [layoutHandler, myname](json_object *object) {
77 layoutHandler->endDraw(myname);
80 HomescreenHandler* homescreenHandler = new HomescreenHandler();
81 homescreenHandler->init(port, token.toStdString().c_str(), layoutHandler, myname);
84 bindingAddress.setScheme(QStringLiteral("ws"));
85 bindingAddress.setHost(QStringLiteral("localhost"));
86 bindingAddress.setPort(port);
87 bindingAddress.setPath(QStringLiteral("/api"));
90 query.addQueryItem(QStringLiteral("token"), token);
91 bindingAddress.setQuery(query);
93 const QByteArray hack_delay = qgetenv("HMI_LAUNCHER_STARTUP_DELAY");
96 if (!hack_delay.isEmpty()) {
97 delay_time = (QString::fromLocal8Bit(hack_delay)).toInt();
100 QThread::sleep(delay_time);
101 qDebug("Sleep %d sec to resolve race condtion between HomeScreen and Launcher", delay_time);
104 QQmlApplicationEngine engine;
105 engine.rootContext()->setContextProperty(QStringLiteral("layoutHandler"), layoutHandler);
106 engine.rootContext()->setContextProperty(QStringLiteral("homescreenHandler"), homescreenHandler);
107 engine.rootContext()->setContextProperty(QStringLiteral("screenInfo"), &screenInfo);
108 engine.load(QUrl(QStringLiteral("qrc:/Launcher.qml")));
109 homescreenHandler->getRunnables();
111 QObject *root = engine.rootObjects().first();
112 QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
113 QObject::connect(window, SIGNAL(frameSwapped()), layoutHandler, SLOT(slotActivateSurface()));