/** * Communication with A/V system * $Id$ * $HeadURL$ * $Author$ */ #pragma once #include "av_socket.h" #include "exercise_context.h" #include "logger.h" #include #include namespace AudioVideoManagement { class AVControl final : public AVSocket { Q_OBJECT public: enum class BasicOperatingMode { Unknown = -1, Reset = 0, Shutdown = 1, Service = 2, PowerOn = 3 }; Q_ENUM(BasicOperatingMode) enum class OperatingMode { Unknown = -1, PowerOn = 3, Initialization = 4, Recording = 5, Pause = 6, SaveData = 8, Cleanup = 10 }; Q_ENUM(OperatingMode) enum class Commands { WrongSessionPriority = 102, Ok = 200, SessionDisabled = 207, SessionEnabled = 208, Context = 240, BasicOperatingMode = 250, ComponentBasicOperatingMode = 251, OperatingMode = 255, FMServerState = 260, KeppAlive = 298, WrongCommand = 400, BadArguments = 401, CommandTooLong = 403, CommandNotAllowed = 405, CommandNotImplemented = 410, CommandNotStateValid = 455, InternalError = 500, InvalidRCPVersion = 505 }; Q_ENUM(Commands) enum class Component { Unknown = 0, Audio = 1, Video = 2, AudioAndVideo = 3 }; Q_ENUM(Component) public: AVControl(const QString &avsServerHost, quint16 avsServerPort, QObject *parent = nullptr); ~AVControl(); Q_SIGNALS: void operatingModeChanged(const ExerciseContext &context, Component comp, OperatingMode om); void successfullyLoggedIn(); public Q_SLOTS: bool triggerAVUpdate(); bool setOperatingModeForContext(const ExerciseContext &context, OperatingMode om); private Q_SLOTS: void onReadyRead() override; void onSendKeepAlive(); void onCheckKeepAlive(); private: void sendNextPendingCommand(); bool trySendCommand(const boost::optional &ctx, const QByteArray &cmd); void checkBasicOperatingMode(BasicOperatingMode mode); bool setOperatingMode(const ExerciseContext &context, Component component, OperatingMode mode); BasicOperatingMode m_basicOperatingMode; bool m_bWaitingForSwitchContext; time_t m_keepAliveTime; QTimer *m_keepAliveTimer; boost::optional m_currentContext; struct CommandToSend { boost::optional ctx; //!< some commands don't require a context, e.g. SetBasicOperatingMode QByteArray cmd; }; std::queue m_commandsToSend; }; std::ostream &operator <<(std::ostream &stream, AVControl::BasicOperatingMode bom); std::ostream &operator <<(std::ostream &stream, AVControl::OperatingMode om); std::ostream &operator <<(std::ostream &stream, AVControl::Commands cmd); std::ostream &operator <<(std::ostream &stream, AVControl::Component comp); } // namespace AudioVideoManagement