OpenDDS  Snapshot(2023/04/07-19:43)
Classes | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
OpenDDS::DCPS::SporadicTask Class Referenceabstract

#include <SporadicTask.h>

Inheritance diagram for OpenDDS::DCPS::SporadicTask:
Inheritance graph
[legend]
Collaboration diagram for OpenDDS::DCPS::SporadicTask:
Collaboration graph
[legend]

Classes

struct  SporadicCommand
 

Public Member Functions

 SporadicTask (const TimeSource &time_source, RcHandle< ReactorInterceptor > interceptor)
 
virtual ~SporadicTask ()
 
void schedule (const TimeDuration &delay)
 
void cancel ()
 
virtual void execute (const MonotonicTimePoint &now)=0
 
- Public Member Functions inherited from OpenDDS::DCPS::RcEventHandler
 RcEventHandler ()
 
ACE_Event_Handler::Reference_Count add_reference ()
 
ACE_Event_Handler::Reference_Count remove_reference ()
 
- Public Member Functions inherited from ACE_Event_Handler
virtual ~ACE_Event_Handler (void)
 
virtual ACE_HANDLE get_handle (void) const
 
virtual void set_handle (ACE_HANDLE)
 
virtual int priority (void) const
 
virtual void priority (int priority)
 
virtual int handle_input (ACE_HANDLE fd=ACE_INVALID_HANDLE)
 
virtual int handle_output (ACE_HANDLE fd=ACE_INVALID_HANDLE)
 
virtual int handle_exception (ACE_HANDLE fd=ACE_INVALID_HANDLE)
 
virtual int handle_exit (ACE_Process *)
 
virtual int handle_close (ACE_HANDLE handle, ACE_Reactor_Mask close_mask)
 
virtual int handle_signal (int signum, siginfo_t *=0, ucontext_t *=0)
 
virtual int resume_handler (void)
 
virtual int handle_qos (ACE_HANDLE=ACE_INVALID_HANDLE)
 
virtual int handle_group_qos (ACE_HANDLE=ACE_INVALID_HANDLE)
 
virtual void reactor (ACE_Reactor *reactor)
 
virtual ACE_Reactorreactor (void) const
 
virtual ACE_Reactor_Timer_Interfacereactor_timer_interface (void) const
 
Reference_Counting_Policyreference_counting_policy (void)
 
- Public Member Functions inherited from OpenDDS::DCPS::RcObject
virtual ~RcObject ()
 
virtual void _add_ref ()
 
virtual void _remove_ref ()
 
long ref_count () const
 
WeakObject_get_weak_object () const
 

Protected Member Functions

long get_timer_id ()
 
- Protected Member Functions inherited from ACE_Event_Handler
 ACE_Event_Handler (ACE_Reactor *=0, int priority=ACE_Event_Handler::LO_PRIORITY)
 
- Protected Member Functions inherited from OpenDDS::DCPS::RcObject
 RcObject ()
 

Private Member Functions

void execute_i ()
 
int handle_timeout (const ACE_Time_Value &tv, const void *)
 

Private Attributes

const TimeSourcetime_source_
 
WeakRcHandle< ReactorInterceptorinterceptor_
 
bool desired_scheduled_
 
MonotonicTimePoint desired_next_time_
 
TimeDuration desired_delay_
 
long timer_id_
 
MonotonicTimePoint actual_next_time_
 
RcHandle< SporadicCommandsporadic_command_
 
ACE_Thread_Mutex mutex_
 

Additional Inherited Members

- Public Types inherited from ACE_Event_Handler
typedef long Reference_Count
 
- Static Public Member Functions inherited from ACE_Event_Handler
static ACE_THR_FUNC_RETURN read_adapter (void *event_handler)
 
static int register_stdin_handler (ACE_Event_Handler *eh, ACE_Reactor *reactor, ACE_Thread_Manager *thr_mgr, int flags=THR_DETACHED)
 
static int remove_stdin_handler (ACE_Reactor *reactor, ACE_Thread_Manager *thr_mgr)
 
- Public Attributes inherited from ACE_Event_Handler
 LO_PRIORITY
 
 HI_PRIORITY
 
 NULL_MASK
 
 READ_MASK
 
 WRITE_MASK
 
 EXCEPT_MASK
 
 ACCEPT_MASK
 
 CONNECT_MASK
 
 TIMER_MASK
 
 QOS_MASK
 
 GROUP_QOS_MASK
 
 SIGNAL_MASK
 
 ALL_EVENTS_MASK
 
 RWE_MASK
 
 DONT_CALL
 
 ACE_EVENT_HANDLER_NOT_RESUMED
 
 ACE_REACTOR_RESUMES_HANDLER
 
 ACE_APPLICATION_RESUMES_HANDLER
 
- Protected Types inherited from ACE_Event_Handler
typedef ACE_Atomic_Op< ACE_SYNCH_MUTEX, Reference_CountAtomic_Reference_Count
 
