OpenDDS  Snapshot(2023/04/28-20:55)
SporadicEvent.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_SPORADIC_EVENT_H
9 #define OPENDDS_DCPS_SPORADIC_EVENT_H
10 
11 #include "EventDispatcher.h"
12 
14 
15 namespace OpenDDS {
16 namespace DCPS {
17 
18 /**
19  * SporadicEvent is an event which can be scheduled multiple times but will only dispatch once
20  *
21  * SporadicEvent allows repeated calls to schedule (when the application is
22  * unsure if the event has already been scheduled), but cumulative calls to
23  * schedule will only result in a single dispatch. After the base event
24  * dispatches, additional calls to schedule will result in another dispatch.
25  * Additional calls to schedule may, however, shorten the scheduled time until
26  * the base event dispatches. The SporadicEvent takes both an EventDispatcher
27  * and a base event (c.f. EventBase) and handles the logic of scheduling,
28  * rescheduling, and canceling the base event with the EventDispatcher.
29  */
31 public:
32 
33  /**
34  * Creates a SporadicEvent to handle scheduling a base event with an EventDispatcher
35  * @param dispatcher the EventDispatcher to use for scheduling
36  * @param event the base event (c.f EventBase) to schedule for dispatch
37  */
39 
40  /**
41  * Schedule the SporadicEvent to dispatch the base event after the specified
42  * duration. If the SporadicEvent is already scheduled, the duration is
43  * compared with the existing scheduled time and the shorter (sooner) of the
44  * two durations is used.
45  * @param duration the time period used to schedule / reschedule the base event
46  */
47  void schedule(const TimeDuration& duration);
48 
49  /**
50  * Cancel the SporadicEvent, canceling the scheduled base event if scheduled.
51  */
52  void cancel();
53 
54  /**
55  * For use by EventDispatcher
56  */
57  void handle_event();
58 
59  /**
60  * For use by EventDispatcher
61  */
62  void handle_cancel();
63 
64 private:
65 
66  void handle_event_scheduling();
67 
73  long timer_id_;
74 };
75 
76 } // DCPS
77 } // OpenDDS
78 
80 
81 #endif // OPENDDS_DCPS_SPORADIC_EVENT_H
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
ACE_Thread_Mutex event_mutex_
Definition: SporadicEvent.h:69
RcHandle< EventBase > event_
Definition: SporadicEvent.h:71
WeakRcHandle< EventDispatcher > dispatcher_
Definition: SporadicEvent.h:70
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
MonotonicTimePoint expiration_
Definition: SporadicEvent.h:72