blob: c38cab5b17c15a783efe400c9fdcaec895d877ff [file] [log] [blame]
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
Alexander Afanasyev0eb70652014-02-27 18:35:07 -08007#include "unix-stream-factory.hpp"
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +01008
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +01009#include <boost/filesystem.hpp> // for canonical()
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010010
11namespace nfd {
12
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010013shared_ptr<UnixStreamChannel>
Alexander Afanasyevd6655302014-02-28 08:41:28 -080014UnixStreamFactory::createChannel(const std::string& unixSocketPath)
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010015{
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010016 boost::filesystem::path p(unixSocketPath);
17 p = boost::filesystem::canonical(p.parent_path()) / p.filename();
18 unix_stream::Endpoint endpoint(p.string());
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010019
Alexander Afanasyevd6655302014-02-28 08:41:28 -080020 shared_ptr<UnixStreamChannel> channel = findChannel(endpoint);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010021 if (channel)
22 return channel;
23
Junxiao Shi61e3cc52014-03-03 20:40:28 -070024 channel = make_shared<UnixStreamChannel>(boost::cref(endpoint));
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010025 m_channels[endpoint] = channel;
26 return channel;
27}
28
29shared_ptr<UnixStreamChannel>
Alexander Afanasyevd6655302014-02-28 08:41:28 -080030UnixStreamFactory::findChannel(const unix_stream::Endpoint& endpoint)
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010031{
32 ChannelMap::iterator i = m_channels.find(endpoint);
33 if (i != m_channels.end())
34 return i->second;
35 else
36 return shared_ptr<UnixStreamChannel>();
37}
38
Alexander Afanasyevd6655302014-02-28 08:41:28 -080039void
40UnixStreamFactory::createFace(const FaceUri& uri,
41 const FaceCreatedCallback& onCreated,
42 const FaceConnectFailedCallback& onConnectFailed)
43{
44 throw Error("UnixStreamFactory does not support 'createFace' operation");
45}
46
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010047} // namespace nfd