#ifndef USEVENTSENDER_H #define USEVENTSENDER_H #include #include #include "model/ultrasoundModule/type/CommandRequest.h" #include "model/ultrasoundModule/type/CommandResponse.h" #include "model/ultrasoundModule/type/CommandResult.h" #include "model/ultrasoundModule/type/ECommandType.h" #include "config/Configuration.h" /*************************************************************************************************/ //Helper macros #define US_EVENT_SENDER(ACCESS) \ ACCESS: \ UsEventSender* _eventSender; \ public: \ UsEventSender* getEventSender() { return _eventSender; } \ #define US_EVENT_SENDER_INSTANTIATE \ _eventSender = new UsEventSender(metaObject()->className()) /*************************************************************************************************/ /** * @brief The class is responsible for sending commands * @details This class with help of \see UsEventReceiver form the communication channel for commands * between all \see US_MODULE s * @author Hessamoddin Hediyehloo(H-4nd-H) * @date 2019/8/5(1398/5/14) */ /*************************************************************************************************/ class UsEventSender : public QObject { Q_OBJECT private: QList)>, std::function)> > > _requestTable; quint32 _id = 0; QString _ownerName; //In contradiction to the composition rule, //But this add a level of safety to app without calling //actual functions of parent bool _result; QList _args; CommandRequest sendRequest(bool needAck, ECommandType::eCommandType type, QString responder, QList args); void success(QList valueList); void failure(QList valueList); public: explicit UsEventSender(QString _ownerName); void sendAsyncRequest(ECommandType::eCommandType type, QString responder, QList args, std::function)> successCallback, std::function)> failureCallback); void sendRequest(ECommandType::eCommandType type, QVector r, QVector args, void (* cb)(void), std::function successCallback, std::function failureCallback){ } void sendAsyncRequest(ECommandType::eCommandType type, QString responder, QList args); void sendRequest(ECommandType::eCommandType type, QVector responder, QVector args) { } const CommandResult sendSyncRequest(ECommandType::eCommandType type, QString responder, QList args); signals: void commandRequest(const CommandRequest& request); void exitLoop(); //uncrustify off public slots: //uncrustify on void newCommandResponse(const CommandResponse& response); }; #endif //USEVENTSENDER_H