OpenDDS
Snapshot(2023/04/28-20:55)
dds
DCPS
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
13
OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
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
*/
27
class
OpenDDS_Dcps_Export
PeriodicEvent
:
public
EventBase
{
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
*/
35
PeriodicEvent
(
EventDispatcher_rch
dispatcher,
EventBase_rch
event);
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
75
mutable
ACE_Thread_Mutex
mutex_
;
76
mutable
ACE_Thread_Mutex
event_mutex_
;
77
WeakRcHandle<EventDispatcher>
dispatcher_
;
78
RcHandle<EventBase>
event_
;
79
TimeDuration
period_
;
80
bool
strict_timing_
;
81
MonotonicTimePoint
expiration_
;
82
long
timer_id_
;
83
};
84
85
}
// DCPS
86
}
// OpenDDS
87
88
OPENDDS_END_VERSIONED_NAMESPACE_DECL
89
90
#endif // OPENDDS_DCPS_PERIODIC_EVENT_H
OpenDDS::DCPS::PeriodicEvent::event_mutex_
ACE_Thread_Mutex event_mutex_
Definition:
PeriodicEvent.h:76
ACE_Thread_Mutex
OpenDDS::DCPS::PeriodicEvent::event_
RcHandle< EventBase > event_
Definition:
PeriodicEvent.h:78
OpenDDS_Dcps_Export
#define OpenDDS_Dcps_Export
Definition:
dcps_export.h:24
OpenDDS::DCPS::PeriodicEvent::strict_timing_
bool strict_timing_
Definition:
PeriodicEvent.h:80
OpenDDS::DCPS::PeriodicEvent::period_
TimeDuration period_
Definition:
PeriodicEvent.h:79
OpenDDS::DCPS::PeriodicEvent::mutex_
ACE_Thread_Mutex mutex_
Definition:
PeriodicEvent.h:75
OpenDDS::DCPS::PeriodicEvent::timer_id_
long timer_id_
Definition:
PeriodicEvent.h:82
OpenDDS::DCPS::WeakRcHandle
Definition:
RcObject.h:127
OpenDDS::DCPS::TimeDuration
Definition:
TimeDuration.h:29
EventDispatcher.h
OpenDDS::DCPS::EventBase
Definition:
EventDispatcher.h:27
OpenDDS::DCPS::PeriodicEvent
Definition:
PeriodicEvent.h:27
OpenDDS::DCPS::PeriodicEvent::dispatcher_
WeakRcHandle< EventDispatcher > dispatcher_
Definition:
PeriodicEvent.h:77
OpenDDS::DCPS::TimePoint_T< MonotonicClock >
OPENDDS_END_VERSIONED_NAMESPACE_DECL
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
Definition:
Versioned_Namespace.h:48
OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
Definition:
Hash.cpp:17
OpenDDS::DCPS::PeriodicEvent::expiration_
MonotonicTimePoint expiration_
Definition:
PeriodicEvent.h:81
OpenDDS
The Internal API and Implementation of OpenDDS.
Definition:
AddressCache.h:28
OpenDDS::DCPS::RcHandle< EventDispatcher >
Generated by
1.8.13