From 37e364b2c6cc7487a1c888d256a73e5337bb7189 Mon Sep 17 00:00:00 2001 From: Ash Wolf Date: Wed, 14 Jun 2023 00:50:34 +0100 Subject: initial commit --- src/T2DLL/LBroadcaster.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/T2DLL/LBroadcaster.cpp (limited to 'src/T2DLL/LBroadcaster.cpp') diff --git a/src/T2DLL/LBroadcaster.cpp b/src/T2DLL/LBroadcaster.cpp new file mode 100644 index 0000000..3486ce9 --- /dev/null +++ b/src/T2DLL/LBroadcaster.cpp @@ -0,0 +1,46 @@ +#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); + } + } +} -- cgit v1.2.3