2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <QJsonDocument>
20 #include <QJsonObject>
21 #include <QQuickWindow>
22 #include <QtQml/QQmlContext>
23 #include "eventhandler.h"
25 void* EventHandler::myThis = 0;
27 EventHandler::EventHandler(QObject *parent) :
36 EventHandler::~EventHandler()
46 void EventHandler::init(int port, const char *token)
49 mp_wm = new QLibWindowmanager();
50 mp_wm->init(port, token);
52 mp_hs = new QLibHomeScreen();
53 mp_hs->init(port, token);
55 mp_hs->set_event_handler(QLibHomeScreen::Event_TapShortcut, [this](json_object *object){
56 this->mp_wm->activateWindow(ROLE_NAME);
57 HMI_DEBUG(APP_ID, "received showWindow event, end!, line=%d", __LINE__);
60 mp_hs->set_event_handler(QLibHomeScreen::Event_ReplyShowWindow, [this](json_object *object){
61 HMI_DEBUG(APP_ID, "got Event_ReplyShowWindow!\n");
62 const char* msg = json_object_to_json_string(object);
63 emit this->signalOnReplyShowWindow(msg);
66 if (mp_wm->requestSurface(ROLE_NAME) != 0) {
67 HMI_DEBUG(APP_ID, "!!!!LayoutHandler requestSurface Failed!!!!!");
71 // Create an event callback against an event type. Here a lambda is called when SyncDraw event occurs
72 mp_wm->set_event_handler(QLibWindowmanager::Event_SyncDraw, [this](json_object *object) {
73 HMI_DEBUG(APP_ID, "Surface got syncDraw!");
74 this->mp_wm->endDraw(ROLE_NAME);
77 mp_wm->set_event_handler(QLibWindowmanager::Event_Visible, [this](json_object *object) {
78 struct json_object *value;
79 json_object_object_get_ex(object, "drawing_name", &value);
80 const char *name = json_object_get_string(value);
82 HMI_DEBUG(APP_ID, "Event_Active kKeyDrawingName = %s", name);
85 mp_wm->set_event_handler(QLibWindowmanager::Event_Invisible, [this](json_object *object) {
86 struct json_object *value;
87 json_object_object_get_ex(object, "drawing_name", &value);
88 const char *name = json_object_get_string(value);
90 HMI_DEBUG(APP_ID, "Event_Inactive kKeyDrawingName = %s", name);
93 HMI_DEBUG(APP_ID, "LayoutHander::init() finished.");
96 void EventHandler::setQuickWindow(QQuickWindow *qw)
99 QObject::connect(mp_qw, SIGNAL(frameSwapped()), mp_wm, SLOT(slotActivateSurface()));
102 void EventHandler::showWindow(QString id, QString json)
105 mp_hs->tapShortcut(id);
107 mp_hs->showWindow(id.toStdString().c_str(), json_tokener_parse(json.toStdString().c_str()));