Nebula
Loading...
Searching...
No Matches
dispatcher.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
29#include "core/ptr.h"
30#include "messaging/port.h"
31
32//------------------------------------------------------------------------------
33namespace Messaging
34{
35class Dispatcher : public Port
36{
38public:
40 Dispatcher();
42 virtual void HandleMessage(const Ptr<Messaging::Message>& msg);
44 void AttachPort(const Ptr<Port>& port);
46 void RemovePort(const Ptr<Port>& port);
48 bool HasPort(const Ptr<Port>& port) const;
49
50private:
52 Util::Array<Util::Array<Ptr<Port> > > idPorts; // one entry per message, contains ports which accepts the message
53 Util::Dictionary<const Id*,IndexT> idPortMap; // maps message id's to indices in the msgIdPorts array
54};
55
56} // namespace Message
57//------------------------------------------------------------------------------
A message Dispatcher is a specialization of a message Port.
Definition dispatcher.h:36
bool HasPort(const Ptr< Port > &port) const
return true if a port exists
Definition dispatcher.cc:98
__DeclareClass(Dispatcher)
Util::Array< Ptr< Port > > portArray
Definition dispatcher.h:51
void AttachPort(const Ptr< Port > &port)
attach a message port
Definition dispatcher.cc:30
Util::Array< Util::Array< Ptr< Port > > > idPorts
Definition dispatcher.h:52
virtual void HandleMessage(const Ptr< Messaging::Message > &msg)
handle a single message (distribute to ports which accept the message)
Definition dispatcher.cc:110
Dispatcher()
constructor
Definition dispatcher.cc:17
Util::Dictionary< const Id *, IndexT > idPortMap
Definition dispatcher.h:53
void RemovePort(const Ptr< Port > &port)
remove a message port
Definition dispatcher.cc:64
A message port is a receiving point for messages.
Definition port.h:32
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
Nebula's dynamic array class.
Definition array.h:60
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:34
Definition asyncport.cc:10