Files
qt5-legatus-legacy/Lts/Services/VideoOverlayManagement/avs_interface.h
T
2026-08-13 18:33:10 +02:00

125 lines
2.9 KiB
C++
Executable File

/**
* AVS-Interface for VideoOverlayManagement
* $Id$
* $HeadURL$
* $Author$
* Created by hjl, SLSE, 2016-06-24
*/
#pragma once
#include <QtCore/QObject>
#include <QtNetwork/QHostAddress>
#include "logger.h"
// Forwarddeclarations
class QTcpSocket;
class QTimer;
namespace VideoOverlayManagement
{
enum class AvsIfConnectionState
{
Undefined = 0,
Connected,
Disconnected,
TryReconnect,
ConnectionError,
};
enum class AvsCmdState
{
Ok = 200,
KeepAlive = 298,
BadArguments = 402,
CommandNotStateValid = 455
};
class AvsInterface
: public QObject
{
Q_OBJECT
public:
/**
* Constructor connect to plugboard
* @param[in] enableTryReconnect if true, try reconnection
* @param[in] parent Pointer to parent qObject
*/
AvsInterface(bool enableTryReconnect, QObject *parent = nullptr);
~AvsInterface();
/**
* Connect to AVS RCP_AVA
* @param[in] hostName Hostname or Ip address to get access to AVS
* @param[in] port Ip port to get access to AVS
*/
void start(const QString &hostName, quint16 port);
AvsIfConnectionState getAvsIfState()
{
return m_avsIfConnectionState;
}
/**
* Send data to connected TcpSocket
* @param[in] qba Data to be transfered completed with "\r\n"
*/
bool sendCommand(const QByteArray &qba);
Q_SIGNALS:
/**
* Signals current AVS connection state
*/
void avsIfConnectionState(AvsIfConnectionState);
/**
* Signals current AVS command state
*/
void avsCmdState(AvsCmdState);
/**
* Signals an missing AVS keep-alive
* If the parameter 'enableTryReconnect' is set
* the connection attempting to restore automatically
*/
void avsKeepAliveTimeout();
/**
* Define the signal/slots connects uesd for TcpSocket
*/
protected Q_SLOTS:
void doConnect();
void onConnected();
void onDisonnected();
void onError(QAbstractSocket::SocketError);
void onReadyRead();
void onAvsKeepAliveTimeout();
private: // methode
void tryReconnect();
private: // attributes
QString m_hostName; ///< Hostname or Ip address to get access to AVS
QString m_ipAddressDNS; ///< DNS IP address of AVS
quint16 m_hostPort; ///< Ip port to get access to AVS
qint32 m_waitTime; ///< delay before try reconnection
bool m_enableTryReconnect; ///< if true, enables try reconnection
bool m_tryReconnect; ///< if true, try reconnection
QTimer *m_avsKeepAliveTimer; ///< AVS keep-alive timer
qint32 m_keepAliveTime; ///< AVS keep-alive time intervall in msec
AvsIfConnectionState m_avsIfConnectionState; ///< AVS Interface connection state
QTcpSocket *m_socket; ///< pointer to tcpsocket object
QByteArray m_buffer; ///< data buffer to hold incoming data form tcpsocket
NGL::INGLLogger &m_logger; ///< Interface to the Logging-Facility
};
} // namespace VideoOverlayManagement