LibJuno 0.42.0
LibJuno is a lightweight C99 library designed specifically for embedded systems.
|
Go to the source code of this file.
Macros | |
The name of the module type | |
DOC OverviewLibJuno implements dependency injection through modules and API traits. This is very similar to the Rust paradigm. There are 3 components to modules within LibJuno: The module The module root The module derivations The Module RootBefore talking about the module itself we need to go over the module root. The module root is a common set of member variables shared across all module derivations and implementations. When a module is derived there is a compile-time gurantee that the module can be safely up-cast to the module root. All derivations of the module can up-cast to the module root. The module root always provides the following as defined by the macros: Implementing a Module: DerivationsConcrete implementations for a module are created through deriving the module. A derivation is guranteed to have the module root as the the first member. Module derivations can always be safely up-cast to the module root. The module derivations can contain implementation specific details, dependencies, and other private memebers. You can think of the members placed within the derivation as "private" in C++ terms The ModuleNow with a background on the module root and module derivations, we can talk about the module. The module is a union of all possible derivations, including the root. The module is forward-declared. Module implementations will provide a default implementation of the module that can be overridden when How to Define The Module UnionBelow is an example of defining a module union: union MY_MODULE_T JUNO_MODULE(MY_MODULE_API_T, MY_MODULE_ROOT_T,
MY_MODULE_DERIVATION_1_T;
MY_MODULE_DERIVATION_2_T;
MY_MODULE_DERIVATION_3_T;
);
Declare a juno module implemented as a union | |
#define | JUNO_MODULE_DECLARE(NAME_T) typedef union NAME_T NAME_T |
#define | JUNO_MODULE_ROOT_DECLARE(NAME_T) typedef struct NAME_T NAME_T |
#define | JUNO_MODULE_DERIVE_DECLARE(NAME_T) JUNO_MODULE_ROOT_DECLARE(NAME_T) |
#define | JUNO_FAILURE_HANDLER _pfcnFailureHandler |
#define | JUNO_FAILURE_USER_DATA _pvFailureUserData |
#define | JUNO_MODULE_EMPTY |
#define | JUNO_MODULE_ARG(...) __VA_ARGS__ |
#define | JUNO_MODULE_SUPER tRoot |
#define | JUNO_MODULE(API_T, ROOT_T, ...) |
#define | JUNO_MODULE_ROOT(API_T, ...) |
#define | JUNO_MODULE_DERIVE(ROOT_T, ...) |
#define | JUNO_MODULE_GET_API(ptModule, ROOT_T) ((const ROOT_T *)ptModule)->ptApi |
#define | JUNO_MODULE_RESULT(NAME_T, SUCCESS_T) |
Defines a result type combining a status and a success payload. | |
#define | JUNO_RESULT(SUCCESS_T) |
#define | JUNO_MODULE_OPTION(NAME_T, SOME_T) |
Defines an option type combining a flag to indicate some and a success payload. | |
#define | JUNO_OPTION(SOME_T) |
#define JUNO_FAILURE_HANDLER _pfcnFailureHandler |
Alias for the failure handler for a module
#define JUNO_FAILURE_USER_DATA _pvFailureUserData |
Alias for the failure handler user data for a module
#define JUNO_MODULE | ( | API_T, | |
ROOT_T, | |||
... | |||
) |
Define a juno module. This needs to be done in the composition root. This is where users define all possible module implementations for a module.
Example:
name | The name of the module as declared |
API | The name of the API type for the module |
root | The name of the root implementation type for the module as declared |
derived | The derived modules seperated by ; |
#define JUNO_MODULE_ARG | ( | ... | ) | __VA_ARGS__ |
A macro to provide template types as arguments to Juno module macros
#define JUNO_MODULE_DECLARE | ( | NAME_T | ) | typedef union NAME_T NAME_T |
#define JUNO_MODULE_DERIVE | ( | ROOT_T, | |
... | |||
) |
Implement a derivation of a module Example:
name | The name of the module derivation as declared |
root | The name of the root implementation for the module as declared |
members | The member components of the module derivation |
#define JUNO_MODULE_DERIVE_DECLARE | ( | NAME_T | ) | JUNO_MODULE_ROOT_DECLARE(NAME_T) |
Declare a derivation of a juno module implemented as a struct
name | The name of the derived module type |
#define JUNO_MODULE_EMPTY |
Empty macro that indicates a module implementation has no additional members
#define JUNO_MODULE_GET_API | ( | ptModule, | |
ROOT_T | |||
) | ((const ROOT_T *)ptModule)->ptApi |
Get the API pointer from the module
ptModule | The module pointer |
MODULE_ROOT_NAME | The root type of the module |
#define JUNO_MODULE_OPTION | ( | NAME_T, | |
SOME_T | |||
) |
Defines an option type combining a flag to indicate some and a success payload.
NAME_T | Name of the result struct to define. |
SUCCESS_T | Type of the success payload contained in the result. |
#define JUNO_MODULE_RESULT | ( | NAME_T, | |
SUCCESS_T | |||
) |
Defines a result type combining a status and a success payload.
NAME_T | Name of the result struct to define. |
SUCCESS_T | Type of the success payload contained in the result. |
#define JUNO_MODULE_ROOT | ( | API_T, | |
... | |||
) |
Implement a root for a module Example:
name | The name of the module root implementation as declared |
API | The API type for the module |
members | The member components of the module root implementation |
#define JUNO_MODULE_ROOT_DECLARE | ( | NAME_T | ) | typedef struct NAME_T NAME_T |
Declare a root implementation for the module implemented as a struct
name | The name of the root implementation type |
#define JUNO_MODULE_SUPER tRoot |
Alias for the module root implementation. All modules can call .tRoot
to access the module root.
#define JUNO_OPTION | ( | SOME_T | ) |
#define JUNO_RESULT | ( | SUCCESS_T | ) |