m2etis  0.4
NodeHandle.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_NET_NODEHANDLE_H__
23 #define __M2ETIS_NET_NODEHANDLE_H__
24 
25 #include <list>
26 #include <sstream>
27 #include <string>
28 
29 #include "m2etis/message/key/Key.h"
31 
32 #include "boost/shared_ptr.hpp"
33 
34 namespace m2etis {
35 namespace net {
36 
43  template<class NetworkType>
44  class NodeHandle {
45  public:
46  NodeHandle() : key_(), hostname_(), port_(0) {}
47  NodeHandle(typename NetworkType::Key key, const std::string & hostname, const uint16_t port) : key_(key), hostname_(hostname), port_(port) {
48  }
50 
52  std::string hostname_;
53  uint16_t port_;
54 
55  std::string to_str() const {
56  std::stringstream ss;
57  ss << key_.toStr() << "\t(" << hostname_ << ":" << port_ << ")";
58  return ss.str();
59  }
60 
61  typedef boost::shared_ptr<const NodeHandle<NetworkType>> Ptr_const;
62  typedef boost::shared_ptr<NodeHandle<NetworkType>> Ptr;
63  typedef std::list<Ptr> PtrList;
64  };
65 
66 } /* namespace net */
67 } /* namespace m2etis */
68 
69 #endif /* __M2ETIS_NET_NODEHANDLE_H__ */
70 
std::string toStr() const
Gets a string representation of the key.
Definition: Key.h:78
std::string hostname_
Definition: NodeHandle.h:52
std::string to_str() const
Definition: NodeHandle.h:55
NodeHandle in different structured p2p-systems.
Definition: NodeHandle.h:44
std::list< Ptr > PtrList
Definition: NodeHandle.h:63
boost::shared_ptr< const NodeHandle< NetworkType > > Ptr_const
Definition: NodeHandle.h:61
NetworkType::Key key_
Definition: NodeHandle.h:51
boost::shared_ptr< NodeHandle< NetworkType > > Ptr
Definition: NodeHandle.h:62
NodeHandle(typename NetworkType::Key key, const std::string &hostname, const uint16_t port)
Definition: NodeHandle.h:47