first commit
This commit is contained in:
33
socketclient.h
Normal file
33
socketclient.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef SOCKETCLIENT_H
|
||||
#define SOCKETCLIENT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <functional>
|
||||
|
||||
class SocketClient : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SocketClient(const QString& socketPath = "/tmp/vizion_control.sock", QObject *parent = nullptr);
|
||||
|
||||
using ResponseCallback = std::function<void(const QJsonObject&)>;
|
||||
using ErrorCallback = std::function<void(const QString&)>;
|
||||
|
||||
void sendCommand(const QString& command, const QJsonObject& params = QJsonObject(),
|
||||
ResponseCallback onSuccess = nullptr, ErrorCallback onError = nullptr);
|
||||
|
||||
signals:
|
||||
void commandSuccess(const QJsonObject& response);
|
||||
void commandError(const QString& errorMessage);
|
||||
void connectionError(const QString& errorMessage);
|
||||
|
||||
private:
|
||||
QString m_socketPath;
|
||||
QJsonObject executeCommand(const QString& command, const QJsonObject& params);
|
||||
};
|
||||
|
||||
#endif // SOCKETCLIENT_H
|
||||
Reference in New Issue
Block a user