71 lines
2.1 KiB
C++
71 lines
2.1 KiB
C++
#ifndef PARKINGSPACEGUIDEREMOTESERVER_H
|
|
#define PARKINGSPACEGUIDEREMOTESERVER_H
|
|
|
|
#include <atomic>
|
|
#include <functional>
|
|
#include <mutex>
|
|
#include <string>
|
|
|
|
#include <QByteArray>
|
|
#include <QObject>
|
|
#include <QString>
|
|
|
|
#include "IVrConfig.h"
|
|
|
|
class IVrZeroMQPublisher;
|
|
class IVrZeroMQServer;
|
|
class QJsonObject;
|
|
class QUdpSocket;
|
|
|
|
class ParkingSpaceGuideRemoteServer : public QObject
|
|
{
|
|
public:
|
|
using ModelHandler = std::function<bool(const QString& modelType)>;
|
|
using StartHandler = std::function<bool(const QString& modelType)>;
|
|
using StopHandler = std::function<int()>;
|
|
using StatusProvider = std::function<std::string()>;
|
|
using RunningProvider = std::function<bool()>;
|
|
using LogHandler = std::function<void(const QString& message)>;
|
|
|
|
explicit ParkingSpaceGuideRemoteServer(QObject* parent = nullptr);
|
|
~ParkingSpaceGuideRemoteServer() override;
|
|
|
|
bool Start(const RemoteViewConfig& config,
|
|
ModelHandler modelHandler,
|
|
StartHandler startHandler,
|
|
StopHandler stopHandler,
|
|
StatusProvider statusProvider,
|
|
RunningProvider runningProvider,
|
|
LogHandler logHandler);
|
|
void Stop();
|
|
|
|
bool IsRunning() const;
|
|
bool PublishStatus(const std::string& statusJson);
|
|
QString LastError() const;
|
|
|
|
private:
|
|
QByteArray HandleControlMessage(const QByteArray& request);
|
|
void HandleDiscoveryDatagrams();
|
|
QJsonObject BuildServerInfo(const QString& command) const;
|
|
std::string DeviceId() const;
|
|
void SetError(const QString& message);
|
|
|
|
private:
|
|
RemoteViewConfig m_config;
|
|
IVrZeroMQServer* m_controlServer = nullptr;
|
|
IVrZeroMQPublisher* m_statusPublisher = nullptr;
|
|
QUdpSocket* m_discoverySocket = nullptr;
|
|
ModelHandler m_modelHandler;
|
|
StartHandler m_startHandler;
|
|
StopHandler m_stopHandler;
|
|
StatusProvider m_statusProvider;
|
|
RunningProvider m_runningProvider;
|
|
LogHandler m_logHandler;
|
|
std::atomic<bool> m_running{false};
|
|
mutable std::mutex m_publishMutex;
|
|
mutable std::mutex m_errorMutex;
|
|
QString m_lastError;
|
|
};
|
|
|
|
#endif // PARKINGSPACEGUIDEREMOTESERVER_H
|