25 #ifndef __I6ENGINE_CORE_MESSAGESUBSCRIBER_H__
26 #define __I6ENGINE_CORE_MESSAGESUBSCRIBER_H__
33 #include "boost/function.hpp"
34 #include "boost/thread/mutex.hpp"
39 class MessageTypeInfo;
81 MessageSubscriber() : _objMessageVectorMutex(), _objMessageVectorA(), _objMessageVectorB(), _objActiveMessageVector(&_objMessageVectorA), _objInActiveMessageVector(&_objMessageVectorB), _ptrMessageMethod(), _newCreatedIDs(), _existingObjects(), _waitingMsgs(), _objMessageListMutex() {
101 virtual void processMessages();
107 void notifyNewID(
const int64_t
id);
113 void buffer(
const ReceivedMessagePtr & msg);
124 _ptrMessageMethod[msgType] = ptrMessageMethod;
131 _ptrMessageMethod.erase(msgType);
132 boost::mutex::scoped_lock objScopeLock(_objMessageVectorMutex);
133 MessageVector result;
134 for (
auto & rm : *_objActiveMessageVector) {
135 if (rm->message->getMessageType() != msgType) {
136 result.push_back(rm);
139 _objActiveMessageVector->clear();
140 for (
auto & rm : result) {
141 _objActiveMessageVector->push_back(rm);
149 void swapMessageBuffer();
168 virtual void deliverMessageInternal(
const ReceivedMessagePtr & msg);
175 std::vector<int64_t> _newCreatedIDs;
180 std::map<int64_t, IDStatus> _existingObjects;
187 std::map<int64_t, std::vector<ReceivedMessagePtr>> _waitingMsgs;
192 mutable boost::mutex _objMessageListMutex;
197 mutable boost::mutex _bufferLock;
MessageSubscriber()
Standard constructor.
MessageVector * _objActiveMessageVector
boost::shared_ptr< Message > Ptr
a received message within a MessageSubscriber
Interface for every class that wants to subscribe to the messaging system.
unknown (most likely not created yet)
MessageVector * _objInActiveMessageVector
void addMethod(uint16_t msgType, const boost::function< void(const Message::Ptr &)> &ptrMessageMethod)
adds a method for given message type where messages shall be delivered
MessageVector _objMessageVectorA
MessageVector _objMessageVectorB
std::set< int64_t > waitingFor
virtual ~MessageSubscriber()
Destructor.
boost::shared_ptr< ReceivedMessage > ReceivedMessagePtr
ReceivedMessage(const Message::Ptr &msg)
boost::mutex _objMessageVectorMutex
std::vector< ReceivedMessagePtr > MessageVector
void removeMethod(uint16_t msgType)
removes method for given message type
std::map< uint16_t, boost::function< void(const Message::Ptr &)> > _ptrMessageMethod