CsSignal  1.3.1
cs_slot.h
1 /***********************************************************************
2 *
3 * Copyright (c) 2016-2024 Barbara Geller
4 * Copyright (c) 2016-2024 Ansel Sermersheim
5 *
6 * This file is part of CsSignal.
7 *
8 * CsSignal is free software, released under the BSD 2-Clause license.
9 * For license details refer to LICENSE provided with this project.
10 *
11 * CsSignal is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 *
15 * https://opensource.org/licenses/BSD-2-Clause
16 *
17 ***********************************************************************/
18 
19 #ifndef LIB_CS_SLOT_H
20 #define LIB_CS_SLOT_H
21 
22 #include <atomic>
23 #include <memory>
24 #include <set>
25 #include <thread>
26 #include <vector>
27 
28 #include "cs_macro.h"
29 #include "cs_rcu_guarded.h"
30 #include "cs_rcu_list.h"
31 
32 namespace CsSignal {
33 
34 class SignalBase;
35 class SlotBase;
36 enum class ConnectionKind;
37 
38 namespace Internal {
39  class BentoAbstract;
40  class TeaCupAbstract;
41 }
42 
43 class LIB_SIG_EXPORT PendingSlot
44 {
45  public:
46  PendingSlot(const PendingSlot &) = delete;
47  PendingSlot(PendingSlot &&) = default;
48 
49  PendingSlot(SignalBase *sender, std::unique_ptr<Internal::BentoAbstract> signal_Bento, SlotBase *receiver,
50  std::unique_ptr<Internal::BentoAbstract> slot_Bento,
51  std::unique_ptr<Internal::TeaCupAbstract> teaCup_Data);
52 
53  SignalBase *sender() const {
54  return m_sender;
55  }
56 
57  SlotBase *receiver() const {
58  return m_receiver;
59  }
60 
61  std::unique_ptr<Internal::BentoAbstract> internal_moveSlotBento() {
62  return std::move(m_slot_Bento);
63  }
64 
65  std::unique_ptr<Internal::TeaCupAbstract> internal_moveTeaCup() {
66  return std::move(m_teaCup_Data);
67  }
68 
69  void operator()() const;
70 
71  private:
72  SignalBase *m_sender;
73  std::unique_ptr<Internal::BentoAbstract> m_signal_Bento;
74  SlotBase *m_receiver;
75  std::unique_ptr<Internal::BentoAbstract> m_slot_Bento;
76  std::unique_ptr<Internal::TeaCupAbstract> m_teaCup_Data;
77 };
78 
79 class LIB_SIG_EXPORT SlotBase
80 {
81  public:
82  SlotBase();
83  SlotBase(const SlotBase &);
84  virtual ~SlotBase();
85 
86  // SlotBase(SlotBase &&);
87  // operator=(const SlotBase &);
88  // operator=(SlotBase &&);
89 
90  SignalBase *sender() const;
91 
92  protected:
93  std::set<SignalBase *> internal_senderList() const;
94 
95  private:
96  static SignalBase *&get_threadLocal_currentSender();
97 
98  // list of possible Senders for this Receiver
99  mutable libguarded::SharedList<const SignalBase *> m_possibleSenders;
100 
101  virtual bool compareThreads() const;
102  virtual void queueSlot(PendingSlot data, ConnectionKind type);
103 
104  friend class SignalBase;
105 
106  template<class Sender, class SignalClass, class ...SignalArgTypes, class ...Ts>
107  friend void activate(Sender &sender, void (SignalClass::*signal)(SignalArgTypes...), Ts &&... Vs);
108 
109  template<class Sender, class Receiver>
110  friend bool internal_disconnect(const Sender &sender, const Internal::BentoAbstract *signalBento,
111  const Receiver *receiver, const Internal::BentoAbstract *slotBento);
112 };
113 
114 
115 }
116 
117 #endif
#define LIB_SIG_EXPORT
Definition: cs_macro.h:28