22 #ifndef __M2ETIS_NET_NETWORKCONTROLLER_H__
23 #define __M2ETIS_NET_NETWORKCONTROLLER_H__
38 #include "boost/function.hpp"
39 #include "boost/shared_ptr.hpp"
40 #include "boost/thread.hpp"
51 template<
class NetworkType>
54 typedef boost::function<void(typename message::NetworkMessage<NetworkType>::Ptr message)>
net_deliver_func;
55 typedef boost::function<pubsub::FIPtr(typename message::NetworkMessage<NetworkType>::Ptr message)>
net_forward_func;
91 typename FMapType::const_iterator iter = forward_map_.find(*message->
typePtr);
92 if (iter != forward_map_.end()) {
112 msgQueue_.
push(DeliverInfo(message));
140 forward_map_.insert(std::make_pair(nr, f));
144 deliver_map_.insert(std::make_pair(nr, f));
148 forward_map_.erase(nr);
152 deliver_map_.erase(nr);
160 typedef std::map<message::MessageType, net_deliver_func> DMapType;
161 DMapType deliver_map_;
162 typedef std::map<message::MessageType, net_forward_func> FMapType;
163 FMapType forward_map_;
165 DIQueueType msgQueue_;
171 uint64_t processingID_;
173 bool processDeliverQueue() {
181 while (!msgQueue_.empty()) {
182 DeliverInfo di = msgQueue_.poll();
184 typename DMapType::iterator it = deliver_map_.find(di.msg_type);
186 if (it != deliver_map_.end()) {
187 it->second(di.message);
virtual void send(const typename message::NetworkMessage< NetworkType >::Ptr msg, typename NodeHandle< NetworkType >::Ptr_const hint)=0
Sends a message to the node which is responsible for the given key. Provide a hint for better routing...
void register_deliver(message::MessageType nr, net_deliver_func f)
boost::shared_ptr< const ForwardInfo > FIPtr
NetworkType::Key sender
sender of the message
boost::function< pubsub::FIPtr(typename message::NetworkMessage< m2etis::net::NetworkType< UDP > >::Ptr message)> net_forward_func
void setCallback(NetworkCallbackInterface< NetworkType > *cb)
Sets the callback-object on which the defined callbacks will be called.
Generic interface for the callback-class used for the network.
NetworkType::Key receiver
receiver of the message
void send(typename message::NetworkMessage< NetworkType >::Ptr msg)
sends a message to the receiver defined within the message if the sender is the receiver, message is put into deliver method directly to remove overhead by serializing and trying to send message otherwise the message is forwarded to the corresponding wrapper
bool forward(typename message::NetworkMessage< NetworkType >::Ptr message, const typename NodeHandle< NetworkType >::Ptr hint)
void push(const T &value)
pushes the given value into the queue
void deregister_deliver(message::MessageType nr)
#define M2ETIS_THROW_FAILURE(module, message, errorcode)
throws on internal errors
NetworkType::Key getSelf() const
virtual void registerMessageType(const typename NetworkType::MessageType type, const bool ack) const =0
register a messagetype. Only registered types are sent.
message::MessageType msg_type
boost::shared_ptr< const NodeHandle< NetworkType > > Ptr_const
void update(const typename NetworkType::Key &, const typename NodeHandle< NetworkType >::Ptr_const, bool)
static const uint32_t PULL_DELIVERQUEUE
message::NetworkMessage< NetworkType >::Ptr message
~NetworkController()
stops polling job and cleans up wrapper
NetworkInterface< NetworkType > * network_
uint64_t runRepeated(uint64_t interval, const boost::function< bool(void)> &func, int16_t priority)
adds new job running repeatedly
void register_forward(message::MessageType nr, net_forward_func f)
boost::function< void(typename message::NetworkMessage< m2etis::net::NetworkType< UDP > >::Ptr message)> net_deliver_func
Scheduler< util::RealTimeClock > scheduler_
void deregister_forward(message::MessageType nr)
void registerMessageType(message::MessageType type, const bool ack=true)
boost::shared_ptr< NetworkMessage > Ptr
boost::shared_ptr< NodeHandle< NetworkType > > Ptr
virtual NodeHandle< NetworkType >::Ptr getSelfNodeHandle() const =0
query your NodeHandle. You may query that for it's key.
DeliverInfo(typename message::NetworkMessage< NetworkType >::Ptr ms)
NetworkController(NetworkInterface< NetworkType > *network, pubsub::PubSubSystemEnvironment *pssi)
creates new interface for communication with a wrapper adds a polling job for incoming messages ...
void deliver(typename message::NetworkMessage< NetworkType >::Ptr message)
called from wrapper for every arriving message because of this method call can be done from different...