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

#include <ServiceEventDispatcher.h>

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

Public Member Functions

 ServiceEventDispatcher (size_t count=1)
 
virtual ~ServiceEventDispatcher ()
 
void shutdown (bool immediate=false)
 
bool dispatch (EventBase_rch event)
 
long schedule (EventBase_rch event, const MonotonicTimePoint &expiration=MonotonicTimePoint::now())
 
size_t cancel (long id)
 
- Public Member Functions inherited from OpenDDS::DCPS::EventDispatcher
 EventDispatcher ()
 
virtual ~EventDispatcher ()
 
- 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
 

Private Attributes

ACE_Thread_Mutex mutex_
 
DispatchService_rch dispatcher_
 

Additional Inherited Members

- Protected Member Functions inherited from OpenDDS::DCPS::RcObject
 RcObject ()
 

Detailed Description

Definition at line 19 of file ServiceEventDispatcher.h.

Constructor & Destructor Documentation

◆ ServiceEventDispatcher()

OpenDDS::DCPS::ServiceEventDispatcher::ServiceEventDispatcher ( size_t  count = 1)
explicit

Create a ServiceEventDispatcher

Parameters
countthe requested size of the internal thread pool (see DispatchService)

Definition at line 17 of file ServiceEventDispatcher.cpp.

18  : dispatcher_(make_rch<DispatchService>(count))
19 {
20 }

◆ ~ServiceEventDispatcher()

OpenDDS::DCPS::ServiceEventDispatcher::~ServiceEventDispatcher ( )
virtual

Definition at line 22 of file ServiceEventDispatcher.cpp.

References shutdown().

23 {
24  shutdown();
25 }

Member Function Documentation

◆ cancel()

size_t OpenDDS::DCPS::ServiceEventDispatcher::cancel ( long  id)
virtual

Cancel a scheduled event dispatch.

Parameters
idthe id of the event timer to cancel
Returns
the number of canceled events (0 for failure to cancel, 1 for success)

Implements OpenDDS::DCPS::EventDispatcher.

Definition at line 75 of file ServiceEventDispatcher.cpp.

References OpenDDS::DCPS::RcObject::_remove_ref(), OpenDDS::DCPS::DispatchService::cancel(), dispatcher_, OpenDDS::DCPS::EventBase::handle_cancel(), mutex_, and OPENDDS_END_VERSIONED_NAMESPACE_DECL.

76 {
78  if (!dispatcher_) {
79  return 0;
80  }
81  void* arg = 0;
82  const size_t result = dispatcher_->cancel(id, &arg);
83  if (result) {
84  EventBase* ptr = static_cast<EventBase*>(arg);
85  if (ptr) {
86  ptr->handle_cancel();
87  ptr->_remove_ref();
88  }
89  }
90  return result;
91 }
size_t cancel(TimerId id, void **arg=0)

◆ dispatch()

bool OpenDDS::DCPS::ServiceEventDispatcher::dispatch ( EventBase_rch  event)
virtual

Dispatch an event.

Parameters
eventthe event to dispatch
Returns
true if event successfully enqueue, otherwise false

Implements OpenDDS::DCPS::EventDispatcher.

Definition at line 47 of file ServiceEventDispatcher.cpp.

References OpenDDS::DCPS::DispatchService::dispatch(), dispatcher_, and mutex_.

48 {
50  if (!dispatcher_) {
51  return false;
52  }
53  event->_add_ref();
54  const bool result = dispatcher_->dispatch(*event);
55  if (!result) {
56  event->_remove_ref();
57  }
58  return result;
59 }
DispatchStatus dispatch(FunPtr fun, void *arg=0)

◆ schedule()

long OpenDDS::DCPS::ServiceEventDispatcher::schedule ( EventBase_rch  event,
const MonotonicTimePoint expiration = MonotonicTimePoint::now() 
)
virtual

Schedule the future dispatch of an event.

Parameters
eventthe event to dispatch
expirationthe requested dispatch time (no earlier than)
Returns
-1 on a failure, otherwise the timer id for the future dispatch

Implements OpenDDS::DCPS::EventDispatcher.

Definition at line 61 of file ServiceEventDispatcher.cpp.

References dispatcher_, mutex_, and OpenDDS::DCPS::DispatchService::schedule().

62 {
64  if (!dispatcher_) {
65  return -1;
66  }
67  event->_add_ref();
68  const long result = dispatcher_->schedule(*event, expiration);
69  if (result < 0) {
70  event->_remove_ref();
71  }
72  return result;
73 }
TimerId schedule(FunPtr fun, void *arg=0, const MonotonicTimePoint &expiration=MonotonicTimePoint::now())

◆ shutdown()

void OpenDDS::DCPS::ServiceEventDispatcher::shutdown ( bool  immediate = false)
virtual

Request shutdown of this EventDispatcher, which prevents sucessful future calls to either dispatch or schedule and cancels all scheduled events.

Parameters
immediateprevent any further dispatches from event queue, otherwise allow current queue to empty

Implements OpenDDS::DCPS::EventDispatcher.

Definition at line 27 of file ServiceEventDispatcher.cpp.

References OpenDDS::DCPS::RcObject::_remove_ref(), dispatcher_, OpenDDS::DCPS::EventBase::handle_cancel(), mutex_, OpenDDS::DCPS::DispatchService::shutdown(), and OpenDDS::DCPS::RcHandle< T >::swap().

Referenced by ~ServiceEventDispatcher().

28 {
29  DispatchService_rch local;
30  {
32  local.swap(dispatcher_);
33  }
34  if (local) {
35  DispatchService::EventQueue remaining;
36  local->shutdown(immediate, &remaining);
37  for (DispatchService::EventQueue::iterator it = remaining.begin(), limit = remaining.end(); it != limit; ++it) {
38  EventBase* ptr = static_cast<EventBase*>(it->second);
39  if (ptr) {
40  ptr->handle_cancel();
41  ptr->_remove_ref();
42  }
43  }
44  }
45 }
RcHandle< DispatchService > DispatchService_rch

Member Data Documentation

◆ dispatcher_

DispatchService_rch OpenDDS::DCPS::ServiceEventDispatcher::dispatcher_
private

Definition at line 39 of file ServiceEventDispatcher.h.

Referenced by cancel(), dispatch(), schedule(), and shutdown().

◆ mutex_

ACE_Thread_Mutex OpenDDS::DCPS::ServiceEventDispatcher::mutex_
mutableprivate

Definition at line 38 of file ServiceEventDispatcher.h.

Referenced by cancel(), dispatch(), schedule(), and shutdown().


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