From bff435db9a4e6776b82c931686f80206a25dfead Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Thu, 1 Sep 2022 07:34:10 +0200 Subject: [PATCH] add WINIX_SAVE_FILELOG plugin message --- winixd/core/app.cpp | 4 ++++ winixd/core/filelog.cpp | 33 ++++++++++++++++++++++----------- winixd/core/filelog.h | 13 ++++++------- winixd/core/pluginmsg.h | 10 ++++++++-- 4 files changed, 40 insertions(+), 20 deletions(-) diff --git a/winixd/core/app.cpp b/winixd/core/app.cpp index fc0cde7..db20b54 100644 --- a/winixd/core/app.cpp +++ b/winixd/core/app.cpp @@ -70,6 +70,7 @@ App::App() file_log.set_synchro(&synchro); file_log.set_time_zones(&system.time_zones); + // file_log.set_plugin(...) is called later, when a plugin object is initialized log.set_log_buffer(&log_buffer); log.set_file_log(&file_log); @@ -116,6 +117,9 @@ App::App() plugin.SetSessionManager(&session_manager); plugin.SetWinixRequest(&winix_request); + // now we can set the plugin in the file_log + file_log.set_plugin(&plugin); + functions.set_dependency(&winix_request); // functions.set_config(&config); // functions.set_file_log(&file_log); diff --git a/winixd/core/filelog.cpp b/winixd/core/filelog.cpp index d3372f3..5ec5ab2 100644 --- a/winixd/core/filelog.cpp +++ b/winixd/core/filelog.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2018-2019, Tomasz Sowa + * Copyright (c) 2018-2022, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,7 +37,7 @@ #include #include "utf8/utf8.h" #include "timezones.h" - +#include "plugin.h" namespace Winix @@ -49,6 +49,7 @@ FileLog::FileLog() { time_zones = nullptr; synchro = nullptr; + plugin = nullptr; log_time_zone_id = 0; } @@ -64,6 +65,12 @@ void FileLog::set_synchro(Synchro * synchro) } +void FileLog::set_plugin(Plugin * plugin) +{ + this->plugin = plugin; +} + + void FileLog::init(const std::wstring & log_file, bool log_stdout, int log_level, bool save_each_line, size_t log_time_zone_id) { pt::FileLog::init(log_file, log_stdout, log_level, save_each_line); @@ -116,19 +123,23 @@ pt::Date FileLog::get_local_date(const pt::Date & date) -bool FileLog::synchro_lock() +void FileLog::save_log(pt::WTextStream * buffer) { - return synchro->Lock(); + if( !buffer->empty() ) + { + Lock lock(synchro); + pt::FileLog::save_log(buffer); + + // at the beginning when winix starts the plugin pointer is null + // this plugin is set after the plugin object is initialized + if( plugin ) + { + plugin->Call(WINIX_SAVE_FILELOG, buffer); + } + } } -void FileLog::synchro_unlock() -{ - synchro->Unlock(); -} - - - } // namespace Winix diff --git a/winixd/core/filelog.h b/winixd/core/filelog.h index 42b44df..a8062d8 100644 --- a/winixd/core/filelog.h +++ b/winixd/core/filelog.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2018-2021, Tomasz Sowa + * Copyright (c) 2018-2022, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -47,7 +47,7 @@ namespace Winix { class TimeZones; - +class Plugin; class FileLog : public pt::FileLog { @@ -57,6 +57,7 @@ public: virtual ~FileLog(); void set_synchro(Synchro * synchro); + void set_plugin(Plugin * plugin); // using pt::FileLog::init to suppress clang warning: // warning: 'Winix::FileLog::init' hides overloaded virtual function [-Woverloaded-virtual] @@ -70,6 +71,8 @@ public: int get_log_level(); bool should_save_each_line(); + void save_log(pt::WTextStream * buffer); + protected: @@ -77,12 +80,8 @@ protected: size_t log_time_zone_id; TimeZones * time_zones; - Synchro * synchro; - - - virtual bool synchro_lock(); - virtual void synchro_unlock(); + Plugin * plugin; // can be null (only at the beginning when winix starts) }; diff --git a/winixd/core/pluginmsg.h b/winixd/core/pluginmsg.h index 4a2510e..dd02302 100644 --- a/winixd/core/pluginmsg.h +++ b/winixd/core/pluginmsg.h @@ -303,14 +303,20 @@ namespace Winix // http headers (without cookies) were created and are ready to send // here you can make some changes to them -// in p1 you have a pointer to the PT::Space (Request::out_headers) +// in p1 you have a pointer to the pt::Space (Request::out_headers) #define WINIX_PREPARE_TO_SEND_HTTP_HEADERS 31070 // http cookies were created and are ready to send // here you can make some changes to them -// in p1 you have a pointer to the PT::Space (Request::out_cookies) +// in p1 you have a pointer to the pt::Space (Request::out_cookies) #define WINIX_PREPARE_TO_SEND_HTTP_COOKIES 31080 +// a file log was saved +// in p1 you have a pointer to the pt::WTextStream buffer +// this can be called from a different thread but with locking +#define WINIX_SAVE_FILELOG 31090 + + /* messages sent from other threads