|
MRTKLIB 0.7.14
Modernized GNSS Positioning Library
|
MRTKLIB Public API — Context Management and Logging. More...
#include <stdarg.h>#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include <time.h>#include "mrtklib/mrtk_version.h"Go to the source code of this file.
Typedefs | |
| typedef struct mrtk_context_s | mrtk_context_t |
| Opaque library context structure. | |
| typedef void(* | mrtk_log_cb_t) (mrtk_context_t *ctx, mrtk_log_level_t level, const char *msg) |
| Log callback function signature. | |
Enumerations | |
| enum | mrtk_log_level_t { MRTK_LOG_DEBUG = 0 , MRTK_LOG_INFO , MRTK_LOG_WARN , MRTK_LOG_ERROR , MRTK_LOG_NONE } |
| Log severity levels. More... | |
Functions | |
| mrtk_context_t * | mrtk_context_new (void) |
| Create a new library context. | |
| void | mrtk_context_free (mrtk_context_t *ctx) |
| Free the library context and release all associated resources. | |
| void | mrtk_context_set_log_callback (mrtk_context_t *ctx, mrtk_log_cb_t cb) |
| Set a custom log callback handler. | |
| void | mrtk_context_set_log_level (mrtk_context_t *ctx, mrtk_log_level_t level) |
| Set the minimum log level threshold. | |
| mrtk_log_level_t | mrtk_context_get_log_level (const mrtk_context_t *ctx) |
| Get the current log level threshold. | |
| void | mrtk_log (mrtk_context_t *ctx, mrtk_log_level_t level, const char *fmt,...) |
| Log a formatted message. | |
| 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. | |
| 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) |
| Associate user-defined data with the context. | |
| void * | mrtk_context_get_user_data (const mrtk_context_t *ctx) |
| Retrieve user-defined data from the context. | |
| const char * | mrtk_version_string (void) |
| Get the library version string. | |
Variables | |
| mrtk_context_t * | g_mrtk_legacy_ctx |
| Global context for legacy RTKLIB trace() bridge. | |
MRTKLIB Public API — Context Management and Logging.
This header defines the public API for MRTKLIB, a modernized and refactored version of RTKLIB targeting JAXA QZSS/MADOCA processing. The library is designed to be:
Definition in file mrtklib.h.
| typedef struct mrtk_context_s mrtk_context_t |
Opaque library context structure.
Holds all library state including logging configuration, error state, and user-defined data. This structure is intentionally opaque to allow internal changes without breaking API compatibility.
| typedef void(* mrtk_log_cb_t) (mrtk_context_t *ctx, mrtk_log_level_t level, const char *msg) |
Log callback function signature.
Custom log handlers must conform to this signature. The callback is invoked for each log message that passes the minimum log level filter.
| ctx | Context instance that generated the log message |
| level | Severity level of the message |
| msg | Null-terminated formatted message string |
| enum mrtk_log_level_t |
Log severity levels.
Levels are ordered by severity (DEBUG < INFO < WARN < ERROR < NONE). Setting a minimum log level filters out all messages below that severity. MRTK_LOG_NONE disables all output.
| void mrtk_clear_error | ( | mrtk_context_t * | ctx | ) |
Clear the last error message.
Resets the error state, clearing any previously stored error message.
| ctx | Context instance |
| 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 and release all associated resources.
Safely frees a context created by mrtk_context_new(). After this call, the context pointer is invalid and must not be used.
| ctx | Context to free. If NULL, this function does nothing. |
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 threshold.
| ctx | Context instance |
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 | ) |
Retrieve user-defined data from the context.
| ctx | Context instance |
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 and initializes a new context with default settings:
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 handler.
Replaces the default logging behavior with a custom callback. This allows integration with external logging systems, GUI log windows, or file-based logging.
| ctx | Context instance |
| cb | Callback function to handle log messages. Pass NULL to restore the default stdout/stderr logger. |
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 threshold.
Messages below this severity level will be silently discarded. Setting MRTK_LOG_NONE disables all logging output.
| ctx | Context instance |
| level | Minimum level to log (inclusive) |
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 ) |
Associate user-defined data with the context.
Stores an arbitrary pointer that can be retrieved later. Useful for passing application-specific state through callbacks.
| ctx | Context instance |
| user_data | Pointer to user data (may be NULL) |
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.
Retrieves the most recent error message stored in the context by an internal library function. Returns an empty string if no error has occurred.
| ctx | Context instance |
| 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.
Formats and dispatches a log message through the registered callback if the message level meets or exceeds the minimum threshold.
| ctx | Context instance |
| level | Severity level of this message |
| fmt | printf-style format string |
| ... | Format arguments |
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 va_list variant of mrtk_log(), intended for use by wrapper functions (such as the legacy RTKLIB trace() bridge) that receive variadic arguments from their own callers.
| ctx | Context instance |
| level | Severity level of this message |
| fmt | printf-style format string |
| args | 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().
| const char * mrtk_version_string | ( | void | ) |
Get the library version string.
Definition at line 363 of file mrtk_core.c.
|
extern |
Global context for legacy RTKLIB trace() bridge.
During the migration period, this global pointer allows the existing trace() / tracet() functions in rtkcmn.c to route their output through the new context-based logging system without modifying thousands of call sites.
Definition at line 40 of file mrtk_core.c.