X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=app%2Feventhandler.cpp;fp=app%2Feventhandler.cpp;h=802b11bc38eb2720d0bb32a470aa6a9206922052;hb=fe42b81570d9730042a52d02ba8715bf75686ca0;hp=d76fcbead777cc080c51a8efb4e839181cf1eecc;hpb=fe3d069d19d4c11c9d905da1d4412a77295a438d;p=apps%2Fonscreenapp.git diff --git a/app/eventhandler.cpp b/app/eventhandler.cpp index d76fcbe..802b11b 100644 --- a/app/eventhandler.cpp +++ b/app/eventhandler.cpp @@ -26,28 +26,22 @@ #include "eventhandler.h" +const char _myrole[] = "on_screen"; const char _parameter[] = "parameter"; const char _replyto[] = "replyto"; -const char _data[] = "data"; -const char _file[] = "file"; -const char _area[] = "area"; -const char _suffix[] = ".qml"; const char _button_name[] = "buttonName"; -const char _button_press_mode[] = "buttonPressMode"; -const char _button_press_state[] = "buttonPressState"; const char _drawing_name[] = "drawing_name"; const char _application_id[] = "application_id"; -const char _onscreen_directory[] = "/usr/lib/qt5/qml/AGL/OnScreen/"; + void* EventHandler::myThis = 0; EventHandler::EventHandler(QObject *parent) : QObject(parent), mp_hs(nullptr), - mp_wm(nullptr) + mp_wm(nullptr), + m_dsp_sts(false) { - m_dspreq = QString(""); - m_req.clear(); } EventHandler::~EventHandler() @@ -68,35 +62,29 @@ void EventHandler::init(int port, const char *token) mp_hs = new LibHomeScreen(); mp_hs->init(port, token); - + mp_hs->registerCallback(nullptr, EventHandler::onRep_static); mp_hs->set_event_handler(LibHomeScreen::Event_ShowWindow, [this](json_object *object){ - // {"id": "onscreenXXX", "parameter": {"file": "onsreen file path", "data": {"key": "value", ...}}, "replyto": "app's id"} + /* + { + "application_id": "onscreenapp", + "parameter": { + "title": "onscreen title", + "type": "critical,exclamation,question,information", + "contents": "message contents", + "buttons": ["button_name1", "button_name2", "button_name3"], + "replyto":"caller application id" + } + } */ HMI_DEBUG(APP_ID, "recived json message is[%s]", json_object_get_string(object)); struct json_object *param; - json_object_object_get_ex(object, _parameter, ¶m); - if(json_object_get_type(param) != json_type_object ) { + if(!json_object_object_get_ex(object, _parameter, ¶m) + || json_object_get_type(param) != json_type_object) { HMI_DEBUG(APP_ID, "parameter error!"); return; } - struct json_object *qml_path; - const char *file = nullptr; - if(json_object_object_get_ex(param, _file, &qml_path)) - file = json_object_get_string(qml_path); - if(file == nullptr) { - HMI_DEBUG(APP_ID, "received qml file is null!"); - return; - } - - QString qml_file = QString(_onscreen_directory) + file; - QFileInfo file_info(qml_file); - if(!file_info.isFile() || !qml_file.contains(QString(_suffix), Qt::CaseSensitive)) { - HMI_DEBUG(APP_ID, "received qml file error! file=%s.", file); - return; - } - struct json_object *replyid; const char *replyto = nullptr; if(json_object_object_get_ex(param, _replyto, &replyid)) @@ -105,61 +93,46 @@ void EventHandler::init(int port, const char *token) HMI_DEBUG(APP_ID, "received replyto is null!"); return; } + m_req = qMakePair(QString(replyto), QString(json_object_to_json_string(param))); - struct json_object *display_area; - const char *area = nullptr; - if(json_object_object_get_ex(param, _area, &display_area)) - area = json_object_get_string(display_area); - - struct json_object *param_data; - const char* data = nullptr; - if(json_object_object_get_ex(param, _data, ¶m_data)) - data = json_object_to_json_string(param_data); - - m_dspreq = QString(replyto); - if(m_req.contains(m_dspreq)) { - m_req[m_dspreq] = qMakePair(qml_file, QString(data)); + if (this->getDisplayStatus() == HIDING) { + this->activateWindow(_myrole, "on_screen"); + } + else if(this->getDisplayStatus() == SHOWING) { + this->setDisplayStatus(SWAPPING); + emit this->hideOnScreen(); + } + else { + HMI_DEBUG(APP_ID, "onscreen swapping!"); } - else - m_req.insert(QString(m_dspreq), qMakePair(qml_file, QString(data))); - - if(area == nullptr) - this->activateWindow(ROLE_NAME); - else - this->activateWindow(ROLE_NAME, area); - HMI_DEBUG(APP_ID, "received showWindow event, end!, line=%d", __LINE__); }); mp_hs->set_event_handler(LibHomeScreen::Event_HideWindow, [this](json_object *object){ - struct json_object *value; - json_object_object_get_ex(object, _application_id, &value); - const char *appid = json_object_get_string(value); - HMI_DEBUG(APP_ID, "request release onScreen application is %s!", appid); - - // onscreenapp only can release by application which request show - if (appid == m_dspreq) - this->deactivateWindow(); - else - HMI_DEBUG(APP_ID, "request hideWindow application isn't request displaying application, m_dspreq=%s", m_dspreq.toStdString().c_str()); + emit this->hideOnScreen(); + HMI_DEBUG(APP_ID, "hideWindow json_object=%s", json_object_get_string(object)); }); - if (mp_wm->requestSurface(ROLE_NAME) != 0) { + if (mp_wm->requestSurface(_myrole) != 0) { HMI_DEBUG(APP_ID, "!!!!LayoutHandler requestSurface Failed!!!!!"); exit(EXIT_FAILURE); } mp_wm->set_event_handler(QLibWindowmanager::Event_SyncDraw, [this](json_object *object) { - HMI_DEBUG(APP_ID, "Surface %s got syncDraw!", ROLE_NAME); - emit this->signalLoader(QVariant("file://" + m_req[m_dspreq].first)); - emit this->signalOnScreenParameter(QVariant(m_req[m_dspreq].second)); - this->mp_wm->endDraw(QString(ROLE_NAME)); + HMI_DEBUG(APP_ID, "Surface %s got syncDraw!", _myrole); + this->mp_wm->endDraw(QString(_myrole)); }); mp_wm->set_event_handler(QLibWindowmanager::Event_Visible, [this](json_object *object) { struct json_object *value; json_object_object_get_ex(object, _drawing_name, &value); const char *name = json_object_get_string(value); + if(!strcasecmp(_myrole, name)){ + this->setDisplayStatus(SHOWING); + this->m_dsp = this->m_req; + this->updateModel(QVariant(this->m_dsp.second)); + emit this->showOnScreen(); + } HMI_DEBUG(APP_ID, "Event_Visible kKeyDrawingName = %s", name); }); @@ -195,24 +168,24 @@ void EventHandler::activateWindow(const char *role, const char *area) void EventHandler::deactivateWindow() { HMI_DEBUG(APP_ID, "EventHandler::deactivateWindow()"); - - emit this->signalLoader(QVariant("")); - mp_wm->deactivateWindow(ROLE_NAME); + if(getDisplayStatus() == SWAPPING) { + setDisplayStatus(SHOWING); + m_dsp = m_req; + updateModel(QVariant(this->m_dsp.second)); + emit showOnScreen(); + } + else { + this->setDisplayStatus(HIDING); + mp_wm->deactivateWindow(_myrole); + } } -void EventHandler::onScreenReply(const QString &btn_name, const QString &press_mode, const QString &press_state) +void EventHandler::onScreenReply(const QString &btn_name) { - HMI_DEBUG(APP_ID, "EventHandler::onScreenReply()"); -// deactivateWindow(); - - struct json_object* j_obj = json_object_new_object(); - json_object_object_add(j_obj, _application_id, json_object_new_string(m_dspreq.toLatin1())); + HMI_DEBUG(APP_ID, "EventHandler::onScreenReply(),btn_name=%s", btn_name.toStdString().c_str()); + emit this->hideOnScreen(); struct json_object* j_param = json_object_new_object(); json_object_object_add(j_param, _button_name, json_object_new_string(btn_name.toStdString().c_str())); - json_object_object_add(j_param, _button_press_mode, json_object_new_string(press_mode.toStdString().c_str())); - json_object_object_add(j_param, _button_press_state, json_object_new_string(press_state.toStdString().c_str())); - json_object_object_add(j_obj, _parameter, j_param); - - mp_hs->replyShowWindow(m_dspreq.toLatin1(), j_obj); + mp_hs->replyShowWindow(m_dsp.first.toStdString().c_str(), j_param); }