mirror of
https://review.coreboot.org/flashrom.git
synced 2025-07-01 22:21:16 +02:00
libflashrom: Update the API for Logger Callback
The initial implementation does not account for user_data, requiring the calling application to use a global scope. This may lead to issues related to object lifecycle management and other architectural concerns. This patch adds user_data to the user’s log callback. Moreover, it performs message formatting, so the application only needs to pass the formatted string to the selected output. The change does not break the existing logging API but extends it. A new API version is introduced with the v2 suffix. Testing: Both unit tests and CLI tools serve as libflashrom clients. All unit tests run successfully. Change-Id: Iea738bd371fa3d69b9cf222c89ee67490d30af39 Signed-off-by: Dmitry Zhadinets <dzhadinets@gmail.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/86875 Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-by: Peter Marheine <pmarheine@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:

committed by
Anastasia Klimchuk

parent
90cc93d9bb
commit
b1794138f0
@ -730,7 +730,14 @@ struct cli_progress {
|
||||
void print_chip_support_status(const struct flashchip *chip);
|
||||
|
||||
/* libflashrom.c */
|
||||
/* Let gcc and clang check for correct printf-style format strings. */
|
||||
/*
|
||||
* Let gcc and clang check for correct printf-style format strings.
|
||||
* Avoid using formatted messages longer than 256 characters.
|
||||
* The new public logging API formats messages and passes a ready-to-print
|
||||
* string to the user callback for performance reasons.
|
||||
* Therefore, any message exceeding 256 characters will be truncated,
|
||||
* and an ERANGE error code will be returned.
|
||||
*/
|
||||
int print(enum flashrom_log_level level, const char *fmt, ...)
|
||||
#ifdef __MINGW32__
|
||||
# ifndef __MINGW_PRINTF_FORMAT
|
||||
|
@ -69,6 +69,24 @@ typedef int(flashrom_log_callback)(enum flashrom_log_level, const char *format,
|
||||
*/
|
||||
void flashrom_set_log_callback(flashrom_log_callback *log_callback);
|
||||
|
||||
typedef void (flashrom_log_callback_v2)(
|
||||
enum flashrom_log_level,
|
||||
const char* message,
|
||||
void* user_data);
|
||||
/**
|
||||
* @brief Set the log callback function.
|
||||
*
|
||||
* Set a callback function which will be invoked whenever libflashrom wants
|
||||
* to output messages. This allows frontends to do whatever they see fit with
|
||||
* such messages, e.g. write them to syslog, or to a file, or print them in a
|
||||
* GUI window, etc.
|
||||
* The message is formatted using vsnprintf
|
||||
*
|
||||
* @param log_callback Pointer to the new log callback function.
|
||||
* @param user_data A pointer to data managed by the caller.
|
||||
*/
|
||||
void flashrom_set_log_callback_v2(flashrom_log_callback_v2 *log_callback, void* user_data);
|
||||
|
||||
enum flashrom_progress_stage {
|
||||
FLASHROM_PROGRESS_READ,
|
||||
FLASHROM_PROGRESS_WRITE,
|
||||
|
Reference in New Issue
Block a user