basic implementation of fast_signal, enqueueing in the event_loop doesn't work yet.
[beacon-ss.git] / beacon / detail / signal_base.hpp
blob96f8d7124b0f3362a50b56d0afb9e0c955262c49
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 BEACON_signal_base_H
8 #define BEACON_signal_base_H
10 #include <beacon/event_loop.hpp>
11 #include <beacon/intrusive_ptr.hpp>
12 #include <beacon/reference_countable.hpp>
13 #include <beacon/detail/slot.hpp>
14 #include <beacon/trackable.hpp>
15 #include <beacon/detail/connection_impl_base.hpp>
16 #include <beacon/detail/quick_wait.hpp>
17 #include <list>
18 #include <utility>
20 extern "C" {
21 #include <atomic_ops.h>
24 namespace beacon {
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 slot_base * slot;
40 intrusive_ptr<connection_impl_base> connection;
41 event_loop * loop;
43 slot_list_item() : slot(0), connection(), loop(0) {}
45 typedef std::list<slot_list_item> slot_list_type;
47 /**
48 * Disconnects all slots from this signal.
50 void clear();
52 protected:
54 signal_base() : _slots(), _slots_guard(AO_TS_INITIALIZER) {}
56 /**
57 * Initializes the connection.
59 intrusive_ptr<connection_impl_base> do_connect(slot_base * slot, trackable * obj);
61 /**
62 * Removes the connection record identified by the iterator from the
63 * slot list.
65 void do_disconnect(slot_list_type::iterator pos);
67 /**
68 * Returns a copy of the slot list as it was at the time
69 * of the call. This operation is thread safe as it made sure
70 * that no modifications are possible while making this copy.
72 slot_list_type get_slots_copy();
73 private:
75 slot_list_type _slots;
77 AO_TS_t _slots_guard;
80 } //namespace detail
82 } //namespace beacon
84 #endif