basic implementation of fast_signal, enqueueing in the event_loop doesn't work yet.
[beacon-ss.git] / beacon / trackable.hpp
blobe78f812212158fb861c7b88fc7af7142b295ffe5
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_loop.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 loop in which its slots are invoked.
31 class trackable : public reference_countable {
32 friend class detail::signal_base;
33 public:
34 trackable(event_loop * el) : _evl(el), _connections() {}
36 /**
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()),
42 _connections(),
43 _cons_guard(AO_TS_INITIALIZER) {}
45 /**
46 * Disconnects all the connections this trackable is part of.
48 ~trackable();
50 /**
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);
57 /**
58 * The event loop the slots of this trackable will
59 * be executed in.
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 {
65 return _evl;
68 protected:
70 /**
71 * Called during new connection creation.
73 void add_connection(intrusive_ptr<detail::connection_impl_base> con);
75 private:
76 event_loop * _evl;
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
82 AO_TS_t _cons_guard;
87 #endif