/*! * * 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 DeviceModels.h * \author (last) Behrouz NematiPour * \date (last) 01-Jun-2021 * \author (original) Behrouz NematiPour * \date (original) 01-Jun-2021 * */ #pragma once // Qt #include // Project #include "MAbstract.h" #include "types.h" // forward declarations class tst_models; namespace Model { /*! * \brief The MDeviceRequestBase class * \details The base class of the all devices requests models */ class MDeviceRequestBase { protected: /*! * \brief toString * \details the global toString function for all the request message models * which is mainly used for logging and debugging. * \param vStringPrefix - a prefix string to be inserted after senderID (UI) and parameter values list. * This is comma separated. * \param vParameters - list of parameter values of the model as a comma separated string. * \return QString */ static QString toString (const QString &vStringPrefix, const QVariant &vParameters) { QString senderID = "UI,"; return QString(senderID + vStringPrefix + "," + vParameters.toStringList().join(',')); } }; /*! * \brief The MDeviceResponseBase class * \details The base class of the all devices responses models */ class MDeviceResponseBase : public MAbstract { // friends friend class ::tst_models; QVariantList parameters() const override; public: Type_Enum typeText () const override { return Type_Enum::eEvent ; } Unit_Enum unitText () const override { return Unit_Enum::eDV ; } QString infoText () const override { return QString("DeviceBase") ; } struct Data { bool mAccepted = true; /*!< Accepted value of type quint32 extracted out */ quint32 mReason = 0 ; /*!< Reason value of type quint32 extracted out */ }; MDeviceResponseBase () { } bool fromByteArray (const QByteArray &, int * = nullptr) override { return false; /* no conversion needed */ } }; // ------------------------------------------------------------------ class MDeviceBrightnessResponse : MDeviceResponseBase { public: struct Data : MDeviceResponseBase::Data { quint8 mBrightnessPercent = 0; } _data; QString infoText () const override { return QString("DeviceBrightness") ; } Data data () const ; }; class MDeviceBrightnessRequest : public MDeviceRequestBase { public: struct Data { quint8 mBrightnessPercent = 100; } _data; QString toString() { return MDeviceRequestBase::toString("DeviceBrightness", { _data.mBrightnessPercent }); } }; } typedef Model::MDeviceBrightnessRequest ::Data DeviceBrightnessRequestData; typedef Model::MDeviceBrightnessResponse::Data DeviceBrightnessResponseData;