Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

EventLogger Class Reference

#include <EventLogger.h>

Inheritance diagram for EventLogger:

Inheritance graph
[legend]
List of all members.

Detailed Description

allows logging of events to the console or a file, also provides some remote logging facilities over logSocket, required by Storyboard tool

Users' behaviors can call logMessage(), logImage(), and logWebcam() to insert the corresponding data into logSocket via an XML 'event' node.

The protocol used with logSocket 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>
 ]>

The 'event' node is also used for the results of logImage(), logMessage(), and logWebcam().

Definition at line 77 of file EventLogger.h.

Public Member Functions

 EventLogger ()
 constructor
virtual ~EventLogger ()
 destructor
virtual ControlBasedoSelect ()
 opens a custom (embedded) menu to toggle individual EGIDs
virtual void refresh ()
 called when the child has deactivated and this control should refresh its display, or some other event (such as the user pressing the refresh button) has happened to cause a refresh to be needed
virtual void processEvent (const EventBase &event)
 sends all events received to stdout and/or logfile

Static Public Member Functions

static class SocketgetLogSocket ()
 returns logSocket
static int getLogSocketPort ()
 returns port
static void setLogSocketPort (int p)
 sets port
static void logImage (FilterBankGenerator &fbg, unsigned int layer, unsigned int channel, const BehaviorBase *source=NULL)
 send the current camera image over the log socket
static void logMessage (std::string msg, const BehaviorBase *source=NULL, const char *icon=NULL, unsigned int placement=0)
 send a string over the log socket
static void logWebcam (const BehaviorBase *source=NULL)
 request that the desktop side take a picture with the webcam (if available)
static int callback (char *buf, int bytes)
 called by wireless when there's new data

Protected Types

typedef std::set< BehaviorBase * > registry_t
 the type of the behavior registry (BehaviorBase::registry)
typedef std::set< std::string > listen_t
 the type of listen
typedef std::queue< xmlNode * > queuedEvents_t
 the type of queuedEvents
typedef std::stack< xmlNode * > transStack_t
 the type of transStack

Protected Member Functions

virtual void clearSlots ()
 deletes each slot item and clears the slots
void setStatus (unsigned int i, char c)
 sets the status char of slot i to c
void checkLogFile ()
 checks to see if logfilePath differs from the StringInputControl's value and switches it if it is
void spider (const StateNode *n, xmlNode *parent=NULL)
 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
void runCommand (const std::string &s)
 parses commands sent from callback()
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
virtual void processStateMachineEvent (const EventBase &event)
 if there is a remote monitor listening for state machine transitions, this will send them over

Static Protected Member Functions

static void dumpQueuedEvents ()
 dumps elements of queuedEvents over logSocket, popping and freeing as it goes
static void dumpNode (xmlNode *node, xmlDoc *doc=NULL)
 writes an xmlNode out over logSocket, freeing node when complete

Protected Attributes

std::string logfilePath
 address of the logfile, if any (empty string is no logfile)
std::ofstream logfile
 if a filename is given, events are logged to here
unsigned int verbosity
 controls the level of verbosity - currently 0 through 2
listen_t listen
 a set of state machine names which should have their subnodes monitored

Static Protected Attributes

static EventLoggertheOne = NULL
 the instance which will handle network communication
static class StateMachineListener smProcess
 handles state machine transitions if the Storyboard GUI (or other remote monitor) is listening for state machine events
static class SocketlogSocket = NULL
 events which are logged will be sent over this port in an xml format. See eventlog.dtd in the docs directory
static int port = 10080
 port number logSocket will listen on
static unsigned int logSocketRefCount = 0
 reference count for logSocket -- when this hits 0, close the socket
static queuedEvents_t queuedEvents
 if logImage/logMessage/etc. are called during a transition, need to queue them until the transition event is complete
static transStack_t transStack
 if another transition occurs during the processing of another, have to recurse on processing the new transition first

Classes

class  StateMachineListener
 a separate processEvent to distinguish between events requested for logging and events requested by a remote monitor More...


Member Function Documentation

void EventLogger::dumpNode ( xmlNode node,
xmlDoc doc = NULL 
) [static, protected]

writes an xmlNode out over logSocket, freeing node when complete

uses doc if provided, otherwise makes a new temporary one which is then deleted again before the function returns

Definition at line 447 of file EventLogger.cc.

Referenced by dumpQueuedEvents(), and spider().

void EventLogger::processStateMachineEvent ( const EventBase event  )  [protected, virtual]

if there is a remote monitor listening for state machine transitions, this will send them over

this is called by the StateMachineListener, which is subscribed to only those machines which have been requested by the remote monitor

Definition at line 375 of file EventLogger.cc.

Referenced by EventLogger::StateMachineListener::processEvent().

void EventLogger::spider ( const StateNode n,
xmlNode parent = NULL 
) [protected]

dumps all of the transitions and subnodes of a given statenode

if parent is NULL, will dump the results over logSocket, otherwise adds the xml tree as a child of parent

Definition at line 238 of file EventLogger.cc.

Referenced by runCommand().


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

Tekkotsu v3.0
Generated Fri May 11 20:08:05 2007 by Doxygen 1.4.7