ST_engine  0.3-ALPHA
subscriber.hpp
1 /* This file is part of the "ST" project.
2  * You may use, distribute or modify this code under the terms
3  * of the GNU General Public License version 2.
4  * See LICENCE.txt in the root directory of the project.
5  *
6  * Author: Maxim Atanasov
7  * E-mail: maxim.atanasov@protonmail.com
8  */
9 
10 #ifndef ST_SUBSCRIBER_HPP
11 #define ST_SUBSCRIBER_HPP
12 
13 #include <ST_util/atomic_queue/concurrentqueue.h>
14 #include "message.hpp"
15 
17 
20 class subscriber {
21 public:
22  subscriber() = default;
23 
25 
26  void push_message(message *arg);
27 
28 private:
29  moodycamel::ConcurrentQueue<message *> queue;
30 };
31 
32 
33 //INLINE METHODS
34 
40  message *new_message{};
41  queue.try_dequeue(new_message);
42  return new_message;
43 }
44 
49 inline void subscriber::push_message(message *arg) {
50  queue.enqueue(arg);
51  //and again, the queues are thread-safe so no locks are needed
52 }
53 
54 #endif //ST_SUBSCRIBER_HPP
A message object passed around in the message bus. Holds anything created with make_data<>().
Definition: message.hpp:21
This class handles a small queue for messages.
Definition: subscriber.hpp:20
message * get_next_message()
Definition: subscriber.hpp:39
void push_message(message *arg)
Definition: subscriber.hpp:49