Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 22 | #ifndef NDN_TRANSPORT_UNIX_TRANSPORT_HPP |
| 23 | #define NDN_TRANSPORT_UNIX_TRANSPORT_HPP |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 24 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 25 | #include "../common.hpp" |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 26 | #include "transport.hpp" |
Junxiao Shi | d27b069 | 2014-12-28 10:33:14 -0700 | [diff] [blame^] | 27 | #include "../util/config-file.hpp" |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 28 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 29 | // forward declaration |
| 30 | namespace boost { namespace asio { namespace local { class stream_protocol; } } } |
| 31 | |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 32 | namespace ndn { |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 33 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 34 | // forward declaration |
| 35 | template<class T, class U> |
| 36 | class StreamTransportImpl; |
| 37 | |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 38 | class UnixTransport : public Transport |
| 39 | { |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 40 | public: |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 41 | |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 42 | /** |
| 43 | * Create Unix transport based on the socket specified |
| 44 | * in a well-known configuration file or fallback to /var/run/nfd.sock |
| 45 | * |
| 46 | * @throws Throws UnixTransport::Error on failure to parse a discovered configuration file |
| 47 | */ |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 48 | UnixTransport(const std::string& unixSocket); |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 49 | |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 50 | ~UnixTransport(); |
| 51 | |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 52 | // from Transport |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 53 | virtual void |
| 54 | connect(boost::asio::io_service& ioService, |
| 55 | const ReceiveCallback& receiveCallback); |
| 56 | |
| 57 | virtual void |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 58 | close(); |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 59 | |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 60 | virtual void |
Alexander Afanasyev | 52afb3f | 2014-03-07 09:05:35 +0000 | [diff] [blame] | 61 | pause(); |
| 62 | |
| 63 | virtual void |
| 64 | resume(); |
| 65 | |
| 66 | virtual void |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 67 | send(const Block& wire); |
| 68 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 69 | virtual void |
| 70 | send(const Block& header, const Block& payload); |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 71 | |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 72 | static shared_ptr<UnixTransport> |
| 73 | create(const ConfigFile& config); |
| 74 | |
| 75 | NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 76 | /** |
| 77 | * Determine the default NFD unix socket |
| 78 | * |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 79 | * @returns transport value if present in config, else /var/run/nfd.sock |
| 80 | * @throws ConfigFile::Error if fail to parse value of a present "transport" field |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 81 | */ |
| 82 | static std::string |
| 83 | getDefaultSocketName(const ConfigFile& config); |
| 84 | |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 85 | private: |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 86 | std::string m_unixSocket; |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 87 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 88 | typedef StreamTransportImpl<UnixTransport, boost::asio::local::stream_protocol> Impl; |
| 89 | friend class StreamTransportImpl<UnixTransport, boost::asio::local::stream_protocol>; |
Alexander Afanasyev | f73f063 | 2014-05-12 18:02:37 -0700 | [diff] [blame] | 90 | shared_ptr< Impl > m_impl; |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 91 | }; |
| 92 | |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 93 | } // namespace ndn |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 94 | |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 95 | #endif // NDN_TRANSPORT_UNIX_TRANSPORT_HPP |