NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
websocket-factory.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "websocket-factory.hpp"
27 
28 namespace nfd {
29 
30 namespace ip = boost::asio::ip;
31 
32 shared_ptr<WebSocketChannel>
34 {
35  auto channel = findChannel(endpoint);
36  if (channel)
37  return channel;
38 
39  channel = make_shared<WebSocketChannel>(endpoint);
40  m_channels[endpoint] = channel;
41 
42  return channel;
43 }
44 
45 shared_ptr<WebSocketChannel>
46 WebSocketFactory::createChannel(const std::string& localIp, const std::string& localPort)
47 {
48  websocket::Endpoint endpoint(ip::address::from_string(localIp),
49  boost::lexical_cast<uint16_t>(localPort));
50  return createChannel(endpoint);
51 }
52 
53 void
55  ndn::nfd::FacePersistency persistency,
56  const FaceCreatedCallback& onCreated,
57  const FaceCreationFailedCallback& onConnectFailed)
58 {
59  BOOST_THROW_EXCEPTION(Error("WebSocketFactory does not support 'createFace' operation"));
60 }
61 
62 std::vector<shared_ptr<const Channel>>
64 {
65  std::vector<shared_ptr<const Channel>> channels;
66  channels.reserve(m_channels.size());
67 
68  for (const auto& i : m_channels)
69  channels.push_back(i.second);
70 
71  return channels;
72 }
73 
74 shared_ptr<WebSocketChannel>
75 WebSocketFactory::findChannel(const websocket::Endpoint& endpoint) const
76 {
77  auto i = m_channels.find(endpoint);
78  if (i != m_channels.end())
79  return i->second;
80  else
81  return nullptr;
82 }
83 
84 } // namespace nfd
virtual void createFace(const FaceUri &uri, ndn::nfd::FacePersistency persistency, const FaceCreatedCallback &onCreated, const FaceCreationFailedCallback &onConnectFailed) 1
Try to create Face using the supplied FaceUri.
function< void(const std::string &reason)> FaceCreationFailedCallback
Prototype for the callback that is invoked when the face fails to be created.
Definition: channel.hpp:44
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:44
shared_ptr< WebSocketChannel > createChannel(const websocket::Endpoint &localEndpoint)
Create WebSocket-based channel using websocket::Endpoint.
Exception of WebSocketFactory.
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
function< void(const shared_ptr< Face > &newFace)> FaceCreatedCallback
Prototype for the callback that is invoked when the face is created (as a response to incoming connec...
Definition: channel.hpp:38
virtual std::vector< shared_ptr< const Channel > > getChannels() const 1
boost::asio::ip::tcp::endpoint Endpoint