Homepage Demos Overview Downloads Tutorials Reference
Credits

EventLogger.cc

Go to the documentation of this file.
00001 #include "EventLogger.h"
00002 #include "Events/EventRouter.h"
00003 #include "Motion/MMAccessor.h"
00004 #include "Motion/LedMC.h"
00005 #include "ValueEditControl.h"
00006 #include "StringInputControl.h"
00007 #include "NullControl.h"
00008 #include <sstream>
00009 #include "Events/LocomotionEvent.h"
00010 #include "Events/TextMsgEvent.h"
00011 #include "Events/VisionObjectEvent.h"
00012 #include "SoundPlay/SoundManager.h"
00013 
00014 EventLogger::EventLogger() : ControlBase("Event Logger","Allows you to see/log all of the un-trapped events as they are generated"), logfilePath(), logfile(), verbosity(0) {
00015   for(unsigned int i=0; i<EventBase::numEGIDs; i++) {
00016     std::string tmp=EventBase::EventGeneratorNames[i];
00017     pushSlot(new NullControl(("[ ] "+tmp).c_str(),"Show/hide events from "+tmp));
00018   }
00019   pushSlot(NULL);
00020   pushSlot(new ValueEditControl<unsigned int>("Verbosity","Controls verbosity level: 0=(gen,source,type); 1=0+gen_id,source_id,type_id; 2=1+duration,timestamp; 3=2+magnitude; additional columns may be added for subclass info","Please enter a new verbosity level: 0=(gen,source,type); 1=0+gen_id,source_id,type_id; 2=1+duration,timestamp; 3=2+magnitude; additional columns may be added for subclass info",&verbosity));
00021   pushSlot(new ControlBase("[X] Console Output","If selected, outputs events to the console"));
00022   pushSlot(new StringInputControl("[ ] File Output","Please enter the filename to log to (in /ms/...)"));
00023 }
00024 
00025 ControlBase* EventLogger::doSelect() {
00026   ControlBase* ans=this;
00027   for(unsigned int i=0; i<hilights.size(); i++) {
00028     unsigned int cur=hilights[i];
00029     if(cur<EventBase::numEGIDs) {
00030       if(options[cur]->getName()[1]!=' ') {
00031         erouter->removeListener(this,(EventBase::EventGeneratorID_t)(cur));
00032         setStatus(cur,' ');
00033       } else {
00034         erouter->addListener(this,(EventBase::EventGeneratorID_t)(cur));
00035         setStatus(cur,'X');
00036       }
00037     } else if(cur==EventBase::numEGIDs+1) {
00038       ans=options[cur];
00039     } else if(cur==EventBase::numEGIDs+2) {
00040       if(options[cur]->getName()[1]!=' ') {
00041         setStatus(cur,' ');
00042       } else {
00043         setStatus(cur,'X');
00044       }
00045     } else if(cur==EventBase::numEGIDs+3) {
00046       if(options[cur]->getName()[1]!=' ') {
00047         logfile.close();
00048         options[cur]->setName("[ ] File Output");
00049       } else {
00050         ans=options[cur];
00051       }
00052     }
00053     sndman->PlayFile(config->controller.select_snd);
00054   }
00055   if(ans==this)
00056     refresh();
00057   return ans;
00058 }
00059 
00060 void EventLogger::refresh() {
00061   checkLogFile();
00062   ControlBase::refresh();
00063 }
00064 
00065 //!sends all events received to stdout and/or logfile
00066 void EventLogger::processEvent(const EventBase& event) {
00067   std::string logdata = event.getDescription(true,verbosity);
00068   if(options[EventBase::numEGIDs+2]->getName()[1]=='X')
00069     sout->printf("EVENT: %s\n",logdata.c_str());
00070   checkLogFile();
00071   if(logfile)
00072     logfile << logdata << endl;
00073 }
00074 
00075 void EventLogger::clearSlots() {
00076   erouter->removeListener(this);
00077   ControlBase::clearSlots();
00078 }
00079 
00080 void EventLogger::setStatus(unsigned int i, char c) {
00081   std::string tmp=options[i]->getName();
00082   tmp[1]=c;
00083   options[i]->setName(tmp);
00084 }
00085 
00086 void EventLogger::checkLogFile() {
00087   unsigned int cur=EventBase::numEGIDs+3;
00088   StringInputControl * strin=dynamic_cast<StringInputControl*>(options[cur]);
00089   ASSERTRET(strin!=NULL,"The StringInputControl is misplaced");
00090   if(strin->getLastInput()!=logfilePath) {
00091     logfile.close();
00092     logfilePath=strin->getLastInput();
00093     logfile.clear();
00094     if(logfilePath.size()!=0) {
00095       sout->printf("Opening `/ms/%s'\n",logfilePath.c_str());
00096       logfile.open(("/ms/"+logfilePath).c_str());
00097       if(!logfile.fail()) {
00098         setStatus(cur,'X');
00099         strin->setName(strin->getName()+": "+logfilePath);
00100       } else {
00101         serr->printf("Opening `/ms/%s' failed\n",logfilePath.c_str());
00102       }
00103     }
00104   }
00105 }
00106 
00107 /*! @file
00108  * @brief Describes EventLogger, which allows logging of events to the console or a file
00109  * @author ejt (Creator)
00110  *
00111  * $Author: ejt $
00112  * $Name: tekkotsu-2_2_2 $
00113  * $Revision: 1.16 $
00114  * $State: Exp $
00115  * $Date: 2004/12/22 23:53:34 $
00116  */

Tekkotsu v2.2.2
Generated Tue Jan 4 15:43:13 2005 by Doxygen 1.4.0