Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

FreeMemReportControl.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_FreeMemReportControl_h_
00003 #define INCLUDED_FreeMemReportControl_h_
00004 
00005 #include "Behaviors/BehaviorBase.h"
00006 #include "ControlBase.h"
00007 #include "Events/EventRouter.h"
00008 #include "BehaviorActivatorControl.h"
00009 #include "ValueEditControl.h"
00010 
00011 //! gives reports on free memory size at variable rates, can also warn if free memory drops too low.
00012 class FreeMemReportControl : public BehaviorBase, public ControlBase {
00013 public:
00014   //!@name Contructors/Destructors
00015   //!contructor
00016   FreeMemReportControl() : BehaviorBase("FreeMemReportControl"), ControlBase("Free Memory Report","Reports size of free memory, and monitors for low memory warning"), report_freq(-1U), low_mem(256), monitor_freq(1000), isWarning(false), lastReport() {init();}
00017   FreeMemReportControl(const std::string& n) : BehaviorBase("FreeMemReportControl"), ControlBase(n,"Reports size of free memory, and monitors for low memory warning"), report_freq(-1U), low_mem(256), monitor_freq(1000),isWarning(false), lastReport() {init();}
00018   FreeMemReportControl(const std::string& n, const std::string& d) : BehaviorBase("FreeMemReportControl"), ControlBase(n,d), report_freq(-1U), low_mem(256), monitor_freq(1000),isWarning(false), lastReport() {init();}
00019   virtual ~FreeMemReportControl() { clearSlots(); stop(); } //!< destructor
00020   //@}
00021 
00022   virtual void doStart() {
00023     BehaviorBase::doStart();
00024     resetTimerFreq();
00025   }
00026 
00027   virtual void doStop() {
00028     isWarning=false;
00029     erouter->removeListener(this);
00030     BehaviorBase::doStop();
00031   }
00032 
00033   virtual void doEvent();
00034 
00035   virtual std::string getName() const { return (isActive()?"#":"-")+ControlBase::getName(); }
00036 
00037   virtual void refresh();
00038   
00039   //! reports size of free memory - if this is below low_mem, also generates a warning
00040   void report();
00041 
00042   //! returns the size of the free memory
00043   static size_t freeMem();
00044 
00045   //! resets timer delays
00046   void resetTimerFreq();
00047 
00048 protected:
00049   //! builds the submenus
00050   void init() {
00051     setAutoDelete(false);
00052     pushSlot(new BehaviorActivatorControl(this));
00053     pushSlot(new NullControl("Free Mem: unknown"));
00054     pushSlot(new ValueEditControl<int>("Report Frequency","Controls how often to generate free memory reports (in milliseconds)","Please enter milliseconds to wait between reports (-1 to stop)",&report_freq));
00055     pushSlot(new ValueEditControl<unsigned int>("Low Memory Threshold","Controls when to start warning about low memory (in KB)","Please enter the new low memory warning threshold (in KB)",&low_mem));
00056     pushSlot(new ValueEditControl<unsigned int>("Monitor Frequency","Controls how often to check for low memory (in milliseconds)","Please enter milliseconds to wait between low memory checks (-1 to stop)",&monitor_freq));
00057     lastReport=freeMem();
00058   }
00059 
00060   int report_freq;  //!< how often to report memory size (in milliseconds - negative turns off, 0 is as often as possible)
00061   unsigned int low_mem;      //!< threshold to trigger low memory warning (in kilobytes)
00062   unsigned int monitor_freq; //!< how often to check for low memory (in milliseconds - -1U turns off, 0 is as often as possible)
00063   bool isWarning;            //!< true we already know we're below threshold
00064   size_t lastReport; //!< free memory at last report so we can report the difference
00065 };
00066 
00067 /*! @file
00068  * @brief Describes FreeMemReportControl, which gives reports on free memory size at various (configurable) rates
00069  * @author ejt (object), alokl (core function)
00070  */
00071 
00072 #endif

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