Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 7 | #include "unix-stream-factory.hpp" |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 8 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 9 | #include <boost/filesystem.hpp> // for canonical() |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 10 | |
| 11 | namespace nfd { |
| 12 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 13 | shared_ptr<UnixStreamChannel> |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 14 | UnixStreamFactory::createChannel(const std::string& unixSocketPath) |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 15 | { |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 16 | boost::filesystem::path p(unixSocketPath); |
| 17 | p = boost::filesystem::canonical(p.parent_path()) / p.filename(); |
| 18 | unix_stream::Endpoint endpoint(p.string()); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 19 | |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 20 | shared_ptr<UnixStreamChannel> channel = findChannel(endpoint); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 21 | if (channel) |
| 22 | return channel; |
| 23 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame^] | 24 | channel = make_shared<UnixStreamChannel>(boost::cref(endpoint)); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 25 | m_channels[endpoint] = channel; |
| 26 | return channel; |
| 27 | } |
| 28 | |
| 29 | shared_ptr<UnixStreamChannel> |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 30 | UnixStreamFactory::findChannel(const unix_stream::Endpoint& endpoint) |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 31 | { |
| 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 Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 39 | void |
| 40 | UnixStreamFactory::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 Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 47 | } // namespace nfd |