- Protected Attributes inherited from ACE_Event_Handler
Atomic_Reference_Count reference_count_
 

Detailed Description

Definition at line 21 of file SporadicTask.h.

Constructor & Destructor Documentation

◆ SporadicTask()

OpenDDS::DCPS::SporadicTask::SporadicTask ( const TimeSource time_source,
RcHandle< ReactorInterceptor interceptor 
)
inline

Definition at line 23 of file SporadicTask.h.

References ACE_Event_Handler::reactor(), and OpenDDS::DCPS::ReactorInterceptor::reactor().

25  : time_source_(time_source)
26  , interceptor_(interceptor)
27  , desired_scheduled_(false)
28  , timer_id_(-1)
29  , sporadic_command_(make_rch<SporadicCommand>(rchandle_from(this)))
30  {
31  reactor(interceptor->reactor());
32  }
virtual ACE_Reactor * reactor(void) const
RcHandle< SporadicCommand > sporadic_command_
Definition: SporadicTask.h:110
virtual void reactor(ACE_Reactor *reactor)
RcHandle< T > rchandle_from(T *pointer)
Definition: RcHandle_T.h:310
WeakRcHandle< ReactorInterceptor > interceptor_
Definition: SporadicTask.h:104
const TimeSource & time_source_
Definition: SporadicTask.h:103

◆ ~SporadicTask()

virtual OpenDDS::DCPS::SporadicTask::~SporadicTask ( )
inlinevirtual

Definition at line 34 of file SporadicTask.h.

34 {}

Member Function Documentation

◆ cancel()

void OpenDDS::DCPS::SporadicTask::cancel ( void  )
inline

Definition at line 60 of file SporadicTask.h.

References ACE_ERROR, desired_scheduled_, OpenDDS::DCPS::LogLevel::Error, execute(), OpenDDS::DCPS::ReactorInterceptor::execute_or_enqueue(), interceptor_, LM_ERROR, OpenDDS::DCPS::log_level, mutex_, and sporadic_command_.

Referenced by OpenDDS::Security::AccessControlBuiltInImpl::RevokePermissionsTask::insert().

61  {
62  {
64  if (!desired_scheduled_) {
65  return;
66  }
67 
68  desired_scheduled_ = false;
69  }
70 
71  RcHandle<ReactorInterceptor> interceptor = interceptor_.lock();
72  if (interceptor) {
73  interceptor->execute_or_enqueue(sporadic_command_);
74  } else if (log_level >= LogLevel::Error) {
75  ACE_ERROR((LM_ERROR,
76  "(%P|%t) ERROR: SporadicTask::cancel: "
77  "failed to receive ReactorInterceptor handle\n"));
78  }
79  }
OpenDDS_Dcps_Export LogLevel log_level
#define ACE_ERROR(X)
RcHandle< SporadicCommand > sporadic_command_
Definition: SporadicTask.h:110
WeakRcHandle< ReactorInterceptor > interceptor_
Definition: SporadicTask.h:104

◆ execute()

virtual void OpenDDS::DCPS::SporadicTask::execute ( const MonotonicTimePoint now)
pure virtual

◆ execute_i()

void OpenDDS::DCPS::SporadicTask::execute_i ( )
inlineprivate

Definition at line 113 of file SporadicTask.h.

References ACE_ERROR, ACE_Reactor::cancel_timer(), desired_next_time_, OpenDDS::DCPS::LogLevel::Error, LM_ERROR, OpenDDS::DCPS::log_level, OpenDDS::DCPS::ReactorInterceptor::Command::reactor(), ACE_Reactor::schedule_timer(), and OpenDDS::DCPS::TimeDuration::value().

114  {
116 
117  if ((!desired_scheduled_ && timer_id_ != -1) ||
120  timer_id_ = -1;
121  }
122 
123  if (desired_scheduled_ && timer_id_ == -1) {
125  if (timer_id_ == -1) {
126  if (log_level >= LogLevel::Error) {
127  ACE_ERROR((LM_ERROR,
128  "(%P|%t) ERROR: SporadicTask::execute_i: "
129  "failed to schedule timer %p\n", ""));
130  }
131  } else {
133  }
134  }
135  }
OpenDDS_Dcps_Export LogLevel log_level
#define ACE_ERROR(X)
const ACE_Time_Value & value() const
MonotonicTimePoint desired_next_time_
Definition: SporadicTask.h:106
MonotonicTimePoint actual_next_time_
Definition: SporadicTask.h:109
virtual long schedule_timer(ACE_Event_Handler *event_handler, const void *arg, const ACE_Time_Value &delay, const ACE_Time_Value &interval=ACE_Time_Value::zero)
virtual ACE_Reactor * reactor(void) const
virtual int cancel_timer(long timer_id, const void **arg=0, int dont_call_handle_close=1)

◆ get_timer_id()

long OpenDDS::DCPS::SporadicTask::get_timer_id ( )
inlineprotected

Definition at line 84 of file SporadicTask.h.

References timer_id_.

84 { return timer_id_; }

