[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

 

LBroadcaster



Overview:

LBroadcaster is a PowerPlant class that is used for creating Broadcast and Listen relationships between objects. A broadcaster object communicates to a Listener object by sending messages. This is udeful if you want to have an object that can send messages to many other objects.

Methods :

The methods in this class are:

 

LBroadcaster()  
~LBroadcaster()  
AddListener()  
BroadcastMessage()  
IsBroadcasting()  
RemoveListener()  
StartBroadcasting()  
StopBroadcasting()  

Data Members:

The data members in this class are:

 

mListeners  
mIsBroadcasting  

Operation:

A Broadcaster sends messages to its Listeners. LBroadcaster is an abstract, mix-in class. Broadcasters have a list of Listeners to which they send messages via the BroadcastMessage() method. You attach a Listener to a Broadcaster using the AddListener() function.

Classes derived from LBroadcaster should call the BroadcastMessage() method whenever they want to announce some happening in the code, such as a change in state. For example, the destructor for LBroadcaster sends a msg_BroadcasterDied message to its Listeners.

Source files:

(Feature Classes)

LBroadcaster.h

LBroadcaster.cp

See also:

LListener

LBroadcaster()

Purpose:

The copy constructor for LBroadcaster makes a copy of the state of mIsBroadcasting data member. Listener links are not copied. The default constructor has no Listeners initially.

Access:

Public

Prototype:

LBroadcaster();

LBroadcaster(const LBroadcaster& inOriginal);
Parameters:

None

Return:

No return value for a constructor

~LBroadcaster()

Purpose:

The destructor destroys the LBroadcaster object, and notifies all Listeners that this Broadcaster object is going away.

Access:

Public, Virtual

Prototype:

virtual ~LBroadcaster();
Parameters:

None

Return:

None

AddListener()

Purpose:

This method adds a Listener to a Broadcaster object. You must associate Broadcasters with Listeners, not the converse:


theBroadcaster->AddListener(theListener); // correct
theListener->AddBroadcaster(theBroadcaster); // incorrect!

This method takes care of notifying the Listener to update its list of Broadcasters.

Access:

Public

Prototype:

void AddListener( LListener *inListener );
Parameters:

This method takes the following parameter:

 

LListener*  
inListener  
a pointer to the LListener object that will be associated with the LBroadcaster  

Return:

None

BroadcastMessage()

Purpose:

This method broadcasts a message to all associated Listeners. Listeners are associated with a Broadcaster using AddListener(). This method does not send a message to its Listeners if broadcasting is turned off. Broadcasting is turned on using StartBroadcasting(), and can be turned off using StopBroadcasting().

Access:

Public

Prototype:

void BroadcastMessage(MessageT inMessage,
void *ioParam = nil);
Parameters:

This method takes the following parameters:

 

MessageT  
inMessage  
This is the message you want to send to all Listeners.  
void  
*ioParam  
This is a pointer to a parameter structure that the Listeners may use. The default value is nil, meaning no parameter.  

Return:

None

Remarks:

IsBroadcasting()

Purpose:

This method tells you whether broadcasting is turned on or not.

Access:

Public, Inline

Prototype:

Boolean IsBroadcasting();
Parameters:

None

Return:

A Boolean indicating "true" if broadcasting is turned on, or "false" otherwise.

RemoveListener()

Purpose:

This method tells a Listener to remove itself from the broadcast list. In response to this, a Listener should update its list of Broadcasters.

Access:

Public

Prototype:

void RemoveListener( LListener *inListener );
Parameters:

This method takes the following parameter:

 

LListener*  
inListener  
A pointer to the Listener object that we want to remove from the broadcast list.  

Return:

None

StartBroadcasting()

Purpose:

This method enables broadcasting, by setting the mIsBroadcasting data member to true.

Access:

Public, Inline

Prototype:

void StartBroadcasting();
Parameters:

None

Return:

None

StopBroadcasting()

Purpose:

This method disables broadcasting, by setting the mIsBroadcasting data member to false. A Broadcaster that has broadcast turned off does not broadcast messages.

Access:

Public, Inline

Prototype:

void StopBroadcasting();
Parameters:

None

Return:

None

mListeners

Purpose:

This data member is a list of pointers to LListener objects. In general, you should use the AddListener() and RemoveListener() methods to access this list.

Access:

Protected

Prototype:

TArray<LListener*> mListeners;

mIsBroadcasting

Purpose:

This data member indicates whether broadcasting is enabled or not. This member should be accessed using the IsBroadcasting() method.

Access:

Protected

Prototype:

Boolean mIsBroadcasting;

 


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: July 21, 2000