OpenDDS  Snapshot(2023/04/28-20:55)
PeriodicEvent.h
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #ifndef OPENDDS_DCPS_PERIODIC_EVENT_H
9 #define OPENDDS_DCPS_PERIODIC_EVENT_H
10 
11 #include "EventDispatcher.h"
12 
14 
15 namespace OpenDDS {
16 namespace DCPS {
17 
18 /**
19  * PeriodicEvent is an event that is dispatched with a regular, repeating period
20  *
21  * PeriodicEvent serves as a helpful utility class for repeatedly dispatching
22  * another base event at a regular, fixed interval. The PeriodicEvent takes both
23  * an EventDispatcher and a base event (c.f. EventBase) and handles the logic
24  * of scheduling, rescheduling, and canceling the base event with the
25  * EventDispatcher.
26  */
28 public:
29 
30  /**
31  * Creates a PeriodicEvent to handle scheduling a base event with an EventDispatcher
32  * @param dispatcher the EventDispatcher to use for scheduling
33  * @param event the base event (c.f EventBase) to schedule for dispatch
34  */
36 
37  /**
38  * Enable the PeriodicEvent to begin scheduling / rescheduling the base event
39  * using the internal EventDispatcher and the provided time period. If strict
40  * scheduling is requested, the elapsed time since the previous dispatch will
41  * not impact the time point provided for the next scheduled dispatch. Note:
42  * strict timing may potentially lead to CPU starvation if the dispatch takes
43  * longer than the requested period.
44  * @param period the time period used to schedule / reschedule the base event
45  * @param immediate_dispatch set to true to immediately dispatch base event
46  * @param strict_timing set to true to strictly calculate scheduled dispatch times
47  */
48  void enable(const TimeDuration& period, bool immediate_dispatch = true, bool strict_timing = true);
49 
50  /**
51  * Disable the PeriodicEvent, canceling the scheduled base event if enabled.
52  */
53  void disable();
54 
55  /**
56  * Check to see if the PeriodicEvent is currently enabled
57  * @return true if the PeriodicEvent is currently enabled
58  */
59  bool enabled() const;
60 
61  /**
62  * For use by EventDispatcher
63  */
64  void handle_event();
65 
66  /**
67  * For use by EventDispatcher
68  */
69  void handle_cancel();
70 
71 private:
72 
73  void handle_event_scheduling();
74 
82  long timer_id_;
83 };
84 
85 } // DCPS
86 } // OpenDDS
87 
89 
90 #endif // OPENDDS_DCPS_PERIODIC_EVENT_H
ACE_Thread_Mutex event_mutex_
Definition: PeriodicEvent.h:76
RcHandle< EventBase > event_
Definition: PeriodicEvent.h:78
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
WeakRcHandle< EventDispatcher > dispatcher_
Definition: PeriodicEvent.h:77
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
MonotonicTimePoint expiration_
Definition: PeriodicEvent.h:81
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28