Index: copyright =================================================================== diff -u -rde1bbf5330f415cd5bae1c0f73d58efe11e9f06d -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d --- copyright (.../copyright) (revision de1bbf5330f415cd5bae1c0f73d58efe11e9f06d) +++ copyright (.../copyright) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -1,10 +1,10 @@ /*! * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. - * \copyright \n - * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, \n - * IN PART OR IN WHOLE, \n - * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. \n + * \copyright + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, + * IN PART OR IN WHOLE, + * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file %FILENAME% * \date %DATE% Index: denali.pro =================================================================== diff -u -rc8738a653871153a32d0f960ffbb1f0dded6673b -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d --- denali.pro (.../denali.pro) (revision c8738a653871153a32d0f960ffbb1f0dded6673b) +++ denali.pro (.../denali.pro) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -1,68 +1,74 @@ -QT += quick -CONFIG += c++14 -Wall - -# The following define makes your compiler emit warnings if you use -# any Qt feature that has been marked deprecated (the exact warnings -# depend on your compiler). Refer to the documentation for the -# deprecated API to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if it uses deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -INCLUDEPATH += \ - sources \ - sources/storage \ - sources/gui - -HEADERS += \ - sources/applicationcontroller.h \ - sources/applicationpost.h \ - sources/canbus/canbus.h \ - sources/configuration/display.h \ - sources/configuration/sound.h \ - sources/gui/guiactions.h \ - sources/gui/guiview.h \ - sources/gui/guicontroller.h \ - sources/maintimer.h \ - sources/storage/filehandler.h \ - sources/storage/logger.h \ - sources/storage/settings.h - -SOURCES += \ - main.cpp \ - sources/applicationcontroller.cpp \ - sources/applicationpost.cpp \ - sources/canbus/canbus.cpp \ - sources/configuration/display.cpp \ - sources/configuration/sound.cpp \ - sources/gui/guiactions.cpp \ - sources/gui/guiview.cpp \ - sources/gui/guicontroller.cpp \ - sources/maintimer.cpp \ - sources/storage/filehandler.cpp \ - sources/storage/logger.cpp \ - sources/storage/settings.cpp - -RESOURCES += \ - denali.qrc - -DEFINES += \ - VER_MAJOR="0" \ - VER_MINOR="4" \ - VER_REVIS="\\\"${buildNumber}\\\"" \ - VER_DEVEL="999" - - -# Additional import path used to resolve QML modules in Qt Creator's code model -QML_IMPORT_PATH = - -# Additional import path used to resolve QML modules just for Qt Quick Designer -QML_DESIGNER_IMPORT_PATH = - -# Default rules for deployment. -qnx: target.path = /tmp/$${TARGET}/bin -else: unix:!android: target.path = /opt/$${TARGET}/bin -!isEmpty(target.path): INSTALLS += target +QT += quick serialbus +CONFIG += c++17 -Wall + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Refer to the documentation for the +# deprecated API to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +INCLUDEPATH += \ + sources \ + sources/storage \ + sources/gui \ + sources/canbus + +HEADERS += \ + sources/applicationcontroller.h \ + sources/applicationpost.h \ + sources/canbus/caninterface.h \ + sources/canbus/messagehandler.h \ + sources/configuration/display.h \ + sources/configuration/sound.h \ + sources/gui/guiactions.h \ + sources/gui/guiglobals.h \ + sources/gui/guiview.h \ + sources/gui/guicontroller.h \ + sources/main.h \ + sources/maintimer.h \ + sources/storage/filehandler.h \ + sources/storage/logger.h \ + sources/storage/settings.h + +SOURCES += \ + main.cpp \ + sources/applicationcontroller.cpp \ + sources/applicationpost.cpp \ + sources/canbus/caninterface.cpp \ + sources/canbus/messagehandler.cpp \ + sources/configuration/display.cpp \ + sources/configuration/sound.cpp \ + sources/gui/guiactions.cpp \ + sources/gui/guiglobals.cpp \ + sources/gui/guiview.cpp \ + sources/gui/guicontroller.cpp \ + sources/maintimer.cpp \ + sources/storage/filehandler.cpp \ + sources/storage/logger.cpp \ + sources/storage/settings.cpp + +RESOURCES += \ + denali.qrc + +DEFINES += \ + VER_MAJOR="0" \ + VER_MINOR="4" \ + VER_REVIS="\\\"${buildNumber}\\\"" \ + VER_DEVEL="999" + + +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH = + +# Additional import path used to resolve QML modules just for Qt Quick Designer +QML_DESIGNER_IMPORT_PATH = + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target Index: main.cpp =================================================================== diff -u -rda12b441af2a10d0650f528325ca93d04eefac5f -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d --- main.cpp (.../main.cpp) (revision da12b441af2a10d0650f528325ca93d04eefac5f) +++ main.cpp (.../main.cpp) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -28,10 +28,16 @@ // Project #include "maintimer.h" +#include "caninterface.h" +#include "messagehandler.h" #include "applicationcontroller.h" +#include "guiglobals.h" +#include "guicontroller.h" /*! \brief Application Initialization\n - * this section includes: + * Some part of the application need to be initialized out of any thread. + * So is initialized here to be initialized in the main thread. + * this section also includes: */ int main(int argc, char *argv[]) { @@ -57,14 +63,26 @@ app.installTranslator(&translator); //! - Initializing Main Timer - MainTimer::I()->init(); + _MainTimer->init(); + + //! - Initializing CanBus Interface + _CanInterface->init(); + + //! - Initializing CanBus Message Handler + _MessageHandler->init(); + //! - Initializing Application Controller - QObject::connect(ApplicationController::I(), &ApplicationController::quit, &app, [](int retcode) { - // TODO : Logger needs to log this issue + _ApplicationController->init(); + QObject::connect(_ApplicationController, &ApplicationController::quit, &app, [](int retcode) { qDebug() << "Application Terminated:" << retcode; QCoreApplication::exit(retcode); }, Qt::QueuedConnection); - ApplicationController::I()->init(); + ////! - Initializing GUI Controller + _GuiController->init(); + + //! - Initialize the Qml Viewer and starts GUI + startGui(); + return app.exec(); } Index: sources/applicationcontroller.cpp =================================================================== diff -u -r5194f3afffb28dac90a7ca4153b6a0ca2f239387 -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d --- sources/applicationcontroller.cpp (.../applicationcontroller.cpp) (revision 5194f3afffb28dac90a7ca4153b6a0ca2f239387) +++ sources/applicationcontroller.cpp (.../applicationcontroller.cpp) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -14,48 +14,111 @@ #include "applicationcontroller.h" // Qt -#include // Project +#include "guiglobals.h" +#include "guicontroller.h" +#include "messagehandler.h" -ApplicationController *ApplicationController::_instance = nullptr; +// Singleton +SINGLETON_INIT(ApplicationController) + +/*! + * \brief ApplicationController::ApplicationController + * \param parent + */ ApplicationController::ApplicationController(QObject *parent) : QObject(parent) { - _guiController = Gui::GuiController::I(); _fileHandler = new Storage::FileHandler (this); _applicationPost = new ApplicationPost(this); - connect(_guiController,&GuiController::initialized,this, &ApplicationController::UiInitialized); + } -bool ApplicationController::event(QEvent *event) +/*! + * \brief ApplicationController initializer + */ +bool ApplicationController::init() { - return QObject::event(event); + if (!_fileHandler ->init()) return false; + if (!_applicationPost->init()) return false; + connection(); + return true; } -ApplicationController *ApplicationController::I() +/*! + * \brief GUI Controller connections definition + */ +void ApplicationController::connection() { - if (!_instance) { - _instance = new ApplicationController(); - } - return _instance; + // From GUI + connect(_GuiController , SIGNAL(didActionRequest(GuiActionType)), + this , SLOT( onActionRequest(GuiActionType))); + // From GUI + connect(_GuiController , SIGNAL(didActionPerform(GuiActionType,GuiActionInfo)), + this , SLOT( onActionPerform(GuiActionType, GuiActionInfo))); + + // From HD/DG + connect(_MessageHandler, SIGNAL(didActionCommand(GuiActionType)), + this , SLOT( onActionCommand(GuiActionType))); + // From HD/DG + connect(_MessageHandler, SIGNAL(didActionConfirm(GuiActionType,GuiActionInfo)), + this , SLOT( onActionConfirm(GuiActionType, GuiActionInfo))); } -bool ApplicationController::init() + +/*! + * \brief Process the requested action + * \details Processes the requested action + * \param vAction - User requested Action + */ +void ApplicationController::onActionRequest(GuiActionType vAction) { - if (!_fileHandler ->init()) return false; - if (!_applicationPost->init()) return false; - _guiController->init(); - return true; + qDebug() << "ApplicationController.actionRequested : " << vAction; + // Process the requested action by GUI + // Process ... + emit didActionRequest(vAction); } -void ApplicationController::UiInitialized(bool ok) +/*! + * \brief Process the performed action + * \details An action which has been commanded by HD has been performed by GUI.\n + * GUI notifies that the action has been performed + * \param vAction + * \param vInfo + */ +void ApplicationController::onActionPerform(GuiActionType vAction, GuiActionInfo vInfo) { - if(ok) { - if(_applicationPost->init()) { - _applicationPost->start(); - } - } - else { - quit(-1); - } + qDebug() << "ApplicationController.actionPerformed : " << vAction << vInfo; + // Process the performed action by GUI + // Process ... + emit didActionPerform(vAction, vInfo); } + +/*! + * \brief Action commanded by HD + * \details An action has been commanded by HD, + * GUI requires to be notified to perform the action. + * \param vAction + */ +void ApplicationController::onActionCommand(GuiActionType vAction) +{ + qDebug() << "ApplicationController.actionCommanded : " << vAction; + // Process the command and notify GUI Controller + // Process ... + emit didActionCommand(vAction); +} + +/*! + * \brief An action has been confirmed + * \details GUI requested an action. + * In response HD confirmed the action. + * \param vAction + * \param vInfo + */ +void ApplicationController::onActionConfirm(GuiActionType vAction, GuiActionInfo vInfo) +{ + qDebug() << "ApplicationController.actionConfirmed : " << vAction; + // Process the command and notify GUI Controller + // Process ... + emit didActionConfirm(vAction, vInfo); +} Index: sources/applicationcontroller.h =================================================================== diff -u -r5194f3afffb28dac90a7ca4153b6a0ca2f239387 -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d --- sources/applicationcontroller.h (.../applicationcontroller.h) (revision 5194f3afffb28dac90a7ca4153b6a0ca2f239387) +++ sources/applicationcontroller.h (.../applicationcontroller.h) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -18,36 +18,50 @@ #include // Project +#include "main.h" +#include "guiactions.h" #include "filehandler.h" #include "applicationpost.h" -#include "guicontroller.h" +#include "canbus/caninterface.h" + + +// define +#define _ApplicationController ApplicationController::I() + +// namespace using namespace Storage; using namespace Gui; +using namespace Can; - class ApplicationController : public QObject { Q_OBJECT - static ApplicationController *_instance; - ApplicationPost *_applicationPost = nullptr; - FileHandler *_fileHandler = nullptr; + FileHandler *_fileHandler = nullptr; + ApplicationPost *_applicationPost = nullptr; - QPointer _guiController; +SINGLETON_DECL(ApplicationController) +public: + bool init(); - explicit ApplicationController(QObject *parent = nullptr); +private: + void connection(); - bool event(QEvent *event) override; +private slots: // Should be private for thread safety and is connected internally. + void onActionRequest (GuiActionType vAction); // UI => HD/DG + void onActionConfirm (GuiActionType vAction, GuiActionInfo vInfo); // UI <= HD/DG -public: - static ApplicationController *I(); - bool init(); + void onActionCommand (GuiActionType vAction); // UI <= HD/DG + void onActionPerform (GuiActionType vAction, GuiActionInfo vInfo); // UI => HD/DG signals: - void quit(int retcode=0); + void didActionRequest(GuiActionType vAction ); // UI => HD/DG + void didActionConfirm(GuiActionType vAction, GuiActionInfo vInfo); // UI <= HD/DG -private slots: - void UiInitialized(bool ok); + void didActionCommand(GuiActionType vAction ); // UI <= HD/DG + void didActionPerform(GuiActionType vAction, GuiActionInfo vInfo); // UI => HD/DG + void quit(int retcode=0); + }; Fisheye: Tag 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d refers to a dead (removed) revision in file `sources/canbus/canbus.cpp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d refers to a dead (removed) revision in file `sources/canbus/canbus.h'. Fisheye: No comparison available. Pass `N' to diff? Index: sources/canbus/caninterface.cpp =================================================================== diff -u --- sources/canbus/caninterface.cpp (revision 0) +++ sources/canbus/caninterface.cpp (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -0,0 +1,176 @@ +/*! + * + * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * \copyright \n + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, \n + * IN PART OR IN WHOLE, \n + * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. \n + * + * \file caninterface.cpp + * \date 2019/09/30 + * \author Behrouz NematiPour + * + */ +#include "caninterface.h" + +// Qt +#include + +// Project +#include "messagehandler.h" + +// namespace +using namespace Can; + +// Singleton +SINGLETON_INIT(CanInterface) + +/*! + * \brief constructor + * \param parent object + */ +CanInterface::CanInterface(QObject *parent) : QObject(parent) {} + +bool CanInterface::init() +{ + QString mError; + _canDevice = QCanBus::instance()->createDevice(_canType, _canInterface, &mError); + if (!_canDevice) { + status(tr("Error: Device Creation"),mError); + return false; + } + + _numberFramesWritten = 0; + + connection(); + + if (!_canDevice->connectDevice()) { + status(tr("Error: Connection")); + delete _canDevice; + _canDevice = nullptr; + return false; + } + status(tr("Connected")); + return true; +} + +QString CanInterface::status() const +{ + return _canStatus; +} + +void CanInterface::connection() +{ + + connect(_canDevice, SIGNAL(framesReceived()), + this , SLOT ( onRead())); + connect(_canDevice, SIGNAL(errorOccurred(QCanBusDevice::CanBusError)), + this , SLOT ( onError(QCanBusDevice::CanBusError))); + + connect(_MessageHandler, SIGNAL(didActionPerform(QCanBusFrame)), + this , SLOT( onActionPerform(QCanBusFrame))); + connect(_MessageHandler, SIGNAL(didActionRequest(QCanBusFrame)), + this , SLOT( onActionRequest(QCanBusFrame))); +} + +void CanInterface::status(const QString &vDescription, QString vError) +{ + _canStatus = tr("%1 '%2[%3]', %4") + .arg(vDescription) + .arg(_canType) + .arg(_canInterface) + .arg(_canDevice->errorString() + vError) + ; + qDebug() << _canStatus; +} + +void CanInterface::send(const QCanBusFrame &vFrame) +{ + if( !_canDevice ) + return; + _canDevice->writeFrame(vFrame); +} + +void CanInterface::quit() +{ + if (!_canDevice) + return; + + _canDevice->disconnectDevice(); + delete _canDevice; + _canDevice = nullptr; + + status(tr("Disconnected")); +} + +static QString frameFlags(const QCanBusFrame &frame) +{ + QString result = QLatin1String(" --- "); + + if (frame.hasBitrateSwitch()) + result[1] = QLatin1Char('B'); + if (frame.hasErrorStateIndicator()) + result[2] = QLatin1Char('E'); + if (frame.hasLocalEcho()) + result[3] = QLatin1Char('L'); + + return result; +} + +void CanInterface::onError(QCanBusDevice::CanBusError vError) +{ + switch (vError) { + case QCanBusDevice::ReadError: + case QCanBusDevice::WriteError: + case QCanBusDevice::ConnectionError: + case QCanBusDevice::ConfigurationError: + case QCanBusDevice::UnknownError: + _canStatus = _canDevice->errorString(); + break; + default: + break; + } + emit didError(_canStatus); +} + +void CanInterface::onRead() +{ + if (!_canDevice) + return; + + while (_canDevice->framesAvailable()) { + const QCanBusFrame frame = _canDevice->readFrame(); + + QString view; + if (frame.frameType() == QCanBusFrame::ErrorFrame) { + view = _canDevice->interpretErrorFrame(frame); + } + else { + view = frame.toString(); + } + + const QString time = QString::fromLatin1("%1.%2 ") + .arg(frame.timeStamp().seconds(), 10, 10, QLatin1Char(' ')) + .arg(frame.timeStamp().microSeconds() / 100, 4, 10, QLatin1Char('0')); + + const QString flags = frameFlags(frame); + + qDebug() << time + flags + view; + // TODO : Needs to be investigated on how the messages on canBus will be received. + // my require to be moved at the end of the function. + emit didRead(frame); + } +} + +void CanInterface::onActionPerform(const QCanBusFrame &vFrame) +{ + // TODO : Process Frame + send(vFrame); +} + +void CanInterface::onActionRequest(const QCanBusFrame &vFrame) +{ + // TODO : Process Frame + send(vFrame); +} + Index: sources/canbus/caninterface.h =================================================================== diff -u --- sources/canbus/caninterface.h (revision 0) +++ sources/canbus/caninterface.h (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -0,0 +1,76 @@ +/*! + * + * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * \copyright \n + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, \n + * IN PART OR IN WHOLE, \n + * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. \n + * + * \file caninterface.h + * \date 2019/09/30 + * \author Behrouz NematiPour + * + */ +#pragma once + +// Qt +#include +#include + +// Project +#include "main.h" + +// Define +#define _CanInterface CanInterface::I() + +// namespace +namespace Can { + +/*! + * \brief CanBus interface + * \details This class contains the interface to CanBus\n + * And utilizes Qt QCanBus to interact with the CanBus\n + * On the OS side there is a driver installed to convert SPI to CAN\n + * Since the GUI Board by itself doesn't contain the CAN Bus. + */ +class CanInterface : public QObject +{ + Q_OBJECT + + // constants + const char *_canType = "socketcan"; + const char *_canInterface = "can0"; + const int _canBitRate = 250000; + + // member variables + QCanBusDevice *_canDevice = nullptr; + qint64 _numberFramesWritten = 0; + QString _canStatus = ""; + + // Singleton +SINGLETON_DECL(CanInterface) +public: + bool init(); + void quit(); + + QString status() const; + +private: + void connection(); + + void status(const QString &vDescription, QString vError = ""); + void send(const QCanBusFrame &vFrame); + +signals: + void didRead (const QCanBusFrame &vFrame ); + void didError(const QString &vStatus); + +public slots: +private slots: + + void onActionPerform(const QCanBusFrame &vFrame); + void onActionRequest(const QCanBusFrame &vFrame); + void onRead (); + void onError(QCanBusDevice::CanBusError vError); +}; +} Index: sources/canbus/messagehandler.cpp =================================================================== diff -u --- sources/canbus/messagehandler.cpp (revision 0) +++ sources/canbus/messagehandler.cpp (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -0,0 +1,135 @@ +/*! + * + * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * copyright + + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, + + * IN PART OR IN WHOLE, + + * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + + * + * file messagehandler.cpp + * date 10/26/2019 + * author Behrouz NematiPour + * + */ +#include "messagehandler.h" + +// Qt +#include + +// Project +#include "applicationcontroller.h" + +// namespace +using namespace Can; + +// Singleton +SINGLETON_INIT(MessageHandler) + +/*! + * \brief MessageHandler::MessageHandler + * \param parent + */ +MessageHandler::MessageHandler(QObject *parent) : QObject(parent) +{ +} + +/*! + * \brief Message Handler initializer + */ +void MessageHandler::init() +{ + connection(); +} + +/*! + * \brief Message Handler connections definition + */ +void MessageHandler::connection() +{ + // From GUI + connect(_ApplicationController, SIGNAL(didActionRequest(GuiActionType)), + this , SLOT( onActionRequest(GuiActionType))); + // From GUI + connect(_ApplicationController, SIGNAL(didActionPerform(GuiActionType,GuiActionInfo)), + this , SLOT( onActionPerform(GuiActionType, GuiActionInfo))); + + connect(_CanInterface , SIGNAL(didRead(QCanBusFrame)), + this , SLOT( onRead(QCanBusFrame))); + +} + + +/*! + * \brief Process the requested action + * \details Processes the requested action + * \param vAction - User requested Action + */ +void MessageHandler::onActionRequest(GuiActionType vAction) +{ + // TODO : Test Code + qDebug() << "MessageHandler.actionRequested : " << vAction; + QCanBusFrame mFrame; + QByteArray mPayload; + switch (vAction) { + case GuiActionType::PowerOff: + mFrame.setFrameId(2); + mPayload.append("\x01\x00\x01\x01\x00\x00\x00\x00"); + mFrame.setPayload(mPayload); + break; + default: + break; + } + emit didActionRequest(mFrame); +} + +/*! + * \brief Process the performed action + * \details An action which has been commanded by HD has been performed by GUI.\n + * GUI notifies that the action has been performed + * \param vAction + * \param vInfo + */ +void MessageHandler::onActionPerform(GuiActionType vAction, GuiActionInfo vInfo) +{ + // TODO : Test Code + qDebug() << "MessageHandler.actionPerformed : " << vAction << vInfo; + QCanBusFrame mFrame; + QByteArray mPayload; + switch (vAction) { + case GuiActionType::PowerOff: + mFrame.setFrameId(2); + mPayload.append("\x01\x00\x01\x01\x00\x00\x00\x00"); + mFrame.setPayload(mPayload); + break; + default: + break; + } + emit didActionPerform(mFrame); +} + +/*! + * \brief MessageHandler::onRead + * \param vFrame + */ +void MessageHandler::onRead(const QCanBusFrame &vFrame) +{ + // TODO : Test Code + bool isCommand = true; + switch (vFrame.frameId()) { + case 1: + qDebug() << "HD Command:" << vFrame.payload(); + break; + default: + break; + } + if (isCommand) { + emit didActionCommand(GuiActions::PowerOff); + } + else { + emit didActionConfirm(GuiActions::PowerOff,GuiActions::Accepted); + } +} Index: sources/canbus/messagehandler.h =================================================================== diff -u --- sources/canbus/messagehandler.h (revision 0) +++ sources/canbus/messagehandler.h (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -0,0 +1,63 @@ +/*! + * + * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * copyright + + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, + + * IN PART OR IN WHOLE, + + * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + + * + * file messagehandler.h + * date 10/26/2019 + * author Behrouz NematiPour + * + */ +#pragma once + +// Qt +#include +#include + +// Project +#include "main.h" +#include "guiactions.h" + +// Define +#define _MessageHandler MessageHandler::I() + +// namespace +using namespace Gui; +namespace Can { + +/*! + * \brief The MessageHandler class + */ +class MessageHandler : public QObject +{ + Q_OBJECT + +SINGLETON_DECL(MessageHandler) +public: + void init(); + +private: + void connection(); + +private slots: // Should be private for thread safety and is connected internally. + void onActionRequest (GuiActionType vAction); // UI => HD/DG + void onActionPerform (GuiActionType vAction, GuiActionInfo vInfo); // UI <= HD/DG + + void onRead (const QCanBusFrame &vFrame); + + +signals: + void didActionConfirm(GuiActionType vAction, GuiActionInfo vInfo); // UI <= HD/DG + void didActionCommand(GuiActionType vAction ); // UI <= HD/DG + + void didActionRequest(const QCanBusFrame &vFrame ); // UI => HD/DG + void didActionPerform(const QCanBusFrame &vFrame ); // UI => HD/DG +}; +} Index: sources/gui/guiactions.h =================================================================== diff -u -r5194f3afffb28dac90a7ca4153b6a0ca2f239387 -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d --- sources/gui/guiactions.h (.../guiactions.h) (revision 5194f3afffb28dac90a7ca4153b6a0ca2f239387) +++ sources/gui/guiactions.h (.../guiactions.h) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -22,15 +22,20 @@ Q_GADGET explicit GuiActions(); public: - enum GuiActions_Enum { - ActStartTreatment, - ActBack, - ActConfirm + enum GuiActionsType_Enum { + PowerOff, }; + enum GuiActionsInfo_Enum { + Accepted, + Rejected, + }; - Q_ENUM(GuiActions_Enum) - + Q_ENUM(GuiActionsType_Enum) + Q_ENUM(GuiActionsInfo_Enum) }; -typedef GuiActions::GuiActions_Enum GuiAction; +// to be able to use the enum as signal/slot parameter +typedef GuiActions::GuiActionsType_Enum GuiActionType; +typedef GuiActions::GuiActionsInfo_Enum GuiActionInfo; + } Index: sources/gui/guicontroller.cpp =================================================================== diff -u -r5194f3afffb28dac90a7ca4153b6a0ca2f239387 -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d --- sources/gui/guicontroller.cpp (.../guicontroller.cpp) (revision 5194f3afffb28dac90a7ca4153b6a0ca2f239387) +++ sources/gui/guicontroller.cpp (.../guicontroller.cpp) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -14,73 +14,110 @@ #include "guicontroller.h" // Qt +#include // Project -#include "guiview.h" -#include "maintimer.h" +#include "applicationcontroller.h" +// namespace using namespace Gui; -GuiController *GuiController::_instance = nullptr; -void GuiController::registerView() +// Singleton +SINGLETON_INIT(GuiController) + +GuiController::GuiController(QObject *parent) : QObject(parent) {} + +/*! + * \brief GuiController connections definition + */ +void GuiController::connection() { - qRegisterMetaType("GuiAction"); - qmlRegisterType ("Gui.View", 0, 1, "GuiView"); - qmlRegisterUncreatableType ("Gui.Actions", 0, 1, "GuiActions",QStringLiteral("Used only for enums no need to have an object")); + // From HD/DG + connect(_ApplicationController, SIGNAL(didActionCommand(GuiActionType)), + this , SLOT( onActionCommand(GuiActionType))); + // From HD/DG + connect(_ApplicationController, SIGNAL(didActionConfirm(GuiActionType, GuiActionInfo)), + this , SLOT( onActionConfirm(GuiActionType, GuiActionInfo))); + } -GuiController::GuiController(QObject *parent) : QObject(parent) + +/*! + * \brief GuiController initializer + */ +void GuiController::init() { - registerView(); - connect(this ,&GuiController::actionRequested, this, &GuiController::actionEvaluation); + connection(); } -GuiController *GuiController::I() +/*! + * \brief GuiController::onActionRequest + * This method Confirmed that if the action is accepted or not,\n + * Regarding the current state and the action.\n + * These actions are only user actions and there is only one user interaction,\n + * So no need to capture from which screen this action comes since we have the current state.\n + * Sometimes GuiController requires to investigate with the ApplicationController to get approval from HD device.\n + * \param vAction - User requested Action + */ +void GuiController::doActionRequest(GuiActionType vAction) { - if (!_instance) { - _instance = new GuiController(); + // Process the GuiView Request. + // If can be processed in GuiController take action and notify GuiView + qDebug() << "GuiController.actionRequested : " << vAction; + GuiActionInfo mInfo = GuiActionInfo::Accepted; + Q_UNUSED(mInfo) + switch (vAction) { + // TODO : Test Code + case GuiActionType::PowerOff: + emit didActionConfirm(vAction, mInfo); + break; + default: + // If it requires to be Confirmed by HD/DG send the request to ApplicationController + emit didActionRequest(vAction); + break; } - return _instance; } -void GuiController::init() +/*! + * \brief Process the performed action + * \details An action which has been commanded by HD has been performed by Gui.\n + * Gui notifies that the action has been performed + * \param vAction + * \param vInfo + */ +void GuiController::doActionPerform(GuiActionType vAction, GuiActionInfo vInfo) { - connect(&_viewer, &QQuickView::statusChanged, this, &GuiController::onUiStatusChanged); - const QUrl url(QML("main")); - _viewer.setSource(url); + qDebug() << "GuiController.actionPerformed : " << vAction << vInfo; + // Process the performed action by Gui + // Process ... + emit didActionPerform(vAction, vInfo); } -void GuiController::onUiStatusChanged(QQuickView::Status vStatus) +/*! + * \brief Action commanded by HD + * \details An action has been commanded by HD, + * Gui requires to be notified to perform the action. + * \param vAction + */ +void GuiController::onActionCommand(GuiActionType vAction) { - bool ok = vStatus == QQuickView::Ready; - if (ok) { - _viewer.show(); - } - emit initialized(ok); + qDebug() << "GuiController.actionCommanded : " << vAction; + // Process the command and notify GuiView + // Process ... + emit didActionCommand(vAction); } /*! - * \brief GuiController::actionEvaluation - * This method evaluated that if the action is accepted or not,\n - * Regarding to the current state and the action.\n - * These actions are only user actions and there is only one user interaction,\n - * So no need to capture from which screen this action comes since we have the current state.\n - * Sometimes GuiController requires to investigate with the ApplicationController to get approval from HD device.\n - * \param vAction - User requested Action + * \brief An action has been confirmed + * \details Gui requested an action. + * In response HD confirmed the action. + * \param vAction + * \param vInfo */ -void GuiController::actionEvaluation(GuiAction vAction) +void GuiController::onActionConfirm(GuiActionType vAction, GuiActionInfo vInfo) { - //static bool requested = false; - qDebug() << "actionRequested : " << vAction; - - // TEST : check state and evaluate. - // if (!requested) { - // requested = true; - // qDebug() << "Ask again: " << vAction; - // actionEvaluated(vAction, false); - // return; - // } - // requested = false; - qDebug() << "Got it: " << vAction; - actionEvaluated(vAction, true); + qDebug() << "GuiController.actionConfirmed : " << vAction; + // Process the command and notify GuiView + // Process ... + emit didActionConfirm(vAction, vInfo); } Index: sources/gui/guicontroller.h =================================================================== diff -u -r5194f3afffb28dac90a7ca4153b6a0ca2f239387 -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d --- sources/gui/guicontroller.h (.../guicontroller.h) (revision 5194f3afffb28dac90a7ca4153b6a0ca2f239387) +++ sources/gui/guicontroller.h (.../guicontroller.h) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -15,38 +15,42 @@ // Qt #include -#include + // Project +#include "main.h" #include "guiactions.h" -#define QML(qml) QStringLiteral("qrc:/" qml ".qml") +// define +#define _GuiController GuiController::I() +// namespace namespace Gui { class GuiController : public QObject { Q_OBJECT - QQuickView _viewer; - void registerView(); - - static GuiController *_instance; - explicit GuiController(QObject *parent = nullptr); - +SINGLETON_DECL(GuiController) public: - static GuiController *I(); void init(); +private: + void connection(); -private slots: - void onUiStatusChanged(QQuickView::Status vStatus); - void actionEvaluation(GuiAction vAction); +public slots: + void doActionRequest (GuiActionType vAction); // UI => HD/DG + void doActionPerform (GuiActionType vAction, GuiActionInfo vInfo); // UI => HD/DG +private slots: // Should be private for thread safety and is connected internally. + void onActionConfirm (GuiActionType vAction, GuiActionInfo vInfo); // UI <= HD/DG + void onActionCommand (GuiActionType vAction); // UI <= HD/DG + signals: - void initialized(bool ok); + void didActionRequest(GuiActionType vAction ); // UI => HD/DG + void didActionConfirm(GuiActionType vAction, GuiActionInfo vInfo); // UI <= HD/DG - void actionRequested(GuiAction vAction); - void actionEvaluated(GuiAction vAction, bool vAccepted); + void didActionCommand(GuiActionType vAction ); // UI <= HD/DG + void didActionPerform(GuiActionType vAction, GuiActionInfo vInfo); // UI => HD/DG }; } Index: sources/gui/guiglobals.cpp =================================================================== diff -u --- sources/gui/guiglobals.cpp (revision 0) +++ sources/gui/guiglobals.cpp (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -0,0 +1,51 @@ +/*! + * + * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * copyright + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, + * IN PART OR IN WHOLE, + * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + * + * file guiglobals.cpp + * date 10/27/2019 + * author Behrouz NematiPour + * + */ +#include "guiglobals.h" + +// Qt +#include + +// Project +#include "guiactions.h" +#include "guiview.h" + +namespace Gui { + QQuickView *_viewer = nullptr; + + void registerTypes() + { + qRegisterMetaType ("GuiActionType"); + qRegisterMetaType ("GuiActionInfo"); + qmlRegisterType ("Gui.View", 0, 1, "GuiView"); + qmlRegisterUncreatableType ("Gui.Actions", 0, 1, "GuiActions",QStringLiteral("Used only for enumerations no need to have an object")); + } + + void startGui() { + _viewer = new QQuickView; + registerTypes(); + + QObject::connect(_viewer, &QQuickView::statusChanged, qApp, [=](QQuickView::Status vStatus) { + bool ok = vStatus == QQuickView::Ready; + if (ok) { + _viewer->show(); + } + else if (vStatus == QQuickView::Error || vStatus == QQuickView::Null) { + qDebug() << "Application Terminated:" << _viewer->errors(); + QCoreApplication::exit(-1); + } + + }); + _viewer->setSource(QStringLiteral("qrc:/main.qml")); + } +} Index: sources/gui/guiglobals.h =================================================================== diff -u --- sources/gui/guiglobals.h (revision 0) +++ sources/gui/guiglobals.h (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -0,0 +1,27 @@ +/*! + * + * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * copyright + + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, + + * IN PART OR IN WHOLE, + + * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + + * + * file guiglobals.h + * date 10/27/2019 + * author Behrouz NematiPour + * + */ +#pragma once + +// Qt +#include + +namespace Gui { + extern QQuickView *_viewer; + void registerTypes(); + void startGui(); +} Index: sources/gui/guiview.cpp =================================================================== diff -u -r5194f3afffb28dac90a7ca4153b6a0ca2f239387 -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d --- sources/gui/guiview.cpp (.../guiview.cpp) (revision 5194f3afffb28dac90a7ca4153b6a0ca2f239387) +++ sources/gui/guiview.cpp (.../guiview.cpp) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -16,18 +16,58 @@ // Project #include "guicontroller.h" +// namespace using namespace Gui; -// We don't have access to view object since it has been created in the GUI -// So here connect to the controller which we have access to. -// Also here emit the controller signal since for the same reason. +/*! + * \brief GuiView::GuiView + * \param parent + */ GuiView::GuiView(QQuickItem *parent) { Q_UNUSED(parent) - connect(GuiController::I(), &GuiController::actionEvaluated, this, &GuiView::actionEvaluated); + connection(); } -void GuiView::notifyActionRequest(GuiAction vAction) +void GuiView::connection() { - emit GuiController::I()->actionRequested(vAction); + connect(_GuiController, SIGNAL(didActionConfirm(GuiActionType, GuiActionInfo)), + this , SLOT( onActionConfirm(GuiActionType, GuiActionInfo))); + + connect(_GuiController, SIGNAL(didActionCommand(GuiActionType )), + this , SLOT( onActionCommand(GuiActionType ))); + + // since we don't have access to GuiView object because it is created in Qml. + // Connection to the GuiController made here + // It should be defined in the class which wants to connect to signal. + connect(this , SIGNAL(didActionRequest(GuiActionType)), + _GuiController, SLOT( doActionRequest(GuiActionType))); + + connect(this , SIGNAL(didActionPerform(GuiActionType,GuiActionInfo)), + _GuiController, SLOT( doActionPerform(GuiActionType,GuiActionInfo))); } + +void GuiView::onActionConfirm(GuiActionType vAction, GuiActionInfo vInfo) +{ + // process the evaluation and notify GUI + // process ... + emit didActionConfirm(vAction, vInfo); +} + +void GuiView::onActionCommand(GuiActionType vAction) +{ + // process the commanded action and notify GUI + // process ... + emit didActionCommand(vAction); + +} + +void GuiView::doActionRequest(GuiActionType vAction) +{ + emit didActionRequest(vAction); +} + +void GuiView::doActionPerform(GuiActionType vAction, GuiActionInfo vInfo) +{ + emit didActionPerform(vAction, vInfo); +} Index: sources/gui/guiview.h =================================================================== diff -u -r5194f3afffb28dac90a7ca4153b6a0ca2f239387 -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d --- sources/gui/guiview.h (.../guiview.h) (revision 5194f3afffb28dac90a7ca4153b6a0ca2f239387) +++ sources/gui/guiview.h (.../guiview.h) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -15,9 +15,14 @@ // Qt #include + // Project #include "guiactions.h" +// define +// ... + +// namespace namespace Gui { class GuiView : public QQuickItem @@ -27,11 +32,23 @@ public: explicit GuiView(QQuickItem *parent = nullptr); -public slots: - void notifyActionRequest(GuiAction vAction); +private: + void connection(); +private slots: + void onActionConfirm (GuiActionType vAction, GuiActionInfo vInfo); // UI <= HD/DG + void onActionCommand (GuiActionType vAction ); // UI <= HD/DG + +public slots: // is public since will be used in the UI and is in the same thread. + void doActionRequest (GuiActionType vAction ); // UI => HD/DG + void doActionPerform (GuiActionType vAction, GuiActionInfo vInfo); // UI => HD/DG + signals: - void actionEvaluated(GuiAction vAction, bool vAccepted); -}; + void didActionConfirm(GuiActionType vAction, GuiActionInfo vInfo); // UI <= HD/DG + void didActionCommand(GuiActionType vAction ); // UI <= HD/DG + void didActionRequest(GuiActionType vAction ); // UI => HD/DG + void didActionPerform(GuiActionType vAction, GuiActionInfo vInfo); // UI => HD/DG + +}; } Index: sources/gui/qml/components/MainMenu.qml =================================================================== diff -u -rd4befd2d92ee54b57de33867a1e2517cafdd89d3 -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d --- sources/gui/qml/components/MainMenu.qml (.../MainMenu.qml) (revision d4befd2d92ee54b57de33867a1e2517cafdd89d3) +++ sources/gui/qml/components/MainMenu.qml (.../MainMenu.qml) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -21,8 +21,6 @@ // Qml imports import "qrc:/globals" -// TODO : Make it more general Component - /* * \brief The MainMenu Component * which contains three [Treatment, Manager, Settings] Index: sources/gui/qml/main.qml =================================================================== diff -u -refac452e8558f6f95b37243f82e980187965e821 -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d --- sources/gui/qml/main.qml (.../main.qml) (revision efac452e8558f6f95b37243f82e980187965e821) +++ sources/gui/qml/main.qml (.../main.qml) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -26,9 +26,6 @@ import "qrc:/components" import "qrc:/dialogs" -// TODO : -// 3 - Version - /* * \brief Initialization and start point of the QML */ @@ -38,20 +35,26 @@ property alias powerOffDialog: _powerOffDialog - GuiView { id: _guiView - onActionEvaluated: { - if (vAction === GuiActions.ActBack) { - if (vAccepted) { - _stackView.pop() - } + GuiView { id: _GuiView + onDidActionConfirm: { + switch(vAction) { + case GuiActions.PowerOff: + if (vInfo === GuiActions.Accepted) + _powerOffDialog.open() + break; } - if (vAction === GuiActions.ActConfirm) { - // NoOp + } + onDidActionCommand: { + switch(vAction) { + case GuiActions.PowerOff: + _powerOffDialog.open() + break; } } } - // ----- Follow the Z order ----- + + // ----- Follow the below Z order ----- // 1 - Screens // 1 - 1 SettingsStack { id: _settingsStack } @@ -74,10 +77,17 @@ } // 4 - Modals - PowerOff { id: _powerOffDialog } + PowerOff { id: _powerOffDialog + onAccepted: { + _GuiView.doActionPerform(GuiActions.PowerOff, GuiActions.Accepted) + } + onRejected: { + _GuiView.doActionPerform(GuiActions.PowerOff, GuiActions.Rejected) + } + } // 9 - Others - Text { //NOTE: Test Code : Must be removed when implemented + Text { // TODO : Test Code color: Colors.textMain x: 1172 y: 767 Index: sources/gui/qml/pages/TreatmentHome.qml =================================================================== diff -u -r5194f3afffb28dac90a7ca4153b6a0ca2f239387 -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d --- sources/gui/qml/pages/TreatmentHome.qml (.../TreatmentHome.qml) (revision 5194f3afffb28dac90a7ca4153b6a0ca2f239387) +++ sources/gui/qml/pages/TreatmentHome.qml (.../TreatmentHome.qml) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -17,6 +17,8 @@ import QtQuick.Controls 2.12 // Project +import Gui.Actions 0.1; + // Qml imports import "qrc:/globals" import "qrc:/components" @@ -34,17 +36,17 @@ property int favoriteCount: 0 TouchRect { id : _poweroff - width: 100 + width: 150 height: Variables.logoHeight anchors { top : parent.top right : parent.right topMargin : (Variables.headerHeight - Variables.logoHeight) / 2 rightMargin : (Variables.headerHeight - Variables.logoHeight) / 2 } - text.text: qsTr("Test") + text.text: qsTr("Shutdown") button.onPressed: { - _mainItem.powerOffDialog.open() + _GuiView.doActionRequest(GuiActions.ActionPowerOff) } } Index: sources/main.h =================================================================== diff -u --- sources/main.h (revision 0) +++ sources/main.h (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -0,0 +1,37 @@ +/*! + * + * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * copyright + + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, + + * IN PART OR IN WHOLE, + + * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + + * + * file main.h + * date 10/25/2019 + * author Behrouz NematiPour + * + */ +#pragma once + +// Qt +#include + +// Project + +#define SINGLETON_DECL(vCLASS) \ +private: \ + static vCLASS *_instance; \ + explicit vCLASS(QObject *parent = nullptr); \ +public: \ + static vCLASS *I() { \ + if (!_instance) \ + _instance = new vCLASS(); \ + return _instance; \ + } + +#define SINGLETON_INIT(vCLASS) \ + vCLASS *vCLASS::_instance = nullptr; Index: sources/maintimer.cpp =================================================================== diff -u -r5194f3afffb28dac90a7ca4153b6a0ca2f239387 -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d --- sources/maintimer.cpp (.../maintimer.cpp) (revision 5194f3afffb28dac90a7ca4153b6a0ca2f239387) +++ sources/maintimer.cpp (.../maintimer.cpp) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -18,9 +18,13 @@ //Project -// Class instance init -MainTimer *MainTimer::_instance = nullptr; +// Singleton +SINGLETON_INIT(MainTimer) +/*! + * \brief MainTimer::MainTimer + * \param parent + */ MainTimer::MainTimer(QObject *parent) : QObject(parent) { _timer = new QTimer(this); @@ -33,12 +37,11 @@ _timer->start(_timeout); } -MainTimer *MainTimer::I() +void MainTimer::quit() { - if (!_instance) { - _instance = new MainTimer(); - } - return _instance; + _timer->stop(); + delete _timer; + _timer = nullptr; } void MainTimer::onTimeout() Index: sources/maintimer.h =================================================================== diff -u -r5194f3afffb28dac90a7ca4153b6a0ca2f239387 -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d --- sources/maintimer.h (.../maintimer.h) (revision 5194f3afffb28dac90a7ca4153b6a0ca2f239387) +++ sources/maintimer.h (.../maintimer.h) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -17,21 +17,29 @@ #include // Project +#include "main.h" +// Define +#define _MainTimer MainTimer::I() + +// Forward declaration class QTimer; + +/*! + * \brief The MainTimer class + * \details This class is going to be used for subjects which want to keep track of time to a second resolution. + */ class MainTimer : public QObject { Q_OBJECT static const int _timeout = 1000; //ms - QTimer *_timer = nullptr; - static MainTimer *_instance; - explicit MainTimer(QObject *parent = nullptr); +SINGLETON_DECL(MainTimer) public: - static MainTimer *I(); void init(); + void quit(); signals: void timeout(); Index: sources/storage/filehandler.cpp =================================================================== diff -u -r5194f3afffb28dac90a7ca4153b6a0ca2f239387 -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d --- sources/storage/filehandler.cpp (.../filehandler.cpp) (revision 5194f3afffb28dac90a7ca4153b6a0ca2f239387) +++ sources/storage/filehandler.cpp (.../filehandler.cpp) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -22,7 +22,8 @@ using namespace Storage; FileHandler::FileHandler(QObject *parent) : QObject(parent) { - connect(&fsWatcher, &QFileSystemWatcher::directoryChanged, this, &FileHandler::directoryChanged); + connect(&fsWatcher, SIGNAL(directoryChanged(QString)), + this , SLOT(directoryChanged(QString))); } bool FileHandler::init() @@ -31,8 +32,9 @@ return true; } -void FileHandler::directoryChanged() +void FileHandler::directoryChanged(const QString &vPath) { + Q_UNUSED(vPath) qDebug() << QFileInfo::exists("/dev/sda"); } Index: sources/storage/filehandler.h =================================================================== diff -u -r5194f3afffb28dac90a7ca4153b6a0ca2f239387 -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d --- sources/storage/filehandler.h (.../filehandler.h) (revision 5194f3afffb28dac90a7ca4153b6a0ca2f239387) +++ sources/storage/filehandler.h (.../filehandler.h) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) @@ -39,7 +39,7 @@ void usbStatusChanged(bool available); private slots: - void directoryChanged(); + void directoryChanged(const QString &vPath); bool mountUsb(); };