OpenDDS  Snapshot(2023/04/28-20:55)
TransportSendControlElement.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 
11 #include "TransportSendListener.h"
12 #include "EntryExit.h"
13 
15 
16 #if !defined (__ACE_INLINE__)
18 #endif /* __ACE_INLINE__ */
19 
21 
22 namespace OpenDDS {
23 namespace DCPS {
24 
25 
27  const GUID_t& publisher_id,
28  TransportSendListener* listener,
29  const DataSampleHeader& header,
30  Message_Block_Ptr msg_block)
31  : TransportQueueElement(initial_count),
32  publisher_id_(publisher_id),
33  listener_(listener),
34  header_(header),
35  msg_(msg_block.release()),
36  dcps_elem_(0)
37 {
38  DBG_ENTRY_LVL("TransportSendControlElement", "TransportSendControlElement", 6);
39 }
40 
41 
43  const DataSampleElement* dcps_elem)
44  : TransportQueueElement(initial_count)
45  , publisher_id_(dcps_elem->get_pub_id())
46  , listener_(dcps_elem->get_send_listener())
47  , header_(dcps_elem->get_header())
48  , dcps_elem_(dcps_elem)
49 {
50  DBG_ENTRY_LVL("TransportSendControlElement", "TransportSendControlElement", 6);
51 }
52 
54 {
55  DBG_ENTRY_LVL("TransportSendControlElement", "~TransportSendControlElement", 6);
56 }
57 
58 bool
60 {
61  DBG_ENTRY_LVL("TransportSendControlElement", "requires_exclusive_packet", 6);
62  return true;
63 }
64 
65 namespace
66 {
67  void handle_message(const bool dropped,
68  const Message_Block_Ptr& msg,
70  const bool dropped_by_transport)
71  {
72  if (dropped) {
73  listener->control_dropped(msg, dropped_by_transport);
74  } else {
75  listener->control_delivered(msg);
76  }
77  }
78 
79  void handle_message(const bool dropped,
80  const DataSampleElement* elem,
81  const bool dropped_by_transport)
82  {
83  TransportSendListener* const listener = elem->get_send_listener();
84  if (dropped) {
85  listener->data_dropped(elem, dropped_by_transport);
86  } else {
87  listener->data_delivered(elem);
88  }
89  }
90 }
91 
92 void
94 {
95  ACE_UNUSED_ARG(dropped_by_transport);
96 
97  DBG_ENTRY_LVL("TransportSendControlElement", "release_element", 6);
98 
99  // store off local copies to use after "this" pointer deleted
100  const bool dropped = was_dropped();
101 
103 
105  const DataSampleElement* dcps_elem = dcps_elem_;
106 
107 
108  delete this;
109 
110 
111  // reporting the message w/o using "this" pointer
112  if (dcps_elem) {
113  handle_message(dropped, dcps_elem, dropped_by_transport);
114  } else {
115  handle_message(dropped, msg, listener, dropped_by_transport);
116  }
117 }
118 
119 GUID_t
121 {
122  DBG_ENTRY_LVL("TransportSendControlElement", "publication_id", 6);
123  return publisher_id_;
124 }
125 
128 {
129  DBG_ENTRY_LVL("TransportSendControlElement", "duplicate_msg", 6);
130  if (dcps_elem_) {
131  return const_cast<DataSampleElement*>(dcps_elem_)->get_sample()->duplicate();
132  }
133  return msg_->duplicate();
134 }
135 
136 const ACE_Message_Block*
138 {
139  DBG_ENTRY_LVL("TransportSendControlElement", "msg", 6);
140  if (dcps_elem_) {
141  return dcps_elem_->get_sample();
142  }
143  return msg_.get();
144 }
145 
146 const ACE_Message_Block*
148 {
149  DBG_ENTRY_LVL("TransportSendControlElement", "msg_payload", 6);
150  return msg()->cont();
151 }
152 
153 bool
155 {
156  return (pub_id == publisher_id_);
157 }
158 
159 }
160 }
161 
virtual const ACE_Message_Block * msg() const
Accessor for the ACE_Message_Block.
virtual ACE_Message_Block * duplicate_msg() const
A reference-incremented duplicate of the marshalled sample (sample header + sample data) ...
void release(T x)
TransportSendListener * get_send_listener() const
virtual bool is_control(GUID_t pub_id) const
Is the element a "control" sample from the specified pub_id?
GUID_t publisher_id_
The publisher of the control message.
virtual GUID_t publication_id() const
Accessor for the publisher id.
const TransportSendListener * listener() const
Message_Block_Ptr msg_
The control message.
Christopher Diggins *renamed files *fixing compilation errors *adding Visual C project file *removed make Max Lybbert *removed references to missing and unused header
Definition: CHANGELOG.txt:8
DataSampleHeader header_
The OpenDDS DCPS header for this control message.
virtual const ACE_Message_Block * msg_payload() const
The marshalled payload only (sample data)
virtual void data_dropped(const DataSampleElement *sample, bool dropped_by_transport)
ACE_Message_Block * cont(void) const
virtual ACE_Message_Block * duplicate(void) const
virtual void release_element(bool dropped_by_transport)
Invoked when the counter reaches 0.
virtual void control_delivered(const Message_Block_Ptr &sample)
TransportSendListener * listener_
The TransportSendListener object to call back upon.
const DataSampleElement *const dcps_elem_
If constructed from a DataSampleElement, keep it around for release.
TransportSendControlElement(int initial_count, const GUID_t &publisher_id, TransportSendListener *listener, const DataSampleHeader &header, Message_Block_Ptr msg_block)
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
virtual bool requires_exclusive_packet() const
Overridden to always return true for Send Control elements.
virtual void control_dropped(const Message_Block_Ptr &sample, bool dropped_by_transport)
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
virtual void data_delivered(const DataSampleElement *sample)
Base wrapper class around a data/control sample to be sent.