MythObservable Class Reference

Superclass for making an object have a set of listeners. More...

#include <mythobservable.h>

Inheritance diagram for MythObservable:
Decoder DecoderHandler DecoderIOFactory MusicPlayer MythCoreContext OutputListeners SSDPCache UPNPSubscription

List of all members.

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

Detailed Description

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.


Constructor & Destructor Documentation

MythObservable::MythObservable (  ) 

Definition at line 25 of file mythobservable.cpp.

MythObservable::~MythObservable (  )  [virtual]

Definition at line 29 of file mythobservable.cpp.


Member Function Documentation

void MythObservable::addListener ( QObject *  listener  ) 
void MythObservable::removeListener ( QObject *  listener  ) 
void MythObservable::dispatch ( const MythEvent event  ) 
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.

Parameters:
event a MythEvent to dispatch.
Deprecated:
Do not use in new code

Reimplemented in MythCoreContext.

Definition at line 97 of file mythobservable.cpp.

bool MythObservable::hasListeners ( void   )  [inline]

Member Data Documentation

QMutex* MythObservable::m_lock [protected]
QSet<QObject*> MythObservable::m_listeners [protected]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends
Generated on Mon May 28 06:42:16 2012 for MythTV by  doxygen 1.6.3