Ticket #2557: mythobservable.patch
File mythobservable.patch, 4.5 KB (added by , 17 years ago) |
---|
-
libs/libmyth/output.cpp
22 22 23 23 24 24 void OutputListeners::error(const QString &e) { 25 QObject *object = firstListener(); 26 while (object) { 27 QApplication::postEvent(object, new OutputEvent(e)); 28 object = nextListener(); 29 } 25 OutputEvent ev (e); 26 dispatch (ev); 30 27 } 31 28 32 29 void OutputListeners::addVisual(MythTV::Visual *v) -
libs/libmyth/mythobservable.cpp
12 12 13 13 void MythObservable::addListener(QObject *listener) 14 14 { 15 QMutexLocker locked (&mutex); 15 16 if (m_listeners.find(listener) == -1) 16 17 m_listeners.append(listener); 17 18 } 18 19 19 20 void MythObservable::removeListener(QObject *listener) 20 21 { 22 QMutexLocker locked (&mutex); 21 23 if (m_listeners.find(listener) != -1) 22 24 m_listeners.remove(listener); 23 25 } 24 26 25 QObject* MythObservable::firstListener()26 {27 return m_listeners.first();28 }29 30 QObject* MythObservable::nextListener()31 {32 return m_listeners.next();33 }34 35 QPtrList<QObject> MythObservable::getListeners()36 {37 return m_listeners;38 }39 40 27 void MythObservable::dispatch(MythEvent &event) 41 28 { 42 QObject *listener = firstListener(); 29 QMutexLocker locked (&mutex); 30 QObject *listener = m_listeners.first(); 43 31 while (listener) 44 32 { 45 33 QApplication::postEvent(listener, event.clone()); 46 listener = nextListener();34 listener = m_listeners.next(); 47 35 } 48 36 } 49 37 50 38 void MythObservable::dispatchNow(MythEvent &event) 51 39 { 52 QObject *listener = firstListener(); 40 QMutexLocker locked (&mutex); 41 QObject *listener = m_listeners.first(); 53 42 while (listener) 54 43 { 55 44 QApplication::sendEvent(listener, event.clone()); 56 listener = nextListener();45 listener = m_listeners.next(); 57 46 } 58 47 } 59 48 -
libs/libmyth/mythobservable.h
2 2 #define MYTHOBSERVABLE_H_ 3 3 4 4 #include <qptrlist.h> 5 #include <qmutex.h> 5 6 #include "mythexp.h" 6 7 #include "mythevent.h" 7 8 … … 36 37 the observers as listeners (ie. addListener), however, 37 38 MythListenable just doesn't sound right, and fixing all the calls 38 39 to addListener was too big a patch. 40 41 All public methods in MythObservable are reentrant. 39 42 */ 40 43 class MPUBLIC MythObservable 41 44 { … … 61 64 */ 62 65 void removeListener(QObject *listener); 63 66 64 /** \brief Begin iteration across listeners65 66 If you simply need to iterate across the listeners, use \p67 firstListener and \p nextListener to iterate across the68 listeners. Ie. instead of69 70 \code71 {72 QPtrList<QObject> listeners = getListeners();73 QObject *listener = listeners.first();74 while (listener) {75 // use listener...76 listener = listeners.next();77 }78 }79 \endcode80 81 you can avoid the copy and just do82 83 \code84 {85 QObject *listener = firstListener();86 while (listener) {87 // use listener...88 listener = nextListener();89 }90 }91 \endcode92 93 \returns pointer to the first listener, NULL if there are no listeners94 */95 QObject* firstListener();96 97 /** \brief Continue iteration to the next listener98 99 See firstListener. Returns NULL if there are no more listeners.100 101 \returns pointer to the next listener, NULL if there are no more listeners102 */103 QObject* nextListener();104 105 /** \brief Get a copy of the list of listener106 107 If you need access to more than just iteration via108 firstListener/nextListerner, you can call this to obtain a109 QPtrList with all the listeners.110 111 \returns a copy of the list of listener112 */113 QPtrList<QObject> getListeners(void);114 115 67 /** \brief Dispatch an event to all listeners 116 68 117 69 Makes a copy of the event on the heap by calling … … 134 86 void dispatchNow(MythEvent &event); 135 87 136 88 private: 89 137 90 QPtrList<QObject> m_listeners; 91 QMutex mutex; 138 92 }; 139 93 140 94 #endif /* MYTHOBSERVABLE_H */