| 14 | } |
| 15 | |
| 16 | GuidPartitionTable::Result GuidPartitionTable::insert(const OpenDDS::DCPS::GUID_t& guid, |
| 17 | const DDS::StringSeq& partitions) |
| 18 | { |
| 19 | Result result; |
| 20 | std::vector<RelayPartitions> relay_partitions; |
| 21 | |
| 22 | { |
| 23 | ACE_GUARD_RETURN(ACE_Thread_Mutex, g, mutex_, NO_CHANGE); |
| 24 | |
| 25 | StringSet parts; |
| 26 | for (CORBA::ULong idx = 0; idx != partitions.length(); ++idx) { |
| 27 | parts.insert(partitions[idx].in()); |
| 28 | } |
| 29 | if (parts.empty()) { |
| 30 | // Special case for empty list of partitions. |
| 31 | parts.insert(""); |
| 32 | } |
| 33 | |
| 34 | const auto r = guid_to_partitions_.insert(std::make_pair(guid, StringSet())); |
| 35 | result = r.second ? ADDED : UPDATED; |
| 36 | auto& x = r.first->second; |
| 37 | |
| 38 | std::vector<std::string> to_add; |
| 39 | std::set_difference(parts.begin(), parts.end(), x.begin(), x.end(), std::back_inserter(to_add)); |
| 40 | |
| 41 | std::vector<std::string> to_remove; |
| 42 | std::set_difference(x.begin(), x.end(), parts.begin(), parts.end(), std::back_inserter(to_remove)); |
| 43 | |
| 44 | if (to_add.empty() && to_remove.empty()) { |
| 45 | if (result == ADDED) { |
| 46 | relay_stats_reporter_.partition_guids(guid_to_partitions_.size(), guid_to_partitions_cache_.size()); |
| 47 | } |
| 48 | return NO_CHANGE; |
| 49 | } |
| 50 | |
| 51 | remove_from_cache(guid); |
| 52 | |
| 53 | StringSet globally_new; |
| 54 | x.insert(to_add.begin(), to_add.end()); |
| 55 | for (const auto& part : to_add) { |
| 56 | const auto q = partition_to_guid_.insert(std::make_pair(part, OrderedGuidSet())); |
| 57 | q.first->second.insert(guid); |
| 58 | partition_index_.insert(part, guid); |
| 59 | if (q.second) { |
| 60 | globally_new.insert(part); |
| 61 | } |
| 62 | } |
| 63 | for (const auto& part : to_remove) { |
| 64 | x.erase(part); |
| 65 | partition_to_guid_[part].erase(guid); |
| 66 | partition_index_.remove(part, guid); |
| 67 | if (partition_to_guid_[part].empty()) { |
| 68 | partition_to_guid_.erase(part); |
| 69 | } |
| 70 | } |
| 71 | if (x.empty()) { |
| 72 | guid_to_partitions_.erase(r.first); |
| 73 | } |
no test coverage detected