Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AutoPacket::HasPublishers #617

Merged
merged 1 commit into from
Jun 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions autowiring/AutoPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ class AutoPacket:
/// <returns>True if the indicated type has been requested for use by some consumer</returns>
bool HasSubscribers(const DecorationKey& key) const;

/// <returns>Zero if there are no publishers, otherwise the number of publishers</returns>
size_t HasPublishers(const DecorationKey& key) const;

/// <returns>A reference to the satisfaction counter for the specified type</returns>
/// <remarks>
/// If the type is not a subscriber GetSatisfaction().GetType() == nullptr will be true
Expand Down Expand Up @@ -529,9 +532,15 @@ class AutoPacket:
std::shared_ptr<AutoPacket> Successor(void);

/// <returns>True if the indicated type has been requested for use by some consumer</returns>
template<class T>
template<typename T>
bool HasSubscribers(void) const {
return HasSubscribers(DecorationKey(auto_id<T>::key(), 0));
return HasSubscribers(DecorationKey{auto_id<T>::key(), 0});
}

/// <returns>Zero if there are no publishers, otherwise the number of publishers</returns>
template<typename T>
size_t HasPublishers(void) const {
return HasPublishers(DecorationKey{auto_id<T>::key(), 0});
}

struct SignalStub {
Expand Down
15 changes: 14 additions & 1 deletion src/autowiring/AutoPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,20 @@ const DecorationDisposition* AutoPacket::GetDisposition(const DecorationKey& key

bool AutoPacket::HasSubscribers(const DecorationKey& key) const {
std::lock_guard<std::mutex> lk(m_lock);
return m_decorations.count(key) != 0;
auto q = m_decorations.find(key);
return
q == m_decorations.end() ?
false :
q->second.m_subscribers.size() != 0;
}

size_t AutoPacket::HasPublishers(const DecorationKey& key) const {
std::lock_guard<std::mutex> lk(m_lock);
auto q = m_decorations.find(key);
return
q == m_decorations.end() ?
0 :
q->second.m_publishers.size();
}

const SatCounter& AutoPacket::GetSatisfaction(const std::type_info& subscriber) const {
Expand Down