Random cleanup (#861)

Co-authored-by: Seker <murat.seker@barco.com>
This commit is contained in:
Murat Seker
2020-07-12 09:19:59 +02:00
committed by GitHub
parent de9ece5139
commit 138b7d9c94
74 changed files with 115 additions and 234 deletions

View File

@@ -1526,11 +1526,11 @@ void JsonAPI::handleTokenResponse(const bool &success, const QString &token, con
sendErrorReply("Token request timeout or denied", cmd, 5);
}
void JsonAPI::handleInstanceStateChange(const instanceState &state, const quint8 &instance, const QString &name)
void JsonAPI::handleInstanceStateChange(const InstanceState &state, const quint8 &instance, const QString &name)
{
switch (state)
{
case H_ON_STOP:
case InstanceState::H_ON_STOP:
if (_hyperion->getInstanceIndex() == instance)
{
handleInstanceSwitch();

View File

@@ -223,7 +223,7 @@ void JsonCB::handlePriorityUpdate()
activePriorities.removeAll(255);
int currentPriority = _prioMuxer->getCurrentPriority();
foreach (int priority, activePriorities) {
for (int priority : activePriorities) {
const Hyperion::InputInfo priorityInfo = _prioMuxer->getInputInfo(priority);
QJsonObject item;
item["priority"] = priority;

View File

@@ -30,7 +30,7 @@ public:
///
/// Destructor
///
~BoblightClientConnection();
~BoblightClientConnection() override;
signals:
///

View File

@@ -59,9 +59,8 @@ void BoblightServer::stop()
if ( ! _server->isListening() )
return;
foreach (BoblightClientConnection * connection, _openConnections) {
delete connection;
}
qDeleteAll(_openConnections);
_server->close();
Info(_log, "Stopped");

View File

@@ -12,7 +12,7 @@ BonjourBrowserWrapper* BonjourBrowserWrapper::instance = nullptr;
BonjourBrowserWrapper::BonjourBrowserWrapper(QObject * parent)
: QObject(parent)
, _bonjourResolver(new BonjourServiceResolver(this))
, _timerBonjourResolver( new QTimer(this))
, _timerBonjourResolver(new QTimer(this))
{
// register meta
qRegisterMetaType<QMap<QString,BonjourRecord>>("QMap<QString,BonjourRecord>");

View File

@@ -22,7 +22,7 @@ bool ColorsOption::validate(Parser & parser, QString & value)
QRegularExpressionMatch match = hexRe.match(value);
if(match.hasMatch())
{
Q_FOREACH(const QString m, match.capturedTexts())
for(const QString m : match.capturedTexts())
{
_colors.push_back(QColor(QString("#%1").arg(m)));
}

View File

@@ -11,7 +11,7 @@ bool Parser::parse(const QStringList &arguments)
return false;
}
Q_FOREACH(Option * option, _options)
for(Option * option : _options)
{
QString value = this->value(*option);
if (!option->validate(*this, value)) {

View File

@@ -28,7 +28,6 @@ EffectEngine::EffectEngine(Hyperion * hyperion)
, _log(Logger::getInstance("EFFECTENGINE"))
, _effectFileHandler(EffectFileHandler::getInstance())
{
Q_INIT_RESOURCE(EffectEngine);
qRegisterMetaType<hyperion::Components>("hyperion::Components");

View File

@@ -5,6 +5,7 @@
#include <linux/fb.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <cstring>
// STL includes
#include <iostream>
@@ -14,17 +15,11 @@
FramebufferFrameGrabber::FramebufferFrameGrabber(const QString & device, const unsigned width, const unsigned height)
: Grabber("FRAMEBUFFERGRABBER", width, height)
, _fbfd(0)
, _fbp(0)
, _fbDevice()
{
setDevicePath(device);
}
FramebufferFrameGrabber::~FramebufferFrameGrabber()
{
}
int FramebufferFrameGrabber::grabFrame(Image<ColorRgb> & image)
{
if (!_enabled) return 0;
@@ -34,10 +29,15 @@ int FramebufferFrameGrabber::grabFrame(Image<ColorRgb> & image)
PixelFormat pixelFormat;
/* Open the framebuffer device */
_fbfd = open(QSTRING_CSTR(_fbDevice), O_RDONLY);
int fbfd = open(QSTRING_CSTR(_fbDevice), O_RDONLY);
if (fbfd == -1)
{
Error(_log, "Error opening %s, %s : ", QSTRING_CSTR(_fbDevice), std::strerror(errno));
return -1;
}
/* get variable screen information */
ioctl (_fbfd, FBIOGET_VSCREENINFO, &vinfo);
ioctl (fbfd, FBIOGET_VSCREENINFO, &vinfo);
bytesPerPixel = vinfo.bits_per_pixel / 8;
capSize = vinfo.xres * vinfo.yres * bytesPerPixel;
@@ -53,24 +53,28 @@ int FramebufferFrameGrabber::grabFrame(Image<ColorRgb> & image)
#endif
default:
Error(_log, "Unknown pixel format: %d bits per pixel", vinfo.bits_per_pixel);
close(_fbfd);
close(fbfd);
return -1;
}
/* map the device to memory */
_fbp = (unsigned char*)mmap(0, capSize, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, _fbfd, 0);
unsigned char * fbp = (unsigned char*)mmap(0, capSize, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, fbfd, 0);
if (fbp == MAP_FAILED) {
Error(_log, "Error mapping %s, %s : ", QSTRING_CSTR(_fbDevice), std::strerror(errno));
return -1;
}
_imageResampler.setHorizontalPixelDecimation(vinfo.xres/_width);
_imageResampler.setVerticalPixelDecimation(vinfo.yres/_height);
_imageResampler.processImage(_fbp,
_imageResampler.processImage(fbp,
vinfo.xres,
vinfo.yres,
vinfo.xres * bytesPerPixel,
pixelFormat,
image);
munmap(_fbp, capSize);
close(_fbfd);
munmap(fbp, capSize);
close(fbfd);
return 0;
}
@@ -84,25 +88,24 @@ void FramebufferFrameGrabber::setDevicePath(const QString& path)
struct fb_var_screeninfo vinfo;
// Check if the framebuffer device can be opened and display the current resolution
_fbfd = open(QSTRING_CSTR(_fbDevice), O_RDONLY);
if (_fbfd == 0)
int fbfd = open(QSTRING_CSTR(_fbDevice), O_RDONLY);
if (fbfd == -1)
{
Error(_log, "Error openning %s", QSTRING_CSTR(_fbDevice));
Error(_log, "Error opening %s, %s : ", QSTRING_CSTR(_fbDevice), std::strerror(errno));
}
else
{
// get variable screen information
result = ioctl (_fbfd, FBIOGET_VSCREENINFO, &vinfo);
result = ioctl (fbfd, FBIOGET_VSCREENINFO, &vinfo);
if (result != 0)
{
Error(_log, "Could not get screen information");
Error(_log, "Could not get screen information, %s", std::strerror(errno));
}
else
{
Info(_log, "Display opened with resolution: %dx%d@%dbit", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
}
close(_fbfd);
close(fbfd);
}
}
}

View File

@@ -95,7 +95,7 @@ bool V4L2Grabber::init()
QString v4lDevices_str;
// show list only once
if (!QString(QSTRING_CSTR(_deviceName)).startsWith("/dev/"))
if (!_deviceName.startsWith("/dev/"))
{
for (auto& dev: _v4lDevices)
{
@@ -369,11 +369,8 @@ void V4L2Grabber::close_device()
_fileDescriptor = -1;
if (_streamNotifier != nullptr)
{
delete _streamNotifier;
_streamNotifier = nullptr;
}
delete _streamNotifier;
_streamNotifier = nullptr;
}
void V4L2Grabber::init_read(unsigned int buffer_size)

View File

@@ -41,10 +41,6 @@ CaptureCont::CaptureCont(Hyperion* hyperion)
handleSettingsUpdate(settings::INSTCAPTURE, _hyperion->getSetting(settings::INSTCAPTURE));
}
CaptureCont::~CaptureCont()
{
}
void CaptureCont::handleV4lImage(const QString& name, const Image<ColorRgb> & image)
{
if(_v4lCaptName != name)

View File

@@ -20,10 +20,6 @@ Grabber::Grabber(QString grabberName, int width, int height, int cropLeft, int c
Grabber::setCropping(cropLeft, cropRight, cropTop, cropBottom);
}
Grabber::~Grabber()
{
}
void Grabber::setEnabled(bool enable)
{
Info(_log,"Capture interface is now %s", enable ? "enabled" : "disabled");

View File

@@ -380,7 +380,7 @@ void Hyperion::setColor(const int priority, const std::vector<ColorRgb> &ledColo
_effectEngine->channelCleared(priority);
// create full led vector from single/multiple colors
unsigned int size = _ledString.leds().size();
size_t size = _ledString.leds().size();
std::vector<ColorRgb> newLedColors;
while (true)
{

View File

@@ -16,7 +16,7 @@ HyperionIManager::HyperionIManager(const QString& rootPath, QObject* parent)
, _rootPath( rootPath )
{
HIMinstance = this;
qRegisterMetaType<instanceState>("instanceState");
qRegisterMetaType<InstanceState>("InstanceState");
}
Hyperion* HyperionIManager::getHyperionInstance(const quint8& instance)
@@ -124,7 +124,7 @@ bool HyperionIManager::stopInstance(const quint8& inst)
if(_runningInstances.contains(inst))
{
// notify a ON_STOP rather sooner than later, queued signal listener should have some time to drop the pointer before it's deleted
emit instanceStateChanged(H_ON_STOP, inst);
emit instanceStateChanged(InstanceState::H_ON_STOP, inst);
Hyperion* hyperion = _runningInstances.value(inst);
hyperion->stop();
@@ -146,7 +146,7 @@ bool HyperionIManager::createInstance(const QString& name, const bool& start)
if(_instanceTable->createInstance(name, inst))
{
Info(_log,"New Hyperion instance created with name '%s'",QSTRING_CSTR(name));
emit instanceStateChanged(H_CREATED, inst, name);
emit instanceStateChanged(InstanceState::H_CREATED, inst, name);
emit change();
if(start)
@@ -168,7 +168,7 @@ bool HyperionIManager::deleteInstance(const quint8& inst)
if(_instanceTable->deleteInstance(inst))
{
Info(_log,"Hyperion instance with index '%d' has been deleted", inst);
emit instanceStateChanged(H_DELETED, inst);
emit instanceStateChanged(InstanceState::H_DELETED, inst);
emit change();
return true;
@@ -195,7 +195,7 @@ void HyperionIManager::handleFinished()
_runningInstances.remove(instance);
hyperion->deleteLater();
emit instanceStateChanged(H_STOPPED, instance);
emit instanceStateChanged(InstanceState::H_STOPPED, instance);
emit change();
}
@@ -208,6 +208,6 @@ void HyperionIManager::handleStarted()
_startQueue.removeAll(instance);
_runningInstances.insert(instance, hyperion);
emit instanceStateChanged(H_STARTED, instance);
emit instanceStateChanged(InstanceState::H_STARTED, instance);
emit change();
}

View File

@@ -69,11 +69,8 @@ void ImageProcessor::setSize(const unsigned width, const unsigned height)
return;
}
if ( _imageToLeds != nullptr)
{
// Clean up the old buffer and mapping
delete _imageToLeds;
}
// Clean up the old buffer and mapping
delete _imageToLeds;
// Construct a new buffer and mapping
_imageToLeds = (width>0 && height>0) ? (new ImageToLedsMap(width, height, 0, 0, _ledString.leds())) : nullptr;

View File

@@ -5,7 +5,6 @@
// hyperion includes
#include <hyperion/LedString.h>
LedString::LedString()
{
// empty

View File

@@ -43,11 +43,6 @@ LinearColorSmoothing::LinearColorSmoothing(const QJsonDocument& config, Hyperion
connect(_timer, &QTimer::timeout, this, &LinearColorSmoothing::updateLeds);
}
LinearColorSmoothing::~LinearColorSmoothing()
{
}
void LinearColorSmoothing::handleSettingsUpdate(const settings::type& type, const QJsonDocument& config)
{
if(type == settings::SMOOTHING)
@@ -224,7 +219,6 @@ void LinearColorSmoothing::componentStateChange(const hyperion::Components compo
{
setEnable(state);
}
}
void LinearColorSmoothing::setEnable(bool enable)

View File

@@ -32,9 +32,6 @@ public:
///
LinearColorSmoothing(const QJsonDocument& config, Hyperion* hyperion);
/// Destructor
virtual ~LinearColorSmoothing();
/// LED values as input for the smoothing filter
///
/// @param ledValues The color-value per led

View File

@@ -88,7 +88,7 @@ SettingsManager::SettingsManager(const quint8& instance, QObject* parent)
// check if our main schema syntax is IO
if (!valid.second)
{
foreach (auto & schemaError, schemaChecker.getMessages())
for (auto & schemaError : schemaChecker.getMessages())
Error(_log, "Schema Syntax Error: %s", QSTRING_CSTR(schemaError));
throw std::runtime_error("The config schema has invalid syntax. This should never happen! Go fix it!");
}
@@ -97,7 +97,7 @@ SettingsManager::SettingsManager(const quint8& instance, QObject* parent)
Info(_log,"Table upgrade required...");
dbConfig = schemaChecker.getAutoCorrectedConfig(dbConfig);
foreach (auto & schemaError, schemaChecker.getMessages())
for (auto & schemaError : schemaChecker.getMessages())
Warning(_log, "Config Fix: %s", QSTRING_CSTR(schemaError));
saveSettings(dbConfig);
@@ -131,7 +131,7 @@ bool SettingsManager::saveSettings(QJsonObject config, const bool& correct)
Warning(_log,"Fixing json data!");
config = schemaChecker.getAutoCorrectedConfig(config);
foreach (auto & schemaError, schemaChecker.getMessages())
for (auto & schemaError : schemaChecker.getMessages())
Warning(_log, "Config Fix: %s", QSTRING_CSTR(schemaError));
}

View File

@@ -35,9 +35,7 @@ JsonServer::JsonServer(const QJsonDocument& config)
JsonServer::~JsonServer()
{
foreach (JsonClientConnection * connection, _openConnections) {
delete connection;
}
qDeleteAll(_openConnections);
}
void JsonServer::start()

View File

@@ -7,10 +7,6 @@ LedDeviceTemplate::LedDeviceTemplate(const QJsonObject &deviceConfig)
_deviceReady = false;
}
LedDeviceTemplate::~LedDeviceTemplate()
{
}
LedDevice* LedDeviceTemplate::construct(const QJsonObject &deviceConfig)
{
return new LedDeviceTemplate(deviceConfig);
@@ -83,5 +79,3 @@ int LedDeviceTemplate::write(const std::vector<ColorRgb> & ledValues)
return retval;
}

View File

@@ -17,11 +17,6 @@ public:
///
explicit LedDeviceTemplate(const QJsonObject &deviceConfig);
///
/// Destructor of this LedDevice
///
virtual ~LedDeviceTemplate() override;
/// constructs leddevice
static LedDevice* construct(const QJsonObject &deviceConfig);
@@ -38,7 +33,7 @@ public slots:
/// Includes switching-off the device and stopping refreshes
///
virtual void close() override;
protected:
///
/// Opens and initiatialises the output device

View File

@@ -54,7 +54,7 @@ int LedDeviceMultiLightpack::open()
std::sort(_lightpacks.begin(), _lightpacks.end(), compareLightpacks);
// open each lightpack device
foreach (auto serial , serialList)
for (auto serial : serialList)
{
LedDeviceLightpack * device = new LedDeviceLightpack(serial);
int error = device->open();

View File

@@ -57,7 +57,7 @@ bool LedDeviceAtmoOrb::init(const QJsonObject &deviceConfig)
_orbIds.clear();
foreach(auto & id_str, orbIds)
for(auto & id_str : orbIds)
{
bool ok;
int id = id_str.toInt(&ok);

View File

@@ -205,7 +205,7 @@ bool LedDeviceNanoleaf::initLeds()
std::map<uint, std::map<uint, uint>> panelMap;
// Loop over all children.
foreach (const QJsonValue & value, positionData)
for (const QJsonValue & value : positionData)
{
QJsonObject panelObj = value.toObject();

View File

@@ -7,7 +7,7 @@
#include <QTimer>
#include <QRgb>
// TODO Remove this class if third-party apps have been migrated (eg. Hyperion Android Gabber, Windows Screen grabber etc.)
// TODO Remove this class if third-party apps have been migrated (eg. Hyperion Android Grabber, Windows Screen grabber etc.)
ProtoClientConnection::ProtoClientConnection(QTcpSocket* socket, const int &timeout, QObject *parent)
: QObject(parent)

View File

@@ -27,11 +27,12 @@ PythonInit::PythonInit()
EffectModule::registerHyperionExtensionModule();
// set Python module path when exists
wchar_t *pythonPath = Py_DecodeLocale((QDir::cleanPath(qApp->applicationDirPath() + "/../lib/python")).toLatin1().data(), nullptr);
wchar_t *pythonPath = nullptr;
#ifdef _WIN32
pythonPath = Py_DecodeLocale((QDir::cleanPath(qApp->applicationDirPath()) + "/python" + STRINGIFY(PYTHON_VERSION_MAJOR_MINOR) + ".zip").toLatin1().data(), nullptr);
if(QFile(QString::fromWCharArray(pythonPath)).exists())
#else
pythonPath = Py_DecodeLocale((QDir::cleanPath(qApp->applicationDirPath() + "/../lib/python")).toLatin1().data(), nullptr);
if(QDir(QString::fromWCharArray(pythonPath)).exists())
#endif

View File

@@ -68,9 +68,10 @@ void SSDPHandler::stopServer()
void SSDPHandler::handleSettingsUpdate(const settings::type& type, const QJsonDocument& config)
{
const QJsonObject& obj = config.object();
if(type == settings::FLATBUFSERVER)
{
const QJsonObject& obj = config.object();
if(obj["port"].toInt() != SSDPServer::getFlatBufPort())
{
SSDPServer::setFlatBufPort(obj["port"].toInt());
@@ -79,7 +80,6 @@ void SSDPHandler::handleSettingsUpdate(const settings::type& type, const QJsonDo
if(type == settings::JSONSERVER)
{
const QJsonObject& obj = config.object();
if(obj["port"].toInt() != SSDPServer::getJsonServerPort())
{
SSDPServer::setJsonServerPort(obj["port"].toInt());
@@ -88,7 +88,6 @@ void SSDPHandler::handleSettingsUpdate(const settings::type& type, const QJsonDo
if (type == settings::GENERAL)
{
const QJsonObject &obj = config.object();
if (obj["name"].toString() != SSDPServer::getHyperionName())
{
SSDPServer::setHyperionName(obj["name"].toString());
@@ -134,13 +133,13 @@ void SSDPHandler::handleNetworkConfigurationChanged(const QNetworkConfiguration
}
}
const QString SSDPHandler::getLocalAddress()
QString SSDPHandler::getLocalAddress() const
{
// get the first valid IPv4 address. This is probably not that one we actually want to announce
for( const auto & address : QNetworkInterface::allAddresses())
for(const auto & address : QNetworkInterface::allAddresses())
{
// is valid when, no loopback, IPv4
if (!address.isLoopback() && address.protocol() == QAbstractSocket::IPv4Protocol )
if (!address.isLoopback() && address.protocol() == QAbstractSocket::IPv4Protocol)
{
return address.toString();
}
@@ -174,26 +173,27 @@ void SSDPHandler::handleMSearchRequest(const QString& target, const QString& mx,
}
}
const QString SSDPHandler::getDescAddress()
QString SSDPHandler::getDescAddress() const
{
return getBaseAddress()+"description.xml";
}
const QString SSDPHandler::getBaseAddress()
QString SSDPHandler::getBaseAddress() const
{
return "http://"+_localAddress+":"+QString::number(_webserver->getPort())+"/";
return QString("http://%1:%2/").arg(_localAddress).arg(_webserver->getPort());
}
const QString SSDPHandler::buildDesc()
QString SSDPHandler::buildDesc() const
{
/// %1 base url http://192.168.0.177:80/
/// %2 friendly name Hyperion 2.0.0 (192.168.0.177)
/// %3 modelNumber 2.0.0
/// %4 serialNumber / UDN (H ID) Fjsa723dD0....
return SSDP_DESCRIPTION.arg(getBaseAddress(), QString("Hyperion (%2)").arg(_localAddress), QString(HYPERION_VERSION), _uuid);
return SSDP_DESCRIPTION.arg(getBaseAddress(), QString("Hyperion (%1)").arg(_localAddress), QString(HYPERION_VERSION), _uuid);
}
void SSDPHandler::sendAnnounceList(const bool alive){
void SSDPHandler::sendAnnounceList(const bool alive)
{
for(const auto & entry : _deviceList){
alive ? SSDPServer::sendAlive(entry) : SSDPServer::sendByeBye(entry);
}

View File

@@ -32,7 +32,6 @@ Profiler::Profiler(const char* sourceFile, const char* func, unsigned int line)
_logger->Message(Logger::DEBUG,_file,_func,_line,">>> enter block %d", _blockId);
}
Profiler::~Profiler()
{
_logger->Message( Logger::DEBUG, _file,_func, _line, "<<< exit block %d, executed for %f s", _blockId, getClockDelta(_startTime));
@@ -86,4 +85,3 @@ void Profiler::TimerGetTime(const QString timerName, const char* sourceFile, con
_logger->Message(Logger::DEBUG, sourceFile, func, line, "ERROR timer '%s' not started", QSTRING_CSTR(timerName));
}
}

View File

@@ -22,10 +22,6 @@ void RgbTransform::init(double gammaR, double gammaG, double gammaB, double back
initializeMapping();
}
RgbTransform::~RgbTransform()
{
}
double RgbTransform::getGammaR() const
{
return _gammaR;
@@ -175,4 +171,3 @@ void RgbTransform::transform(uint8_t & red, uint8_t & green, uint8_t & blue)
}
}
}

View File

@@ -19,10 +19,6 @@ SysInfo::SysInfo()
_sysinfo.domainName = QHostInfo::localDomainName();
}
SysInfo::~SysInfo()
{
}
SysInfo::HyperionSysInfo SysInfo::get()
{
if (SysInfo::_instance == nullptr)

View File

@@ -21,10 +21,6 @@ CgiHandler::CgiHandler (QObject * parent)
{
}
CgiHandler::~CgiHandler()
{
}
void CgiHandler::setBaseUrl(const QString& url)
{
_baseUrl = url;

View File

@@ -15,7 +15,6 @@ class CgiHandler : public QObject {
public:
CgiHandler (QObject * parent = NULL);
virtual ~CgiHandler (void);
void setBaseUrl(const QString& url);
void exec(const QStringList & args,QtHttpRequest * request, QtHttpReply * reply);

View File

@@ -54,7 +54,7 @@ void WebServer::initServer()
void WebServer::onServerStarted (quint16 port)
{
_inited= true;
_inited = true;
Info(_log, "Started on port %d name '%s'", port ,_server->getServerName().toStdString().c_str());
#ifdef ENABLE_AVAHI