LibJuno 0.42.0
LibJuno is a lightweight C99 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 "status.h"
21#include <stdint.h>
22
102#define JUNO_MODULE_DECLARE(NAME_T) typedef union NAME_T NAME_T
107#define JUNO_MODULE_ROOT_DECLARE(NAME_T) typedef struct NAME_T NAME_T
112#define JUNO_MODULE_DERIVE_DECLARE(NAME_T) JUNO_MODULE_ROOT_DECLARE(NAME_T)
113
117#define JUNO_FAILURE_HANDLER _pfcnFailureHandler
121#define JUNO_FAILURE_USER_DATA _pvFailureUserData
126#define JUNO_MODULE_EMPTY
127
132#define JUNO_MODULE_ARG(...) __VA_ARGS__
133
139#define JUNO_MODULE_SUPER tRoot
140
161#define JUNO_MODULE(API_T, ROOT_T, ...) \
162{ \
163 const API_T *ptApi; \
164 ROOT_T JUNO_MODULE_SUPER; \
165 __VA_ARGS__ \
166}
167
182#define JUNO_MODULE_ROOT(API_T, ...) \
183{ \
184 const API_T *ptApi; \
185 __VA_ARGS__ \
186 JUNO_FAILURE_HANDLER_T JUNO_FAILURE_HANDLER; \
187 JUNO_USER_DATA_T *JUNO_FAILURE_USER_DATA; \
188}
189
203#define JUNO_MODULE_DERIVE(ROOT_T, ...) \
204{ \
205 ROOT_T JUNO_MODULE_SUPER; \
206 __VA_ARGS__ \
207}
208
214#define JUNO_MODULE_GET_API(ptModule, ROOT_T) ((const ROOT_T *)ptModule)->ptApi
215
216
223#define JUNO_MODULE_RESULT(NAME_T, SUCCESS_T) \
224typedef struct NAME_T \
225{ \
226 JUNO_STATUS_T tStatus; \
227 SUCCESS_T tSuccess; \
228} NAME_T
229
230#define JUNO_RESULT(SUCCESS_T) \
231{ \
232 JUNO_STATUS_T tStatus; \
233 SUCCESS_T tSuccess; \
234}
235
242#define JUNO_MODULE_OPTION(NAME_T, SOME_T) \
243typedef struct NAME_T \
244{ \
245 bool bIsSome; \
246 SOME_T tSome; \
247} NAME_T
248
249#define JUNO_OPTION(SOME_T) \
250{ \
251 bool bIsSome; \
252 SOME_T tSome; \
253}
254
255#endif // JUNO_MODULE_H