NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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  auto 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 void
50  ndn::nfd::FacePersistency persistency,
51  bool wantLocalFieldsEnabled,
52  const FaceCreatedCallback& onCreated,
53  const FaceCreationFailedCallback& onFailure)
54 {
55  onFailure(406, "Unsupported protocol");
56 }
57 
58 std::vector<shared_ptr<const Channel>>
60 {
61  std::vector<shared_ptr<const Channel>> channels;
62  channels.reserve(m_channels.size());
63 
64  for (const auto& i : m_channels)
65  channels.push_back(i.second);
66 
67  return channels;
68 }
69 
70 shared_ptr<UnixStreamChannel>
71 UnixStreamFactory::findChannel(const unix_stream::Endpoint& endpoint) const
72 {
73  auto i = m_channels.find(endpoint);
74  if (i != m_channels.end())
75  return i->second;
76  else
77  return nullptr;
78 }
79 
80 } // namespace nfd
virtual void createFace(const FaceUri &uri, ndn::nfd::FacePersistency persistency, bool wantLocalFieldsEnabled, const FaceCreatedCallback &onCreated, const FaceCreationFailedCallback &onFailure) override
Try to create Face using the supplied FaceUri.
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:44
virtual std::vector< shared_ptr< const Channel > > getChannels() const override
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
shared_ptr< UnixStreamChannel > createChannel(const std::string &unixSocketPath)
Create stream-oriented Unix channel using specified socket path.
function< void(uint32_t status, const std::string &reason)> FaceCreationFailedCallback
Prototype for the callback that is invoked when the face fails to be created.
Definition: channel.hpp:44
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
boost::asio::local::stream_protocol::endpoint Endpoint