2018-12-27 23:11:32 +01:00
|
|
|
#pragma once
|
|
|
|
// qt incl
|
|
|
|
#include <QObject>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QHostInfo>
|
|
|
|
|
|
|
|
#include <bonjour/bonjourrecord.h>
|
|
|
|
|
|
|
|
class BonjourServiceBrowser;
|
|
|
|
class BonjourServiceResolver;
|
|
|
|
class QTimer;
|
|
|
|
|
|
|
|
class BonjourBrowserWrapper : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private:
|
|
|
|
friend class HyperionDaemon;
|
|
|
|
///
|
|
|
|
/// @brief Browse for hyperion services in bonjour, constructed from HyperionDaemon
|
|
|
|
/// Searching for hyperion http service by default
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
BonjourBrowserWrapper(QObject * parent = nullptr);
|
2018-12-27 23:11:32 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Browse for a service
|
|
|
|
///
|
|
|
|
bool browseForServiceType(const QString &serviceType);
|
|
|
|
///
|
|
|
|
/// @brief Get all available sessions
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
QMap<QString, BonjourRecord> getAllServices() { return _hyperionSessions; }
|
2018-12-27 23:11:32 +01:00
|
|
|
|
|
|
|
static BonjourBrowserWrapper* instance;
|
2020-11-14 17:58:56 +01:00
|
|
|
static BonjourBrowserWrapper *getInstance() { return instance; }
|
2018-12-27 23:11:32 +01:00
|
|
|
|
|
|
|
signals:
|
|
|
|
///
|
|
|
|
/// @brief Emits whenever a change happend
|
|
|
|
///
|
2020-11-14 17:58:56 +01:00
|
|
|
void browserChange( const QMap<QString, BonjourRecord> &bRegisters );
|
2018-12-27 23:11:32 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// map of service names and browsers
|
2020-11-14 17:58:56 +01:00
|
|
|
QMap<QString, BonjourServiceBrowser *> _browsedServices;
|
2018-12-27 23:11:32 +01:00
|
|
|
/// Resolver
|
2020-11-14 17:58:56 +01:00
|
|
|
BonjourServiceResolver *_bonjourResolver;
|
2018-12-27 23:11:32 +01:00
|
|
|
|
|
|
|
// contains all current active service sessions
|
2020-11-14 17:58:56 +01:00
|
|
|
QMap<QString, BonjourRecord> _hyperionSessions;
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2020-11-14 17:58:56 +01:00
|
|
|
QString _bonjourCurrentServiceToResolve;
|
2018-12-27 23:11:32 +01:00
|
|
|
/// timer to resolve changes
|
2020-11-14 17:58:56 +01:00
|
|
|
QTimer *_timerBonjourResolver;
|
2018-12-27 23:11:32 +01:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
///
|
|
|
|
/// @brief is called whenever a BonjourServiceBrowser emits change
|
2020-11-14 17:58:56 +01:00
|
|
|
void currentBonjourRecordsChanged( const QList<BonjourRecord> &list );
|
2018-12-27 23:11:32 +01:00
|
|
|
/// @brief new record resolved
|
2020-11-14 17:58:56 +01:00
|
|
|
void bonjourRecordResolved( const QHostInfo &hostInfo, int port );
|
2018-12-27 23:11:32 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief timer slot which updates regularly entries
|
|
|
|
///
|
|
|
|
void bonjourResolve();
|
|
|
|
};
|