rllib
1
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
lib
rlstate.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
rlstate.cpp - description
3
-------------------
4
begin : Sat Dec 29 2012
5
copyright : (C) 2012 by R. Lehrig
6
email : lehrig@t-online.de
7
***************************************************************************/
8
9
/***************************************************************************
10
* *
11
* This library is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as *
13
* published by the Free Software Foundation *
14
* *
15
***************************************************************************/
16
#include "
rlstate.h
"
17
18
rlState::rlState
()
19
{
20
user
= NULL;
21
stepCounter
= -1;
22
cycletime
= 1000;
23
nextStep
= NULL;
24
lastState
= NULL;
25
}
26
27
rlState::~rlState
()
28
{
29
}
30
31
void
rlState::gotoState
(
void
(*funcPtr)(
rlState
*sm) )
32
{
33
stepCounter
= -1;
34
lastState
=
nextStep
;
35
nextStep
= funcPtr;
36
}
37
38
int
rlState::runSteps
(
int
_cycletime)
39
{
40
cycletime
= _cycletime;
41
lastState
= NULL;;
42
stepCounter
= 0;
43
44
while
(
nextStep
!= NULL)
45
{
46
(*nextStep)(
this
);
47
rlsleep
(
cycletime
);
48
stepCounter
++;
49
if
(
stepCounter
>
MAX_STEP
)
stepCounter
= 1;
50
}
51
52
return
0;
53
}
54
55
static
void
*
stepsThread
(
void
*arg)
56
{
57
THREAD_PARAM
*tp = (
THREAD_PARAM
*) arg;
58
rlState
*st = (
rlState
*) tp->
user
;
59
int
cycletime = st->
cycletime
;
60
st->
runSteps
(cycletime);
61
return
arg;
62
}
63
64
int
rlState::startSteps
(
int
_cycletime)
65
{
66
if
(
cycletime
< 0)
return
0;
67
cycletime
= _cycletime;
68
thread
.
create
(
stepsThread
,
this
);
69
return
0;
70
}
71
Generated by
1.8.2