appkit  1.5.1
RoadNarrows Robotics Application Kit
rnr::StateKb Class Reference

#include <StateKb.h>

Inheritance diagram for rnr::StateKb:
rnr::State

Public Member Functions

 StateKb (int nStateId, const std::string &strStateName="", const std::string &strRefTag="")
 Initialization constructor. More...
 
 StateKb (int nStateId, const std::string &strStateName, const std::string &strRefTag, StateEvent *listStateEvents[])
 List constructor. More...
 
virtual ~StateKb ()
 Destructor.
 
virtual int receiveEvent ()
 Receive next event. More...
 
- Public Member Functions inherited from rnr::State
 State (int nStateId, const std::string &strStateName="", const std::string &strRefTag="")
 Initialization constructor. More...
 
 State (int nStateId, const std::string &strStateName, const std::string &strRefTag, StateEvent *listStateEvents[])
 List constructor. More...
 
virtual ~State ()
 Destructor.
 
int addStateEvents (StateEvent *pStateEvent,...)
 Add a list of state events to this state. More...
 
void addStateEvent (StateEvent *pStateEvent)
 Add state to this state. More...
 
bool deleteStateEvent (int nEventId)
 Delete state event from this state. More...
 
uint_t setTimeOut (uint_t usecTimeOut)
 Set recieve event time out. More...
 
uint_t getTimeOut ()
 Get recieve event time out. More...
 
virtual void queueNextEvent (int nEventId)
 Queue the next event to be "recieved". More...
 
virtual int dispatchEvent (int nPrevStateId, int nEventId)
 Dispatch received event by executing associated action and transitioning to the next state. More...
 
virtual void actionEnterState (int nPrevStateId, int nEventId)
 Execute 'enter state' action. More...
 
virtual void actionExitState (int nNextStateId, int nEventId)
 Execute 'exit state' action. More...
 
virtual int actionDefault (int nPrevStateId, int nEventId)
 Execute 'default' action. More...
 
int getStateId () const
 Get state id. More...
 
std::string getStateName () const
 Get state name. More...
 
std::string getRefTag () const
 Get state reference tag. More...
 
std::string getEventName (int nEventId)
 Get state event name. More...
 
std::string getActionName (int nEventId)
 Get state action name. More...
 
virtual void printState (FILE *fp=stdout, int indent=0)
 Print out state. More...
 
 State (Session &session, int nInitAction=UIActionNone)
 
virtual int getNextAction (Session &session, int nTimeoutMs)
 
virtual int setNextAction (int nAction)
 Set the next input action to process. More...
 
int getCurAction ()
 Get the currently retrieved input action. More...
 
bool hasFatal ()
 Test if state has fatal condition. More...
 
void setFatal ()
 
bool isModified ()
 
void setModifiedState (bool bModified)
 
void maskHardButton (bool bEnDis)
 Enable/disable masking of hard button input. More...
 
virtual bool isHardButtonPushed (Session &session)
 
virtual void prompt (Session &session)
 Prompt user, given the state. More...
 
virtual void setMenuStates (Session &session)
 
virtual void transQuit (Session &session)
 
virtual void transPrev (Session &session)
 

Static Public Attributes

static int ClassObjRefCnt = 0
 object reference count
 
static int OrigInputStatusFlags = 0
 original status flags
 
static struct termios OrigInputTio
 original terminal i/o
 
static const int KbEventError = -2
 input error
 
static const int KbEventEof = -1
 end of file
 
static const int KbEventTimeOut = 256
 time out
 
- Static Public Attributes inherited from rnr::State
static const int StateIdUndef = 0
 undefined state
 
static const int StateIdStart = 1
 start state
 
static const int StateIdPrev = 2
 the previous state
 
static const int StateIdThis = 3
 the current (this) state
 
static const int StateIdTerminate = 4
 terminate state
 
static const int StateIdNumOf = 5
 number of reserved state id's
 

Protected Member Functions

void configInput ()
 Configure stdin input.
 
void restoreInput ()
 Restore stdin original configuration.
 
- Protected Member Functions inherited from rnr::State
void init (int nStateId, const std::string &strStateName="", const std::string &strRefTag="")
 Initialize data. More...
 
virtual std::string getReservedStateName (int nStateId)
 Get the reserved state name. More...
 
virtual void buildInterface (Session &session)
 
virtual void destroyInterface ()
 
virtual void initButtonMenu ()
 

Friends

class StateEvent
 friend
 

Additional Inherited Members

- Public Types inherited from rnr::State
typedef std::map< int, StateEvent * > TransTblMap_T
 transition table type
 
- Protected Attributes inherited from rnr::State
int m_nStateId
 state id
 
std::string m_strStateName
 state name
 
std::string m_strRefTag
 state tag (short id string)
 
TransTblMap_T m_mapTransTbl
 state transition table
 
int m_nQueuedEventId
 queue state event
 
bool m_bHasQueuedEvent
 [no] queued state event
 
