00001 /* 00002 * 00003 * 00004 * Distributed under the OpenDDS License. 00005 * See: http://www.opendds.org/license.html 00006 */ 00007 00008 #ifndef OPENDDS_WATCHDOG_H 00009 #define OPENDDS_WATCHDOG_H 00010 00011 #include "ace/config-all.h" 00012 00013 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00014 # pragma once 00015 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00016 00017 #include "dds/DCPS/ReactorInterceptor.h" 00018 00019 #include "ace/Time_Value.h" 00020 00021 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 00022 00023 namespace OpenDDS { 00024 namespace DCPS { 00025 00026 /** 00027 * @brief Watchdog abstract base class. 00028 * 00029 * A @c Watchdog object executes an operation each time a 00030 * corresponding timer expires. The timer is managed by this 00031 * class. However, it is the responsibility of the @c Watchdog 00032 * owner, for example, to run the @c ACE_Reactor event loop. 00033 * The @c Watchdog timer will not fire, otherwise. 00034 */ 00035 class OpenDDS_Dcps_Export Watchdog : public ReactorInterceptor { 00036 protected: 00037 00038 explicit Watchdog(const ACE_Time_Value& interval); 00039 00040 virtual ~Watchdog(); 00041 00042 private: 00043 00044 /// Re-schedule timer with new interval. 00045 virtual void reschedule_deadline() = 0; 00046 00047 bool reactor_is_shut_down() const; 00048 00049 public: 00050 /// Reset the @c Watchdog timer interval, i.e. time between 00051 /// recurring timer expirations. 00052 /** 00053 * @note The new interval takes effect after the next 00054 * expiration. This behavior is dictated by the 00055 * @c ACE_Reactor. 00056 */ 00057 void reset_interval(const ACE_Time_Value& interval); 00058 00059 /// Schedule with the @c Watchdog timer interval, i.e. time between 00060 /// recurring timer expirations. 00061 long schedule_timer(const void* act, const ACE_Time_Value& interval); 00062 00063 /// Schedule with the @c Watchdog timer delay and timer interval, 00064 /// i.e. time between recurring timer expirations. 00065 long schedule_timer(const void* act, const ACE_Time_Value& delay, const ACE_Time_Value& interval); 00066 00067 /// Cancel a specific timer. 00068 int cancel_timer(long timer_id); 00069 00070 /// Cancel all associated timers. 00071 void cancel_all(); 00072 00073 /// Reset interval for a specific timer. 00074 int reset_timer_interval(long timer_id); 00075 00076 protected: 00077 /// Current time interval. 00078 ACE_Time_Value interval_; 00079 }; 00080 00081 } // namespace DCPS 00082 } // namespace OpenDDS 00083 00084 OPENDDS_END_VERSIONED_NAMESPACE_DECL 00085 00086 #endif /* OPENDDS_WATCHDOG_H */