3 * Author: Lukas Krejci <krejci.l@centrum.cz>, (C) 2008
4 * Copyright: See COPYING file that comes with this distribution
7 #ifndef BEACONS_signal_base_H
8 #define BEACONS_signal_base_H
10 #include <beacons/event_queue.hpp>
11 #include <beacons/intrusive_ptr.hpp>
12 #include <beacons/reference_countable.hpp>
13 #include <beacons/detail/slot.hpp>
14 #include <beacons/trackable.hpp>
15 #include <beacons/detail/connection_impl_base.hpp>
16 #include <beacons/detail/quick_wait.hpp>
21 #include <atomic_ops.h>
29 class connection_impl
;
31 class signal_base
: public reference_countable
{
32 friend class connection_impl
;
35 //we represent the slot as just a slot_base * so that this
36 //class doesn't have to be templated. The subclasses will
37 //know what concrete slot type to cast it to...
38 struct slot_list_item
{
39 intrusive_ptr
<slot_base
> slot
;
40 intrusive_ptr
<connection_impl_base
> connection
;
43 slot_list_item() : slot(0), connection(), queue(0) {}
45 typedef std::list
<slot_list_item
> slot_list_type
;
52 * Disconnects all slots from this signal.
58 signal_base() : _slots(), _slots_guard(AO_TS_INITIALIZER
) {}
61 * Initializes the connection.
63 intrusive_ptr
<connection_impl_base
> do_connect(intrusive_ptr
<slot_base
> slot
, trackable
* obj
);
66 * Initializes the connection.
68 intrusive_ptr
<connection_impl_base
> do_connect(intrusive_ptr
<slot_base
> slot
, event_queue
& queue
);
71 * Removes the connection record identified by the iterator from the
74 void do_disconnect(slot_list_type::iterator pos
);
77 * Returns a copy of the slot list as it was at the time
78 * of the call. This operation is thread safe as it made sure
79 * that no modifications are possible while making this copy.
81 slot_list_type
get_slots_copy();
84 intrusive_ptr
<connection_impl_base
> _init_connection(slot_list_item
& item
);
86 slot_list_type _slots
;