uint_t m_usecTimeOut
 receive event time out (useconds)
 
Window * m_pWin
 bound window
 
Menu * m_pMenu
 button menu
 
int m_nInitAction
 initial state input action
 
int m_nCurAction
 current state input action
 
bool m_bFatal
 fatal error
 
bool m_bModified
 state [not] modified
 
bool m_bHardBttnEnable
 enable/disable hard button input
 

Detailed Description

Keyboard state class.

The keyboard state receives non-blocking input from stdin. The events are:

  • KbEventError
  • KbEventEof
  • KbEvnetTimeOut
  • 8-bit ascii code

Definition at line 89 of file StateKb.h.

Constructor & Destructor Documentation

rnr::StateKb::StateKb ( int  nStateId,
const std::string &  strStateName = "",
const std::string &  strRefTag = "" 
)
inline

Initialization constructor.

Parameters
nStateIdState id. Must be state machine unique.
strStateNameState name.
strRefTagState reference id.

Definition at line 110 of file StateKb.h.

References configInput().

112  :
113  State(nStateId, strStateName, strRefTag)
114  {
115  if( ++ClassObjRefCnt == 1 )
116  {
117  configInput();
118  }
119  }
static int ClassObjRefCnt
object reference count
Definition: StateKb.h:92
State(int nStateId, const std::string &strStateName="", const std::string &strRefTag="")
Initialization constructor.
Definition: State.h:180
void configInput()
Configure stdin input.
Definition: StateKb.cxx:170
rnr::StateKb::StateKb ( int  nStateId,
const std::string &  strStateName,
const std::string &  strRefTag,
StateEvent listStateEvents[] 
)
inline

List constructor.

Parameters
nStateIdState id. Must be state machine unique.
strStateNameState name.
strRefTagState reference id.
listStateEventsDeclaration list of allocated state events. NULL terminated.

Definition at line 130 of file StateKb.h.

References configInput().

133  :
134  State(nStateId, strStateName, strRefTag, listStateEvents)
135  {
136  if( ++ClassObjRefCnt == 1 )
137  {
138  configInput();
139  }
140  }
static int ClassObjRefCnt
object reference count
Definition: StateKb.h:92
State(int nStateId, const std::string &strStateName="", const std::string &strRefTag="")
Initialization constructor.
Definition: State.h:180
void configInput()
Configure stdin input.
Definition: StateKb.cxx:170

Member Function Documentation

int StateKb::receiveEvent ( )
virtual

Receive next event.

This Keyboard state class receives keyboard input.

The receive event may set state internal variables used specifically by the state.

Returns
Returns event id.

Reimplemented from rnr::State.

Definition at line 104 of file StateKb.cxx.

References fdset_nowarn().

Referenced by ~StateKb().

105 {
106  byte_t byte;
107  fd_set rset;
108  struct timeval timeout;
109  int fd = fileno(stdin);
110  int nFd;
111  ssize_t n;
112 
113  FD_ZERO(&rset);
114  fdset_nowarn(fd, &rset);
115 
116  // wait for character with timeout
117  if( m_usecTimeOut > 0 )
118  {
119  // load timeout
120  timeout.tv_sec = (time_t)(m_usecTimeOut / 1000000);
121  timeout.tv_usec = (time_t)(m_usecTimeOut % 1000000);
122 
123  nFd = select(fd+1, &rset, NULL, NULL, &timeout);
124  }
125 
126  // block indefinitely for character
127  else
128  {
129  nFd = select(fd+1, &rset, NULL, NULL, NULL);
130  }
131 
132  // system error occurred
133  if( nFd < 0 )
134  {
135  LOGSYSERROR("select(%d,...)", fd);
136  return KbEventError;
137  }
138 
139  // select() timeout occurred
140  else if( nFd == 0 )
141  {
142  LOGDIAG4("select() on read timed out");
143  errno = ETIMEDOUT;
144  return KbEventTimeOut;
145  }
146 
147  // data available from serial device, but error on read
148  else if( (n = read(fd, &byte, (size_t)1)) < 0 )
149  {
150  LOGSYSERROR("read(%d,...)", fd);
151  return KbEventError;
152  }
153 
154  // nothing read
155  else if( n == 0 )
156  {
157  LOGERROR("0=read(%d,...)", fd);
158  errno = EIO;
159  return KbEventError;
160  }
161 
162  // read character
163  else
164  {
165  LOGDIAG4("%s() byte=0x%02x read", LOGFUNCNAME, byte);
166  return (int)(((uint_t)(byte)) & 0x00ff);
167  }
168 }
static const int KbEventTimeOut
time out
Definition: StateKb.h:101
static void fdset_nowarn(int fd, fd_set *pset)
FD_SET() wrapper with no annoying warnings.
Definition: StateKb.cxx:89
static const int KbEventError
input error
Definition: StateKb.h:99
uint_t m_usecTimeOut
receive event time out (useconds)
Definition: State.h:395

The documentation for this class was generated from the following files: