00001
00002
00003 #include "ace/Monitor_Admin.h"
00004
00005 #if defined (ACE_HAS_MONITOR_FRAMEWORK) && (ACE_HAS_MONITOR_FRAMEWORK == 1)
00006
00007 #include "ace/Reactor.h"
00008 #include "ace/Monitor_Point_Registry.h"
00009
00010 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00011
00012 namespace ACE
00013 {
00014 namespace Monitor_Control
00015 {
00016 int
00017 Monitor_Point_Auto_Updater::handle_timeout (
00018 const ACE_Time_Value& ,
00019 const void* monitor_point)
00020 {
00021 const Monitor_Base* const_mp =
00022 reinterpret_cast<const Monitor_Base*> (monitor_point);
00023 Monitor_Base* mp = const_cast<Monitor_Base*> (const_mp);
00024 mp->update ();
00025 return 0;
00026 }
00027
00028
00029
00030 Monitor_Admin::Monitor_Admin (void)
00031 : reactor_ (ACE_Reactor::instance ()),
00032 default_reactor_ (true)
00033 {}
00034
00035 Monitor_Admin::~Monitor_Admin (void)
00036 {
00037 if (this->default_reactor_)
00038 {
00039
00040
00041 ACE_Reactor::instance ()->close_singleton ();
00042 }
00043
00044
00045
00046
00047
00048 Monitor_Point_Registry::instance ()->cleanup ();
00049 }
00050
00051 bool
00052 Monitor_Admin::monitor_point (Monitor_Base* monitor_point,
00053 const ACE_Time_Value& time)
00054 {
00055
00056 bool good_reg_add =
00057 Monitor_Point_Registry::instance ()->add (monitor_point);
00058
00059 if (!good_reg_add)
00060 {
00061 ACE_ERROR_RETURN ((LM_ERROR,
00062 "registration of %s failed\n",
00063 monitor_point->name ()),
00064 good_reg_add);
00065 }
00066 else if (time != ACE_Time_Value::zero)
00067 {
00068 this->reactor_->schedule_timer (&this->auto_updater_,
00069 monitor_point,
00070 ACE_Time_Value::zero,
00071 time);
00072 }
00073
00074 return good_reg_add;
00075 }
00076
00077 Monitor_Base*
00078 Monitor_Admin::monitor_point (const char* name)
00079 {
00080 ACE_CString name_str (name, 0, false);
00081 return Monitor_Point_Registry::instance ()->get (name_str);
00082 }
00083
00084 void
00085 Monitor_Admin::auto_query (ACE_Event_Handler* handler,
00086 MonitorQuery* query,
00087 const ACE_Time_Value& time)
00088 {
00089 this->reactor_->schedule_timer (handler,
00090 query,
00091 ACE_Time_Value::zero,
00092 time);
00093 }
00094
00095 void
00096 Monitor_Admin::reactor (ACE_Reactor* new_reactor)
00097 {
00098 this->reactor_ = new_reactor;
00099 this->default_reactor_ = false;
00100 }
00101
00102 ACE_Reactor*
00103 Monitor_Admin::reactor (void) const
00104 {
00105 return this->reactor_;
00106 }
00107 }
00108 }
00109
00110 ACE_END_VERSIONED_NAMESPACE_DECL
00111
00112 #endif
00113