Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

SpiderMachineBehavior Class Reference

#include <SpiderMachineBehavior.h>

Inheritance diagram for SpiderMachineBehavior:

Inheritance graph
[legend]
List of all members.

Detailed Description

When active and connected over network socket, outputs structure of requested state machine(s).

The protocol is:

  • 'list' - send list of all instantiated StateNodes
  • 'spider name' - spider the current structure of StateNode named name
  • 'listen name' - send updates regarding the activation status of name and its subnodes; you can specify a state which is not yet running
  • 'ignore name' - cancels a previous listen command
  • 'clear' - cancels all previous listen commands; should be called at the beginning or end of each connection, preferably both

Each of those commands should be terminated with a newline - i.e. one command per line

After a list command, the first line will be the number of StateNodes, followed by that number of lines, one StateNode name per line.

After a spider command, an XML description of the model will be sent. If no matching StateNode is found, an warning will be displayed on serr, and an empty model ("<model></model>") returned over the network connection.

All other commands give no direct response - listen can be executed before the specified StateNode is yet running, and ignore doesn't care whether or not the specified StateNode was actually being listened for.

The format of the model is:

 <!DOCTYPE model [
 <!ELEMENT model (state*, transition*)>
 <!ELEMENT state (state*, transition*)>
 <!ELEMENT transition (source+, dest+)>
 <!ELEMENT source (#PCDATA)>
 <!ELEMENT dest (#PCDATA)>
 
 <!ATTLIST state id CDATA #REQUIRED>
 <!ATTLIST state class CDATA #REQUIRED>
 <!ATTLIST transition id CDATA #REQUIRED>
 <!ATTLIST transition class CDATA #REQUIRED>
 ]>

The format of status updates following a listen command is:

 <!DOCTYPE event [
 <!ELEMENT event (fire*, statestart*, statestop*)>
 <!ELEMENT fire (EMPTY)>
 <!ELEMENT statestart (EMPTY)>
 <!ELEMENT statestop (EMPTY)>

 <!ATTLIST fire id CDATA #REQUIRED>
 <!ATTLIST fire time CDATA #REQUIRED>
 <!ATTLIST statestart id CDATA #REQUIRED>
 <!ATTLIST statestart time CDATA #REQUIRED>
 <!ATTLIST statestop id CDATA #REQUIRED>
 <!ATTLIST statestop time CDATA #REQUIRED>
 ]>

Definition at line 67 of file SpiderMachineBehavior.h.

Public Member Functions

 SpiderMachineBehavior ()
 constructor
virtual void DoStart ()
 By default, merely adds to the reference counter (through AddReference()); Note you should still call this from your overriding methods.
virtual void DoStop ()
 By default, subtracts from the reference counter (RemoveReference()), and thus may deletex if zero; Don't forget to still call this when you override this; Warning: call this at the end of your DoStop(), not beginning (it might delete this ).
virtual void processEvent (const EventBase &e)
 By defining here, allows you to get away with not supplying a processEvent() function for the EventListener interface. By default, does nothing.
void spider (const StateNode *n, unsigned int depth=0)
 dumps all of the transitions and subnodes of a given statenode
bool isListening (const StateNode *n)
 returns true iff n or one of its parents is found in listen
virtual std::string getDescription () const
 Gives a short description of what this particular instantiation does (in case a more specific description is needed on an individual basis).
void runCommand (const std::string &s)
 parses commands sent from callback()

Static Public Member Functions

static int callback (char *buf, int bytes)
 called by wireless when there's new data
static std::string getClassDescription ()
 Gives a short description of what this class of behaviors does... you should override this (but don't have to).

Static Public Attributes

static SpiderMachineBehaviortheOne = NULL
 Points to the one SpiderMachineBehavior object that the input command stream is talking to.
static unsigned int port = 10081
 the port to listen on (10081 by default)

Protected Types

typedef std::set< BehaviorBase * > registry_t
 the type of the behavior registry (BehaviorBase::registry)
typedef std::multiset< const
StateNode * > 
expected_t
 the type of expected
typedef std::set< std::string > listen_t
 the type of listen
typedef std::queue< EventBasequeuedEvents_t
 the type of queuedEvents

Protected Member Functions

void indent (unsigned int level)
 just to prettify the data sent out - probably should make this a null-op to save bandwidth after debugging is done
const StateNodefind (const std::string &name)
 searches currently instantiated StateNodes to find the one named name

Protected Attributes

Socketcmdsock
 the socket for communication
expected_t expected
 a set of behaviors which are involved with an impending transition - their next stateMachineEGID event should be ignored
listen_t listen
 a set of state machine names which should have their subnodes monitored
queuedEvents_t queuedEvents
 used if a transition causes other transitions, those transitions need to be remembered

Private Member Functions

 SpiderMachineBehavior (const SpiderMachineBehavior &)
 don't call
SpiderMachineBehavior operator= (const SpiderMachineBehavior &)
 don't call


Member Typedef Documentation

typedef std::multiset<const StateNode*> SpiderMachineBehavior::expected_t [protected]
 

the type of expected

Definition at line 110 of file SpiderMachineBehavior.h.

typedef std::set<std::string> SpiderMachineBehavior::listen_t [protected]
 

the type of listen

Definition at line 111 of file SpiderMachineBehavior.h.

typedef std::queue<EventBase> SpiderMachineBehavior::queuedEvents_t [protected]
 

the type of queuedEvents

Definition at line 112 of file SpiderMachineBehavior.h.

typedef std::set<BehaviorBase*> SpiderMachineBehavior::registry_t [protected]
 

the type of the behavior registry (BehaviorBase::registry)

Definition at line 109 of file SpiderMachineBehavior.h.


Constructor & Destructor Documentation

SpiderMachineBehavior::SpiderMachineBehavior  )  [inline]
 

constructor

Definition at line 77 of file SpiderMachineBehavior.h.

SpiderMachineBehavior::SpiderMachineBehavior const SpiderMachineBehavior  )  [private]
 

don't call


Member Function Documentation

int SpiderMachineBehavior::callback char *  buf,
int  bytes
[static]
 

called by wireless when there's new data

Definition at line 216 of file SpiderMachineBehavior.cc.

Referenced by DoStart().

void SpiderMachineBehavior::DoStart  )  [virtual]
 

