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.
17 #include "homescreenhandler.h"
19 #include "hmi-debug.h"
21 void* HomescreenHandler::myThis = 0;
23 HomescreenHandler::HomescreenHandler(QObject *parent) :
26 current_applciation("launcher")
31 HomescreenHandler::~HomescreenHandler()
38 void HomescreenHandler::init(int port, const char *token)
40 mp_hs = new LibHomeScreen();
41 mp_hs->init(port, token);
45 mp_hs->registerCallback(nullptr, HomescreenHandler::onRep_static);
47 mp_hs->set_event_handler(LibHomeScreen::Event_OnScreenMessage, [this](json_object *object){
48 const char *display_message = json_object_get_string(
49 json_object_object_get(object, "display_message"));
50 HMI_DEBUG("HomeScreen","set_event_handler Event_OnScreenMessage display_message = %s", display_message);
54 void HomescreenHandler::tapShortcut(QString application_name, bool is_full)
56 HMI_DEBUG("HomeScreen","tapShortcut %s", application_name.toStdString().c_str());
57 struct json_object* j_json = json_object_new_object();
58 struct json_object* value;
60 value = json_object_new_string("fullscreen");
61 HMI_DEBUG("HomeScreen","tapShortcut fullscreen");
63 value = json_object_new_string("normal");
64 HMI_DEBUG("HomeScreen","tapShortcut normal");
66 json_object_object_add(j_json, "area", value);
67 mp_hs->showWindow(application_name.toStdString().c_str(), j_json);
70 void HomescreenHandler::setCurrentApplication(QString application_name)
72 HMI_DEBUG("HomeScreen","setCurrentApplication %s", application_name.toStdString().c_str());
73 current_applciation = application_name;
76 QString HomescreenHandler::getCurrentApplication()
78 HMI_DEBUG("HomeScreen","getCurrentApplication %s", current_applciation.toStdString().c_str());
79 return current_applciation;
82 void HomescreenHandler::onRep_static(struct json_object* reply_contents)
84 static_cast<HomescreenHandler*>(HomescreenHandler::myThis)->onRep(reply_contents);
87 void HomescreenHandler::onEv_static(const string& event, struct json_object* event_contents)
89 static_cast<HomescreenHandler*>(HomescreenHandler::myThis)->onEv(event, event_contents);
92 void HomescreenHandler::onRep(struct json_object* reply_contents)
94 const char* str = json_object_to_json_string(reply_contents);
95 HMI_DEBUG("HomeScreen","HomeScreen onReply %s", str);
98 void HomescreenHandler::onEv(const string& event, struct json_object* event_contents)
100 const char* str = json_object_to_json_string(event_contents);
101 HMI_DEBUG("HomeScreen","HomeScreen onEv %s, contents: %s", event.c_str(), str);
103 if (event.compare("homescreen/on_screen_message") == 0) {
104 struct json_object *json_data = json_object_object_get(event_contents, "data");
105 struct json_object *json_display_message = json_object_object_get(json_data, "display_message");
106 const char* display_message = json_object_get_string(json_display_message);
108 HMI_DEBUG("HomeScreen","display_message = %s", display_message);