OpenDDS  Snapshot(2023/04/28-20:55)
TransportImpl.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 #include "TransportImpl.h"
10 #include "DataLink.h"
11 #include "TransportExceptions.h"
15 #include "dds/DCPS/PublisherImpl.h"
17 #include "dds/DCPS/Util.h"
21 #include "tao/debug.h"
23 
24 #if !defined (__ACE_INLINE__)
25 #include "TransportImpl.inl"
26 #endif /* __ACE_INLINE__ */
27 
29 
30 namespace OpenDDS {
31 namespace DCPS {
32 
34  : config_(config)
35  , event_dispatcher_(make_rch<ServiceEventDispatcher>(1))
36  , is_shut_down_(false)
37 {
38  DBG_ENTRY_LVL("TransportImpl", "TransportImpl", 6);
39  if (TheServiceParticipant->monitor_factory_) {
40  monitor_.reset(TheServiceParticipant->monitor_factory_->create_transport_monitor(this));
41  }
42 }
43 
45 {
46  DBG_ENTRY_LVL("TransportImpl", "~TransportImpl", 6);
48 }
49 
50 bool
52 {
53  return is_shut_down_;
54 }
55 
56 void
58 {
59  DBG_ENTRY_LVL("TransportImpl", "shutdown", 6);
60 
61  is_shut_down_ = true;
62 
63  if (!this->reactor_task_.is_nil()) {
64  this->reactor_task_->stop();
65  }
66 
68 
69  // Tell our subclass about the "shutdown event".
70  this->shutdown_i();
71 }
72 
73 
74 bool
76 {
77  // Success.
78  if (this->monitor_) {
79  this->monitor_->report();
80  }
81 
82  if (Transport_debug_level > 0) {
83 
85  ACE_TEXT("(%P|%t) TransportImpl::open()\n%C"),
86  dump_to_str().c_str()));
87  }
88 
89  return true;
90 }
91 
92 void
94 {
96  pending_connections_.insert( PendConnMap::value_type(client, link) );
97 }
98 
99 void
101 {
102  if (is_shut_down_ || this->reactor_task_.in()) {
103  return;
104  }
105 
106  this->reactor_task_= make_rch<ReactorTask>(useAsyncSend);
107 
109  &TheServiceParticipant->get_thread_status_manager(),
110  name)) {
111  throw Transport::MiscProblem(); // error already logged by TRT::open()
112  }
113 }
114 
115 
116 void
118 {
119  // may be overridden by subclass
120  DBG_ENTRY_LVL("TransportImpl", "unbind_link",6);
121 }
122 
123 bool
125 {
126  DBG_ENTRY_LVL("TransportImpl", "release_link_resources",6);
127 
128  DataLink_rch link_rch = rchandle_from(link);
129  EventBase_rch do_clear = make_rch<DoClear>(link_rch);
130  event_dispatcher_->dispatch(do_clear);
131  return true;
132 }
133 
134 void
136 {
137  if (this->monitor_) {
138  this->monitor_->report();
139  }
140 }
141 
142 void
144 {
146  ACE_TEXT("(%P|%t) TransportImpl::dump() -\n%C"),
147  dump_to_str().c_str()));
148 }
149 
152 {
153  TransportInst_rch cfg = config_.lock();
154  return cfg ? cfg->dump_to_str() : OPENDDS_STRING();
155 }
156 
157 }
158 }
159 
#define ACE_DEBUG(X)
RcHandle< T > rchandle_from(T *pointer)
Definition: RcHandle_T.h:310
EventDispatcher_rch event_dispatcher_
smart ptr to the associated DL cleanup task
TransportImpl(TransportInst_rch config)
void create_reactor_task(bool useAsyncSend=false, const OPENDDS_STRING &name="")
virtual void shutdown_i()=0
RcHandle< T > make_rch()
Definition: RcHandle_T.h:256
#define OPENDDS_STRING
OpenDDS_Dcps_Export unsigned int Transport_debug_level
Transport Logging verbosity level.
Definition: debug.cpp:25
LM_DEBUG
void dump()
Diagnostic aid.
void add_pending_connection(const TransportClient_rch &client, DataLink_rch link)
const char *const name
Definition: debug.cpp:60
LockType pending_connections_lock_
Lock to protect the pending_connections_ data member.
ACE_TEXT("TCP_Factory")
bool release_link_resources(DataLink *link)
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68
virtual void unbind_link(DataLink *link)
Remove any pending_release mappings.
virtual void shutdown(bool immediate=false)=0
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
WeakRcHandle< TransportInst > config_
unique_ptr< Monitor > monitor_
Monitor object for this entity.
virtual bool dispatch(EventBase_rch event)=0
#define TheServiceParticipant
int open_reactor_task(void *, ThreadStatusManager *thread_status_manager=0, const String &name="")
Definition: ReactorTask.cpp:79
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
virtual OPENDDS_STRING dump_to_str() const
AtomicBool is_shut_down_
Id of the last link established.