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 using namespace boost::asio;
31 
32 WebSocketFactory::WebSocketFactory(const std::string& defaultPort)
33  : m_defaultPort(defaultPort)
34 {
35 }
36 
37 shared_ptr<WebSocketChannel>
39 {
40  shared_ptr<WebSocketChannel> channel = findChannel(endpoint);
41  if (static_cast<bool>(channel))
42  return channel;
43 
44  channel = make_shared<WebSocketChannel>(endpoint);
45  m_channels[endpoint] = channel;
46 
47  return channel;
48 }
49 
50 shared_ptr<WebSocketChannel>
51 WebSocketFactory::createChannel(const std::string& localIp, const std::string& port)
52 {
53  using namespace boost::asio::ip;
54  websocket::Endpoint endpoint(address::from_string(localIp), boost::lexical_cast<uint16_t>(port));
55  return createChannel(endpoint);
56 }
57 
58 shared_ptr<WebSocketChannel>
59 WebSocketFactory::findChannel(const websocket::Endpoint& localEndpoint)
60 {
61  ChannelMap::iterator i = m_channels.find(localEndpoint);
62  if (i != m_channels.end())
63  return i->second;
64  else
65  return shared_ptr<WebSocketChannel>();
66 }
67 
68 void
70  ndn::nfd::FacePersistency persistency,
71  const FaceCreatedCallback& onCreated,
72  const FaceConnectFailedCallback& onConnectFailed)
73 {
74  BOOST_THROW_EXCEPTION(Error("WebSocketFactory does not support 'createFace' operation"));
75 }
76 
77 std::list<shared_ptr<const Channel> >
79 {
80  std::list<shared_ptr<const Channel> > channels;
81  for (ChannelMap::const_iterator i = m_channels.begin(); i != m_channels.end(); ++i)
82  {
83  channels.push_back(i->second);
84  }
85 
86  return channels;
87 }
88 
89 } // namespace nfd
function< void(const std::string &reason)> FaceConnectFailedCallback
Prototype for the callback that is called when face is failed to get created.
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.
Table::const_iterator iterator
Definition: cs-internal.hpp:41
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
virtual std::list< shared_ptr< const Channel > > getChannels() const
virtual void createFace(const FaceUri &uri, ndn::nfd::FacePersistency persistency, const FaceCreatedCallback &onCreated, const FaceConnectFailedCallback &onConnectFailed) 1
Try to create Face using the supplied FaceUri.
WebSocketFactory(const std::string &defaultPort)
function< void(const shared_ptr< Face > &newFace)> FaceCreatedCallback
Prototype for the callback called when face is created (as a response to incoming connection or after...
boost::asio::ip::tcp::endpoint Endpoint