From c2530b3761abd69b0d6e36e65901dd5b2127e078 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Mon, 21 Oct 2013 18:04:13 +0300 Subject: [PATCH] Plugin API: Add RmLog and RmLogF functions These functions take a `void* rm` parameter that is used to populate the Source field in the log. --- Library/Export.cpp | 39 +++++++++++++++++++++++++++++----- Library/Exports.def | 6 ++++-- Library/Logger.cpp | 13 +++++++++++- Library/Logger.h | 1 + Library/Section.h | 4 +++- Plugins/API/RainmeterAPI.h | 6 +++++- Plugins/API/x32/Rainmeter.lib | Bin 4092 -> 4426 bytes Plugins/API/x64/Rainmeter.lib | Bin 3966 -> 4276 bytes 8 files changed, 59 insertions(+), 10 deletions(-) diff --git a/Library/Export.cpp b/Library/Export.cpp index ebf48a7b..0738cba5 100644 --- a/Library/Export.cpp +++ b/Library/Export.cpp @@ -117,19 +117,48 @@ void __stdcall RmExecute(void* skin, LPCWSTR command) } } -BOOL LSLog(int nLevel, LPCWSTR unused, LPCWSTR pszMessage) +BOOL LSLog(int level, LPCWSTR unused, LPCWSTR message) { - NULLCHECK(pszMessage); + NULLCHECK(message); - // Ignore Level::Debug messages from plugins unless in debug mode - if (nLevel != (int)Logger::Level::Debug || GetRainmeter().GetDebug()) + // Ignore Debug messages from plugins unless in debug mode. + if (level != (int)Logger::Level::Debug || GetRainmeter().GetDebug()) { - GetLogger().Log((Logger::Level)nLevel, L"", pszMessage); + GetLogger().Log((Logger::Level)level, L"", message); } return TRUE; } +void __stdcall RmLog(void* rm, int level, LPCWSTR message) +{ + NULLCHECK(message); + + MeasurePlugin* measure = (MeasurePlugin*)rm; + + // Ignore Debug messages from plugins unless in debug mode. + if (level != (int)Logger::Level::Debug || GetRainmeter().GetDebug()) + { + GetLogger().LogSection((Logger::Level)level, measure, message); + } +} + +void RmLogF(void* rm, int level, LPCWSTR format, ...) +{ + NULLCHECK(format); + + MeasurePlugin* measure = (MeasurePlugin*)rm; + + // Ignore Debug messages from plugins unless in debug mode. + if (level != (int)Logger::Level::Debug || GetRainmeter().GetDebug()) + { + va_list args; + va_start(args, format); + GetLogger().LogSectionVF((Logger::Level)level, measure, format, args); + va_end(args); + } +} + // Deprecated! LPCWSTR ReadConfigString(LPCWSTR section, LPCWSTR option, LPCWSTR defValue) { diff --git a/Library/Exports.def b/Library/Exports.def index 6ca08df6..58b76fc1 100644 --- a/Library/Exports.def +++ b/Library/Exports.def @@ -1,7 +1,7 @@ LIBRARY EXPORTS - ; Note: If new functions are added, the Rainmeter.lib files in Plugins\API\x32 and Plugins\API\x64 - ; must be replaced by the corresponding file in Library\x32\Release and Library\x64\Release. + ; Note: If new functions are added, the Rainmeter.lib files in Plugins\API\{x32,x64} must be + ; replaced by the corresponding file in {x32,x64}-Release\Obj\Library. ; Set 'true' in Rainmeter.props first to minimize the .lib size. RmReadString RmReadFormula @@ -9,6 +9,8 @@ EXPORTS RmPathToAbsolute RmExecute RmGet + RmLog + RmLogF LSLog ReadConfigString PluginBridge diff --git a/Library/Logger.cpp b/Library/Logger.cpp index 4429f50a..4f077ed4 100644 --- a/Library/Logger.cpp +++ b/Library/Logger.cpp @@ -234,7 +234,7 @@ void Logger::LogVF(Level level, const WCHAR* source, const WCHAR* format, va_lis delete [] buffer; } -void Logger::LogSectionVF(Logger::Level level, Section* section, const WCHAR* format, va_list args) +std::wstring GetSectionSourceString(Section* section) { std::wstring source; if (section) @@ -250,7 +250,18 @@ void Logger::LogSectionVF(Logger::Level level, Section* section, const WCHAR* fo source += section->GetOriginalName(); source += L']'; } + return source; +} +void Logger::LogSection(Logger::Level level, Section* section, const WCHAR* message) +{ + const std::wstring source = GetSectionSourceString(section); + GetLogger().Log(level, source.c_str(), message); +} + +void Logger::LogSectionVF(Logger::Level level, Section* section, const WCHAR* format, va_list args) +{ + const std::wstring source = GetSectionSourceString(section); GetLogger().LogVF(level, source.c_str(), format, args); } diff --git a/Library/Logger.h b/Library/Logger.h index 45f548ab..645da3b3 100644 --- a/Library/Logger.h +++ b/Library/Logger.h @@ -61,6 +61,7 @@ public: void Log(Level level, const WCHAR* source, const WCHAR* msg); void LogVF(Level level, const WCHAR* source, const WCHAR* format, va_list args); void LogMeterWindowVF(Logger::Level level, MeterWindow* meterWindow, const WCHAR* format, va_list args); + void LogSection(Logger::Level level, Section* section, const WCHAR* message); void LogSectionVF(Logger::Level level, Section* section, const WCHAR* format, va_list args); const std::wstring& GetLogFilePath() { return m_LogFilePath; } diff --git a/Library/Section.h b/Library/Section.h index 04070e29..78406d03 100644 --- a/Library/Section.h +++ b/Library/Section.h @@ -55,7 +55,9 @@ protected: bool UpdateCounter(); - const std::wstring m_Name; // Name of this Section + // Plugins may access this string through RmGetMeasureName(). This should never changed be to + // ensure thread-safety. + const std::wstring m_Name; bool m_DynamicVariables; // If true, the section contains dynamic variables int m_UpdateDivider; // Divider for the update diff --git a/Plugins/API/RainmeterAPI.h b/Plugins/API/RainmeterAPI.h index d74d08b3..fae3a835 100644 --- a/Plugins/API/RainmeterAPI.h +++ b/Plugins/API/RainmeterAPI.h @@ -56,7 +56,11 @@ enum RmGetType RMG_SKINWINDOWHANDLE = 4 }; -LIBRARY_EXPORT BOOL LSLog(int type, LPCWSTR unused, LPCWSTR message); +LIBRARY_EXPORT void __stdcall RmLog(void* rm, int level, LPCWSTR message); + +LIBRARY_EXPORT void __cdecl RmLogF(void* rm, int level, LPCWSTR format, ...); + +LIBRARY_EXPORT BOOL __cdecl LSLog(int level, LPCWSTR unused, LPCWSTR message); // // Wrapper functions diff --git a/Plugins/API/x32/Rainmeter.lib b/Plugins/API/x32/Rainmeter.lib index 47bcfa3073c3639bafeb14ab9e13b0577fc7b7ff..f7d3cb6655ecce39c3a25975b4b9827101f1ace6 100644 GIT binary patch delta 1037 zcmZWnJ!=$E6g}ha&d%qXF}s-!M%c*`BMM4(T;0{mA}khLZME1;gauIurjUS@{s0TZ zg@BN1du@U#6f7h*_F7nkwXsnUVj+ka@0*X!%s6o7&b;%^z3<%n{xm z>$b_Yy~o|4#9<8M2#~Ni zr-V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