renamed from beacon to beacons, bumped version to 0.1.1 for that.
[beacon-ss.git] / src / beacons / detail / signal_base.hpp
blob0aed876298b9c15a90a5d69667374ab794546483
1 /**
2 * beacon
3 * Author: Lukas Krejci <krejci.l@centrum.cz>, (C) 2008
4 * Copyright: See COPYING file that comes with this distribution
5 */
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>
17 #include <list>
18 #include <utility>
20 extern "C" {
21 #include <atomic_ops.h>
24 namespace beacons {
26 namespace detail {
28 //forward decl
29 class connection_impl;
31 class signal_base : public reference_countable {
32 friend class connection_impl;
33 public:
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;
41 event_queue * queue;
43 slot_list_item() : slot(0), connection(), queue(0) {}
45 typedef std::list<slot_list_item> slot_list_type;
47 ~signal_base() {
48 clear();
51 /**
52 * Disconnects all slots from this signal.
54 void clear();
56 protected:
58 signal_base() : _slots(), _slots_guard(AO_TS_INITIALIZER) {}
60 /**
61 * Initializes the connection.
63 intrusive_ptr<connection_impl_base> do_connect(intrusive_ptr<slot_base> slot, trackable * obj);
65 /**
66 * Initializes the connection.
68 intrusive_ptr<connection_impl_base> do_connect(intrusive_ptr<slot_base> slot, event_queue & queue);
70 /**
71 * Removes the connection record identified by the iterator from the
72 * slot list.
74 void do_disconnect(slot_list_type::iterator pos);
76 /**
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();
82 private:
84 intrusive_ptr<connection_impl_base> _init_connection(slot_list_item & item);
86 slot_list_type _slots;
88 AO_TS_t _slots_guard;
91 } //namespace detail
93 } //namespace beacons
95 #endif