MRTKLIB 0.7.14
Modernized GNSS Positioning Library
Loading...
Searching...
No Matches
mrtk_context.h
Go to the documentation of this file.
1/*------------------------------------------------------------------------------
2 * mrtk_context.h : MRTKLIB legacy context type definitions
3 *
4 * Copyright (C) 2026 H.SHIONO (MRTKLIB Project)
5 * Copyright (C) 2023-2025 Cabinet Office, Japan
6 * Copyright (C) 2024-2025 Lighthouse Technology & Consulting Co. Ltd.
7 * Copyright (C) 2023-2025 Japan Aerospace Exploration Agency
8 * Copyright (C) 2023-2025 TOSHIBA ELECTRONIC TECHNOLOGIES CORPORATION
9 * Copyright (C) 2015- Mitsubishi Electric Corp.
10 * Copyright (C) 2014 Geospatial Information Authority of Japan
11 * Copyright (C) 2014 T.SUZUKI
12 * Copyright (C) 2007-2023 T.TAKASU
13 *
14 * SPDX-License-Identifier: BSD-2-Clause
15 *----------------------------------------------------------------------------*/
16/**
17 * @file mrtk_context.h
18 * @brief MRTKLIB Context — runtime context for processing, trace, and error handling.
19 *
20 * This header defines the non-opaque runtime context structure that replaces
21 * global variables for trace output, error state, and processing control.
22 * All trace functions and major processing pipeline functions accept a
23 * pointer to this context as their first argument.
24 */
25#ifndef MRTK_CONTEXT_H
26#define MRTK_CONTEXT_H
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#include <stdint.h>
33#include <stdio.h>
34
35/*============================================================================
36 * Error Codes
37 *===========================================================================*/
38
39/**
40 * @brief Error code enumeration for MRTKLIB functions.
41 */
42typedef enum {
43 MRTK_OK = 0, /**< Success */
44 MRTK_ERR_VALUE = -1, /**< Invalid parameter value */
45 MRTK_ERR_IO = -2, /**< I/O error (file, stream) */
46 MRTK_ERR_MEMORY = -3, /**< Memory allocation failure */
47 MRTK_ERR_FORMAT = -4, /**< Data format error */
48 MRTK_ERR_CANCEL = -5 /**< Processing cancelled */
50
51/*============================================================================
52 * Callback Types
53 *===========================================================================*/
54
55/**
56 * @brief Message display callback (for GUI/app-level status messages).
57 * @param[in] msg Null-terminated message string
58 */
59typedef void (*mrtk_showmsg_cb_t)(const char* msg);
60
61/*============================================================================
62 * Context Structure
63 *===========================================================================*/
64
65/**
66 * @brief Runtime context for MRTKLIB processing.
67 *
68 * Holds per-session state: runtime control flags, error state, trace
69 * configuration, user data, and application callbacks. All major
70 * processing and trace functions accept a pointer to this structure
71 * as their first argument.
72 */
73typedef struct {
74 /* Runtime control */
75 volatile int is_running; /**< Non-zero while processing is active */
76 volatile int cancel_requested; /**< Non-zero to request cancellation */
77
78 /* Error state */
79 mrtk_err_t last_err_code; /**< Most recent error code */
80 char last_err_msg[256]; /**< Most recent error message */
81
82 /* Trace / debug */
83 int trace_level; /**< Trace level (0:off, 1:error..5:verbose) */
84 FILE* trace_fp; /**< Trace output stream (NULL = disabled) */
85 uint32_t tick_trace; /**< Tick count at traceopen (for elapsed time) */
86
87 /* User data and callbacks */
88 void* user_data; /**< Application-specific data pointer */
89 mrtk_showmsg_cb_t cb_showmsg; /**< Status message callback (may be NULL) */
91
92/*============================================================================
93 * Lifecycle Functions
94 *===========================================================================*/
95
96/**
97 * @brief Create a new runtime context.
98 *
99 * Allocates and zero-initialises a context. Default settings:
100 * - trace_level: 0 (off)
101 * - trace_fp: NULL (no trace output)
102 * - All other members: zero / NULL
103 *
104 * @return Newly allocated context, or NULL on allocation failure.
105 */
107
108/**
109 * @brief Destroy a runtime context.
110 *
111 * Closes the trace file (unless stdout/stderr) and frees memory.
112 * Safe to call with NULL.
113 *
114 * @param[in] ctx Context to destroy, or NULL (no-op)
115 */
117
118/*============================================================================
119 * Global Context (transitional)
120 *===========================================================================*/
121
122/**
123 * @brief Global context pointer for transitional migration.
124 *
125 * Functions that have not yet received an explicit ctx parameter use
126 * this global as a fallback. Applications should set this at startup
127 * and clear it at shutdown.
128 *
129 * @note This pointer will be removed once all modules have been migrated
130 * to explicit context passing.
131 */
132extern mrtk_ctx_t* g_mrtk_ctx;
133
134#ifdef __cplusplus
135}
136#endif
137
138#endif /* MRTK_CONTEXT_H */
mrtk_ctx_t * g_mrtk_ctx
Global context pointer for transitional migration.
mrtk_err_t
Error code enumeration for MRTKLIB functions.
@ MRTK_ERR_MEMORY
@ MRTK_ERR_CANCEL
@ MRTK_ERR_VALUE
@ MRTK_OK
@ MRTK_ERR_FORMAT
@ MRTK_ERR_IO
void mrtk_ctx_destroy(mrtk_ctx_t *ctx)
Destroy a runtime context.
mrtk_ctx_t * mrtk_ctx_create(void)
Create a new runtime context.
void(* mrtk_showmsg_cb_t)(const char *msg)
Message display callback (for GUI/app-level status messages).
Runtime context for MRTKLIB processing.
mrtk_showmsg_cb_t cb_showmsg
mrtk_err_t last_err_code
volatile int is_running
FILE * trace_fp
uint32_t tick_trace
char last_err_msg[256]
void * user_data
volatile int cancel_requested