#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>
#include <sys/time.h>
#include <errno.h>
#include "fsm_common_events.h"
Go to the source code of this file.
Classes | |
struct | robo_fsm |
Structure describing FSM. More... | |
Defines | |
#define | EV_NOEVENT __COMMON_EV_NOEVENT |
#define | EV_INIT __COMMON_EV_INIT |
#define | EV_EXIT __COMMON_EV_EXIT |
#define | EV_STATE_ENTERED __COMMON_EV_STATE_ENTERED |
#define | EV_RETURN __COMMON_EV_RETURN |
#define | EV_TIMEOUT __COMMON_EV_TIMEOUT |
#define | EV_TIMER __COMMON_EV_TIMER |
#define | FSM_SIGNAL(fsm_id, event) __fsm_signal(FSM_GET_BY_ID(fsm_id), __##fsm_id##_##event) |
Sends an event to another automaton (FSM), running in another thread. | |
#define | DBG_STATE() DBG_FSM_STATE(__FUNCTION__) |
#define | DBG_FSM_STATE(name) do { if (fsm->debug_states) DBG("fsm %s: %s(%s)\n", fsm->debug_name, name, fsm_event_str(fsm->event)); } while(0) |
#define | DBG_PRINT_EVENT(msg) DBG("%s: event: %s\n", msg, fsm_event_str(fsm->event)) |
Prints current event in a human readable form. | |
#define | FSM_STATE(name) |
Defines a state function for finite state machine. | |
#define | FSM_STATE_DECL(name) int fsm_state_##name(struct robo_fsm *fsm) |
Declares a prototype of state function defined later. | |
#define | FSM_TIMEOUT(ms) __fsm_timespec_add_ms(&fsm->timeout, &fsm->now, (ms)) |
Sets FSM's timeout. | |
#define | FSM_TIMER(ms) __fsm_timespec_add_ms(&fsm->timer, &fsm->now, (ms)) |
Sets FSM's one-shot timer. | |
#define | FSM_TIMER_STOP() __fsm_timespec_invalidate(&fsm->timer) |
Stops the timer. | |
#define | __FSM_EVENT_ENUM enum fsm_common_events |
#define | FSM_EVENT ((__FSM_EVENT_ENUM)(fsm->event)) |
Value of current event in state functions. | |
#define | FSM_TRANSITION(next) |
Sets current state to next . | |
#define | SUBFSM_TRANSITION(substate) |
Invoke state transition to sub-FSM. | |
#define | SUBFSM_RET() |
Return from sub-FSM. | |
Return codes of state functions | |
#define | RC_WAIT 0 |
After return, FSM thread starts waiting for the new event. | |
#define | RC_PROC 1 |
After return, current state function (fnc_act) will be immediately called again. | |
Typedefs | |
typedef int | fsm_event |
Type for FSM events. | |
Functions | |
void | fsm_init (struct robo_fsm *fsm, char *debug_name) |
FSM initialization. | |
int | fsm_start (struct robo_fsm *fsm, pthread_attr_t *attr) |
Starts previously initialized FSM. | |
int | fsm_destroy (struct robo_fsm *fsm) |
Deallocates all resources allocated by fsm_init(). | |
void | __fsm_timespec_add_ms (struct timespec *ts, struct timespec *now, long ms) |
Set timespec to some time from now. | |
void | __fsm_timespec_invalidate (struct timespec *ts) |
int | fsm_nop_state (struct robo_fsm *fsm) |
Non operative state, do nothing. | |
const char * | fsm_event_str (fsm_event ev) |
Returns string with the name of event submitted as parameter. | |
const char * | fsm_common_event_str (enum fsm_common_events ev) |
static void | __fsm_signal (struct robo_fsm *fsm, fsm_event event) |
Definition in file fsm.h.
#define RC_PROC 1 |
After return, current state function (fnc_act) will be immediately called again.
Used by FSM_TRANSITION().
#define RC_WAIT 0 |
After return, FSM thread starts waiting for the new event.
Definition at line 230 of file fsm.h.
Referenced by fsm_nop_state(), and handle_event().
void __fsm_timespec_add_ms | ( | struct timespec * | ts, | |
struct timespec * | now, | |||
long | ms | |||
) |
Set timespec to some time from now.
[out] | ts | Result |
[in] | now | Actual time or NULL. If NULL, actual time is determined by calling gettimeofday(). |
[in] | ms | number of milliseconds to be set |
Definition at line 55 of file fsm.c.
References gettimeofday_ts().