2018-12-30 22:07:53 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <utils/Logger.h>
|
|
|
|
|
|
|
|
class QUdpSocket;
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief The SSDP Server sends and receives (parses) SSDP requests
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
class SSDPServer : public QObject
|
|
|
|
{
|
2018-12-30 22:07:53 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
friend class SSDPHandler;
|
|
|
|
///
|
|
|
|
/// @brief Construct the server, listen on default ssdp address/port with multicast
|
|
|
|
/// @param parent The parent object
|
|
|
|
///
|
|
|
|
SSDPServer(QObject* parent = nullptr);
|
2020-08-08 23:12:43 +02:00
|
|
|
~SSDPServer() override;
|
2018-12-30 22:07:53 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Prepare server after thread start
|
|
|
|
///
|
|
|
|
void initServer();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Start SSDP
|
|
|
|
/// @return false if already running or bind failure
|
|
|
|
///
|
2019-06-05 18:19:08 +02:00
|
|
|
bool start();
|
2018-12-30 22:07:53 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Stop SSDP
|
|
|
|
///
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Send an answer to mSearch requester
|
|
|
|
/// @param st the searchTarget
|
|
|
|
/// @param senderIp Ip address of the sender
|
|
|
|
/// @param senderPort The port of the sender
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
void sendMSearchResponse(const QString& st, const QString& senderIp, quint16 senderPort);
|
2018-12-30 22:07:53 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Send ByeBye notification (on SSDP stop) (repeated 3 times)
|
|
|
|
/// @param st Search target
|
|
|
|
///
|
|
|
|
void sendByeBye(const QString& st);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Send a NOTIFY msg on SSDP startup to notify our presence (repeated 3 times)
|
|
|
|
/// @param st The search target
|
|
|
|
///
|
|
|
|
void sendAlive(const QString& st);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Send a NOTIFY msg as ssdp:update to notify about changes
|
|
|
|
/// @param st The search target
|
|
|
|
///
|
|
|
|
void sendUpdate(const QString& st);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Overwrite description address
|
|
|
|
/// @param addr new address
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
void setDescriptionAddress( const QString &addr ) { _descAddress = addr; }
|
2018-12-30 22:07:53 +01:00
|
|
|
|
2019-08-14 21:19:05 +02:00
|
|
|
///
|
|
|
|
/// @brief Set uuid
|
|
|
|
/// @param uuid The uuid
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
void setUuid( const QString &uuid ) { _uuid = uuid; }
|
2019-08-14 21:19:05 +02:00
|
|
|
|
2018-12-30 22:07:53 +01:00
|
|
|
///
|
|
|
|
/// @brief set new flatbuffer server port
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
void setFlatBufPort( quint16 port ){_fbsPort = QString::number( port ); }
|
2018-12-30 22:07:53 +01:00
|
|
|
|
2019-08-17 09:44:57 +02:00
|
|
|
///
|
|
|
|
/// @brief Get current flatbuffer server port
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
quint16 getFlatBufPort() const
|
|
|
|
{
|
|
|
|
return _fbsPort.toInt();
|
|
|
|
}
|
2019-08-17 09:44:57 +02:00
|
|
|
///
|
2020-10-18 17:05:07 +02:00
|
|
|
/// @brief set new protobuf server port
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
void setProtoBufPort( quint16 port ) { _pbsPort = QString::number( port ); }
|
2020-10-18 17:05:07 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Get current protobuf server port
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
quint16 getProtoBufPort() const { return _pbsPort.toInt(); }
|
2020-10-18 17:05:07 +02:00
|
|
|
///
|
|
|
|
/// @brief set new json server port
|
2019-08-17 09:44:57 +02:00
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
void setJsonServerPort( quint16 port ) { _jssPort = QString::number( port ); }
|
2019-08-17 09:44:57 +02:00
|
|
|
///
|
2020-10-18 17:05:07 +02:00
|
|
|
/// @brief get new json server port
|
2019-08-17 09:44:57 +02:00
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
quint16 getJsonServerPort() const { return _jssPort.toInt(); }
|
2020-10-18 17:05:07 +02:00
|
|
|
///
|
|
|
|
/// @brief set new ssl server port
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
void setSSLServerPort( quint16 port ) { _sslPort = QString::number( port ); }
|
2020-10-18 17:05:07 +02:00
|
|
|
///
|
|
|
|
/// @brief get new ssl server port
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
quint16 getSSLServerPort() const { return _sslPort.toInt(); }
|
2020-10-18 17:05:07 +02:00
|
|
|
|
|
|
|
///
|
2020-02-26 18:54:56 +01:00
|
|
|
/// @brief set new hyperion name
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
void setHyperionName( const QString &name ) { _name = name; }
|
2020-02-26 18:54:56 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief get hyperion name
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
QString getHyperionName() const { return _name; }
|
|
|
|
|
2018-12-30 22:07:53 +01:00
|
|
|
signals:
|
|
|
|
///
|
|
|
|
/// @brief Emits whenever a new SSDP search "man : ssdp:discover" is received along with the service type
|
|
|
|
/// @param target The ST service type
|
|
|
|
/// @param mx Answer with delay in s
|
|
|
|
/// @param address The ip of the caller
|
|
|
|
/// @param port The port of the caller
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
void msearchRequestReceived( const QString &target,
|
|
|
|
const QString &mx,
|
|
|
|
const QString address,
|
|
|
|
quint16 port );
|
2018-12-30 22:07:53 +01:00
|
|
|
|
|
|
|
private:
|
2020-11-14 17:58:56 +01:00
|
|
|
Logger *_log;
|
|
|
|
QUdpSocket *_udpSocket;
|
|
|
|
|
|
|
|
QString _serverHeader, _uuid, _fbsPort, _pbsPort, _jssPort, _sslPort, _name, _descAddress;
|
|
|
|
bool _running;
|
2018-12-30 22:07:53 +01:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void readPendingDatagrams();
|
|
|
|
};
|