remove protobuf (part 2)

This commit is contained in:
Paulchen-Panther
2018-12-30 22:07:53 +01:00
parent 559311e18c
commit 38950edf35
54 changed files with 1441 additions and 377 deletions

View File

@@ -0,0 +1,56 @@
#pragma once
#include <utils/Logger.h>
#include <QHostAddress>
class QUdpSocket;
enum searchType{
STY_WEBSERVER,
STY_FLATBUFSERVER
};
///
/// @brief Search for SSDP sessions, used by standalone capture binaries
///
class SSDPDiscover : public QObject
{
Q_OBJECT
public:
SSDPDiscover(QObject* parent = nullptr);
///
/// @brief Search for specified service, results will be returned by signal newService(). Calling this method again will reset all found usns and search again
/// @param st The service to search for
///
void searchForService(const QString& st = "urn:hyperion-project.org:device:basic:1");
///
/// @brief Search for specified searchTarget, the method will block until a server has been found or a timeout happend
/// @param type The address type one of struct searchType
/// @param st The service to search for
/// @param timeout_ms The timeout in ms
/// @return The address+port of webserver or empty if timed out
///
const QString getFirstService(const searchType& type = STY_WEBSERVER,const QString& st = "urn:hyperion-project.org:device:basic:1", const int& timeout_ms = 3000);
signals:
///
/// @brief Emits whenever a new service has ben found, search started with searchForService()
/// @param webServer The address+port of webserver "192.168.0.10:8090"
///
void newService(const QString webServer);
private slots:
void readPendingDatagrams();
private:
void sendSearch(const QString& st);
private:
Logger* _log;
QUdpSocket* _udpSocket;
QString _searchTarget;
QStringList _usnList;
};

View File

@@ -0,0 +1,81 @@
#pragma once
#include <ssdp/SSDPServer.h>
#include <QNetworkConfiguration>
// utils
#include <utils/settings.h>
class WebServer;
class QNetworkConfigurationManager;
///
/// Manage SSDP discovery. SimpleServiceDisoveryProtocol is the discovery subset of UPnP. Implemented is spec V1.0.
/// As SSDP requires a webserver, this class depends on it
/// UPnP 1.0: spec: http://upnp.org/specs/arch/UPnP-arch-DeviceArchitecture-v1.0.pdf
///
class SSDPHandler : public SSDPServer{
Q_OBJECT
public:
SSDPHandler(WebServer* webserver, const quint16& flatBufPort, QObject * parent = nullptr);
public slots:
///
/// @brief Init SSDP after thread start
///
void initServer();
///
/// @brief get state changes from webserver
///
void handleWebServerStateChange(const bool newState);
///
/// @brief Handle settings update from Hyperion Settingsmanager emit
/// @param type settingyType from enum
/// @param config configuration object
///
void handleSettingsUpdate(const settings::type& type, const QJsonDocument& config);
private:
///
/// @brief Build http url for current ip:port/desc.xml
///
const QString getDescAddress();
///
/// @brief Get the base address
///
const QString getBaseAddress();
///
/// @brief Build the ssdp description (description.xml)
///
const QString buildDesc();
///
/// @brief Get the local address of interface
/// @return the address, might be empty
///
const QString getLocalAddress();
private slots:
///
/// @brief Handle the mSeach request from SSDPServer
/// @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
///
void handleMSearchRequest(const QString& target, const QString& mx, const QString address, const quint16 & port);
void handleNetworkConfigurationChanged(const QNetworkConfiguration &config);
private:
WebServer* _webserver;
QString _localAddress;
QNetworkConfigurationManager* _NCA;
quint16 _flatbufPort;
};

98
include/ssdp/SSDPServer.h Normal file
View File

@@ -0,0 +1,98 @@
#pragma once
#include <utils/Logger.h>
class QUdpSocket;
///
/// @brief The SSDP Server sends and receives (parses) SSDP requests
///
class SSDPServer : public QObject {
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);
virtual ~SSDPServer();
///
/// @brief Prepare server after thread start
///
void initServer();
///
/// @brief Start SSDP
/// @return false if already running or bind failure
///
const bool start();
///
/// @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
///
void sendMSearchResponse(const QString& st, const QString& senderIp, const quint16& senderPort);
///
/// @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
///
void setDescriptionAddress(const QString& addr) { _descAddress = addr; };
///
/// @brief set new flatbuffer server port
///
void setFlatBufPort(const quint16& port) { _fbsPort = QString::number(port); };
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
///
void msearchRequestReceived(const QString& target, const QString& mx, const QString address, const quint16 & port);
private:
Logger* _log;
QUdpSocket* _udpSocket;
QString _serverHeader;
QString _uuid;
QString _fbsPort;
QString _descAddress;
bool _running;
private slots:
void readPendingDatagrams();
};