Using a typedef on the structure tag allows for having the structure reference itself.
In this case, the callback that is part of the structure accepts its own structure as one of the callback parameters.
I previously did not know that I could do this and opted to use a void pointer to provide this.
With this approach I get more safety, integrity, and less memory usage (for not having to add a variable that is a cast of the void pointer to the f_state_t).
* This allows for the error to be processed with all relevant data before the function returns.
*
* These two callbacks (handle() and interrupt()) accept the following parameters:
- * - state: The state data. Must be of type f_state_t. Must not be NULL.
+ * - state: The state data. Must not be NULL.
* - internal: Additional data passed by the function being called, often containing internal data to the called function. May be NULL.
*
* The "custom" property on f_state_t is intended to be used so that the callback, such as the interrupt(), can make changes to something within the scope of the parent.
* - data: A structure (defined by function) for holding data relevant to the function. May be NULL. May be required.
*/
#ifndef _di_f_state_t_
- typedef struct {
+ typedef struct f_state_t_ f_state_t;
+ struct f_state_t_ {
uint16_t step_large;
uint16_t step_small;
f_status_t status;
uint64_t flag;
uint64_t code;
- void (*handle)(void * const state, void * const internal);
- void (*interrupt)(void * const state, void * const internal);
+ void (*handle)(f_state_t * const state, void * const internal);
+ void (*interrupt)(f_state_t * const state, void * const internal);
void *callbacks;
void *custom;
void *data;
- } f_state_t;
+ };
#define f_state_t_initialize { \
F_memory_default_allocation_large_d, \
#endif // _di_fll_program_standard_signal_received_
#ifndef _di_fll_program_standard_signal_handle_
- void fll_program_standard_signal_handle(void * const void_state, void * const internal) {
+ void fll_program_standard_signal_handle(f_state_t * const state, void * const internal) {
#ifndef _di_level_2_parameter_checking_
- if (!void_state) return;
+ if (!state) return;
#endif // _di_level_2_parameter_checking_
- f_state_t * const state = (f_state_t *) void_state;
-
if (!state->custom) {
state->status = F_interrupt_not;
* @see fll_program_standard_signal_received()
*/
#ifndef _di_fll_program_standard_signal_handle_
- extern void fll_program_standard_signal_handle(void * const state, void * const internal);
+ extern void fll_program_standard_signal_handle(f_state_t * const state, void * const internal);
#endif // _di_fll_program_standard_signal_handle_
#ifdef __cplusplus
#endif // _di_controller_thread_signal_
#ifndef _di_controller_thread_signal_state_fss_
- f_status_t controller_thread_signal_state_fss(void * const state, void * const internal) {
+ f_status_t controller_thread_signal_state_fss(f_state_t * const state, void * const internal) {
- if (!state) {
+ if (!state || !state->custom) {
return F_interrupt_not;
}
- f_state_t *state_ptr = (f_state_t *) state;
-
- if (!state_ptr->custom) {
- return F_interrupt_not;
- }
-
- controller_state_interrupt_t *custom = (controller_state_interrupt_t *) state_ptr->custom;
+ controller_state_interrupt_t *custom = (controller_state_interrupt_t *) state->custom;
controller_thread_t *thread = custom->thread;
if (!controller_thread_is_enabled(custom->is_normal, thread)) {
#ifndef _di_controller_thread_signal_state_iki_
f_status_t controller_thread_signal_state_iki(void * const state, void * const internal) {
- if (!state) {
- return F_interrupt_not;
- }
-
- f_state_t *state_ptr = (f_state_t *) state;
-
- if (!state_ptr->custom) {
+ if (!state || !state->custom) {
return F_interrupt_not;
}
- controller_state_interrupt_t *custom = (controller_state_interrupt_t *) state_ptr->custom;
+ controller_state_interrupt_t *custom = (controller_state_interrupt_t *) state->custom;
controller_thread_t *thread = custom->thread;
if (!controller_thread_is_enabled(custom->is_normal, thread)) {
#endif // !defined(_di_fake_signal_handler_) && !defined(_di_thread_support_)
#ifndef _di_fake_signal_handler_callback_
- void fake_signal_handler_callback(void * const void_state, void * const void_internal) {
+ void fake_signal_handler_callback(f_state_t * const state, void * const void_internal) {
- if (!void_state) return;
-
- f_state_t * const state = (f_state_t *) void_state;
+ if (!state) return;
if (!state->custom) {
state->status = F_interrupt_not;
* Not used.
*/
#ifndef _di_fake_signal_handler_callback_
- extern void fake_signal_handler_callback(void * const state, void * const internal);
+ extern void fake_signal_handler_callback(f_state_t * const state, void * const internal);
#endif // _di_fake_signal_handler_callback_
#ifdef __cplusplus