OwnershipManager.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef OPENDDS_DCPS_OWNERSHIP_MANAGER_H
00009 #define OPENDDS_DCPS_OWNERSHIP_MANAGER_H
00010
00011 #ifndef OPENDDS_NO_OWNERSHIP_KIND_EXCLUSIVE
00012
00013 #include "Definitions.h"
00014 #include "GuidUtils.h"
00015 #include "dds/DdsDcpsInfrastructureC.h"
00016 #include "PoolAllocator.h"
00017 #include "RepoIdTypes.h"
00018 #include "RcObject.h"
00019
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 #pragma once
00022 #endif
00023
00024 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00025
00026 namespace OpenDDS {
00027 namespace DCPS {
00028
00029 class InstanceState;
00030 class DataReaderImpl;
00031
00032 class OpenDDS_Dcps_Export OwnershipManager {
00033 public:
00034 typedef OPENDDS_SET(DataReaderImpl*) ReaderSet;
00035
00036
00037 struct InstanceMap {
00038 InstanceMap() {}
00039 InstanceMap(const RcHandle<RcObject>& map, DataReaderImpl* reader)
00040 : map_(map)
00041 {
00042 readers_.insert(reader);
00043 }
00044
00045 RcHandle<RcObject> map_;
00046 ReaderSet readers_;
00047 };
00048
00049 typedef OPENDDS_MAP(OPENDDS_STRING, InstanceMap) TypeInstanceMap;
00050
00051 struct WriterInfo {
00052 WriterInfo(const PublicationId& pub_id,
00053 const CORBA::Long& ownership_strength)
00054 : pub_id_(pub_id)
00055 , ownership_strength_(ownership_strength)
00056 {}
00057
00058 WriterInfo()
00059 : pub_id_(GUID_UNKNOWN)
00060 , ownership_strength_(0)
00061 {}
00062
00063 PublicationId pub_id_;
00064 CORBA::Long ownership_strength_;
00065 };
00066
00067 typedef OPENDDS_VECTOR(WriterInfo) WriterInfos;
00068 typedef OPENDDS_VECTOR(InstanceState*) InstanceStateVec;
00069
00070 struct OwnershipWriterInfos {
00071 WriterInfo owner_;
00072 WriterInfos candidates_;
00073 InstanceStateVec instance_states_;
00074 };
00075
00076 typedef OPENDDS_MAP(DDS::InstanceHandle_t, OwnershipWriterInfos)
00077 InstanceOwnershipWriterInfos;
00078
00079 OwnershipManager();
00080 ~OwnershipManager();
00081
00082
00083
00084
00085
00086 int instance_lock_acquire();
00087 int instance_lock_release();
00088
00089
00090
00091
00092
00093 void set_instance_map(const char* type_name,
00094 const RcHandle<RcObject>& instance_map,
00095 DataReaderImpl* reader);
00096
00097
00098
00099
00100
00101 RcHandle<RcObject> get_instance_map(const char* type_name, DataReaderImpl* reader);
00102
00103
00104
00105
00106
00107
00108
00109
00110 void unregister_reader(const char* type_name,
00111 DataReaderImpl* reader);
00112
00113
00114
00115
00116 void remove_writer(const PublicationId& pub_id);
00117
00118
00119
00120
00121 void remove_writers(const DDS::InstanceHandle_t& instance_handle);
00122
00123
00124
00125
00126
00127 bool remove_writer(const DDS::InstanceHandle_t& instance_handle,
00128 const PublicationId& pub_id);
00129
00130
00131
00132
00133 bool is_owner(const DDS::InstanceHandle_t& instance_handle,
00134 const PublicationId& pub_id);
00135
00136
00137
00138
00139 bool select_owner(const DDS::InstanceHandle_t& instance_handle,
00140 const PublicationId& pub_id,
00141 const CORBA::Long& ownership_strength,
00142 InstanceState* instance_state);
00143
00144
00145
00146
00147 void remove_owner(const DDS::InstanceHandle_t& instance_handle);
00148
00149 void remove_instance(InstanceState* instance_state);
00150
00151
00152
00153
00154 void update_ownership_strength(const PublicationId& pub_id,
00155 const CORBA::Long& ownership_strength);
00156
00157 private:
00158
00159 bool remove_writer(const DDS::InstanceHandle_t& instance_handle,
00160 OwnershipWriterInfos& infos,
00161 const PublicationId& pub_id);
00162
00163 void remove_owner(const DDS::InstanceHandle_t& instance_handle,
00164 OwnershipWriterInfos& infos,
00165 bool sort);
00166
00167 void remove_candidate(OwnershipWriterInfos& infos,
00168 const PublicationId& pub_id);
00169
00170 void broadcast_new_owner(const DDS::InstanceHandle_t& instance_handle,
00171 OwnershipWriterInfos& infos,
00172 const PublicationId& owner);
00173
00174 ACE_Thread_Mutex instance_lock_;
00175 TypeInstanceMap type_instance_map_;
00176 InstanceOwnershipWriterInfos instance_ownership_infos_;
00177
00178 };
00179
00180 }
00181 }
00182
00183 OPENDDS_END_VERSIONED_NAMESPACE_DECL
00184
00185 #endif
00186
00187 #endif