hyperion.ng/libsrc/leddevice/dev_net/ProviderUdp.h
LordGrey 31b5be39b5
Merge pull request #961 from Lord-Grey/Improve_errohandling
Improve UDP-Device Error handling
2020-09-05 15:14:22 +02:00

74 lines
1.5 KiB
C++

#ifndef PROVIDERUDP_H
#define PROVIDERUDP_H
// LedDevice includes
#include <leddevice/LedDevice.h>
// Hyperion includes
#include <utils/Logger.h>
// Qt includes
#include <QHostAddress>
#include <QUdpSocket>
///
/// The ProviderUdp implements an abstract base-class for LedDevices using UDP packets.
///
class ProviderUdp : public LedDevice
{
public:
///
/// @brief Constructs an UDP LED-device
///
ProviderUdp(const QJsonObject &deviceConfig);
///
/// @brief Destructor of the UDP LED-device
///
~ProviderUdp() override;
protected:
///
/// @brief Initialise the UDP device's configuration and network address details
///
/// @param[in] deviceConfig the JSON device configuration
/// @return True, if success
///
bool init(const QJsonObject &deviceConfig) override;
///
/// @brief Opens the output device.
///
/// @return Zero on success (i.e. device is ready), else negative
///
int open() override;
///
/// @brief Closes the UDP device.
///
/// @return Zero on success (i.e. device is closed), else negative
///
int close() override;
///
/// @brief Writes the given bytes/bits to the UDP-device and sleeps the latch time to ensure that the
/// values are latched.
///
/// @param[in] size The length of the data
/// @param[in] data The data
///
/// @return Zero on success, else negative
///
int writeBytes(const unsigned size, const uint8_t *data);
///
QUdpSocket * _udpSocket;
QHostAddress _address;
quint16 _port;
QString _defaultHost;
};
#endif // PROVIDERUDP_H