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() { SetAutoDelete(false); DoStop(); clearSlots(); } //!< 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 processEvent(const EventBase& e);
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     pushSlot(new BehaviorActivatorControl(this));
00052     pushSlot(new NullControl("Free Mem: unknown"));
00053     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));
00054     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));
00055     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));
00056     lastReport=freeMem();
00057   }
00058 
00059   int report_freq;  //!< how often to report memory size (in milliseconds - negative turns off, 0 is as often as possible)
00060   unsigned int low_mem;      //!< threshold to trigger low memory warning (in kilobytes)
00061   unsigned int monitor_freq; //!< how often to check for low memory (in milliseconds - -1U turns off, 0 is as often as possible)
00062   bool isWarning;            //!< true we already know we're below threshold
00063   size_t lastReport; //!< free memory at last report so we can report the difference
00064 };
00065 
00066 /*! @file
00067  * @brief Describes FreeMemReportControl, which gives reports on free memory size at various (configurable) rates
00068  * @author ejt (object), alokl (core function)
00069  *
00070  * $Author: ejt $
00071  * $Name: tekkotsu-4_0 $
00072  * $Revision: 1.9 $
00073  * $State: Exp $
00074  * $Date: 2006/09/25 23:26:56 $
00075  */
00076 
00077 #endif

Tekkotsu v4.0
Generated Thu Nov 22 00:54:53 2007 by Doxygen 1.5.4