State machine
Main Page
Modules
Classes
Files
Examples
File List
File Members
All
Classes
Files
Functions
Variables
Enumerations
Enumerator
Groups
src
stateMachine.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2013 Andreas Misje
3
*
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice shall be included in
12
* all copies or substantial portions of the Software.
13
*
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
* DEALINGS IN THE SOFTWARE.
21
*/
22
67
#ifndef STATEMACHINE_H
68
#define STATEMACHINE_H
69
70
#include <stddef.h>
71
#include <stdbool.h>
72
83
struct
event
84
{
86
int
type
;
94
void
*
data
;
95
};
96
97
struct
state
;
98
154
struct
transition
155
{
157
int
eventType
;
166
void
*
condition
;
181
bool ( *
guard
)(
void
*
condition
,
struct
event
*
event
);
194
void ( *
action
)(
void
*currentStateData,
struct
event
*
event
,
195
void
*newStateData );
203
struct
state
*
nextState
;
204
};
205
287
struct
state
288
{
292
struct
state
*
parentState
;
297
struct
state
*
entryState
;
301
struct
transition
*
transitions
;
305
size_t
numTransitions
;
310
void
*
data
;
324
void ( *
entryAction
)(
void
*stateData,
struct
event
*
event
);
335
void ( *
exitAction
)(
void
*stateData,
struct
event
*
event
);
336
};
337
343
struct
stateMachine
344
{
346
struct
state
*
currentState
;
353
struct
state
*
previousState
;
361
struct
state
*
errorState
;
362
};
363
385
void
stateM_init
(
struct
stateMachine
*
stateMachine
,
386
struct
state
*initialState,
struct
state
*errorState );
387
391
enum
stateM_handleEventRetVals
392
{
394
stateM_errArg
= -2,
407
stateM_errorStateReached
,
409
stateM_stateChanged
,
417
stateM_stateLoopSelf
,
424
stateM_noStateChange
,
426
stateM_finalStateReached
,
427
};
428
448
int
stateM_handleEvent
(
struct
stateMachine
*
stateMachine
,
449
struct
event
*
event
);
450
459
struct
state
*
stateM_currentState
(
struct
stateMachine
*
stateMachine
);
460
470
struct
state
*
stateM_previousState
(
struct
stateMachine
*
stateMachine
);
471
481
bool
stateM_stopped
(
struct
stateMachine
*
stateMachine
);
482
483
#endif // STATEMACHINE_H
484
Generated on Wed Jul 17 2013 14:01:32 for State machine by
1.8.1.2