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_loop.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 loop in which its slots are invoked.
31 class trackable
: public reference_countable
{
32 friend class detail::signal_base
;
34 trackable(event_loop
* el
) : _evl(el
), _connections() {}
37 * The copy constructor of a trackable doesn't make the copy a part
38 * of the connections of the original.
40 trackable(trackable
const & other
) :
41 _evl(other
.current_event_loop()),
43 _cons_guard(AO_TS_INITIALIZER
) {}
46 * Disconnects all the connections this trackable is part of.
51 * The connections are not transfered from trackable to trackable.
52 * Upon assignment this trackable will have the same event loop
53 * but empty will have no signals connected to it.
55 trackable
& operator=(trackable
const & rhs
);
58 * The event loop the slots of this trackable will
60 * Can be null, which means that the slots are called
61 * immediately during the signal invocation instead of
62 * queuing in some event_loop.
64 event_loop
* current_event_loop() const {
71 * Called during new connection creation.
73 void add_connection(intrusive_ptr
<detail::connection_impl_base
> con
);
78 //list of connections this trackable is part (destination) of
79 std::list
<intrusive_ptr
<detail::connection_impl_base
> > _connections
;
81 //guarding the access to the connection list