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