From 93cef66115e08f065b75e33b3f56fdfb89ec9bbb Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 6 Feb 2020 16:59:29 +0100 Subject: [PATCH] lib: prepare callbacks for mockup callbacks in unittests --- core/src/lib/message.cc | 18 ++++++++++-------- core/src/lib/message.h | 11 +++++++---- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/core/src/lib/message.cc b/core/src/lib/message.cc index a531529656e..7312f5c67e5 100644 --- a/core/src/lib/message.cc +++ b/core/src/lib/message.cc @@ -3,7 +3,7 @@ Copyright (C) 2000-2012 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2019 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -43,8 +43,6 @@ #include "lib/message_queue_item.h" #include "lib/thread_specific_data.h" -static db_log_insert_func p_db_log_insert = NULL; - // globals const char* working_directory = NULL; /* working directory path stored here */ const char* assert_msg = (char*)NULL; /* ASSERT2 error message */ @@ -597,7 +595,7 @@ static inline bool SetSyslogFacility(JobControlRecord* jcr, * Split the output for syslog (it converts \n to ' ' and is * limited to 1024 characters per syslog message */ -static inline void SendToSyslog(int mode, const char* msg) +static void SendToSyslog_(int mode, const char* msg) { int len; char buf[1024]; @@ -616,6 +614,12 @@ static inline void SendToSyslog(int mode, const char* msg) } } +static SyslogCallback SendToSyslog{SendToSyslog_}; +void RegisterSyslogCallback(SyslogCallback c) { SendToSyslog = c; } + +static DbLogInsertCallback SendToDbLog = NULL; +void SetDbLogInsertCallback(DbLogInsertCallback f) { SendToDbLog = f; } + /* * Handle sending the message to the appropriate place */ @@ -737,8 +741,8 @@ void DispatchMessage(JobControlRecord* jcr, case MessageDestinationCode::kCatalog: if (!jcr || !jcr->db) { break; } - if (p_db_log_insert) { - if (!p_db_log_insert(jcr, mtime, msg)) { + if (SendToDbLog) { + if (!SendToDbLog(jcr, mtime, msg)) { DeliveryError( _("Msg delivery error: Unable to store data in database.\n")); } @@ -1678,5 +1682,3 @@ void SetLogTimestampFormat(const char* format) { log_timestamp_format = format; } - -void SetDbLogInsertCallback(db_log_insert_func f) { p_db_log_insert = f; } diff --git a/core/src/lib/message.h b/core/src/lib/message.h index d45b7efe320..0e2d8fb3fdd 100644 --- a/core/src/lib/message.h +++ b/core/src/lib/message.h @@ -37,6 +37,7 @@ #include "lib/message_destination_info.h" #include +#include class JobControlRecord; @@ -50,10 +51,9 @@ bool GetTrace(void); const char* get_basename(const char* pathname); void SetLogTimestampFormat(const char* format); -typedef bool (*db_log_insert_func)(JobControlRecord* jcr, - utime_t mtime, - const char* msg); -void SetDbLogInsertCallback(db_log_insert_func f); +using DbLogInsertCallback = + std::function; +void SetDbLogInsertCallback(DbLogInsertCallback f); class MessagesResource; @@ -92,4 +92,7 @@ bool GetTimestamp(void); void SetDbType(const char* name); void RegisterMessageCallback(void msg_callback(int type, const char* msg)); +using SyslogCallback = std::function; +void RegisterSyslogCallback(SyslogCallback c); + #endif /* BAREOS_LIB_MESSAGE_H_ */