diff --git a/include/leddevice/LedDevice.h b/include/leddevice/LedDevice.h index fbb7904d8..30efd19a7 100644 --- a/include/leddevice/LedDevice.h +++ b/include/leddevice/LedDevice.h @@ -48,7 +48,7 @@ class LedDevice : public QObject /// /// @brief Destructor of the LED-device /// - virtual ~LedDevice(); + ~LedDevice() override; /// /// @brief Get color order of device. diff --git a/include/leddevice/LedDeviceWrapper.h b/include/leddevice/LedDeviceWrapper.h index 6235dcbfe..585a9c9ce 100644 --- a/include/leddevice/LedDeviceWrapper.h +++ b/include/leddevice/LedDeviceWrapper.h @@ -58,7 +58,7 @@ class LedDeviceWrapper : public QObject /// /// @brief Return the last enable state /// - const bool & enabled(); + bool enabled(); /// /// @brief Get the current colorOrder from device diff --git a/include/ssdp/SSDPDiscover.h b/include/ssdp/SSDPDiscover.h index 77ace92ae..79a59665e 100644 --- a/include/ssdp/SSDPDiscover.h +++ b/include/ssdp/SSDPDiscover.h @@ -29,7 +29,7 @@ static const int DEFAULT_SEARCH_PORT = 1900; static const char DEFAULT_FILTER[] = ".*"; static const char DEFAULT_FILTER_HEADER[] = "ST"; -const int DEFAULT_SSDP_TIMEOUT = 5000; // timeout in ms +constexpr std::chrono::milliseconds DEFAULT_SSDP_TIMEOUT{5000}; // timeout in ms /// /// @brief Search for SSDP sessions, used by stand-alone capture binaries diff --git a/include/utils/QStringUtils.h b/include/utils/QStringUtils.h new file mode 100644 index 000000000..52d245c0e --- /dev/null +++ b/include/utils/QStringUtils.h @@ -0,0 +1,42 @@ +#ifndef QSTRINGUTILS_H +#define QSTRINGUTILS_H + +#include +#include + +namespace QStringUtils { + +enum class SplitBehavior { + KeepEmptyParts, + SkipEmptyParts, +}; + +inline QStringList split (const QString &string, const QString &sep, SplitBehavior behavior = SplitBehavior::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) +{ + #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + return behavior == SplitBehavior::SkipEmptyParts ? string.split(sep, Qt::SkipEmptyParts , cs) : string.split(sep, Qt::KeepEmptyParts , cs); + #else + return behavior == SplitBehavior::SkipEmptyParts ? string.split(sep, QString::SkipEmptyParts , cs) : string.split(sep, QString::KeepEmptyParts , cs); + #endif +} + +inline QStringList split (const QString &string, QChar sep, SplitBehavior behavior = SplitBehavior::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) +{ +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + return behavior == SplitBehavior::SkipEmptyParts ? string.split(sep, Qt::SkipEmptyParts , cs) : string.split(sep, Qt::KeepEmptyParts , cs); +#else + return behavior == SplitBehavior::SkipEmptyParts ? string.split(sep, QString::SkipEmptyParts , cs) : string.split(sep, QString::KeepEmptyParts , cs); +#endif +} + +inline QStringList split (const QString &string, const QRegExp &rx, SplitBehavior behavior = SplitBehavior::KeepEmptyParts) +{ +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + return behavior == SplitBehavior::SkipEmptyParts ? string.split(rx, Qt::SkipEmptyParts) : string.split(rx, Qt::KeepEmptyParts); +#else + return behavior == SplitBehavior::SkipEmptyParts ? string.split(rx, QString::SkipEmptyParts) : string.split(rx, QString::KeepEmptyParts); +#endif +} +} + +#endif // QSTRINGUTILS_H diff --git a/libsrc/boblightserver/BoblightClientConnection.cpp b/libsrc/boblightserver/BoblightClientConnection.cpp index 0336f34f5..cb1d70408 100644 --- a/libsrc/boblightserver/BoblightClientConnection.cpp +++ b/libsrc/boblightserver/BoblightClientConnection.cpp @@ -18,6 +18,7 @@ #include #include "HyperionConfig.h" #include +#include // project includes #include "BoblightClientConnection.h" @@ -81,7 +82,7 @@ void BoblightClientConnection::readData() void BoblightClientConnection::socketClosed() { // clear the current channel - if (_priority != 0 && _priority >= 128 && _priority < 254) + if (_priority >= 128 && _priority < 254) _hyperion->clear(_priority); emit connectionClosed(this); @@ -90,12 +91,7 @@ void BoblightClientConnection::socketClosed() void BoblightClientConnection::handleMessage(const QString & message) { //std::cout << "boblight message: " << message.toStdString() << std::endl; - #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - QStringList messageParts = message.split(" ", Qt::SkipEmptyParts); - #else - QStringList messageParts = message.split(" ", QString::SkipEmptyParts); - #endif - + QStringList messageParts = QStringUtils::split(message," ",QStringUtils::SplitBehavior::SkipEmptyParts); if (messageParts.size() > 0) { if (messageParts[0] == "hello") @@ -217,7 +213,7 @@ void BoblightClientConnection::handleMessage(const QString & message) } else if (messageParts[0] == "sync") { - if (_priority != 0 && _priority >= 128 && _priority < 254) + if ( _priority >= 128 && _priority < 254) _hyperion->setInput(_priority, _ledColors); // send current color values to hyperion return; diff --git a/libsrc/leddevice/LedDevice.cpp b/libsrc/leddevice/LedDevice.cpp index 1387fa153..bb446e397 100644 --- a/libsrc/leddevice/LedDevice.cpp +++ b/libsrc/leddevice/LedDevice.cpp @@ -38,7 +38,7 @@ LedDevice::LedDevice(const QJsonObject& deviceConfig, QObject* parent) LedDevice::~LedDevice() { - _refreshTimer->deleteLater(); + delete _refreshTimer; } void LedDevice::start() diff --git a/libsrc/leddevice/LedDeviceWrapper.cpp b/libsrc/leddevice/LedDeviceWrapper.cpp index 560c5a63a..e5bd76d1e 100644 --- a/libsrc/leddevice/LedDeviceWrapper.cpp +++ b/libsrc/leddevice/LedDeviceWrapper.cpp @@ -134,7 +134,7 @@ unsigned int LedDeviceWrapper::getLedCount() const return _ledDevice->getLedCount(); } -const bool & LedDeviceWrapper::enabled() +bool LedDeviceWrapper::enabled() { return _enabled; } diff --git a/libsrc/leddevice/dev_hid/LedDeviceHyperionUsbasp.cpp b/libsrc/leddevice/dev_hid/LedDeviceHyperionUsbasp.cpp index 8a67db73b..532dddd60 100644 --- a/libsrc/leddevice/dev_hid/LedDeviceHyperionUsbasp.cpp +++ b/libsrc/leddevice/dev_hid/LedDeviceHyperionUsbasp.cpp @@ -5,10 +5,12 @@ // Local Hyperion includes #include "LedDeviceHyperionUsbasp.h" -// Static constants which define the Hyperion USBasp device -uint16_t LedDeviceHyperionUsbasp::_usbVendorId = 0x16c0; -uint16_t LedDeviceHyperionUsbasp::_usbProductId = 0x05dc; -QString LedDeviceHyperionUsbasp::_usbProductDescription = "Hyperion led controller"; +// Constants which define the Hyperion USBasp device +namespace { +uint16_t _usbVendorId = 0x16c0; +uint16_t _usbProductId = 0x05dc; +QString _usbProductDescription = "Hyperion led controller"; +} LedDeviceHyperionUsbasp::LedDeviceHyperionUsbasp(const QJsonObject &deviceConfig) : LedDevice() diff --git a/libsrc/leddevice/dev_hid/LedDeviceHyperionUsbasp.h b/libsrc/leddevice/dev_hid/LedDeviceHyperionUsbasp.h index 09f6d43e4..830100983 100644 --- a/libsrc/leddevice/dev_hid/LedDeviceHyperionUsbasp.h +++ b/libsrc/leddevice/dev_hid/LedDeviceHyperionUsbasp.h @@ -91,11 +91,6 @@ public slots: /// libusb device handle libusb_device_handle * _deviceHandle; - - /// Usb device identifiers - static uint16_t _usbVendorId; - static uint16_t _usbProductId; - static QString _usbProductDescription; }; #endif // LEDEVICEHYPERIONUSBASP_H diff --git a/libsrc/leddevice/dev_hid/LedDeviceMultiLightpack.h b/libsrc/leddevice/dev_hid/LedDeviceMultiLightpack.h index 2c39cc78c..256c3d7bb 100644 --- a/libsrc/leddevice/dev_hid/LedDeviceMultiLightpack.h +++ b/libsrc/leddevice/dev_hid/LedDeviceMultiLightpack.h @@ -78,7 +78,7 @@ class LedDeviceMultiLightpack : public LedDevice /// @param[in] ledValues The RGB-color per LED /// @return Zero on success, else negative /// - virtual int write(const std::vector & ledValues) override; + int write(const std::vector & ledValues) override; private: diff --git a/libsrc/leddevice/dev_net/LedDeviceAtmoOrb.cpp b/libsrc/leddevice/dev_net/LedDeviceAtmoOrb.cpp index b1209ae8a..9aceeb74e 100644 --- a/libsrc/leddevice/dev_net/LedDeviceAtmoOrb.cpp +++ b/libsrc/leddevice/dev_net/LedDeviceAtmoOrb.cpp @@ -1,5 +1,6 @@ // Local-Hyperion includes #include "LedDeviceAtmoOrb.h" +#include // qt includes #include @@ -33,7 +34,7 @@ LedDeviceAtmoOrb::~LedDeviceAtmoOrb() { if ( _udpSocket != nullptr ) { - _udpSocket->deleteLater(); + delete _udpSocket; } } @@ -51,12 +52,7 @@ bool LedDeviceAtmoOrb::init(const QJsonObject &deviceConfig) _multiCastGroupPort = static_cast(deviceConfig["port"].toInt(MULTICAST_GROUPL_DEFAULT_PORT)); _numLeds = deviceConfig["numLeds"].toInt(LEDS_DEFAULT_NUMBER); - #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - const QStringList orbIds = deviceConfig["orbIds"].toString().simplified().remove(" ").split(",", Qt::SkipEmptyParts); - #else - const QStringList orbIds = deviceConfig["orbIds"].toString().simplified().remove(" ").split(",", QString::SkipEmptyParts); - #endif - + QStringList orbIds = QStringUtils::split(deviceConfig["orbIds"].toString().simplified().remove(" "),",", QStringUtils::SplitBehavior::SkipEmptyParts); _orbIds.clear(); for (auto & id_str : orbIds) diff --git a/libsrc/leddevice/dev_net/LedDeviceFadeCandy.cpp b/libsrc/leddevice/dev_net/LedDeviceFadeCandy.cpp index 4d1f5c41a..15de0b5bc 100644 --- a/libsrc/leddevice/dev_net/LedDeviceFadeCandy.cpp +++ b/libsrc/leddevice/dev_net/LedDeviceFadeCandy.cpp @@ -6,10 +6,15 @@ typedef SSIZE_T ssize_t; #endif -static const signed MAX_NUM_LEDS = 10000; // OPC can handle 21845 LEDs - in theory, fadecandy device should handle 10000 LEDs -static const unsigned OPC_SET_PIXELS = 0; // OPC command codes -static const unsigned OPC_SYS_EX = 255; // OPC command codes -static const unsigned OPC_HEADER_SIZE = 4; // OPC header size +// Constants +namespace { + +const signed MAX_NUM_LEDS = 10000; // OPC can handle 21845 LEDs - in theory, fadecandy device should handle 10000 LEDs +const unsigned OPC_SET_PIXELS = 0; // OPC command codes +const unsigned OPC_SYS_EX = 255; // OPC command codes +const unsigned OPC_HEADER_SIZE = 4; // OPC header size + +} //End of constants // TCP elements const quint16 STREAM_DEFAULT_PORT = 7890; @@ -30,7 +35,7 @@ LedDeviceFadeCandy::~LedDeviceFadeCandy() { if ( _client != nullptr ) { - _client->deleteLater(); + delete _client; } } diff --git a/libsrc/leddevice/dev_net/LedDeviceNanoleaf.cpp b/libsrc/leddevice/dev_net/LedDeviceNanoleaf.cpp index 44ed2970e..7912f0933 100644 --- a/libsrc/leddevice/dev_net/LedDeviceNanoleaf.cpp +++ b/libsrc/leddevice/dev_net/LedDeviceNanoleaf.cpp @@ -1,8 +1,8 @@ // Local-Hyperion includes #include "LedDeviceNanoleaf.h" -// ssdp discover #include +#include // Qt includes #include @@ -12,62 +12,66 @@ #include #include -// -static const bool verbose = false; -static const bool verbose3 = false; +// Constants +namespace { + +const bool verbose = false; +const bool verbose3 = false; // Configuration settings -static const char CONFIG_ADDRESS[] = "host"; -//static const char CONFIG_PORT[] = "port"; -static const char CONFIG_AUTH_TOKEN[] ="token"; +const char CONFIG_ADDRESS[] = "host"; +//const char CONFIG_PORT[] = "port"; +const char CONFIG_AUTH_TOKEN[] ="token"; -static const char CONFIG_PANEL_ORDER_TOP_DOWN[] ="panelOrderTopDown"; -static const char CONFIG_PANEL_ORDER_LEFT_RIGHT[] ="panelOrderLeftRight"; -static const char CONFIG_PANEL_START_POS[] ="panelStartPos"; +const char CONFIG_PANEL_ORDER_TOP_DOWN[] ="panelOrderTopDown"; +const char CONFIG_PANEL_ORDER_LEFT_RIGHT[] ="panelOrderLeftRight"; +const char CONFIG_PANEL_START_POS[] ="panelStartPos"; // Panel configuration settings -static const char PANEL_LAYOUT[] = "layout"; -static const char PANEL_NUM[] = "numPanels"; -static const char PANEL_ID[] = "panelId"; -static const char PANEL_POSITIONDATA[] = "positionData"; -static const char PANEL_SHAPE_TYPE[] = "shapeType"; -//static const char PANEL_ORIENTATION[] = "0"; -static const char PANEL_POS_X[] = "x"; -static const char PANEL_POS_Y[] = "y"; +const char PANEL_LAYOUT[] = "layout"; +const char PANEL_NUM[] = "numPanels"; +const char PANEL_ID[] = "panelId"; +const char PANEL_POSITIONDATA[] = "positionData"; +const char PANEL_SHAPE_TYPE[] = "shapeType"; +//const char PANEL_ORIENTATION[] = "0"; +const char PANEL_POS_X[] = "x"; +const char PANEL_POS_Y[] = "y"; // List of State Information -static const char STATE_ON[] = "on"; -static const char STATE_ONOFF_VALUE[] = "value"; -static const char STATE_VALUE_TRUE[] = "true"; -static const char STATE_VALUE_FALSE[] = "false"; +const char STATE_ON[] = "on"; +const char STATE_ONOFF_VALUE[] = "value"; +const char STATE_VALUE_TRUE[] = "true"; +const char STATE_VALUE_FALSE[] = "false"; // Device Data elements -static const char DEV_DATA_NAME[] = "name"; -static const char DEV_DATA_MODEL[] = "model"; -static const char DEV_DATA_MANUFACTURER[] = "manufacturer"; -static const char DEV_DATA_FIRMWAREVERSION[] = "firmwareVersion"; +const char DEV_DATA_NAME[] = "name"; +const char DEV_DATA_MODEL[] = "model"; +const char DEV_DATA_MANUFACTURER[] = "manufacturer"; +const char DEV_DATA_FIRMWAREVERSION[] = "firmwareVersion"; // Nanoleaf Stream Control elements -//static const char STREAM_CONTROL_IP[] = "streamControlIpAddr"; -static const char STREAM_CONTROL_PORT[] = "streamControlPort"; -//static const char STREAM_CONTROL_PROTOCOL[] = "streamControlProtocol"; +//const char STREAM_CONTROL_IP[] = "streamControlIpAddr"; +const char STREAM_CONTROL_PORT[] = "streamControlPort"; +//const char STREAM_CONTROL_PROTOCOL[] = "streamControlProtocol"; const quint16 STREAM_CONTROL_DEFAULT_PORT = 60222; //Fixed port for Canvas; // Nanoleaf OpenAPI URLs -static const int API_DEFAULT_PORT = 16021; -static const char API_BASE_PATH[] = "/api/v1/%1/"; -static const char API_ROOT[] = ""; -//static const char API_EXT_MODE_STRING_V1[] = "{\"write\" : {\"command\" : \"display\", \"animType\" : \"extControl\"}}"; -static const char API_EXT_MODE_STRING_V2[] = "{\"write\" : {\"command\" : \"display\", \"animType\" : \"extControl\", \"extControlVersion\" : \"v2\"}}"; -static const char API_STATE[] ="state"; -static const char API_PANELLAYOUT[] = "panelLayout"; -static const char API_EFFECT[] = "effects"; +const int API_DEFAULT_PORT = 16021; +const char API_BASE_PATH[] = "/api/v1/%1/"; +const char API_ROOT[] = ""; +//const char API_EXT_MODE_STRING_V1[] = "{\"write\" : {\"command\" : \"display\", \"animType\" : \"extControl\"}}"; +const char API_EXT_MODE_STRING_V2[] = "{\"write\" : {\"command\" : \"display\", \"animType\" : \"extControl\", \"extControlVersion\" : \"v2\"}}"; +const char API_STATE[] ="state"; +const char API_PANELLAYOUT[] = "panelLayout"; +const char API_EFFECT[] = "effects"; // Nanoleaf ssdp services -static const char SSDP_ID[] = "ssdp:all"; -static const char SSDP_FILTER_HEADER[] = "ST"; -static const char SSDP_CANVAS[] = "nanoleaf:nl29"; -static const char SSDP_LIGHTPANELS[] = "nanoleaf_aurora:light"; +const char SSDP_ID[] = "ssdp:all"; +const char SSDP_FILTER_HEADER[] = "ST"; +const char SSDP_CANVAS[] = "nanoleaf:nl29"; +const char SSDP_LIGHTPANELS[] = "nanoleaf_aurora:light"; + +} //End of constants // Nanoleaf Panel Shapetypes enum SHAPETYPES { @@ -419,12 +423,7 @@ QJsonObject LedDeviceNanoleaf::getProperties(const QJsonObject& params) QString filter = params["filter"].toString(""); // Resolve hostname and port (or use default API port) - #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - QStringList addressparts = host.split(":", Qt::SkipEmptyParts); - #else - QStringList addressparts = host.split(":", QString::SkipEmptyParts); - #endif - + QStringList addressparts = QStringUtils::split(host,":", QStringUtils::SplitBehavior::SkipEmptyParts); QString apiHost = addressparts[0]; int apiPort; @@ -467,13 +466,8 @@ void LedDeviceNanoleaf::identify(const QJsonObject& params) QString authToken = params["token"].toString(""); // Resolve hostname and port (or use default API port) - #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - QStringList addressparts = host.split(":", Qt::SkipEmptyParts); - #else - QStringList addressparts = host.split(":", QString::SkipEmptyParts); - #endif - - QString apiHost = addressparts[0]; + QStringList addressparts = QStringUtils::split(host,":", QStringUtils::SplitBehavior::SkipEmptyParts); + QString apiHost = addressparts[0]; int apiPort; if ( addressparts.size() > 1) diff --git a/libsrc/leddevice/dev_net/LedDevicePhilipsHue.cpp b/libsrc/leddevice/dev_net/LedDevicePhilipsHue.cpp index 103a629ec..f2e374d31 100644 --- a/libsrc/leddevice/dev_net/LedDevicePhilipsHue.cpp +++ b/libsrc/leddevice/dev_net/LedDevicePhilipsHue.cpp @@ -1,100 +1,127 @@ // Local-Hyperion includes #include "LedDevicePhilipsHue.h" -// ssdp discover #include +#include bool verbose = false; +// Constants +namespace { + // Configuration settings -static const char CONFIG_ADDRESS[] = "output"; -//static const char CONFIG_PORT[] = "port"; -static const char CONFIG_USERNAME[] = "username"; -static const char CONFIG_CLIENTKEY[] = "clientkey"; -static const char CONFIG_BRIGHTNESSFACTOR[] = "brightnessFactor"; -static const char CONFIG_TRANSITIONTIME[] = "transitiontime"; -static const char CONFIG_BLACK_LIGHTS_TIMEOUT[] = "blackLightsTimeout"; -static const char CONFIG_ON_OFF_BLACK[] = "switchOffOnBlack"; -static const char CONFIG_RESTORE_STATE[] = "restoreOriginalState"; -static const char CONFIG_LIGHTIDS[] = "lightIds"; -static const char CONFIG_USE_HUE_ENTERTAINMENT_API[] = "useEntertainmentAPI"; -static const char CONFIG_GROUPID[] = "groupId"; - -static const char CONFIG_VERBOSE[] = "verbose"; -static const char CONFIG_BRIGHTNESS_MIN[] = "brightnessMin"; -static const char CONFIG_BRIGHTNESS_MAX[] = "brightnessMax"; -static const char CONFIG_BRIGHTNESS_THRESHOLD[] = "brightnessThreshold"; - -static const char CONFIG_SSL_HANDSHAKE_TIMEOUT_MIN[] = "sslHSTimeoutMin"; -static const char CONFIG_SSL_HANDSHAKE_TIMEOUT_MAX[] = "sslHSTimeoutMax"; -static const char CONFIG_SSL_READ_TIMEOUT[] = "sslReadTimeout"; +const char CONFIG_ADDRESS[] = "output"; +//const char CONFIG_PORT[] = "port"; +const char CONFIG_USERNAME[] = "username"; +const char CONFIG_CLIENTKEY[] = "clientkey"; +const char CONFIG_BRIGHTNESSFACTOR[] = "brightnessFactor"; +const char CONFIG_TRANSITIONTIME[] = "transitiontime"; +const char CONFIG_BLACK_LIGHTS_TIMEOUT[] = "blackLightsTimeout"; +const char CONFIG_ON_OFF_BLACK[] = "switchOffOnBlack"; +const char CONFIG_RESTORE_STATE[] = "restoreOriginalState"; +const char CONFIG_LIGHTIDS[] = "lightIds"; +const char CONFIG_USE_HUE_ENTERTAINMENT_API[] = "useEntertainmentAPI"; +const char CONFIG_GROUPID[] = "groupId"; + +const char CONFIG_VERBOSE[] = "verbose"; +const char CONFIG_BRIGHTNESS_MIN[] = "brightnessMin"; +const char CONFIG_BRIGHTNESS_MAX[] = "brightnessMax"; +const char CONFIG_BRIGHTNESS_THRESHOLD[] = "brightnessThreshold"; + +const char CONFIG_SSL_HANDSHAKE_TIMEOUT_MIN[] = "sslHSTimeoutMin"; +const char CONFIG_SSL_HANDSHAKE_TIMEOUT_MAX[] = "sslHSTimeoutMax"; +const char CONFIG_SSL_READ_TIMEOUT[] = "sslReadTimeout"; // Device Data elements -static const char DEV_DATA_BRIDGEID[] = "bridgeid"; -static const char DEV_DATA_MODEL[] = "modelid"; -static const char DEV_DATA_NAME[] = "name"; -//static const char DEV_DATA_MANUFACTURER[] = "manufacturer"; -static const char DEV_DATA_FIRMWAREVERSION[] = "swversion"; -static const char DEV_DATA_APIVERSION[] = "apiversion"; +const char DEV_DATA_BRIDGEID[] = "bridgeid"; +const char DEV_DATA_MODEL[] = "modelid"; +const char DEV_DATA_NAME[] = "name"; +//const char DEV_DATA_MANUFACTURER[] = "manufacturer"; +const char DEV_DATA_FIRMWAREVERSION[] = "swversion"; +const char DEV_DATA_APIVERSION[] = "apiversion"; // Philips Hue OpenAPI URLs -static const int API_DEFAULT_PORT = -1; //Use default port per communication scheme -static const char API_BASE_PATH[] = "/api/%1/"; -static const char API_ROOT[] = ""; -static const char API_STATE[] = "state"; -static const char API_CONFIG[] = "config"; -static const char API_LIGHTS[] = "lights"; -static const char API_GROUPS[] = "groups"; +const int API_DEFAULT_PORT = -1; //Use default port per communication scheme +const char API_BASE_PATH[] = "/api/%1/"; +const char API_ROOT[] = ""; +const char API_STATE[] = "state"; +const char API_CONFIG[] = "config"; +const char API_LIGHTS[] = "lights"; +const char API_GROUPS[] = "groups"; // List of Group / Stream Information -static const char API_GROUP_NAME[] = "name"; -static const char API_GROUP_TYPE[] = "type"; -static const char API_GROUP_TYPE_ENTERTAINMENT[] = "Entertainment"; -static const char API_STREAM[] = "stream"; -static const char API_STREAM_ACTIVE[] = "active"; -static const char API_STREAM_ACTIVE_VALUE_TRUE[] = "true"; -static const char API_STREAM_ACTIVE_VALUE_FALSE[] = "false"; -static const char API_STREAM_OWNER[] = "owner"; -static const char API_STREAM_RESPONSE_FORMAT[] = "/%1/%2/%3/%4"; +const char API_GROUP_NAME[] = "name"; +const char API_GROUP_TYPE[] = "type"; +const char API_GROUP_TYPE_ENTERTAINMENT[] = "Entertainment"; +const char API_STREAM[] = "stream"; +const char API_STREAM_ACTIVE[] = "active"; +const char API_STREAM_ACTIVE_VALUE_TRUE[] = "true"; +const char API_STREAM_ACTIVE_VALUE_FALSE[] = "false"; +const char API_STREAM_OWNER[] = "owner"; +const char API_STREAM_RESPONSE_FORMAT[] = "/%1/%2/%3/%4"; // List of resources -static const char API_XY_COORDINATES[] = "xy"; -static const char API_BRIGHTNESS[] = "bri"; -//static const char API_SATURATION[] = "sat"; -static const char API_TRANSITIONTIME[] = "transitiontime"; -static const char API_MODEID[] = "modelid"; +const char API_XY_COORDINATES[] = "xy"; +const char API_BRIGHTNESS[] = "bri"; +//const char API_SATURATION[] = "sat"; +const char API_TRANSITIONTIME[] = "transitiontime"; +const char API_MODEID[] = "modelid"; // List of State Information -static const char API_STATE_ON[] = "on"; -static const char API_STATE_VALUE_TRUE[] = "true"; -static const char API_STATE_VALUE_FALSE[] = "false"; +const char API_STATE_ON[] = "on"; +const char API_STATE_VALUE_TRUE[] = "true"; +const char API_STATE_VALUE_FALSE[] = "false"; // List of Error Information -static const char API_ERROR[] = "error"; -static const char API_ERROR_ADDRESS[] = "address"; -static const char API_ERROR_DESCRIPTION[] = "description"; -static const char API_ERROR_TYPE[] = "type"; +const char API_ERROR[] = "error"; +const char API_ERROR_ADDRESS[] = "address"; +const char API_ERROR_DESCRIPTION[] = "description"; +const char API_ERROR_TYPE[] = "type"; // List of Success Information -static const char API_SUCCESS[] = "success"; +const char API_SUCCESS[] = "success"; // Phlips Hue ssdp services -static const char SSDP_ID[] = "upnp:rootdevice"; -static const char SSDP_FILTER[] = "(.*)IpBridge(.*)"; -static const char SSDP_FILTER_HEADER[] = "SERVER"; +const char SSDP_ID[] = "upnp:rootdevice"; +const char SSDP_FILTER[] = "(.*)IpBridge(.*)"; +const char SSDP_FILTER_HEADER[] = "SERVER"; // DTLS Connection / SSL / Cipher Suite -static const char API_SSL_SERVER_NAME[] = "Hue"; -static const char API_SSL_SEED_CUSTOM[] = "dtls_client"; +const char API_SSL_SERVER_NAME[] = "Hue"; +const char API_SSL_SEED_CUSTOM[] = "dtls_client"; const int API_SSL_SERVER_PORT = 2100; const int STREAM_CONNECTION_RETRYS = 5; -const int STREAM_REWRITE_TIME = 20; const int STREAM_SSL_HANDSHAKE_ATTEMPTS = 5; -const int STREAM_SSL_HANDSHAKE_TIMEOUT_MIN = 400; -const int STREAM_SSL_HANDSHAKE_TIMEOUT_MAX = 1000; -const int STREAM_SSL_READ_TIMEOUT = 0; +constexpr std::chrono::milliseconds STREAM_REWRITE_TIME{20}; const int SSL_CIPHERSUITES[2] = { MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256, 0 }; +//Streaming message header and payload definition +const uint8_t HEADER[] = +{ + 'H', 'u', 'e', 'S', 't', 'r', 'e', 'a', 'm', //protocol + 0x01, 0x00, //version 1.0 + 0x01, //sequence number 1 + 0x00, 0x00, //Reserved write 0’s + 0x01, //xy Brightness + 0x00, // Reserved, write 0’s +}; + +const uint8_t PAYLOAD_PER_LIGHT[] = +{ + 0x01, 0x00, 0x06, //light ID + //color: 16 bpc + 0xff, 0xff, + 0xff, 0xff, + 0xff, 0xff, + /* + (message.R >> 8) & 0xff, message.R & 0xff, + (message.G >> 8) & 0xff, message.G & 0xff, + (message.B >> 8) & 0xff, message.B & 0xff + */ +}; + +} //End of constants + bool operator ==(const CiColor& p1, const CiColor& p2) { return ((p1.x == p2.x) && (p1.y == p2.y) && (p1.bri == p2.bri)); @@ -293,12 +320,7 @@ bool LedDevicePhilipsHueBridge::init(const QJsonObject &deviceConfig) } else { - #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - QStringList addressparts = address.split(":", Qt::SkipEmptyParts); - #else - QStringList addressparts = address.split(":", QString::SkipEmptyParts); - #endif - + QStringList addressparts = QStringUtils::split(address,":", QStringUtils::SplitBehavior::SkipEmptyParts); _hostname = addressparts[0]; log( "Hostname/IP", "%s", QSTRING_CSTR( _hostname ) ); @@ -448,12 +470,7 @@ void LedDevicePhilipsHueBridge::setBridgeConfig(const QJsonDocument &doc) _deviceFirmwareVersion = jsonConfigInfo[DEV_DATA_FIRMWAREVERSION].toString(); _deviceAPIVersion = jsonConfigInfo[DEV_DATA_APIVERSION].toString(); - #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - QStringList apiVersionParts = _deviceAPIVersion.split(".", Qt::SkipEmptyParts); - #else - QStringList apiVersionParts = _deviceAPIVersion.split(".", QString::SkipEmptyParts); - #endif - + QStringList apiVersionParts = QStringUtils::split(_deviceAPIVersion,".", QStringUtils::SplitBehavior::SkipEmptyParts); if ( !apiVersionParts.isEmpty() ) { _api_major = apiVersionParts[0].toUInt(); @@ -802,9 +819,9 @@ LedDevicePhilipsHue::LedDevicePhilipsHue(const QJsonObject& deviceConfig) , _blackLightsTimer(nullptr) , _blackLightsTimeout(15000) , _brightnessThreshold(0.0) - , _handshake_timeout_min(STREAM_SSL_HANDSHAKE_TIMEOUT_MIN) - , _handshake_timeout_max(STREAM_SSL_HANDSHAKE_TIMEOUT_MAX) - , _ssl_read_timeout(STREAM_SSL_READ_TIMEOUT) + , _handshake_timeout_min(STREAM_SSL_HANDSHAKE_TIMEOUT_MIN.count()) + , _handshake_timeout_max(STREAM_SSL_HANDSHAKE_TIMEOUT_MAX.count()) + , _ssl_read_timeout(STREAM_SSL_READ_TIMEOUT.count()) , _stopConnection(false) , start_retry_left(3) , stop_retry_left(3) @@ -822,10 +839,7 @@ LedDevice* LedDevicePhilipsHue::construct(const QJsonObject &deviceConfig) LedDevicePhilipsHue::~LedDevicePhilipsHue() { - if ( _blackLightsTimer != nullptr ) - { - _blackLightsTimer->deleteLater(); - } + delete _blackLightsTimer; } bool LedDevicePhilipsHue::init(const QJsonObject &deviceConfig) @@ -846,9 +860,9 @@ bool LedDevicePhilipsHue::init(const QJsonObject &deviceConfig) _brightnessMin = _devConfig[CONFIG_BRIGHTNESS_MIN].toDouble(0.0); _brightnessMax = _devConfig[CONFIG_BRIGHTNESS_MAX].toDouble(1.0); _brightnessThreshold = _devConfig[CONFIG_BRIGHTNESS_THRESHOLD].toDouble(0.0); - _handshake_timeout_min = _devConfig[CONFIG_SSL_HANDSHAKE_TIMEOUT_MIN].toInt(STREAM_SSL_HANDSHAKE_TIMEOUT_MIN); - _handshake_timeout_max = _devConfig[CONFIG_SSL_HANDSHAKE_TIMEOUT_MAX].toInt(STREAM_SSL_HANDSHAKE_TIMEOUT_MAX); - _ssl_read_timeout = _devConfig[CONFIG_SSL_READ_TIMEOUT].toInt(STREAM_SSL_READ_TIMEOUT); + _handshake_timeout_min = _devConfig[CONFIG_SSL_HANDSHAKE_TIMEOUT_MIN].toInt(STREAM_SSL_HANDSHAKE_TIMEOUT_MIN.count()); + _handshake_timeout_max = _devConfig[CONFIG_SSL_HANDSHAKE_TIMEOUT_MAX].toInt(STREAM_SSL_HANDSHAKE_TIMEOUT_MAX.count()); + _ssl_read_timeout = _devConfig[CONFIG_SSL_READ_TIMEOUT].toInt(STREAM_SSL_READ_TIMEOUT.count()); if( _brightnessMin < 0.0 ) { _brightnessMin = 0.0; } if( _brightnessMax > 1.0 ) { _brightnessMax = 1.0; } @@ -963,7 +977,7 @@ bool LedDevicePhilipsHue::initLeds() _devConfig["host"] = _hostname; _devConfig["sslport"] = API_SSL_SERVER_PORT; _devConfig["servername"] = API_SSL_SERVER_NAME; - _devConfig["rewriteTime"] = STREAM_REWRITE_TIME; + _devConfig["rewriteTime"] = static_cast( STREAM_REWRITE_TIME.count() ); _devConfig["psk"] = _devConfig[ CONFIG_CLIENTKEY ].toString(); _devConfig["psk_identity"] = _devConfig[ CONFIG_USERNAME ].toString(); _devConfig["seed_custom"] = API_SSL_SEED_CUSTOM; @@ -1240,30 +1254,6 @@ bool LedDevicePhilipsHue::setStreamGroupState(bool state) QByteArray LedDevicePhilipsHue::prepareStreamData() { - static const uint8_t HEADER[] = - { - 'H', 'u', 'e', 'S', 't', 'r', 'e', 'a', 'm', //protocol - 0x01, 0x00, //version 1.0 - 0x01, //sequence number 1 - 0x00, 0x00, //Reserved write 0’s - 0x01, //xy Brightness - 0x00, // Reserved, write 0’s - }; - - static const uint8_t PAYLOAD_PER_LIGHT[] = - { - 0x01, 0x00, 0x06, //light ID - //color: 16 bpc - 0xff, 0xff, - 0xff, 0xff, - 0xff, 0xff, - /* - (message.R >> 8) & 0xff, message.R & 0xff, - (message.G >> 8) & 0xff, message.G & 0xff, - (message.B >> 8) & 0xff, message.B & 0xff - */ - }; - QByteArray msg; msg.reserve(static_cast(sizeof(HEADER) + sizeof(PAYLOAD_PER_LIGHT) * _lights.size())); msg.append((const char*)HEADER, sizeof(HEADER)); @@ -1287,6 +1277,12 @@ QByteArray LedDevicePhilipsHue::prepareStreamData() return msg; } +void LedDevicePhilipsHue::stop() +{ + stopBlackTimeoutTimer(); + LedDevicePhilipsHueBridge::stop(); +} + int LedDevicePhilipsHue::open() { int retval = -1; @@ -1365,7 +1361,7 @@ int LedDevicePhilipsHue::write(const std::vector & ledValues) void LedDevicePhilipsHue::noSignalTimeout() { - Debug(_log, "No Signal (timeout: %sms), only black color detected - stop stream for \"%s\" [%u]", QSTRING_CSTR( QString::number( _blackLightsTimer->remainingTime() ) ), QSTRING_CSTR(_groupName), _groupId ); + Debug(_log, "No Signal (timeout: %dms), only black color detected - stop stream for \"%s\" [%u]", _blackLightsTimer->remainingTime(), QSTRING_CSTR(_groupName), _groupId ); _stopConnection = true; switchOff(); } @@ -1642,12 +1638,7 @@ QJsonObject LedDevicePhilipsHue::getProperties(const QJsonObject& params) QString filter = params["filter"].toString(""); // Resolve hostname and port (or use default API port) - #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - QStringList addressparts = host.split(":", Qt::SkipEmptyParts); - #else - QStringList addressparts = host.split(":", QString::SkipEmptyParts); - #endif - + QStringList addressparts = QStringUtils::split(host,":", QStringUtils::SplitBehavior::SkipEmptyParts); QString apiHost = addressparts[0]; int apiPort; @@ -1689,12 +1680,7 @@ void LedDevicePhilipsHue::identify(const QJsonObject& params) int lightId = params["lightId"].toInt(0); // Resolve hostname and port (or use default API port) - #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - QStringList addressparts = host.split(":", Qt::SkipEmptyParts); - #else - QStringList addressparts = host.split(":", QString::SkipEmptyParts); - #endif - + QStringList addressparts = QStringUtils::split(host,":", QStringUtils::SplitBehavior::SkipEmptyParts); QString apiHost = addressparts[0]; int apiPort; diff --git a/libsrc/leddevice/dev_net/LedDevicePhilipsHue.h b/libsrc/leddevice/dev_net/LedDevicePhilipsHue.h index f100972ff..d18709ed4 100644 --- a/libsrc/leddevice/dev_net/LedDevicePhilipsHue.h +++ b/libsrc/leddevice/dev_net/LedDevicePhilipsHue.h @@ -371,6 +371,15 @@ class LedDevicePhilipsHue: public LedDevicePhilipsHueBridge void setColor(PhilipsHueLight& light, CiColor& color); void setState(PhilipsHueLight& light, bool on, const CiColor& color); +public slots: + + /// + /// @brief Stops the device. + /// + /// Includes switching-off the device and stopping refreshes. + /// + virtual void stop() override; + protected: /// diff --git a/libsrc/leddevice/dev_net/LedDeviceUdpH801.cpp b/libsrc/leddevice/dev_net/LedDeviceUdpH801.cpp index 31e0cc4df..52b7d0cf0 100644 --- a/libsrc/leddevice/dev_net/LedDeviceUdpH801.cpp +++ b/libsrc/leddevice/dev_net/LedDeviceUdpH801.cpp @@ -1,7 +1,12 @@ #include "LedDeviceUdpH801.h" +// Constants +namespace { + const ushort H801_DEFAULT_PORT = 30977; -static const char H801_DEFAULT_HOST[] = "255.255.255.255"; +const char H801_DEFAULT_HOST[] = "255.255.255.255"; + +} //End of constants LedDeviceUdpH801::LedDeviceUdpH801(const QJsonObject &deviceConfig) : ProviderUdp() diff --git a/libsrc/leddevice/dev_net/LedDeviceWled.cpp b/libsrc/leddevice/dev_net/LedDeviceWled.cpp index 76f7d787f..952814efb 100644 --- a/libsrc/leddevice/dev_net/LedDeviceWled.cpp +++ b/libsrc/leddevice/dev_net/LedDeviceWled.cpp @@ -1,32 +1,37 @@ // Local-Hyperion includes #include "LedDeviceWled.h" -// ssdp discover #include +#include + +// Constants +namespace { // Configuration settings -static const char CONFIG_ADDRESS[] = "host"; +const char CONFIG_ADDRESS[] = "host"; // UDP elements const quint16 STREAM_DEFAULT_PORT = 19446; // WLED JSON-API elements -static const int API_DEFAULT_PORT = -1; //Use default port per communication scheme +const int API_DEFAULT_PORT = -1; //Use default port per communication scheme -static const char API_BASE_PATH[] = "/json/"; -static const char API_PATH_INFO[] = "info"; -static const char API_PATH_STATE[] = "state"; +const char API_BASE_PATH[] = "/json/"; +const char API_PATH_INFO[] = "info"; +const char API_PATH_STATE[] = "state"; // List of State Information -static const char STATE_ON[] = "on"; -static const char STATE_VALUE_TRUE[] = "true"; -static const char STATE_VALUE_FALSE[] = "false"; +const char STATE_ON[] = "on"; +const char STATE_VALUE_TRUE[] = "true"; +const char STATE_VALUE_FALSE[] = "false"; // WLED ssdp services // TODO: WLED - Update ssdp discovery parameters when available -static const char SSDP_ID[] = "ssdp:all"; -static const char SSDP_FILTER[] = "(.*)"; -static const char SSDP_FILTER_HEADER[] = "ST"; +const char SSDP_ID[] = "ssdp:all"; +const char SSDP_FILTER[] = "(.*)"; +const char SSDP_FILTER_HEADER[] = "ST"; + +} //End of constants LedDeviceWled::LedDeviceWled(const QJsonObject &deviceConfig) : ProviderUdp() @@ -79,12 +84,7 @@ bool LedDeviceWled::init(const QJsonObject &deviceConfig) } else { - #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - QStringList addressparts = address.split(":", Qt::SkipEmptyParts); - #else - QStringList addressparts = address.split(":", QString::SkipEmptyParts); - #endif - + QStringList addressparts = QStringUtils::split(address,":", QStringUtils::SplitBehavior::SkipEmptyParts); _hostname = addressparts[0]; if ( addressparts.size() > 1 ) { @@ -209,12 +209,7 @@ QJsonObject LedDeviceWled::getProperties(const QJsonObject& params) QString filter = params["filter"].toString(""); // Resolve hostname and port (or use default API port) - #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - QStringList addressparts = host.split(":", Qt::SkipEmptyParts); - #else - QStringList addressparts = host.split(":", QString::SkipEmptyParts); - #endif - + QStringList addressparts = QStringUtils::split(host,":", QStringUtils::SplitBehavior::SkipEmptyParts); QString apiHost = addressparts[0]; int apiPort; @@ -258,12 +253,7 @@ void LedDeviceWled::identify(const QJsonObject& params) if ( !host.isEmpty() ) { // Resolve hostname and port (or use default API port) - #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - QStringList addressparts = host.split(":", Qt::SkipEmptyParts); - #else - QStringList addressparts = host.split(":", QString::SkipEmptyParts); - #endif - + QStringList addressparts = QStringUtils::split(host,":", QStringUtils::SplitBehavior::SkipEmptyParts); QString apiHost = addressparts[0]; int apiPort; diff --git a/libsrc/leddevice/dev_net/LedDeviceYeelight.cpp b/libsrc/leddevice/dev_net/LedDeviceYeelight.cpp index 4342e6ab8..236acbb7f 100644 --- a/libsrc/leddevice/dev_net/LedDeviceYeelight.cpp +++ b/libsrc/leddevice/dev_net/LedDeviceYeelight.cpp @@ -1,7 +1,7 @@ #include "LedDeviceYeelight.h" -// ssdp discover #include +#include // Qt includes #include @@ -14,75 +14,79 @@ #include #include -static const bool verbose = false; -static const bool verbose3 = false; - // Constants -const int WRITE_TIMEOUT = 1000; // device write timeout in ms -const int READ_TIMEOUT = 1000; // device write timeout in ms -const int CONNECT_TIMEOUT = 1000; // device connect timeout in ms -const int CONNECT_STREAM_TIMEOUT = 1000; // device streaming connect timeout in ms +namespace { + +const bool verbose = false; +const bool verbose3 = false; + +constexpr std::chrono::milliseconds WRITE_TIMEOUT{1000}; // device write timeout in ms +constexpr std::chrono::milliseconds READ_TIMEOUT{1000}; // device read timeout in ms +constexpr std::chrono::milliseconds CONNECT_TIMEOUT{1000}; // device connect timeout in ms +constexpr std::chrono::milliseconds CONNECT_STREAM_TIMEOUT{1000}; // device streaming connect timeout in ms -static const bool TEST_CORRELATION_IDS = false; //Ignore, if yeelight sends responses in different order as request commands +const bool TEST_CORRELATION_IDS = false; //Ignore, if yeelight sends responses in different order as request commands // Configuration settings -static const char CONFIG_LIGHTS [] = "lights"; +const char CONFIG_LIGHTS [] = "lights"; -static const char CONFIG_COLOR_MODEL [] = "colorModel"; -static const char CONFIG_TRANS_EFFECT [] = "transEffect"; -static const char CONFIG_TRANS_TIME [] = "transTime"; -static const char CONFIG_EXTRA_TIME_DARKNESS[] = "extraTimeDarkness"; -static const char CONFIG_DEBUGLEVEL [] = "debugLevel"; +const char CONFIG_COLOR_MODEL [] = "colorModel"; +const char CONFIG_TRANS_EFFECT [] = "transEffect"; +const char CONFIG_TRANS_TIME [] = "transTime"; +const char CONFIG_EXTRA_TIME_DARKNESS[] = "extraTimeDarkness"; +const char CONFIG_DEBUGLEVEL [] = "debugLevel"; -static const char CONFIG_BRIGHTNESS_MIN[] = "brightnessMin"; -static const char CONFIG_BRIGHTNESS_SWITCHOFF[] = "brightnessSwitchOffOnMinimum"; -static const char CONFIG_BRIGHTNESS_MAX[] = "brightnessMax"; -static const char CONFIG_BRIGHTNESSFACTOR[] = "brightnessFactor"; +const char CONFIG_BRIGHTNESS_MIN[] = "brightnessMin"; +const char CONFIG_BRIGHTNESS_SWITCHOFF[] = "brightnessSwitchOffOnMinimum"; +const char CONFIG_BRIGHTNESS_MAX[] = "brightnessMax"; +const char CONFIG_BRIGHTNESSFACTOR[] = "brightnessFactor"; -static const char CONFIG_RESTORE_STATE[] = "restoreOriginalState"; +const char CONFIG_RESTORE_STATE[] = "restoreOriginalState"; -static const char CONFIG_QUOTA_WAIT_TIME[] = "quotaWait"; +const char CONFIG_QUOTA_WAIT_TIME[] = "quotaWait"; // Yeelights API -static const int API_DEFAULT_PORT = 55443; -static const quint16 API_DEFAULT_QUOTA_WAIT_TIME = 1000; +const int API_DEFAULT_PORT = 55443; +const quint16 API_DEFAULT_QUOTA_WAIT_TIME = 1000; // Yeelight API Command -static const char API_COMMAND_ID[] = "id"; -static const char API_COMMAND_METHOD[] = "method"; -static const char API_COMMAND_PARAMS[] = "params"; -static const char API_COMMAND_PROPS[] = "props"; +const char API_COMMAND_ID[] = "id"; +const char API_COMMAND_METHOD[] = "method"; +const char API_COMMAND_PARAMS[] = "params"; +const char API_COMMAND_PROPS[] = "props"; -static const char API_PARAM_CLASS_COLOR[] = "color"; -static const char API_PARAM_CLASS_HSV[] = "hsv"; +const char API_PARAM_CLASS_COLOR[] = "color"; +const char API_PARAM_CLASS_HSV[] = "hsv"; -static const char API_PROP_NAME[] = "name"; -static const char API_PROP_MODEL[] = "model"; -static const char API_PROP_FWVER[] = "fw_ver"; +const char API_PROP_NAME[] = "name"; +const char API_PROP_MODEL[] = "model"; +const char API_PROP_FWVER[] = "fw_ver"; -static const char API_PROP_POWER[] = "power"; -static const char API_PROP_MUSIC[] = "music_on"; -static const char API_PROP_RGB[] = "rgb"; -static const char API_PROP_CT[] = "ct"; -static const char API_PROP_COLORFLOW[] = "cf"; -static const char API_PROP_BRIGHT[] = "bright"; +const char API_PROP_POWER[] = "power"; +const char API_PROP_MUSIC[] = "music_on"; +const char API_PROP_RGB[] = "rgb"; +const char API_PROP_CT[] = "ct"; +const char API_PROP_COLORFLOW[] = "cf"; +const char API_PROP_BRIGHT[] = "bright"; // List of Result Information -static const char API_RESULT_ID[] = "id"; -static const char API_RESULT[] = "result"; -//static const char API_RESULT_OK[] = "OK"; +const char API_RESULT_ID[] = "id"; +const char API_RESULT[] = "result"; +//const char API_RESULT_OK[] = "OK"; // List of Error Information -static const char API_ERROR[] = "error"; -static const char API_ERROR_CODE[] = "code"; -static const char API_ERROR_MESSAGE[] = "message"; +const char API_ERROR[] = "error"; +const char API_ERROR_CODE[] = "code"; +const char API_ERROR_MESSAGE[] = "message"; // Yeelight ssdp services -static const char SSDP_ID[] = "wifi_bulb"; -static const char SSDP_FILTER[] = "yeelight(.*)"; -static const char SSDP_FILTER_HEADER[] = "Location"; +const char SSDP_ID[] = "wifi_bulb"; +const char SSDP_FILTER[] = "yeelight(.*)"; +const char SSDP_FILTER_HEADER[] = "Location"; const quint16 SSDP_PORT = 1982; +} //End of constants + YeelightLight::YeelightLight( Logger *log, const QString &hostname, quint16 port = API_DEFAULT_PORT) :_log(log) ,_debugLevel(0) @@ -95,8 +99,8 @@ YeelightLight::YeelightLight( Logger *log, const QString &hostname, quint16 port ,_lastWriteTime(QDateTime::currentMSecsSinceEpoch()) ,_lastColorRgbValue(0) ,_transitionEffect(YeelightLight::API_EFFECT_SMOOTH) - ,_transitionDuration(API_PARAM_DURATION) - ,_extraTimeDarkness(API_PARAM_EXTRA_TIME_DARKNESS) + ,_transitionDuration(API_PARAM_DURATION.count()) + ,_extraTimeDarkness(API_PARAM_EXTRA_TIME_DARKNESS.count()) ,_brightnessMin(0) ,_isBrightnessSwitchOffMinimum(false) ,_brightnessMax(100) @@ -115,7 +119,7 @@ YeelightLight::~YeelightLight() log (3,"~YeelightLight()","" ); if ( _tcpSocket != nullptr) { - _tcpSocket->deleteLater(); + delete _tcpSocket; } log (2,"~YeelightLight()","void" ); } @@ -152,7 +156,7 @@ bool YeelightLight::open() { _tcpSocket->connectToHost( _host, _port); - if ( _tcpSocket->waitForConnected( CONNECT_TIMEOUT ) ) + if ( _tcpSocket->waitForConnected( CONNECT_TIMEOUT.count() ) ) { if ( _tcpSocket->state() != QAbstractSocket::ConnectedState ) { @@ -230,7 +234,7 @@ int YeelightLight::writeCommand( const QJsonDocument &command, QJsonArray &resul } else { - if ( ! _tcpSocket->waitForBytesWritten(WRITE_TIMEOUT) ) + if ( ! _tcpSocket->waitForBytesWritten(WRITE_TIMEOUT.count()) ) { QString errorReason = QString ("(%1) %2").arg(_tcpSocket->error()).arg( _tcpSocket->errorString()); log ( 2, "Error:", "bytesWritten: [%d], %s", bytesWritten, QSTRING_CSTR(errorReason)); @@ -253,7 +257,7 @@ int YeelightLight::writeCommand( const QJsonDocument &command, QJsonArray &resul } } - if ( _tcpSocket->waitForReadyRead(READ_TIMEOUT) ) + if ( _tcpSocket->waitForReadyRead(READ_TIMEOUT.count()) ) { do { @@ -333,7 +337,7 @@ bool YeelightLight::streamCommand( const QJsonDocument &command ) } else { - if ( ! _tcpStreamSocket->waitForBytesWritten(WRITE_TIMEOUT) ) + if ( ! _tcpStreamSocket->waitForBytesWritten(WRITE_TIMEOUT.count()) ) { int error = _tcpStreamSocket->error(); QString errorReason = QString ("(%1) %2").arg(error).arg( _tcpStreamSocket->errorString()); @@ -968,7 +972,7 @@ LedDeviceYeelight::LedDeviceYeelight(const QJsonObject &deviceConfig) ,_lightsCount (0) ,_outputColorModel(0) ,_transitionEffect(YeelightLight::API_EFFECT_SMOOTH) - ,_transitionDuration(API_PARAM_DURATION) + ,_transitionDuration(API_PARAM_DURATION.count()) ,_extraTimeDarkness(0) ,_brightnessMin(0) ,_isBrightnessSwitchOffMinimum(false) @@ -988,7 +992,7 @@ LedDeviceYeelight::~LedDeviceYeelight() { if ( _tcpMusicModeServer != nullptr ) { - _tcpMusicModeServer->deleteLater(); + delete _tcpMusicModeServer; } } @@ -1039,7 +1043,7 @@ bool LedDeviceYeelight::init(const QJsonObject &deviceConfig) _transitionEffect = static_cast( deviceConfig[ CONFIG_TRANS_EFFECT ].toInt(YeelightLight::API_EFFECT_SMOOTH) ); } - _transitionDuration = deviceConfig[ CONFIG_TRANS_TIME ].toInt(API_PARAM_DURATION); + _transitionDuration = deviceConfig[ CONFIG_TRANS_TIME ].toInt(API_PARAM_DURATION.count()); _extraTimeDarkness = _devConfig[CONFIG_EXTRA_TIME_DARKNESS].toInt(0); _brightnessMin = _devConfig[CONFIG_BRIGHTNESS_MIN].toInt(0); @@ -1115,12 +1119,7 @@ bool LedDeviceYeelight::init(const QJsonObject &deviceConfig) QString address = configuredYeelightLights[j].toObject().value("host").toString(); int port = configuredYeelightLights[j].toObject().value("port").toInt(API_DEFAULT_PORT); - #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - QStringList addressparts = address.split(":", Qt::SkipEmptyParts); - #else - QStringList addressparts = address.split(":", QString::SkipEmptyParts); - #endif - + QStringList addressparts = QStringUtils::split(address,":", QStringUtils::SplitBehavior::SkipEmptyParts); QString apiHost = addressparts[0]; int apiPort = port; @@ -1325,7 +1324,7 @@ bool LedDeviceYeelight::powerOff() //Power-off all Yeelights for (YeelightLight& light : _lights) { - light.setPower( false, _transitionEffect, API_PARAM_DURATION_POWERONOFF); + light.setPower( false, _transitionEffect, API_PARAM_DURATION_POWERONOFF.count()); } } return true; @@ -1351,7 +1350,7 @@ bool LedDeviceYeelight::restoreState() light.restoreState(); if ( !light.wasOriginallyOn() ) { - light.setPower( false, _transitionEffect, API_PARAM_DURATION_POWERONOFF); + light.setPower( false, _transitionEffect, API_PARAM_DURATION_POWERONOFF.count()); } } return rc; @@ -1449,7 +1448,7 @@ int LedDeviceYeelight::write(const std::vector & ledValues) if ( light.setMusicMode(true, _musicModeServerAddress, _musicModeServerPort) ) { // Wait for callback of the device to establish streaming socket - if ( _tcpMusicModeServer->waitForNewConnection(CONNECT_STREAM_TIMEOUT) ) + if ( _tcpMusicModeServer->waitForNewConnection(CONNECT_STREAM_TIMEOUT.count()) ) { light.setStreamSocket( _tcpMusicModeServer->nextPendingConnection() ); } diff --git a/libsrc/leddevice/dev_net/LedDeviceYeelight.h b/libsrc/leddevice/dev_net/LedDeviceYeelight.h index aa227c196..a7ae19b12 100644 --- a/libsrc/leddevice/dev_net/LedDeviceYeelight.h +++ b/libsrc/leddevice/dev_net/LedDeviceYeelight.h @@ -10,26 +10,30 @@ #include #include +// Constants +namespace { + // List of State Information -static const char API_METHOD_POWER[] = "set_power"; -static const char API_METHOD_POWER_ON[] = "on"; -static const char API_METHOD_POWER_OFF[] = "off"; +const char API_METHOD_POWER[] = "set_power"; +const char API_METHOD_POWER_ON[] = "on"; +const char API_METHOD_POWER_OFF[] = "off"; -static const char API_METHOD_MUSIC_MODE[] = "set_music"; -static const int API_METHOD_MUSIC_MODE_ON = 1; -static const int API_METHOD_MUSIC_MODE_OFF = 0; +const char API_METHOD_MUSIC_MODE[] = "set_music"; +const int API_METHOD_MUSIC_MODE_ON = 1; +const int API_METHOD_MUSIC_MODE_OFF = 0; -static const char API_METHOD_SETRGB[] = "set_rgb"; -static const char API_METHOD_SETSCENE[] = "set_scene"; -static const char API_METHOD_GETPROP[] = "get_prop"; +const char API_METHOD_SETRGB[] = "set_rgb"; +const char API_METHOD_SETSCENE[] = "set_scene"; +const char API_METHOD_GETPROP[] = "get_prop"; -static const char API_PARAM_EFFECT_SUDDEN[] = "sudden"; -static const char API_PARAM_EFFECT_SMOOTH[] = "smooth"; +const char API_PARAM_EFFECT_SUDDEN[] = "sudden"; +const char API_PARAM_EFFECT_SMOOTH[] = "smooth"; -static const int API_PARAM_DURATION = 50; -static const int API_PARAM_DURATION_POWERONOFF = 1000; -static const int API_PARAM_EXTRA_TIME_DARKNESS = 200; +constexpr std::chrono::milliseconds API_PARAM_DURATION{50}; +constexpr std::chrono::milliseconds API_PARAM_DURATION_POWERONOFF{1000}; +constexpr std::chrono::milliseconds API_PARAM_EXTRA_TIME_DARKNESS{200}; +} //End of constants /// /// Response object for Yeelight-API calls and JSON-responses /// @@ -223,7 +227,7 @@ class YeelightLight /// @param[in] effect Transition effect, sudden or smooth /// @param[in] duration Duration of the transition, if smooth /// - void setTransitionEffect ( API_EFFECT effect ,int duration = API_PARAM_DURATION ); + void setTransitionEffect ( API_EFFECT effect ,int duration = API_PARAM_DURATION.count() ); /// /// @brief Set the Yeelight light brightness configuration behaviour diff --git a/libsrc/leddevice/dev_net/ProviderRestApi.cpp b/libsrc/leddevice/dev_net/ProviderRestApi.cpp index e16ce11aa..783667aa3 100644 --- a/libsrc/leddevice/dev_net/ProviderRestApi.cpp +++ b/libsrc/leddevice/dev_net/ProviderRestApi.cpp @@ -9,10 +9,15 @@ //std includes #include -static const QChar ONE_SLASH = '/'; +// Constants +namespace { + +const QChar ONE_SLASH = '/'; + +} //End of constants ProviderRestApi::ProviderRestApi(const QString &host, const int &port, const QString &basePath) - :_log(Logger::getInstance("LDEDEVICE")) + :_log(Logger::getInstance("LEDDEVICE")) ,_networkManager(nullptr) ,_scheme("http") ,_hostname(host) @@ -36,7 +41,7 @@ ProviderRestApi::~ProviderRestApi() { if ( _networkManager != nullptr ) { - _networkManager->deleteLater(); + delete _networkManager; } } @@ -57,7 +62,7 @@ void ProviderRestApi::appendPath ( const QString &path ) appendPath (_path, path ); } -void ProviderRestApi::appendPath (QString& path, const QString &appendPath) +void ProviderRestApi::appendPath ( QString& path, const QString &appendPath) const { if ( !appendPath.isEmpty() && appendPath != ONE_SLASH ) { @@ -96,7 +101,7 @@ void ProviderRestApi::setQuery(const QUrlQuery &query) _query = query; } -QUrl ProviderRestApi::getUrl() +QUrl ProviderRestApi::getUrl() const { QUrl url = _apiUrl; diff --git a/libsrc/leddevice/dev_net/ProviderRestApi.h b/libsrc/leddevice/dev_net/ProviderRestApi.h index 32c267316..06c342199 100644 --- a/libsrc/leddevice/dev_net/ProviderRestApi.h +++ b/libsrc/leddevice/dev_net/ProviderRestApi.h @@ -99,7 +99,7 @@ class ProviderRestApi /// /// @return url /// - QUrl getUrl(); + QUrl getUrl() const; /// /// @brief Set an API's base path (the stable path element before addressing resources) @@ -192,7 +192,7 @@ class ProviderRestApi /// @param[in/out] path to be updated /// @param[in] path, element to be appended /// - void appendPath (QString &path, const QString &appendPath); + void appendPath (QString &path, const QString &appendPath) const; Logger* _log; diff --git a/libsrc/leddevice/dev_net/ProviderUdp.cpp b/libsrc/leddevice/dev_net/ProviderUdp.cpp index 9dccd41f7..9c9c124c8 100644 --- a/libsrc/leddevice/dev_net/ProviderUdp.cpp +++ b/libsrc/leddevice/dev_net/ProviderUdp.cpp @@ -30,7 +30,7 @@ ProviderUdp::~ProviderUdp() { if ( _udpSocket != nullptr ) { - _udpSocket->deleteLater(); + delete _udpSocket; } } diff --git a/libsrc/leddevice/dev_net/ProviderUdpSSL.cpp b/libsrc/leddevice/dev_net/ProviderUdpSSL.cpp index ef171f9cf..6facf2f7d 100644 --- a/libsrc/leddevice/dev_net/ProviderUdpSSL.cpp +++ b/libsrc/leddevice/dev_net/ProviderUdpSSL.cpp @@ -32,9 +32,9 @@ ProviderUdpSSL::ProviderUdpSSL() , _server_name() , _psk() , _psk_identity() - , _read_timeout(0) - , _handshake_timeout_min(400) - , _handshake_timeout_max(1000) + , _read_timeout(STREAM_SSL_READ_TIMEOUT.count()) + , _handshake_timeout_min(STREAM_SSL_HANDSHAKE_TIMEOUT_MIN.count()) + , _handshake_timeout_max(STREAM_SSL_HANDSHAKE_TIMEOUT_MAX.count()) , _handshake_attempts(5) , _retry_left(MAX_RETRY) , _stopConnection(true) diff --git a/libsrc/leddevice/dev_net/ProviderUdpSSL.h b/libsrc/leddevice/dev_net/ProviderUdpSSL.h index b9e101ae2..37cb4589f 100644 --- a/libsrc/leddevice/dev_net/ProviderUdpSSL.h +++ b/libsrc/leddevice/dev_net/ProviderUdpSSL.h @@ -48,6 +48,9 @@ //----------- END mbedtls +constexpr std::chrono::milliseconds STREAM_SSL_HANDSHAKE_TIMEOUT_MIN{400}; +constexpr std::chrono::milliseconds STREAM_SSL_HANDSHAKE_TIMEOUT_MAX{1000}; +constexpr std::chrono::milliseconds STREAM_SSL_READ_TIMEOUT{0}; class ProviderUdpSSL : public LedDevice { diff --git a/libsrc/leddevice/dev_other/LedDeviceFile.cpp b/libsrc/leddevice/dev_other/LedDeviceFile.cpp index afd27aeb2..bb9b24d8d 100644 --- a/libsrc/leddevice/dev_other/LedDeviceFile.cpp +++ b/libsrc/leddevice/dev_other/LedDeviceFile.cpp @@ -17,10 +17,7 @@ LedDeviceFile::LedDeviceFile(const QJsonObject &deviceConfig) LedDeviceFile::~LedDeviceFile() { - if ( _file != nullptr ) - { - _file->deleteLater(); - } + delete _file; } LedDevice* LedDeviceFile::construct(const QJsonObject &deviceConfig) @@ -44,7 +41,7 @@ void LedDeviceFile::initFile(const QString &fileName) { if ( _file == nullptr ) { - _file = new QFile(fileName); + _file = new QFile(fileName, this); } } diff --git a/libsrc/leddevice/dev_serial/ProviderRs232.cpp b/libsrc/leddevice/dev_serial/ProviderRs232.cpp index 5a89c8487..01a921c05 100644 --- a/libsrc/leddevice/dev_serial/ProviderRs232.cpp +++ b/libsrc/leddevice/dev_serial/ProviderRs232.cpp @@ -8,8 +8,8 @@ #include // Constants -const int WRITE_TIMEOUT = 1000; // device write timeout in ms -const int OPEN_TIMEOUT = 5000; // device open timeout in ms +constexpr std::chrono::milliseconds WRITE_TIMEOUT{1000}; // device write timeout in ms +constexpr std::chrono::milliseconds OPEN_TIMEOUT{5000}; // device open timeout in ms const int MAX_WRITE_TIMEOUTS = 5; // maximum number of allowed timeouts const int NUM_POWEROFF_WRITE_BLACK = 2; // Number of write "BLACK" during powering off @@ -198,7 +198,7 @@ int ProviderRs232::writeBytes(const qint64 size, const uint8_t *data) { Debug(_log, "!_rs232Port.isOpen()"); - if ( !tryOpen(OPEN_TIMEOUT) ) + if ( !tryOpen(OPEN_TIMEOUT.count()) ) { return -1; } @@ -214,7 +214,7 @@ int ProviderRs232::writeBytes(const qint64 size, const uint8_t *data) } else { - if (!_rs232Port.waitForBytesWritten(WRITE_TIMEOUT)) + if (!_rs232Port.waitForBytesWritten(WRITE_TIMEOUT.count())) { if ( _rs232Port.error() == QSerialPort::TimeoutError ) { diff --git a/libsrc/leddevice/dev_tinker/LedDeviceTinkerforge.cpp b/libsrc/leddevice/dev_tinker/LedDeviceTinkerforge.cpp index e282f97a1..6f54bace3 100644 --- a/libsrc/leddevice/dev_tinker/LedDeviceTinkerforge.cpp +++ b/libsrc/leddevice/dev_tinker/LedDeviceTinkerforge.cpp @@ -6,10 +6,15 @@ // Local LedDevice includes #include "LedDeviceTinkerforge.h" -static const unsigned MAX_NUM_LEDS = 320; -static const unsigned MAX_NUM_LEDS_SETTABLE = 16; +// Constants +namespace { + +const unsigned MAX_NUM_LEDS = 320; +const unsigned MAX_NUM_LEDS_SETTABLE = 16; const uint16_t DEFAULT_PORT = 4223; +} //End of constants + LedDeviceTinkerforge::LedDeviceTinkerforge(const QJsonObject &deviceConfig) : LedDevice() ,_port(DEFAULT_PORT) diff --git a/libsrc/ssdp/SSDPDiscover.cpp b/libsrc/ssdp/SSDPDiscover.cpp index b9080437b..af952f945 100644 --- a/libsrc/ssdp/SSDPDiscover.cpp +++ b/libsrc/ssdp/SSDPDiscover.cpp @@ -1,5 +1,7 @@ #include +#include + // Qt includes #include #include @@ -9,13 +11,17 @@ #include +// Constants +namespace { + // as per upnp spec 1.1, section 1.2.2. -static const QString UPNP_DISCOVER_MESSAGE = "M-SEARCH * HTTP/1.1\r\n" +const QString UPNP_DISCOVER_MESSAGE = "M-SEARCH * HTTP/1.1\r\n" "HOST: %1:%2\r\n" "MAN: \"ssdp:discover\"\r\n" "MX: %3\r\n" "ST: %4\r\n" "\r\n"; +} //End of constants SSDPDiscover::SSDPDiscover(QObject* parent) : QObject(parent) @@ -24,7 +30,7 @@ SSDPDiscover::SSDPDiscover(QObject* parent) , _ssdpAddr(DEFAULT_SEARCH_ADDRESS) , _ssdpPort(DEFAULT_SEARCH_PORT) , _ssdpMaxWaitResponseTime(1) - , _ssdpTimeout(DEFAULT_SSDP_TIMEOUT) + , _ssdpTimeout(DEFAULT_SSDP_TIMEOUT.count()) ,_filter(DEFAULT_FILTER) ,_filterHeader(DEFAULT_FILTER_HEADER) ,_regExFilter(_filter) @@ -73,12 +79,7 @@ const QString SSDPDiscover::getFirstService(const searchType& type, const QStrin QString address; // parse request - #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - QStringList entries = data.split("\n", Qt::SkipEmptyParts); - #else - QStringList entries = data.split("\n", QString::SkipEmptyParts); - #endif - + QStringList entries = QStringUtils::split(data,"\n", QStringUtils::SplitBehavior::SkipEmptyParts); for(auto entry : entries) { // http header parse skip @@ -161,11 +162,7 @@ void SSDPDiscover::readPendingDatagrams() QString data(datagram); QMap headers; // parse request - #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - QStringList entries = data.split("\n", Qt::SkipEmptyParts); - #else - QStringList entries = data.split("\n", QString::SkipEmptyParts); - #endif + QStringList entries = QStringUtils::split(data,"\n", QStringUtils::SplitBehavior::SkipEmptyParts); for(auto entry : entries) { // http header parse skip @@ -233,12 +230,7 @@ int SSDPDiscover::discoverServices(const QString& searchTarget, const QString& k QMap headers; // parse request - #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - QStringList entries = data.split("\n", Qt::SkipEmptyParts); - #else - QStringList entries = data.split("\n", QString::SkipEmptyParts); - #endif - + QStringList entries = QStringUtils::split(data,"\n", QStringUtils::SplitBehavior::SkipEmptyParts); for(auto entry : entries) { // http header parse skip diff --git a/libsrc/ssdp/SSDPServer.cpp b/libsrc/ssdp/SSDPServer.cpp index 8845c1a17..19ed54c52 100644 --- a/libsrc/ssdp/SSDPServer.cpp +++ b/libsrc/ssdp/SSDPServer.cpp @@ -2,6 +2,7 @@ // utils #include +#include // Hyperion #include @@ -137,11 +138,7 @@ void SSDPServer::readPendingDatagrams() QString data(datagram); QMap headers; // parse request - #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - QStringList entries = data.split("\n", Qt::SkipEmptyParts); - #else - QStringList entries = data.split("\n", QString::SkipEmptyParts); - #endif + QStringList entries = QStringUtils::split(data,"\n", QStringUtils::SplitBehavior::SkipEmptyParts); for(auto entry : entries) { // http header parse skip diff --git a/libsrc/webserver/QtHttpClientWrapper.cpp b/libsrc/webserver/QtHttpClientWrapper.cpp index 2495098f1..37b148a6a 100644 --- a/libsrc/webserver/QtHttpClientWrapper.cpp +++ b/libsrc/webserver/QtHttpClientWrapper.cpp @@ -1,3 +1,4 @@ +#include #include "QtHttpClientWrapper.h" #include "QtHttpRequest.h" @@ -58,12 +59,7 @@ void QtHttpClientWrapper::onClientDataReceived (void) case AwaitingRequest: // "command url version" × 1 { QString str = QString::fromUtf8 (line).trimmed (); - #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - QStringList parts = str.split (SPACE, Qt::SkipEmptyParts); - #else - QStringList parts = str.split (SPACE, QString::SkipEmptyParts); - #endif - + QStringList parts = QStringUtils::split(str,SPACE, QStringUtils::SplitBehavior::SkipEmptyParts); if (parts.size () == 3) { QString command = parts.at (0); @@ -197,12 +193,7 @@ void QtHttpClientWrapper::onClientDataReceived (void) // catch /jsonrpc in url, we need async callback, StaticFileServing is sync QString path = m_currentRequest->getUrl ().path (); - #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - QStringList uri_parts = path.split('/', Qt::SkipEmptyParts); - #else - QStringList uri_parts = path.split('/', QString::SkipEmptyParts); - #endif - + QStringList uri_parts = QStringUtils::split(path,'/', QStringUtils::SplitBehavior::SkipEmptyParts); if ( ! uri_parts.empty() && uri_parts.at(0) == "json-rpc" ) { if(m_webJsonRpc == Q_NULLPTR) diff --git a/libsrc/webserver/StaticFileServing.cpp b/libsrc/webserver/StaticFileServing.cpp index 5986eb915..8d20b98a8 100644 --- a/libsrc/webserver/StaticFileServing.cpp +++ b/libsrc/webserver/StaticFileServing.cpp @@ -1,5 +1,6 @@ #include "StaticFileServing.h" +#include #include #include @@ -81,12 +82,7 @@ void StaticFileServing::onRequestNeedsReply (QtHttpRequest * request, QtHttpRepl if (command == QStringLiteral ("GET")) { QString path = request->getUrl ().path (); - #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - QStringList uri_parts = path.split('/', Qt::SkipEmptyParts); - #else - QStringList uri_parts = path.split('/', QString::SkipEmptyParts); - #endif - + QStringList uri_parts = QStringUtils::split(path,'/', QStringUtils::SplitBehavior::SkipEmptyParts); // special uri handling for server commands if ( ! uri_parts.empty() ) {