Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=860898ed2140a09a9e6a9111b29cdf346d829c3d
commit 860898ed2140a09a9e6a9111b29cdf346d829c3d Author: Michel Hermier <[email protected]> Date: Tue Sep 30 09:30:16 2014 +0200 libpacman: Make FAbstractLogger really abstract. diff --git a/lib/libpacman/util/fabstractlogger.cpp b/lib/libpacman/util/fabstractlogger.cpp index 5d14d35..f59c337 100644 --- a/lib/libpacman/util/fabstractlogger.cpp +++ b/lib/libpacman/util/fabstractlogger.cpp @@ -31,8 +31,8 @@ #include "fstdlib.h" #include "fstring.h" -FAbstractLogger::FAbstractLogger(unsigned char mask, FLogFunc fn, void *data) - : m_mask(mask), m_fn(fn), m_data(data) +FAbstractLogger::FAbstractLogger(unsigned char mask) + : m_mask(mask) { } FAbstractLogger::~FAbstractLogger() @@ -49,20 +49,18 @@ void FAbstractLogger::log(unsigned char flag, const char *format, ...) void FAbstractLogger::logs(unsigned char flag, const char *s) { - if(m_fn == NULL || - (flag & m_mask) == 0) { + if((flag & m_mask) == 0) { return; } - m_fn(flag, s, m_data); + logs_impl(s); } void FAbstractLogger::vlog(unsigned char flag, const char *format, va_list ap) { char str[LOG_STR_LEN]; - if(m_fn == NULL || - (flag & m_mask) == 0) { + if((flag & m_mask) == 0) { return; } diff --git a/lib/libpacman/util/fabstractlogger.h b/lib/libpacman/util/fabstractlogger.h index 8df20ca..6b55666 100644 --- a/lib/libpacman/util/fabstractlogger.h +++ b/lib/libpacman/util/fabstractlogger.h @@ -25,21 +25,19 @@ #define LOG_STR_LEN 256 -typedef void (*FLogFunc)(unsigned char flag, const char *message, void *data); - class FAbstractLogger { public: - FAbstractLogger(unsigned char mask, FLogFunc fn, void *data); + FAbstractLogger(unsigned char mask); virtual ~FAbstractLogger(); void log(unsigned char flag, const char *format, ...); - virtual void logs(unsigned char flag, const char *s); + void logs(unsigned char flag, const char *s); void vlog(unsigned char flag, const char *format, va_list ap); protected: + virtual void logs_impl(const char *s) = 0; + unsigned char m_mask; - FLogFunc m_fn; - void *m_data; }; #endif /* F_ABSTRACTLOGGER_H */ diff --git a/lib/libpacman/util/fdispatchlogger.cpp b/lib/libpacman/util/fdispatchlogger.cpp index 2fa1711..6a53deb 100644 --- a/lib/libpacman/util/fdispatchlogger.cpp +++ b/lib/libpacman/util/fdispatchlogger.cpp @@ -26,21 +26,16 @@ #include "util/fptrlist.h" -static -void f_dispatchlogger_log(unsigned char flag, const char *message, void *data) -{ - FPtrList *list = (FPtrList *)data; - - for (auto it = f_ptrlist_first(list), end = f_ptrlist_end(list); it != end; it = it->next()) { - ((FAbstractLogger *)f_ptrlistitem_data(it))->logs(flag, message); - } -} - FDispatchLogger::FDispatchLogger(unsigned char mask) - : FAbstractLogger(mask, f_dispatchlogger_log, f_ptrlist_new()) + : FAbstractLogger(mask) { } FDispatchLogger::~FDispatchLogger() { } +void FDispatchLogger::logs_impl(const char *message) +{ + logs_signal(message); +} + /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libpacman/util/fdispatchlogger.h b/lib/libpacman/util/fdispatchlogger.h index 7294eb3..85444ec 100644 --- a/lib/libpacman/util/fdispatchlogger.h +++ b/lib/libpacman/util/fdispatchlogger.h @@ -21,8 +21,7 @@ #ifndef F_DISPATCHLOGGER_H #define F_DISPATCHLOGGER_H -#include <stdio.h> - +#include "kernel/fsignal.h" #include "util/fabstractlogger.h" class FDispatchLogger @@ -31,6 +30,11 @@ class FDispatchLogger public: FDispatchLogger(unsigned char mask); ~FDispatchLogger(); + + flib::FSignal<void(const char *message)> logs_signal; + +protected: + virtual void logs_impl(const char *message) override; }; #endif /* F_DISPATCHLOGGER_H */ diff --git a/lib/libpacman/util/ffilelogger.cpp b/lib/libpacman/util/ffilelogger.cpp index f86cd36..363d3c1 100644 --- a/lib/libpacman/util/ffilelogger.cpp +++ b/lib/libpacman/util/ffilelogger.cpp @@ -30,25 +30,23 @@ #include "fstdlib.h" -static -void f_filelogger_log(unsigned char flag, const char *message, void *data) -{ - FILE *file = data; - struct tm *tm; - - tm = f_localtime(NULL); - fprintf(file, "[%02d/%02d/%02d %02d:%02d] %s\n", - tm->tm_mon+1, tm->tm_mday, tm->tm_year-100, - tm->tm_hour, tm->tm_min, - message); - fflush(file); -} - FFileLogger::FFileLogger(unsigned char mask, FILE *file) - : FAbstractLogger(mask, f_filelogger_log, file) + : FAbstractLogger(mask), m_file(file) { } FFileLogger::~FFileLogger() { } +void FFileLogger::logs_impl(const char *message) +{ + struct tm *tm; + + tm = f_localtime(NULL); + fprintf(m_file, "[%02d/%02d/%02d %02d:%02d] %s\n", + tm->tm_mon+1, tm->tm_mday, tm->tm_year-100, + tm->tm_hour, tm->tm_min, + message); + fflush(m_file); +} + /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libpacman/util/ffilelogger.h b/lib/libpacman/util/ffilelogger.h index 4ac3958..cc76b75 100644 --- a/lib/libpacman/util/ffilelogger.h +++ b/lib/libpacman/util/ffilelogger.h @@ -31,6 +31,10 @@ class FFileLogger public: FFileLogger(unsigned char mask, FILE *file); ~FFileLogger(); + +protected: + virtual void logs_impl(const char *message) override; + FILE *m_file; }; #endif /* F_FILELOGGER_H */ diff --git a/lib/libpacman/util/fsyslogger.cpp b/lib/libpacman/util/fsyslogger.cpp index 24c7515..8d27e3e 100644 --- a/lib/libpacman/util/fsyslogger.cpp +++ b/lib/libpacman/util/fsyslogger.cpp @@ -30,17 +30,16 @@ #include "fstdlib.h" -static -void f_syslogger_log(unsigned char flag, const char *message, void *data) -{ - syslog(LOG_WARNING, "%s", message); -} - FSysLogger::FSysLogger(unsigned char mask) - : FAbstractLogger(mask, f_syslogger_log, NULL) + : FAbstractLogger(mask) { } FSysLogger::~FSysLogger() { } +void FSysLogger::logs_impl(const char *message) +{ + syslog(LOG_WARNING, "%s", message); +} + /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libpacman/util/fsyslogger.h b/lib/libpacman/util/fsyslogger.h index c4fb24d..00fdaff 100644 --- a/lib/libpacman/util/fsyslogger.h +++ b/lib/libpacman/util/fsyslogger.h @@ -29,6 +29,9 @@ class FSysLogger public: FSysLogger(unsigned char mask); ~FSysLogger(); + +protected: + void logs_impl(const char *message) override; }; #endif /* F_SYSLOGGER_H */ _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
