OpenDDS  Snapshot(2023/04/28-20:55)
DataLinkSet.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 "DataLinkSet.h"
10 #include "DataLinkSet_rch.h"
11 
12 #include "dds/DCPS/GuidConverter.h"
13 #include "dds/DCPS/Util.h"
14 #include "TransportImpl.h"
15 #include "TransportSendListener.h"
16 
17 #include "EntryExit.h"
18 
19 #if !defined (__ACE_INLINE__)
20 #include "DataLinkSet.inl"
21 #endif /* __ACE_INLINE__ */
22 
23 //TBD: The number of chunks in send control cached allocator and map
24 // entry allocator are hard coded for now. These values will be
25 // configured when we implement the dds configurations.
26 
27 /// The number of chuncks in send control cached allocator per pub/sub.
28 #define NUM_SEND_CONTROL_ELEMENT_CHUNKS 20
29 
31  : send_response_listener_("DataLinkSet")
32 {
33  DBG_ENTRY_LVL("DataLinkSet","DataLinkSet",6);
34 }
35 
37 {
38  DBG_ENTRY_LVL("DataLinkSet","~DataLinkSet",6);
39 }
40 
41 int
43 {
44  DBG_ENTRY_LVL("DataLinkSet","insert_link",6);
45  GuardType guard(this->lock_);
46  return OpenDDS::DCPS::bind(map_, link->id(), link);
47 }
48 
49 void
51 {
52  DBG_ENTRY_LVL("DataLinkSet", "remove_link", 6);
53  GuardType guard1(this->lock_);
54  if (unbind(map_, link->id()) != 0) {
55  // Just report to the log that we tried.
56  VDBG((LM_DEBUG,
57  ACE_TEXT("(%P|%t) DataLinkSet::remove_links: ")
58  ACE_TEXT("link_id %d not found in map.\n"),
59  link->id()));
60  }
61 }
62 
65  const CORBA::ULong num_targets)
66 {
67  DBG_ENTRY_LVL("DataLinkSet","select_links",6);
68 
69  DataLinkSet_rch selected_links ( make_rch<DataLinkSet>() );
70  GuardType guard(this->lock_);
71  for (MapType::iterator itr = map_.begin();
72  itr != map_.end();
73  ++itr) {
74  for (CORBA::ULong i = 0; i < num_targets; ++i) {
75  if (itr->second->is_target(remoteIds[i])) {
76  OpenDDS::DCPS::bind(selected_links->map_,
77  itr->second->id(), itr->second);
78  break;
79  }
80  }
81  }
82 
83  return selected_links;
84 }
85 
86 bool
88 {
89  GuardType guard(this->lock_);
90 
91  return map_.empty();
92 }
93 
95 {
96  MapType map_copy;
97  {
98  GuardType guard(lock_);
99  map_copy = map_;
100  }
101  for (MapType::iterator itr = map_copy.begin();
102  itr != map_copy.end(); ++itr) {
103  itr->second->terminate_send_if_suspended();
104  }
105 }
106 
108  const GUID_t& reader_id) const
109 {
110  GuardType guard(this->lock_);
111  for (MapType::const_iterator pos = map_.begin(), limit = map_.end(); pos != limit; ++pos) {
112  if (pos->second->is_leading(writer_id, reader_id)) {
113  return true;
114  }
115  }
116 
117  return false;
118 }
void remove_link(const DataLink_rch &link)
Definition: DataLinkSet.cpp:50
MapType map_
Hash map for DataLinks.
Definition: DataLinkSet.h:96
int bind(Container &c, const FirstType &first, const SecondType &second)
Definition: Util.h:20
bool is_leading(const GUID_t &writer_id, const GUID_t &reader_id) const
LM_DEBUG
ACE_CDR::ULong ULong
int insert_link(const DataLink_rch &link)
Definition: DataLinkSet.cpp:42
#define VDBG(DBG_ARGS)
DataLinkSet_rch select_links(const GUID_t *remoteIds, const CORBA::ULong num_targets)
Definition: DataLinkSet.cpp:64
DataLinkIdType id() const
Obtain a unique identifier for this DataLink object.
Definition: DataLink.inl:205
ACE_TEXT("TCP_Factory")
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68
int unbind(Container &c, const typename Container::key_type &k, typename Container::mapped_type &v)
Definition: Util.h:40