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

@@ -56,7 +56,7 @@ public:
///
/// @param message the incoming message as string
///
void handleMessage(const QString & message, const QString& httpAuthHeader = "");
void handleMessage(const QString & message);
public slots:
/// _timer_ledcolors requests ledcolor updates (if enabled)

View File

@@ -28,23 +28,29 @@ class FlatBufferConnection : public QObject
public:
///
/// Constructor
///
/// @brief Constructor
/// @param address The address of the Hyperion server (for example "192.168.0.32:19444)
/// @param skipReply If true skip reply
///
FlatBufferConnection(const QString & address);
FlatBufferConnection(const QString& origin, const QString & address, const int& priority, const bool& skipReply);
///
/// Destructor
/// @brief Destructor
///
~FlatBufferConnection();
/// Do not read reply messages from Hyperion if set to true
/// @brief Do not read reply messages from Hyperion if set to true
void setSkipReply(const bool& skip);
///
/// Set all leds to the specified color
/// @brief Register a new priority with given origin
/// @param origin The user friendly origin string
/// @param priority The priority to register
///
void setRegister(const QString& origin, int priority);
///
/// @brief Set all leds to the specified color
/// @param color The color
/// @param priority The priority
/// @param duration The duration in milliseconds
@@ -52,64 +58,63 @@ public:
void setColor(const ColorRgb & color, int priority, int duration = 1);
///
/// Set the leds according to the given image (assume the image is stretched to the display size)
///
/// @param image The image
/// @param priority The priority
/// @param duration The duration in milliseconds
///
void setImage(const Image<ColorRgb> & image, int priority, int duration = -1);
///
/// Clear the given priority channel
///
/// @brief Clear the given priority channel
/// @param priority The priority
///
void clear(int priority);
///
/// Clear all priority channels
/// @brief Clear all priority channels
///
void clearAll();
///
/// Send a command message and receive its reply
///
/// @brief Send a command message and receive its reply
/// @param message The message to send
///
void sendMessage(const uint8_t* buffer, uint32_t size);
public slots:
///
/// @brief Set the leds according to the given image
/// @param image The image
///
void setImage(const Image<ColorRgb> &image);
private slots:
/// Try to connect to the Hyperion host
///
/// @brief Try to connect to the Hyperion host
///
void connectToHost();
///
/// Slot called when new data has arrived
/// @brief Slot called when new data has arrived
///
void readData();
signals:
///
/// emits when a new videoMode was requested from flatbuf client
/// @brief emits when a new videoMode was requested from flatbuf client
///
void setVideoMode(const VideoMode videoMode);
private:
///
/// Parse a reply message
///
/// @brief Parse a reply message
/// @param reply The received reply
///
/// @return true if the reply indicates success
///
bool parseReply(const flatbuf::HyperionReply * reply);
bool parseReply(const hyperionnet::Reply *reply);
private:
/// The TCP-Socket with the connection to the server
QTcpSocket _socket;
QString _origin;
int _priority;
/// Host address
QString _host;
@@ -124,4 +129,6 @@ private:
Logger * _log;
flatbuffers::FlatBufferBuilder _builder;
bool _registered;
};

View File

@@ -24,8 +24,8 @@ public:
public slots:
///
/// @brief Handle settings update
/// @param type The type from enum
/// @param config The configuration
/// @param type The type from enum
/// @param config The configuration
///
void handleSettingsUpdate(const settings::type& type, const QJsonDocument& config);

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();
};

View File

@@ -21,7 +21,6 @@ enum Components
COMP_COLOR,
COMP_IMAGE,
COMP_EFFECT,
COMP_PROTOSERVER,
COMP_LEDDEVICE,
COMP_FLATBUFSERVER
};
@@ -41,7 +40,6 @@ inline const char* componentToString(Components c)
case COMP_COLOR: return "Solid color";
case COMP_EFFECT: return "Effect";
case COMP_IMAGE: return "Image";
case COMP_PROTOSERVER: return "Proto Server";
case COMP_LEDDEVICE: return "LED device";
case COMP_FLATBUFSERVER: return "Image Receiver";
default: return "";
@@ -63,7 +61,6 @@ inline const char* componentToIdString(Components c)
case COMP_COLOR: return "COLOR";
case COMP_EFFECT: return "EFFECT";
case COMP_IMAGE: return "IMAGE";
case COMP_PROTOSERVER: return "PROTOSERVER";
case COMP_LEDDEVICE: return "LEDDEVICE";
case COMP_FLATBUFSERVER: return "FLATBUFSERVER";
default: return "";
@@ -84,7 +81,6 @@ inline Components stringToComponent(QString component)
if (component == "COLOR") return COMP_COLOR;
if (component == "EFFECT") return COMP_EFFECT;
if (component == "IMAGE") return COMP_IMAGE;
if (component == "PROTOSERVER") return COMP_PROTOSERVER;
if (component == "LEDDEVICE") return COMP_LEDDEVICE;
if (component == "FLATBUFSERVER") return COMP_FLATBUFSERVER;
return COMP_INVALID;

View File

@@ -240,7 +240,7 @@ public:
///
/// get size of buffer
//
ssize_t size()
ssize_t size() const
{
return _width * _height * sizeof(Pixel_T);
}

View File

@@ -23,7 +23,6 @@ enum type {
LEDCONFIG,
LEDS,
LOGGER,
PROTOSERVER,
SMOOTHING,
UDPLISTENER,
WEBSERVER,
@@ -57,7 +56,6 @@ inline QString typeToString(const type& type)
case LEDCONFIG: return "ledConfig";
case LEDS: return "leds";
case LOGGER: return "logger";
case PROTOSERVER: return "protoServer";
case SMOOTHING: return "smoothing";
case UDPLISTENER: return "udpListener";
case WEBSERVER: return "webConfig";
@@ -90,7 +88,6 @@ inline type stringToType(const QString& type)
else if (type == "ledConfig") return LEDCONFIG;
else if (type == "leds") return LEDS;
else if (type == "logger") return LOGGER;
else if (type == "protoServer") return PROTOSERVER;
else if (type == "smoothing") return SMOOTHING;
else if (type == "udpListener") return UDPLISTENER;
else if (type == "webConfig") return WEBSERVER;

View File

@@ -5,7 +5,7 @@
#include <QString>
#include <QJsonDocument>
// utils include
// hyperion / utils
#include <utils/Logger.h>
// settings
@@ -28,7 +28,32 @@ public:
quint16 getPort() { return _port; };
/// check if server has been inited
const bool isInited() { return _inited; };
///
/// @brief Set a new description, if empty the description is NotFound for clients
///
void setSSDPDescription(const QString & desc);
signals:
///
/// @emits whenever server is started or stopped (to sync with SSDPHandler)
/// @param newState True when started, false when stopped
///
void stateChange(const bool newState);
///
/// @brief Emits whenever the port changes (doesn't compare prev <> now)
///
void portChanged(const quint16& port);
public slots:
///
/// @brief Init server after thread start
///
void initServer();
void onServerStopped (void);
void onServerStarted (quint16 port);
void onServerError (QString msg);
@@ -41,11 +66,13 @@ public slots:
void handleSettingsUpdate(const settings::type& type, const QJsonDocument& config);
private:
QJsonDocument _config;
Logger* _log;
QString _baseUrl;
quint16 _port;
StaticFileServing* _staticFileServing;
QtHttpServer* _server;
bool _inited = false;
const QString WEBSERVER_DEFAULT_PATH = ":/webconfig";
const quint16 WEBSERVER_DEFAULT_PORT = 8090;