POI: AGL LifeCycle Management
[apps/agl-service-windowmanager.git] / client / main.cpp.sample2
1 /*
2  * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 #include <QDebug>
19 #include <QDir>
20 #include <QGuiApplication>
21 #include <QQmlApplicationEngine>
22 #include <QQmlContext>
23 #include <QQuickView>
24 #include <QQuickWindow>
25 #include "communication.h"
26
27 #include "qlibwindowmanager.h"
28
29 int main(int argc, char *argv[]) {
30     QGuiApplication app(argc, argv);
31
32     qDebug() << QCoreApplication::arguments();
33
34     if (QCoreApplication::arguments().count() < 5) {
35         qWarning() << "Wrong parameters specified for the application. "
36                       "Please restart with correct parameters:"
37                       "width, height, name, color [port] [token]:\n\n"
38                       "/usr/bin/WindowManagerSampleApp/"
39                       "qmlWindowManagerSampleApp width height name color\n";
40         exit(EXIT_FAILURE);
41     }
42
43     QString label = QCoreApplication::arguments().at(3);
44
45     QLibWindowmanager* qwm = new QLibWindowmanager();
46
47     QString token = "wm";
48     int port = 1700;
49     if(QCoreApplication::arguments().count() == 7){
50         bool ok;
51         port = QCoreApplication::arguments().at(5).toInt(&ok);
52         if(ok == false){
53             port = 1700;
54         }
55         else{
56             token = QCoreApplication::arguments().at(6);
57         }
58     }
59     const char* ctoken = token.toLatin1().data();
60     if (qwm->init(port, ctoken) != 0) {
61         exit(EXIT_FAILURE);
62     }
63
64     if (qwm->requestSurface(
65             QCoreApplication::arguments().at(3).toLatin1().data()) != 0) {
66         exit(EXIT_FAILURE);
67     }
68
69     qwm->set_event_handler(QLibWindowmanager::Event_SyncDraw, [qwm](char const *label) {
70         //qwm->endDraw(label);
71         fprintf(stderr, "Surface %s got syncDraw!\n", label);
72     });
73     qwm->set_event_handler(QLibWindowmanager::Event_Active, [](char const *label) {
74         fprintf(stderr, "Surface %s got activated!\n", label);
75     });
76
77     communication comm;
78     comm.setWidth(QCoreApplication::arguments().at(1).toUInt());
79     comm.setHeight(QCoreApplication::arguments().at(2).toUInt());
80     comm.setAppName(label);
81     comm.setColor(QCoreApplication::arguments().at(4));
82
83     QQmlApplicationEngine engine;
84     engine.rootContext()->setContextProperty("COMM", &comm);
85
86     engine.load(
87         QUrl(QStringLiteral("qrc:/extra/WindowManagerSampleApp.qml")));
88     QObject *root = engine.rootObjects().first();
89     QObject::connect(root, SIGNAL(created()), qwm, SLOT(slotActivateSurface()));
90
91     return app.exec();
92 }