FreeMemReportControl.h
Go to the documentation of this file.00001
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
00012 class FreeMemReportControl : public BehaviorBase, public ControlBase {
00013 public:
00014
00015
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(); }
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
00040 void report();
00041
00042
00043 static size_t freeMem();
00044
00045
00046 void resetTimerFreq();
00047
00048 protected:
00049
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;
00061 unsigned int low_mem;
00062 unsigned int monitor_freq;
00063 bool isWarning;
00064 size_t lastReport;
00065 };
00066
00067
00068
00069
00070
00071
00072 #endif