OpenDDS  Snapshot(2023/04/28-20:55)
OwnershipManager.h
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 #ifndef OPENDDS_DCPS_OWNERSHIP_MANAGER_H
9 #define OPENDDS_DCPS_OWNERSHIP_MANAGER_H
10 
11 #ifndef OPENDDS_NO_OWNERSHIP_KIND_EXCLUSIVE
12 
13 #include "Definitions.h"
14 #include "GuidUtils.h"
15 #include "InstanceState.h"
16 #include "dds/DdsDcpsInfrastructureC.h"
17 #include "PoolAllocator.h"
18 #include "RcObject.h"
19 
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 #pragma once
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 
25 
26 namespace OpenDDS {
27 namespace DCPS {
28 
29 class DataReaderImpl;
30 
32 public:
33  typedef OPENDDS_SET(DataReaderImpl*) ReaderSet;
34 
35  // TypeInstanceMap is only used for EXCLUSIVE ownership.
36  struct InstanceMap {
39  : map_(map)
40  {
41  readers_.insert(reader);
42  }
43 
45  ReaderSet readers_;
46  };
47 
48  typedef OPENDDS_MAP(OPENDDS_STRING, InstanceMap) TypeInstanceMap;
49 
50  struct WriterInfo {
51  WriterInfo(const GUID_t& pub_id,
52  const CORBA::Long& ownership_strength)
53  : pub_id_(pub_id)
54  , ownership_strength_(ownership_strength)
55  {}
56 
58  : pub_id_(GUID_UNKNOWN)
59  , ownership_strength_(0)
60  {}
61 
64  };
65 
66  typedef OPENDDS_VECTOR(WriterInfo) WriterInfos;
67  typedef OPENDDS_VECTOR(InstanceState_rch) InstanceStateVec;
68 
71  WriterInfos candidates_;
72  InstanceStateVec instance_states_;
73  };
74 
76  InstanceOwnershipWriterInfos;
77 
80 
81  /**
82  * Acquire/release lock for type instance map.
83  * The following functions are synchronized by instance_lock_.
84  */
85  int instance_lock_acquire();
86  int instance_lock_release();
87 
88  /**
89  * The instance map per type is created by the concrete datareader
90  * when first sample with the type is received.
91  */
92  void set_instance_map(const char* type_name,
93  const RcHandle<RcObject>& instance_map,
94  DataReaderImpl* reader);
95 
96  /**
97  * Accesor of the instance map for provided type. It is called once
98  * for each new instance in a datareader.
99  */
100  RcHandle<RcObject> get_instance_map(const char* type_name, DataReaderImpl* reader);
101 
102  /**
103  * The readers that access the instance map are keep tracked as ref
104  * counting to the instance map. The readers need unregister itself
105  * with the instance map upon unregistering instance.The instance map
106  * is deleted upon the last reader unregistering an instance of the
107  * type.
108  */
109  void unregister_reader(const char* type_name,
110  DataReaderImpl* reader);
111 
112  /**
113  * Remove a writer from all instances ownership collection.
114  */
115  void remove_writer(const GUID_t& pub_id);
116 
117  /**
118  * Remove all writers that write to the specified instance.
119  */
120  void remove_writers(const DDS::InstanceHandle_t& instance_handle);
121 
122  /**
123  * Remove a writer that write to the specified instance.
124  * Return true if it's the owner writer removed.
125  */
126  bool remove_writer(const DDS::InstanceHandle_t& instance_handle,
127  const GUID_t& pub_id);
128 
129  /**
130  * Return true if the provide writer is the owner of the instance.
131  */
132  bool is_owner(const DDS::InstanceHandle_t& instance_handle,
133  const GUID_t& pub_id);
134 
135  /**
136  * Determine if the provided publication can be the owner.
137  */
138  bool select_owner(const DDS::InstanceHandle_t& instance_handle,
139  const GUID_t& pub_id,
140  const CORBA::Long& ownership_strength,
141  InstanceState_rch instance_state);
142 
143  /**
144  * Remove an owner of the specified instance.
145  */
146  void remove_owner(const DDS::InstanceHandle_t& instance_handle);
147 
148  void remove_instance(InstanceState* instance_state);
149 
150  /**
151  * Update the ownership strength of a publication.
152  */
153  void update_ownership_strength(const GUID_t& pub_id,
154  const CORBA::Long& ownership_strength);
155 
156 private:
157 
158  bool remove_writer(const DDS::InstanceHandle_t& instance_handle,
159  OwnershipWriterInfos& infos,
160  const GUID_t& pub_id);
161 
162  void remove_owner(const DDS::InstanceHandle_t& instance_handle,
163  OwnershipWriterInfos& infos,
164  bool sort);
165 
166  void remove_candidate(OwnershipWriterInfos& infos,
167  const GUID_t& pub_id);
168 
169  void broadcast_new_owner(const DDS::InstanceHandle_t& instance_handle,
170  OwnershipWriterInfos& infos,
171  const GUID_t& owner);
172 
174  TypeInstanceMap type_instance_map_;
175  InstanceOwnershipWriterInfos instance_ownership_infos_;
176 
177 };
178 
179 } // namespace DCPS
180 } // namespace OpenDDS
181 
183 
184 #endif /* OPENDDS_NO_OWNERSHIP_KIND_EXCLUSIVE */
185 
186 #endif /* OPENDDS_DCPS_OWNERSHIP_MANAGER_H */
manage the states of a received data instance.
Definition: InstanceState.h:49
ACE_CDR::Long Long
const GUID_t GUID_UNKNOWN
Nil value for GUID.
Definition: GuidUtils.h:59
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
#define OPENDDS_STRING
Implements the DDS::DataReader interface.
HANDLE_TYPE_NATIVE InstanceHandle_t
Definition: DdsDcpsCore.idl:51
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
InstanceMap(const RcHandle< RcObject > &map, DataReaderImpl *reader)
typedef OPENDDS_VECTOR(ActionConnectionRecord) ConnectionRecords
WriterInfo(const GUID_t &pub_id, const CORBA::Long &ownership_strength)
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
typedef OPENDDS_MAP(OPENDDS_STRING, OPENDDS_STRING) ValueMap
Helper types and functions for config file parsing.
typedef OPENDDS_SET(NetworkAddress) AddrSet
InstanceOwnershipWriterInfos instance_ownership_infos_