This commit is contained in:
Matthias Janetschek
2015-06-01 16:33:09 +02:00
parent 03d71034f8
commit 8de7d5b10c
8 changed files with 292 additions and 144 deletions
@@ -324,7 +324,7 @@ public:
* \param[in] e event.
* \return notified observer count.
*/
size_t notifyObservers(const _Key& k, const _Event* e) noexcept override {
virtual size_t notifyObservers(const _Key& k, const _Event* e) noexcept override {
std::lock_guard<std::recursive_mutex> lock(_observersMutex);
size_t retval = 0;
// We work with a copy so that we can insert/remove observers within a callback.
@@ -337,6 +337,27 @@ public:
return retval;
}
/**
* Notify observers of a new event.
*
* \param[in] key observer filter key.
* \param[in] substkey key that is send to the observers.
* \param[in] e event.
* \return notified observer count.
*/
virtual size_t notifyObservers(const _Key& key, const _Key& substkey, const _Event* e) noexcept override {
std::lock_guard<std::recursive_mutex> lock(_observersMutex);
size_t retval = 0;
// We work with a copy so that we can insert/remove observers within a callback.
observers_type tmp = _observers;
auto ol = tmp.equal_range(key);
for (auto i = ol.first; i != ol.second; i++) {
i->second->notificationReceived(this, substkey, e);
retval++;
}
return retval;
}
};
@@ -269,6 +269,18 @@ public:
*/
virtual size_t notifyObservers(const _Key& key, const _Event* e) noexcept = 0;
/**
* Notify observers of a new event.
*
* The purpose of this function is to implement an all-events key.
*
* \param[in] key observer filter key.
* \param[in] substkey key that is send to the observers.
* \param[in] e event.
* \return notified observer count.
*/
virtual size_t notifyObservers(const _Key& key, const _Key& substkey, const _Event* e) noexcept = 0;
};