blob: 20c01d915f93161bb3c1d43ab744231eba464d71 [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"
Alexander Afanasyev7329e022014-02-27 14:47:22 -08008#include "core/global-io.hpp"
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +01009
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010010#include <boost/filesystem.hpp> // for canonical()
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010011
12namespace nfd {
13
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010014shared_ptr<UnixStreamChannel>
Alexander Afanasyevd6655302014-02-28 08:41:28 -080015UnixStreamFactory::createChannel(const std::string& unixSocketPath)
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010016{
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010017 boost::filesystem::path p(unixSocketPath);
18 p = boost::filesystem::canonical(p.parent_path()) / p.filename();
19 unix_stream::Endpoint endpoint(p.string());
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010020
Alexander Afanasyevd6655302014-02-28 08:41:28 -080021 shared_ptr<UnixStreamChannel> channel = findChannel(endpoint);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010022 if (channel)
23 return channel;
24
Alexander Afanasyev7329e022014-02-27 14:47:22 -080025 channel = make_shared<UnixStreamChannel>(boost::ref(getGlobalIoService()),
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010026 boost::cref(endpoint));
27 m_channels[endpoint] = channel;
28 return channel;
29}
30
31shared_ptr<UnixStreamChannel>
Alexander Afanasyevd6655302014-02-28 08:41:28 -080032UnixStreamFactory::findChannel(const unix_stream::Endpoint& endpoint)
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010033{
34 ChannelMap::iterator i = m_channels.find(endpoint);
35 if (i != m_channels.end())
36 return i->second;
37 else
38 return shared_ptr<UnixStreamChannel>();
39}
40
Alexander Afanasyevd6655302014-02-28 08:41:28 -080041void
42UnixStreamFactory::createFace(const FaceUri& uri,
43 const FaceCreatedCallback& onCreated,
44 const FaceConnectFailedCallback& onConnectFailed)
45{
46 throw Error("UnixStreamFactory does not support 'createFace' operation");
47}
48
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010049} // namespace nfd