|
coan 4.2.4
|
|
Files | |
| file | state_utils.c |
| file | state_utils.h |
Functions | |
| void | component_initor (bool is_static, bool is_zero_initable, void **state, void **public_state, void const *initialiser, size_t size, void(*user_init)()) |
| void | component_finitor (bool is_static, void **state, void **public_state, void(*user_finis)()) |
| #define | STATE_ALLOCATOR (malloc) |
| #define | STATE(component) component##_state |
| #define | PUBLIC_STATE(component) component##_public_state |
| #define | HANDLE(component) component##_h |
| #define | PUBLIC_HANDLE(component) component##_public_h |
| #define | USER_INIT(component) component##_init |
| #define | USER_FINIS(component) component##_finis |
| #define | USER_INIT_HANDLE(component) component##_init_h |
| #define | USER_FINIS_HANDLE(component) component##_finis_h |
| #define | INITOR(component) component##_initor |
| #define | FINITOR(component) component##_finitor |
| #define | STATIC_INITIALISER(component) component##_static_initialiser |
| #define | STATIC_INITIALISER_HANDLE(component) component##_static_initialiser_h |
| #define | STORAGE_TYPE_TAG(component) component##_storage_type |
| #define | INITIALISATION_TYPE_TAG(component) component##_initialisation_type |
| #define | DECL_USER_INIT(component) void USER_INIT(component)(STATE_T(component) *) |
| #define | DECL_USER_FINIS(component) void USER_FINIS(component)(STATE_T(component) *) |
| #define | DECL_USER_INIT_HANDLE(component) void (*USER_INIT_HANDLE(component))(STATE_T(component) *) |
| #define | DECL_USER_FINIS_HANDLE(component) void (*USER_FINIS_HANDLE(component))(STATE_T(component) *) |
| #define | DECL_INITOR(component) void INITOR(component)(void) |
| #define | DECL_FINITOR(component) void FINITOR(component)(void) |
| #define | DECL_STATIC_INITIALISER(component) static const STATE_T(component) STATIC_INITIALISER(component) |
| #define | DECL_STATIC_INITIALISER_HANDLE(component) static const STATE_T(component) * const STATIC_INITIALISER_HANDLE(component) |
| #define | SELECT_STATIC(component) enum component##_storage_type { STORAGE_TYPE_TAG(component) = STATE_STATIC } |
| #define | SELECT_DYNAMIC(component) enum component##_storage_type { STORAGE_TYPE_TAG(component) = STATE_DYNAMIC } |
| #define | SELECT_INITIALISATION_TYPE(component, init_type) enum component##_init_type { INITIALISATION_TYPE_TAG(component) = init_type } |
| #define | SELECT_ZERO_INITABLE(component) SELECT_INITIALISATION_TYPE(component,ZERO_INITABLE) |
| #define | SELECT_STATIC_INITABLE(component) SELECT_INITIALISATION_TYPE(component,STATIC_INITABLE) |
| #define | SELECT_USER_INITABLE(component) SELECT_INITIALISATION_TYPE(component,USER_INITABLE) |
| #define | IS_STATIC(component) (STORAGE_TYPE_TAG(component) == (int)STATE_STATIC) |
| #define | IS_ZERO_INITABLE(component) (INITIALISATION_TYPE_TAG(component) == (int)ZERO_INITABLE) |
| #define | HAS_STATIC_INITIALISER(component) (INITIALISATION_TYPE_TAG(component) == STATIC_INITABLE) |
| #define | HAS_USER_INIT(component) (INITIALISATION_TYPE_TAG(component) == (int)USER_INITABLE) |
| #define | DECL_DYNAMIC_STATE(component) |
| #define | DECL_STATIC_STATE(component) |
| #define | IMPORT_INITOR(component) extern DECL_INITOR(component) |
| #define | IMPORT_FINITOR(component) extern DECL_FINITOR(component) |
| #define | IMPORT_STATE(component) extern PUBLIC_STATE_T(component) * PUBLIC_HANDLE(component) |
| #define | GET_STATE_BY_HANDLE(component, field) (assert(true),HANDLE(component)->field) |
| #define | SET_STATE_BY_HANDLE(component, field) (HANDLE(component)->field) |
| #define | GET_STATIC_STATE(component, field) (assert(true),STATE(component).field) |
| #define | SET_STATIC_STATE(component, field) (STATE(component).field) |
| #define | DEFINE_INITOR(component) |
| #define | DEFINE_FINITOR(component) |
infrastructure.
| #define DECL_DYNAMIC_STATE | ( | component | ) |
STATE_T(component) * HANDLE(component) = NULL;\ PUBLIC_STATE_T(component) * PUBLIC_HANDLE(component) = NULL
Declare handles to component's global and public state when state is in dynamic storage
Definition at line 143 of file state_utils.h.
| #define DECL_FINITOR | ( | component | ) | void FINITOR(component)(void) |
Declare generated component finalising function
Definition at line 105 of file state_utils.h.
| #define DECL_INITOR | ( | component | ) | void INITOR(component)(void) |
Declare generated component initialising function
Definition at line 103 of file state_utils.h.
| #define DECL_STATIC_INITIALISER | ( | component | ) | static const STATE_T(component) STATIC_INITIALISER(component) |
Declare a static initialiser for the component
Definition at line 107 of file state_utils.h.
| #define DECL_STATIC_INITIALISER_HANDLE | ( | component | ) | static const STATE_T(component) * const STATIC_INITIALISER_HANDLE(component) |
Declare pointer to component const initialiser. Can be null if none
Definition at line 110 of file state_utils.h.
| #define DECL_STATIC_STATE | ( | component | ) |
static STATE_T(component) STATE(component);\ STATE_T(component) * HANDLE(component) = &STATE(component);\ PUBLIC_STATE_T(component) * PUBLIC_HANDLE(component) =\ (PUBLIC_STATE_T(component) *)&STATE(component)
Declare component's state in static storage, with handles to global and public state.
Definition at line 150 of file state_utils.h.
| #define DECL_USER_FINIS | ( | component | ) | void USER_FINIS(component)(STATE_T(component) *) |
Declare user-defined component finalising function
Definition at line 94 of file state_utils.h.
| #define DECL_USER_FINIS_HANDLE | ( | component | ) | void (*USER_FINIS_HANDLE(component))(STATE_T(component) *) |
Declare pointer to user-defined finalising function
Definition at line 100 of file state_utils.h.
| #define DECL_USER_INIT | ( | component | ) | void USER_INIT(component)(STATE_T(component) *) |
Declare user-defined component initialising function
Definition at line 91 of file state_utils.h.
| #define DECL_USER_INIT_HANDLE | ( | component | ) | void (*USER_INIT_HANDLE(component))(STATE_T(component) *) |
Declare pointer to user-defined component initialising function
Definition at line 97 of file state_utils.h.
| #define DEFINE_FINITOR | ( | component | ) |
DECL_FINITOR(component) {\ component_finitor(\ IS_STATIC(component),\ (void **)(char *)&HANDLE(component),\ (void **)(char *)&PUBLIC_HANDLE(component),\ USER_INIT_HANDLE(component));\ }
Define the generated component finalisation function FINITOR(component)
Definition at line 200 of file state_utils.h.
| #define DEFINE_INITOR | ( | component | ) |
DECL_INITOR(component) {\ component_initor(\ IS_STATIC(component),\ IS_ZERO_INITABLE(component),\ (void **)(char *)&HANDLE(component),\ (void **)(char *)&PUBLIC_HANDLE(component),\ STATIC_INITIALISER_HANDLE(component),\ sizeof(STATE_T(component)),\ USER_INIT_HANDLE(component));\ }
Define the generated component initialisation function INITOR(component)
Definition at line 187 of file state_utils.h.
| #define FINITOR | ( | component | ) | component##_finitor |
Generated name for component finalising function
Definition at line 81 of file state_utils.h.
| #define GET_STATE_BY_HANDLE | ( | component, | |
| field | |||
| ) | (assert(true),HANDLE(component)->field) |
Get the value of a field from the component's global state, accessed through the component's handle.
Definition at line 168 of file state_utils.h.
| #define GET_STATIC_STATE | ( | component, | |
| field | |||
| ) | (assert(true),STATE(component).field) |
Get the value of a field from the component's global static state. Quicker than GET_STATE_BY_HANDLE for a statically implemented component.
Definition at line 179 of file state_utils.h.
| #define HANDLE | ( | component | ) | component##_h |
Generated name for pointer to component global state instance
Definition at line 67 of file state_utils.h.
Referenced by fs_open_dir().
| #define HAS_STATIC_INITIALISER | ( | component | ) | (INITIALISATION_TYPE_TAG(component) == STATIC_INITABLE) |
Has component a static initialiser?
Definition at line 136 of file state_utils.h.
| #define HAS_USER_INIT | ( | component | ) | (INITIALISATION_TYPE_TAG(component) == (int)USER_INITABLE) |
Has component user-defined initialisation and finalisation?
Definition at line 139 of file state_utils.h.
| #define IMPORT_FINITOR | ( | component | ) | extern DECL_FINITOR(component) |
Extern declaration of generated component finalsing function
Definition at line 159 of file state_utils.h.
| #define IMPORT_INITOR | ( | component | ) | extern DECL_INITOR(component) |
Extern declaration of generated component initialising function
Definition at line 157 of file state_utils.h.
| #define IMPORT_STATE | ( | component | ) | extern PUBLIC_STATE_T(component) * PUBLIC_HANDLE(component) |
Extern declaration of handle to component's public state
Definition at line 162 of file state_utils.h.
| #define INITIALISATION_TYPE_TAG | ( | component | ) | component##_initialisation_type |
enum tag name for component's initialisation type
Definition at line 89 of file state_utils.h.
| #define INITOR | ( | component | ) | component##_initor |
Generated name for component initialising function
Definition at line 79 of file state_utils.h.
| #define IS_STATIC | ( | component | ) | (STORAGE_TYPE_TAG(component) == (int)STATE_STATIC) |
Is component state in static storage ?
Definition at line 131 of file state_utils.h.
| #define IS_ZERO_INITABLE | ( | component | ) | (INITIALISATION_TYPE_TAG(component) == (int)ZERO_INITABLE) |
Is component zero-initialisable?
Definition at line 133 of file state_utils.h.
| #define PUBLIC_HANDLE | ( | component | ) | component##_public_h |
Generated name for pointer to component public state instance
Definition at line 69 of file state_utils.h.
| #define PUBLIC_STATE | ( | component | ) | component##_public_state |
Generated name for component public state instance
Definition at line 65 of file state_utils.h.
| #define SELECT_DYNAMIC | ( | component | ) | enum component##_storage_type { STORAGE_TYPE_TAG(component) = STATE_DYNAMIC } |
Select dynamic storage for component state instance
Definition at line 116 of file state_utils.h.
| #define SELECT_INITIALISATION_TYPE | ( | component, | |
| init_type | |||
| ) | enum component##_init_type { INITIALISATION_TYPE_TAG(component) = init_type } |
Select the component's initialisation type
Definition at line 119 of file state_utils.h.
| #define SELECT_STATIC | ( | component | ) | enum component##_storage_type { STORAGE_TYPE_TAG(component) = STATE_STATIC } |
Select static storage for component state instance
Definition at line 113 of file state_utils.h.
| #define SELECT_STATIC_INITABLE | ( | component | ) | SELECT_INITIALISATION_TYPE(component,STATIC_INITABLE) |
Select static initialisation for the component's state instance
Definition at line 125 of file state_utils.h.
| #define SELECT_USER_INITABLE | ( | component | ) | SELECT_INITIALISATION_TYPE(component,USER_INITABLE) |
Select user-defined initialisation for the component's state instance
Definition at line 128 of file state_utils.h.
| #define SELECT_ZERO_INITABLE | ( | component | ) | SELECT_INITIALISATION_TYPE(component,ZERO_INITABLE) |
Select 0-fill initialisation for component state instance
Definition at line 122 of file state_utils.h.
| #define SET_STATE_BY_HANDLE | ( | component, | |
| field | |||
| ) | (HANDLE(component)->field) |
Reference a field in the component's global state, accessed through the the the component's handle.
Definition at line 174 of file state_utils.h.
| #define SET_STATIC_STATE | ( | component, | |
| field | |||
| ) | (STATE(component).field) |
Reference a field in the component's global static state. Quicker than SET_STATE_BY_HANDLE for a statically implemented mdoule
Definition at line 184 of file state_utils.h.
| #define STATE | ( | component | ) | component##_state |
Generated name for component global state instance
Definition at line 63 of file state_utils.h.
| #define STATE_ALLOCATOR (malloc) |
These items that are imported by state_utils.h to implement the user macros but are inessential to client code.
Define malloc-like function for allocating dynamic state storage
Definition at line 59 of file state_utils.h.
| #define STATIC_INITIALISER | ( | component | ) | component##_static_initialiser |
Generated name for component static initialiser
Definition at line 83 of file state_utils.h.
| #define STATIC_INITIALISER_HANDLE | ( | component | ) | component##_static_initialiser_h |
Generated name for pointer to component static initialiser
Definition at line 85 of file state_utils.h.
| #define STORAGE_TYPE_TAG | ( | component | ) | component##_storage_type |
enum tag name for component storage type, static or dynamic
Definition at line 87 of file state_utils.h.
| #define USER_FINIS | ( | component | ) | component##_finis |
Mandatory name user defined component finaliser
Definition at line 73 of file state_utils.h.
| #define USER_FINIS_HANDLE | ( | component | ) | component##_finis_h |
Mandatory name for pointer to user defined component finaliser
Definition at line 77 of file state_utils.h.
| #define USER_INIT | ( | component | ) | component##_init |
Mandatory name user defined component initialiser
Definition at line 71 of file state_utils.h.
| #define USER_INIT_HANDLE | ( | component | ) | component##_init_h |
Mandatory name for pointer to user defined component initialiser
Definition at line 75 of file state_utils.h.
| void component_finitor | ( | bool | is_static, |
| void ** | state, | ||
| void ** | public_state, | ||
| void(*)() | user_finis | ||
| ) |
Finalise a component's global state
| is_static | Is the component's global state in static storage? |
| state | Pointer to a pointer to the component's global state. |
| public_state | Pointer to a pointer to the component's public state. |
| user_finis | NULL, otherwise a pointer to a user-supplied function to finalise the component's global state. If user_init != NULL, the function asserts that *state != NULL and then calls user_init(*state) |
Otherwise, state is assumed to address the component's global state in static storage.
Then, if is_static is false, the function again asserts that *state != NULL, then calls free(*state), and sets *public_state = *state = NULL
Definition at line 83 of file state_utils.c.
References release().

| void component_initor | ( | bool | is_static, |
| bool | is_zero_initable, | ||
| void ** | state, | ||
| void ** | public_state, | ||
| void const * | initialiser, | ||
| size_t | size, | ||
| void(*)() | user_init | ||
| ) |
Initialise a component's global state
| is_static | Is the component's global state in static storage? |
| is_zero_initable | Is the component's global state zero-initialisable? |
| state | Pointer to a pointer to the component's global state. |
| public_state | Pointer to a pointer to the component's public state. |
| initialiser | NULL, otherwise a pointer to a constant initialiser for the component's global state. |
| size | The size of the component's global state. |
| user_init | NULL, otherwise a pointer to a user-supplied function to initialise the component's global state. If is_static is false, the function asserts that *state == NULL and then assigns to *state a heap block of size bytes. |
Otherwise, state is assumed to address the component's global state in static storage.
Then, if is_zero_initable is true, the component's state is 0-filled.
Otherwise, if initialiser != NULL, the size bytes at initialiser are copied to *state.
Otherwise, the function asserts that user_init != NULL, and then calls user_init(*state)
Definition at line 58 of file state_utils.c.
References zallocate().
