Homepage Demos Overview Downloads Tutorials Reference
Credits
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Search

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

Tekkotsu v1.4
Generated Sat Jul 19 00:06:30 2003 by Doxygen 1.3.2