◆ handle_timeout()

int OpenDDS::DCPS::SporadicTask::handle_timeout ( const ACE_Time_Value tv,
const void *   
)
inlineprivatevirtual

Reimplemented from ACE_Event_Handler.

Definition at line 137 of file SporadicTask.h.

References OpenDDS::DCPS::SporadicTask::SporadicCommand::execute(), and TheServiceParticipant.

138  {
139  ThreadStatusManager::Event ev(TheServiceParticipant->get_thread_status_manager());
140 
141  const MonotonicTimePoint now(tv);
142  {
144  desired_scheduled_ = false;
145  timer_id_ = -1;
146  }
147  execute(now);
148  return 0;
149  }
virtual void execute(const MonotonicTimePoint &now)=0
TimePoint_T< MonotonicClock > MonotonicTimePoint
Definition: TimeTypes.h:51
#define TheServiceParticipant

◆ schedule()

void OpenDDS::DCPS::SporadicTask::schedule ( const TimeDuration delay)
inline

Definition at line 36 of file SporadicTask.h.

References ACE_ERROR, desired_delay_, desired_next_time_, desired_scheduled_, OpenDDS::DCPS::LogLevel::Error, OpenDDS::DCPS::ReactorInterceptor::execute_or_enqueue(), interceptor_, LM_ERROR, OpenDDS::DCPS::log_level, OpenDDS::DCPS::TimeSource::monotonic_time_point_now(), mutex_, sporadic_command_, and time_source_.

Referenced by OpenDDS::Security::AccessControlBuiltInImpl::RevokePermissionsTask::execute(), and OpenDDS::Security::AccessControlBuiltInImpl::RevokePermissionsTask::insert().

37  {
38  const MonotonicTimePoint next_time = time_source_.monotonic_time_point_now() + delay;
39  {
41  if (!desired_scheduled_ || next_time < desired_next_time_) {
42  desired_scheduled_ = true;
43  desired_next_time_ = next_time;
44  desired_delay_ = delay;
45  } else {
46  return;
47  }
48  }
49 
50  RcHandle<ReactorInterceptor> interceptor = interceptor_.lock();
51  if (interceptor) {
52  interceptor->execute_or_enqueue(sporadic_command_);
53  } else if (log_level >= LogLevel::Error) {
54  ACE_ERROR((LM_ERROR,
55  "(%P|%t) ERROR: SporadicTask::schedule: "
56  "failed to receive ReactorInterceptor handle\n"));
57  }
58  }
OpenDDS_Dcps_Export LogLevel log_level
#define ACE_ERROR(X)
MonotonicTimePoint desired_next_time_
Definition: SporadicTask.h:106
virtual MonotonicTimePoint monotonic_time_point_now() const
Definition: TimeSource.h:26
RcHandle< SporadicCommand > sporadic_command_
Definition: SporadicTask.h:110
TimePoint_T< MonotonicClock > MonotonicTimePoint
Definition: TimeTypes.h:51
WeakRcHandle< ReactorInterceptor > interceptor_
Definition: SporadicTask.h:104
const TimeSource & time_source_
Definition: SporadicTask.h:103

Member Data Documentation

◆ actual_next_time_

MonotonicTimePoint OpenDDS::DCPS::SporadicTask::actual_next_time_
private

Definition at line 109 of file SporadicTask.h.

◆ desired_delay_

TimeDuration OpenDDS::DCPS::SporadicTask::desired_delay_
private

Definition at line 107 of file SporadicTask.h.

Referenced by schedule().

◆ desired_next_time_

MonotonicTimePoint OpenDDS::DCPS::SporadicTask::desired_next_time_
private

Definition at line 106 of file SporadicTask.h.

Referenced by execute_i(), and schedule().

◆ desired_scheduled_

bool OpenDDS::DCPS::SporadicTask::desired_scheduled_
private

Definition at line 105 of file SporadicTask.h.

Referenced by cancel(), and schedule().

◆ interceptor_

WeakRcHandle<ReactorInterceptor> OpenDDS::DCPS::SporadicTask::interceptor_
private

Definition at line 104 of file SporadicTask.h.

Referenced by cancel(), and schedule().

◆ mutex_

ACE_Thread_Mutex OpenDDS::DCPS::SporadicTask::mutex_
mutableprivate

Definition at line 111 of file SporadicTask.h.

Referenced by cancel(), and schedule().

◆ sporadic_command_

RcHandle<SporadicCommand> OpenDDS::DCPS::SporadicTask::sporadic_command_
private

Definition at line 110 of file SporadicTask.h.

Referenced by cancel(), and schedule().

◆ time_source_

const TimeSource& OpenDDS::DCPS::SporadicTask::time_source_
private

Definition at line 103 of file SporadicTask.h.

Referenced by schedule().

◆ timer_id_

long OpenDDS::DCPS::SporadicTask::timer_id_
private

Definition at line 108 of file SporadicTask.h.

Referenced by get_timer_id().


The documentation for this class was generated from the following file: