45 lines
1.3 KiB
C++
45 lines
1.3 KiB
C++
#pragma once
|
|||
|
|
#include <QObject>
|
||
|
|
#include <QJsonObject>
|
||
|
|
#include <QHash>
|
||
|
|
#include <QSet>
|
||
|
|
#include <QQueue>
|
||
|
|
#include <QByteArray>
|
||
|
|
|
||
|
|
class QLocalServer;
|
||
|
|
class QLocalSocket;
|
||
|
|
|
||
|
|
// Lives entirely on its own QThread. Camera/UI work is delivered by queued signals.
|
||
|
|
class VisionIpcServer : public QObject
|
||
|
|
{
|
||
|
|
Q_OBJECT
|
||
|
|
public:
|
||
|
|
explicit VisionIpcServer(QObject* parent = nullptr);
|
||
|
|
public slots:
|
||
|
|
void listen(const QString& name);
|
||
|
|
void close();
|
||
|
|
void setBackendState(const QJsonObject& state);
|
||
|
|
void finish(const QJsonObject& result);
|
||
|
|
signals:
|
||
|
|
void commandReceived(const QJsonObject& request);
|
||
|
|
void controllerChanged(bool attached);
|
||
|
|
void fatalError(const QString& message);
|
||
|
|
private:
|
||
|
|
void read();
|
||
|
|
void dispatch(const QJsonObject& request);
|
||
|
|
void send(QJsonObject reply, bool remember = true);
|
||
|
|
QJsonObject reply(const QJsonObject& request, const QString& status,
|
||
|
|
const QString& code = QString(), const QString& message = QString()) const;
|
||
|
|
QLocalServer* m_server = nullptr;
|
||
|
|
QLocalSocket* m_socket = nullptr;
|
||
|
|
QByteArray m_buffer;
|
||
|
|
QString m_session;
|
||
|
|
QJsonObject m_state;
|
||
|
|
QJsonObject m_active;
|
||
|
|
bool m_terminal = false;
|
||
|
|
bool m_dispatchPending = false;
|
||
|
|
QHash<QString,QJsonObject> m_replies;
|
||
|
|
QSet<QString> m_seen;
|
||
|
|
QQueue<QString> m_replyOrder;
|
||
|
|
};
|