Revert "removed the kdevelop project files from the repo"
[beacon-ss.git] / src / beacon / trackable.hpp
blob448fb3fa8e24a0ab7b58cb91bdb89f02a40e9c5e
1 /**
2 * signals
3 * Author: Lukas Krejci <krejci.l@centrum.cz>, (C) 2008
4 * Copyright: See COPYING file that comes with this distribution
5 */
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>
14 #include <list>
16 extern "C" {
17 #include <atomic_ops.h>
20 namespace beacon {
22 //forward decl
23 namespace detail { class signal_base; }
25 /**
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;
33 public:
34 trackable(event_queue * eq) : _evq(eq), _connections(),
35 _cons_guard(AO_TS_INITIALIZER) {}
37 /**
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()),
43 _connections(),
44 _cons_guard(AO_TS_INITIALIZER) {}
46 /**
47 * Disconnects all the connections this trackable is part of.
49 ~trackable();
51 /**
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);
58 /**
59 * The event queue the slots of this trackable will
60 * be executed in.
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 {
66 return _evq;
69 protected:
71 /**
72 * Called during new connection creation.
74 void add_connection(intrusive_ptr<detail::connection_impl_base> con);
76 private:
77 event_queue * _evq;
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
83 AO_TS_t _cons_guard;
88 #endif