OpenDDS  Snapshot(2023/04/28-20:55)
ServiceEventDispatcher.cpp
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 #include "DCPS/DdsDcps_pch.h" //Only the _pch include should start with DCPS/
9 
10 #include "ServiceEventDispatcher.h"
11 
13 
14 namespace OpenDDS {
15 namespace DCPS {
16 
18  : dispatcher_(make_rch<DispatchService>(count))
19 {
20 }
21 
23 {
24  shutdown();
25 }
26 
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 }
46 
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 }
60 
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 }
74 
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 }
92 
93 } // DCPS
94 } // OpenDDS
95 
size_t cancel(TimerId id, void **arg=0)
RcHandle< T > make_rch()
Definition: RcHandle_T.h:256
DispatchStatus dispatch(FunPtr fun, void *arg=0)
long schedule(EventBase_rch event, const MonotonicTimePoint &expiration=MonotonicTimePoint::now())
void swap(RcHandle &rhs)
Definition: RcHandle_T.h:102
virtual void _remove_ref()
Definition: RcObject.h:74
TimerId schedule(FunPtr fun, void *arg=0, const MonotonicTimePoint &expiration=MonotonicTimePoint::now())
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
void shutdown(bool immediate=false, EventQueue *pending=0)
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28