Monitor_Admin.cpp

Go to the documentation of this file.
00001 // $Id: Monitor_Admin.cpp 81691 2008-05-14 11:09:21Z johnnyw $
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& /* current_time */,
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           /// Destroys the timers associated with our event handler
00040           /// before its destructor is called.
00041           ACE_Reactor::instance ()->close_singleton ();
00042         }
00043 
00044       /// We access the registry through ACE_Singleton, which
00045       /// doesn't call the destructor, so we call this method to
00046       /// do a remove_ref() on all monitor points left in the registry.
00047       /// which needs to be done before the registry goes away.
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       /// This call checks for a null monitor_point.
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 /* ACE_HAS_MONITOR_FRAMEWORK==1 */
00113 

Generated on Tue Feb 2 17:18:40 2010 for ACE by  doxygen 1.4.7