89 lines
2.2 KiB
C++
Executable File
89 lines
2.2 KiB
C++
Executable File
/**
|
|
* Communication with A/V system - fm server
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <QObject>
|
|
#include <QTimer>
|
|
#include <QTcpSocket>
|
|
#include <queue>
|
|
|
|
#include "logger.h"
|
|
#include "avm_export.h"
|
|
|
|
namespace AudioVideoManagement
|
|
{
|
|
class AVM_COMMON_EXPORT AVSocket : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
AVSocket(const QString &avsServerHost,
|
|
quint16 avsServerPort,
|
|
NGL::INGLLogger &logger,
|
|
NGL::INGLLogger &loggerIO,
|
|
QObject *parent = nullptr);
|
|
~AVSocket();
|
|
|
|
void connectToAVS() { onConnectToAVS(); }
|
|
|
|
// From TcpServer::Workerbase to properly parse quoted arguments
|
|
// cfroebel 2017-06-19: Made it static public in order to unit-test it.
|
|
static QVector<QByteArray> parseLine(const QByteArray &ba, const int iStart = 0);
|
|
|
|
protected Q_SLOTS:
|
|
virtual void onDisconnected();
|
|
void onError(QAbstractSocket::SocketError error);
|
|
virtual void onReadyRead() = 0;
|
|
void onConnectToAVS();
|
|
void onRcpLogin();
|
|
|
|
protected:
|
|
QString getConnectionString() const;
|
|
bool sendInternal(const QByteArray &cmd);
|
|
|
|
protected:
|
|
bool m_bSuccessfullyLoggedIn;
|
|
bool m_bErrorInTcpComWarnedOnce;
|
|
QTcpSocket *m_avsSocket; //!< Will be deleted and re-created with every new connection.
|
|
QString m_avsServerHost;
|
|
quint16 m_avsServerPort;
|
|
QTimer *m_rcpLoginTimer;
|
|
QTimer *m_reconnectTimer;
|
|
std::queue<QByteArray> m_commandQueueForErrorHandling;
|
|
NGL::INGLLogger &m_logger;
|
|
NGL::INGLLogger &m_loggerIO;
|
|
};
|
|
|
|
|
|
/**
|
|
* Small wrapper around AVSocket in order to avoid that clients need to derive from it.
|
|
*/
|
|
class AVM_COMMON_EXPORT AVSocketWrapper : public AVSocket
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
AVSocketWrapper(const QString &avsServerHost, quint16 avsServerPort, NGL::INGLLogger &logger, NGL::INGLLogger &loggerIO)
|
|
: AVSocket(avsServerHost, avsServerPort, logger, loggerIO)
|
|
{}
|
|
|
|
void send(const QByteArray &cmd) { sendInternal(cmd); }
|
|
void disconnectFromHost() { m_avsSocket->disconnectFromHost(); }
|
|
|
|
signals:
|
|
void disconnected();
|
|
void readyRead(QTcpSocket *socket);
|
|
|
|
private:
|
|
void onDisconnected() override { AVSocket::onDisconnected(); emit disconnected(); }
|
|
void onReadyRead() override { emit readyRead(m_avsSocket); }
|
|
};
|
|
|
|
|
|
} // namespace AudioVideoManagement
|