From 646e552ba7410a925748ffe5e191ac577570f163 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 21 Jul 2015 18:50:35 +0200 Subject: Warning on command failure, null debugstream to ignore messages --- common/clientapi.h | 13 ++++++++++--- common/log.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) (limited to 'common') diff --git a/common/clientapi.h b/common/clientapi.h index a01db23..4644ae1 100644 --- a/common/clientapi.h +++ b/common/clientapi.h @@ -35,6 +35,7 @@ #include "resultprovider.h" #include "domain/applicationdomaintype.h" #include "resourceconfig.h" +#include "log.h" namespace async { //This should abstract if we execute from eventloop or in thread. @@ -277,7 +278,9 @@ public: //Potentially move to separate thread as well auto facade = FacadeFactory::instance().getFacade(resourceName(resourceIdentifier), resourceIdentifier); if (facade) { - facade->create(domainObject).exec().waitForFinished(); + facade->create(domainObject).template then([](){}, [](int errorCode, const QString &error) { + Warning() << "Failed to create"; + }).exec().waitForFinished(); } //TODO return job? } @@ -292,7 +295,9 @@ public: //Potentially move to separate thread as well auto facade = FacadeFactory::instance().getFacade(resourceName(resourceIdentifier), resourceIdentifier); if (facade) { - facade->modify(domainObject).exec().waitForFinished(); + facade->modify(domainObject).template then([](){}, [](int errorCode, const QString &error) { + Warning() << "Failed to modify"; + }).exec().waitForFinished(); } //TODO return job? } @@ -305,7 +310,9 @@ public: //Potentially move to separate thread as well auto facade = FacadeFactory::instance().getFacade(resourceName(resourceIdentifier), resourceIdentifier); if (facade) { - facade->remove(domainObject).exec().waitForFinished(); + facade->remove(domainObject).template then([](){}, [](int errorCode, const QString &error) { + Warning() << "Failed to remove"; + }).exec().waitForFinished(); } //TODO return job? } diff --git a/common/log.cpp b/common/log.cpp index 14869bb..95a9c01 100644 --- a/common/log.cpp +++ b/common/log.cpp @@ -33,6 +33,27 @@ private: Q_DISABLE_COPY(DebugStream) }; +class NullStream: public QIODevice +{ +public: + NullStream() + : QIODevice() + { + open(WriteOnly); + } + virtual ~NullStream(){}; + + bool isSequential() const { return true; } + qint64 readData(char *, qint64) { return 0; /* eof */ } + qint64 readLineData(char *, qint64) { return 0; /* eof */ } + qint64 writeData(const char *data, qint64 len) + { + return len; + } +private: + Q_DISABLE_COPY(NullStream) +}; + /* * ANSI color codes: * 0: reset colors/style @@ -75,6 +96,11 @@ static QString colorCommand(QList colorCodes) QDebug debugStream(DebugLevel debugLevel, int line, const char* file, const char* function, const char* debugArea) { + if (debugLevel <= DebugLevel::Trace) { + static NullStream stream; + return QDebug(&stream); + } + static DebugStream stream; QDebug debug(&stream); -- cgit v1.2.3