Files
NFD/daemon/face/unix-stream-factory.cpp
T
Junxiao Shi 61e3cc51ed faces: Channel base class
refs #1261

Change-Id: If17037c4802cb6ccec0201c3bff7fc4b6db41c6a
2014-03-05 11:56:10 -07:00

48 lines
1.3 KiB
C++

/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (C) 2014 Named Data Networking Project
* See COPYING for copyright and distribution information.
*/
#include "unix-stream-factory.hpp"
#include <boost/filesystem.hpp> // for canonical()
namespace nfd {
shared_ptr<UnixStreamChannel>
UnixStreamFactory::createChannel(const std::string& unixSocketPath)
{
boost::filesystem::path p(unixSocketPath);
p = boost::filesystem::canonical(p.parent_path()) / p.filename();
unix_stream::Endpoint endpoint(p.string());
shared_ptr<UnixStreamChannel> channel = findChannel(endpoint);
if (channel)
return channel;
channel = make_shared<UnixStreamChannel>(boost::cref(endpoint));
m_channels[endpoint] = channel;
return channel;
}
shared_ptr<UnixStreamChannel>
UnixStreamFactory::findChannel(const unix_stream::Endpoint& endpoint)
{
ChannelMap::iterator i = m_channels.find(endpoint);
if (i != m_channels.end())
return i->second;
else
return shared_ptr<UnixStreamChannel>();
}
void
UnixStreamFactory::createFace(const FaceUri& uri,
const FaceCreatedCallback& onCreated,
const FaceConnectFailedCallback& onConnectFailed)
{
throw Error("UnixStreamFactory does not support 'createFace' operation");
}
} // namespace nfd