aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRainer Hochecker <fernetmenta@online.de>2016-04-24 09:29:19 +0200
committerRainer Hochecker <fernetmenta@online.de>2016-04-24 09:29:19 +0200
commitd9cdd67f903f557e042649b9139041e1b9b33ef5 (patch)
tree0e00c7965568adca5626185c8825aae8123cae46
parent979e6d080a0e42c27e5f343242c0e234d45890ac (diff)
parent6bacee632180652445affec1d5b475b26de620b4 (diff)
Merge pull request #9669 from FernetMenta/observer
fix observers
-rw-r--r--xbmc/utils/Observer.cpp33
-rw-r--r--xbmc/utils/Observer.h2
2 files changed, 12 insertions, 23 deletions
diff --git a/xbmc/utils/Observer.cpp b/xbmc/utils/Observer.cpp
index 237608aced..016f823a1e 100644
--- a/xbmc/utils/Observer.cpp
+++ b/xbmc/utils/Observer.cpp
@@ -18,7 +18,7 @@
*
*/
-#include "Application.h"
+
#include "Observer.h"
#include "threads/SingleLock.h"
@@ -32,9 +32,8 @@ Observer::~Observer(void)
void Observer::StopObserving(void)
{
CSingleLock lock(m_obsCritSection);
- std::vector<Observable *> observables = m_observables;
- for (unsigned int iObsPtr = 0; iObsPtr < observables.size(); iObsPtr++)
- observables.at(iObsPtr)->UnregisterObserver(this);
+ for (auto& observable : m_observables)
+ observable->UnregisterObserver(this);
}
bool Observer::IsObserving(const Observable &obs) const
@@ -83,9 +82,8 @@ Observable &Observable::operator=(const Observable &observable)
void Observable::StopObserver(void)
{
CSingleLock lock(m_obsCritSection);
- std::vector<Observer *> observers = m_observers;
- for (unsigned int iObsPtr = 0; iObsPtr < observers.size(); iObsPtr++)
- observers.at(iObsPtr)->UnregisterObservable(this);
+ for (auto& observer : m_observers)
+ observer->UnregisterObservable(this);
}
bool Observable::IsObserving(const Observer &obs) const
@@ -120,13 +118,13 @@ void Observable::NotifyObservers(const ObservableMessage message /* = Observable
bool bNotify(false);
{
CSingleLock lock(m_obsCritSection);
- if (m_bObservableChanged && !g_application.m_bStop)
+ if (m_bObservableChanged)
bNotify = true;
m_bObservableChanged = false;
}
if (bNotify)
- SendMessage(*this, message);
+ SendMessage(message);
}
void Observable::SetChanged(bool SetTo)
@@ -135,20 +133,11 @@ void Observable::SetChanged(bool SetTo)
m_bObservableChanged = SetTo;
}
-void Observable::SendMessage(const Observable& obs, const ObservableMessage message)
+void Observable::SendMessage(const ObservableMessage message)
{
- CSingleLock lock(obs.m_obsCritSection);
- for(int ptr = obs.m_observers.size() - 1; ptr >= 0; ptr--)
+ CSingleLock lock(m_obsCritSection);
+ for (auto& observer : m_observers)
{
- if (ptr < (int)obs.m_observers.size())
- {
- Observer *observer = obs.m_observers.at(ptr);
- if (observer)
- {
- lock.Leave();
- observer->Notify(obs, message);
- lock.Enter();
- }
- }
+ observer->Notify(*this, message);
}
}
diff --git a/xbmc/utils/Observer.h b/xbmc/utils/Observer.h
index 3ac032a056..2bcc31b185 100644
--- a/xbmc/utils/Observer.h
+++ b/xbmc/utils/Observer.h
@@ -138,7 +138,7 @@ protected:
* @param obs The observer that sends the message.
* @param message The message to send.
*/
- static void SendMessage(const Observable& obs, const ObservableMessage message);
+ void SendMessage(const ObservableMessage message);
bool m_bObservableChanged; /*!< true when the observable is marked as changed, false otherwise */
std::vector<Observer *> m_observers; /*!< all observers */