2018-12-30 22:07:53 +01:00
# pragma once
# include <utils/Logger.h>
# include <QHostAddress>
class QUdpSocket ;
2020-06-28 23:05:32 +02:00
enum class searchType {
2018-12-30 22:07:53 +01:00
STY_WEBSERVER ,
2019-08-17 09:44:57 +02:00
STY_FLATBUFSERVER ,
STY_JSONSERVER
2018-12-30 22:07:53 +01:00
} ;
///
2020-06-28 23:05:32 +02:00
/// @brief Search for SSDP sessions, used by stand-alone capture binaries
2018-12-30 22:07:53 +01:00
///
class SSDPDiscover : public QObject
{
Q_OBJECT
public :
2020-06-28 23:05:32 +02:00
2018-12-30 22:07:53 +01:00
SSDPDiscover ( QObject * parent = nullptr ) ;
///
2020-06-28 23:05:32 +02:00
/// @brief Search for specified service, results will be returned by signal newService(). Calling this method again will reset all found urns and search again
2018-12-30 22:07:53 +01:00
/// @param st The service to search for
///
2020-06-28 23:05:32 +02:00
void searchForService ( const QString & st = " urn:hyperion-project.org:device:basic:1 " ) ;
2018-12-30 22:07:53 +01:00
///
2020-06-28 23:05:32 +02:00
/// @brief Search for specified searchTarget, the method will block until a server has been found or a timeout happened
2018-12-30 22:07:53 +01:00
/// @param type The address type one of struct searchType
/// @param st The service to search for
/// @param timeout_ms The timeout in ms
2020-06-28 23:05:32 +02:00
/// @return The address+port of web-server or empty if timed out
2018-12-30 22:07:53 +01:00
///
2020-06-28 23:05:32 +02:00
const QString getFirstService ( const searchType & type = searchType : : STY_WEBSERVER , const QString & st = " urn:hyperion-project.org:device:basic:1 " , const int & timeout_ms = 3000 ) ;
2018-12-30 22:07:53 +01:00
signals :
///
2020-06-28 23:05:32 +02:00
/// @brief Emits whenever a new service has been found, search started with searchForService()
///
/// @param webServer The address+port of web-server "192.168.0.10:8090"
2018-12-30 22:07:53 +01:00
///
2020-06-28 23:05:32 +02:00
void newService ( const QString & webServer ) ;
2018-12-30 22:07:53 +01:00
private slots :
void readPendingDatagrams ( ) ;
private :
2020-06-28 23:05:32 +02:00
///
/// @brief Execute ssdp discovery request
///
/// @param[in] st Search Target
///
void sendSearch ( const QString & st ) ;
2018-12-30 22:07:53 +01:00
private :
2020-06-28 23:05:32 +02:00
2018-12-30 22:07:53 +01:00
Logger * _log ;
QUdpSocket * _udpSocket ;
QString _searchTarget ;
QStringList _usnList ;
} ;