#include <mythobservable.h>

This superclass provides the basic API for adding and removing listeners and iterating across them. It is typically used to post events to listening QObjects.
For example, to post a custom event with event id 100 to all listeners :
void dispatch() { QObject *listener = firstListener(); while (listener) { QApplication::postEvent (listener, new QCustomEvent(100)); listener = nextListener(); } }
MythEvents can be dispatched to all listeners by calling dispatch or dispatchNow. The former is much preferred as it uses QApplication::postEvent() while the latter uses the blocking QApplication::sendEvent().
The name MythObservable is 'wrong', since all the methods refer to the observers as listeners (ie. addListener), however, MythListenable just doesn't sound right, and fixing all the calls to addListener was too big a patch.
Definition at line 40 of file mythobservable.h.
Public Member Functions | |
| MythObservable () | |
| virtual | ~MythObservable () |
| void | addListener (QObject *listener) |
| Add a listener to the observable. | |
| void | removeListener (QObject *listener) |
| Remove a listener to the observable. | |
| QObject * | firstListener () |
| Begin iteration across listeners. | |
| QObject * | nextListener () |
| Continue iteration to the next listener. | |
| QPtrList< QObject > | getListeners (void) |
| Get a copy of the list of listener. | |
| void | dispatch (MythEvent &event) |
| Dispatch an event to all listeners. | |
| void | dispatchNow (MythEvent &event) |
| Dispatch an event to all listeners. | |
Private Attributes | |
| QPtrList< QObject > | m_listeners |
| MythObservable::MythObservable | ( | ) |
Definition at line 5 of file mythobservable.cpp.
| MythObservable::~MythObservable | ( | ) | [virtual] |
Definition at line 9 of file mythobservable.cpp.
| void MythObservable::addListener | ( | QObject * | listener | ) |
Add a listener to the observable.
Adds the given QObject to the list of objects that observe this observable.
| listener | the QObject that will listen to this observable |
Definition at line 13 of file mythobservable.cpp.
Referenced by UPnp::AddListener(), AutoExpire::AutoExpire(), ChannelRecPriority::ChannelRecPriority(), CustomEdit::CustomEdit(), CustomEventRelayer::CustomEventRelayer(), CustomPriority::CustomPriority(), GuideGrid::GuideGrid(), ProgFinder::Initialize(), JobQueue::JobQueue(), LCDProcClient::LCDProcClient(), MainServer::MainServer(), ManualBox::ManualBox(), ManualSchedule::ManualSchedule(), MusicPlayer::MusicPlayer(), NetworkControl::NetworkControl(), MusicPlayer::openOutputDevice(), MusicPlayer::play(), PlaybackBox::PlaybackBox(), PreviousList::PreviousList(), ProgLister::ProgLister(), ProgramRecPriority::ProgramRecPriority(), MusicPlayer::setListener(), MusicPlayer::setVisual(), SmartPlaylistEditor::SmartPlaylistEditor(), TV::TV(), ViewScheduled::ViewScheduled(), ViewScheduleDiff::ViewScheduleDiff(), and WelcomeDialog::WelcomeDialog().
| void MythObservable::removeListener | ( | QObject * | listener | ) |
Remove a listener to the observable.
Remove the given QObject from the list of objects that observe this observable.
| listener | the QObject that already listens to this observable |
Definition at line 19 of file mythobservable.cpp.
Referenced by MusicPlayer::play(), UPnp::RemoveListener(), MusicPlayer::setListener(), MusicPlayer::setVisual(), MusicPlayer::stop(), AutoExpire::~AutoExpire(), ChannelRecPriority::~ChannelRecPriority(), CustomEdit::~CustomEdit(), CustomEventRelayer::~CustomEventRelayer(), CustomPriority::~CustomPriority(), GuideGrid::~GuideGrid(), JobQueue::~JobQueue(), LCDProcClient::~LCDProcClient(), ManualBox::~ManualBox(), ManualSchedule::~ManualSchedule(), MusicPlayer::~MusicPlayer(), PlaybackBox::~PlaybackBox(), PreviousList::~PreviousList(), ProgFinder::~ProgFinder(), ProgLister::~ProgLister(), ProgramRecPriority::~ProgramRecPriority(), SmartPlaylistEditor::~SmartPlaylistEditor(), TV::~TV(), ViewScheduled::~ViewScheduled(), ViewScheduleDiff::~ViewScheduleDiff(), and WelcomeDialog::~WelcomeDialog().
| QObject * MythObservable::firstListener | ( | ) |
Begin iteration across listeners.
If you simply need to iterate across the listeners, use firstListener and nextListener to iterate across the listeners. Ie. instead of
{
QPtrList<QObject> listeners = getListeners();
QObject *listener = listeners.first();
while (listener) {
// use listener...
listener = listeners.next();
}
}
you can avoid the copy and just do
{
QObject *listener = firstListener();
while (listener) {
// use listener...
listener = nextListener();
}
}
Definition at line 25 of file mythobservable.cpp.
Referenced by dispatch(), dispatchNow(), and OutputListeners::error().
| QObject * MythObservable::nextListener | ( | ) |
Continue iteration to the next listener.
See firstListener. Returns NULL if there are no more listeners.
Definition at line 30 of file mythobservable.cpp.
Referenced by dispatch(), dispatchNow(), and OutputListeners::error().
| QPtrList< QObject > MythObservable::getListeners | ( | void | ) |
Get a copy of the list of listener.
If you need access to more than just iteration via firstListener/nextListerner, you can call this to obtain a QPtrList with all the listeners.
Definition at line 35 of file mythobservable.cpp.
| void MythObservable::dispatch | ( | MythEvent & | event | ) |
Dispatch an event to all listeners.
Makes a copy of the event on the heap by calling MythEvent::clone and dispatches is by calling QApplication::postEvent.
| event | a MythEvent to dispatch. |
Reimplemented in MythContext.
Definition at line 40 of file mythobservable.cpp.
Referenced by MythContext::dispatch(), Decoder::error(), SSDPCache::NotifyAdd(), SSDPCache::NotifyRemove(), AudioOutputBase::OutputAudioLoop(), VorbisDecoder::run(), MadDecoder::run(), FlacDecoder::run(), avfDecoder::run(), aacDecoder::run(), and AudioOutputBase::Status().
| void MythObservable::dispatchNow | ( | MythEvent & | event | ) |
Dispatch an event to all listeners.
See dispatch.
| event | a MythEvent to dispatch. |
Reimplemented in MythContext.
Definition at line 50 of file mythobservable.cpp.
Referenced by MythContext::dispatchNow().
QPtrList<QObject> MythObservable::m_listeners [private] |
Definition at line 137 of file mythobservable.h.
Referenced by addListener(), firstListener(), getListeners(), nextListener(), and removeListener().
1.5.5