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
This commit is contained in:
redPanther
2017-03-04 22:17:42 +01:00
committed by GitHub
parent 19f8928869
commit bfb9a08c80
90 changed files with 539 additions and 529 deletions

View File

@@ -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)
{

View File

@@ -5,7 +5,6 @@
#include <QString>
// stl includes
#include <string>
#include <stdio.h>
#include <stdarg.h>
#include <map>
@@ -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<std::string,Logger*> *LoggerMap;
static std::map<QString,Logger*> *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;
};

View File

@@ -1,7 +1,6 @@
#pragma once
#include <string>
#include <algorithm>
#include <QString>
/**
* 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")
{

View File

@@ -1,4 +1,3 @@
#include <string>
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
@@ -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;
};

View File

@@ -1,4 +1,5 @@
#pragma once
#include <QString>
#include <utils/ColorRgb.h>
#include <utils/ColorRgbw.h>
@@ -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);
};

View File

@@ -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 // <Vendor_ID release Version_ID> // single line file <Release_ID/sid>
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 // <Vendor_ID release Version_ID> // single line file <Release_ID/sid>
QString prettyName; // $PRETTY_NAME $DISTRIB_DESCRIPTION
QString productType;
QString productVersion;
QString prettyName;
};
QString machineHostName();

View File

@@ -1,7 +1,6 @@
#pragma once
#include <string>
#include <algorithm>
#include <QString>
/**
* 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")
{

View File

@@ -1,9 +1,7 @@
#pragma once
#include <iostream>
#include <string>
#include <stdexcept>
#include <sstream>
// JSON-Schema includes
#include <utils/jsonschema/QJsonSchemaChecker.h>
@@ -30,9 +28,10 @@ public:
bool valid = schemaChecker.validate(configTree);
for (std::list<std::string>::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();

View File

@@ -1,9 +1,5 @@
#pragma once
// stl includes
#include <string>
#include <list>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
@@ -48,7 +44,7 @@ public:
///
/// @return A list of error messages
///
const std::list<std::string> & 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<std::string> _currentPath;
QStringList _currentPath;
/// The result messages collected during the schema verification
std::list<std::string> _messages;
QStringList _messages;
/// Flag indicating an error occured during validation
bool _error;
};