Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

BehaviorReportControl.cc

Go to the documentation of this file.
00001 #include "ControlBase.h"
00002 #include "Behaviors/BehaviorBase.h"
00003 #include "Wireless/Socket.h"
00004 #include <cstdio>
00005 
00006 //! Reads the set of currently instantiated behaviors and sends a report to ::sout
00007 class BehaviorReportControl : public ControlBase {
00008 public:
00009   //! Constructor
00010   BehaviorReportControl()
00011     : ControlBase("Behavior Report","Generates a summary of currently instantiated behaviors")
00012   {}
00013 
00014   //! Prints a report to sout
00015   virtual ControlBase * activate(MC_ID, Socket *) {
00016     typedef std::set<BehaviorBase*> registry_t;
00017     typedef std::vector<BehaviorBase*> behlist_t;
00018     const registry_t& reg=BehaviorBase::getRegistry();
00019     behlist_t active,inactive;
00020     for(registry_t::const_iterator it=reg.begin(); it!=reg.end(); it++) {
00021       if((*it)->isActive())
00022         active.push_back(*it);
00023       else
00024         inactive.push_back(*it);
00025     }
00026 
00027     char format[100];
00028     unsigned int maxlen=0;
00029     for(behlist_t::const_iterator it=active.begin(); it!=active.end(); it++)
00030       if((*it)->getName().size()>maxlen)
00031         maxlen=(*it)->getClassName().size();
00032     for(behlist_t::const_iterator it=inactive.begin(); it!=inactive.end(); it++)
00033       if((*it)->getName().size()>maxlen)
00034         maxlen=(*it)->getClassName().size();
00035     snprintf(format,100,"  %%-%ds   %%s\n",maxlen);
00036 
00037     sout->printf("** Currently Instantiated Behavior Report **\n");
00038     sout->printf("%lu active, %lu inactive, %lu total\n\n",(unsigned long)active.size(),(unsigned long)inactive.size(),(unsigned long)reg.size());
00039     sout->printf("Active Behaviors:\n");
00040     sout->printf(format,"Class Name","Instance Name");
00041     sout->printf(format,"------------","---------------");
00042     for(behlist_t::const_iterator it=active.begin(); it!=active.end(); it++)
00043       sout->printf(format,(*it)->getClassName().c_str(),(*it)->getName().c_str());
00044     sout->printf("\n");
00045     sout->printf("Inactive Behaviors:\n");
00046     sout->printf(format,"Class Name","Instance Name");
00047     sout->printf(format,"------------","---------------");
00048     for(behlist_t::const_iterator it=inactive.begin(); it!=inactive.end(); it++)
00049       sout->printf(format,(*it)->getClassName().c_str(),(*it)->getName().c_str());
00050     return NULL;
00051   }
00052 };
00053 
00054 REGISTER_CONTROL(BehaviorReportControl,"Status Reports");
00055 
00056 /*! @file
00057  * @brief Defines BehaviorReportControl, which reads the set of currently instantiated behaviors and sends a report to ::sout
00058  * @author ejt (Creator)
00059  */

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:36 2016 by Doxygen 1.6.3