i6engine  1.0
MessagingController.h
Go to the documentation of this file.
1 /*
2  * i6engine
3  * Copyright (2016) Daniel Bonrath, Michael Baer, All rights reserved.
4  *
5  * This file is part of i6engine; i6engine is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
25 #ifndef __I6ENGINE_CORE_MESSAGINGCONTROLLER_H__
26 #define __I6ENGINE_CORE_MESSAGINGCONTROLLER_H__
27 
28 #include <condition_variable>
29 #include <list>
30 #include <map>
31 #include <mutex>
32 
34 
37 
75 namespace i6e {
76 namespace core {
77 
78  class EngineCoreController;
79  class MessageSubscriber;
80 
86  public:
91 
96 
104  void registerMessageType(uint16_t messageType, MessageSubscriber * objMessageSubscriber);
105 
111  void unregisterMessageType(uint16_t messageType, MessageSubscriber * objMessageSubscriber);
112 
117  void deliverMessage(const Message::Ptr & msg);
118 
122  void clear();
123 
124  private:
128  void deliverMessages();
129 
134  void deliverMessageToSubscribers(const Message::Ptr & msg) const;
135 
139  std::map<uint16_t, std::vector<MessageSubscriber *>> _objMessageTypeDictionary;
140 
144  mutable std::mutex _dictionaryMutex;
145 
150 
151  boost::thread * _deliverThread;
152 
153  std::condition_variable _condVar;
154  std::mutex _condMutex;
155 
156  bool _running;
157 
161  MessagingController(const MessagingController &) = delete;
162 
166  MessagingController & operator=(const MessagingController &) = delete;
167  };
168 
169 } /* namespace core */
170 } /* namespace i6e */
171 
172 #endif /* __I6ENGINE_CORE_MESSAGINGCONTROLLER_H__ */
173 
boost::shared_ptr< Message > Ptr
Definition: Message.h:66
Interface for every class that wants to subscribe to the messaging system.
Central controller for messaging between subsystems and subsystems of different clients.
#define ISIXE_CORE_API