siplasplas
A library for C++ reflection and introspection
asyncsink.hpp
1 #ifndef SIPLASPLAS_SIGNALS_ASYNCSINK_HPP
2 #define SIPLASPLAS_SIGNALS_ASYNCSINK_HPP
3 
4 #include "sink.hpp"
5 #include <siplasplas/typeerasure/function.hpp>
6 #include <readerwriterqueue/readerwriterqueue.h>
7 #include <siplasplas/signals/export.hpp>
8 
9 namespace cpp
10 {
11 
23 class SIPLASPLAS_SIGNALS_EXPORT AsyncSink : public SignalSink
24 {
25 public:
35  template<typename Caller, typename Function>
36  AsyncSink(Caller& caller, Function function) :
37  SignalSink{caller},
38  _fptr{function}
39  {}
40 
51  template<typename Caller, typename Callee, typename Function>
52  AsyncSink(Caller& caller, Callee& callee, Function function) :
53  SignalSink{caller, callee},
54  _fptr{function}
55  {}
56 
71  bool pull() override;
72 
73  virtual ~AsyncSink();
74 
75 protected:
76  void invoke(std::vector<cpp::SimpleAny32>&& args) override;
77  bool invokeWithoutCallee() const override;
78 
79 private:
80  moodycamel::ReaderWriterQueue<std::vector<cpp::SimpleAny32>> _queue;
82 };
83 
84 }
85 
86 #endif // SIPLASPLAS_SIGNALS_ASYNCSINK_HPP
Definition: canary_allocator.hpp:7
Interface to the signals sink API.
Definition: sink.hpp:39
AsyncSink(Caller &caller, Callee &callee, Function function)
Creates an asynchronous sink given a caller, a callee, and a destination function.
Definition: asyncsink.hpp:52
AsyncSink(Caller &caller, Function function)
Creates an asynchronous sink given a caller and a destination function.
Definition: asyncsink.hpp:36
Stores a type-erased callable of any signature and kind.
Definition: function.hpp:58
decltype(auto) invoke(Callable &&callable, const ::cpp::SimpleAny< Storages > &...args)
Invokes a callable object with the given type-erased arguments.
Definition: invoke.hpp:214
Implements an asynchronous signal sink suited for communication between different threads...
Definition: asyncsink.hpp:23