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

Tekkotsu v2.2
Generated Tue Oct 19 14:19:14 2004 by Doxygen 1.3.9.1