blob: 3486ce96829c7c9d46cba5a42620923a2b7ea20b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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);
}
}
}
|