MCPcopy Create free account
hub / github.com/OpenDDS/OpenDDS / select_owner

Method select_owner

dds/DCPS/OwnershipManager.cpp:283–379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

281}
282
283bool
284OwnershipManager::select_owner(const DDS::InstanceHandle_t& instance_handle,
285 const GUID_t& pub_id,
286 const CORBA::Long& ownership_strength,
287 InstanceState_rch instance_state)
288{
289 ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, instance_lock_, false);
290
291 InstanceOwnershipWriterInfos::iterator iter =
292 instance_ownership_infos_.find(instance_handle);
293 if (iter != instance_ownership_infos_.end()) {
294 OwnershipWriterInfos& infos = iter->second;
295 if (!instance_state->registered()) {
296 infos.instance_states_.push_back(instance_state);
297 instance_state->registered(true);
298 }
299
300 // No owner at some point.
301 if (infos.owner_.pub_id_ == GUID_UNKNOWN) {
302 infos.owner_ = WriterInfo(pub_id, ownership_strength);
303 broadcast_new_owner(instance_handle, infos, pub_id);
304 return true;
305
306 } else if (infos.owner_.pub_id_ == pub_id) { // is current owner
307 //still owner but strength changed to be bigger..
308 if (infos.owner_.ownership_strength_ <= ownership_strength) {
309 infos.owner_.ownership_strength_ = ownership_strength;
310 return true;
311
312 } else { //update strength and reevaluate owner which broadcast new owner.
313 infos.candidates_.push_back(WriterInfo(pub_id, ownership_strength));
314 remove_owner(instance_handle, infos, true);
315 return infos.owner_.pub_id_ == pub_id;
316 }
317
318 } else { // not current owner, reevaluate the owner
319 bool replace_owner = false;
320 // Add current owner to candidate list for owner reevaluation
321 // if provided pub has strength greater than current owner.
322 if (ownership_strength > infos.owner_.ownership_strength_) {
323 infos.candidates_.push_back(infos.owner_);
324 replace_owner = true;
325 }
326
327 bool found = false;
328 bool sort = true;
329
330 // check if it already existed in candidate list. If not,
331 // add it to the candidate list, otherwise update strength
332 // if strength was changed.
333 const WriterInfos::iterator the_end = infos.candidates_.end();
334
335 for (WriterInfos::iterator it = infos.candidates_.begin(); it != the_end; ++it) {
336 if (it->pub_id_ == pub_id) {
337 if (it->ownership_strength_ != ownership_strength) {
338 it->ownership_strength_ = ownership_strength;
339 } else {
340 sort = false;

Callers 1

Calls 5

registeredMethod · 0.80
WriterInfoClass · 0.70
findMethod · 0.45
endMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected