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