NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
unix-stream-factory.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "unix-stream-factory.hpp"
27 
28 #include <boost/filesystem.hpp> // for canonical()
29 
30 namespace nfd {
31 
32 shared_ptr<UnixStreamChannel>
33 UnixStreamFactory::createChannel(const std::string& unixSocketPath)
34 {
35  boost::filesystem::path p(unixSocketPath);
36  p = boost::filesystem::canonical(p.parent_path()) / p.filename();
37  unix_stream::Endpoint endpoint(p.string());
38 
39  shared_ptr<UnixStreamChannel> channel = findChannel(endpoint);
40  if (channel)
41  return channel;
42 
43  channel = make_shared<UnixStreamChannel>(endpoint);
44  m_channels[endpoint] = channel;
45  return channel;
46 }
47 
48 shared_ptr<UnixStreamChannel>
49 UnixStreamFactory::findChannel(const unix_stream::Endpoint& endpoint)
50 {
51  ChannelMap::iterator i = m_channels.find(endpoint);
52  if (i != m_channels.end())
53  return i->second;
54  else
55  return shared_ptr<UnixStreamChannel>();
56 }
57 
58 void
60  ndn::nfd::FacePersistency persistency,
61  const FaceCreatedCallback& onCreated,
62  const FaceConnectFailedCallback& onConnectFailed)
63 {
64  BOOST_THROW_EXCEPTION(Error("UnixStreamFactory does not support 'createFace' operation"));
65 }
66 
67 std::list<shared_ptr<const Channel> >
69 {
70  std::list<shared_ptr<const Channel> > channels;
71  for (ChannelMap::const_iterator i = m_channels.begin(); i != m_channels.end(); ++i)
72  {
73  channels.push_back(i->second);
74  }
75 
76  return channels;
77 }
78 
79 } // namespace nfd
function< void(const std::string &reason)> FaceConnectFailedCallback
Prototype for the callback that is called when face is failed to get created.
virtual std::list< shared_ptr< const Channel > > getChannels() const
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:44
Exception of UnixStreamFactory.
Table::const_iterator iterator
Definition: cs-internal.hpp:41
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
shared_ptr< UnixStreamChannel > createChannel(const std::string &unixSocketPath)
Create stream-oriented Unix channel using specified socket path.
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::local::stream_protocol::endpoint Endpoint
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.