SEGS  0.4.2
Super Entity Game Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 - 2018 SEGS Team (see Authors.txt)
5  * This software is licensed! (See License.txt 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(SEGSEvent *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:
38  MessageBus();
39  bool ReadConfigAndRestart();
40 private:
46  void subscribe(uint32_t type, MessageBusEndpoint *ep);
50  void unsubscribe(uint32_t type,MessageBusEndpoint *);
51  void on_timer_event(TimerEvent *tmr);
52  void dispatch(SEGSEvent *ev) override;
57  void do_publish(SEGSEvent *ev);
58  void recalculateStatisitcs();
59 };
60 
61 void postGlobalEvent(SEGSEvent *ev);
62 void shutDownMessageBus();
Instances of SEGSTimer class are used to schedule events in the future.
Definition: SEGSTimer.h:18
Definition: SEGSEvent.h:32
friend void postGlobalEvent(SEGSEvent *ev)
Definition: MessageBus.cpp:120
MessageBus()
Definition: MessageBus.cpp:44
void subscribe(uint32_t ev_type)
Definition: MessageBusEndpoint.cpp:24
The MessageBusEndpoint class is responsible for:
Definition: MessageBusEndpoint.h:18
bool ReadConfigAndRestart()
Definition: MessageBus.cpp:49
The MessageBus class is responsible for forwarding incoming events to correct subscriber&#39;s endpoints...
Definition: MessageBus.h:25
void postGlobalEvent(SEGSEvent *ev)
Definition: MessageBus.cpp:120
Definition: EventProcessor.h:13
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:128
void shutDownMessageBus()
shutDownMessageBus will request that all message bus handling threads terminate
Definition: MessageBus.cpp:128
Definition: SEGSEvent.h:69
void unsubscribe(uint32_t ev_type)
Definition: MessageBusEndpoint.cpp:30