SEGS  0.6.1-develop [d2cac982]
Super Entity Game Server
MessageBus.h
Go to the documentation of this file.
1 /*
2  * SEGS - Super Entity Game Server
3  * http://www.segs.io/
4  * Copyright (c) 2006 - 2019 SEGS Team (see AUTHORS.md)
5  * This software is licensed under the terms of the 3-clause BSD License. See LICENSE.md for details.
6  */
7 
8 #pragma once
9 #include "EventProcessor.h"
10 
11 #include <ace/Thread_Mutex.h>
12 #include <ace/Guard_T.h>
13 
14 #include <unordered_map>
15 #include <vector>
16 
17 class MessageBusEndpoint;
18 
19 class SEGSTimer;
25 class MessageBus final : public EventProcessor
26 {
27  std::unordered_map<uint32_t,std::vector<MessageBusEndpoint *> > m_specific_subscriber_map;
28  std::vector<MessageBusEndpoint *> m_catch_all_subscribers;
29  std::unique_ptr<SEGSTimer> m_statistics_timer;
30  friend void postGlobalEvent(SEGSEvents::Event *ev);
31  friend void shutDownMessageBus();
32  friend class MessageBusEndpoint; // allow endpoints to register/unregister
33 public:
34 
35 static constexpr uint32_t ALL_EVENTS = ~0U; // special event type allowing subscriptions to all incoming events
36 
37 public:
39  MessageBus();
40  bool ReadConfigAndRestart();
41 private:
47  void subscribe(uint32_t type, MessageBusEndpoint *ep);
51  void unsubscribe(uint32_t type,MessageBusEndpoint *);
56  void do_publish(SEGSEvents::Event *ev);
57  void recalculateStatisitcs();
58  // EventProcessor interface
59 protected:
60  void serialize_from(std::istream &is) override;
61  void serialize_to(std::ostream &os) override;
62  void dispatch(SEGSEvents::Event *ev) override;
63 };
64 
66 void shutDownMessageBus();
Instances of SEGSTimer class are used to schedule events in the future.
Definition: SEGSTimer.h:18
Definition: SEGSEvent.h:35
void serialize_from(std::istream &is) override
Definition: MessageBus.cpp:123
MessageBus()
Definition: MessageBus.cpp:46
void subscribe(uint32_t ev_type)
Definition: MessageBusEndpoint.cpp:24
void serialize_to(std::ostream &os) override
Definition: MessageBus.cpp:128
The MessageBusEndpoint class is responsible for:
Definition: MessageBusEndpoint.h:18
bool ReadConfigAndRestart()
Definition: MessageBus.cpp:51
The MessageBus class is responsible for forwarding incoming events to correct subscriber&#39;s endpoints...
Definition: MessageBus.h:25
void dispatch(SEGSEvents::Event *ev) override
Definition: MessageBus.cpp:108
friend void postGlobalEvent(SEGSEvents::Event *ev)
Definition: MessageBus.cpp:133
Definition: EventProcessor.h:22
static constexpr uint32_t ALL_EVENTS
Definition: MessageBus.h:35
friend void shutDownMessageBus()
shutDownMessageBus will request that all message bus handling threads terminate
Definition: MessageBus.cpp:141
#define IMPL_ID(EventProcessorChildType)
Definition: EventProcessor.h:44
void unsubscribe(uint32_t ev_type)
Definition: MessageBusEndpoint.cpp:30