3 * Author: Lukas Krejci <krejci.l@centrum.cz>, (C) 2008
4 * Copyright: See COPYING file that comes with this distribution
7 #ifndef BEACON_TRACKABLE_H
8 #define BEACON_TRACKABLE_H
10 #include <beacon/event_queue.hpp>
11 #include <beacon/reference_countable.hpp>
12 #include <beacon/intrusive_ptr.hpp>
13 #include <beacon/detail/connection_impl_base.hpp>
17 #include <atomic_ops.h>
23 namespace detail
{ class signal_base
; }
26 * Trackable objects are automatically tracked by the library.
27 * I.e. the connections are automatically disconnected
28 * when a trackable object is destroyed. Each trackable object also belongs to
29 * an event queue in which its slots are invoked.
31 class trackable
: public reference_countable
{
32 friend class detail::signal_base
;
34 trackable(event_queue
* eq
) : _evq(eq
), _connections(),
35 _cons_guard(AO_TS_INITIALIZER
) {}
38 * The copy constructor of a trackable doesn't make the copy a part
39 * of the connections of the original.
41 trackable(trackable
const & other
) :
42 _evq(other
.current_event_queue()),
44 _cons_guard(AO_TS_INITIALIZER
) {}
47 * Disconnects all the connections this trackable is part of.
52 * The connections are not transfered from trackable to trackable.
53 * Upon assignment this trackable will have the same event loop
54 * but empty will have no signals connected to it.
56 trackable
& operator=(trackable
const & rhs
);
59 * The event queue the slots of this trackable will
61 * Can be null, which means that the slots are called
62 * immediately during the signal invocation instead of
63 * queuing in some event_queue.
65 event_queue
* current_event_queue() const {
72 * Called during new connection creation.
74 void add_connection(intrusive_ptr
<detail::connection_impl_base
> con
);
79 //list of connections this trackable is part (destination) of
80 std::list
<intrusive_ptr
<detail::connection_impl_base
> > _connections
;
82 //guarding the access to the connection list