blob: 99d868839aa3fe607c534db306865af008985c0c [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 Afanasyev57e00362016-06-23 13:22:54 -07003 * Copyright (c) 2013-2016 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 Afanasyevfe3b1502013-12-18 16:45:03 -080025#include "transport.hpp"
Junxiao Shid27b0692014-12-28 10:33:14 -070026#include "../util/config-file.hpp"
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080027
Junxiao Shi446de3c2016-07-25 22:38:16 +000028namespace boost {
29namespace asio {
30namespace local {
31class stream_protocol;
32} // namespace local
33} // namespace asio
34} // namespace boost
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080035
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080036namespace ndn {
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080037
Junxiao Shi446de3c2016-07-25 22:38:16 +000038template<typename BaseTransport, typename Protocol>
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080039class StreamTransportImpl;
40
Junxiao Shi446de3c2016-07-25 22:38:16 +000041/** \brief a transport using Unix stream socket
42 */
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080043class UnixTransport : public Transport
44{
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080045public:
Junxiao Shi446de3c2016-07-25 22:38:16 +000046 explicit
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080047 UnixTransport(const std::string& unixSocket);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060048
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080049 ~UnixTransport();
50
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080051 virtual void
52 connect(boost::asio::io_service& ioService,
Junxiao Shi446de3c2016-07-25 22:38:16 +000053 const ReceiveCallback& receiveCallback) override;
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080054
55 virtual void
Junxiao Shi446de3c2016-07-25 22:38:16 +000056 close() override;
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080057
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080058 virtual void
Junxiao Shi446de3c2016-07-25 22:38:16 +000059 pause() override;
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000060
61 virtual void
Junxiao Shi446de3c2016-07-25 22:38:16 +000062 resume() override;
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000063
64 virtual void
Junxiao Shi446de3c2016-07-25 22:38:16 +000065 send(const Block& wire) override;
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080066
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080067 virtual void
Junxiao Shi446de3c2016-07-25 22:38:16 +000068 send(const Block& header, const Block& payload) override;
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060069
Junxiao Shi446de3c2016-07-25 22:38:16 +000070 /** \brief Create transport with parameters defined in URI
71 * \throw Transport::Error if incorrect URI or unsupported protocol is specified
Alexander Afanasyev57e00362016-06-23 13:22:54 -070072 */
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070073 static shared_ptr<UnixTransport>
Alexander Afanasyev57e00362016-06-23 13:22:54 -070074 create(const std::string& uri);
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070075
76NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060077 static std::string
Alexander Afanasyev57e00362016-06-23 13:22:54 -070078 getSocketNameFromUri(const std::string& uri);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060079
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080080private:
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080081 std::string m_unixSocket;
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080082
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080083 typedef StreamTransportImpl<UnixTransport, boost::asio::local::stream_protocol> Impl;
84 friend class StreamTransportImpl<UnixTransport, boost::asio::local::stream_protocol>;
Junxiao Shi446de3c2016-07-25 22:38:16 +000085 shared_ptr<Impl> m_impl;
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080086};
87
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070088} // namespace ndn
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080089
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070090#endif // NDN_TRANSPORT_UNIX_TRANSPORT_HPP