Index: sources/main.h =================================================================== diff -u -r781e62c996e81897517fbdb1bc79fe3bbcf165c1 -r526875e8db8cf0c97f5cd8aa90564e41d42f5fde --- sources/main.h (.../main.h) (revision 781e62c996e81897517fbdb1bc79fe3bbcf165c1) +++ sources/main.h (.../main.h) (revision 526875e8db8cf0c97f5cd8aa90564e41d42f5fde) @@ -1,37 +1,454 @@ /*! * - * Copyright (c) 2019-2019 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. - + * Copyright (c) 2019-2022 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 + * \file main.h + * \author (last) Behrouz NematiPour + * \date (last) 14-Jan-2022 + * \author (original) Behrouz NematiPour + * \date (original) 28-Oct-2019 * */ #pragma once // Qt #include - +#include // Project -#define SINGLETON_DECL(vCLASS) \ +// Application +#define PRINT_THREAD_NAME_ENABLE 0 +#if (PRINT_THREAD_NAME_ENABLE) + #include + #define PRINT_THREAD_NAME qDebug() << " ----- " << QThread::currentThread()->objectName() << metaObject()->className() << __func__ ; +#else + #define PRINT_THREAD_NAME +#endif + +#undef DEBUG_BCUFF_MIMIC + +// TODO : A singleton parent class needs to be created +// to taking care of the Threading, init, quit, and so + +// TODO : Threading +// - We still need to work on threading on other classes +// - We need to have a singleton parent class +// - Some code has been added to debug can interface (We still have swap frames) +#define SINGLETON(vCLASS) \ private: \ - static vCLASS *_instance; \ explicit vCLASS(QObject *parent = nullptr); \ + virtual ~vCLASS() { } \ + vCLASS(vCLASS const &) = delete; \ + vCLASS & operator = (vCLASS const &) = delete; \ public: \ - static vCLASS *I() { \ - if (!_instance) \ - _instance = new vCLASS(); \ - return _instance; \ + /*! \brief instance accessor + \details A singleton class single instance creator/accessor + \return reference to the class static instance + */\ + static vCLASS &I() { \ + static vCLASS _instance; \ + return _instance; \ + } \ +private: +//--------------------------------------------------------------------------------// +//--------------------------------------------------------------------------------// +extern int gFakeInterval ; +extern QByteArray gFakeData ; +extern const char*gFakeData_default ; +extern bool gSendEmptyKeepAwake ; +extern bool gFakeSeqAtBegin ; +extern bool gDisableUnhandledReport ; +extern bool gEnableDialinUnhandled ; +extern bool gDisableTimeout ; +extern bool gDisableAlarmNoMinimize ; +//--------------------------------------------------------------------------------// +//--------------------------------------------------------------------------------// +#define SKIPPER_DEF(X) \ + const quint8 skipperMaxTry = X; \ + static quint8 skipperCounter = 0; +#define SKIPPER_TST(WHAT) \ + if ( skipperCounter < skipperMaxTry ) WHAT +#define SKIPPER_TRY \ + skipperCounter++ +#define SKIPPER_RST \ + skipperCounter = 0 +//--------------------------------------------------------------------------------// +//--------------------------------------------------------------------------------// +#define DEBUG_PROPERTY_CHANGED(vVARIABLE, PREFIX) // qDebug() << "#" << #vVARIABLE << PREFIX##vVARIABLE; +//--------------------------------------------------------------------------------// +#define PROPERTY_SLOT( vTYPE , vVARIABLE ) \ + protected : \ + /*! \brief Property setter + \details The property setter which update the private variable \n + - if only the value has been changed \n + - or it's the first time property is set. \n + emits the Property notify (...Changed) signal on update. \n + the notify signal (...Changed) passes the new value as its parameter. \n + \param new value + */\ + void vVARIABLE ( const vTYPE & v##vVARIABLE ) { \ + static bool init = false; \ + _##vVARIABLE##Changed = _##vVARIABLE != v##vVARIABLE; \ + if ( !init || _##vVARIABLE##Changed ) { \ + DEBUG_PROPERTY_CHANGED(vVARIABLE, v) \ + init = true; \ + _##vVARIABLE = v##vVARIABLE; \ + emit vVARIABLE##Changed( _##vVARIABLE ); \ + } \ + } +//--------------------------------------------------------------------------------// +#define TRIGGER_SLOT( vTYPE , vVARIABLE ) \ + protected: \ + /*! \brief Trigger setter + \details The Trigger setter which update the private variable \n + with no condition each time the value the passed. \n + emits the Trigger notify (...Triggered) signal after update. \n + the notify signal (...Triggered) passes the new value as its parameter.\n + \param new value + */\ + void vVARIABLE ( const vTYPE & v##vVARIABLE ) { \ + DEBUG_PROPERTY_CHANGED(vVARIABLE, v) \ + _##vVARIABLE##Changed = true; \ + _##vVARIABLE = v##vVARIABLE; \ + emit vVARIABLE##Triggered( _##vVARIABLE ); \ + } +//--------------------------------------------------------------------------------// +#define STATE_SLOT( vTYPE , vVARIABLE ) \ + protected : \ + /*! \brief Property setter + \details The property setter which update the private variable \n + - if only the value has been changed \n + emits the Property notify (...Entered) signal on update. \n + the notify signal (...Entered) passes the new value as its parameter. \n + \param new value + */\ + void vVARIABLE ( const vTYPE & v##vVARIABLE ) { \ + _##vVARIABLE##Changed = _##vVARIABLE != v##vVARIABLE; \ + if ( _##vVARIABLE##Changed ) { \ + DEBUG_PROPERTY_CHANGED(vVARIABLE, v) \ + _##vVARIABLE = v##vVARIABLE; \ + emit vVARIABLE##Entered( _##vVARIABLE ); \ + } \ + } +//--------------------------------------------------------------------------------// +#define PROPERTY_BASE(vTYPE , vVARIABLE , vDEFVALUE, vSIGNAL) \ + /*! \brief Qt Property declaration + \details The Qt Property definition by Q_PROPERTY documentation. + */\ + Q_PROPERTY( vTYPE vVARIABLE \ + READ vVARIABLE \ + WRITE vVARIABLE \ + NOTIFY vVARIABLE##vSIGNAL) \ + Q_SIGNALS: \ + /*! \brief Property notify signal + \details The property notify signal (...Changed) + which will be emitted by property setter + - if only the value has been changed \n + - or it's the first time property is set. \n + \return current value + */\ + void vVARIABLE##vSIGNAL( const vTYPE & v##vVARIABLE ); \ + private: \ + vTYPE _##vVARIABLE = vDEFVALUE; \ + bool _##vVARIABLE##Changed = false; \ + protected: \ + /*! \brief Property getter + \details The property getter which reads the private variable + \return current value + */\ + vTYPE vVARIABLE () const { \ + return _##vVARIABLE ; \ + } +//--------------------------------------------------------------------------------// +#define READONLY_BASE(vTYPE , vVARIABLE , vDEFVALUE, vSIGNAL) \ + /*! \brief Qt Read-Only Property declaration + \details The Qt Property definition by Q_PROPERTY documentation. + */\ + Q_PROPERTY( vTYPE vVARIABLE \ + READ vVARIABLE \ + NOTIFY vVARIABLE##vSIGNAL) \ + Q_SIGNALS: \ + /*! \brief Property notify signal + \details The property notify signal (...Changed) + which will be emitted by property setter + - if only the value has been changed \n + - or it's the first time property is set. \n + \return current value + */\ + void vVARIABLE##vSIGNAL( const vTYPE & v##vVARIABLE ); \ + private: \ + vTYPE _##vVARIABLE = vDEFVALUE; \ + bool _##vVARIABLE##Changed = false; \ + protected: \ + /*! \brief Property getter + \details The property getter which reads the private variable + \return current value + */\ + vTYPE vVARIABLE () const { \ + return _##vVARIABLE ; \ + } +//--------------------------------------------------------------------------------// +#define READONLY( vTYPE , vVARIABLE , vDEFVALUE ) \ + READONLY_BASE( vTYPE , vVARIABLE , vDEFVALUE , Changed ) \ + PROPERTY_SLOT( vTYPE , vVARIABLE) +//--------------------------------------------------------------------------------// +#define PROPERTY( vTYPE , vVARIABLE , vDEFVALUE ) \ + PROPERTY_BASE( vTYPE , vVARIABLE , vDEFVALUE , Changed ) \ + PROPERTY_SLOT( vTYPE , vVARIABLE) +//--------------------------------------------------------------------------------// +#define TRIGGER( vTYPE , vVARIABLE , vDEFVALUE ) \ + PROPERTY_BASE( vTYPE , vVARIABLE , vDEFVALUE , Triggered) \ + TRIGGER_SLOT ( vTYPE , vVARIABLE) +//--------------------------------------------------------------------------------// +#define STATE( vTYPE , vVARIABLE , vDEFVALUE ) \ + PROPERTY_BASE( vTYPE , vVARIABLE , vDEFVALUE , Entered ) \ + STATE_SLOT ( vTYPE , vVARIABLE) +//--------------------------------------------------------------------------------// +#define CONSTANT( vTYPE , vVARIABLE , vDEFVALUE ) \ + /*! \brief Qt Constant Property declaration + \details The Qt Property definition by Q_PROPERTY documentation. + */\ + Q_PROPERTY( vTYPE vVARIABLE \ + READ vVARIABLE \ + CONSTANT) \ + protected: \ + /*! \brief Property getter + \details The property getter which reads the private variable + \return current value + */\ + vTYPE vVARIABLE () const { \ + return vDEFVALUE ; \ + } +//--------------------------------------------------------------------------------// +#define NOTIFIER( vVARIABLE ) \ + Q_SIGNALS: \ + /*! \brief Property notify signal + \details The property notify signal (...Changed) + which will be emitted by property setter + - if only the value has been changed \n + - or it's the first time property is set. \n + \return current value + */\ + void vVARIABLE##Notified( const bool & v##vVARIABLE ); \ + private: \ + bool _##vVARIABLE = false; \ + protected: \ + /*! \brief Property getter + \details The property getter which reads the private variable + \return current value + */\ + bool vVARIABLE () const { \ + return _##vVARIABLE ; \ + } \ + /*! \brief Notifier setter + \details The notifier setter which update the private variable \n + emits the notifier (is...) signal on update. \n + the notify signal (is...) passes the new value as its parameter. \n + \param new value + */\ + void vVARIABLE ( const bool & v##vVARIABLE ) { \ + DEBUG_PROPERTY_CHANGED(vVARIABLE, v) \ + _##vVARIABLE = v##vVARIABLE; \ + emit vVARIABLE##Notified( _##vVARIABLE ); \ + } +//--------------------------------------------------------------------------------// +//--------------------------------------------------------------------------------// +#define ACTION_VIEW_CONNECTION(vTYPE) \ + connect(&_GuiController, SIGNAL(didActionReceive(const vTYPE &)), \ + this, SLOT( onActionReceive(const vTYPE &))); +//--------------------------------------------------------------------------------// +#define ADJUST_VIEW_CONNECTION(vTYPE) \ + connect( this, SIGNAL(didAdjustment (const vTYPE &)), \ + &_GuiController, SLOT( doAdjustment (const vTYPE &))); +//--------------------------------------------------------------------------------// +//--------------------------------------------------------------------------------// +#define ACTION_METHOD_BRIDGE_CONNECTION(vMETHOD, vSOURCE, vTYPE) \ + connect(&vSOURCE, SIGNAL(did##vMETHOD(const vTYPE &)), \ + this , SLOT( on##vMETHOD(const vTYPE &))); +//--------------------------------------------------------------------------------// +#define ACTION_RECEIVE_BRIDGE_CONNECTION(vSOURCE, vTYPE) \ + ACTION_METHOD_BRIDGE_CONNECTION(ActionReceive, vSOURCE, vTYPE) +//--------------------------------------------------------------------------------// +#define ADJUST_TRANSMT_BRIDGE_CONNECTION(vSOURCE, vTYPE) \ + ACTION_METHOD_BRIDGE_CONNECTION(Adjustment , vSOURCE, vTYPE) +//--------------------------------------------------------------------------------// +#define ACTION_RECEIVE_PRIVATE_SLOT(vTYPE) \ +private Q_SLOTS: \ + /*! \brief Bridge slot + \details The bridge slot is for thread safety between classes for received message + and is used to emit its signal to pass the model data to next observer. + \param vData - The model data which has been received. + \note This method is private and the interface is signals only. (starts with 'on') + */\ + void onActionReceive (const vTYPE &vData) { \ + emit didActionReceive(vData); \ } +//--------------------------------------------------------------------------------// +#define ADJUST_TRANSMT_PRIVATE_SLOT_DEFINITION(vTYPE) \ +private Q_SLOTS: \ + /*! \brief Adjustment slot + \details The bridge slot is for thread safety between classes for adjustment messages + and is used to emit its signal to pass the model data to next observer. + \param vData - The model data to be used for adjustment + \note This method is private and the interface is signals only. (starts with 'on') + This slot has to have its specific implementation and is not a bridge (not a signal emitter). + */\ + void onAdjustment (const vTYPE &vData); +//--------------------------------------------------------------------------------// +#define ADJUST_TRANSMT_PRIVATE_SLOT(vTYPE) \ +private Q_SLOTS: \ + /*! \brief Adjustment bridge slot + \details The bridge slot is for thread safety between classes for adjustment messages + and is used to emit its signal to pass the model data to next observer. + \param vData - The model data to be used for adjustment + \note This method is private and the interface is signals only. (starts with 'on') + */\ + void onAdjustment (const vTYPE &vData) { \ + emit didAdjustment( vData); \ + } +//--------------------------------------------------------------------------------// +#define ADJUST_TRANSMT_PUBLIC_SLOT(vTYPE) \ +public Q_SLOTS: \ + /*! \brief Adjustment invocable/exposed slot + \details This slot is able to be called within QML context + when an object of the class is instantiated in QML. + For thread safety it's calling its designated signal to notify observers. + \note This method is public and is the interface. (starts with 'do') + */\ + void doAdjustment (const vTYPE &vData) { \ + emit didAdjustment( vData); \ + } +//--------------------------------------------------------------------------------// +#define ACTION_RECEIVE_SIGNAL(vTYPE) \ +Q_SIGNALS: \ + /*! \brief Receive bridge signal + \details The bridge signal is for thread safety between classes for received message + and is used to be emitted in its slot to pass the model data to next observer. + \param vData - The model data which has been received. + \note This method is public to be exposed to the observers to be able to connect to it as the interface. (starts with 'did') + */\ + void didActionReceive (const vTYPE &vData); +//--------------------------------------------------------------------------------// +#define ADJUST_TRANSMT_SIGNAL(vTYPE) \ +Q_SIGNALS: \ + /*! \brief Adjustment bridge signal + \details The bridge signal is for thread safety between classes for received message + and is used to be emitted in its slot to pass the model data to next observer. + \param vData - The model data which has been received. + \note This method is public to be exposed to the observers to be able to connect to it as the interface. (starts with 'did') + */\ + void didAdjustment (const vTYPE &vData); +//--------------------------------------------------------------------------------// +#define ACTION_RECEIVE_BRIDGE_DEFINITION(vTYPE) \ + \ + ACTION_RECEIVE_PRIVATE_SLOT (vTYPE) \ + ACTION_RECEIVE_SIGNAL (vTYPE) \ +//--------------------------------------------------------------------------------// +#define ADJUST_TRANSMT_BRIDGE_DEFINITION_NOEMIT(vTYPE) \ + \ + ADJUST_TRANSMT_PRIVATE_SLOT_DEFINITION (vTYPE) \ + ADJUST_TRANSMT_SIGNAL (vTYPE) \ +//--------------------------------------------------------------------------------// +#define ADJUST_TRANSMT_BRIDGE_DEFINITION(vTYPE) \ + \ + ADJUST_TRANSMT_PRIVATE_SLOT (vTYPE) \ + ADJUST_TRANSMT_SIGNAL (vTYPE) \ +//--------------------------------------------------------------------------------// +#define ADJUST_TRANSMT_BRIDGE_DEFINITION_PUBLIC(vTYPE) \ + \ + ADJUST_TRANSMT_PUBLIC_SLOT (vTYPE) \ + ADJUST_TRANSMT_SIGNAL (vTYPE) \ +//--------------------------------------------------------------------------------// +#define SAFE_CALL( vMETHOD) \ +public Q_SLOTS : void vMETHOD() { \ + static bool init = false; \ + if ( ! init ) { \ + connect(this, SIGNAL( did##vMETHOD()), \ + this, SLOT( on##vMETHOD())); \ + init = true; \ + } \ + emit did##vMETHOD(); \ + } \ +Q_SIGNALS : void did##vMETHOD(); \ +private Q_SLOTS : void on##vMETHOD(); +//--------------------------------------------------------------------------------// +#define SAFE_CALL_EX( vMETHOD,vTYPE) \ +public Q_SLOTS : void vMETHOD(vTYPE vData) { \ + static bool init = false; \ + if ( ! init ) { \ + connect(this, SIGNAL( did##vMETHOD(vTYPE)), \ + this, SLOT( on##vMETHOD(vTYPE))); \ + init = true; \ + } \ + emit did##vMETHOD( vData); \ + } \ +Q_SIGNALS : void did##vMETHOD(vTYPE); \ +private Q_SLOTS : void on##vMETHOD(vTYPE); +//--------------------------------------------------------------------------------// +#define REGISTER_METATYPE(vTYPE) \ + qRegisterMetaType < vTYPE > (#vTYPE); +//--------------------------------------------------------------------------------// +#define REGISTER_TYPE(vTYPE) \ + qmlRegisterType < vTYPE > (#vTYPE, 0, 1, #vTYPE); +#define GET_VARIABLE_NAME(VARIABLE) (#VARIABLE) +#define DEBUG_TREATMENT_PARAMETER(NAME, VARIABLE) // qDebug() << NAME << VARIABLE; +#define TREATMENT_PARAMETER(TYPE, NAME, DEFVALUE, MIN, MAX, RES) \ +private: \ + TYPE _##NAME = DEFVALUE; \ + TYPE _##NAME##Min = MIN; \ + TYPE _##NAME##Max = MAX; \ + TYPE _##NAME##Res = RES; \ + bool is##NAME##Set = false; \ +protected: \ + Q_PROPERTY(TYPE NAME \ + READ NAME \ + WRITE NAME \ + NOTIFY NAME##Changed) \ + Q_PROPERTY(TYPE NAME##Min \ + READ NAME##Min \ + WRITE NAME##Min \ + NOTIFY NAME##MinChanged) \ + Q_PROPERTY(TYPE NAME##Max \ + READ NAME##Max \ + WRITE NAME##Max \ + NOTIFY NAME##MaxChanged) \ + Q_PROPERTY(TYPE NAME##Res \ + READ NAME##Res \ + WRITE NAME##Res \ + NOTIFY NAME##ResChanged) \ + void NAME(const TYPE &v##NAME) { \ + if ( !is##NAME##Set || _##NAME != v##NAME ) { \ + _##NAME = v##NAME; \ + is##NAME##Set = true; \ + emit NAME##Changed(_##NAME); \ + doUserModifiedParameters(); \ + } \ + DEBUG_TREATMENT_PARAMETER(#NAME, _##NAME) \ + } \ + TYPE NAME##Min() const { return _##NAME##Min; } \ + void NAME##Min(const TYPE &v##NAME##Min) \ + { _##NAME##Min = v##NAME##Min; emit NAME##MinChanged(_##NAME##Min);} \ + TYPE NAME##Max() const { return _##NAME##Max; } \ + void NAME##Max(const TYPE &v##NAME##Max) \ + { _##NAME##Max = v##NAME##Max; emit NAME##MaxChanged(_##NAME##Max);} \ + TYPE NAME##Res() const { return _##NAME##Res; } \ + void NAME##Res(const TYPE &v##NAME##Res) \ + { _##NAME##Res = v##NAME##Res; emit NAME##ResChanged(_##NAME##Res);} \ + TYPE NAME() const { \ + return _##NAME; \ + } \ + void reset_##NAME() { \ + _##NAME = DEFVALUE; \ + is##NAME##Set = false; \ + emit NAME##Changed(_##NAME); \ + } \ +Q_SIGNALS: \ + void NAME##Changed(const TYPE &v##NAME); \ + void NAME##MinChanged(const TYPE &v##NAME); \ + void NAME##MaxChanged(const TYPE &v##NAME); \ + void NAME##ResChanged(const TYPE &v##NAME); \ + void NAME##_ValidationFailed(const QString &reason); -#define SINGLETON_INIT(vCLASS) \ - vCLASS *vCLASS::_instance = nullptr;