By default, merely adds to the reference counter (through AddReference()); Note you should still call this from your overriding methods.

Reimplemented from BehaviorBase.

Definition at line 9 of file SpiderMachineBehavior.cc.

void SpiderMachineBehavior::DoStop  )  [virtual]
 

By default, subtracts from the reference counter (RemoveReference()), and thus may deletex if zero; Don't forget to still call this when you override this; Warning: call this at the end of your DoStop(), not beginning (it might delete this ).

Reimplemented from BehaviorBase.

Definition at line 21 of file SpiderMachineBehavior.cc.

const StateNode * SpiderMachineBehavior::find const std::string &  name  )  [protected]
 

searches currently instantiated StateNodes to find the one named name

Definition at line 165 of file SpiderMachineBehavior.cc.

Referenced by runCommand().

static std::string SpiderMachineBehavior::getClassDescription  )  [inline, static]
 

Gives a short description of what this class of behaviors does... you should override this (but don't have to).

If you do override this, also consider overriding getDescription() to return it

Reimplemented from BehaviorBase.

Definition at line 89 of file SpiderMachineBehavior.h.

Referenced by getDescription().

virtual std::string SpiderMachineBehavior::getDescription  )  const [inline, virtual]
 

Gives a short description of what this particular instantiation does (in case a more specific description is needed on an individual basis).

By default simply returns getName(), because any calls from a BehaviorBase function to getClassDescription() are going to call BehaviorBase::getClassDescription(), not ~YourSubClass~getClassDescription(), because static functions can't be virtual in C++ (doh!)

This means that getDescription called on a pointer to a BehaviorBase of unknown subtype would always return an empty string, which is pretty useless. So instead we return the name in this situation. If you want getDescription to return getClassDescription, you'll have to override it in your subclass to do so.

Reimplemented from BehaviorBase.

Definition at line 95 of file SpiderMachineBehavior.h.

void SpiderMachineBehavior::indent unsigned int  level  )  [protected]
 

just to prettify the data sent out - probably should make this a null-op to save bandwidth after debugging is done

Definition at line 160 of file SpiderMachineBehavior.cc.

Referenced by processEvent(), and spider().

bool SpiderMachineBehavior::isListening const StateNode n  ) 
 

returns true iff n or one of its parents is found in listen

Definition at line 151 of file SpiderMachineBehavior.cc.

Referenced by processEvent().

SpiderMachineBehavior SpiderMachineBehavior::operator= const SpiderMachineBehavior  )  [private]
 

don't call

void SpiderMachineBehavior::processEvent const EventBase e  )  [virtual]
 

By defining here, allows you to get away with not supplying a processEvent() function for the EventListener interface. By default, does nothing.

Reimplemented from BehaviorBase.

Definition at line 34 of file SpiderMachineBehavior.cc.

void SpiderMachineBehavior::runCommand const std::string &  s  ) 
 

parses commands sent from callback()

Definition at line 175 of file SpiderMachineBehavior.cc.

Referenced by callback().

void SpiderMachineBehavior::spider const StateNode n,
unsigned int  depth = 0
 

dumps all of the transitions and subnodes of a given statenode

Definition at line 105 of file SpiderMachineBehavior.cc.

Referenced by runCommand().


Member Data Documentation

class Socket* SpiderMachineBehavior::cmdsock [protected]
 

the socket for communication

Definition at line 107 of file SpiderMachineBehavior.h.

Referenced by DoStart(), DoStop(), indent(), processEvent(), runCommand(), and spider().

expected_t SpiderMachineBehavior::expected [protected]
 

a set of behaviors which are involved with an impending transition - their next stateMachineEGID event should be ignored

Definition at line 114 of file SpiderMachineBehavior.h.

Referenced by DoStop(), and processEvent().

listen_t SpiderMachineBehavior::listen [protected]
 

a set of state machine names which should have their subnodes monitored

Definition at line 116 of file SpiderMachineBehavior.h.

Referenced by isListening(), processEvent(), and runCommand().

unsigned int SpiderMachineBehavior::port = 10081 [static]
 

the port to listen on (10081 by default)

Definition at line 72 of file SpiderMachineBehavior.h.

Referenced by DoStart(), and getClassDescription().

queuedEvents_t SpiderMachineBehavior::queuedEvents [protected]
 

used if a transition causes other transitions, those transitions need to be remembered

Definition at line 118 of file SpiderMachineBehavior.h.

Referenced by DoStop(), and processEvent().

SpiderMachineBehavior * SpiderMachineBehavior::theOne = NULL [static]
 

Points to the one SpiderMachineBehavior object that the input command stream is talking to.

A kludge. Dunno how you're gonna make sure you're not using this uninitialized.

Definition at line 71 of file SpiderMachineBehavior.h.

Referenced by DoStart(), and DoStop().


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

Tekkotsu v2.4.1
Generated Tue Aug 16 16:35:10 2005 by Doxygen 1.4.4