diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-10-27 23:17:48 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-10-31 13:59:08 +0100 |
commit | f218378453cc391437efe6aa51112b12591a982e (patch) | |
tree | c794d6bc5456ea28b96b3f6f3677ed6785735857 | |
parent | ddff06a62bdb66c50645a9c56d5959bc09193d9d (diff) |
Porting to new HMI Framework
Change-Id: Ifb298e09db821dba5dc1a28ad2d1c2193c511ee9
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r-- | app/app.pri | 7 | ||||
-rw-r--r-- | app/app.pro | 6 | ||||
-rw-r--r-- | app/main.cpp | 58 | ||||
-rw-r--r-- | app/qlibwindowmanager.cpp | 81 | ||||
-rw-r--r-- | app/qlibwindowmanager.h | 72 | ||||
-rw-r--r-- | package/config.xml | 4 |
6 files changed, 203 insertions, 25 deletions
diff --git a/app/app.pri b/app/app.pri index 014646f..e535cbc 100644 --- a/app/app.pri +++ b/app/app.pri @@ -1,12 +1,5 @@ TEMPLATE = app load(configure) -qtCompileTest(libhomescreen) - -config_libhomescreen { - CONFIG += link_pkgconfig - PKGCONFIG += homescreen - DEFINES += HAVE_LIBHOMESCREEN -} DESTDIR = $${OUT_PWD}/../package/root/bin diff --git a/app/app.pro b/app/app.pro index 2c81b9f..62d547e 100644 --- a/app/app.pro +++ b/app/app.pro @@ -1,7 +1,11 @@ TARGET = hvac QT = quickcontrols2 -SOURCES = main.cpp +HEADERS = qlibwindowmanager.h +SOURCES = main.cpp qlibwindowmanager.cpp + +CONFIG += link_pkgconfig +PKGCONFIG += libhomescreen libwindowmanager RESOURCES += \ hvac.qrc \ diff --git a/app/main.cpp b/app/main.cpp index b532b73..ca527e6 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -21,24 +21,16 @@ #include <QtQml/QQmlApplicationEngine> #include <QtQml/QQmlContext> #include <QtQuickControls2/QQuickStyle> - -#ifdef HAVE_LIBHOMESCREEN +#include <QQuickWindow> #include <libhomescreen.hpp> -#endif +#include "qlibwindowmanager.h" int main(int argc, char *argv[]) { -#ifdef HAVE_LIBHOMESCREEN - LibHomeScreen libHomeScreen; - - if (!libHomeScreen.renderAppToAreaAllowed(0, 1)) { - qWarning() << "renderAppToAreaAllowed is denied"; - return -1; - } -#endif + std::string myname = std::string("HVAC"); QGuiApplication app(argc, argv); - app.setApplicationName(QStringLiteral("HVAC")); + app.setApplicationName(myname.c_str()); app.setApplicationVersion(QStringLiteral("0.1.0")); app.setOrganizationDomain(QStringLiteral("automotivelinux.org")); app.setOrganizationName(QStringLiteral("AutomotiveGradeLinux")); @@ -53,7 +45,6 @@ int main(int argc, char *argv[]) parser.process(app); QStringList positionalArguments = parser.positionalArguments(); - QQmlApplicationEngine engine; if (positionalArguments.length() == 2) { int port = positionalArguments.takeFirst().toInt(); @@ -68,9 +59,46 @@ int main(int argc, char *argv[]) bindingAddress.setQuery(query); QQmlContext *context = engine.rootContext(); context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress); - } - engine.load(QUrl(QStringLiteral("qrc:/HVAC.qml"))); + std::string token = secret.toStdString(); + LibHomeScreen* hs = new LibHomeScreen(); + QLibWindowmanager* qwm = new QLibWindowmanager(); + + // WindowManager + if(qwm->init(port,secret) != 0){ + exit(EXIT_FAILURE); + } + if (qwm->requestSurface(json_object_new_string(myname.c_str())) != 0) { + exit(EXIT_FAILURE); + } + qwm->set_event_handler(QLibWindowmanager::Event_SyncDraw, [qwm, myname](json_object *object) { + fprintf(stderr, "Surface got syncDraw!\n"); + qwm->endDraw(json_object_new_string(myname.c_str())); + }); + + // HomeScreen + hs->init(port, token.c_str()); + hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [qwm, myname](json_object *object){ + qDebug("object %s", json_object_to_json_string(object)); + json_object *appnameJ = nullptr; + if(json_object_object_get_ex(object, "application_name", &appnameJ)) + { + const char *appname = json_object_get_string(appnameJ); + qDebug("appnameJ %s", json_object_to_json_string(appnameJ)); + if(myname == appname) + { + qDebug("Surface %s got tapShortcut\n", appname); + qwm->activateSurface(json_object_new_string(myname.c_str())); + } + } + }); + + engine.load(QUrl(QStringLiteral("qrc:/HVAC.qml"))); + QObject *root = engine.rootObjects().first(); + QQuickWindow *window = qobject_cast<QQuickWindow *>(root); + QObject::connect(window, SIGNAL(frameSwapped()), qwm, SLOT(slotActivateSurface() + )); + } return app.exec(); } diff --git a/app/qlibwindowmanager.cpp b/app/qlibwindowmanager.cpp new file mode 100644 index 0000000..370f9f7 --- /dev/null +++ b/app/qlibwindowmanager.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2017 TOYOTA MOTOR CORPORATION + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "qlibwindowmanager.h" +#include <QDebug> +#include <unistd.h> + +int QLibWindowmanager::init(int port, const QString &token) { + std::string ctoken = token.toStdString(); + return this->wm->init(port, ctoken.c_str()); +} + +int QLibWindowmanager::requestSurface(json_object *label) { + applabel = json_object_get_string(label); + + json_object *obj = json_object_new_object(); + json_object_object_add(obj, wm->kKeyDrawingName, label); + return this->wm->requestSurface(obj); +} + +int QLibWindowmanager::activateSurface(json_object *label) { + qDebug() << "activateSurface applabel: " << applabel.c_str(); + json_object *obj = json_object_new_object(); + qDebug() << "DrawingName: " << wm->kKeyDrawingName; + json_object_object_add(obj, wm->kKeyDrawingName, label); + qDebug() << "DrawingArea: " << wm->kKeyDrawingArea; + json_object_object_add(obj, wm->kKeyDrawingArea, json_object_new_string("normal.full")); + qDebug() << "obj pointer: " << obj; + qDebug() << "activateSurface end obj: " << json_object_get_string(obj); + + return this->wm->activateSurface(obj); +} + +int QLibWindowmanager::deactivateSurface(json_object *label) { + json_object *obj = json_object_new_object(); + json_object_object_add(obj, wm->kKeyDrawingName, label); + return this->wm->deactivateSurface(obj); +} + +int QLibWindowmanager::endDraw(json_object *label) { + json_object *obj = json_object_new_object(); + qDebug() << "endDraw label: " << json_object_get_string(label); + json_object_object_add(obj, wm->kKeyDrawingName, label); + return this->wm->endDraw(obj); + } + +void QLibWindowmanager::set_event_handler(enum QEventType et, + handler_fun f) { + LibWindowmanager::EventType wet = (LibWindowmanager::EventType)et; + return this->wm->set_event_handler(wet, std::move(f)); +} + +void QLibWindowmanager::slotActivateSurface(){ + if(!isActive){ + qDebug("Let's show HVAC"); + isActive = true; + qDebug() << "slotActivateSurface applabel: " << applabel.c_str(); + this->activateSurface(json_object_new_string(applabel.c_str())); + } +} + +QLibWindowmanager::QLibWindowmanager(QObject *parent) + :QObject(parent), isActive(false) +{ + wm = new LibWindowmanager(); +} + +QLibWindowmanager::~QLibWindowmanager() { } diff --git a/app/qlibwindowmanager.h b/app/qlibwindowmanager.h new file mode 100644 index 0000000..07f8479 --- /dev/null +++ b/app/qlibwindowmanager.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2017 TOYOTA MOTOR CORPORATION + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef QLIBWINDOWMANAGER_H +#define QLIBWINDOWMANAGER_H + +#include <libwindowmanager.h> +#include <functional> +#include <QObject> +#include <QUrl> +#include <QVariant> +#include <string> +#include <vector> + +class QLibWindowmanager : public QObject{ +Q_OBJECT +public: + explicit QLibWindowmanager(QObject *parent = nullptr); + ~QLibWindowmanager(); + + QLibWindowmanager(const QLibWindowmanager &) = delete; + QLibWindowmanager &operator=(const QLibWindowmanager &) = delete; + +public: + using handler_fun = std::function<void(json_object *object)>; + + enum QEventType { + Event_Active = 0, + Event_Inactive, + + Event_Visible, + Event_Invisible, + + Event_SyncDraw, + Event_FlushDraw, + }; + + static QLibWindowmanager &instance(); + + int init(int port, const QString &token); + + // WM API + int requestSurface(json_object *label); + int activateSurface(json_object *label); + int deactivateSurface(json_object *label); + int endDraw(json_object *label); + void set_event_handler(enum QEventType et, handler_fun f); + +public slots: + void slotActivateSurface(); + +private: + LibWindowmanager* wm; + std::string applabel; + std::vector<int> surfaceIDs; + bool isActive; + +}; +#endif // LIBWINDOWMANAGER_H diff --git a/package/config.xml b/package/config.xml index a576945..9748f0b 100644 --- a/package/config.xml +++ b/package/config.xml @@ -7,11 +7,11 @@ <author>Romain Forlot <romain.forlot@iot.bzh></author> <license>APL 2.0</license> <feature name="urn:AGL:widget:required-api"> + <param name="windowmanager" value="ws" /> + <param name="homescreen" value="ws" /> <param name="lib/libhvac-demo-binding.so" value="local" /> </feature> <feature name="urn:AGL:widget:required-permission"> <param name="urn:AGL:permission::public:no-htdocs" value="required" /> </feature> </widget> - - |