OpenDDS
Snapshot(2023/04/28-20:55)
dds
DCPS
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
13
OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
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
*/
30
class
OpenDDS_Dcps_Export
SporadicEvent
:
public
EventBase
{
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
*/
38
SporadicEvent
(
EventDispatcher_rch
dispatcher,
EventBase_rch
event);
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
68
mutable
ACE_Thread_Mutex
mutex_
;
69
mutable
ACE_Thread_Mutex
event_mutex_
;
70
WeakRcHandle<EventDispatcher>
dispatcher_
;
71
RcHandle<EventBase>
event_
;
72
MonotonicTimePoint
expiration_
;
73
long
timer_id_
;
74
};
75
76
}
// DCPS
77
}
// OpenDDS
78
79
OPENDDS_END_VERSIONED_NAMESPACE_DECL
80
81
#endif // OPENDDS_DCPS_SPORADIC_EVENT_H
ACE_Thread_Mutex
OpenDDS_Dcps_Export
#define OpenDDS_Dcps_Export
Definition:
dcps_export.h:24
OpenDDS::DCPS::SporadicEvent
Definition:
SporadicEvent.h:30
OpenDDS::DCPS::WeakRcHandle
Definition:
RcObject.h:127
OpenDDS::DCPS::TimeDuration
Definition:
TimeDuration.h:29
OpenDDS::DCPS::SporadicEvent::event_mutex_
ACE_Thread_Mutex event_mutex_
Definition:
SporadicEvent.h:69
OpenDDS::DCPS::SporadicEvent::event_
RcHandle< EventBase > event_
Definition:
SporadicEvent.h:71
OpenDDS::DCPS::SporadicEvent::dispatcher_
WeakRcHandle< EventDispatcher > dispatcher_
Definition:
SporadicEvent.h:70
EventDispatcher.h
OpenDDS::DCPS::SporadicEvent::mutex_
ACE_Thread_Mutex mutex_
Definition:
SporadicEvent.h:68
OpenDDS::DCPS::SporadicEvent::timer_id_
long timer_id_
Definition:
SporadicEvent.h:73
OpenDDS::DCPS::EventBase
Definition:
EventDispatcher.h:27
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
The Internal API and Implementation of OpenDDS.
Definition:
AddressCache.h:28
OpenDDS::DCPS::RcHandle< EventDispatcher >
OpenDDS::DCPS::SporadicEvent::expiration_
MonotonicTimePoint expiration_
Definition:
SporadicEvent.h:72
Generated by
1.8.13