m2etis  0.4
OmNetMediator.h
Go to the documentation of this file.
1 /*
2  Copyright (2016) Michael Baer, Daniel Bonrath, All rights reserved.
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16 
22 #ifndef __M2ETIS_SIM_OMNETMEDIATOR_H__
23 #define __M2ETIS_SIM_OMNETMEDIATOR_H__
24 
25 #include <string>
26 
27 #include "m2etis/config/GeneratedEventTypes.h"
28 
31 
34 #include "m2etis/net/NetworkType.h"
35 #include "m2etis/net/NodeHandle.h"
36 
38 
39 namespace m2etis {
40 namespace sim {
41 
42  class PubSubWrapper;
43 
44  class OmNetMediator : public net::NetworkInterface<net::NetworkType<net::OMNET> > {
45  public:
54  OmNetMediator(const std::string & ip, const int port, const std::string & known_hostname, const int known_hostport) : _nodeHandle(new net::NodeHandle<net::NetworkType<net::OMNET>>), _callback(NULL), _ocallback(NULL), _name(ip), _hostName(known_hostname), _listenPort(port), _hostPort(known_hostport), _root(_hostName + std::string(":") + std::to_string(_hostPort)), _pubsub() {
55  }
56 
61 
68 
75 
85  void send(const message::ActionType type, const std::string & to, const message::M2Message<SimulationEventType>::Ptr payload, net::NodeHandle<net::NetworkType<net::OMNET>>::Ptr_const hint, unsigned int size);
86 
94 
101 
106 
110  void registerMessageType(const message::ActionType type, const bool ack) const;
111 
115  void registerMessageType(const net::NetworkType<net::OMNET>::MessageType type, const bool ack) const;
116 
125 
132 
140  void update(const std::string & key, const net::NodeHandle<net::NetworkType<net::OMNET>>::Ptr_const handle, bool joined);
141 
147  std::string getSHA1(int channel_name);
148 
156 
160  net::NetworkType<net::OMNET>::Key getRoot() const { return _root; }
161 
168  _pubsub = p;
169  }
170 
171  private:
174  OmNetCallbackInterface * _ocallback;
175  std::string _name;
176  std::string _hostName;
177  int _listenPort;
178  int _hostPort;
180  PubSubWrapper * _pubsub;
181 
182  OmNetMediator(const OmNetMediator &);
183  OmNetMediator & operator=(const OmNetMediator &);
184  };
185 
186 } /* namespace sim */
187 } /* namespace m2etis */
188 
189 #endif /* __M2ETIS_SIM_OMNETMEDIATOR_H__ */
190 
boost::shared_ptr< M2Message< EventType > > Ptr
Definition: M2Message.h:42
void registerWrapper(PubSubWrapper *p)
registers the PubSubWrapper of this simulation node in the wrapper
Generic interface for the callback-class used for the network.
NodeHandle in different structured p2p-systems.
Definition: NodeHandle.h:44
void registerMessageType(const message::ActionType type, const bool ack) const
not used
STL namespace.
void update(const std::string &key, const net::NodeHandle< net::NetworkType< net::OMNET >>::Ptr_const handle, bool joined)
method called by M2etisAdapter to validate status in overlay
net::NodeHandle< net::NetworkType< net::OMNET > >::Ptr getSelfNodeHandle() const
returns this nodes NodeHandle
OmNetMediator(const std::string &ip, const int port, const std::string &known_hostname, const int known_hostport)
constructor
Definition: OmNetMediator.h:54
void setCallback(net::NetworkCallbackInterface< net::NetworkType< net::OMNET >> *cb)
sets callback of NetworkController to communicate with Tree
bool forward(std::string &key, message::M2Message< SimulationEventType >::Ptr msg, const net::NodeHandle< net::NetworkType< net::OMNET >>::Ptr hint)
method to forward message using an overlay
message::MessageType MessageType
Definition: NetworkType.h:75
std::string getSHA1(int channel_name)
method to get SHA1 key out of channel name
bool isResponsibleFor(const net::NetworkType< net::OMNET >::Key &key, const net::NetworkType< net::OMNET >::Key &node) const
returns whether one node is responsible for another
void send(const message::ActionType type, const std::string &to, const message::M2Message< SimulationEventType >::Ptr payload, net::NodeHandle< net::NetworkType< net::OMNET >>::Ptr_const hint, unsigned int size)
method to send the given message into the M2etisAdapter
boost::shared_ptr< NetworkMessage > Ptr
net::NetworkType< net::OMNET >::Key getRoot() const
returns the root node of the tree
void registerOmNetCallback(OmNetCallbackInterface *o)
method to register M2etisAdapter in here
void deliver(message::NetworkMessage< net::NetworkType< net::OMNET >>::Ptr msg)
method to deliver messages from M2etisAdapter