/*! * * 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 VDeviceGlobals.h * \author (last) Behrouz NematiPour * \date (last) 01-Jun-2021 * \author (original) Behrouz NematiPour * \date (original) 01-Jun-2021 * */ #pragma once // Qt // Project #include "StorageGlobals.h" namespace Device { const QString _scriptsFolder = Storage::Scripts_Path_Name; } /* DEVICE ATTRIBUTE PROPERTY DEFINITION */ // The FLC in vATTRIBUTEFLC means First Letter Capital #define ATTRIBUTE( vTYPE, vATTRIBUTE, vDEFAULT, vATTRIBUTEFLC) \ private: \ /*! the private property member variable */ \ vTYPE _##vATTRIBUTE = vDEFAULT; \ /*! the property definition */ \ Q_PROPERTY( vTYPE vATTRIBUTE \ READ vATTRIBUTE /*! it shall only be called in bg by qml */ \ WRITE qml##vATTRIBUTE \ NOTIFY vATTRIBUTE##Changed) \ /*! the READ/getter method */ \ vTYPE vATTRIBUTE ( ) { \ return _##vATTRIBUTE; \ } \ /*! the WRITE method and it shall only be called in bg by qml */ \ void qml##vATTRIBUTE (const vTYPE & v##vATTRIBUTE ) { \ /*! This write method is not changing the actual property, And instead will send only a request to change to device, and if only device successfully changes, it will notify the view */ \ vATTRIBUTE##Request ( v##vATTRIBUTE ); \ } \ /*! the response write method and can be used in c++ response update */ \ void vATTRIBUTE (const vTYPE & v##vATTRIBUTE ) { \ if ( _##vATTRIBUTE != v##vATTRIBUTE ) { \ _##vATTRIBUTE = v##vATTRIBUTE ; \ emit vATTRIBUTE##Changed ( v##vATTRIBUTE ); \ } \ } \ public Q_SLOTS : \ /*! \ * \brief VDevice::doInit \ * \details the slot to be called to initialize the attribute. }\ */ \ void doInit##vATTRIBUTEFLC ( ); \ Q_SIGNALS: /*! the signals for property bindings(Changed) and communications */ \ void vATTRIBUTE##Changed (const vTYPE & v##vATTRIBUTE ); \ private : \ /*! \ * \brief VDevice::Request \ * \details The slot which will be called in case \ * the attribute value has been updated in the QML. \ * The updated value is wrapped in the corresponding model \ * and will be used to call the assigned script eventually. \ */ \ void vATTRIBUTE##Request (const vTYPE & v##vATTRIBUTE ); \ Q_SIGNALS : \ void didAttributeRequest (const Device##vATTRIBUTEFLC##RequestData &vData ); \ private Q_SLOTS : \ /*! \ * \brief VDevice::onAttributeResponse \ * \details The slot which will be called in case the updated value for the attribute\ * has been receive by the output of designated script. \ * \param vData - the data model containing the values. \ */ \ void onAttributeResponse(const Device##vATTRIBUTEFLC##ResponseData &vData ); \ private : /* ---------------------------- DEVICE DEFINITIONS */ /* ---------------------------- DEV */ #define DEVICE_DEV_PARENT( vATTRIBUTEFLC ) \ _process##vATTRIBUTEFLC .setParent(this); #define DEVICE_DEV_DEFINITION( vATTRIBUTEFLC ) \ QProcess _process##vATTRIBUTEFLC; \ Model::MDevice##vATTRIBUTEFLC##Response _device##vATTRIBUTEFLC##Response; \ Model::MDevice##vATTRIBUTEFLC##Request _device##vATTRIBUTEFLC##Request ; \ Q_SIGNALS : void didAttributeResponse (const Device##vATTRIBUTEFLC##ResponseData &); \ private Q_SLOTS : \ /*! \ * \brief DeviceController::onAttributeRequest \ * \details This slot will be called in case the attribute is updated in the QML, \ * to start the corresponding process and call the script assigned to it. \ */ \ void onAttributeRequest (const Device##vATTRIBUTEFLC##RequestData &vData); \ /*! \ * \brief DeviceController::onProcessExitCode \ * \details The slot which is being called once the started process is returning a value \ * as an exit code, probably from within the called script \ * \param vExitCode - the returned exit code \ * \param vStatus - the status of the process \ */ \ void onProcess##vATTRIBUTEFLC##ExitCode(int vExitCode, QProcess::ExitStatus vStatus); \ private : #define DEVICE_DEV_INIT_CONNECTIONS( vATTRIBUTEFLC ) \ /* App -> Dev //TODO: Add the error LOG connection */ \ connect(&_ApplicationController , SIGNAL(didAttributeRequest(const Device##vATTRIBUTEFLC##RequestData &)), \ this , SLOT( onAttributeRequest(const Device##vATTRIBUTEFLC##RequestData &))); \ connect(&_process##vATTRIBUTEFLC, SIGNAL( finished(int, QProcess::ExitStatus)), \ this, SLOT(onProcess##vATTRIBUTEFLC##ExitCode(int, QProcess::ExitStatus))); /* ---------------------------- APP */ #define DEVICE_APP_BRIDGE_DEFINITION( vATTRIBUTEFLC ) \ Q_SIGNALS : void didAttributeRequest (const Device##vATTRIBUTEFLC##RequestData &); \ private Q_SLOTS : void onAttributeRequest (const Device##vATTRIBUTEFLC##RequestData &vData) { \ /* this is a bridge only if it is required later can be removed and implemented */ \ emit didAttributeRequest(vData); /* Gui -> App */ \ } \ Q_SIGNALS : void didAttributeResponse(const Device##vATTRIBUTEFLC##ResponseData &); \ private Q_SLOTS : void onAttributeResponse(const Device##vATTRIBUTEFLC##ResponseData &vData) { \ /* this is a bridge only if it is required later can be removed and implemented */ \ emit didAttributeResponse(vData); /* Gui <- App */ \ } \ private : #define DEVICE_APP_INIT_CONNECTIONS( vATTRIBUTEFLC ) \ /* Gui -> App */ \ connect(&_GuiController , SIGNAL(didAttributeRequest (const Device##vATTRIBUTEFLC##RequestData &)), \ this , SLOT( onAttributeRequest (const Device##vATTRIBUTEFLC##RequestData &))); \ /* App <- Dev */ \ connect(&_DeviceController , SIGNAL(didAttributeResponse(const Device##vATTRIBUTEFLC##ResponseData &)), \ this , SLOT( onAttributeResponse(const Device##vATTRIBUTEFLC##ResponseData &))); /* ---------------------------- GUI */ #define DEVICE_GUI_BRIDGE_DEFINITION( vATTRIBUTEFLC ) \ Q_SIGNALS : void didAttributeRequest (const Device##vATTRIBUTEFLC##RequestData &); \ public Q_SLOTS : void doAttributeRequest (const Device##vATTRIBUTEFLC##RequestData &vData) { \ /* this is a bridge only if it is required later can be removed and implemented */ \ emit didAttributeRequest(vData); /* Gui -> App */ \ } \ Q_SIGNALS : void didAttributeResponse(const Device##vATTRIBUTEFLC##ResponseData &); \ public Q_SLOTS : void onAttributeResponse(const Device##vATTRIBUTEFLC##ResponseData &vData) { \ /* this is a bridge only if it is required later can be removed and implemented */ \ emit didAttributeResponse(vData); /* Gui <- App */ \ } \ private : #define DEVICE_GUI_INIT_CONNECTIONS( vATTRIBUTEFLC ) \ /* Gui <- App */ \ connect(&_ApplicationController, SIGNAL(didAttributeResponse(const Device##vATTRIBUTEFLC##ResponseData &)), \ this , SLOT( onAttributeResponse(const Device##vATTRIBUTEFLC##ResponseData &))); /* ---------------------------- VIEW */ #define DEVICE_VIEW_INIT_CONNECTIONS( vATTRIBUTEFLC ) \ /* to convert the value to the model and emit the signal to go to the controller (Qml -> View) */ \ connect(this , SIGNAL(didAttributeRequest (const Device##vATTRIBUTEFLC##RequestData &)), \ &_GuiController , SLOT( doAttributeRequest (const Device##vATTRIBUTEFLC##RequestData &))); \ /* View <- Gui */ \ connect(&_GuiController , SIGNAL(didAttributeResponse(const Device##vATTRIBUTEFLC##ResponseData &)), \ this , SLOT( onAttributeResponse(const Device##vATTRIBUTEFLC##ResponseData &))); /* ---------------------------- DEVICE DEFINITIONS LISTS */ /* Please list all the device attributes here for each list */ /* ---------------------------- DEV */ #define DEVICE_DEV_PARENT_LIST \ DEVICE_DEV_PARENT ( Brightness ) \ DEVICE_DEV_PARENT ( BluetoothPairedReset ) \ DEVICE_DEV_PARENT ( BluetoothPairedQuery ) \ #define DEVICE_DEV_INIT_CONNECTIONS_LIST \ DEVICE_DEV_INIT_CONNECTIONS ( Brightness ) \ DEVICE_DEV_INIT_CONNECTIONS ( BluetoothPairedReset ) \ DEVICE_DEV_INIT_CONNECTIONS ( BluetoothPairedQuery ) \ #define DEVICE_DEV_DEFINITION_LIST \ DEVICE_DEV_DEFINITION ( Brightness ) \ DEVICE_DEV_DEFINITION ( BluetoothPairedReset ) \ DEVICE_DEV_DEFINITION ( BluetoothPairedQuery ) \ /* ---------------------------- APP */ #define DEVICE_APP_INIT_CONNECTIONS_LIST \ DEVICE_APP_INIT_CONNECTIONS ( Brightness ) \ DEVICE_APP_INIT_CONNECTIONS ( BluetoothPairedReset ) \ DEVICE_APP_INIT_CONNECTIONS ( BluetoothPairedQuery ) \ #define DEVICE_APP_BRIDGE_DEFINITION_LIST \ DEVICE_APP_BRIDGE_DEFINITION( Brightness ) \ DEVICE_APP_BRIDGE_DEFINITION( BluetoothPairedReset ) \ DEVICE_APP_BRIDGE_DEFINITION( BluetoothPairedQuery ) \ /* ---------------------------- GUI */ #define DEVICE_GUI_BRIDGE_DEFINITION_LIST \ DEVICE_GUI_BRIDGE_DEFINITION( Brightness ) \ DEVICE_GUI_BRIDGE_DEFINITION( BluetoothPairedReset ) \ DEVICE_GUI_BRIDGE_DEFINITION( BluetoothPairedQuery ) \ #define DEVICE_GUI_INIT_CONNECTIONS_LIST \ DEVICE_GUI_INIT_CONNECTIONS ( Brightness ) \ DEVICE_GUI_INIT_CONNECTIONS ( BluetoothPairedReset ) \ DEVICE_GUI_INIT_CONNECTIONS ( BluetoothPairedQuery ) \ /* ---------------------------- VIEW */ #define DEVICE_VIEW_INIT_CONNECTIONS_LIST \ DEVICE_VIEW_INIT_CONNECTIONS( Brightness ) \ DEVICE_VIEW_INIT_CONNECTIONS( BluetoothPairedReset ) \ DEVICE_VIEW_INIT_CONNECTIONS( BluetoothPairedQuery ) \