You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

99 lines
3.0 KiB

#ifndef USEVENTSENDER_H
#define USEVENTSENDER_H
#include <QObject>
#include <functional>
#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::tuple<quint32, QString,
std::function<void(QList<QVariant>)>,
std::function<void(QList<QVariant>)> > > _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<QVariant> _args;
CommandRequest sendRequest(bool needAck,
ECommandType::eCommandType type,
QString responder,
QList<QVariant> args);
void success(QList<QVariant> valueList);
void failure(QList<QVariant> valueList);
public:
explicit UsEventSender(QString _ownerName);
void sendAsyncRequest(ECommandType::eCommandType type,
QString responder,
QList<QVariant> args,
std::function<void (QList<QVariant>)> successCallback,
std::function<void (QList<QVariant>)> failureCallback);
void sendRequest(ECommandType::eCommandType type,
QVector<QString> r,
QVector<QVariant> args,
void (* cb)(void),
std::function<void(void)> successCallback,
std::function<void(void)> failureCallback){
}
void sendAsyncRequest(ECommandType::eCommandType type,
QString responder,
QList<QVariant> args);
void sendRequest(ECommandType::eCommandType type,
QVector<QString> responder,
QVector<QVariant> args) {
}
const CommandResult sendSyncRequest(ECommandType::eCommandType type,
QString responder,
QList<QVariant> args);
signals:
void commandRequest(const CommandRequest& request);
void exitLoop();
//uncrustify off
public slots:
//uncrustify on
void newCommandResponse(const CommandResponse& response);
};
#endif //USEVENTSENDER_H