Watchdog.h

Go to the documentation of this file.
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 namespace OpenDDS {
00022 namespace DCPS {
00023 
00024 /**
00025  * @brief Watchdog abstract base class.
00026  *
00027  * A @c Watchdog object executes an operation each time a
00028  * corresponding timer expires.  The timer is managed by this
00029  * class.  However, it is the responsibility of the @c Watchdog
00030  * owner, for example, to run the @c ACE_Reactor event loop.
00031  * The @c Watchdog timer will not fire, otherwise.
00032  */
00033 class Watchdog : public ReactorInterceptor {
00034 protected:
00035 
00036   explicit Watchdog(const ACE_Time_Value& interval);
00037 
00038   virtual ~Watchdog();
00039 
00040 private:
00041   int handle_timeout(const ACE_Time_Value&, const void* act)
00042   {
00043     return execute(act, true), 0;
00044   }
00045 
00046   /// Operation to be executed when the associated timer expires
00047   /// or whenever samples are received/sent.
00048   /// The @c timer_called flag indicates if it's called from
00049   /// reator handle_timeout() or upon a sample receiving/sending.
00050   virtual void execute(const void* act, bool timer_called) = 0;
00051 
00052   /// Re-schedule timer with new interval.
00053   virtual void reschedule_deadline() = 0;
00054 
00055   bool reactor_is_shut_down() const;
00056 
00057 public:
00058   /// Reset the @c Watchdog timer interval, i.e. time between
00059   /// recurring timer expirations.
00060   /**
00061    * @note The new interval takes effect after the next
00062    *       expiration.  This behavior is dictated by the
00063    *       @c ACE_Reactor.
00064    */
00065   void reset_interval(const ACE_Time_Value& interval);
00066 
00067   /// Schedule with the @c Watchdog timer interval, i.e. time between
00068   /// recurring timer expirations.
00069   long schedule_timer(const void* act, const ACE_Time_Value& interval);
00070 
00071   /// Cancel a specific timer.
00072   int cancel_timer(long timer_id);
00073 
00074   /// Cancel all associated timers.
00075   void cancel_all();
00076 
00077   /// Reset interval for a specific timer.
00078   int reset_timer_interval(long timer_id);
00079 
00080 protected:
00081   /// Current time interval.
00082   ACE_Time_Value interval_;
00083 };
00084 
00085 } // namespace DCPS
00086 } // namespace OpenDDS
00087 
00088 #endif  /* OPENDDS_WATCHDOG_H */

Generated on Fri Feb 12 20:05:29 2016 for OpenDDS by  doxygen 1.4.7