Superclass for making an object have a set of listeners. More...
#include <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. | |
| void | dispatch (const MythEvent &event) |
| Dispatch an event to all listeners. | |
| void | dispatchNow (const MythEvent &event) |
| Dispatch an event to all listeners. | |
| bool | hasListeners (void) |
Protected Attributes | |
| QMutex * | m_lock |
| QSet< QObject * > | m_listeners |
Superclass for making an object have a set of listeners.
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.
MythEvents can be dispatched to all listeners by calling dispatch or dispatchNow. The former is much preferred as it uses QCoreApplication::postEvent() while the latter uses the blocking QCoreApplication::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 11 of file mythobservable.h.
| MythObservable::MythObservable | ( | ) |
Definition at line 25 of file mythobservable.cpp.
| MythObservable::~MythObservable | ( | ) | [virtual] |
Definition at line 29 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 |
Reimplemented in MusicPlayer.
Definition at line 45 of file mythobservable.cpp.
Referenced by SSDP::AddListener(), MusicPlayer::addListener(), MusicPlayer::addVisual(), AutoExpire::AutoExpire(), BackendConnectionManager::BackendConnectionManager(), BrowserApi::BrowserApi(), ChannelRecPriority::ChannelRecPriority(), ProgLister::Create(), CustomEdit::CustomEdit(), CustomEventRelayer::CustomEventRelayer(), CustomPriority::CustomPriority(), MusicPlayer::decoderHandlerReady(), EditAlbumartDialog::EditAlbumartDialog(), EditMetadataDialog::EditMetadataDialog(), IdleScreen::IdleScreen(), ProgFinder::Init(), MediaServer::Init(), GuideGrid::Init(), TV::InitFromDB(), JobQueue::JobQueue(), LCDProcClient::LCDProcClient(), MainServer::MainServer(), MessageHandler::MessageHandler(), MusicPlayer::MusicPlayer(), MythMainWindow::MythMainWindow(), MythSystemEventHandler::MythSystemEventHandler(), NetSearch::NetSearch(), NetTree::NetTree(), NetworkControl::NetworkControl(), DecoderHandler::next(), MusicPlayer::openOutputDevice(), PlaybackBox::PlaybackBox(), PreviewGenerator::RemotePreviewRun(), MusicPlayer::setupDecoderHandler(), UPNPScanner::Start(), ThemeChooser::ThemeChooser(), VideoSetupWizard::VideoSetupWizard(), ViewScheduled::ViewScheduled(), 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 |
Reimplemented in MusicPlayer.
Definition at line 62 of file mythobservable.cpp.
Referenced by DecoderHandler::deleteIOFactory(), CustomEventRelayer::deleteLater(), PreviewGenerator::RemotePreviewRun(), SSDP::RemoveListener(), MusicPlayer::removeListener(), MusicPlayer::removeVisual(), UPNPScanner::Stop(), MusicPlayer::stop(), MainServer::Stop(), AutoExpire::~AutoExpire(), BackendConnectionManager::~BackendConnectionManager(), BrowserApi::~BrowserApi(), ChannelRecPriority::~ChannelRecPriority(), CustomEdit::~CustomEdit(), CustomPriority::~CustomPriority(), EditAlbumartDialog::~EditAlbumartDialog(), GuideGrid::~GuideGrid(), IdleScreen::~IdleScreen(), JobQueue::~JobQueue(), LCDProcClient::~LCDProcClient(), MediaServer::~MediaServer(), MusicPlayer::~MusicPlayer(), MythMainWindow::~MythMainWindow(), MythSystemEventHandler::~MythSystemEventHandler(), NetSearch::~NetSearch(), NetTree::~NetTree(), NetworkControl::~NetworkControl(), PlaybackBox::~PlaybackBox(), ProgFinder::~ProgFinder(), ProgLister::~ProgLister(), ThemeChooser::~ThemeChooser(), TV::~TV(), VideoSetupWizard::~VideoSetupWizard(), ViewScheduled::~ViewScheduled(), and WelcomeDialog::~WelcomeDialog().
| void MythObservable::dispatch | ( | const 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 QCoreApplication::postEvent().
| event | MythEvent to dispatch. |
Reimplemented in MythCoreContext.
Definition at line 80 of file mythobservable.cpp.
Referenced by MusicPlayer::activePlaylistChanged(), AudioOutputJACK::CloseDevice(), MusicPlayer::customEvent(), DecoderHandler::customEvent(), MusicPlayer::decoderHandlerReady(), DecoderHandler::doConnectDecoder(), DecoderHandler::doFailed(), DecoderHandler::doInfo(), DecoderHandler::doOperationStart(), DecoderHandler::doOperationStop(), OutputListeners::error(), DecoderHandler::error(), Decoder::error(), AudioOutputJACK::JackCallback(), SSDPCache::NotifyAdd(), SSDPCache::NotifyRemove(), AudioOutputBase::OutputAudioLoop(), MusicPlayer::playlistChanged(), UPNPSubscription::ProcessRequest(), CdDecoder::run(), avfDecoder::run(), MusicPlayer::sendAlbumArtChangedEvent(), MusicPlayer::sendCDChangedEvent(), MusicPlayer::sendMetadataChangedEvent(), MusicPlayer::sendTrackStatsChangedEvent(), MusicPlayer::sendVolumeChangedEvent(), DecoderIOFactoryShoutCast::shoutcastMeta(), AudioOutputBase::Status(), DecoderIOFactoryShoutCast::stop(), and MusicPlayer::stop().
| void MythObservable::dispatchNow | ( | const MythEvent & | event | ) |
Dispatch an event to all listeners.
This sends an event using the current thread, this is almost always unsafe.
| event | a MythEvent to dispatch. |
Reimplemented in MythCoreContext.
Definition at line 97 of file mythobservable.cpp.
| bool MythObservable::hasListeners | ( | void | ) | [inline] |
Definition at line 24 of file mythobservable.h.
Referenced by MusicPlayer::addListener(), MusicPlayer::hasClient(), and MusicPlayer::removeListener().
QMutex* MythObservable::m_lock [protected] |
Definition at line 27 of file mythobservable.h.
Referenced by addListener(), MusicPlayer::decoderHandlerReady(), dispatch(), dispatchNow(), MusicPlayer::openOutputDevice(), removeListener(), MusicPlayer::setupDecoderHandler(), MusicPlayer::stop(), and ~MythObservable().
QSet<QObject*> MythObservable::m_listeners [protected] |
Definition at line 28 of file mythobservable.h.
Referenced by addListener(), MusicPlayer::decoderHandlerReady(), dispatch(), dispatchNow(), MusicPlayer::openOutputDevice(), removeListener(), MusicPlayer::setupDecoderHandler(), MusicPlayer::stop(), and ~MythObservable().
1.6.3