Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

EventLogger.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_EventLogger_h_
00003 #define INCLUDED_EventLogger_h_
00004 
00005 #include "ControlBase.h"
00006 #include "Events/EventListener.h"
00007 #include <fstream>
00008 #include <set>
00009 #include <queue>
00010 
00011 class FilterBankGenerator;
00012 class BehaviorBase;
00013 class StateNode;
00014 
00015 //! allows logging of events to the console or a file
00016 class EventLogger : public ControlBase, public EventListener {
00017 public:
00018   //!constructor
00019   EventLogger();
00020   //!destructor
00021   virtual ~EventLogger();
00022 
00023   //!opens a custom (embedded) menu to toggle individual EGIDs
00024   virtual ControlBase* doSelect();
00025   
00026   virtual void refresh();
00027 
00028   //!sends all events received to stdout and/or logfile
00029   virtual void processEvent(const EventBase& event);
00030 
00031   //!returns #logSocket
00032   static class Socket* getLogSocket() { return logSocket; }
00033   
00034   //! returns #port
00035   static int getLogSocketPort() { return port; }
00036   
00037   //! sets #port
00038   static void setLogSocketPort(int p) { port=p; }
00039 
00040   //! send the current camera image over the log socket
00041   static void logImage(FilterBankGenerator& fbg, unsigned int layer, unsigned int channel, const BehaviorBase* source=NULL);
00042 
00043   //! send a string over the log socket
00044   static void logMessage(std::string msg, const BehaviorBase* source=NULL, const char* icon=NULL, unsigned int placement=0);
00045   
00046   //! request that the desktop side take a picture with the webcam (if available)
00047   static void logWebcam(const BehaviorBase* source=NULL);
00048   
00049   static int callback(char *buf, int bytes); //!< called by wireless when there's new data
00050 
00051 protected:
00052   static EventLogger * theOne; //!< the instance which will handle network communication
00053 
00054   //! a separate processEvent to distinguish between events requested for logging and events requested by a remote monitor
00055   class StateMachineListener : public EventListener {
00056     //! forwards any events received to EventLogger::theOne's EventLogger::processStateMachineEvent()
00057     /*! EventLogger::runCommand() is responsible for maintaining which events this is listening to */
00058     virtual void processEvent(const EventBase& event) {
00059       EventLogger::theOne->processStateMachineEvent(event);
00060     }
00061   };
00062   static class StateMachineListener smProcess; //!< handles state machine transitions if the Storyboard GUI (or other remote monitor) is listening for state machine events
00063 
00064   virtual void clearSlots();
00065 
00066   //!sets the status char of slot @a i to @a c
00067   void setStatus(unsigned int i, char c);
00068 
00069   //!checks to see if logfilePath differs from the StringInputControl's value and switches it if it is
00070   void checkLogFile();
00071   
00072   //! dumps all of the transitions and subnodes of a given statenode
00073   void spider(const StateNode* n, unsigned int depth=0);
00074 
00075   //! returns true iff @a n or one of its parents is found in #listen
00076   bool isListening(const StateNode* n);
00077 
00078   //! parses commands sent from callback()
00079   void runCommand(const std::string& s);
00080 
00081   //!just to prettify the data sent out - probably should make this a null-op to save bandwidth after debugging is done
00082   void indent(unsigned int level);
00083   
00084   //!searches currently instantiated StateNodes to find the one named @a name
00085   const StateNode * find(const std::string& name);
00086 
00087   //!if there is a remote monitor listening for state machine transitions, this will send them over
00088   /*!this is called by the StateMachineListener, which is subscribed to only
00089    * those machines which have been requested by the remote monitor */
00090   virtual void processStateMachineEvent(const EventBase& event);
00091 
00092   //!address of the logfile, if any (empty string is no logfile)
00093   std::string logfilePath;
00094 
00095   //!if a filename is given, events are logged to here
00096   std::ofstream logfile;
00097   
00098   //! events which are logged will be sent over this port in an xml format.  See eventlog.dtd in the docs directory
00099   static class Socket* logSocket;
00100   
00101   //! port number #logSocket will listen on
00102   static int port;
00103   
00104   //! reference count for #logSocket -- when this hits 0, close the socket
00105   static unsigned int logSocketRefCount;
00106   
00107   //!controls the level of verbosity - currently 0 through 2
00108   unsigned int verbosity;
00109 
00110   typedef std::set<BehaviorBase*> registry_t; //!< the type of the behavior registry (BehaviorBase::registry)
00111 
00112   typedef std::multiset<const StateNode*> expected_t; //!< the type of #expected
00113   expected_t expected; //!< a set of behaviors which are involved with an impending transition - their next stateMachineEGID event should be ignored
00114 
00115   typedef std::set<std::string> listen_t; //!< the type of #listen
00116   listen_t listen; //!< a set of state machine names which should have their subnodes monitored
00117 
00118   typedef std::queue<EventBase> queuedEvents_t; //!< the type of #queuedEvents
00119   queuedEvents_t queuedEvents; //!< used if a transition causes other transitions, those transitions need to be remembered
00120 };
00121 
00122 /*! @file
00123  * @brief Describes EventLogger, which allows logging of events to the console or a file
00124  * @author ejt (Creator)
00125  *
00126  * $Author: ejt $
00127  * $Name: tekkotsu-3_0 $
00128  * $Revision: 1.9 $
00129  * $State: Exp $
00130  * $Date: 2006/09/16 06:28:06 $
00131  */
00132 
00133 #endif

Tekkotsu v3.0
Generated Wed Oct 4 00:03:43 2006 by Doxygen 1.4.7