rllib  1
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 
19 {
20  user = NULL;
21  stepCounter = -1;
22  cycletime = 1000;
23  nextStep = NULL;
24  lastState = NULL;
25 }
26 
28 {
29 }
30 
31 void rlState::gotoState( void (*funcPtr)(rlState *sm) )
32 {
33  stepCounter = -1;
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);
48  stepCounter++;
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;
69  return 0;
70 }
71 
~rlState()
Definition: rlstate.cpp:27
void * user
Definition: rlthread.h:30
int create(void *(*func)(void *), void *argument)
Definition: rlthread.cpp:35
rlState()
Definition: rlstate.cpp:18
void * user
Definition: rlstate.h:264
int cycletime
Definition: rlstate.h:266
void(* lastState)(rlState *sm)
Definition: rlstate.h:269
void rlsleep(long msec)
Definition: rlwthread.cpp:396
void gotoState(void(*funcPtr)(rlState *sm))
Definition: rlstate.cpp:31
rlThread thread
Definition: rlstate.h:270
static void * stepsThread(void *arg)
Definition: rlstate.cpp:55
int stepCounter
Definition: rlstate.h:265
int startSteps(int cycletime)
Definition: rlstate.cpp:64
int runSteps(int cycletime)
Definition: rlstate.cpp:38
static const long MAX_STEP
Definition: rlstate.h:267
void(* nextStep)(rlState *sm)
Definition: rlstate.h:268