changed for new libpcscxx interface version 3; refs #176

This commit is contained in:
Marc Wäckerlin
2014-04-04 11:29:41 +00:00
parent d02ef2ff55
commit fbb3150285
11 changed files with 381 additions and 483 deletions

View File

@@ -42,7 +42,7 @@ namespace qbrowserlib {
}
static QString networkError(QNetworkReply::NetworkError err) {
TRC_FN; LOG<<err;
TRC_FN; LOG_FN<<err;
switch (err) {
case QNetworkReply::NoError:
return tr("Network connection successful, remote host can be"

View File

@@ -17,24 +17,32 @@ namespace qbrowserlib {
const std::string& file, unsigned long line,
bool traceOpenClose):
_debug(DEBUG), _close(traceOpenClose),
_addr(addr), _name(name), _file(file), _line(line) {
if (!_debug || !_close) return;
++_level;
std::stringstream ss;
indent(ss)<<"\\ "<<_name;
close(init(std::clog)<<ss.str())<<std::endl;
if (!_dialog) _dialog = new LogDialog;
_dialog->append(*this, ss.str());
_addr(addr), _name(name), _file(file), _line(line), _clean(true) {
if (!_debug) return;
if (_close) {
++_level;
indent(_ss)<<"\\ "<<_name;
close(init(std::clog)<<_ss.str())<<std::endl;
if (!_dialog) _dialog = new LogDialog;
_dialog->append(*this, _ss.str());
_ss.str(std::string());
}
indent(_ss)<<"";
}
Log::~Log() throw() {
if (!_debug || !_close) return;
std::stringstream ss;
indent(ss)<<"/ "<<_name;
close(init(std::clog)<<ss.str())<<std::endl;
if (!_debug) return;
if (!_clean) {
close(init(std::clog)<<_ss.str())<<std::endl;
if (!_dialog) _dialog = new LogDialog;
_dialog->append(*this, _ss.str());
}
if (!_close) return;
_ss.str(std::string());
indent(_ss)<<"/ "<<_name;
close(init(std::clog)<<_ss.str())<<std::endl;
--_level;
if (!_dialog) _dialog = new LogDialog;
_dialog->append(*this, ss.str());
_dialog->append(*this, _ss.str());
}
void Log::show(QWidget* p) {

View File

@@ -28,42 +28,43 @@
namespace qbrowserlib {
#ifndef LOG
#define LOG \
QBROWSERLIB_LOCAL_TRACER
#endif
#define LOG \
qbrowserlib::Log(this, __PRETTY_FUNCTION__, __FILE__, __LINE__, false)
#endif
#ifndef LOG_FN
#define LOG_FN \
qbrowserlib::Log(0, __PRETTY_FUNCTION__, __FILE__, __LINE__, false)
#endif
#ifndef TRC
#define TRC \
qbrowserlib::Log QBROWSERLIB_LOCAL_TRACER \
(this, __PRETTY_FUNCTION__, __FILE__, __LINE__)
#define TRC \
qbrowserlib::Log __TRC_LOCAL(this, __PRETTY_FUNCTION__, __FILE__, __LINE__)
#endif
#ifndef TRC_FN
#define TRC_FN \
qbrowserlib::Log QBROWSERLIB_LOCAL_TRACER \
(0, __PRETTY_FUNCTION__, __FILE__, __LINE__)
#define TRC_FN \
qbrowserlib::Log __TRC_LOCAL(0, __PRETTY_FUNCTION__, __FILE__, __LINE__)
#endif
#define CRYPTOKI_LOG(X) \
qbrowserlib::Log(0, __PRETTY_FUNCTION__, __FILE__, __LINE__, false)<<X
#ifdef CRYPTOLOG
#undef CRYPTOLOG
#endif
#define CRYPTOLOG(X) \
qbrowserlib::Log(0, __PRETTY_FUNCTION__, __FILE__, __LINE__, false)<<X;
#define PCSC_LOG(X) \
qbrowserlib::Log(0, __PRETTY_FUNCTION__, __FILE__, __LINE__, false)<<X
#define OPENSSL_LOG(X) \
qbrowserlib::Log(0, __PRETTY_FUNCTION__, __FILE__, __LINE__, false)<<X
#ifdef OPENSSL_CHECK
#undef OPENSSL_CHECK
#endif
#define OPENSSL_CHECK(X) \
if (!(X)) { \
ERR_load_ENGINE_strings(); \
std::stringstream ss; \
qbrowserlib::Log ss(0, __PRETTY_FUNCTION__, __FILE__, __LINE__, false); \
for (unsigned int err(0); err=ERR_get_error();) { \
ss<<"Error: "<<ERR_error_string(err, 0)<<"; "; \
} \
ss<<"Command "<<#X<<" failed in function "<<__PRETTY_FUNCTION__ \
<<" in file "<<__FILE__<<":"<<__LINE__; \
qbrowserlib::Log(0, __PRETTY_FUNCTION__, __FILE__, __LINE__, false) \
<<ss.str(); \
throw std::runtime_error(ss.str()); \
}
@@ -81,6 +82,8 @@ namespace qbrowserlib {
public:
Log();
Log(const void* addr, const std::string& name,
const std::string& file, unsigned long line,
bool traceOpenClose=true);
@@ -90,6 +93,10 @@ namespace qbrowserlib {
~Log() throw();
static void show(QWidget* p);
std::string str() {
return _ss.str();
}
private:
@@ -111,6 +118,8 @@ namespace qbrowserlib {
const std::string _name;
const std::string _file;
unsigned long _line;
std::stringstream _ss;
bool _clean;
};
class LogDialog:
@@ -221,11 +230,8 @@ namespace qbrowserlib {
// note: template class method must be defined in the header
template<typename TYPE> Log& Log::operator<<(TYPE arg) {
if (!_debug) return *this;
std::stringstream ss;
indent(ss)<<" "<<arg;
close(init(std::clog)<<ss.str())<<std::endl;
if (!_dialog) _dialog = new LogDialog;
_dialog->append(*this, ss.str());
_clean = false;
_ss<<" "<<arg;
return *this;
}