2 * Copyright 2006-2007, Haiku.
3 * Distributed under the terms of the MIT License.
6 * Stephan Aßmus <superstippi@gmx.de>
22 fPendingNotifications(false)
29 if (fListeners
.CountItems() > 0) {
31 Listener
* o
= (Listener
*)fListeners
.ItemAt(0);
32 sprintf(message
, "Notifier::~Notifier() - %" B_PRId32
33 " listeners still watching, first: %s\n",
34 fListeners
.CountItems(), typeid(*o
).name());
41 Notifier::AddListener(Listener
* listener
)
43 if (listener
&& !fListeners
.HasItem((void*)listener
)) {
44 return fListeners
.AddItem((void*)listener
);
51 Notifier::RemoveListener(Listener
* listener
)
53 return fListeners
.RemoveItem((void*)listener
);
58 Notifier::CountListeners() const
60 return fListeners
.CountItems();
65 Notifier::ListenerAtFast(int32 index
) const
67 return (Listener
*)fListeners
.ItemAtFast(index
);
74 Notifier::Notify() const
77 BList
observers(fListeners
);
78 int32 count
= observers
.CountItems();
79 for (int32 i
= 0; i
< count
; i
++)
80 ((Listener
*)observers
.ItemAtFast(i
))->ObjectChanged(this);
81 fPendingNotifications
= false;
83 fPendingNotifications
= true;
87 // SuspendNotifications
89 Notifier::SuspendNotifications(bool suspend
)
97 fprintf(stderr
, "Notifier::SuspendNotifications(false) - "
98 "error: suspend level below zero!\n");
102 if (!fSuspended
&& fPendingNotifications
)