<commit_before>/**
@file state.h
@brief Definitions, data structues and prototypes for state machine handling
@author <NAME>
*/

#ifndef STATE_H
#define STATE_H

#include "config.h"

/** @brief function pointer to a state function that accepts an event variable*/
typedef void (*State)(uint8_t);

/** @brief List of default events*/
#define DEFAULT_EVENTS IDLE=0,ENTER=1,EXIT=2

/** @brief A transition which holds a current state, an event, and the state
that will be entered upon receiving that event*/
typedef struct
{
    State   current_state;  /**< the current state function pointer */
    uint8_t event_code;     /**< the event that triggers a transition */
    State   next_state;     /**< the state that follows the transition */
} Transition;

/** @brief A structure that contains all information about a given state machine */
typedef struct
{
    uint8_t event_queue[MAX_EVENT_CNT]; /**< The event queue array to be malloced in init */
    uint8_t start;                  /**< Start of the circular buffer */
    uint8_t event_cnt;              /**< Number of events in the buffer */
    Transition* transitions;        /**< Pointer to transition table */
    uint8_t transition_table_size;  /**< Size of transition table */
    uint8_t transition_event;       /**< Current transition event in the state machine */
    State state;                    /**< Current state of the state machine */
} StateMachine;

/**
@brief State machine initialization
@details
Initializes the state machine by saving a pointer to the transition rules,
saving the size (so we can loop through it looking for state changes) and
initially publishes and ENTER event so the first state can initialize whatever
it needs.
@param[in] rules Pointer to state transitions rules table
@param[in] t_size The size of the transition rules table (not accounting for Transition struct size)
@param[in] state The initial state of the state machine
@param[in] event_cnt_max The max number of events in the event queue
@return A pointer to the state machine struct
*/
extern StateMachine StateMachineCreate(Transition* rules, uint8_t t_size, State state);

/**
@brief Queue a new event
@details
Pushes a new event in to the event queue and adjust the size.
@param[in] s A pointer to state machine to publish to
@param[in] event The event to enqueue.
@return SUCCESS if event was queued, FAILURE otherwise
*/
extern int8_t StateMachinePublishEvent(StateMachine* s, uint8_t event);

/**
@brief Run the state machine
@details
Checks the event queue for new events, processes the current state and modifies
the state based on state transitions.
@param[in] s A pointer to the state machine to run
*/
extern void StateMachineRun(StateMachine* s);<commit_msg>Remove incorrect documentation.<commit_after>/**
@file state.h
@brief Definitions, data structues and prototypes for state machine handling
@author <NAME>
*/

#ifndef STATE_H
#define STATE_H

#include "config.h"

/** @brief function pointer to a state function that accepts an event variable*/
typedef void (*State)(uint8_t);

/** @brief List of default events*/
#define DEFAULT_EVENTS IDLE=0,ENTER=1,EXIT=2

/** @brief A transition which holds a current state, an event, and the state
that will be entered upon receiving that event*/
typedef struct
{
    State   current_state;  /**< the current state function pointer */
    uint8_t event_code;     /**< the event that triggers a transition */
    State   next_state;     /**< the state that follows the transition */
} Transition;

/** @brief A structure that contains all information about a given state machine */
typedef struct
{
    uint8_t event_queue[MAX_EVENT_CNT]; /**< The event queue array to be malloced in init */
    uint8_t start;                  /**< Start of the circular buffer */
    uint8_t event_cnt;              /**< Number of events in the buffer */
    Transition* transitions;        /**< Pointer to transition table */
    uint8_t transition_table_size;  /**< Size of transition table */
    uint8_t transition_event;       /**< Current transition event in the state machine */
    State state;                    /**< Current state of the state machine */
} StateMachine;

/**
@brief State machine initialization
@details
Initializes the state machine by saving a pointer to the transition rules,
saving the size (so we can loop through it looking for state changes) and
initially publishes and ENTER event so the first state can initialize whatever
it needs.
@param[in] rules Pointer to state transitions rules table
@param[in] t_size The size of the transition rules table (not accounting for Transition struct size)
@param[in] state The initial state of the state machine
@return A pointer to the state machine struct
*/
extern StateMachine StateMachineCreate(Transition* rules, uint8_t t_size, State state);

/**
@brief Queue a new event
@details
Pushes a new event in to the event queue and adjust the size.
@param[in] s A pointer to state machine to publish to
@param[in] event The event to enqueue.
@return SUCCESS if event was queued, FAILURE otherwise
*/
extern int8_t StateMachinePublishEvent(StateMachine* s, uint8_t event);

/**
@brief Run the state machine
@details
Checks the event queue for new events, processes the current state and modifies
the state based on state transitions.
@param[in] s A pointer to the state machine to run
*/
extern void StateMachineRun(StateMachine* s);
{'fraction_non_alphanumeric': 0.07659574468085106, 'fraction_numerical': 0.004810360777058279, 'mean_word_length': 3.901178603807797, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3990391', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1398, 'n_words': 696}