#include "StdAfx.h" #include "LBroadcaster.h" #include "LListener.h" LBroadcaster::LBroadcaster() { mBroadcasting = true; } LBroadcaster::LBroadcaster(const LBroadcaster& other) { mBroadcasting = other.mBroadcasting; } /*virtual*/ LBroadcaster::~LBroadcaster() { BroadcastMessage(0xFFFFFFFF, this); LArrayIterator iter(mListeners); LListener *listener; while (iter.Next(&listener)) { listener->RemoveBroadcaster(this); } } void LBroadcaster::AddListener(LListener* listener) { // bug - should pass &listener to FetchIndexOf if (mListeners.FetchIndexOf(listener) == 0) { mListeners.Add(&listener); listener->AddBroadcaster(this); } } void LBroadcaster::RemoveListener(LListener* listener) { mListeners.Remove(&listener); listener->RemoveBroadcaster(this); } void LBroadcaster::BroadcastMessage(unsigned int msg, void* data) { if (mBroadcasting) { LArrayIterator iter(mListeners); LListener *listener; while (iter.Next(&listener)) { if (listener->IsListening()) listener->ListenToMessage(msg, data); } } }