X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=doc%2Fapi-ref%2Fhtml%2Fd5%2Fd49%2Feventhandler_8cpp_source.html;fp=doc%2Fapi-ref%2Fhtml%2Fd5%2Fd49%2Feventhandler_8cpp_source.html;h=6845cb11863f4767b26d75aef3efd797c8834495;hb=b2670af592e664ed304f7df77d84f1964f039636;hp=0000000000000000000000000000000000000000;hpb=ec044f44133cad1d12311345437b13b1a953226e;p=apps%2Fonscreenapp.git diff --git a/doc/api-ref/html/d5/d49/eventhandler_8cpp_source.html b/doc/api-ref/html/d5/d49/eventhandler_8cpp_source.html new file mode 100644 index 0000000..6845cb1 --- /dev/null +++ b/doc/api-ref/html/d5/d49/eventhandler_8cpp_source.html @@ -0,0 +1,96 @@ + + + + + + + +OnScreenApp: app/eventhandler.cpp Source File + + + + + + + + + +
+
+ + + + + + +
+
OnScreenApp +
+
+
+ + + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
eventhandler.cpp
+
+
+Go to the documentation of this file.
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 #include "eventhandler.h"
18 #include <functional>
19 #include <QUrl>
20 #include <QDebug>
21 #include <QJsonDocument>
22 #include <QJsonObject>
23 #include <QQuickWindow>
24 #include <QPixmap>
25 #include <QBitmap>
26 #include <QImage>
27 
28 void* EventHandler::myThis = 0;
29 #define SCREEN_AREA "OnScreen"
30 #define SCREEN_NAME "OnScreenApp"
31 
32 EventHandler::EventHandler(QObject *parent) :
33  QObject(parent),
34  mp_hs(NULL),
35  mp_wm(NULL),
36  mp_qw(NULL)
37 {
38  m_isActive = false;
39  m_vecOSM.clear();
40 }
41 
43 {
44  if (mp_hs != NULL) {
45  delete mp_hs;
46  }
47  if (mp_wm != NULL) {
48  delete mp_wm;
49  }
50 }
51 
52 void EventHandler::init(int port, const char *token)
53 {
54  myThis = this;
55  mp_wm = new QLibWindowmanager();
56  mp_wm->init(port, token);
57 
58  mp_hs = new LibHomeScreen();
59  mp_hs->init(port, token);
60 
61  mp_hs->registerCallback(nullptr, EventHandler::onRep_static);
62  mp_hs->set_event_handler(LibHomeScreen::Event_OnScreenMessage, [this](json_object *object){
63  struct json_object *value;
64  json_object_object_get_ex(object, "display_message", &value);
65  const char *display_message = json_object_get_string(value);
66 
67  HMI_DEBUG("onscreenapp", "display_message = %s", display_message);
68 
69  QString data(display_message);
70  QJsonDocument doc = QJsonDocument::fromJson(data.toUtf8());
71  QJsonObject jsonObj(doc.object());
72 
74 
75  if (jsonObj.contains("app")) {
76  HMI_DEBUG("onscreenapp", "json parse. app is %s", jsonObj["app"].toString());
77  osm.app = jsonObj["app"].toString();
78  }
79 
80  if (jsonObj.contains("message")) {
81  HMI_DEBUG("onscreenapp", "json parse. message is %s", jsonObj["message"].toString());
82  osm.message = jsonObj["message"].toString();
83  }
84 
85  if (jsonObj.contains("file")) {
86  HMI_DEBUG("onscreenapp", "json parse. file is %s", jsonObj["file"].toString());
87  osm.file = jsonObj["file"].toString();
88 
89  if (osm.file.left(1) == "/") {
90  osm.file = QUrl::fromLocalFile(osm.file).toString();
91  }
92  }
93 
94  if (jsonObj.contains("mask")) {
95  HMI_DEBUG("onscreenapp", "json parse. mask is %s", jsonObj["mask"].toString());
96  osm.mask = jsonObj["mask"].toString();
97  }
98 
99  bool isNewApp = true;
100  for(QVector<ON_SCREEN_MESSAGE>::iterator it = m_vecOSM.begin(); it != m_vecOSM.end(); ++it) {
101  if (it->app == osm.app) {
102  it->message = osm.message;
103  it->file = osm.file;
104  it->mask = osm.mask;
105  isNewApp = false;
106  break;
107  }
108  }
109 
110  if (isNewApp) {
111  m_vecOSM.append(osm);
112  }
113 
114  if (osm.app == "Phone") {
115  if (osm.message == "incoming call") {
116  this->activateSurface(osm.app);
117  emit this->signalLoader(osm.file);
118  emit this->signalSetClearBackgroud();
119  }
120  else if (osm.message == "call rejected") {
121  this->deactivateSurface(osm.app);
122  }
123  }
124  else if (osm.app == "System") {
125  if (osm.message == "error") {
126  this->activateSurface(osm.app);
127  emit this->signalLoader(osm.file);
128  emit this->signalSetClearBackgroud();
129  }
130  else if (osm.message == "rejected") {
131  this->deactivateSurface(osm.app);
132  }
133  }
134 
135 // this->setWindowMask(jsonObj["mask"].toString());
136 
137 // if(strcmp(display_message, "incoming call") == 0){
138 // this->activateSurface();
139 // emit this->signalOnScreenMessage(display_message);
140 // }
141 // else if(strcmp(display_message, "call rejected") == 0){
142 // this->deactivateSurface();
143 // }
144 // else if(strcmp(display_message, "page1") == 0) {
145 // emit this->signalLoader("qrc:/page1.qml");
146 // }
147 // else if(strcmp(display_message, "page2") == 0) {
148 // emit this->signalLoader("qrc:/page2.qml");
149 // }
150 // else if(strcmp(display_message, "page3") == 0) {
151 // emit this->signalLoader(QUrl::fromLocalFile("/home/root/page3.qml"));
152 // }
153 // else{
154 // emit this->signalOnScreenMessage(display_message);
155 // }
156  });
157 
158  if (mp_wm->requestSurface(SCREEN_NAME) != 0) {
159  HMI_DEBUG("onscreenapp", "!!!!LayoutHandler requestSurface Failed!!!!!");
160  exit(EXIT_FAILURE);
161  }
162 
163  mp_wm->set_event_handler(QLibWindowmanager::Event_SyncDraw, [this](json_object *object) {
164  HMI_DEBUG("onscreenapp", "Surface %s got syncDraw!", SCREEN_NAME);
165  this->mp_wm->endDraw(SCREEN_NAME);
166  });
167 
168  mp_wm->set_event_handler(QLibWindowmanager::Event_Active, [this](json_object *object) {
169  struct json_object *value;
170  json_object_object_get_ex(object, "drawing_name", &value);
171  const char *name = json_object_get_string(value);
172 
173  HMI_DEBUG("onscreenapp", "Event_Active kKeyDrawingName = %s", name);
174  });
175 
176  mp_wm->set_event_handler(QLibWindowmanager::Event_Inactive, [this](json_object *object) {
177  struct json_object *value;
178  json_object_object_get_ex(object, "drawing_name", &value);
179  const char *name = json_object_get_string(value);
180 
181  HMI_DEBUG("onscreenapp", "Event_Inactive kKeyDrawingName = %s", name);
182  });
183 
184  HMI_DEBUG("onscreenapp", "LayoutHander::init() finished.");
185 }
186 
187 void EventHandler::setQuickWindow(QQuickWindow *qw)
188 {
189  mp_qw = qw;
190 }
191 
192 void EventHandler::onRep_static(struct json_object* reply_contents)
193 {
194  static_cast<EventHandler*>(EventHandler::myThis)->onRep(reply_contents);
195 }
196 void EventHandler::onRep(struct json_object* reply_contents)
197 {
198  const char* str = json_object_to_json_string(reply_contents);
199  HMI_DEBUG("onscreenapp", "EventHandler::onReply %s", str);
200 }
201 
203 {
204  HMI_DEBUG("onscreenapp", "EventHandler::activateSurface()");
205  if (m_isActive == false) {
206  m_isActive = true;
207  mp_wm->activateSurface(SCREEN_NAME);
208  }
209 
210  QString label = SCREEN_AREA + app;
211  mp_wm->activateSurface(label, SCREEN_AREA);
212 }
213 
215 {
216  HMI_DEBUG("onscreenapp", "EventHandler::deactivateSurface()");
217 
218  for(QVector<ON_SCREEN_MESSAGE>::iterator it = m_vecOSM.begin(); it != m_vecOSM.end(); ++it) {
219  if (it->app == app) {
220  m_vecOSM.erase(it);
221  break;
222  }
223  }
224 
225  if (m_vecOSM.length() > 0) {
226  ON_SCREEN_MESSAGE osm = m_vecOSM.last();
227 
228  if (!osm.file.isEmpty()) {
229  emit this->signalLoader(osm.file);
230  emit this->signalSetClearBackgroud();
231  }
232  } else {
233  // nothing on screen
234  mp_wm->deactivateSurface(SCREEN_NAME);
235 // ??? mp_wm->deactivateSurface(SCREEN_AREA);
236  m_isActive = false;
237  }
238 }
239 
240 void EventHandler::onScreenReply(const QString &message)
241 {
242  HMI_DEBUG("onscreenapp", "EventHandler::onScreenReply()");
243  mp_hs->onScreenReply(message.toLatin1());
244 }
245 
246 #if USE_TEST_DISPLAY
247 void EventHandler::slotActivateSurface(){
248  // This is needed for first rendering when the app is launched
249  if(!m_isActive){
250  m_isActive = true;
251  this->activateSurface();
252  }
253 }
254 #endif
255 
256 void EventHandler::setWindowMask(QString maskfile)
257 {
258  HMI_DEBUG("onscreenapp", "EventHandler::setWindowMask()");
259  HMI_DEBUG("onscreenapp", "maskfile = %s", maskfile);
260 
261  QImage img(maskfile);
262  QPixmap mask = QPixmap::fromImage(img);
263 
264  if (mask.hasAlphaChannel()) {
265  HMI_DEBUG("onscreenapp", "input maskfile has alpha.");
266  mp_qw->setMask(mask.mask());
267  }
268  else {
269  HMI_DEBUG("onscreenapp", "!!!! maskfile does not have alpha!!!!");
270  }
271 }
+ +
#define HMI_DEBUG(prefix, args,...)
Definition: hmi-debug.h:42
+
void deactivateSurface(QString app)
+ +
void init(int port, const char *token)
+
void onRep(struct json_object *reply_contents)
+
void activateSurface(QString app)
+
void setQuickWindow(QQuickWindow *qw)
+
#define SCREEN_AREA
+
static void * myThis
Definition: eventhandler.h:53
+ +
void signalLoader(QVariant url)
+
Q_INVOKABLE void onScreenReply(const QString &message)
+ +
static void onRep_static(struct json_object *reply_contents)
+
void signalSetClearBackgroud()
+
EventHandler(QObject *parent=0)
+
#define SCREEN_NAME
+
+ + + +