34 lines
960 B
C++
34 lines
960 B
C++
#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
|