LibJuno
1.0.4
LibJuno is a lightweight C11 library designed specifically for embedded systems.
Loading...
Searching...
No Matches
module.h
Go to the documentation of this file.
1
/*
2
MIT License
3
4
Copyright (c) 2025 Robin A. Onsay
5
6
Permission is hereby granted, free of charge, to any person obtaining
7
a copy of this software and associated documentation files
8
(the "Software"), to deal in the Software without restriction,
9
including without limitation the rights to use, copy, modify, merge,
10
publish, distribute, sublicense, and/or sell copies of the Software,
11
and to permit persons to whom the Software is furnished to do so,
12
subject to the following conditions:
13
14
The above copyright notice and this permission notice shall be
15
included in all copies or substantial portions of the Software.
16
*/
17
#ifndef JUNO_MODULE_H
18
#define JUNO_MODULE_H
19
20
#include "
juno/status.h
"
21
#include <stdint.h>
22
#include <stdbool.h>
54
// @{"req": ["REQ-SYS-002", "REQ-SYS-006", "REQ-SYS-009"]}
55
56
62
#define JUNO_MODULE_DECLARE(NAME_T) typedef union NAME_T NAME_T
68
#define JUNO_MODULE_ROOT_DECLARE(NAME_T) typedef struct NAME_T NAME_T
74
#define JUNO_MODULE_DERIVE_DECLARE(NAME_T) JUNO_MODULE_ROOT_DECLARE(NAME_T)
75
79
#define JUNO_FAILURE_HANDLER _pfcnFailureHandler
83
#define JUNO_FAILURE_USER_DATA _pvFailureUserData
87
#define JUNO_MODULE_EMPTY
88
92
#define JUNO_MODULE_ARG(...) __VA_ARGS__
93
97
#define JUNO_MODULE_SUPER tRoot
98
111
// @{"req": ["REQ-MODULE-004"]}
112
#define JUNO_MODULE(API_T, ROOT_T, ...) \
113
{ \
114
ROOT_T JUNO_MODULE_SUPER; \
115
__VA_ARGS__ \
116
}
117
128
// @{"req": ["REQ-MODULE-001", "REQ-MODULE-002"]}
129
#define JUNO_MODULE_ROOT(API_T, ...) \
130
{ \
131
const API_T *ptApi; \
132
JUNO_FAILURE_HANDLER_T JUNO_FAILURE_HANDLER; \
133
JUNO_USER_DATA_T *JUNO_FAILURE_USER_DATA; \
134
__VA_ARGS__ \
135
}
136
145
#define JUNO_TRAIT_ROOT(API_T, ...) \
146
{ \
147
const API_T *ptApi; \
148
__VA_ARGS__ \
149
}
150
160
// @{"req": ["REQ-MODULE-003"]}
161
#define JUNO_MODULE_DERIVE(ROOT_T, ...) \
162
{ \
163
ROOT_T JUNO_MODULE_SUPER; \
164
__VA_ARGS__ \
165
}
166
170
#define JUNO_TRAIT_DERIVE(ROOT_T, ...) JUNO_MODULE_DERIVE(ROOT_T, __VA_ARGS__)
171
184
#define JUNO_MODULE_GET_API(ptModule, ROOT_T) ((const ROOT_T *)ptModule)->ptApi
185
186
197
// @{"req": ["REQ-MODULE-005"]}
198
#define JUNO_MODULE_RESULT(NAME_T, OK_T) \
199
typedef struct NAME_T \
200
{ \
201
JUNO_STATUS_T tStatus; \
202
OK_T tOk; \
203
} NAME_T
204
209
#define JUNO_OK(result) result.tOk
220
#define JUNO_ASSERT_OK(result, ...) JUNO_ASSERT_SUCCESS(result.tStatus, __VA_ARGS__)
225
#define JUNO_OK_RESULT(value) {JUNO_STATUS_SUCCESS, value}
230
#define JUNO_ERR_RESULT(err, value) {err, value}
241
// @{"req": ["REQ-MODULE-006"]}
242
#define JUNO_MODULE_OPTION(NAME_T, SOME_T) \
243
typedef struct NAME_T \
244
{ \
245
bool bIsSome; \
246
SOME_T tSome; \
247
} NAME_T
248
253
#define JUNO_SOME(result) result.tSome
264
#define JUNO_ASSERT_SOME(result, ...) if(!result.bIsSome){ \
265
__VA_ARGS__ \
266
}
271
#define JUNO_SOME_OPTION(value) {true, value}
276
#define JUNO_NONE_OPTION(default_value) {false, default_value}
277
278
#endif
// JUNO_MODULE_H
status.h
Status codes and failure-handling helpers for LibJuno.
include
juno
module.h
Generated by
1.9.8