|
MRTKLIB 0.7.14
Modernized GNSS Positioning Library
|
Core implementation of MRTKLIB context management and logging. More...
#include <stdarg.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include "mrtklib/mrtklib.h"Go to the source code of this file.
Classes | |
| struct | mrtk_context_s |
| Internal context structure. More... | |
Macros | |
| #define | MAX_ERROR_LEN 256 |
| Maximum length of error messages stored in context. | |
| #define | MAX_LOG_LEN 1024 |
| Maximum length of formatted log messages. | |
Functions | |
| static void | default_log_callback (mrtk_context_t *ctx, mrtk_log_level_t level, const char *msg) |
| Default log callback implementation. | |
| static void | mrtk_set_error (mrtk_context_t *ctx, const char *fmt,...) |
| Set the internal error message. | |
| mrtk_context_t * | mrtk_context_new (void) |
| Create a new library context. | |
| void | mrtk_context_free (mrtk_context_t *ctx) |
| Free the library context. | |
| void | mrtk_context_set_log_callback (mrtk_context_t *ctx, mrtk_log_cb_t cb) |
| Set a custom log callback. | |
| void | mrtk_context_set_log_level (mrtk_context_t *ctx, mrtk_log_level_t level) |
| Set the minimum log level. | |
| mrtk_log_level_t | mrtk_context_get_log_level (const mrtk_context_t *ctx) |
| Get the current log level. | |
| void | mrtk_log_v (mrtk_context_t *ctx, mrtk_log_level_t level, const char *fmt, va_list args) |
| Log a formatted message using a pre-initialized va_list. | |
| void | mrtk_log (mrtk_context_t *ctx, mrtk_log_level_t level, const char *fmt,...) |
| Log a formatted message. | |
| const char * | mrtk_get_last_error (const mrtk_context_t *ctx) |
| Get the last error message. | |
| void | mrtk_clear_error (mrtk_context_t *ctx) |
| Clear the last error message. | |
| void | mrtk_context_set_user_data (mrtk_context_t *ctx, void *user_data) |
| Set user-defined data. | |
| void * | mrtk_context_get_user_data (const mrtk_context_t *ctx) |
| Get user-defined data. | |
| const char * | mrtk_version_string (void) |
| Get the library version string. | |
Variables | |
| mrtk_context_t * | g_mrtk_legacy_ctx = NULL |
| Global context for legacy RTKLIB trace() bridge. | |
Core implementation of MRTKLIB context management and logging.
This file contains the implementation of the opaque context structure and all associated lifecycle, logging, and error handling functions.
Definition in file mrtk_core.c.
| #define MAX_ERROR_LEN 256 |
Maximum length of error messages stored in context.
Definition at line 47 of file mrtk_core.c.
Referenced by mrtk_set_error().
| #define MAX_LOG_LEN 1024 |
Maximum length of formatted log messages.
Definition at line 50 of file mrtk_core.c.
Referenced by mrtk_log_v().
|
static |
Default log callback implementation.
Outputs log messages to stdout (DEBUG, INFO, WARN) or stderr (ERROR). This is the default handler used when no custom callback is registered.
| ctx | Context instance (unused in default implementation) |
| level | Severity level of the message |
| msg | Formatted message string |
Definition at line 83 of file mrtk_core.c.
References MRTK_LOG_DEBUG, MRTK_LOG_ERROR, MRTK_LOG_INFO, MRTK_LOG_NONE, and MRTK_LOG_WARN.
Referenced by mrtk_context_new(), and mrtk_context_set_log_callback().
| void mrtk_clear_error | ( | mrtk_context_t * | ctx | ) |
Clear the last error message.
| ctx | Context instance |
Definition at line 319 of file mrtk_core.c.
References mrtk_context_s::last_error.
| void mrtk_context_free | ( | mrtk_context_t * | ctx | ) |
Free the library context.
Free the library context and release all associated resources.
Releases all memory associated with the context. Safe to call with NULL.
| ctx | Context to free, or NULL (no-op) |
Definition at line 184 of file mrtk_core.c.
References free.
| mrtk_log_level_t mrtk_context_get_log_level | ( | const mrtk_context_t * | ctx | ) |
Get the current log level.
Get the current log level threshold.
| ctx | Context instance |
Definition at line 233 of file mrtk_core.c.
References mrtk_context_s::log_level, and MRTK_LOG_NONE.
| void * mrtk_context_get_user_data | ( | const mrtk_context_t * | ctx | ) |
Get user-defined data.
Retrieve user-defined data from the context.
| ctx | Context instance |
Definition at line 347 of file mrtk_core.c.
References mrtk_context_s::user_data.
| mrtk_context_t * mrtk_context_new | ( | void | ) |
Create a new library context.
Allocates memory for a new context and initializes it with default values. The default configuration is:
Definition at line 162 of file mrtk_core.c.
References calloc, default_log_callback(), mrtk_context_s::last_error, mrtk_context_s::log_callback, mrtk_context_s::log_level, MRTK_LOG_INFO, and mrtk_context_s::user_data.
| void mrtk_context_set_log_callback | ( | mrtk_context_t * | ctx, |
| mrtk_log_cb_t | cb ) |
Set a custom log callback.
Set a custom log callback handler.
| ctx | Context instance |
| cb | Callback function, or NULL to restore default logger |
Definition at line 202 of file mrtk_core.c.
References default_log_callback(), and mrtk_context_s::log_callback.
| void mrtk_context_set_log_level | ( | mrtk_context_t * | ctx, |
| mrtk_log_level_t | level ) |
Set the minimum log level.
Set the minimum log level threshold.
| ctx | Context instance |
| level | New minimum log level |
Definition at line 221 of file mrtk_core.c.
References mrtk_context_s::log_level.
| void mrtk_context_set_user_data | ( | mrtk_context_t * | ctx, |
| void * | user_data ) |
Set user-defined data.
Associate user-defined data with the context.
| ctx | Context instance |
| user_data | Pointer to associate with context |
Definition at line 335 of file mrtk_core.c.
References mrtk_context_s::user_data.
| const char * mrtk_get_last_error | ( | const mrtk_context_t * | ctx | ) |
Get the last error message.
| ctx | Context instance |
Definition at line 307 of file mrtk_core.c.
References mrtk_context_s::last_error.
| void mrtk_log | ( | mrtk_context_t * | ctx, |
| mrtk_log_level_t | level, | ||
| const char * | fmt, | ||
| ... ) |
Log a formatted message.
Convenience wrapper around mrtk_log_v() that accepts variadic arguments.
| ctx | Context instance |
| level | Message severity level |
| fmt | printf-style format string |
| ... | Format arguments |
Definition at line 289 of file mrtk_core.c.
References mrtk_log_v().
Referenced by mrtk_set_error().
| void mrtk_log_v | ( | mrtk_context_t * | ctx, |
| mrtk_log_level_t | level, | ||
| const char * | fmt, | ||
| va_list | args ) |
Log a formatted message using a pre-initialized va_list.
This is the core formatting and dispatch function. Both mrtk_log() and the legacy trace() bridge delegate to this function.
| ctx | Context instance |
| level | Message severity level |
| fmt | printf-style format string |
| args | Pre-initialized va_list |
Definition at line 251 of file mrtk_core.c.
References mrtk_context_s::log_callback, MAX_LOG_LEN, and MRTK_LOG_NONE.
Referenced by mrtk_log().
|
static |
Set the internal error message.
Stores a formatted error message in the context for later retrieval via mrtk_get_last_error(). Also logs the error message at ERROR level.
| ctx | Context instance |
| fmt | printf-style format string |
| ... | Format arguments |
Definition at line 131 of file mrtk_core.c.
References mrtk_context_s::last_error, MAX_ERROR_LEN, mrtk_log(), and MRTK_LOG_ERROR.
| const char * mrtk_version_string | ( | void | ) |
Get the library version string.
Definition at line 363 of file mrtk_core.c.
| mrtk_context_t* g_mrtk_legacy_ctx = NULL |
Global context for legacy RTKLIB trace() bridge.
Definition at line 40 of file mrtk_core.c.