Continues migration with DDS, Common
This commit is contained in:
1 parent
9b15cee841
commit
fa48db111e
668 files changed
+111841
-2
No files matched your search
@@ -0,0 +1,123 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef REQUEST_HELPER_WITH_GUI
|
||||
#include <LtsUtilsGuiDds/ltsutilsguidds_export.h>
|
||||
#define LTSUTILSGUIDDS_INTERNAL_EXPORT LTSUTILSGUIDDS_EXPORT
|
||||
#else
|
||||
#include <LtsUtilsGuiDds/ltsutilsdds_export.h>
|
||||
#define LTSUTILSGUIDDS_INTERNAL_EXPORT LTSUTILSDDS_EXPORT
|
||||
#endif
|
||||
|
||||
#include <DDS/Core/function_reply_object.h>
|
||||
#include <DDS/Core/core.hpp>
|
||||
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
#include <QPair>
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace LtsUtils
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
dds::core::optional<T> toOptional(T inVal)
|
||||
{
|
||||
return inVal != T() ? dds::core::optional<T>(inVal) : dds::core::optional<T>();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
dds::core::optional<T> optional()
|
||||
{
|
||||
return dds::core::optional<T>();
|
||||
}
|
||||
|
||||
|
||||
class LTSUTILSGUIDDS_INTERNAL_EXPORT RequestHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static bool s_debug;
|
||||
|
||||
explicit RequestHelper(QObject *parent = nullptr, bool quiet = false,
|
||||
|
||||
const std::function<void (void)> &success = [](){},
|
||||
const std::function<void (void)> &failure = [](){});
|
||||
~RequestHelper() = default;
|
||||
|
||||
bool quiet() const { return m_quiet; }
|
||||
void setQuiet(bool quiet) { m_quiet = quiet; }
|
||||
void addRequest(const std::function<int64_t()> &requestFunction,
|
||||
const std::function<void(const Core::FunctionReply &baseReply)> &baseReplyHandler = nullptr);
|
||||
bool startRequests();
|
||||
|
||||
|
||||
bool startSingleRequest(const std::function<int64_t(void)> &requestFunction,
|
||||
const std::function<void(const Core::FunctionReply &baseReply)> &baseReplyHandler = nullptr
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
void startSingleBackgroundRequest(const std::function<int64_t()> &requestFunction,
|
||||
const std::function<void(const Core::FunctionReply &baseReply)> &baseReplyHandler = nullptr);
|
||||
|
||||
|
||||
void startBackgroundRequests();
|
||||
|
||||
bool requestReply(const Core::FunctionReply &baseReply);
|
||||
bool requestReply(const Core::FunctionReplyObject &replyObject);
|
||||
|
||||
|
||||
|
||||
bool hasRequests() const { return !m_requestFunctions.isEmpty(); }
|
||||
|
||||
|
||||
|
||||
|
||||
int getRepliedId() const { return m_repliedId; }
|
||||
|
||||
|
||||
|
||||
QString getErrorString() const { return m_errorString; }
|
||||
|
||||
|
||||
|
||||
void setCustomWaitMessage(const QString &customWaitMessage);
|
||||
|
||||
bool failed() const { return m_failed; }
|
||||
void failure();
|
||||
|
||||
private:
|
||||
using RequestFunctionContainer = QPair<std::function<int64_t()>, std::function<void(const Core::FunctionReply &)>>;
|
||||
|
||||
QVector<RequestFunctionContainer> m_requestFunctions;
|
||||
bool m_failed;
|
||||
int m_repliedId;
|
||||
std::function<void(const Core::FunctionReply &)> m_singleRequestCustomFunctionReply;
|
||||
bool m_quiet;
|
||||
bool m_blockingCall;
|
||||
std::function<void (void)> m_successFn;
|
||||
std::function<void (void)> m_failureFn;
|
||||
QString m_errorString;
|
||||
QString m_customWaitMessage;
|
||||
|
||||
void done();
|
||||
bool _requestReply(const Core::FunctionReplyObject &fro, const Core::FunctionReply *baseReply);
|
||||
|
||||
signals:
|
||||
void signalNextRequest();
|
||||
void signalQuitLoop();
|
||||
void signalSuccess();
|
||||
void signalFailed();
|
||||
|
||||
private slots:
|
||||
void slotNextRequest();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user