diff options
author | sebastien baudouin <sebastien.baudouin@windriver.com> | 2015-04-10 14:17:00 +0200 |
---|---|---|
committer | sebastien baudouin <sebastien.baudouin@windriver.com> | 2015-04-16 13:25:16 +0200 |
commit | f03f6810c1860a9dc945a2fb3e0f2921a855fa42 (patch) | |
tree | f17278e9c62892b1646e35167e4d5a4972deb462 | |
parent | 3955d0dd4a544577f812854ef333ddb80dbc177f (diff) | |
download | genivi-demo-platform-hmi-f03f6810c1860a9dc945a2fb3e0f2921a855fa42.tar.gz |
Launcher2: Implement last User Mode
this commit implement last user mode for launcher.
The application will save the last started Application and will restart it the
next boot time. The mechanism rely on persistent data and Node State Management
frameworks.
-rwxr-xr-x | app/gdp-hmi-launcher2/content/ListItem.qml | 4 | ||||
-rw-r--r-- | app/gdp-hmi-launcher2/gdp-hmi-launcher2.cpp | 91 | ||||
-rw-r--r-- | app/gdp-hmi-launcher2/gdp-hmi-launcher2.h | 19 | ||||
-rw-r--r-- | app/gdp-hmi-launcher2/gdp-hmi-launcher2.pro | 2 | ||||
-rwxr-xr-x | app/gdp-hmi-launcher2/gdp-hmi-launcher2.qml | 28 | ||||
-rwxr-xr-x | app/gdp-hmi-launcher2/main.cpp | 14 |
6 files changed, 152 insertions, 6 deletions
diff --git a/app/gdp-hmi-launcher2/content/ListItem.qml b/app/gdp-hmi-launcher2/content/ListItem.qml index bfa63bf..4dcc978 100755 --- a/app/gdp-hmi-launcher2/content/ListItem.qml +++ b/app/gdp-hmi-launcher2/content/ListItem.qml @@ -56,8 +56,10 @@ Item { anchors.fill: parent onClicked: { if (isSelected) { + //Save the index for Last User Mode + GDPLauncher2.setLastAppIndex(model.index); // Open the item - mainView.appSelectSignal(model.unit) + mainView.appSelectSignal(model.unit); } else { pathView.currentIndex = model.index; } diff --git a/app/gdp-hmi-launcher2/gdp-hmi-launcher2.cpp b/app/gdp-hmi-launcher2/gdp-hmi-launcher2.cpp index 84bccff..a79172a 100644 --- a/app/gdp-hmi-launcher2/gdp-hmi-launcher2.cpp +++ b/app/gdp-hmi-launcher2/gdp-hmi-launcher2.cpp @@ -32,15 +32,23 @@ DLT_IMPORT_CONTEXT(launcherTraceCtx); #include <systemd/sd-journal.h> #endif + #include "gdp-hmi-launcher2.h" static const char *GDP_HMI_PID_FILENAME = "/var/run/gdp-hmi-controller.pid"; static const char *GDP_DBUS_SERVICE_NAME = "org.genivi.gdp.hmi.controller"; static const char *GDP_DBUS_SERVICE_PATH = "/org/genivi/gdp/hmi/controller"; +#define GDP_LAUNCHER2_LAST_APP_UNIT_DB_ID 0xFF +#define GDP_LAUNCHER2_LAST_APP_UNIT_KEY "LastAppIndex" +#define GDP_LAUNCHER2_USER 3 +#define GDP_LAUNCHER2_SEAT 2 +#define GDP_LAUNCHER2_INDEX_MAX 0xFF + GDPLauncherClass::GDPLauncherClass() : m_hmiControllerPid(-1) { + int pcl_return; #ifdef USE_DLT DLT_LOG(launcherTraceCtx,DLT_LOG_INFO,DLT_STRING("Debug: GDPLauncherClass - dbus session.\n")); #else @@ -49,10 +57,93 @@ GDPLauncherClass::GDPLauncherClass() m_controller = new org::genivi::gdp::HMI_Controller(GDP_DBUS_SERVICE_NAME, GDP_DBUS_SERVICE_PATH, QDBusConnection::sessionBus(), this); m_timerId = startTimer(5000); // 5 second timer + + /* Initialize Persistence Client Library */ + pcl_return = pclInitLibrary("Launcher", PCL_SHUTDOWN_TYPE_NORMAL | PCL_SHUTDOWN_TYPE_FAST); + if (pcl_return < 0) { +#ifdef USE_DLT + DLT_LOG(launcherTraceCtx, DLT_LOG_INFO, + DLT_STRING("Launcher2: Failed to initialize PCL."); + DLT_STRING("Error: Unexpected PCL return."); + DLT_STRING("Return:"); DLT_INT(pcl_return)); +#else + sd_journal_print(LOG_DEBUG, "Launcher2: Failed to initialize PCL\n"); +#endif + return; + } } GDPLauncherClass::~GDPLauncherClass() { + int pcl_return; + + /* Deinitialize the PCL */ + pcl_return = pclDeinitLibrary(); + + if (pcl_return < 0) { +#ifdef USE_DLT + DLT_LOG(launcherTraceCtx, DLT_LOG_INFO, + DLT_STRING("Launcher2: Failed to deinitialize PCL."); + DLT_STRING("Error: Unexpected PCL return."); + DLT_STRING("Return:"); DLT_INT(pcl_return)); +#else + sd_journal_print(LOG_DEBUG, "Launcher2: Failed to deinitialize PCL.\n"); +#endif + } +} + +int GDPLauncherClass::readLastUserAppIndex() +{ + int pcl_return; + unsigned char value[8]; + /* Get data from persistence */ + + pcl_return = pclKeyReadData(GDP_LAUNCHER2_LAST_APP_UNIT_DB_ID, + GDP_LAUNCHER2_LAST_APP_UNIT_KEY, + GDP_LAUNCHER2_USER, + GDP_LAUNCHER2_SEAT, + value, + sizeof(value)); + if (pcl_return != sizeof(value)) { +#ifdef USE_DLT + DLT_LOG(launcherTraceCtx, DLT_LOG_INFO, + DLT_STRING("Launcher2: Failed to read Last Application Unit."); + DLT_STRING("Error: Unexpected PCL return."); + DLT_STRING("Return:"); DLT_INT(pcl_return)); +#else + sd_journal_print(LOG_DEBUG, "Launcher2: Failed to read Last Application Unit.\n"); +#endif + return GDP_LAUNCHER2_INDEX_MAX; + } + + return atoi((char*)value); +} + + +void GDPLauncherClass::writeLastUserAppIndex(int index) +{ + int pcl_return; + unsigned char value[8]; + + sprintf((char*)value, "%d", index); + /* Set data to persistence */ + + pcl_return = pclKeyWriteData(GDP_LAUNCHER2_LAST_APP_UNIT_DB_ID, + GDP_LAUNCHER2_LAST_APP_UNIT_KEY, + GDP_LAUNCHER2_USER, + GDP_LAUNCHER2_SEAT, + value, + sizeof(value)); + if (pcl_return != sizeof(value)) { +#ifdef USE_DLT + DLT_LOG(launcherTraceCtx, DLT_LOG_INFO, + DLT_STRING("Launcher2: Failed to write Last Application Unit."); + DLT_STRING("Error: Unexpected PCL return."); + DLT_STRING("Return:"); DLT_INT(pcl_return)); +#else + sd_journal_print(LOG_DEBUG, "Launcher2: Failed to write Last Application Unit.\n"); +#endif + } } void GDPLauncherClass::timerEvent(QTimerEvent *event) diff --git a/app/gdp-hmi-launcher2/gdp-hmi-launcher2.h b/app/gdp-hmi-launcher2/gdp-hmi-launcher2.h index d13e91b..f10b7ca 100644 --- a/app/gdp-hmi-launcher2/gdp-hmi-launcher2.h +++ b/app/gdp-hmi-launcher2/gdp-hmi-launcher2.h @@ -28,6 +28,9 @@ #include <sys/types.h> #include <systemd/sd-journal.h> +#include <persistence_client_library.h> /* Init/DeInit PCL */ +#include <persistence_client_library_key.h> /* Access persistent data */ + #include "gdp-hmi-introspect_interface.h" class GDPLauncherClass : public QObject @@ -37,6 +40,21 @@ class GDPLauncherClass : public QObject public: GDPLauncherClass(); ~GDPLauncherClass(); + int readLastUserAppIndex(); + void writeLastUserAppIndex(int index); + + Q_INVOKABLE int getLastAppIndex() { + m_selectedAppIndex = readLastUserAppIndex(); + return m_selectedAppIndex; + } + + Q_INVOKABLE void setLastAppIndex(int index) { + if (index != m_selectedAppIndex) { + m_selectedAppIndex = index; + } + writeLastUserAppIndex(m_selectedAppIndex); + } + public slots: void hmiRequestOffSlot() { @@ -59,6 +77,7 @@ protected: private: pid_t m_hmiControllerPid; int m_timerId; + int m_selectedAppIndex; org::genivi::gdp::HMI_Controller *m_controller; }; diff --git a/app/gdp-hmi-launcher2/gdp-hmi-launcher2.pro b/app/gdp-hmi-launcher2/gdp-hmi-launcher2.pro index a98ecc1..6478c1b 100644 --- a/app/gdp-hmi-launcher2/gdp-hmi-launcher2.pro +++ b/app/gdp-hmi-launcher2/gdp-hmi-launcher2.pro @@ -39,7 +39,7 @@ QML_IMPORT_PATH = # enable C standard as published in 2011 as ISO/IEC 9899:2011 (known as C11) CONFIG += c++11 -LIBS += -lsystemd -ldlt +LIBS += -lpersistence_client_library -lsystemd -ldlt target.path = /usr/bin diff --git a/app/gdp-hmi-launcher2/gdp-hmi-launcher2.qml b/app/gdp-hmi-launcher2/gdp-hmi-launcher2.qml index caf764c..f9a58af 100755 --- a/app/gdp-hmi-launcher2/gdp-hmi-launcher2.qml +++ b/app/gdp-hmi-launcher2/gdp-hmi-launcher2.qml @@ -23,10 +23,30 @@ Item { width: 1024 height: 768 + property int lastIndex: GDPLauncher2.getLastAppIndex(); signal appSelectSignal(string unit) signal requestOffSignal() + Timer { + id: timer + interval: 1000; running: false; + onTriggered: mainView.appSelectSignal(listModel.get(mainView.lastIndex).unit) + } + + Component.onCompleted: { + if (mainView.lastIndex < pathView.count) { + //We have a valid Index so let's process it + + //First postion the list to right Application + pathView.positionViewAtIndex(mainView.lastIndex, ListView.Beginning); + + //Now let's start the Application + timer.running = true + } + } + + QtObject { id: settings property real spotAnimationPosition: 0.0 @@ -120,7 +140,9 @@ Item { source: "file://usr/share/gdp/arrow-right.png" MouseArea { anchors.fill: parent - onClicked: pathView.incrementCurrentIndex() + onClicked: { + pathView.incrementCurrentIndex() + } } } @@ -133,7 +155,9 @@ Item { source: "file://usr/share/gdp/arrow-right.png" MouseArea { anchors.fill: parent - onClicked: pathView.decrementCurrentIndex() + onClicked: { + pathView.decrementCurrentIndex(); + } } } diff --git a/app/gdp-hmi-launcher2/main.cpp b/app/gdp-hmi-launcher2/main.cpp index 22099f3..8a399bd 100755 --- a/app/gdp-hmi-launcher2/main.cpp +++ b/app/gdp-hmi-launcher2/main.cpp @@ -17,6 +17,7 @@ #include <QGuiApplication> #include <QQuickView> #include <QtDBus> +#include <QQmlContext> #ifdef USE_DLT #include <dlt/dlt.h> @@ -49,21 +50,30 @@ int main(int argc, char* argv[]) QObject *object; QGuiApplication app(argc,argv); + GDPLauncherClass launcher2; + QQuickView view; - QQuickView view(QUrl(QStringLiteral("qrc:/gdp-hmi-launcher2.qml"))); + //Update QML GDPLauncher2 property + view.rootContext()->setContextProperty("GDPLauncher2", &launcher2); + //Load the QML file + view.setSource(QUrl(QStringLiteral("qrc:/gdp-hmi-launcher2.qml"))); view.setResizeMode(QQuickView::SizeRootObjectToView); object = (QObject *)view.rootObject(); - GDPLauncherClass launcher2; + //Connect signal and slot QObject::connect(object, SIGNAL(appSelectSignal(QString)), &launcher2, SLOT(hmiAppLaunchSlot(QString))); QObject::connect(object, SIGNAL(requestOffSignal()), &launcher2, SLOT(hmiRequestOffSlot())); + //Set Surface property value for controller view.setProperty("IVI-Surface-ID", GDP_LAUNCHER2_SURFACE_ID); + + //let's show the view view.showFullScreen(); + //let's start the App ret = app.exec(); #ifdef USE_DLT |