8 #ifndef OPENDDS_DCPS_ADDRESSCACHE_H 9 #define OPENDDS_DCPS_ADDRESSCACHE_H 13 #ifndef ACE_LACKS_PRAGMA_ONCE 36 #
if defined ACE_HAS_CPP11
42 #
if defined ACE_HAS_CPP11
43 , addrs_hash_(calculate_hash(
addrs_))
49 #if defined ACE_HAS_CPP11 58 #if defined ACE_HAS_CPP11 59 return entry_ && rhs.
entry_ && entry_->addrs_hash_ == rhs.
entry_->addrs_hash_ && entry_->addrs_ == rhs.
entry_->addrs_;
61 return entry_ && rhs.
entry_ && entry_->addrs_ == rhs.
entry_->addrs_;
66 #if defined ACE_HAS_CPP11 67 return (rhs.
entry_ && (!entry_ || (entry_->addrs_hash_ < rhs.
entry_->addrs_hash_ || (entry_->addrs_hash_ == rhs.
entry_->addrs_hash_ && entry_->addrs_ < rhs.
entry_->addrs_))));
69 return (rhs.
entry_ && (!entry_ || (entry_->addrs_ < rhs.
entry_->addrs_)));
73 const AddrSet&
addrs()
const {
return entry_->addrs_; }
75 #if defined ACE_HAS_CPP11 76 size_t hash()
const noexcept {
return entry_ ? entry_->addrs_hash_ : 0; }
83 template <
typename Key>
87 #if defined ACE_HAS_CPP11 90 typedef OPENDDS_UNORDERED_MAP_T(
GUID_t, KeyVec) IdMapType;
102 : guard_(cache.mutex_)
105 #
if defined ACE_HAS_CPP11
106 , non_const_touch_(false)
112 : guard_(cache.mutex_, block)
115 #
if defined ACE_HAS_CPP11
116 , non_const_touch_(false)
119 const typename MapType::iterator pos = cache.
map_.find(key);
120 if (pos == cache.
map_.end()) {
121 rch_ = make_rch<AddressCacheEntry>();
122 cache.
map_[key] = rch_;
124 key.get_contained_guids(
set);
125 for (GuidSet::const_iterator it =
set.begin(), limit =
set.end(); it != limit; ++it) {
126 cache.
id_map_[*it].push_back(key);
133 if (rch_->expires_ < now) {
134 rch_->addrs_.clear();
142 #if defined ACE_HAS_CPP11 149 #if defined ACE_HAS_CPP11 150 non_const_touch_ =
true;
160 #if defined ACE_HAS_CPP11 161 inline void recalculate_hash() {
162 if (non_const_touch_) {
163 rch_->addrs_hash_ = calculate_hash(rch_->addrs_);
164 non_const_touch_ =
false;
172 #if defined ACE_HAS_CPP11 173 bool non_const_touch_;
182 bool load(
const Key&
key, AddrSet& addrs)
const 185 const typename MapType::const_iterator pos = map_.find(key);
186 if (pos != map_.end()) {
188 const AddrSet& as = pos->second->addrs_;
189 for (AddrSet::const_iterator it = as.begin(), limit = as.end(); it != limit; ++it) {
204 rch->expires_ = expires;
206 rch = make_rch<AddressCacheEntry>(addrs, expires);
208 key.get_contained_guids(
set);
209 for (GuidSet::const_iterator it =
set.begin(), limit =
set.end(); it != limit; ++it) {
210 id_map_[*it].push_back(key);
215 bool remove(
const Key&
key)
218 return map_.erase(
key) != 0;
224 const typename IdMapType::iterator pos = id_map_.find(val);
225 if (pos != id_map_.end()) {
226 for (
typename KeyVec::iterator it = pos->second.begin(), limit = pos->second.end(); it != limit; ++it) {
AddressCacheEntryProxy(RcHandle< AddressCacheEntry > rch)
const AddressCacheEntry & value() const
bool operator<(const AddressCacheEntryProxy &rhs) const
void store(const Key &key, const AddrSet &addrs, const MonotonicTimePoint &expires=MonotonicTimePoint::max_value)
ScopedAccess(AddressCache &cache, const Key &key, bool block=true, const MonotonicTimePoint &now=MonotonicTimePoint::now())
int hash(const std::vector< const DDS::OctetSeq *> &src, DDS::OctetSeq &dst)
#define OPENDDS_ASSERT(C)
ScopedAccess(AddressCache &cache)
static TimePoint_T< MonotonicClock > now()
bool load(const Key &key, AddrSet &addrs) const
void remove_id(const GUID_t &val)
RcObject & operator=(const RcObject &)
typedef OPENDDS_SET_CMP(GUID_t, GUID_tKeyLessThan) GuidSet
bool operator==(const AddressCacheEntryProxy &rhs) const
static const TimePoint_T< MonotonicClock > max_value
RcHandle< AddressCacheEntry > entry_
ACE_Guard< ACE_Thread_Mutex > guard_
AddressCacheEntry(const AddrSet &addrs, const MonotonicTimePoint &expires)
const AddrSet & addrs() const
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
MonotonicTimePoint expires_
typedef OPENDDS_VECTOR(ActionConnectionRecord) ConnectionRecords
RcHandle< AddressCacheEntry > rch_
The Internal API and Implementation of OpenDDS.
AddressCacheEntry & value()