Use macros for debug/verbose/trace to avoid calculation of args if debug/verbose/trace are not enabled.

pull/1095/head
Fredrik Öhrström 2023-11-12 13:16:51 +01:00
rodzic c5dc2ada51
commit 92090073cb
4 zmienionych plików z 23 dodań i 9 usunięć

Wyświetl plik

@ -589,7 +589,10 @@ bool SerialDeviceFile::open(bool fail_if_not_ok)
fd_ = ::open(file_.c_str(), O_RDONLY | O_NONBLOCK);
if (fd_ == -1)
{
if (fail_if_not_ok) error("Could not open file %s for reading.\n", file_.c_str());
if (fail_if_not_ok)
{
error("Could not open file %s for reading.\n", file_.c_str());
}
verbose("(serialdevicefile) could not open file %s for reading.\n", file_.c_str());
return false;
}

Wyświetl plik

@ -587,7 +587,7 @@ void warning(const char* fmt, ...) {
}
}
void verbose(const char* fmt, ...) {
void verbose_int(const char* fmt, ...) {
if (verbose_enabled_) {
va_list args;
va_start(args, fmt);
@ -596,7 +596,7 @@ void verbose(const char* fmt, ...) {
}
}
void debug(const char* fmt, ...) {
void debug_int(const char* fmt, ...) {
if (debug_enabled_) {
va_list args;
va_start(args, fmt);
@ -605,7 +605,7 @@ void debug(const char* fmt, ...) {
}
}
void trace(const char* fmt, ...) {
void trace_int(const char* fmt, ...) {
if (trace_enabled_) {
va_list args;
va_start(args, fmt);

Wyświetl plik

@ -100,9 +100,16 @@ bool enableLogfile(const std::string& logfile, bool daemon);
void disableLogfile();
void enableSyslog();
void error(const char* fmt, ...);
void verbose(const char* fmt, ...);
void trace(const char* fmt, ...);
void debug(const char* fmt, ...);
#define verbose(...) { if (isVerboseEnabled()) { verbose_int(__VA_ARGS__); } }
void verbose_int(const char* fmt, ...);
#define trace(...) { if (isTraceEnabled()) { trace_int(__VA_ARGS__); } }
void trace_int(const char* fmt, ...);
#define debug(...) { if (isDebugEnabled()) { debug_int(__VA_ARGS__); } }
void debug_int(const char* fmt, ...);
void warning(const char* fmt, ...);
void info(const char* fmt, ...);
void notice(const char* fmt, ...);

Wyświetl plik

@ -1532,8 +1532,12 @@ bool Telegram::checkMAC(std::vector<uchar> &frame,
debug("(wmbus) received mac %s\n", received.c_str());
string truncated = calculated.substr(0, received.length());
bool ok = truncated == received;
if (ok) debug("(wmbus) mac ok!\n");
else {
if (ok)
{
debug("(wmbus) mac ok!\n");
}
else
{
debug("(wmbus) mac NOT ok!\n");
explainParse("BADMAC", 0);
}