#ifndef cp_fsm_fsm_h #define cp_fsm_fsm_h /* Cesar project {{{ * * Copyright (C) 2008 Spidcom * * <<>> * * }}} */ /** * \file cp/fsm/fsm.h * \brief Control plane finite state machine. * \ingroup cp_fsm * * Some events are posted, other are triggered. Posted events corresponds to * asynchronous events. Their treatment is not strictly ordered. They are * added to the end of the event queue. Triggered events are synchronous. * They should be processed before asynchronous events as they may imply state * changes for which data has been manipulated yet. * * For example, a code can update the sta/mgr to make the station * unassociated. The FSM should reflect this change right now, before any * asynchronous message is handled. */ #include "cp/cp.h" #include "forward.h" #include "inc/events.h" /** * Shortcut to initialise and post an event. * \param ctx control plane context * \param kind one of the possible kinds of event * \param type event type, automatically prefixed with CP_FSM_EVENT_TYPE_ * \param args event creation arguments */ #define cp_fsm_post_new_event(ctx, kind, type, args...) \ cp_fsm_post ((ctx), cp_fsm_event_ ## kind ## _new \ ((ctx), CP_FSM_EVENT_TYPE_ ## type, ## args)) /** * Shortcut to initialise and post an urgent event. * \param ctx control plane context * \param kind one of the possible kinds of event * \param type event type, automatically prefixed with CP_FSM_EVENT_TYPE_ * \param args event creation arguments */ #define cp_fsm_post_urgent_new_event(ctx, kind, type, args...) \ cp_fsm_post_urgent ((ctx), cp_fsm_event_ ## kind ## _new \ ((ctx), CP_FSM_EVENT_TYPE_ ## type, ## args)) /** * Shortcut to initialise and trigger an event. * \param ctx control plane context * \param kind one of the possible kinds of event * \param type event type, automatically prefixed with CP_FSM_EVENT_TYPE_ * \param args event creation arguments */ #define cp_fsm_trigger_new_event(ctx, kind, type, args...) \ cp_fsm_trigger ((ctx), cp_fsm_event_ ## kind ## _new \ ((ctx), CP_FSM_EVENT_TYPE_ ## type, ## args)) BEGIN_DECLS /** * Initialise the FSM. * \param ctx control plane context */ void cp_fsm_init (cp_t *ctx); /** * Uninitialise the FSM, drop any pending event. * \param ctx control plane context */ void cp_fsm_uninit (cp_t *ctx); /** * Process one event from the FSM queue. * \param ctx control plane context */ void cp_fsm_process (cp_t *ctx); /** * Process one urgent event from the FSM queue. * \param ctx control plane context * * Urgent events are not allowed to change FSM states. The counterpart is * that this function can be called during the handling of a normal event. */ void cp_fsm_process_urgent (cp_t *ctx); /** * Add an event in the FSM event queue. * \param ctx control plane context * \param event event to add * * Event reference is transfered to the FSM module. */ void cp_fsm_post (cp_t *ctx, cp_fsm_event_t *event); /** * Insert an event in front of the FSM event queue (after last triggered * event, but before first posted event). * \param ctx control plane context * \param event event to add * * Event reference is transfered to the FSM module. */ void cp_fsm_trigger (cp_t *ctx, cp_fsm_event_t *event); /** * Add an event in the FSM urgent event queue. * \param ctx control plane context * \param event event to add * * Event reference is transfered to the FSM module. */ void cp_fsm_post_urgent (cp_t *ctx, cp_fsm_event_t *event); /** * Select a branch during a transition. * \param ctx control plane context * \param branch branch to select * * The selected branch must correspond to the current handled transition. */ void cp_fsm_branch_ (cp_t *ctx, cp_fsm_branch_t branch); #define cp_fsm_branch(ctx, state, event, branch) \ cp_fsm_branch_ ((ctx), CP_FSM_BRANCH (state, event, branch)) END_DECLS #endif /* cp_fsm_fsm_h */