blob: 5a7304705765c9e8ad90633492ac268b6f18beeb [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -08002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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 Afanasyevfe3b1502013-12-18 16:45:03 -080020 */
21
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070022#ifndef NDN_TRANSPORT_UNIX_TRANSPORT_HPP
23#define NDN_TRANSPORT_UNIX_TRANSPORT_HPP
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080024
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080025#include "../common.hpp"
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080026#include "transport.hpp"
Junxiao Shid27b0692014-12-28 10:33:14 -070027#include "../util/config-file.hpp"
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080028
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080029// forward declaration
30namespace boost { namespace asio { namespace local { class stream_protocol; } } }
31
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080032namespace ndn {
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080033
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080034// forward declaration
35template<class T, class U>
36class StreamTransportImpl;
37
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080038class UnixTransport : public Transport
39{
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080040public:
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080041
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060042 /**
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 Afanasyevf7ca3202014-02-14 22:28:31 -080048 UnixTransport(const std::string& unixSocket);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060049
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080050 ~UnixTransport();
51
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080052 // from Transport
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080053 virtual void
54 connect(boost::asio::io_service& ioService,
55 const ReceiveCallback& receiveCallback);
56
57 virtual void
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080058 close();
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080059
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080060 virtual void
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000061 pause();
62
63 virtual void
64 resume();
65
66 virtual void
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080067 send(const Block& wire);
68
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080069 virtual void
70 send(const Block& header, const Block& payload);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060071
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070072 static shared_ptr<UnixTransport>
73 create(const ConfigFile& config);
74
75NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060076 /**
77 * Determine the default NFD unix socket
78 *
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070079 * @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 DiBenedettoc07b3a22014-03-19 12:32:52 -060081 */
82 static std::string
83 getDefaultSocketName(const ConfigFile& config);
84
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080085private:
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080086 std::string m_unixSocket;
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080087
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080088 typedef StreamTransportImpl<UnixTransport, boost::asio::local::stream_protocol> Impl;
89 friend class StreamTransportImpl<UnixTransport, boost::asio::local::stream_protocol>;
Alexander Afanasyevf73f0632014-05-12 18:02:37 -070090 shared_ptr< Impl > m_impl;
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080091};
92
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070093} // namespace ndn
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080094
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070095#endif // NDN_TRANSPORT_UNIX_TRANSPORT_HPP