blob: 45668c988b678beff9c4008df68ea4959ded2ceb [file] [log] [blame]
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * Copyright (c) 2014 Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology
9 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010024
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080025#include "unix-stream-factory.hpp"
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010026
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010027#include <boost/filesystem.hpp> // for canonical()
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010028
29namespace nfd {
30
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010031shared_ptr<UnixStreamChannel>
Alexander Afanasyevd6655302014-02-28 08:41:28 -080032UnixStreamFactory::createChannel(const std::string& unixSocketPath)
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010033{
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010034 boost::filesystem::path p(unixSocketPath);
35 p = boost::filesystem::canonical(p.parent_path()) / p.filename();
36 unix_stream::Endpoint endpoint(p.string());
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010037
Alexander Afanasyevd6655302014-02-28 08:41:28 -080038 shared_ptr<UnixStreamChannel> channel = findChannel(endpoint);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010039 if (channel)
40 return channel;
41
Alexander Afanasyevf6980282014-05-13 18:28:40 -070042 channel = make_shared<UnixStreamChannel>(endpoint);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010043 m_channels[endpoint] = channel;
44 return channel;
45}
46
47shared_ptr<UnixStreamChannel>
Alexander Afanasyevd6655302014-02-28 08:41:28 -080048UnixStreamFactory::findChannel(const unix_stream::Endpoint& endpoint)
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010049{
50 ChannelMap::iterator i = m_channels.find(endpoint);
51 if (i != m_channels.end())
52 return i->second;
53 else
54 return shared_ptr<UnixStreamChannel>();
55}
56
Alexander Afanasyevd6655302014-02-28 08:41:28 -080057void
58UnixStreamFactory::createFace(const FaceUri& uri,
59 const FaceCreatedCallback& onCreated,
60 const FaceConnectFailedCallback& onConnectFailed)
61{
62 throw Error("UnixStreamFactory does not support 'createFace' operation");
63}
64
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010065} // namespace nfd