238 template <
class OBJECT_T>
254 template <
typename Callable,
255 typename = std::enable_if_t<!std::is_same<std::decay_t<Callable>,
DtVreMessageHandler>::value>>
269 virtual void connect(
const std::string& messageType,
310 template <
class OBJECT_T>
316 myConnectors[messageType] = std::make_shared<DtVreMessageHandler>(
object, method);
317 myConnectors[messageType]->connect(messageType, position);
334 myConnectors[messageType] = std::make_shared<DtVreMessageHandler>(function);
335 myConnectors[messageType]->connect(messageType, position);
343 template <
typename Callable>
348 myConnectors[messageType] = std::make_shared<DtVreMessageHandler>(std::forward<Callable>(callable));
349 myConnectors[messageType]->connect(messageType, position);
359 return findIt !=
myConnectors.end() && findIt->second->isConnected(messageType);
371 std::map<std::string, std::shared_ptr<DtVreMessageHandler>>
myConnectors;
388#define ASSERT_TYPE(msg, MsgType, msgCast)\
389 DtASSERT(dynamic_cast<MsgType*>(msg), "Message is incorrect type");\
390 MsgType* msgCast = static_cast<MsgType*>(msg);
400#define ASSERT_TYPE_NO_CAST(msg, MsgType) DtASSERT(dynamic_cast<MsgType*>(msg), "Message is incorrect type");
Provides assertion macros and functions for error detection and handling.
Modern delegate class that can bind and invoke callables with any number of parameters.
Definition delegate.h:31
Factory for creating VREngage messages from serialized data.
Definition vreMessageFactory.h:48
std::map< std::string, std::shared_ptr< DtVreMessageHandler > > myConnectors
Definition vreMessageManager.h:371
void connect(const std::string &messageType, DtVreMessageResult(*function)(DtVreMessage *), DtVreMessageManager::HandlerPosition position=DtVreMessageManager::HandlerPosition::BACK)
Connects a free function or static member function to a specific message type.
Definition vreMessageManager.h:330
DtVreMessageHandlerGroup()
Definition vreMessageManager.h:294
bool isConnected(const std::string &messageType) const
Checks if a handler is currently connected for a specific message type.
Definition vreMessageManager.h:356
void disconnect(const std::string &messageType)
Disconnects a handler from a specific message type.
Definition vreMessageManager.h:365
void connect(const std::string &messageType, Callable &&callable, DtVreMessageManager::HandlerPosition position=DtVreMessageManager::HandlerPosition::BACK)
Connects a callable handler to a specific message type.
Definition vreMessageManager.h:344
virtual ~DtVreMessageHandlerGroup()
Definition vreMessageManager.h:296
void connect(const std::string &messageType, OBJECT_T *object, DtVreMessageResult(OBJECT_T::*method)(DtVreMessage *), DtVreMessageManager::HandlerPosition position=DtVreMessageManager::HandlerPosition::BACK)
Connects a handler method to a specific message type.
Definition vreMessageManager.h:311
void disconnectAll()
Disconnects all handlers for all message types.
Definition vreMessageManager.h:368
Message handler class for VREngage messages.
Definition vreMessageManager.h:232
virtual void disconnect(const std::string &messageType)
Disconnects this handler from a specific message type.
virtual void disconnectAll()
Disconnects this handler from all message types it is connected to.
ConnectedList myConnectedList
List of message types this handler is currently connected to.
Definition vreMessageManager.h:285
virtual bool isConnected(const std::string &messageType) const
Checks if this handler is currently connected to a specific message type.
virtual void connect(const std::string &messageType, DtVreMessageManager::HandlerPosition position=DtVreMessageManager::HandlerPosition::BACK)
Connects this handler to a specific message type.
virtual ~DtVreMessageHandler()
Virtual destructor.
std::set< std::string > ConnectedList
Definition vreMessageManager.h:282
DtVreMessageHandler(OBJECT_T *object, DtVreMessageResult(OBJECT_T::*method)(DtVreMessage *))
Definition vreMessageManager.h:239
DtVreMessageHandler(DtVreMessageResult(*function)(DtVreMessage *))
Definition vreMessageManager.h:246
DtVreMessageHandler(Callable &&callable)
Constructor for callable handlers.
Definition vreMessageManager.h:256
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
static DtVreMessageManager * theVreMessageManager
Singleton instance of the message manager.
Definition vreMessageManager.h:209
virtual void queueMessage(DtVreMessage *msg, double delay=0.0)=0
Queues a message for later dispatch.
virtual const EventStats & stats()=0
Gets the event statistics for the current thread.
virtual void shutdownDispatchThread()=0
static DtVreMessageManager & instance()
Gets the singleton instance of the message manager.
DtVreMessageManager()
Protected constructor.
virtual void dispatchTick(double dt)=0
Processes queued messages for the current thread.
virtual DtVreMessageFactory & factory()=0
Gets the message factory associated with this message manager.
virtual ~DtVreMessageManager()
Virtual destructor.
static DtVreMessageFactory * theMessageFactory
Message factory for creating messages.
Definition vreMessageManager.h:216
virtual void addHandler(const std::string &messageType, const DtVreMessageDelegate &handler, HandlerPosition handlerPos=HandlerPosition::BACK)=0
Registers a message handler for a specific message type.
HandlerPosition
Position for adding a message handler in the handler list.
Definition vreMessageManager.h:75
@ BACK
Add the handler at the back of the list (called last)
Definition vreMessageManager.h:77
@ FRONT
Add the handler at the front of the list (called first)
Definition vreMessageManager.h:76
virtual void initDispatchThread(bool isMainThread=false)=0
Initialize the current thread as a tickable dispatch thread.
virtual void sendMessageAsap(DtVreMessage *msg)=0
Like queueMessage, but immediately dispatches message to handlers on the current thread,...
virtual void removeHandler(const std::string &messageType, const DtVreMessageDelegate &handler)=0
Unregisters a message handler for a specific message type.
Defines export macros for the VREngage Message Manager library.
#define MESSAGEMANAGER_DLL
Export/import macro for non-Windows platforms.
Definition export.h:39
!
Definition glsVreMessageUtil.h:50
DtDelegate< DtVreMessageResult, DtVreMessage * > DtVreMessageDelegate
Delegate type for message handler callbacks.
Definition vreMessageManager.h:36
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Statistics for message dispatching.
Definition vreMessageManager.h:61
std::vector< std::string > messageTypesDispatched
List of message types that were dispatched.
Definition vreMessageManager.h:66
int messagesDispatchedThisFrame
Number of messages dispatched in the current frame.
Definition vreMessageManager.h:63
Defines the base class for all VREngage messages.