NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
face-uri.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
28 #ifndef NDN_UTIL_FACE_URI_HPP
29 #define NDN_UTIL_FACE_URI_HPP
30 
31 #include "../common.hpp"
32 #include <boost/asio/ip/udp.hpp>
33 #include <boost/asio/ip/tcp.hpp>
34 #include <boost/asio/local/stream_protocol.hpp>
35 #include "ethernet.hpp"
36 #include "time.hpp"
37 
38 namespace ndn {
39 namespace util {
40 
44 class FaceUri
45 {
46 public:
47  class Error : public std::invalid_argument
48  {
49  public:
50  explicit
51  Error(const std::string& what)
52  : std::invalid_argument(what)
53  {
54  }
55  };
56 
57  FaceUri();
58 
64  explicit
65  FaceUri(const std::string& uri);
66 
67  // This overload is needed so that calls with string literal won't be
68  // resolved to boost::asio::local::stream_protocol::endpoint overload.
69  explicit
70  FaceUri(const char* uri);
71 
73  bool
74  parse(const std::string& uri);
75 
76 public: // scheme-specific construction
78  explicit
79  FaceUri(const boost::asio::ip::udp::endpoint& endpoint);
80 
82  explicit
83  FaceUri(const boost::asio::ip::tcp::endpoint& endpoint);
84 
86  FaceUri(const boost::asio::ip::tcp::endpoint& endpoint, const std::string& scheme);
87 
88 #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS
89  explicit
91  FaceUri(const boost::asio::local::stream_protocol::endpoint& endpoint);
92 #endif // BOOST_ASIO_HAS_LOCAL_SOCKETS
93 
95  static FaceUri
96  fromFd(int fd);
97 
99  explicit
100  FaceUri(const ethernet::Address& address);
101 
103  static FaceUri
104  fromDev(const std::string& ifname);
105 
106 public: // getters
108  const std::string&
109  getScheme() const
110  {
111  return m_scheme;
112  }
113 
115  const std::string&
116  getHost() const
117  {
118  return m_host;
119  }
120 
122  const std::string&
123  getPort() const
124  {
125  return m_port;
126  }
127 
129  const std::string&
130  getPath() const
131  {
132  return m_path;
133  }
134 
136  std::string
137  toString() const;
138 
139 public: // EqualityComparable concept
140  bool
141  operator==(const FaceUri& rhs) const;
142 
143  bool
144  operator!=(const FaceUri& rhs) const;
145 
146 public: // canonical FaceUri
149  static bool
150  canCanonize(const std::string& scheme);
151 
157  bool
158  isCanonical() const;
159 
160  typedef function<void(const FaceUri&)> CanonizeSuccessCallback;
161  typedef function<void(const std::string& reason)> CanonizeFailureCallback;
162 
171  void
172  canonize(const CanonizeSuccessCallback& onSuccess,
173  const CanonizeFailureCallback& onFailure,
174  boost::asio::io_service& io, const time::nanoseconds& timeout) const;
175 
176 private:
177  std::string m_scheme;
178  std::string m_host;
180  bool m_isV6;
181  std::string m_port;
182  std::string m_path;
183 
184  friend std::ostream& operator<<(std::ostream& os, const FaceUri& uri);
185 };
186 
187 std::ostream&
188 operator<<(std::ostream& os, const FaceUri& uri);
189 
190 } // namespace util
191 } // namespace ndn
192 
193 #endif // NDN_UTIL_FACE_URI_HPP
Copyright (c) 2011-2015 Regents of the University of California.
const std::string & getPath() const
get path
Definition: face-uri.hpp:130
bool parse(const std::string &uri)
exception-safe parsing
Definition: face-uri.cpp:63
static bool canCanonize(const std::string &scheme)
Definition: face-uri.cpp:501
bool operator==(const FaceUri &rhs) const
Definition: face-uri.cpp:169
represents an Ethernet hardware address
Definition: ethernet.hpp:53
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:44
STL namespace.
function< void(const FaceUri &)> CanonizeSuccessCallback
Definition: face-uri.hpp:160
const std::string & getPort() const
get port
Definition: face-uri.hpp:123
bool isCanonical() const
determine whether this FaceUri is in canonical form
Definition: face-uri.cpp:507
friend std::ostream & operator<<(std::ostream &os, const FaceUri &uri)
Definition: face-uri.cpp:193
const std::string & getScheme() const
get scheme (protocol)
Definition: face-uri.hpp:109
Error(const std::string &what)
Definition: face-uri.hpp:51
bool operator!=(const FaceUri &rhs) const
Definition: face-uri.cpp:179
const std::string & getHost() const
get host (domain)
Definition: face-uri.hpp:116
static FaceUri fromDev(const std::string &ifname)
create dev FaceUri from network device name
Definition: face-uri.cpp:160
std::string toString() const
write as a string
Definition: face-uri.cpp:185
function< void(const std::string &reason)> CanonizeFailureCallback
Definition: face-uri.hpp:161
static FaceUri fromFd(int fd)
create fd FaceUri from file descriptor
Definition: face-uri.cpp:144
void canonize(const CanonizeSuccessCallback &onSuccess, const CanonizeFailureCallback &onFailure, boost::asio::io_service &io, const time::nanoseconds &timeout) const
asynchronously convert this FaceUri to canonical form
Definition: face-uri.cpp:523