From bfb9a08c80c08fdaba33a3f097e84df440fe6529 Mon Sep 17 00:00:00 2001 From: redPanther Date: Sat, 4 Mar 2017 22:17:42 +0100 Subject: [PATCH] migrate std::string to qstring + add sysinfo via json (#412) * std::string -> qstring part 1 * more string migration * more string migration ... * ... * more qstring mogrations add sysinfo via json * remove unneccessary includes * integrate sysinfo into webui --- assets/webconfig/js/content_dashboard.js | 2 +- assets/webconfig/js/content_index.js | 14 +- assets/webconfig/js/hyperion.js | 9 +- include/blackborder/BlackBorderProcessor.h | 2 +- include/commandline/Option.h | 51 +++---- include/grabber/FramebufferFrameGrabber.h | 4 +- include/grabber/FramebufferWrapper.h | 2 +- include/grabber/V4L2Grabber.h | 11 +- include/grabber/V4L2Wrapper.h | 2 +- include/grabber/VideoStandard.h | 7 +- include/hyperion/ColorAdjustment.h | 4 +- include/hyperion/GrabberWrapper.h | 1 - include/hyperion/Hyperion.h | 6 +- include/hyperion/LedString.h | 1 - include/hyperion/MessageForwarder.h | 4 +- include/kodivideochecker/KODIVideoChecker.h | 1 - include/leddevice/LedDevice.h | 11 +- include/protoserver/ProtoConnection.h | 6 +- include/utils/ColorRgb.h | 1 - include/utils/Logger.h | 21 ++- include/utils/PixelFormat.h | 7 +- include/utils/Profiler.h | 15 +- include/utils/RgbToRgbw.h | 3 +- include/utils/SysInfo.h | 20 +-- include/utils/VideoMode.h | 7 +- include/utils/jsonschema/QJsonFactory.h | 27 ++-- include/utils/jsonschema/QJsonSchemaChecker.h | 12 +- include/webconfig/WebConfig.h | 1 - libsrc/blackborder/BlackBorderProcessor.cpp | 4 +- libsrc/commandline/Option.cpp | 22 ++- libsrc/effectengine/EffectEngine.cpp | 6 +- libsrc/grabber/amlogic/AmlogicGrabber.cpp | 6 +- .../framebuffer/FramebufferFrameGrabber.cpp | 8 +- .../framebuffer/FramebufferWrapper.cpp | 2 +- libsrc/grabber/v4l2/V4L2Grabber.cpp | 48 +++--- libsrc/grabber/v4l2/V4L2Wrapper.cpp | 4 +- libsrc/hyperion/Hyperion.cpp | 21 ++- libsrc/hyperion/LinearColorSmoothing.h | 1 - libsrc/hyperion/MessageForwarder.cpp | 10 +- libsrc/hyperion/MultiColorAdjustment.cpp | 6 +- libsrc/hyperion/MultiColorAdjustment.h | 14 +- libsrc/jsonserver/JsonClientConnection.cpp | 143 +++++++++--------- libsrc/jsonserver/JsonClientConnection.h | 11 +- libsrc/jsonserver/JsonSchemas.qrc | 1 + libsrc/jsonserver/schema/schema-sysinfo.json | 15 ++ libsrc/jsonserver/schema/schema.json | 2 +- libsrc/leddevice/LedDevice.cpp | 15 +- libsrc/leddevice/LedDeviceAtmoOrb.cpp | 39 ++--- libsrc/leddevice/LedDeviceAtmoOrb.h | 4 +- libsrc/leddevice/LedDeviceDMX.cpp | 10 +- libsrc/leddevice/LedDeviceFactory.cpp | 14 +- libsrc/leddevice/LedDeviceFadeCandy.cpp | 6 +- libsrc/leddevice/LedDeviceFadeCandy.h | 3 +- libsrc/leddevice/LedDeviceFile.cpp | 4 +- libsrc/leddevice/LedDeviceHyperionUsbasp.cpp | 18 +-- libsrc/leddevice/LedDeviceHyperionUsbasp.h | 5 +- libsrc/leddevice/LedDeviceLightpack.cpp | 24 +-- libsrc/leddevice/LedDeviceLightpack.h | 10 +- libsrc/leddevice/LedDeviceMultiLightpack.cpp | 20 +-- libsrc/leddevice/LedDeviceMultiLightpack.h | 8 +- libsrc/leddevice/LedDevicePiBlaster.cpp | 14 +- libsrc/leddevice/LedDevicePiBlaster.h | 2 +- libsrc/leddevice/LedDeviceSk6812SPI.cpp | 6 +- libsrc/leddevice/LedDeviceTinkerforge.cpp | 10 +- libsrc/leddevice/LedDeviceTinkerforge.h | 6 +- libsrc/leddevice/LedDeviceUdpE131.cpp | 8 +- libsrc/leddevice/LedDeviceUdpE131.h | 2 +- libsrc/leddevice/LedDeviceWS281x.cpp | 6 +- libsrc/leddevice/ProviderSpi.cpp | 6 +- libsrc/leddevice/ProviderSpi.h | 2 +- libsrc/protoserver/ProtoConnection.cpp | 3 +- libsrc/protoserver/ProtoConnectionWrapper.cpp | 2 +- libsrc/utils/CMakeLists.txt | 2 +- libsrc/utils/Logger.cpp | 52 +++---- libsrc/utils/Process.cpp | 5 +- libsrc/utils/Profiler.cpp | 20 +-- libsrc/utils/RgbToRgbw.cpp | 4 +- libsrc/utils/SysInfo.cpp | 16 +- .../utils/jsonschema/QJsonSchemaChecker.cpp | 51 +++---- libsrc/webconfig/CgiHandler.cpp | 15 +- libsrc/webconfig/StaticFileServing.cpp | 4 +- .../FramebufferWrapper.cpp | 2 +- src/hyperion-framebuffer/FramebufferWrapper.h | 2 +- .../hyperion-framebuffer.cpp | 2 +- src/hyperion-remote/JsonConnection.cpp | 27 ++++ src/hyperion-remote/JsonConnection.h | 10 +- src/hyperion-remote/hyperion-remote.cpp | 11 +- src/hyperion-v4l2/hyperion-v4l2.cpp | 2 +- src/hyperiond/hyperiond.cpp | 15 +- test/TestConfigFile.cpp | 5 +- 90 files changed, 539 insertions(+), 529 deletions(-) create mode 100644 libsrc/jsonserver/schema/schema-sysinfo.json diff --git a/assets/webconfig/js/content_dashboard.js b/assets/webconfig/js/content_dashboard.js index 47159064..d2b13392 100644 --- a/assets/webconfig/js/content_dashboard.js +++ b/assets/webconfig/js/content_dashboard.js @@ -105,4 +105,4 @@ $(document).ready( function() { createHintH("intro", $.i18n('dashboard_label_intro'), "dash_intro"); removeOverlay(); -}); \ No newline at end of file +}); diff --git a/assets/webconfig/js/content_index.js b/assets/webconfig/js/content_index.js index dcd0cf93..e476df31 100644 --- a/assets/webconfig/js/content_index.js +++ b/assets/webconfig/js/content_index.js @@ -6,11 +6,14 @@ $(document).ready( function() { initWebSocket(); $(hyperion).on("cmd-serverinfo",function(event){ + // get sysinfo only once + if ( typeof(sysInfo.info) == "undefined" ) + requestSysInfo(); + serverInfo = event.response; - currentVersion = serverInfo.info.hyperion[0].version; $(hyperion).trigger("ready"); - if (serverInfo.info.hyperion[0].config_modified) + if (serverInfo.info.hyperion.config_modified) $("#hyperion_reload_notify").fadeIn("fast"); else $("#hyperion_reload_notify").fadeOut("fast"); @@ -22,7 +25,7 @@ $(document).ready( function() { loggingStreamActive = false; } - if (!serverInfo.info.hyperion[0].config_writeable) + if (!serverInfo.info.hyperion.config_writeable) { showInfoDialog('uilock',$.i18n('InfoDialog_nowrite_title'),$.i18n('InfoDialog_nowrite_text')); $('#wrapper').toggle(false); @@ -37,6 +40,11 @@ $(document).ready( function() { }); // end cmd-serverinfo + $(hyperion).one("cmd-sysinfo", function(event) { + sysInfo = event.response; + currentVersion = sysInfo.info.hyperion.version; + }); + $(hyperion).one("cmd-config-getschema", function(event) { serverSchema = event.response.result; requestServerConfig(); diff --git a/assets/webconfig/js/hyperion.js b/assets/webconfig/js/hyperion.js index b08b00ff..316638f2 100644 --- a/assets/webconfig/js/hyperion.js +++ b/assets/webconfig/js/hyperion.js @@ -3,12 +3,13 @@ var webPrio = 1; var webOrigin = "Web Configuration"; var showOptHelp; -var currentVersion; +var currentVersion = ""; var latestVersion; var serverInfo = {}; var parsedUpdateJSON = {}; var serverSchema = {}; var serverConfig = {}; +var sysInfo = {}; var schema; var jsonPort = 19444; var websocket = null; @@ -76,7 +77,6 @@ function initWebSocket() websocket.onopen = function (event) { $(hyperion).trigger({type:"open"}); - $(hyperion).on("cmd-serverinfo", function(event) { watchdog = 0; }); @@ -171,6 +171,11 @@ function requestServerInfo() sendToHyperion("serverinfo"); } +function requestSysInfo() +{ + sendToHyperion("sysinfo"); +} + function requestServerConfigSchema() { sendToHyperion("config","getschema"); diff --git a/include/blackborder/BlackBorderProcessor.h b/include/blackborder/BlackBorderProcessor.h index 03fef409..d5f1b9de 100644 --- a/include/blackborder/BlackBorderProcessor.h +++ b/include/blackborder/BlackBorderProcessor.h @@ -116,7 +116,7 @@ namespace hyperion unsigned _blurRemoveCnt; /// The border detection mode - const std::string _detectionMode; + const QString _detectionMode; /// The blackborder detector BlackBorderDetector _detector; diff --git a/include/commandline/Option.h b/include/commandline/Option.h index 722a002f..0981bc3d 100644 --- a/include/commandline/Option.h +++ b/include/commandline/Option.h @@ -1,5 +1,4 @@ -#ifndef HYPERION_OPTION_H -#define HYPERION_OPTION_H +#pragma once #include #include @@ -13,38 +12,30 @@ class Parser; * regular QCommandLineOption it is _not_ idempotent! */ class Option: public QCommandLineOption { -protected: - QString _error; public: - Option(const QString &name, - const QString &description = QString(), - const QString &valueName = QString::null, - const QString &defaultValue = QString() - ) - : QCommandLineOption(name, description, valueName, defaultValue) - {} - Option(const QStringList &names, - const QString &description = QString(), - const QString &valueName = QString::null, - const QString &defaultValue = QString() - ) - : QCommandLineOption(names, description, valueName, defaultValue) - {} - Option(const QCommandLineOption &other) - : QCommandLineOption(other) - {} + Option(const QString &name, + const QString &description = QString(), + const QString &valueName = QString::null, + const QString &defaultValue = QString() + ); - virtual bool validate(Parser &parser, QString &value); - QString name() - { return this->names().last();} - QString getError() - { return this->_error; } + Option(const QStringList &names, + const QString &description = QString(), + const QString &valueName = QString::null, + const QString &defaultValue = QString() + ); + + Option(const QCommandLineOption &other); + + virtual bool validate(Parser &parser, QString &value); + QString name(); + QString getError(); QString value(Parser &parser); - std::string getStdString(Parser &parser); - std::wstring getStdWString(Parser &parser); - const char* getCString(Parser &parser); + const char* getCString(Parser &parser); + +protected: + QString _error; }; } -#endif //HYPERION_OPTION_H diff --git a/include/grabber/FramebufferFrameGrabber.h b/include/grabber/FramebufferFrameGrabber.h index ae74a818..fd5add9c 100644 --- a/include/grabber/FramebufferFrameGrabber.h +++ b/include/grabber/FramebufferFrameGrabber.h @@ -20,7 +20,7 @@ public: /// @param[in] width The width of the captured screenshot /// @param[in] height The heigth of the captured screenshot /// - FramebufferFrameGrabber(const std::string & device, const unsigned width, const unsigned height); + FramebufferFrameGrabber(const QString & device, const unsigned width, const unsigned height); ~FramebufferFrameGrabber(); /// @@ -47,7 +47,7 @@ private: unsigned char * _fbp; /// Framebuffer device e.g. /dev/fb0 - const std::string _fbDevice; + const QString _fbDevice; /// With of the captured snapshot [pixels] const unsigned _width; diff --git a/include/grabber/FramebufferWrapper.h b/include/grabber/FramebufferWrapper.h index e0aa9602..4b5a80ef 100644 --- a/include/grabber/FramebufferWrapper.h +++ b/include/grabber/FramebufferWrapper.h @@ -28,7 +28,7 @@ public: /// @param[in] grabHeight The height of the grabbed images [pixels] /// @param[in] updateRate_Hz The image grab rate [Hz] /// - FramebufferWrapper(const std::string & device, const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz, const int priority); + FramebufferWrapper(const QString & device, const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz, const int priority); /// /// Destructor of this framebuffer frame grabber. Releases any claimed resources. diff --git a/include/grabber/V4L2Grabber.h b/include/grabber/V4L2Grabber.h index 9f3f9a31..4d157af9 100644 --- a/include/grabber/V4L2Grabber.h +++ b/include/grabber/V4L2Grabber.h @@ -1,7 +1,6 @@ #pragma once // stl includes -#include #include #include @@ -29,7 +28,7 @@ class V4L2Grabber : public QObject Q_OBJECT public: - V4L2Grabber(const std::string & device, + V4L2Grabber(const QString & device, int input, VideoStandard videoStandard, PixelFormat pixelFormat, int width, @@ -103,9 +102,9 @@ private: int xioctl(int request, void *arg); - void throw_exception(const std::string &error); + void throw_exception(const QString &error); - void throw_errno_exception(const std::string &error); + void throw_errno_exception(const QString &error); private: enum io_method { @@ -120,8 +119,8 @@ private: }; private: - std::string _deviceName; - std::map _v4lDevices; + QString _deviceName; + std::map _v4lDevices; int _input; VideoStandard _videoStandard; io_method _ioMethod; diff --git a/include/grabber/V4L2Wrapper.h b/include/grabber/V4L2Wrapper.h index 2f6e7915..bf347a12 100644 --- a/include/grabber/V4L2Wrapper.h +++ b/include/grabber/V4L2Wrapper.h @@ -13,7 +13,7 @@ class V4L2Wrapper : public GrabberWrapper Q_OBJECT public: - V4L2Wrapper(const std::string & device, + V4L2Wrapper(const QString & device, int input, VideoStandard videoStandard, PixelFormat pixelFormat, diff --git a/include/grabber/VideoStandard.h b/include/grabber/VideoStandard.h index 56636af8..72e7b58e 100644 --- a/include/grabber/VideoStandard.h +++ b/include/grabber/VideoStandard.h @@ -1,8 +1,5 @@ #pragma once -#include -#include - /** * Enumeration of the possible video standards the grabber can be set to */ @@ -12,10 +9,10 @@ enum VideoStandard { VIDEOSTANDARD_NO_CHANGE }; -inline VideoStandard parseVideoStandard(std::string videoStandard) +inline VideoStandard parseVideoStandard(QString videoStandard) { // convert to lower case - std::transform(videoStandard.begin(), videoStandard.end(), videoStandard.begin(), ::tolower); + videoStandard = videoStandard.toLower(); if (videoStandard == "pal") { diff --git a/include/hyperion/ColorAdjustment.h b/include/hyperion/ColorAdjustment.h index f3bb5228..2e04b07c 100644 --- a/include/hyperion/ColorAdjustment.h +++ b/include/hyperion/ColorAdjustment.h @@ -1,7 +1,7 @@ #pragma once // STL includes -#include +#include // Utils includes #include @@ -12,7 +12,7 @@ class ColorAdjustment public: /// Unique identifier for this color transform - std::string _id; + QString _id; /// The BLACK (RGB-Channel) adjustment RgbChannelAdjustment _rgbBlackAdjustment; diff --git a/include/hyperion/GrabberWrapper.h b/include/hyperion/GrabberWrapper.h index b066d814..d73d4587 100644 --- a/include/hyperion/GrabberWrapper.h +++ b/include/hyperion/GrabberWrapper.h @@ -2,7 +2,6 @@ #include #include -#include #include #include diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index 6e817284..3202b7af 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -128,7 +128,7 @@ public: /// get filename of configfile /// @return the current config filename - std::string getConfigFileName() { return _configFile.toStdString(); }; + QString getConfigFileName() { return _configFile; }; /// register a input source to a priority channel /// @param name uniq name of input source @@ -210,13 +210,13 @@ public slots: /// Returns the list with unique adjustment identifiers /// @return The list with adjustment identifiers /// - const std::vector & getAdjustmentIds() const; + const QStringList & getAdjustmentIds() const; /// /// Returns the ColorAdjustment with the given identifier /// @return The adjustment with the given identifier (or nullptr if the identifier does not exist) /// - ColorAdjustment * getAdjustment(const std::string& id); + ColorAdjustment * getAdjustment(const QString& id); /// /// Returns MessageForwarder Object diff --git a/include/hyperion/LedString.h b/include/hyperion/LedString.h index 186bf724..18808cc0 100644 --- a/include/hyperion/LedString.h +++ b/include/hyperion/LedString.h @@ -3,7 +3,6 @@ // STL includes #include -#include #include // Local includes diff --git a/include/hyperion/MessageForwarder.h b/include/hyperion/MessageForwarder.h index 48b084bc..d0d5de1a 100644 --- a/include/hyperion/MessageForwarder.h +++ b/include/hyperion/MessageForwarder.h @@ -25,8 +25,8 @@ public: MessageForwarder(); ~MessageForwarder(); - void addJsonSlave(std::string slave); - void addProtoSlave(std::string slave); + void addJsonSlave(QString slave); + void addProtoSlave(QString slave); bool protoForwardingEnabled(); bool jsonForwardingEnabled(); diff --git a/include/kodivideochecker/KODIVideoChecker.h b/include/kodivideochecker/KODIVideoChecker.h index f1731c4a..3c606fe9 100644 --- a/include/kodivideochecker/KODIVideoChecker.h +++ b/include/kodivideochecker/KODIVideoChecker.h @@ -3,7 +3,6 @@ // system includes #include -#include // QT includes #include diff --git a/include/leddevice/LedDevice.h b/include/leddevice/LedDevice.h index 522cd629..aae575eb 100644 --- a/include/leddevice/LedDevice.h +++ b/include/leddevice/LedDevice.h @@ -8,7 +8,6 @@ // STL incldues #include -#include #include #include @@ -24,7 +23,7 @@ class LedDevice; typedef LedDevice* ( *LedDeviceCreateFuncType ) ( const QJsonObject& ); -typedef std::map LedDeviceRegistry; +typedef std::map LedDeviceRegistry; /// /// Interface (pure virtual base class) for LedDevices. @@ -52,10 +51,10 @@ public: /// virtual int open(); - static int addToDeviceMap(std::string name, LedDeviceCreateFuncType funcPtr); + static int addToDeviceMap(QString name, LedDeviceCreateFuncType funcPtr); static const LedDeviceRegistry& getDeviceMap(); - static void setActiveDevice(std::string dev); - static std::string activeDevice() { return _activeDevice; } + static void setActiveDevice(QString dev); + static QString activeDevice() { return _activeDevice; } static QJsonObject getLedDeviceSchemas(); static void setLedCount(int ledCount); static int getLedCount() { return _ledCount; } @@ -78,7 +77,7 @@ protected: bool _deviceReady; - static std::string _activeDevice; + static QString _activeDevice; static LedDeviceRegistry _ledDeviceMap; static int _ledCount; diff --git a/include/protoserver/ProtoConnection.h b/include/protoserver/ProtoConnection.h index 732a4625..ee11bd37 100644 --- a/include/protoserver/ProtoConnection.h +++ b/include/protoserver/ProtoConnection.h @@ -1,9 +1,7 @@ #pragma once -// stl includes -#include - // Qt includes +#include #include #include #include @@ -33,7 +31,7 @@ public: /// /// @param address The address of the Hyperion server (for example "192.168.0.32:19444) /// - ProtoConnection(const std::string & address); + ProtoConnection(const QString & address); /// /// Destructor diff --git a/include/utils/ColorRgb.h b/include/utils/ColorRgb.h index 0bdd850a..3a05075a 100644 --- a/include/utils/ColorRgb.h +++ b/include/utils/ColorRgb.h @@ -49,7 +49,6 @@ inline std::ostream& operator<<(std::ostream& os, const ColorRgb& color) return os; } - /// Compare operator to check if a color is 'smaller' than another color inline bool operator<(const ColorRgb & lhs, const ColorRgb & rhs) { diff --git a/include/utils/Logger.h b/include/utils/Logger.h index 504f6901..2504b48e 100644 --- a/include/utils/Logger.h +++ b/include/utils/Logger.h @@ -5,7 +5,6 @@ #include // stl includes -#include #include #include #include @@ -51,9 +50,9 @@ public: } T_LOG_MESSAGE; static Logger* getInstance(QString name="", LogLevel minLevel=Logger::INFO); - static void deleteInstance(std::string name=""); - static void setLogLevel(LogLevel level,std::string name=""); - static LogLevel getLogLevel(std::string name=""); + static void deleteInstance(QString name=""); + static void setLogLevel(LogLevel level, QString name=""); + static LogLevel getLogLevel(QString name=""); void Message(LogLevel level, const char* sourceFile, const char* func, unsigned int line, const char* fmt, ...); void setMinLevel(LogLevel level) { _minLevel = level; }; @@ -63,18 +62,18 @@ signals: void newLogMessage(Logger::T_LOG_MESSAGE); protected: - Logger( std::string name="", LogLevel minLevel=INFO); + Logger( QString name="", LogLevel minLevel=INFO); ~Logger(); private: - static std::map *LoggerMap; + static std::map *LoggerMap; static LogLevel GLOBAL_MIN_LOG_LEVEL; - std::string _name; - std::string _appname; - LogLevel _minLevel; - bool _syslogEnabled; - unsigned int _loggerId; + QString _name; + QString _appname; + LogLevel _minLevel; + bool _syslogEnabled; + unsigned _loggerId; }; diff --git a/include/utils/PixelFormat.h b/include/utils/PixelFormat.h index 472b18f2..cade1817 100644 --- a/include/utils/PixelFormat.h +++ b/include/utils/PixelFormat.h @@ -1,7 +1,6 @@ #pragma once -#include -#include +#include /** * Enumeration of the possible pixel formats the grabber can be set to @@ -16,10 +15,10 @@ enum PixelFormat { PIXELFORMAT_NO_CHANGE }; -inline PixelFormat parsePixelFormat(std::string pixelFormat) +inline PixelFormat parsePixelFormat(QString pixelFormat) { // convert to lower case - std::transform(pixelFormat.begin(), pixelFormat.end(), pixelFormat.begin(), ::tolower); + pixelFormat = pixelFormat.toLower(); if (pixelFormat == "yuyv") { diff --git a/include/utils/Profiler.h b/include/utils/Profiler.h index 79e3d8b0..ba930e58 100644 --- a/include/utils/Profiler.h +++ b/include/utils/Profiler.h @@ -1,4 +1,3 @@ -#include #include #include #include @@ -23,16 +22,16 @@ public: Profiler(const char* sourceFile, const char* func, unsigned int line); ~Profiler(); - static void TimerStart(const std::string stopWatchName, const char* sourceFile, const char* func, unsigned int line); - static void TimerGetTime(const std::string stopWatchName, const char* sourceFile, const char* func, unsigned int line); + static void TimerStart(const QString stopWatchName, const char* sourceFile, const char* func, unsigned int line); + static void TimerGetTime(const QString stopWatchName, const char* sourceFile, const char* func, unsigned int line); private: static void initLogger(); static Logger* _logger; - const char* _file; - const char* _func; - unsigned int _line; - unsigned int _blockId; - clock_t _startTime; + const char* _file; + const char* _func; + unsigned int _line; + unsigned int _blockId; + clock_t _startTime; }; diff --git a/include/utils/RgbToRgbw.h b/include/utils/RgbToRgbw.h index 290e215b..f1450427 100644 --- a/include/utils/RgbToRgbw.h +++ b/include/utils/RgbToRgbw.h @@ -1,4 +1,5 @@ #pragma once +#include #include #include @@ -7,7 +8,7 @@ namespace RGBW { enum WhiteAlgorithm { INVALID, SUBTRACT_MINIMUM, SUB_MIN_WARM_ADJUST, WHITE_OFF }; - WhiteAlgorithm stringToWhiteAlgorithm(std::string str); + WhiteAlgorithm stringToWhiteAlgorithm(QString str); void Rgb_to_Rgbw(ColorRgb input, ColorRgbw * output, const WhiteAlgorithm algorithm); }; diff --git a/include/utils/SysInfo.h b/include/utils/SysInfo.h index 1e47a796..b6b97bb6 100644 --- a/include/utils/SysInfo.h +++ b/include/utils/SysInfo.h @@ -6,8 +6,7 @@ class SysInfo : public QObject { -// Q_OBJECT - + public: struct HyperionSysInfo { @@ -15,26 +14,27 @@ public: QString kernelVersion; QString architecture; QString wordSize; - QString productType; // $ID $DISTRIB_ID // single line file containing: // Debian - QString productVersion; // $VERSION_ID $DISTRIB_RELEASE // // single line file - QString prettyName; // $PRETTY_NAME $DISTRIB_DESCRIPTION + QString productType; + QString productVersion; + QString prettyName; + QString hostName; }; + ~SysInfo(); static HyperionSysInfo get(); private: SysInfo(); - ~SysInfo(); + static SysInfo* _instance; HyperionSysInfo _sysinfo; struct QUnixOSVersion { - // from /etc/os-release older /etc/lsb-release // redhat /etc/redhat-release // debian /etc/debian_version - QString productType; // $ID $DISTRIB_ID // single line file containing: // Debian - QString productVersion; // $VERSION_ID $DISTRIB_RELEASE // // single line file - QString prettyName; // $PRETTY_NAME $DISTRIB_DESCRIPTION + QString productType; + QString productVersion; + QString prettyName; }; QString machineHostName(); diff --git a/include/utils/VideoMode.h b/include/utils/VideoMode.h index ae727657..226a0e1f 100644 --- a/include/utils/VideoMode.h +++ b/include/utils/VideoMode.h @@ -1,7 +1,6 @@ #pragma once -#include -#include +#include /** * Enumeration of the possible modes in which video can be playing (2D, 3D) @@ -13,10 +12,10 @@ enum VideoMode VIDEO_3DTAB }; -inline VideoMode parse3DMode(std::string videoMode) +inline VideoMode parse3DMode(QString videoMode) { // convert to lower case - std::transform(videoMode.begin(), videoMode.end(), videoMode.begin(), ::tolower); + videoMode = videoMode.toLower(); if (videoMode == "3DTAB") { diff --git a/include/utils/jsonschema/QJsonFactory.h b/include/utils/jsonschema/QJsonFactory.h index 83b2a53e..89e5ef61 100644 --- a/include/utils/jsonschema/QJsonFactory.h +++ b/include/utils/jsonschema/QJsonFactory.h @@ -1,9 +1,7 @@ #pragma once #include -#include #include -#include // JSON-Schema includes #include @@ -30,9 +28,10 @@ public: bool valid = schemaChecker.validate(configTree); - for (std::list::const_iterator i = schemaChecker.getMessages().begin(); i != schemaChecker.getMessages().end(); ++i) + QStringList messages = schemaChecker.getMessages(); + for (int i = 0; i < messages.size(); ++i) { - std::cout << *i << std::endl; + std::cout << messages[i].toStdString() << std::endl; } if (!valid) @@ -52,9 +51,7 @@ public: if (!file.open(QIODevice::ReadOnly)) { - std::stringstream sstream; - sstream << "Configuration file not found: '" << path.toStdString() << "' (" << file.errorString().toStdString() << ")"; - throw std::runtime_error(sstream.str()); + throw std::runtime_error(QString("Configuration file not found: '" + path + "' (" + file.errorString() + ")").toStdString()); } QString config = QString(file.readAll()); @@ -78,9 +75,9 @@ public: } } - std::stringstream sstream; - sstream << "Failed to parse configuration: " << error.errorString().toStdString() << " at Line: " << errorLine << ", Column: " << errorColumn; - throw std::runtime_error(sstream.str()); + throw std::runtime_error ( + QString("Failed to parse configuration: " + error.errorString() + " at Line: " + QString::number(errorLine) + ", Column: " + QString::number(errorColumn)).toStdString() + ); } return doc.object(); @@ -93,9 +90,7 @@ public: if (!schemaData.open(QIODevice::ReadOnly)) { - std::stringstream sstream; - sstream << "Schema not found: '" << path.toStdString() << "' (" << schemaData.errorString().toStdString() << ")"; - throw std::runtime_error(sstream.str()); + throw std::runtime_error(QString("Schema not found: '" + path + "' (" + schemaData.errorString() + ")").toStdString()); } QByteArray schema = schemaData.readAll(); @@ -117,9 +112,9 @@ public: } } - std::stringstream sstream; - sstream << "ERROR: Json schema wrong: " << error.errorString().toStdString() << " at Line: " << errorLine << ", Column: " << errorColumn; - throw std::runtime_error(sstream.str()); + throw std::runtime_error(QString("ERROR: Json schema wrong: " + error.errorString() + " at Line: " + QString::number(errorLine) + + ", Column: " + QString::number(errorColumn)).toStdString() + ); } return doc.object(); diff --git a/include/utils/jsonschema/QJsonSchemaChecker.h b/include/utils/jsonschema/QJsonSchemaChecker.h index fce7b112..f250d41b 100644 --- a/include/utils/jsonschema/QJsonSchemaChecker.h +++ b/include/utils/jsonschema/QJsonSchemaChecker.h @@ -1,9 +1,5 @@ #pragma once -// stl includes -#include -#include - #include #include #include @@ -48,7 +44,7 @@ public: /// /// @return A list of error messages /// - const std::list & getMessages() const; + const QStringList & getMessages() const; private: /// @@ -65,7 +61,7 @@ private: /// /// @param[in] message The message to add to the queue /// - void setMessage(const std::string & message); + void setMessage(const QString & message); private: // attribute check functions @@ -166,9 +162,9 @@ private: /// ignore the required value in json schema bool _ignoreRequired; /// The current location into a json-configuration structure being checked - std::list _currentPath; + QStringList _currentPath; /// The result messages collected during the schema verification - std::list _messages; + QStringList _messages; /// Flag indicating an error occured during validation bool _error; }; diff --git a/include/webconfig/WebConfig.h b/include/webconfig/WebConfig.h index 379459d2..b29c89cb 100644 --- a/include/webconfig/WebConfig.h +++ b/include/webconfig/WebConfig.h @@ -3,7 +3,6 @@ #include #include -#include #include class StaticFileServing; diff --git a/libsrc/blackborder/BlackBorderProcessor.cpp b/libsrc/blackborder/BlackBorderProcessor.cpp index cbe4bc33..75148c8e 100644 --- a/libsrc/blackborder/BlackBorderProcessor.cpp +++ b/libsrc/blackborder/BlackBorderProcessor.cpp @@ -14,7 +14,7 @@ BlackBorderProcessor::BlackBorderProcessor(const QJsonObject &blackborderConfig) , _borderSwitchCnt(blackborderConfig["borderFrameCnt"].toInt(50)) , _maxInconsistentCnt(blackborderConfig["maxInconsistentCnt"].toInt(10)) , _blurRemoveCnt(blackborderConfig["blurRemoveCnt"].toInt(1)) - , _detectionMode(blackborderConfig["mode"].toString("default").toStdString()) + , _detectionMode(blackborderConfig["mode"].toString("default")) , _detector(blackborderConfig["threshold"].toDouble(0.01)) , _currentBorder({true, -1, -1}) , _previousDetectedBorder({true, -1, -1}) @@ -23,7 +23,7 @@ BlackBorderProcessor::BlackBorderProcessor(const QJsonObject &blackborderConfig) { if (_enabled) { - Debug(Logger::getInstance("BLACKBORDER"), "mode: %s", _detectionMode.c_str()); + Debug(Logger::getInstance("BLACKBORDER"), "mode: %s", QSTRING_CSTR(_detectionMode)); } } diff --git a/libsrc/commandline/Option.cpp b/libsrc/commandline/Option.cpp index aa045bf3..4b25ad9d 100644 --- a/libsrc/commandline/Option.cpp +++ b/libsrc/commandline/Option.cpp @@ -3,29 +3,41 @@ using namespace commandline; +Option::Option(const QString &name, const QString &description, const QString &valueName, const QString &defaultValue) + : QCommandLineOption(name, description, valueName, defaultValue) +{} + +Option::Option(const QStringList &names, const QString &description, const QString &valueName, const QString &defaultValue) + : QCommandLineOption(names, description, valueName, defaultValue) +{} + + bool Option::validate(Parser & parser, QString &value) { /* By default everything is accepted */ return true; } +Option::Option(const QCommandLineOption &other) + : QCommandLineOption(other) +{} + QString Option::value(Parser &parser) { return parser.value(*this); } -std::string Option::getStdString(Parser &parser) +QString Option::name() { - return value(parser).toStdString(); + return this->names().last(); } -std::wstring Option::getStdWString(Parser &parser) +QString Option::getError() { - return value(parser).toStdWString(); + return this->_error; } const char* Option::getCString(Parser &parser) { return value(parser).toLocal8Bit().constData(); } - diff --git a/libsrc/effectengine/EffectEngine.cpp b/libsrc/effectengine/EffectEngine.cpp index 414e6f19..a84dd9fa 100644 --- a/libsrc/effectengine/EffectEngine.cpp +++ b/libsrc/effectengine/EffectEngine.cpp @@ -152,10 +152,10 @@ bool EffectEngine::loadEffectDefinition(const QString &path, const QString &effe schemaChecker.setSchema(configSchema.object()); if (!schemaChecker.validate(configEffect.object())) { - const std::list & errors = schemaChecker.getMessages(); - foreach (const std::string & error, errors) + const QStringList & errors = schemaChecker.getMessages(); + foreach (auto & error, errors) { - Error( log, "Error while checking '%s':%s", fileName.toUtf8().constData(), error.c_str()); + Error( log, "Error while checking '%s':%s", QSTRING_CSTR(fileName), QSTRING_CSTR(error)); } return false; } diff --git a/libsrc/grabber/amlogic/AmlogicGrabber.cpp b/libsrc/grabber/amlogic/AmlogicGrabber.cpp index 3e575f7e..a609b3b8 100755 --- a/libsrc/grabber/amlogic/AmlogicGrabber.cpp +++ b/libsrc/grabber/amlogic/AmlogicGrabber.cpp @@ -69,13 +69,13 @@ void AmlogicGrabber::setVideoMode(const VideoMode videoMode) bool AmlogicGrabber::isVideoPlaying() { - const std::string videoDevice = "/dev/amvideo"; + const QString videoDevice = "/dev/amvideo"; // Open the video device - int video_fd = open(videoDevice.c_str(), O_RDONLY); + int video_fd = open(QSTRING_CSTR(videoDevice), O_RDONLY); if (video_fd < 0) { - Error(_log, "Failed to open video device(%s): %d - %s", videoDevice.c_str(), errno, strerror(errno)); + Error(_log, "Failed to open video device(%s): %d - %s", QSTRING_CSTR(videoDevice), errno, strerror(errno)); return false; } diff --git a/libsrc/grabber/framebuffer/FramebufferFrameGrabber.cpp b/libsrc/grabber/framebuffer/FramebufferFrameGrabber.cpp index 699d832d..fa320f22 100755 --- a/libsrc/grabber/framebuffer/FramebufferFrameGrabber.cpp +++ b/libsrc/grabber/framebuffer/FramebufferFrameGrabber.cpp @@ -12,7 +12,7 @@ // Local includes #include -FramebufferFrameGrabber::FramebufferFrameGrabber(const std::string & device, const unsigned width, const unsigned height) : +FramebufferFrameGrabber::FramebufferFrameGrabber(const QString & device, const unsigned width, const unsigned height) : _fbfd(0), _fbp(0), _fbDevice(device), @@ -25,10 +25,10 @@ FramebufferFrameGrabber::FramebufferFrameGrabber(const std::string & device, con struct fb_var_screeninfo vinfo; // Check if the framebuffer device can be opened and display the current resolution - _fbfd = open(_fbDevice.c_str(), O_RDONLY); + _fbfd = open(QSTRING_CSTR(_fbDevice), O_RDONLY); if (_fbfd == 0) { - Error(_log, "Error openning %s", _fbDevice.c_str()); + Error(_log, "Error openning %s", QSTRING_CSTR(_fbDevice)); } else { @@ -63,7 +63,7 @@ void FramebufferFrameGrabber::grabFrame(Image & image) PixelFormat pixelFormat; /* Open the framebuffer device */ - _fbfd = open(_fbDevice.c_str(), O_RDONLY); + _fbfd = open(QSTRING_CSTR(_fbDevice), O_RDONLY); /* get variable screen information */ ioctl (_fbfd, FBIOGET_VSCREENINFO, &vinfo); diff --git a/libsrc/grabber/framebuffer/FramebufferWrapper.cpp b/libsrc/grabber/framebuffer/FramebufferWrapper.cpp index 3c60607b..6deb0d9b 100644 --- a/libsrc/grabber/framebuffer/FramebufferWrapper.cpp +++ b/libsrc/grabber/framebuffer/FramebufferWrapper.cpp @@ -7,7 +7,7 @@ #include #include -FramebufferWrapper::FramebufferWrapper(const std::string & device, const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz, const int priority) +FramebufferWrapper::FramebufferWrapper(const QString & device, const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz, const int priority) : GrabberWrapper("FrameBuffer", priority) , _updateInterval_ms(1000/updateRate_Hz) , _timeout_ms(2 * _updateInterval_ms) diff --git a/libsrc/grabber/v4l2/V4L2Grabber.cpp b/libsrc/grabber/v4l2/V4L2Grabber.cpp index c04587f7..dc71fe5c 100644 --- a/libsrc/grabber/v4l2/V4L2Grabber.cpp +++ b/libsrc/grabber/v4l2/V4L2Grabber.cpp @@ -23,7 +23,7 @@ #define CLEAR(x) memset(&(x), 0, sizeof(x)) -V4L2Grabber::V4L2Grabber(const std::string & device +V4L2Grabber::V4L2Grabber(const QString & device , int input , VideoStandard videoStandard , PixelFormat pixelFormat @@ -51,7 +51,7 @@ V4L2Grabber::V4L2Grabber(const std::string & device , _noSignalCounter(0) , _streamNotifier(nullptr) , _imageResampler() - , _log(Logger::getInstance("V4L2:"+QString::fromStdString(device))) + , _log(Logger::getInstance("V4L2:"+device)) , _initialized(false) , _deviceAutoDiscoverEnabled(false) , _noSignalDetected(false) @@ -74,7 +74,7 @@ V4L2Grabber::~V4L2Grabber() void V4L2Grabber::uninit() { - Debug(_log,"uninit grabber: %s", _deviceName.c_str()); + Debug(_log,"uninit grabber: %s", QSTRING_CSTR(_deviceName)); // stop if the grabber was not stopped if (_initialized) { @@ -91,16 +91,16 @@ bool V4L2Grabber::init() if (! _initialized) { getV4Ldevices(); - std::string v4lDevices_str; + QString v4lDevices_str; // show list only once - if ( ! QString(_deviceName.c_str()).startsWith("/dev/") ) + if ( ! QString(QSTRING_CSTR(_deviceName)).startsWith("/dev/") ) { for (auto& dev: _v4lDevices) { v4lDevices_str += "\t"+ dev.first + "\t" + dev.second + "\n"; } - Info(_log, "available V4L2 devices:\n%s", v4lDevices_str.c_str()); + Info(_log, "available V4L2 devices:\n%s", QSTRING_CSTR(v4lDevices_str)); } if ( _deviceName == "auto" ) @@ -113,28 +113,28 @@ bool V4L2Grabber::init() _deviceName = dev.first; if ( init() ) { - Info(_log, "found usable v4l2 device: %s (%s)",dev.first.c_str(), dev.second.c_str()); + Info(_log, "found usable v4l2 device: %s (%s)",QSTRING_CSTR(dev.first), QSTRING_CSTR(dev.second)); _deviceAutoDiscoverEnabled = false; return _initialized; } } Info( _log, "no usable device found" ); } - else if ( ! QString(_deviceName.c_str()).startsWith("/dev/") ) + else if ( ! _deviceName.startsWith("/dev/") ) { for (auto& dev: _v4lDevices) { - if ( QString(_deviceName.c_str()).toLower() == QString(dev.second.c_str()).toLower() ) + if ( _deviceName.toLower() == dev.second.toLower() ) { _deviceName = dev.first; - Info(_log, "found v4l2 device with configured name: %s (%s)", dev.second.c_str(), dev.first.c_str() ); + Info(_log, "found v4l2 device with configured name: %s (%s)", QSTRING_CSTR(dev.second), QSTRING_CSTR(dev.first) ); break; } } } else { - Info(_log, "%s v4l device: %s", (_deviceAutoDiscoverEnabled? "test" : "configured"),_deviceName.c_str()); + Info(_log, "%s v4l device: %s", (_deviceAutoDiscoverEnabled? "test" : "configured"), QSTRING_CSTR(_deviceName)); } bool opened = false; @@ -177,7 +177,7 @@ void V4L2Grabber::getV4Ldevices() devName = devName.trimmed(); devNameFile.close(); } - _v4lDevices.emplace("/dev/"+it.fileName().toStdString(), devName.toStdString()); + _v4lDevices.emplace("/dev/"+it.fileName(), devName); } } } @@ -194,14 +194,12 @@ void V4L2Grabber::set3D(VideoMode mode) void V4L2Grabber::setSignalThreshold(double redSignalThreshold, double greenSignalThreshold, double blueSignalThreshold, int noSignalCounterThreshold) { - _noSignalThresholdColor.red = uint8_t(255*redSignalThreshold); + _noSignalThresholdColor.red = uint8_t(255*redSignalThreshold); _noSignalThresholdColor.green = uint8_t(255*greenSignalThreshold); - _noSignalThresholdColor.blue = uint8_t(255*blueSignalThreshold); - _noSignalCounterThreshold = std::max(1, noSignalCounterThreshold); + _noSignalThresholdColor.blue = uint8_t(255*blueSignalThreshold); + _noSignalCounterThreshold = std::max(1, noSignalCounterThreshold); - std::stringstream ss; - ss << _noSignalThresholdColor; - Info(_log, "Signal threshold set to: %s", ss.str().c_str() ); + Info(_log, "Signal threshold set to: {%d, %d, %d}", _noSignalThresholdColor.red, _noSignalThresholdColor.green, _noSignalThresholdColor.blue ); } void V4L2Grabber::setSignalDetectionOffset(double horizontalMin, double verticalMin, double horizontalMax, double verticalMax) @@ -256,7 +254,7 @@ void V4L2Grabber::open_device() { struct stat st; - if (-1 == stat(_deviceName.c_str(), &st)) + if (-1 == stat(QSTRING_CSTR(_deviceName), &st)) { throw_errno_exception("Cannot identify '" + _deviceName + "'"); } @@ -266,7 +264,7 @@ void V4L2Grabber::open_device() throw_exception("'" + _deviceName + "' is no device"); } - _fileDescriptor = open(_deviceName.c_str(), O_RDWR /* required */ | O_NONBLOCK, 0); + _fileDescriptor = open(QSTRING_CSTR(_deviceName), O_RDWR | O_NONBLOCK, 0); if (-1 == _fileDescriptor) { @@ -870,14 +868,12 @@ int V4L2Grabber::xioctl(int request, void *arg) return r; } -void V4L2Grabber::throw_exception(const std::string & error) +void V4L2Grabber::throw_exception(const QString & error) { - throw std::runtime_error(error); + throw std::runtime_error(error.toStdString()); } -void V4L2Grabber::throw_errno_exception(const std::string & error) +void V4L2Grabber::throw_errno_exception(const QString & error) { - std::ostringstream oss; - oss << error << " error code " << errno << ", " << strerror(errno); - throw std::runtime_error(oss.str()); + throw std::runtime_error(QString(error + " error code " + QString::number(errno) + ", " + strerror(errno)).toStdString()); } diff --git a/libsrc/grabber/v4l2/V4L2Wrapper.cpp b/libsrc/grabber/v4l2/V4L2Wrapper.cpp index 2358528c..3ff2664f 100644 --- a/libsrc/grabber/v4l2/V4L2Wrapper.cpp +++ b/libsrc/grabber/v4l2/V4L2Wrapper.cpp @@ -4,7 +4,7 @@ #include -V4L2Wrapper::V4L2Wrapper(const std::string &device, +V4L2Wrapper::V4L2Wrapper(const QString &device, int input, VideoStandard videoStandard, PixelFormat pixelFormat, @@ -16,7 +16,7 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device, double greenSignalThreshold, double blueSignalThreshold, const int priority) - : GrabberWrapper("V4L2:"+QString::fromStdString(device), priority, hyperion::COMP_V4L) + : GrabberWrapper("V4L2:"+device, priority, hyperion::COMP_V4L) , _timeout_ms(1000) , _grabber(device, input, diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index 2cf31447..8835e396 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -58,7 +58,7 @@ ColorOrder Hyperion::createColorOrder(const QJsonObject &deviceConfig) ColorAdjustment * Hyperion::createColorAdjustment(const QJsonObject & adjustmentConfig) { - const std::string id = adjustmentConfig["id"].toString("default").toStdString(); + const QString id = adjustmentConfig["id"].toString("default"); RgbChannelAdjustment * blackAdjustment = createRgbChannelAdjustment(adjustmentConfig, "black" , 0, 0, 0); RgbChannelAdjustment * whiteAdjustment = createRgbChannelAdjustment(adjustmentConfig, "white" , 255,255,255); @@ -117,13 +117,13 @@ MultiColorAdjustment * Hyperion::createLedColorsAdjustment(const unsigned ledCnt { // Special case for indices '*' => all leds adjustment->setAdjustmentForLed(colorAdjustment->_id, 0, ledCnt-1); - Info(CORE_LOGGER, "ColorAdjustment '%s' => [0; %d]", colorAdjustment->_id.c_str(), ledCnt-1); + Info(CORE_LOGGER, "ColorAdjustment '%s' => [0; %d]", QSTRING_CSTR(colorAdjustment->_id), ledCnt-1); continue; } if (!overallExp.exactMatch(ledIndicesStr)) { - Error(CORE_LOGGER, "Given led indices %d not correct format: %s", i, ledIndicesStr.toStdString().c_str()); + Error(CORE_LOGGER, "Given led indices %d not correct format: %s", i, QSTRING_CSTR(ledIndicesStr)); continue; } @@ -150,7 +150,7 @@ MultiColorAdjustment * Hyperion::createLedColorsAdjustment(const unsigned ledCnt ss << index; } } - Info(CORE_LOGGER, "ColorAdjustment '%s' => [%s]", colorAdjustment->_id.c_str(), ss.str().c_str()); + Info(CORE_LOGGER, "ColorAdjustment '%s' => [%s]", QSTRING_CSTR(colorAdjustment->_id), ss.str().c_str()); } return adjustment; @@ -319,8 +319,7 @@ QSize Hyperion::getLedLayoutGridSize(const QJsonValue& ledsConfig) LinearColorSmoothing * Hyperion::createColorSmoothing(const QJsonObject & smoothingConfig, LedDevice* leddevice) { - std::string type = smoothingConfig["type"].toString("linear").toStdString(); - std::transform(type.begin(), type.end(), type.begin(), ::tolower); + QString type = smoothingConfig["type"].toString("linear").toLower(); LinearColorSmoothing * device = nullptr; type = "linear"; // TODO currently hardcoded type, delete it if we have more types @@ -337,7 +336,7 @@ LinearColorSmoothing * Hyperion::createColorSmoothing(const QJsonObject & smooth } else { - Error(CORE_LOGGER, "Smoothing disabled, because of unknown type '%s'.", type.c_str()); + Error(CORE_LOGGER, "Smoothing disabled, because of unknown type '%s'.", QSTRING_CSTR(type)); } device->setEnable(smoothingConfig["enable"].toBool(true)); @@ -358,7 +357,7 @@ MessageForwarder * Hyperion::createMessageForwarder(const QJsonObject & forwarde for (signed i = 0; i < addr.size(); ++i) { Info(CORE_LOGGER, "Json forward to %s", addr.at(i).toString().toStdString().c_str()); - forwarder->addJsonSlave(addr[i].toString().toStdString()); + forwarder->addJsonSlave(addr[i].toString()); } } @@ -368,7 +367,7 @@ MessageForwarder * Hyperion::createMessageForwarder(const QJsonObject & forwarde for (signed i = 0; i < addr.size(); ++i) { Info(CORE_LOGGER, "Proto forward to %s", addr.at(i).toString().toStdString().c_str()); - forwarder->addProtoSlave(addr[i].toString().toStdString()); + forwarder->addProtoSlave(addr[i].toString()); } } } @@ -603,12 +602,12 @@ void Hyperion::setImage(int priority, const Image & image, int duratio } } -const std::vector & Hyperion::getAdjustmentIds() const +const QStringList & Hyperion::getAdjustmentIds() const { return _raw2ledAdjustment->getAdjustmentIds(); } -ColorAdjustment * Hyperion::getAdjustment(const std::string& id) +ColorAdjustment * Hyperion::getAdjustment(const QString& id) { return _raw2ledAdjustment->getAdjustment(id); } diff --git a/libsrc/hyperion/LinearColorSmoothing.h b/libsrc/hyperion/LinearColorSmoothing.h index 03cbbae1..d321cb01 100644 --- a/libsrc/hyperion/LinearColorSmoothing.h +++ b/libsrc/hyperion/LinearColorSmoothing.h @@ -1,7 +1,6 @@ #pragma once // STL includes -#include #include diff --git a/libsrc/hyperion/MessageForwarder.cpp b/libsrc/hyperion/MessageForwarder.cpp index 95d007ee..9ddb9863 100644 --- a/libsrc/hyperion/MessageForwarder.cpp +++ b/libsrc/hyperion/MessageForwarder.cpp @@ -13,11 +13,11 @@ MessageForwarder::~MessageForwarder() } -void MessageForwarder::addJsonSlave(std::string slave) +void MessageForwarder::addJsonSlave(QString slave) { - QStringList parts = QString(slave.c_str()).split(":"); + QStringList parts = slave.split(":"); if (parts.size() != 2) - throw std::runtime_error(QString("HYPERION (forwarder) ERROR: Wrong address: unable to parse address (%1)").arg(slave.c_str()).toStdString()); + throw std::runtime_error(QString("HYPERION (forwarder) ERROR: Wrong address: unable to parse address (%1)").arg(slave).toStdString()); bool ok; quint16 port = parts[1].toUShort(&ok); @@ -30,9 +30,9 @@ void MessageForwarder::addJsonSlave(std::string slave) _jsonSlaves << c; } -void MessageForwarder::addProtoSlave(std::string slave) +void MessageForwarder::addProtoSlave(QString slave) { - _protoSlaves << QString(slave.c_str()); + _protoSlaves << slave; } QStringList MessageForwarder::getProtoSlaves() diff --git a/libsrc/hyperion/MultiColorAdjustment.cpp b/libsrc/hyperion/MultiColorAdjustment.cpp index b1662ba6..8af98804 100644 --- a/libsrc/hyperion/MultiColorAdjustment.cpp +++ b/libsrc/hyperion/MultiColorAdjustment.cpp @@ -27,7 +27,7 @@ void MultiColorAdjustment::addAdjustment(ColorAdjustment * adjustment) _adjustment.push_back(adjustment); } -void MultiColorAdjustment::setAdjustmentForLed(const std::string& id, const unsigned startLed, const unsigned endLed) +void MultiColorAdjustment::setAdjustmentForLed(const QString& id, const unsigned startLed, const unsigned endLed) { assert(startLed <= endLed); assert(endLed < _ledAdjustments.size()); @@ -61,12 +61,12 @@ bool MultiColorAdjustment::verifyAdjustments() const return true; } -const std::vector & MultiColorAdjustment::getAdjustmentIds() +const QStringList & MultiColorAdjustment::getAdjustmentIds() { return _adjustmentIds; } -ColorAdjustment* MultiColorAdjustment::getAdjustment(const std::string& id) +ColorAdjustment* MultiColorAdjustment::getAdjustment(const QString& id) { // Iterate through the unique adjustments until we find the one with the given id for (ColorAdjustment* adjustment : _adjustment) diff --git a/libsrc/hyperion/MultiColorAdjustment.h b/libsrc/hyperion/MultiColorAdjustment.h index eaeb94ba..f6568049 100644 --- a/libsrc/hyperion/MultiColorAdjustment.h +++ b/libsrc/hyperion/MultiColorAdjustment.h @@ -2,11 +2,11 @@ // STL includes #include - -// Utils includes -#include +#include +#include // Hyperion includes +#include #include /// @@ -26,7 +26,7 @@ public: */ void addAdjustment(ColorAdjustment * adjustment); - void setAdjustmentForLed(const std::string& id, const unsigned startLed, const unsigned endLed); + void setAdjustmentForLed(const QString& id, const unsigned startLed, const unsigned endLed); bool verifyAdjustments() const; @@ -36,7 +36,7 @@ public: /// Returns the identifier of all the unique ColorAdjustment /// /// @return The list with unique id's of the ColorAdjustment - const std::vector & getAdjustmentIds(); + const QStringList & getAdjustmentIds(); /// /// Returns the pointer to the ColorAdjustment with the given id @@ -45,7 +45,7 @@ public: /// /// @return The ColorAdjustment with the given id (or nullptr if it does not exist) /// - ColorAdjustment* getAdjustment(const std::string& id); + ColorAdjustment* getAdjustment(const QString& id); /// /// Performs the color adjustment from raw-color to led-color @@ -56,7 +56,7 @@ public: private: /// List with transform ids - std::vector _adjustmentIds; + QStringList _adjustmentIds; /// List with unique ColorTransforms std::vector _adjustment; diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 84bea379..a7cba33d 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -41,6 +41,7 @@ #include #include #include +#include // project includes #include "JsonClientConnection.h" @@ -98,13 +99,13 @@ void JsonClientConnection::readData() while(bytes > 0) { // create message string - std::string message(_receiveBuffer.data(), bytes); + QString message(QByteArray(_receiveBuffer.data(), bytes)); // remove message data from buffer _receiveBuffer = _receiveBuffer.mid(bytes); // handle message - handleMessage(QString::fromStdString(message)); + handleMessage(message); // try too look up '\n' again bytes = _receiveBuffer.indexOf('\n') + 1; @@ -215,14 +216,14 @@ void JsonClientConnection::doWebSocketHandshake() // get the key to prepare an answer int start = _receiveBuffer.indexOf("Sec-WebSocket-Key") + 19; - std::string value(_receiveBuffer.mid(start, _receiveBuffer.indexOf("\r\n", start) - start).data()); + QByteArray value = _receiveBuffer.mid(start, _receiveBuffer.indexOf("\r\n", start) - start); _receiveBuffer.clear(); // must be always appended value += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; // generate sha1 hash - QByteArray hash = QCryptographicHash::hash(value.c_str(), QCryptographicHash::Sha1); + QByteArray hash = QCryptographicHash::hash(value, QCryptographicHash::Sha1); // prepare an answer std::ostringstream h; @@ -292,38 +293,23 @@ void JsonClientConnection::handleMessage(const QString& messageString) int tan = message["tan"].toInt(0); // switch over all possible commands and handle them - if (command == "color") - handleColorCommand(message, command, tan); - else if (command == "image") - handleImageCommand(message, command, tan); - else if (command == "effect") - handleEffectCommand(message, command, tan); - else if (command == "create-effect") - handleCreateEffectCommand(message, command, tan); - else if (command == "delete-effect") - handleDeleteEffectCommand(message, command, tan); - else if (command == "serverinfo") - handleServerInfoCommand(message, command, tan); - else if (command == "clear") - handleClearCommand(message, command, tan); - else if (command == "clearall") - handleClearallCommand(message, command, tan); - else if (command == "adjustment") - handleAdjustmentCommand(message, command, tan); - else if (command == "sourceselect") - handleSourceSelectCommand(message, command, tan); - else if (command == "config") - handleConfigCommand(message, command, tan); - else if (command == "componentstate") - handleComponentStateCommand(message, command, tan); - else if (command == "ledcolors") - handleLedColorsCommand(message, command, tan); - else if (command == "logging") - handleLoggingCommand(message, command, tan); - else if (command == "processing") - handleProcessingCommand(message, command, tan); - else - handleNotImplemented(); + if (command == "color") handleColorCommand (message, command, tan); + else if (command == "image") handleImageCommand (message, command, tan); + else if (command == "effect") handleEffectCommand (message, command, tan); + else if (command == "create-effect") handleCreateEffectCommand (message, command, tan); + else if (command == "delete-effect") handleDeleteEffectCommand (message, command, tan); + else if (command == "serverinfo") handleServerInfoCommand (message, command, tan); + else if (command == "sysinfo") handleSysInfoCommand (message, command, tan); + else if (command == "clear") handleClearCommand (message, command, tan); + else if (command == "clearall") handleClearallCommand (message, command, tan); + else if (command == "adjustment") handleAdjustmentCommand (message, command, tan); + else if (command == "sourceselect") handleSourceSelectCommand (message, command, tan); + else if (command == "config") handleConfigCommand (message, command, tan); + else if (command == "componentstate") handleComponentStateCommand(message, command, tan); + else if (command == "ledcolors") handleLedColorsCommand (message, command, tan); + else if (command == "logging") handleLoggingCommand (message, command, tan); + else if (command == "processing") handleProcessingCommand (message, command, tan); + else handleNotImplemented (); } catch (std::exception& e) { @@ -571,6 +557,41 @@ void JsonClientConnection::handleDeleteEffectCommand(const QJsonObject& message, sendErrorReply("Error while parsing json: Message size " + QString(message.size()), command, tan); } + +void JsonClientConnection::handleSysInfoCommand(const QJsonObject&, const QString& command, const int tan) +{ + // create result + QJsonObject result; + QJsonObject info; + result["success"] = true; + result["command"] = command; + result["tan"] = tan; + + SysInfo::HyperionSysInfo data = SysInfo::get(); + QJsonObject system; + system["kernelType" ] = data.kernelType; + system["kernelVersion" ] = data.kernelVersion; + system["architecture" ] = data.architecture; + system["wordSize" ] = data.wordSize; + system["productType" ] = data.productType; + system["productVersion"] = data.productVersion; + system["prettyName" ] = data.prettyName; + system["hostName" ] = data.hostName; + info["system"] = system; + + QJsonObject hyperion; + hyperion["jsonrpc_version" ] = QString(HYPERION_JSON_VERSION); + hyperion["version" ] = QString(HYPERION_VERSION); + hyperion["build" ] = QString(HYPERION_BUILD_ID); + hyperion["time" ] = QString(__DATE__ " " __TIME__); + info["hyperion"] = hyperion; + + // send the result + result["info" ] = info; + sendMessage(result); +} + + void JsonClientConnection::handleServerInfoCommand(const QJsonObject&, const QString& command, const int tan) { // create result @@ -581,9 +602,6 @@ void JsonClientConnection::handleServerInfoCommand(const QJsonObject&, const QSt QJsonObject info; - // add host name for remote clients - info["hostname"] = QHostInfo::localHostName(); - // collect priority information QJsonArray priorities; uint64_t now = QDateTime::currentMSecsSinceEpoch(); @@ -677,17 +695,17 @@ void JsonClientConnection::handleServerInfoCommand(const QJsonObject&, const QSt // collect adjustment information QJsonArray adjustmentArray; - for (const std::string& adjustmentId : _hyperion->getAdjustmentIds()) + for (const QString& adjustmentId : _hyperion->getAdjustmentIds()) { const ColorAdjustment * colorAdjustment = _hyperion->getAdjustment(adjustmentId); if (colorAdjustment == nullptr) { - Error(_log, "Incorrect color adjustment id: %s", adjustmentId.c_str()); + Error(_log, "Incorrect color adjustment id: %s", QSTRING_CSTR(adjustmentId)); continue; } QJsonObject adjustment; - adjustment["id"] = QString::fromStdString(adjustmentId); + adjustment["id"] = adjustmentId; QJsonArray blackAdjust; blackAdjust.append(colorAdjustment->_rgbBlackAdjustment.getAdjustmentR()); @@ -766,11 +784,11 @@ void JsonClientConnection::handleServerInfoCommand(const QJsonObject&, const QSt // get available led devices QJsonObject ledDevices; - ledDevices["active"] = QString::fromStdString(LedDevice::activeDevice()); + ledDevices["active"] =LedDevice::activeDevice(); QJsonArray availableLedDevices; for (auto dev: LedDevice::getDeviceMap()) { - availableLedDevices.append(QString::fromStdString(dev.first)); + availableLedDevices.append(dev.first); } ledDevices["available"] = availableLedDevices; @@ -805,17 +823,10 @@ void JsonClientConnection::handleServerInfoCommand(const QJsonObject&, const QSt info["components"] = component; info["ledMAppingType"] = ImageProcessor::mappingTypeToStr(_hyperion->getLedMappingType()); - // Add Hyperion Version, build time - QJsonArray hyperion; - QJsonObject ver; - ver["jsonrpc_version"] = QString(HYPERION_JSON_VERSION); - ver["version"] = QString(HYPERION_VERSION); - ver["build"] = QString(HYPERION_BUILD_ID); - ver["time"] = QString(__DATE__ " " __TIME__); - ver["config_modified"] = _hyperion->configModified(); - ver["config_writeable"] = _hyperion->configWriteable(); - - hyperion.append(ver); + // Add Hyperion + QJsonObject hyperion; + hyperion["config_modified" ] = _hyperion->configModified(); + hyperion["config_writeable"] = _hyperion->configWriteable(); info["hyperion"] = hyperion; // send the result @@ -852,8 +863,8 @@ void JsonClientConnection::handleAdjustmentCommand(const QJsonObject& message, c { const QJsonObject & adjustment = message["adjustment"].toObject(); - const QString adjustmentId = adjustment["id"].toString(QString::fromStdString(_hyperion->getAdjustmentIds().front())); - ColorAdjustment * colorAdjustment = _hyperion->getAdjustment(adjustmentId.toStdString()); + const QString adjustmentId = adjustment["id"].toString(_hyperion->getAdjustmentIds().first()); + ColorAdjustment * colorAdjustment = _hyperion->getAdjustment(adjustmentId); if (colorAdjustment == nullptr) { Warning(_log, "Incorrect adjustment identifier: %s", adjustmentId.toStdString().c_str()); @@ -1008,7 +1019,7 @@ void JsonClientConnection::handleConfigGetCommand(const QJsonObject& message, co try { - result["result"] = QJsonFactory::readConfig(QString::fromStdString(_hyperion->getConfigFileName())); + result["result"] = QJsonFactory::readConfig(_hyperion->getConfigFileName()); } catch(...) { @@ -1387,9 +1398,7 @@ bool JsonClientConnection::checkJson(const QJsonObject& message, const QString& } } - std::stringstream sstream; - sstream << "Schema error: " << error.errorString().toStdString() << " at Line: " << errorLine << ", Column: " << errorColumn; - errorMessage = QString::fromStdString(sstream.str()); + errorMessage = "Schema error: " + error.errorString() + " at Line: " + QString::number(errorLine) + ", Column: " + QString::number(errorColumn); return false; } @@ -1399,15 +1408,13 @@ bool JsonClientConnection::checkJson(const QJsonObject& message, const QString& // check the message if (!schemaChecker.validate(message, ignoreRequired)) { - const std::list & errors = schemaChecker.getMessages(); - std::stringstream ss; - ss << "{"; - foreach (const std::string & error, errors) + const QStringList & errors = schemaChecker.getMessages(); + errorMessage = "{"; + foreach (auto & error, errors) { - ss << error << " "; + errorMessage += error + " "; } - ss << "}"; - errorMessage = QString::fromStdString(ss.str()); + errorMessage += "}"; return false; } diff --git a/libsrc/jsonserver/JsonClientConnection.h b/libsrc/jsonserver/JsonClientConnection.h index 7decad84..ceb0c478 100644 --- a/libsrc/jsonserver/JsonClientConnection.h +++ b/libsrc/jsonserver/JsonClientConnection.h @@ -1,13 +1,11 @@ #pragma once -// stl includes -#include - // Qt includes #include #include #include #include +#include // Hyperion includes #include @@ -189,6 +187,13 @@ private: /// void handleServerInfoCommand(const QJsonObject & message, const QString &command, const int tan); + /// + /// Handle an incoming JSON System info message + /// + /// @param message the incoming message + /// + void handleSysInfoCommand(const QJsonObject & message, const QString &command, const int tan); + /// /// Handle an incoming JSON Clear message /// diff --git a/libsrc/jsonserver/JsonSchemas.qrc b/libsrc/jsonserver/JsonSchemas.qrc index 666ec0dc..c7988d2b 100644 --- a/libsrc/jsonserver/JsonSchemas.qrc +++ b/libsrc/jsonserver/JsonSchemas.qrc @@ -4,6 +4,7 @@ schema/schema-color.json schema/schema-image.json schema/schema-serverinfo.json + schema/schema-sysinfo.json schema/schema-clear.json schema/schema-clearall.json schema/schema-adjustment.json diff --git a/libsrc/jsonserver/schema/schema-sysinfo.json b/libsrc/jsonserver/schema/schema-sysinfo.json new file mode 100644 index 00000000..33fcda88 --- /dev/null +++ b/libsrc/jsonserver/schema/schema-sysinfo.json @@ -0,0 +1,15 @@ +{ + "type":"object", + "required":true, + "properties":{ + "command": { + "type" : "string", + "required" : true, + "enum" : ["sysinfo"] + }, + "tan" : { + "type" : "integer" + } + }, + "additionalProperties": false +} diff --git a/libsrc/jsonserver/schema/schema.json b/libsrc/jsonserver/schema/schema.json index f75522ea..20156ff7 100644 --- a/libsrc/jsonserver/schema/schema.json +++ b/libsrc/jsonserver/schema/schema.json @@ -5,7 +5,7 @@ "command": { "type" : "string", "required" : true, - "enum" : ["color", "image", "effect", "create-effect", "delete-effect", "serverinfo", "clear", "clearall", "adjustment", "sourceselect", "config", "componentstate", "ledcolors", "logging", "processing"] + "enum" : ["color", "image", "effect", "create-effect", "delete-effect", "serverinfo", "clear", "clearall", "adjustment", "sourceselect", "config", "componentstate", "ledcolors", "logging", "processing", "sysinfo"] } } } diff --git a/libsrc/leddevice/LedDevice.cpp b/libsrc/leddevice/LedDevice.cpp index 1be6277b..54d825ff 100644 --- a/libsrc/leddevice/LedDevice.cpp +++ b/libsrc/leddevice/LedDevice.cpp @@ -7,7 +7,7 @@ #include LedDeviceRegistry LedDevice::_ledDeviceMap = LedDeviceRegistry(); -std::string LedDevice::_activeDevice = ""; +QString LedDevice::_activeDevice = ""; int LedDevice::_ledCount = 0; int LedDevice::_ledRGBCount = 0; int LedDevice::_ledRGBWCount= 0; @@ -34,7 +34,7 @@ int LedDevice::open() return 0; } -int LedDevice::addToDeviceMap(std::string name, LedDeviceCreateFuncType funcPtr) +int LedDevice::addToDeviceMap(QString name, LedDeviceCreateFuncType funcPtr) { _ledDeviceMap.emplace(name,funcPtr); return 0; @@ -45,7 +45,7 @@ const LedDeviceRegistry& LedDevice::getDeviceMap() return _ledDeviceMap; } -void LedDevice::setActiveDevice(std::string dev) +void LedDevice::setActiveDevice(QString dev) { _activeDevice = dev; } @@ -74,7 +74,7 @@ QJsonObject LedDevice::getLedDeviceSchemas() if (!schemaData.open(QIODevice::ReadOnly)) { - Error(Logger::getInstance("LedDevice"), "Schema not found: %s", item.toUtf8().constData()); + Error(Logger::getInstance("LedDevice"), "Schema not found: %s", QSTRING_CSTR(item)); throw std::runtime_error("ERROR: Schema not found: " + item.toStdString()); } @@ -97,10 +97,9 @@ QJsonObject LedDevice::getLedDeviceSchemas() } } - std::stringstream sstream; - sstream << error.errorString().toStdString() << " at Line: " << errorLine << ", Column: " << errorColumn; - Error(Logger::getInstance("LedDevice"), "LedDevice JSON schema error in %s (%s)", item.toUtf8().constData(), sstream.str().c_str()); - throw std::runtime_error("ERROR: Json schema wrong: " + sstream.str()); + QString errorMsg = error.errorString() + " at Line: " + QString::number(errorLine) + ", Column: " + QString::number(errorColumn); + Error(Logger::getInstance("LedDevice"), "LedDevice JSON schema error in %s (%s)", QSTRING_CSTR(item), QSTRING_CSTR(errorMsg)); + throw std::runtime_error("ERROR: Json schema wrong: " + errorMsg.toStdString()); } schemaJson = doc.object(); diff --git a/libsrc/leddevice/LedDeviceAtmoOrb.cpp b/libsrc/leddevice/LedDeviceAtmoOrb.cpp index 6265c021..a731b9d8 100644 --- a/libsrc/leddevice/LedDeviceAtmoOrb.cpp +++ b/libsrc/leddevice/LedDeviceAtmoOrb.cpp @@ -6,13 +6,10 @@ #include #include #include +#include -#include -#include -#include -#include - -AtmoOrbLight::AtmoOrbLight(unsigned int id) { +AtmoOrbLight::AtmoOrbLight(unsigned int id) +{ // Not implemented } @@ -38,28 +35,20 @@ bool LedDeviceAtmoOrb::init(const QJsonObject &deviceConfig) _multiCastGroupPort = deviceConfig["port"].toInt(49692); _numLeds = deviceConfig["numLeds"].toInt(24); - const std::string orbId = deviceConfig["orbIds"].toString().toStdString(); + const QStringList orbIds = deviceConfig["orbIds"].toString().simplified().remove(" ").split(",", QString::SkipEmptyParts); _orbIds.clear(); - // If we find multiple Orb ids separate them and add to list - const std::string separator (","); - if (orbId.find(separator) != std::string::npos) + foreach(auto & id_str, orbIds) { - std::stringstream ss(orbId); - std::vector output; - unsigned int i; - while (ss >> i) - { - _orbIds.push_back(i); - if (ss.peek() == ',' || ss.peek() == ' ') ss.ignore(); - } - } - else - { - _orbIds.push_back(atoi(orbId.c_str())); + bool ok; + int id = id_str.toInt(&ok); + if (ok) + _orbIds.append(id); + else + Error(_log, "orb id '%s' is not a number", QSTRING_CSTR(id_str)); } - return true; + return _orbIds.size() > 0; } LedDevice* LedDeviceAtmoOrb::construct(const QJsonObject &deviceConfig) @@ -104,7 +93,7 @@ int LedDeviceAtmoOrb::write(const std::vector &ledValues) abs(color.green - lastGreen) >= _skipSmoothingDiff)) { // Skip Orb smoothing when using (command type 4) - for (unsigned int i = 0; i < _orbIds.size(); i++) + for (int i = 0; i < _orbIds.size(); i++) { if (_orbIds[i] == idx) { @@ -115,7 +104,7 @@ int LedDeviceAtmoOrb::write(const std::vector &ledValues) else { // Send color - for (unsigned int i = 0; i < _orbIds.size(); i++) + for (int i = 0; i < _orbIds.size(); i++) { if (_orbIds[i] == idx) { diff --git a/libsrc/leddevice/LedDeviceAtmoOrb.h b/libsrc/leddevice/LedDeviceAtmoOrb.h index ecb26eea..bbc36a87 100644 --- a/libsrc/leddevice/LedDeviceAtmoOrb.h +++ b/libsrc/leddevice/LedDeviceAtmoOrb.h @@ -5,6 +5,8 @@ #include #include #include +#include +#include // Leddevice includes #include @@ -101,7 +103,7 @@ private: QUdpSocket * _udpSocket; /// Array of the orb ids. - std::vector _orbIds; + QVector _orbIds; /// /// Set Orbcolor diff --git a/libsrc/leddevice/LedDeviceDMX.cpp b/libsrc/leddevice/LedDeviceDMX.cpp index 13709504..fe1c06aa 100644 --- a/libsrc/leddevice/LedDeviceDMX.cpp +++ b/libsrc/leddevice/LedDeviceDMX.cpp @@ -17,14 +17,14 @@ bool LedDeviceDMX::init(const QJsonObject &deviceConfig) { ProviderRs232::init(deviceConfig); - std::string _dmxString = deviceConfig["dmxdevice"].toString("invalid").toStdString(); - if (_dmxString == "raw") + QString dmxString = deviceConfig["dmxdevice"].toString("invalid"); + if (dmxString == "raw") { _dmxDeviceType = 0; _dmxStart = 1; _dmxSlotsPerLed = 3; } - else if (_dmxString == "McCrypt") + else if (dmxString == "McCrypt") { _dmxDeviceType = 1; _dmxStart = 1; @@ -32,10 +32,10 @@ bool LedDeviceDMX::init(const QJsonObject &deviceConfig) } else { - Error(_log, "unknown dmx device type %s", _dmxString.c_str()); + Error(_log, "unknown dmx device type %s", QSTRING_CSTR(dmxString)); } - Debug(_log, "_dmxString \"%s\", _dmxDeviceType %d", _dmxString.c_str(), _dmxDeviceType ); + Debug(_log, "_dmxString \"%s\", _dmxDeviceType %d", QSTRING_CSTR(dmxString), _dmxDeviceType ); _rs232Port.setStopBits(QSerialPort::TwoStop); _dmxLedCount = std::min(_ledCount, 512/_dmxSlotsPerLed); diff --git a/libsrc/leddevice/LedDeviceFactory.cpp b/libsrc/leddevice/LedDeviceFactory.cpp index 6e68efa0..ee2c3a09 100755 --- a/libsrc/leddevice/LedDeviceFactory.cpp +++ b/libsrc/leddevice/LedDeviceFactory.cpp @@ -1,7 +1,4 @@ // Stl includes -#include -#include -#include #include #include @@ -60,13 +57,12 @@ LedDevice * LedDeviceFactory::construct(const QJsonObject & deviceConfig, const QString ss(config.toJson(QJsonDocument::Indented)); Info(log, "configuration: %s ", ss.toUtf8().constData()); - std::string type = deviceConfig["type"].toString("UNSPECIFIED").toStdString(); - std::transform(type.begin(), type.end(), type.begin(), ::tolower); + QString type = deviceConfig["type"].toString("UNSPECIFIED").toLower(); // set amount of led to leddevice LedDevice::setLedCount(ledCount); - #define REGISTER(className) LedDevice::addToDeviceMap(QString(#className).toLower().toStdString(), LedDevice##className::construct); + #define REGISTER(className) LedDevice::addToDeviceMap(QString(#className).toLower(), LedDevice##className::construct); // rs232 devices REGISTER(Adalight); REGISTER(Sedu); @@ -126,21 +122,21 @@ LedDevice * LedDeviceFactory::construct(const QJsonObject & deviceConfig, const { device = dev.second(deviceConfig); LedDevice::setActiveDevice(dev.first); - Info(log,"LedDevice '%s' configured.", dev.first.c_str()); + Info(log,"LedDevice '%s' configured.", QSTRING_CSTR(dev.first)); break; } } if (device == nullptr) { - Error(log, "Dummy device used, because configured device '%s' is unknown", type.c_str() ); + Error(log, "Dummy device used, because configured device '%s' is unknown", QSTRING_CSTR(type) ); throw std::runtime_error("unknown device"); } } catch(std::exception& e) { - Error(log, "Dummy device used, because configured device '%s' throws error '%s'", type.c_str(), e.what()); + Error(log, "Dummy device used, because configured device '%s' throws error '%s'", QSTRING_CSTR(type), e.what()); const QJsonObject dummyDeviceConfig; device = LedDeviceFile::construct(QJsonObject()); } diff --git a/libsrc/leddevice/LedDeviceFadeCandy.cpp b/libsrc/leddevice/LedDeviceFadeCandy.cpp index b924b53f..e5ada501 100644 --- a/libsrc/leddevice/LedDeviceFadeCandy.cpp +++ b/libsrc/leddevice/LedDeviceFadeCandy.cpp @@ -34,7 +34,7 @@ bool LedDeviceFadeCandy::init(const QJsonObject &deviceConfig) return false; } - _host = deviceConfig["output"].toString("127.0.0.1").toStdString(); + _host = deviceConfig["output"].toString("127.0.0.1"); _port = deviceConfig["port"].toInt(7890); _channel = deviceConfig["channel"].toInt(0); _gamma = deviceConfig["gamma"].toDouble(1.0); @@ -74,10 +74,10 @@ bool LedDeviceFadeCandy::isConnected() bool LedDeviceFadeCandy::tryConnect() { if ( _client.state() == QAbstractSocket::UnconnectedState ) { - _client.connectToHost( _host.c_str(), _port); + _client.connectToHost( _host, _port); if ( _client.waitForConnected(1000) ) { - Info(_log,"fadecandy/opc: connected to %s:%i on channel %i", _host.c_str(), _port, _channel); + Info(_log,"fadecandy/opc: connected to %s:%i on channel %i", QSTRING_CSTR(_host), _port, _channel); if (_setFcConfig) { sendFadeCandyConfiguration(); diff --git a/libsrc/leddevice/LedDeviceFadeCandy.h b/libsrc/leddevice/LedDeviceFadeCandy.h index e00bcc5e..11cd6f68 100644 --- a/libsrc/leddevice/LedDeviceFadeCandy.h +++ b/libsrc/leddevice/LedDeviceFadeCandy.h @@ -2,6 +2,7 @@ // STL/Qt includes #include +#include // Leddevice includes #include @@ -65,7 +66,7 @@ public: private: QTcpSocket _client; - std::string _host; + QString _host; uint16_t _port; unsigned _channel; QByteArray _opc_data; diff --git a/libsrc/leddevice/LedDeviceFile.cpp b/libsrc/leddevice/LedDeviceFile.cpp index 0f8f11b7..2728440b 100644 --- a/libsrc/leddevice/LedDeviceFile.cpp +++ b/libsrc/leddevice/LedDeviceFile.cpp @@ -25,8 +25,8 @@ bool LedDeviceFile::init(const QJsonObject &deviceConfig) _refresh_timer_interval = 0; LedDevice::init(deviceConfig); - std::string fileName = deviceConfig["output"].toString("/dev/null").toStdString(); - _ofs.open( fileName.c_str() ); + QString fileName = deviceConfig["output"].toString("/dev/null"); + _ofs.open( QSTRING_CSTR(fileName) ); return true; } diff --git a/libsrc/leddevice/LedDeviceHyperionUsbasp.cpp b/libsrc/leddevice/LedDeviceHyperionUsbasp.cpp index 542c7b7d..b1f02f38 100644 --- a/libsrc/leddevice/LedDeviceHyperionUsbasp.cpp +++ b/libsrc/leddevice/LedDeviceHyperionUsbasp.cpp @@ -8,7 +8,7 @@ // Static constants which define the Hyperion Usbasp device uint16_t LedDeviceHyperionUsbasp::_usbVendorId = 0x16c0; uint16_t LedDeviceHyperionUsbasp::_usbProductId = 0x05dc; -std::string LedDeviceHyperionUsbasp::_usbProductDescription = "Hyperion led controller"; +QString LedDeviceHyperionUsbasp::_usbProductDescription = "Hyperion led controller"; LedDeviceHyperionUsbasp::LedDeviceHyperionUsbasp(const QJsonObject &deviceConfig) @@ -41,7 +41,7 @@ bool LedDeviceHyperionUsbasp::init(const QJsonObject &deviceConfig) { LedDevice::init(deviceConfig); - std::string ledType = deviceConfig["output"].toString("ws2801").toStdString(); + QString ledType = deviceConfig["output"].toString("ws2801"); if (ledType != "ws2801" && ledType != "ws2812") { throw std::runtime_error("HyperionUsbasp: invalid output; must be 'ws2801' or 'ws2812'."); @@ -94,7 +94,7 @@ int LedDeviceHyperionUsbasp::open() if (_deviceHandle == nullptr) { - Error(_log, "No %s has been found", _usbProductDescription.c_str()); + Error(_log, "No %s has been found", QSTRING_CSTR(_usbProductDescription)); } return _deviceHandle == nullptr ? -1 : 0; @@ -119,18 +119,18 @@ int LedDeviceHyperionUsbasp::testAndOpen(libusb_device * device) int busNumber = libusb_get_bus_number(device); int addressNumber = libusb_get_device_address(device); - Info(_log, "%s found: bus=%d address=%d", _usbProductDescription.c_str(), busNumber, addressNumber); + Info(_log, "%s found: bus=%d address=%d", QSTRING_CSTR(_usbProductDescription), busNumber, addressNumber); try { _deviceHandle = openDevice(device); - Info(_log, "%s successfully opened", _usbProductDescription.c_str() ); + Info(_log, "%s successfully opened", QSTRING_CSTR(_usbProductDescription) ); return 0; } catch(int e) { _deviceHandle = nullptr; - Error(_log, "Unable to open %s. Searching for other device(%d): %s", _usbProductDescription.c_str(), e, libusb_error_name(e)); + Error(_log, "Unable to open %s. Searching for other device(%d): %s", QSTRING_CSTR(_usbProductDescription), e, libusb_error_name(e)); } } @@ -152,7 +152,7 @@ int LedDeviceHyperionUsbasp::write(const std::vector &ledValues) // Disabling interupts for a little while on the device results in a PIPE error. All seems to keep functioning though... if(nbytes < 0 && nbytes != LIBUSB_ERROR_PIPE) { - Error(_log, "Error while writing data to %s (%s)", _usbProductDescription.c_str(), libusb_error_name(nbytes)); + Error(_log, "Error while writing data to %s (%s)", QSTRING_CSTR(_usbProductDescription), libusb_error_name(nbytes)); return -1; } @@ -195,7 +195,7 @@ libusb_device_handle * LedDeviceHyperionUsbasp::openDevice(libusb_device *device return handle; } -std::string LedDeviceHyperionUsbasp::getString(libusb_device * device, int stringDescriptorIndex) +QString LedDeviceHyperionUsbasp::getString(libusb_device * device, int stringDescriptorIndex) { libusb_device_handle * handle = nullptr; @@ -214,5 +214,5 @@ std::string LedDeviceHyperionUsbasp::getString(libusb_device * device, int strin } libusb_close(handle); - return std::string(buffer, error); + return QString(QByteArray(buffer, error)); } diff --git a/libsrc/leddevice/LedDeviceHyperionUsbasp.h b/libsrc/leddevice/LedDeviceHyperionUsbasp.h index 72f61753..f1a8c307 100644 --- a/libsrc/leddevice/LedDeviceHyperionUsbasp.h +++ b/libsrc/leddevice/LedDeviceHyperionUsbasp.h @@ -3,7 +3,6 @@ // stl includes #include #include -#include // libusb include #include @@ -71,7 +70,7 @@ protected: static libusb_device_handle * openDevice(libusb_device * device); - static std::string getString(libusb_device * device, int stringDescriptorIndex); + static QString getString(libusb_device * device, int stringDescriptorIndex); /// command to write the leds uint8_t _writeLedsCommand; @@ -85,5 +84,5 @@ protected: /// Usb device identifiers static uint16_t _usbVendorId; static uint16_t _usbProductId; - static std::string _usbProductDescription; + static QString _usbProductDescription; }; diff --git a/libsrc/leddevice/LedDeviceLightpack.cpp b/libsrc/leddevice/LedDeviceLightpack.cpp index cba6f4fc..5dc3aa02 100644 --- a/libsrc/leddevice/LedDeviceLightpack.cpp +++ b/libsrc/leddevice/LedDeviceLightpack.cpp @@ -32,7 +32,7 @@ enum DATA_VERSION_INDEXES{ INDEX_FW_VER_MINOR }; -LedDeviceLightpack::LedDeviceLightpack(const std::string & serialNumber) +LedDeviceLightpack::LedDeviceLightpack(const QString & serialNumber) : LedDevice() , _libusbContext(nullptr) , _deviceHandle(nullptr) @@ -72,7 +72,7 @@ LedDeviceLightpack::~LedDeviceLightpack() bool LedDeviceLightpack::init(const QJsonObject &deviceConfig) { LedDevice::init(deviceConfig); - _serialNumber = deviceConfig["output"].toString("").toStdString(); + _serialNumber = deviceConfig["output"].toString(""); return true; } @@ -118,20 +118,20 @@ int LedDeviceLightpack::open() if (_deviceHandle == nullptr) { - if (_serialNumber.empty()) + if (_serialNumber.isEmpty()) { Warning(_log, "No Lightpack device has been found"); } else { - Error(_log,"No Lightpack device has been found with serial %s", _serialNumber.c_str()); + Error(_log,"No Lightpack device has been found with serial %s", QSTRING_CSTR(_serialNumber)); } } return _deviceHandle == nullptr ? -1 : 0; } -int LedDeviceLightpack::testAndOpen(libusb_device * device, const std::string & requestedSerialNumber) +int LedDeviceLightpack::testAndOpen(libusb_device * device, const QString & requestedSerialNumber) { libusb_device_descriptor deviceDescriptor; int error = libusb_get_device_descriptor(device, &deviceDescriptor); @@ -151,7 +151,7 @@ int LedDeviceLightpack::testAndOpen(libusb_device * device, const std::string & int addressNumber = libusb_get_device_address(device); // get the serial number - std::string serialNumber; + QString serialNumber; if (deviceDescriptor.iSerialNumber != 0) { try @@ -165,10 +165,10 @@ int LedDeviceLightpack::testAndOpen(libusb_device * device, const std::string & } } - Debug(_log,"Lightpack device found: bus=%d address=%d serial=%s", busNumber, addressNumber, serialNumber.c_str()); + Debug(_log,"Lightpack device found: bus=%d address=%d serial=%s", busNumber, addressNumber, QSTRING_CSTR(serialNumber)); // check if this is the device we are looking for - if (requestedSerialNumber.empty() || requestedSerialNumber == serialNumber) + if (requestedSerialNumber.isEmpty() || requestedSerialNumber == serialNumber) { // This is it! try @@ -231,7 +231,7 @@ int LedDeviceLightpack::testAndOpen(libusb_device * device, const std::string & _ledBuffer[0] = CMD_UPDATE_LEDS; // return success - Debug(_log, "Lightpack device opened: bus=%d address=%d serial=%s version=%s.%s.", _busNumber, _addressNumber, _serialNumber.c_str(), _firmwareVersion.majorVersion, _firmwareVersion.minorVersion ); + Debug(_log, "Lightpack device opened: bus=%d address=%d serial=%s version=%s.%s.", _busNumber, _addressNumber, QSTRING_CSTR(_serialNumber), _firmwareVersion.majorVersion, _firmwareVersion.minorVersion ); return 0; } catch(int e) @@ -279,7 +279,7 @@ int LedDeviceLightpack::switchOff() return writeBytes(buf, sizeof(buf)) == sizeof(buf); } -const std::string &LedDeviceLightpack::getSerialNumber() const +const QString &LedDeviceLightpack::getSerialNumber() const { return _serialNumber; } @@ -352,7 +352,7 @@ libusb_device_handle * LedDeviceLightpack::openDevice(libusb_device *device) return handle; } -std::string LedDeviceLightpack::getString(libusb_device * device, int stringDescriptorIndex) +QString LedDeviceLightpack::getString(libusb_device * device, int stringDescriptorIndex) { libusb_device_handle * handle = nullptr; @@ -371,5 +371,5 @@ std::string LedDeviceLightpack::getString(libusb_device * device, int stringDesc } libusb_close(handle); - return std::string(buffer, error); + return QString(QByteArray(buffer, error)); } diff --git a/libsrc/leddevice/LedDeviceLightpack.h b/libsrc/leddevice/LedDeviceLightpack.h index 47cfb83c..c9b34ce2 100644 --- a/libsrc/leddevice/LedDeviceLightpack.h +++ b/libsrc/leddevice/LedDeviceLightpack.h @@ -20,7 +20,7 @@ public: /// /// @param serialNumber serial output device /// - LedDeviceLightpack(const std::string & serialNumber = ""); + LedDeviceLightpack(const QString & serialNumber = ""); /// /// Constructs specific LedDevice /// @@ -68,7 +68,7 @@ public: virtual int switchOff(); /// Get the serial of the Lightpack - const std::string & getSerialNumber() const; + const QString & getSerialNumber() const; /// Get the number of leds int getLedCount() const; @@ -88,7 +88,7 @@ private: /// /// @return Zero on succes else negative /// - int testAndOpen(libusb_device * device, const std::string & requestedSerialNumber); + int testAndOpen(libusb_device * device, const QString & requestedSerialNumber); /// write bytes to the device int writeBytes(uint8_t *data, int size); @@ -103,7 +103,7 @@ private: }; static libusb_device_handle * openDevice(libusb_device * device); - static std::string getString(libusb_device * device, int stringDescriptorIndex); + static QString getString(libusb_device * device, int stringDescriptorIndex); /// libusb context libusb_context * _libusbContext; @@ -118,7 +118,7 @@ private: int _addressNumber; /// device serial number - std::string _serialNumber; + QString _serialNumber; /// firmware version of the device Version _firmwareVersion; diff --git a/libsrc/leddevice/LedDeviceMultiLightpack.cpp b/libsrc/leddevice/LedDeviceMultiLightpack.cpp index bb96553c..9f1082a1 100644 --- a/libsrc/leddevice/LedDeviceMultiLightpack.cpp +++ b/libsrc/leddevice/LedDeviceMultiLightpack.cpp @@ -40,13 +40,13 @@ LedDevice* LedDeviceMultiLightpack::construct(const QJsonObject &deviceConfig) int LedDeviceMultiLightpack::open() { // retrieve a list with Lightpack serials - std::list serialList = getLightpackSerials(); + QStringList serialList = getLightpackSerials(); // sort the list of Lightpacks based on the serial to get a fixed order std::sort(_lightpacks.begin(), _lightpacks.end(), compareLightpacks); // open each lightpack device - for (const std::string & serial : serialList) + foreach (auto serial , serialList) { LedDeviceLightpack * device = new LedDeviceLightpack(serial); int error = device->open(); @@ -57,7 +57,7 @@ int LedDeviceMultiLightpack::open() } else { - Error(_log, "Error while creating Lightpack device with serial %s", serial.c_str()); + Error(_log, "Error while creating Lightpack device with serial %s", QSTRING_CSTR(serial)); delete device; } } @@ -109,9 +109,9 @@ int LedDeviceMultiLightpack::switchOff() return 0; } -std::list LedDeviceMultiLightpack::getLightpackSerials() +QStringList LedDeviceMultiLightpack::getLightpackSerials() { - std::list serialList; + QStringList serialList; Logger * log = Logger::getInstance("LedDevice"); Debug(log, "Getting list of Lightpack serials"); @@ -148,7 +148,7 @@ std::list LedDeviceMultiLightpack::getLightpackSerials() Info(log, "Found a lightpack device. Retrieving serial..."); // get the serial number - std::string serialNumber; + QString serialNumber; if (deviceDescriptor.iSerialNumber != 0) { try @@ -162,8 +162,8 @@ std::list LedDeviceMultiLightpack::getLightpackSerials() } } - Error(log, "Lightpack device found with serial %s", serialNumber.c_str());; - serialList.push_back(serialNumber); + Error(log, "Lightpack device found with serial %s", QSTRING_CSTR(serialNumber));; + serialList.append(serialNumber); } } @@ -174,7 +174,7 @@ std::list LedDeviceMultiLightpack::getLightpackSerials() return serialList; } -std::string LedDeviceMultiLightpack::getString(libusb_device * device, int stringDescriptorIndex) +QString LedDeviceMultiLightpack::getString(libusb_device * device, int stringDescriptorIndex) { libusb_device_handle * handle = nullptr; @@ -193,5 +193,5 @@ std::string LedDeviceMultiLightpack::getString(libusb_device * device, int strin } libusb_close(handle); - return std::string(buffer, error); + return QString(QByteArray(buffer, error)); } diff --git a/libsrc/leddevice/LedDeviceMultiLightpack.h b/libsrc/leddevice/LedDeviceMultiLightpack.h index 0b285fd3..419e5bed 100644 --- a/libsrc/leddevice/LedDeviceMultiLightpack.h +++ b/libsrc/leddevice/LedDeviceMultiLightpack.h @@ -3,8 +3,8 @@ // stl includes #include #include -#include -#include +#include +#include // libusb include #include @@ -56,8 +56,8 @@ private: /// virtual int write(const std::vector& ledValues); - static std::list getLightpackSerials(); - static std::string getString(libusb_device * device, int stringDescriptorIndex); + static QStringList getLightpackSerials(); + static QString getString(libusb_device * device, int stringDescriptorIndex); /// buffer for led data std::vector _lightpacks; diff --git a/libsrc/leddevice/LedDevicePiBlaster.cpp b/libsrc/leddevice/LedDevicePiBlaster.cpp index dca25f9b..c39ab668 100644 --- a/libsrc/leddevice/LedDevicePiBlaster.cpp +++ b/libsrc/leddevice/LedDevicePiBlaster.cpp @@ -44,7 +44,7 @@ bool LedDevicePiBlaster::init(const QJsonObject &deviceConfig) { LedDevice::init(deviceConfig); - _deviceName = deviceConfig["output"].toString("/dev/pi-blaster").toStdString(); + QString _deviceName = deviceConfig["output"].toString("/dev/pi-blaster"); QJsonArray gpioMapping = deviceConfig["gpiomap"].toArray(); if (gpioMapping.isEmpty()) @@ -82,24 +82,24 @@ int LedDevicePiBlaster::open() if (_fid != nullptr) { // The file pointer is already open - Error( _log, "Device (%s) is already open.", _deviceName.c_str() ); + Error( _log, "Device (%s) is already open.", QSTRING_CSTR(_deviceName) ); return -1; } - if (!QFile::exists(_deviceName.c_str())) + if (!QFile::exists(_deviceName)) { - Error( _log, "The device (%s) does not yet exist.", _deviceName.c_str() ); + Error( _log, "The device (%s) does not yet exist.",QSTRING_CSTR(_deviceName) ); return -1; } - _fid = fopen(_deviceName.c_str(), "w"); + _fid = fopen(QSTRING_CSTR(_deviceName), "w"); if (_fid == nullptr) { - Error( _log, "Failed to open device (%s). Error message: %s", _deviceName.c_str(), strerror(errno) ); + Error( _log, "Failed to open device (%s). Error message: %s", QSTRING_CSTR(_deviceName), strerror(errno) ); return -1; } - Info( _log, "Connected to device(%s)", _deviceName.c_str()); + Info( _log, "Connected to device(%s)", QSTRING_CSTR(_deviceName)); return 0; } diff --git a/libsrc/leddevice/LedDevicePiBlaster.h b/libsrc/leddevice/LedDevicePiBlaster.h index e42479c7..35115e29 100644 --- a/libsrc/leddevice/LedDevicePiBlaster.h +++ b/libsrc/leddevice/LedDevicePiBlaster.h @@ -48,7 +48,7 @@ private: int write(const std::vector &ledValues); /// The name of the output device (very likely '/dev/pi-blaster') - std::string _deviceName; + QString _deviceName; int _gpio_to_led[64]; char _gpio_to_color[64]; diff --git a/libsrc/leddevice/LedDeviceSk6812SPI.cpp b/libsrc/leddevice/LedDeviceSk6812SPI.cpp index 5d10bf89..2c98a5b6 100644 --- a/libsrc/leddevice/LedDeviceSk6812SPI.cpp +++ b/libsrc/leddevice/LedDeviceSk6812SPI.cpp @@ -21,15 +21,15 @@ LedDevice* LedDeviceSk6812SPI::construct(const QJsonObject &deviceConfig) bool LedDeviceSk6812SPI::init(const QJsonObject &deviceConfig) { - std::string whiteAlgorithm = deviceConfig["white_algorithm"].toString("white_off").toStdString(); + QString whiteAlgorithm = deviceConfig["white_algorithm"].toString("white_off"); _whiteAlgorithm = RGBW::stringToWhiteAlgorithm(whiteAlgorithm); if (_whiteAlgorithm == RGBW::INVALID) { - Error(_log, "unknown whiteAlgorithm %s", whiteAlgorithm.c_str()); + Error(_log, "unknown whiteAlgorithm %s", QSTRING_CSTR(whiteAlgorithm)); return false; } - Debug( _log, "whiteAlgorithm : %s", whiteAlgorithm.c_str()); + Debug( _log, "whiteAlgorithm : %s", QSTRING_CSTR(whiteAlgorithm)); _baudRate_Hz = 3000000; if ( !ProviderSpi::init(deviceConfig) ) diff --git a/libsrc/leddevice/LedDeviceTinkerforge.cpp b/libsrc/leddevice/LedDeviceTinkerforge.cpp index 70e94e1f..b0c319ae 100644 --- a/libsrc/leddevice/LedDeviceTinkerforge.cpp +++ b/libsrc/leddevice/LedDeviceTinkerforge.cpp @@ -35,9 +35,9 @@ bool LedDeviceTinkerforge::init(const QJsonObject &deviceConfig) { LedDevice::init(deviceConfig); - _host = deviceConfig["output"].toString("127.0.0.1").toStdString(); + _host = deviceConfig["output"].toString("127.0.0.1"); _port = deviceConfig["port"].toInt(4223); - _uid = deviceConfig["uid"].toString().toStdString(); + _uid = deviceConfig["uid"].toString(); _interval = deviceConfig["rate"].toInt(); if ((unsigned)_ledCount > MAX_NUM_LEDS) @@ -75,16 +75,16 @@ int LedDeviceTinkerforge::open() _ipConnection = new IPConnection; ipcon_create(_ipConnection); - int connectionStatus = ipcon_connect(_ipConnection, _host.c_str(), _port); + int connectionStatus = ipcon_connect(_ipConnection, QSTRING_CSTR(_host), _port); if (connectionStatus < 0) { - Warning(_log, "Attempt to connect to master brick (%s:%d) failed with status %d", _host.c_str(), _port, connectionStatus); + Warning(_log, "Attempt to connect to master brick (%s:%d) failed with status %d", QSTRING_CSTR(_host), _port, connectionStatus); return -1; } // Create the 'LedStrip' _ledStrip = new LEDStrip; - led_strip_create(_ledStrip, _uid.c_str(), _ipConnection); + led_strip_create(_ledStrip, QSTRING_CSTR(_uid), _ipConnection); int frameStatus = led_strip_set_frame_duration(_ledStrip, _interval); if (frameStatus < 0) diff --git a/libsrc/leddevice/LedDeviceTinkerforge.h b/libsrc/leddevice/LedDeviceTinkerforge.h index d282c14b..fd086cf1 100644 --- a/libsrc/leddevice/LedDeviceTinkerforge.h +++ b/libsrc/leddevice/LedDeviceTinkerforge.h @@ -3,6 +3,8 @@ // STL includes #include +#include + // Hyperion-Leddevice includes #include @@ -56,13 +58,13 @@ private: int transferLedData(LEDStrip *ledstrip, unsigned int index, unsigned int length, uint8_t *redChannel, uint8_t *greenChannel, uint8_t *blueChannel); /// The host of the master brick - std::string _host; + QString _host; /// The port of the master brick uint16_t _port; /// The uid of the led strip bricklet - std::string _uid; + QString _uid; /// The interval/rate unsigned _interval; diff --git a/libsrc/leddevice/LedDeviceUdpE131.cpp b/libsrc/leddevice/LedDeviceUdpE131.cpp index 2df5a1e2..ae15ab9d 100644 --- a/libsrc/leddevice/LedDeviceUdpE131.cpp +++ b/libsrc/leddevice/LedDeviceUdpE131.cpp @@ -16,16 +16,16 @@ bool LedDeviceUdpE131::init(const QJsonObject &deviceConfig) _port = 5568; ProviderUdp::init(deviceConfig); _e131_universe = deviceConfig["universe"].toInt(1); - _e131_source_name = deviceConfig["source-name"].toString("hyperion on "+QHostInfo::localHostName()).toStdString(); + _e131_source_name = deviceConfig["source-name"].toString("hyperion on "+QHostInfo::localHostName()); QString _json_cid = deviceConfig["cid"].toString(""); if (_json_cid.isEmpty()) { _e131_cid = QUuid::createUuid(); - Debug( _log, "e131 no cid found, generated %s", _e131_cid.toString().toStdString().c_str()); + Debug( _log, "e131 no cid found, generated %s", QSTRING_CSTR(_e131_cid.toString())); } else { _e131_cid = QUuid(_json_cid); - Debug( _log, "e131 cid found, using %s", _e131_cid.toString().toStdString().c_str()); + Debug( _log, "e131 cid found, using %s", QSTRING_CSTR(_e131_cid.toString())); } return true; @@ -53,7 +53,7 @@ void LedDeviceUdpE131::prepare(const unsigned this_universe, const unsigned this /* Frame Layer */ e131_packet.frame_flength = htons(0x7000 | (88+this_dmxChannelCount)); e131_packet.frame_vector = htonl(VECTOR_E131_DATA_PACKET); - snprintf (e131_packet.source_name, sizeof(e131_packet.source_name), "%s", _e131_source_name.c_str() ); + snprintf (e131_packet.source_name, sizeof(e131_packet.source_name), "%s", QSTRING_CSTR(_e131_source_name) ); e131_packet.priority = 100; e131_packet.reserved = htons(0); e131_packet.options = 0; // Bit 7 = Preview_Data diff --git a/libsrc/leddevice/LedDeviceUdpE131.h b/libsrc/leddevice/LedDeviceUdpE131.h index 4c153822..5591b123 100644 --- a/libsrc/leddevice/LedDeviceUdpE131.h +++ b/libsrc/leddevice/LedDeviceUdpE131.h @@ -133,6 +133,6 @@ private: uint8_t _e131_seq = 0; uint8_t _e131_universe = 1; uint8_t _acn_id[12] = {0x41, 0x53, 0x43, 0x2d, 0x45, 0x31, 0x2e, 0x31, 0x37, 0x00, 0x00, 0x00 }; - std::string _e131_source_name; + QString _e131_source_name; QUuid _e131_cid; }; diff --git a/libsrc/leddevice/LedDeviceWS281x.cpp b/libsrc/leddevice/LedDeviceWS281x.cpp index 2ac10a08..47d80465 100644 --- a/libsrc/leddevice/LedDeviceWS281x.cpp +++ b/libsrc/leddevice/LedDeviceWS281x.cpp @@ -20,12 +20,12 @@ bool LedDeviceWS281x::init(const QJsonObject &deviceConfig) { LedDevice::init(deviceConfig); - std::string whiteAlgorithm = deviceConfig["white_algorithm"].toString("white_off").toStdString(); + QString whiteAlgorithm = deviceConfig["white_algorithm"].toString("white_off"); _whiteAlgorithm = RGBW::stringToWhiteAlgorithm(whiteAlgorithm); - Debug( _log, "whiteAlgorithm : %s", whiteAlgorithm.c_str()); + Debug( _log, "whiteAlgorithm : %s", QSTRING_CSTR(whiteAlgorithm)); if (_whiteAlgorithm == RGBW::INVALID) { - Error(_log, "unknown whiteAlgorithm %s", whiteAlgorithm.c_str()); + Error(_log, "unknown whiteAlgorithm %s", QSTRING_CSTR(whiteAlgorithm)); return false; } diff --git a/libsrc/leddevice/ProviderSpi.cpp b/libsrc/leddevice/ProviderSpi.cpp index e7d59e14..d78a4999 100644 --- a/libsrc/leddevice/ProviderSpi.cpp +++ b/libsrc/leddevice/ProviderSpi.cpp @@ -35,7 +35,7 @@ bool ProviderSpi::init(const QJsonObject &deviceConfig) { LedDevice::init(deviceConfig); - _deviceName = deviceConfig["output"].toString(QString::fromStdString(_deviceName)).toStdString(); + _deviceName = deviceConfig["output"].toString(_deviceName); _baudRate_Hz = deviceConfig["rate"].toInt(_baudRate_Hz); _latchTime_ns = deviceConfig["latchtime"].toInt(_latchTime_ns); _spiMode = deviceConfig["spimode"].toInt(_spiMode); @@ -51,11 +51,11 @@ int ProviderSpi::open() const int bitsPerWord = 8; - _fid = ::open(_deviceName.c_str(), O_RDWR); + _fid = ::open(QSTRING_CSTR(_deviceName), O_RDWR); if (_fid < 0) { - Error( _log, "Failed to open device (%s). Error message: %s", _deviceName.c_str(), strerror(errno) ); + Error( _log, "Failed to open device (%s). Error message: %s", QSTRING_CSTR(_deviceName), strerror(errno) ); return -1; } diff --git a/libsrc/leddevice/ProviderSpi.h b/libsrc/leddevice/ProviderSpi.h index 0d20cb4c..11b88ffb 100644 --- a/libsrc/leddevice/ProviderSpi.h +++ b/libsrc/leddevice/ProviderSpi.h @@ -49,7 +49,7 @@ protected: int writeBytes(const unsigned size, const uint8_t *data); /// The name of the output device - std::string _deviceName; + QString _deviceName; /// The used baudrate of the output device int _baudRate_Hz; diff --git a/libsrc/protoserver/ProtoConnection.cpp b/libsrc/protoserver/ProtoConnection.cpp index 42e8babe..add6c9f3 100644 --- a/libsrc/protoserver/ProtoConnection.cpp +++ b/libsrc/protoserver/ProtoConnection.cpp @@ -7,13 +7,12 @@ // protoserver includes #include "protoserver/ProtoConnection.h" -ProtoConnection::ProtoConnection(const std::string & a) : +ProtoConnection::ProtoConnection(const QString & address) : _socket(), _skipReply(false), _prevSocketState(QAbstractSocket::UnconnectedState), _log(Logger::getInstance("PROTOCONNECTION")) { - QString address(a.c_str()); QStringList parts = address.split(":"); if (parts.size() != 2) { diff --git a/libsrc/protoserver/ProtoConnectionWrapper.cpp b/libsrc/protoserver/ProtoConnectionWrapper.cpp index bc38e735..000918fa 100644 --- a/libsrc/protoserver/ProtoConnectionWrapper.cpp +++ b/libsrc/protoserver/ProtoConnectionWrapper.cpp @@ -7,7 +7,7 @@ ProtoConnectionWrapper::ProtoConnectionWrapper(const QString &address, bool skipProtoReply) : _priority(priority) , _duration_ms(duration_ms) - , _connection(address.toStdString()) + , _connection(address) { _connection.setSkipReply(skipProtoReply); connect(&_connection, SIGNAL(setGrabbingMode(GrabbingMode)), this, SIGNAL(setGrabbingMode(GrabbingMode))); diff --git a/libsrc/utils/CMakeLists.txt b/libsrc/utils/CMakeLists.txt index 2ee4c261..72ce2ecd 100644 --- a/libsrc/utils/CMakeLists.txt +++ b/libsrc/utils/CMakeLists.txt @@ -62,7 +62,7 @@ add_library(hyperion-utils ${PROFILER_SOURCE} ) -qt5_use_modules(hyperion-utils Core Gui) +qt5_use_modules(hyperion-utils Core Gui Network) target_link_libraries(hyperion-utils ${QT_LIBRARIES}) diff --git a/libsrc/utils/Logger.cpp b/libsrc/utils/Logger.cpp index 3c134538..93409e4d 100644 --- a/libsrc/utils/Logger.cpp +++ b/libsrc/utils/Logger.cpp @@ -12,43 +12,42 @@ static const int LogLevelSysLog[] = { LOG_DEBUG, LOG_DEBUG, LOG_INFO, LOG_ static unsigned int loggerCount = 0; static unsigned int loggerId = 0; -std::map *Logger::LoggerMap = nullptr; +std::map *Logger::LoggerMap = nullptr; Logger::LogLevel Logger::GLOBAL_MIN_LOG_LEVEL = Logger::UNSET; LoggerManager* LoggerManager::_instance = nullptr; Logger* Logger::getInstance(QString name, Logger::LogLevel minLevel) { qRegisterMetaType(); - std::string loggerName = name.toStdString(); Logger* log = nullptr; if (LoggerMap == nullptr) { - LoggerMap = new std::map; + LoggerMap = new std::map; } - if ( LoggerMap->find(loggerName) == LoggerMap->end() ) + if ( LoggerMap->find(name) == LoggerMap->end() ) { - log = new Logger(loggerName,minLevel); - LoggerMap->insert(std::pair(loggerName,log)); // compat version, replace it with following line if we have 100% c++11 - //LoggerMap->emplace(loggerName,log); // not compat with older linux distro's e.g. wheezy + log = new Logger(name,minLevel); + LoggerMap->insert(std::pair(name,log)); // compat version, replace it with following line if we have 100% c++11 + //LoggerMap->emplace(name,log); // not compat with older linux distro's e.g. wheezy connect(log, SIGNAL(newLogMessage(Logger::T_LOG_MESSAGE)), LoggerManager::getInstance(), SLOT(handleNewLogMessage(Logger::T_LOG_MESSAGE))); } else { - log = LoggerMap->at(loggerName); + log = LoggerMap->at(name); } return log; } -void Logger::deleteInstance(std::string name) +void Logger::deleteInstance(QString name) { if (LoggerMap == nullptr) return; - if ( name.empty() ) + if ( name.isEmpty() ) { - std::map::iterator it; + std::map::iterator it; for ( it=LoggerMap->begin(); it != LoggerMap->end(); it++) { delete it->second; @@ -63,31 +62,31 @@ void Logger::deleteInstance(std::string name) } -void Logger::setLogLevel(LogLevel level,std::string name) +void Logger::setLogLevel(LogLevel level,QString name) { - if ( name.empty() ) + if ( name.isEmpty() ) { GLOBAL_MIN_LOG_LEVEL = level; } else { - Logger* log = Logger::getInstance(QString::fromStdString(name),level); + Logger* log = Logger::getInstance(name,level); log->setMinLevel(level); } } -Logger::LogLevel Logger::getLogLevel(std::string name) +Logger::LogLevel Logger::getLogLevel(QString name) { - if ( name.empty() ) + if ( name.isEmpty() ) { return GLOBAL_MIN_LOG_LEVEL; } - Logger* log = Logger::getInstance(QString::fromStdString(name)); + Logger* log = Logger::getInstance(name); return log->getMinLevel(); } -Logger::Logger ( std::string name, LogLevel minLevel ) +Logger::Logger ( QString name, LogLevel minLevel ) : QObject() , _name(name) , _minLevel(minLevel) @@ -99,8 +98,8 @@ Logger::Logger ( std::string name, LogLevel minLevel ) #else const char* _appname_char = getprogname(); #endif - _appname = std::string(_appname_char); - std::transform(_appname.begin(), _appname.end(),_appname.begin(), ::toupper); + _appname = QString(_appname_char).toLower(); + loggerCount++; @@ -112,7 +111,7 @@ Logger::Logger ( std::string name, LogLevel minLevel ) Logger::~Logger() { - Debug(this, "logger '%s' destroyed", _name.c_str() ); + Debug(this, "logger '%s' destroyed", QSTRING_CSTR(_name) ); loggerCount--; if ( loggerCount == 0 ) closelog(); @@ -134,15 +133,15 @@ void Logger::Message(LogLevel level, const char* sourceFile, const char* func, u Logger::T_LOG_MESSAGE logMsg; - logMsg.appName = QString::fromStdString(_appname); - logMsg.loggerName = QString::fromStdString(_name); + logMsg.appName = _appname; + logMsg.loggerName = _name; logMsg.function = QString(func); logMsg.line = line; logMsg.fileName = FileUtils::getBaseName(sourceFile); time(&(logMsg.utime)); logMsg.message = QString(msg); logMsg.level = level; - logMsg.levelString = QString::fromStdString(LogLevelStrings[level]); + logMsg.levelString = LogLevelStrings[level]; emit newLogMessage(logMsg); @@ -152,10 +151,7 @@ void Logger::Message(LogLevel level, const char* sourceFile, const char* func, u location = "<" + logMsg.fileName + ":" + QString::number(line)+":"+ logMsg.function + "()> "; } - std::cout - << "[" << _appname << " " << _name << "] <" - << LogLevelStrings[level] << "> " << location.toStdString() << msg - << std::endl; + std::cout << QString("[" + _appname + " " + _name + "] <" + LogLevelStrings[level] + "> " + location + msg).toStdString() << std::endl; if ( _syslogEnabled && level >= Logger::WARNING ) syslog (LogLevelSysLog[level], "%s", msg); diff --git a/libsrc/utils/Process.cpp b/libsrc/utils/Process.cpp index 8005e919..83bfad94 100644 --- a/libsrc/utils/Process.cpp +++ b/libsrc/utils/Process.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include @@ -41,7 +40,7 @@ void restartHyperion(bool asNewProcess) QByteArray command_exec(QString cmd, QByteArray data) { char buffer[128]; - std::string result = ""; + QString result = ""; std::shared_ptr pipe(popen(cmd.toLocal8Bit().constData(), "r"), pclose); if (pipe) @@ -52,7 +51,7 @@ QByteArray command_exec(QString cmd, QByteArray data) result += buffer; } } - return result.c_str(); + return QSTRING_CSTR(result); } }; \ No newline at end of file diff --git a/libsrc/utils/Profiler.cpp b/libsrc/utils/Profiler.cpp index 70c207fe..c478fb06 100644 --- a/libsrc/utils/Profiler.cpp +++ b/libsrc/utils/Profiler.cpp @@ -13,7 +13,7 @@ struct StopWatchItem { }; static unsigned int blockCounter = 0; -static std::map GlobalProfilerMap; +static std::map GlobalProfilerMap; Logger* Profiler::_logger = nullptr; double getClockDelta(clock_t start) @@ -44,9 +44,9 @@ void Profiler::initLogger() _logger = Logger::getInstance("PROFILER", Logger::DEBUG); } -void Profiler::TimerStart(const std::string timerName, const char* sourceFile, const char* func, unsigned int line) +void Profiler::TimerStart(const QString timerName, const char* sourceFile, const char* func, unsigned int line) { - std::pair::iterator,bool> ret; + std::pair::iterator,bool> ret; Profiler::initLogger(); StopWatchItem item = {sourceFile, func, line}; @@ -56,34 +56,34 @@ void Profiler::TimerStart(const std::string timerName, const char* sourceFile, c { if ( ret.first->second.sourceFile == sourceFile && ret.first->second.func == func && ret.first->second.line == line ) { - _logger->Message(Logger::DEBUG, sourceFile, func, line, "restart timer '%s'", timerName.c_str() ); + _logger->Message(Logger::DEBUG, sourceFile, func, line, "restart timer '%s'", QSTRING_CSTR(timerName) ); ret.first->second.startTime = clock(); } else { _logger->Message(Logger::DEBUG, sourceFile, func, line, "ERROR timer '%s' started in multiple locations. First occurence %s:%d:%s()", - timerName.c_str(), FileUtils::getBaseName(ret.first->second.sourceFile).toLocal8Bit().constData(), ret.first->second.line, ret.first->second.func ); + QSTRING_CSTR(timerName), FileUtils::getBaseName(ret.first->second.sourceFile).toLocal8Bit().constData(), ret.first->second.line, ret.first->second.func ); } } else { - _logger->Message(Logger::DEBUG, sourceFile, func, line, "start timer '%s'", timerName.c_str() ); + _logger->Message(Logger::DEBUG, sourceFile, func, line, "start timer '%s'", QSTRING_CSTR(timerName) ); } } -void Profiler::TimerGetTime(const std::string timerName, const char* sourceFile, const char* func, unsigned int line) +void Profiler::TimerGetTime(const QString timerName, const char* sourceFile, const char* func, unsigned int line) { - std::map::iterator ret = GlobalProfilerMap.find(timerName); + std::map::iterator ret = GlobalProfilerMap.find(timerName); Profiler::initLogger(); if (ret != GlobalProfilerMap.end()) { - _logger->Message(Logger::DEBUG, sourceFile, func, line, "timer '%s' started at %s:%d:%s() took %f s execution time until here", timerName.c_str(), + _logger->Message(Logger::DEBUG, sourceFile, func, line, "timer '%s' started at %s:%d:%s() took %f s execution time until here", QSTRING_CSTR(timerName), FileUtils::getBaseName(ret->second.sourceFile).toLocal8Bit().constData(), ret->second.line, ret->second.func, getClockDelta(ret->second.startTime) ); } else { - _logger->Message(Logger::DEBUG, sourceFile, func, line, "ERROR timer '%s' not started", timerName.c_str() ); + _logger->Message(Logger::DEBUG, sourceFile, func, line, "ERROR timer '%s' not started", QSTRING_CSTR(timerName) ); } } diff --git a/libsrc/utils/RgbToRgbw.cpp b/libsrc/utils/RgbToRgbw.cpp index 4dd816c2..11aaa585 100755 --- a/libsrc/utils/RgbToRgbw.cpp +++ b/libsrc/utils/RgbToRgbw.cpp @@ -5,11 +5,11 @@ namespace RGBW { -WhiteAlgorithm stringToWhiteAlgorithm(std::string str) +WhiteAlgorithm stringToWhiteAlgorithm(QString str) { if (str == "subtract_minimum") return SUBTRACT_MINIMUM; if (str == "sub_min_warm_adjust") return SUB_MIN_WARM_ADJUST; - if (str.empty() || str == "white_off") return WHITE_OFF; + if (str.isEmpty() || str == "white_off") return WHITE_OFF; return INVALID; } diff --git a/libsrc/utils/SysInfo.cpp b/libsrc/utils/SysInfo.cpp index b098f389..92762ec6 100644 --- a/libsrc/utils/SysInfo.cpp +++ b/libsrc/utils/SysInfo.cpp @@ -1,5 +1,6 @@ #include "utils/SysInfo.h" +#include #include #include #include @@ -8,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -20,23 +20,15 @@ SysInfo::SysInfo() { SysInfo::QUnixOSVersion v; findUnixOsVersion(v); - - std::cout - << currentCpuArchitecture().toStdString() << " " - << kernelType().toStdString() << " " - << kernelVersion().toStdString() << " " - << v.productType.toStdString() << " " - << v.productVersion.toStdString() << " " - << v.prettyName.toStdString() << " " - << std::endl; - + _sysinfo.kernelType = kernelType(); _sysinfo.kernelVersion = kernelVersion(); _sysinfo.architecture = currentCpuArchitecture(); - _sysinfo.wordSize = QSysInfo::WordSize; + _sysinfo.wordSize = QString::number(QSysInfo::WordSize); _sysinfo.productType = v.productType; _sysinfo.productVersion = v.productVersion; _sysinfo.prettyName = v.prettyName; + _sysinfo.hostName = QHostInfo::localHostName(); } SysInfo::~SysInfo() diff --git a/libsrc/utils/jsonschema/QJsonSchemaChecker.cpp b/libsrc/utils/jsonschema/QJsonSchemaChecker.cpp index 29afcba5..94491137 100644 --- a/libsrc/utils/jsonschema/QJsonSchemaChecker.cpp +++ b/libsrc/utils/jsonschema/QJsonSchemaChecker.cpp @@ -1,6 +1,5 @@ // stdlib includes #include -#include #include #include @@ -33,7 +32,7 @@ bool QJsonSchemaChecker::validate(const QJsonObject & value, bool ignoreRequired _error = false; _messages.clear(); _currentPath.clear(); - _currentPath.push_back("[root]"); + _currentPath.append("[root]"); // validate validate(value, _qSchema); @@ -116,21 +115,18 @@ void QJsonSchemaChecker::validate(const QJsonValue & value, const QJsonObject &s { // no check function defined for this attribute _error = true; - setMessage(std::string("No check function defined for attribute ") + attribute.toStdString()); + setMessage("No check function defined for attribute " + attribute); continue; } } } -void QJsonSchemaChecker::setMessage(const std::string & message) +void QJsonSchemaChecker::setMessage(const QString & message) { - std::ostringstream oss; - std::copy(_currentPath.begin(), _currentPath.end(), std::ostream_iterator(oss, "")); - oss << ": " << message; - _messages.push_back(oss.str()); + _messages.append(_currentPath.join("") +": "+message); } -const std::list & QJsonSchemaChecker::getMessages() const +const QStringList & QJsonSchemaChecker::getMessages() const { return _messages; } @@ -166,7 +162,7 @@ void QJsonSchemaChecker::checkType(const QJsonValue & value, const QJsonValue & if (wrongType) { _error = true; - setMessage(type.toStdString() + " expected"); + setMessage(type + " expected"); } } @@ -178,7 +174,7 @@ void QJsonSchemaChecker::checkProperties(const QJsonObject & value, const QJsonO const QJsonValue & propertyValue = i.value(); - _currentPath.push_back(std::string(".") + property.toStdString()); + _currentPath.append("." + property); QJsonObject::const_iterator required = propertyValue.toObject().find("required"); if (value.contains(property)) @@ -190,7 +186,7 @@ void QJsonSchemaChecker::checkProperties(const QJsonObject & value, const QJsonO _error = true; setMessage("missing member"); } - _currentPath.pop_back(); + _currentPath.removeLast(); } } @@ -202,7 +198,7 @@ void QJsonSchemaChecker::checkAdditionalProperties(const QJsonObject & value, co if (std::find(ignoredProperties.begin(), ignoredProperties.end(), property) == ignoredProperties.end()) { // property has no property definition. check against the definition for additional properties - _currentPath.push_back(std::string(".") + property.toStdString()); + _currentPath.append("." + property); if (schema.isBool()) { if (schema.toBool() == false) @@ -215,7 +211,7 @@ void QJsonSchemaChecker::checkAdditionalProperties(const QJsonObject & value, co { validate(value[property].toObject(), schema.toObject()); } - _currentPath.pop_back(); + _currentPath.removeLast(); } } } @@ -233,9 +229,7 @@ void QJsonSchemaChecker::checkMinimum(const QJsonValue & value, const QJsonValue if (value.toDouble() < schema.toDouble()) { _error = true; - std::ostringstream oss; - oss << "value is too small (minimum=" << schema.toDouble() << ")"; - setMessage(oss.str()); + setMessage("value is too small (minimum=" + schema.toString() + ")"); } } @@ -252,9 +246,7 @@ void QJsonSchemaChecker::checkMaximum(const QJsonValue & value, const QJsonValue if (value.toDouble() > schema.toDouble()) { _error = true; - std::ostringstream oss; - oss << "value is too large (maximum=" << schema.toDouble() << ")"; - setMessage(oss.str()); + setMessage("value is too large (maximum=" + schema.toString() + ")"); } } @@ -272,11 +264,9 @@ void QJsonSchemaChecker::checkItems(const QJsonValue & value, const QJsonObject for(int i = 0; i < jArray.size(); ++i) { // validate each item - std::ostringstream oss; - oss << "[" << i << "]"; - _currentPath.push_back(oss.str()); + _currentPath.append("[" + QString::number(i) + "]"); validate(jArray[i], schema); - _currentPath.pop_back(); + _currentPath.removeLast(); } } @@ -296,9 +286,7 @@ void QJsonSchemaChecker::checkMinItems(const QJsonValue & value, const QJsonValu if (static_cast(jArray.size()) < minimum) { _error = true; - std::ostringstream oss; - oss << "array is too small (minimum=" << minimum << ")"; - setMessage(oss.str()); + setMessage("array is too large (minimum=" + QString::number(minimum) + ")"); } } @@ -318,9 +306,7 @@ void QJsonSchemaChecker::checkMaxItems(const QJsonValue & value, const QJsonValu if (static_cast(jArray.size()) > maximum) { _error = true; - std::ostringstream oss; - oss << "array is too large (maximum=" << maximum << ")"; - setMessage(oss.str()); + setMessage("array is too large (maximum=" + QString::number(maximum) + ")"); } } @@ -371,10 +357,7 @@ void QJsonSchemaChecker::checkEnum(const QJsonValue & value, const QJsonValue & // nothing found _error = true; - std::ostringstream oss; - oss << "Unknown enum value (allowed values are: " << schema.toString().toStdString(); QJsonDocument doc(schema.toArray()); QString strJson(doc.toJson(QJsonDocument::Compact)); - oss << strJson.toStdString() << ")"; - setMessage(oss.str()); + setMessage("Unknown enum value (allowed values are: " + schema.toString() + strJson+ ")"); } diff --git a/libsrc/webconfig/CgiHandler.cpp b/libsrc/webconfig/CgiHandler.cpp index 3796f135..97af4f83 100644 --- a/libsrc/webconfig/CgiHandler.cpp +++ b/libsrc/webconfig/CgiHandler.cpp @@ -73,7 +73,7 @@ void CgiHandler::cmd_cfg_get() { if ( _args.at(0) == "cfg_get" ) { - QFile file ( _hyperion->getConfigFileName().c_str() ); + QFile file ( _hyperion->getConfigFileName() ); if (file.exists ()) { if (file.open (QFile::ReadOnly)) { @@ -110,17 +110,18 @@ void CgiHandler::cmd_cfg_set() schemaChecker.setSchema(schemaJson); if ( schemaChecker.validate(hyperionConfigJsonObj) ) { - QJsonFactory::writeJson(QString::fromStdString(_hyperion->getConfigFileName()), hyperionConfigJsonObj); + QJsonFactory::writeJson(_hyperion->getConfigFileName(), hyperionConfigJsonObj); } else { - std::string errorMsg = "ERROR: Json validation failed: \n"; - for (std::list::const_iterator i = schemaChecker.getMessages().begin(); i != schemaChecker.getMessages().end(); ++i) + QString errorMsg = "ERROR: Json validation failed: \n"; + QStringList schemaErrors = schemaChecker.getMessages(); + foreach (auto & schemaError, schemaErrors) { - Error(_log, "config write validation: %s", (*i).c_str()); - errorMsg += *i + "\n"; + Error(_log, "config write validation: %s", QSTRING_CSTR(schemaError)); + errorMsg += schemaError + "\n"; } - throw std::runtime_error(errorMsg.c_str()); + throw std::runtime_error(errorMsg.toStdString()); } } catch(const std::runtime_error& validate_error) diff --git a/libsrc/webconfig/StaticFileServing.cpp b/libsrc/webconfig/StaticFileServing.cpp index dc79e247..8389a6aa 100644 --- a/libsrc/webconfig/StaticFileServing.cpp +++ b/libsrc/webconfig/StaticFileServing.cpp @@ -45,11 +45,11 @@ void StaticFileServing::onServerStarted (quint16 port) { Info(_log, "started on port %d name \"%s\"", port ,_server->getServerName().toStdString().c_str()); - const std::string mDNSDescr = (_server->getServerName().toStdString() + "@" + QHostInfo::localHostName().toStdString()); + const QString mDNSDescr = _server->getServerName() + "@" + QHostInfo::localHostName(); BonjourServiceRegister *bonjourRegister_http = new BonjourServiceRegister(); bonjourRegister_http->registerService( - BonjourRecord(mDNSDescr.c_str(), "_hyperiond-http._tcp", QString()), + BonjourRecord(mDNSDescr, "_hyperiond-http._tcp", QString()), port ); Debug(_log, "Web Config mDNS responder started"); diff --git a/src/hyperion-framebuffer/FramebufferWrapper.cpp b/src/hyperion-framebuffer/FramebufferWrapper.cpp index 48ef4ec7..66568288 100644 --- a/src/hyperion-framebuffer/FramebufferWrapper.cpp +++ b/src/hyperion-framebuffer/FramebufferWrapper.cpp @@ -2,7 +2,7 @@ // Hyperion-AmLogic includes #include "FramebufferWrapper.h" -FramebufferWrapper::FramebufferWrapper(const std::string & device, const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz) : +FramebufferWrapper::FramebufferWrapper(const QString & device, const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz) : _timer(this), _grabber(device,grabWidth, grabHeight) { diff --git a/src/hyperion-framebuffer/FramebufferWrapper.h b/src/hyperion-framebuffer/FramebufferWrapper.h index b763b52b..6103d403 100644 --- a/src/hyperion-framebuffer/FramebufferWrapper.h +++ b/src/hyperion-framebuffer/FramebufferWrapper.h @@ -9,7 +9,7 @@ class FramebufferWrapper : public QObject { Q_OBJECT public: - FramebufferWrapper(const std::string & device, const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz); + FramebufferWrapper(const QString & device, const unsigned grabWidth, const unsigned grabHeight, const unsigned updateRate_Hz); const Image & getScreenshot(); diff --git a/src/hyperion-framebuffer/hyperion-framebuffer.cpp b/src/hyperion-framebuffer/hyperion-framebuffer.cpp index 2f920f81..c6fc396d 100644 --- a/src/hyperion-framebuffer/hyperion-framebuffer.cpp +++ b/src/hyperion-framebuffer/hyperion-framebuffer.cpp @@ -46,7 +46,7 @@ int main(int argc, char ** argv) parser.showHelp(0); } - FramebufferWrapper fbWrapper(argDevice.getStdString(parser), argWidth.getInt(parser), argHeight.getInt(parser), 1000 / argFps.getInt(parser)); + FramebufferWrapper fbWrapper(argDevice.value(parser), argWidth.getInt(parser), argHeight.getInt(parser), 1000 / argFps.getInt(parser)); if (parser.isSet(argScreenshot)) { diff --git a/src/hyperion-remote/JsonConnection.cpp b/src/hyperion-remote/JsonConnection.cpp index 25b0738e..bfb42f7b 100644 --- a/src/hyperion-remote/JsonConnection.cpp +++ b/src/hyperion-remote/JsonConnection.cpp @@ -256,6 +256,33 @@ QString JsonConnection::getServerInfo() return QString(); } +QString JsonConnection::getSysInfo() +{ + qDebug() << "Get system info"; + + // create command + QJsonObject command; + command["command"] = QString("sysinfo"); + + // send command message + QJsonObject reply = sendMessage(command); + + // parse reply message + if (parseReply(reply)) + { + if (!reply.contains("info") || !reply["info"].isObject()) + { + throw std::runtime_error("No info available in result"); + } + + QJsonDocument doc(reply["info"].toObject()); + QString info(doc.toJson(QJsonDocument::Indented)); + return info; + } + + return QString(); +} + void JsonConnection::clear(int priority) { qDebug() << "Clear priority channel " << priority; diff --git a/src/hyperion-remote/JsonConnection.h b/src/hyperion-remote/JsonConnection.h index 0cef3e44..5e1df5b6 100644 --- a/src/hyperion-remote/JsonConnection.h +++ b/src/hyperion-remote/JsonConnection.h @@ -1,8 +1,5 @@ #pragma once -// stl includes -#include - // Qt includes #include #include @@ -79,6 +76,13 @@ public: /// QString getServerInfo(); + /// + /// Retrieve system info + /// + /// @return String with the sys info + /// + QString getSysInfo(); + /// /// Clear the given priority channel /// diff --git a/src/hyperion-remote/hyperion-remote.cpp b/src/hyperion-remote/hyperion-remote.cpp index 1caaabbd..8966d946 100644 --- a/src/hyperion-remote/hyperion-remote.cpp +++ b/src/hyperion-remote/hyperion-remote.cpp @@ -67,6 +67,7 @@ int main(int argc, char * argv[]) Option & argCreateEffect= parser.add