From c2e2c26ab23f5914f35bc2e26ff65aed7d7e7afc Mon Sep 17 00:00:00 2001 From: redPanther Date: Sun, 10 Jul 2016 23:14:23 +0200 Subject: [PATCH] Logging migration continues ... (#97) * migrate logging for blackborder and bonjour. fix logging bug in hyperion * fix kodichecker when kodi is not there --- include/blackborder/BlackBorderProcessor.h | 2 +- libsrc/blackborder/BlackBorderDetector.cpp | 8 +- libsrc/blackborder/BlackBorderProcessor.cpp | 31 +++---- libsrc/bonjour/bonjourserviceregister.cpp | 92 +++++++++++--------- libsrc/effectengine/EffectEngine.cpp | 2 - libsrc/hyperion/Hyperion.cpp | 6 +- libsrc/kodivideochecker/KODIVideoChecker.cpp | 2 +- 7 files changed, 76 insertions(+), 67 deletions(-) diff --git a/include/blackborder/BlackBorderProcessor.h b/include/blackborder/BlackBorderProcessor.h index 443b1789..f7c2bcc4 100644 --- a/include/blackborder/BlackBorderProcessor.h +++ b/include/blackborder/BlackBorderProcessor.h @@ -3,6 +3,7 @@ // Jsoncpp includes #include + // Local Hyperion includes #include "BlackBorderDetector.h" @@ -107,6 +108,5 @@ namespace hyperion unsigned _consistentCnt; /// The number of frame the previous detected border NOT matched the incomming border unsigned _inconsistentCnt; - }; } // end namespace hyperion diff --git a/libsrc/blackborder/BlackBorderDetector.cpp b/libsrc/blackborder/BlackBorderDetector.cpp index c75e7f85..7f9b1129 100644 --- a/libsrc/blackborder/BlackBorderDetector.cpp +++ b/libsrc/blackborder/BlackBorderDetector.cpp @@ -1,12 +1,14 @@ #include +#include + // BlackBorders includes #include #include using namespace hyperion; -BlackBorderDetector::BlackBorderDetector(double threshold) : - _blackborderThreshold(calculateThreshold(threshold)) +BlackBorderDetector::BlackBorderDetector(double threshold) + : _blackborderThreshold(calculateThreshold(threshold)) { // empty } @@ -21,7 +23,7 @@ uint8_t BlackBorderDetector::calculateThreshold(double threshold) uint8_t blackborderThreshold = uint8_t(rgbThreshold); - std::cout << "BLACKBORDER INFO: threshold set to " << threshold << " (" << int(blackborderThreshold) << ")" << std::endl; + Info(Logger::getInstance("BLACKBORDER"), "threshold set to %f (%d)", threshold , int(blackborderThreshold)); return blackborderThreshold; } diff --git a/libsrc/blackborder/BlackBorderProcessor.cpp b/libsrc/blackborder/BlackBorderProcessor.cpp index 9ee324fc..c84d3054 100644 --- a/libsrc/blackborder/BlackBorderProcessor.cpp +++ b/libsrc/blackborder/BlackBorderProcessor.cpp @@ -1,8 +1,6 @@ #include -/* -#include -using std::setw; -//*/ + +#include // Blackborder includes #include @@ -10,20 +8,19 @@ using std::setw; using namespace hyperion; -BlackBorderProcessor::BlackBorderProcessor(const Json::Value &blackborderConfig) : - _unknownSwitchCnt(blackborderConfig.get("unknownFrameCnt", 600).asUInt()), - _borderSwitchCnt(blackborderConfig.get("borderFrameCnt", 50).asUInt()), - _maxInconsistentCnt(blackborderConfig.get("maxInconsistentCnt", 10).asUInt()), - _blurRemoveCnt(blackborderConfig.get("blurRemoveCnt", 1).asUInt()), - _detectionMode(blackborderConfig.get("mode", "default").asString()), - _detector(blackborderConfig.get("threshold", 0.01).asDouble()), - _currentBorder({true, -1, -1}), - _previousDetectedBorder({true, -1, -1}), - _consistentCnt(0), - _inconsistentCnt(10) +BlackBorderProcessor::BlackBorderProcessor(const Json::Value &blackborderConfig) + : _unknownSwitchCnt(blackborderConfig.get("unknownFrameCnt", 600).asUInt()) + , _borderSwitchCnt(blackborderConfig.get("borderFrameCnt", 50).asUInt()) + , _maxInconsistentCnt(blackborderConfig.get("maxInconsistentCnt", 10).asUInt()) + , _blurRemoveCnt(blackborderConfig.get("blurRemoveCnt", 1).asUInt()) + , _detectionMode(blackborderConfig.get("mode", "default").asString()) + , _detector(blackborderConfig.get("threshold", 0.01).asDouble()) + , _currentBorder({true, -1, -1}) + , _previousDetectedBorder({true, -1, -1}) + , _consistentCnt(0) + , _inconsistentCnt(10) { - std::cout << "BLACKBORDER INFO: mode:" << _detectionMode << std::endl; - // empty + Info(Logger::getInstance("BLACKBORDER"), "mode: %s", _detectionMode.c_str()); } BlackBorder BlackBorderProcessor::getCurrentBorder() const diff --git a/libsrc/bonjour/bonjourserviceregister.cpp b/libsrc/bonjour/bonjourserviceregister.cpp index a0dcc96a..dbe83e01 100755 --- a/libsrc/bonjour/bonjourserviceregister.cpp +++ b/libsrc/bonjour/bonjourserviceregister.cpp @@ -31,6 +31,8 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include + BonjourServiceRegister::BonjourServiceRegister(QObject *parent) : QObject(parent), dnssref(0), bonjourSocket(0) { @@ -39,49 +41,56 @@ BonjourServiceRegister::BonjourServiceRegister(QObject *parent) BonjourServiceRegister::~BonjourServiceRegister() { - if (dnssref) { - DNSServiceRefDeallocate(dnssref); - dnssref = 0; - } + if (dnssref) + { + DNSServiceRefDeallocate(dnssref); + dnssref = 0; + } } void BonjourServiceRegister::registerService(const BonjourRecord &record, quint16 servicePort) { - if (dnssref) { - qWarning("Warning: Already registered a service for this object, aborting new register"); - return; - } - quint16 bigEndianPort = servicePort; + if (dnssref) + { + Warning(Logger::getInstance("BonJour"), "Already registered a service for this object, aborting new register"); + return; + } + quint16 bigEndianPort = servicePort; #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN - { - bigEndianPort = 0 | ((servicePort & 0x00ff) << 8) | ((servicePort & 0xff00) >> 8); - } + { + bigEndianPort = 0 | ((servicePort & 0x00ff) << 8) | ((servicePort & 0xff00) >> 8); + } #endif - DNSServiceErrorType err = DNSServiceRegister(&dnssref, 0, 0, record.serviceName.toUtf8().constData(), - record.registeredType.toUtf8().constData(), - record.replyDomain.isEmpty() ? 0 - : record.replyDomain.toUtf8().constData(), 0, - bigEndianPort, 0, 0, bonjourRegisterService, this); - if (err != kDNSServiceErr_NoError) { - emit error(err); - } else { - int sockfd = DNSServiceRefSockFD(dnssref); - if (sockfd == -1) { - emit error(kDNSServiceErr_Invalid); - } else { - bonjourSocket = new QSocketNotifier(sockfd, QSocketNotifier::Read, this); - connect(bonjourSocket, SIGNAL(activated(int)), this, SLOT(bonjourSocketReadyRead())); - } - } + DNSServiceErrorType err = DNSServiceRegister(&dnssref, 0, 0, record.serviceName.toUtf8().constData(), + record.registeredType.toUtf8().constData(), + (record.replyDomain.isEmpty() ? 0 : record.replyDomain.toUtf8().constData()), + 0, bigEndianPort, 0, 0, bonjourRegisterService, this); + if (err != kDNSServiceErr_NoError) + { + emit error(err); + } + else + { + int sockfd = DNSServiceRefSockFD(dnssref); + if (sockfd == -1) + { + emit error(kDNSServiceErr_Invalid); + } + else + { + bonjourSocket = new QSocketNotifier(sockfd, QSocketNotifier::Read, this); + connect(bonjourSocket, SIGNAL(activated(int)), this, SLOT(bonjourSocketReadyRead())); + } + } } void BonjourServiceRegister::bonjourSocketReadyRead() { - DNSServiceErrorType err = DNSServiceProcessResult(dnssref); - if (err != kDNSServiceErr_NoError) - emit error(err); + DNSServiceErrorType err = DNSServiceProcessResult(dnssref); + if (err != kDNSServiceErr_NoError) + emit error(err); } @@ -90,13 +99,16 @@ void BonjourServiceRegister::bonjourRegisterService(DNSServiceRef, DNSServiceFla const char *regtype, const char *domain, void *data) { - BonjourServiceRegister *serviceRegister = static_cast(data); - if (errorCode != kDNSServiceErr_NoError) { - emit serviceRegister->error(errorCode); - } else { - serviceRegister->finalRecord = BonjourRecord(QString::fromUtf8(name), - QString::fromUtf8(regtype), - QString::fromUtf8(domain)); - emit serviceRegister->serviceRegistered(serviceRegister->finalRecord); - } + BonjourServiceRegister *serviceRegister = static_cast(data); + if (errorCode != kDNSServiceErr_NoError) + { + emit serviceRegister->error(errorCode); + } + else + { + serviceRegister->finalRecord = BonjourRecord(QString::fromUtf8(name), + QString::fromUtf8(regtype), + QString::fromUtf8(domain)); + emit serviceRegister->serviceRegistered(serviceRegister->finalRecord); + } } diff --git a/libsrc/effectengine/EffectEngine.cpp b/libsrc/effectengine/EffectEngine.cpp index 2def554a..a22fd3cf 100644 --- a/libsrc/effectengine/EffectEngine.cpp +++ b/libsrc/effectengine/EffectEngine.cpp @@ -138,8 +138,6 @@ bool EffectEngine::loadEffectDefinition(const std::string &path, const std::stri effectDefinition.script = path + QDir::separator().toLatin1() + config["script"].asString(); effectDefinition.args = config["args"]; - // return succes //BLACKLIST OUTPUT TO LOG (Spam). This is more a effect development thing and the list gets longer and longer -// std::cout << "EFFECTENGINE INFO: Effect loaded: " + effectDefinition.name << std::endl; return true; } diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index 595c7d57..5352fe04 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -202,7 +202,7 @@ MultiColorTransform * Hyperion::createLedColorsTransform(const unsigned ledCnt, for (int i=0; i 0) { - std::cout << ", "; + ss << ", "; } if (ledIndexList[i].contains("-")) { @@ -211,13 +211,13 @@ MultiColorTransform * Hyperion::createLedColorsTransform(const unsigned ledCnt, int endInd = ledIndices[1].toInt(); transform->setTransformForLed(colorTransform->_id, startInd, endInd); - std::cout << startInd << "-" << endInd; + ss << startInd << "-" << endInd; } else { int index = ledIndexList[i].toInt(); transform->setTransformForLed(colorTransform->_id, index, index); - std::cout << index; + ss << index; } } Info(log, "ColorTransform '%s' => [%s]", colorTransform->_id.c_str(), ss.str().c_str()); diff --git a/libsrc/kodivideochecker/KODIVideoChecker.cpp b/libsrc/kodivideochecker/KODIVideoChecker.cpp index e3cef4a9..6f0d5435 100644 --- a/libsrc/kodivideochecker/KODIVideoChecker.cpp +++ b/libsrc/kodivideochecker/KODIVideoChecker.cpp @@ -310,7 +310,7 @@ void KODIVideoChecker::reconnect() void KODIVideoChecker::connectionError(QAbstractSocket::SocketError error) { - Error(_log,"Connection error (%s)", error); + Error(_log,"Connection error (%s)", _socket.errorString().toStdString().c_str()); // close the socket _socket.close();