blob: 41089cd6e76faed6608cf092595939821ef5bbdf [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#ifndef NFD_FACE_UNIX_STREAM_FACTORY_HPP
26#define NFD_FACE_UNIX_STREAM_FACTORY_HPP
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010027
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080028#include "protocol-factory.hpp"
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010029#include "unix-stream-channel.hpp"
30
31namespace nfd {
32
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080033class UnixStreamFactory : public ProtocolFactory
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010034{
35public:
36 /**
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080037 * \brief Exception of UnixStreamFactory
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010038 */
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080039 struct Error : public ProtocolFactory::Error
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010040 {
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080041 Error(const std::string& what) : ProtocolFactory::Error(what) {}
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010042 };
43
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010044 /**
45 * \brief Create stream-oriented Unix channel using specified socket path
46 *
47 * If this method is called twice with the same path, only one channel
48 * will be created. The second call will just retrieve the existing
49 * channel.
50 *
51 * \returns always a valid pointer to a UnixStreamChannel object,
52 * an exception will be thrown if the channel cannot be created.
53 *
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080054 * \throws UnixStreamFactory::Error
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010055 */
56 shared_ptr<UnixStreamChannel>
Alexander Afanasyevd6655302014-02-28 08:41:28 -080057 createChannel(const std::string& unixSocketPath);
58
59 // from Factory
60
61 virtual void
62 createFace(const FaceUri& uri,
63 const FaceCreatedCallback& onCreated,
64 const FaceConnectFailedCallback& onConnectFailed);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010065
66private:
67 /**
68 * \brief Look up UnixStreamChannel using specified endpoint
69 *
70 * \returns shared pointer to the existing UnixStreamChannel object
71 * or empty shared pointer when such channel does not exist
72 *
73 * \throws never
74 */
75 shared_ptr<UnixStreamChannel>
Alexander Afanasyevd6655302014-02-28 08:41:28 -080076 findChannel(const unix_stream::Endpoint& endpoint);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010077
78private:
Alexander Afanasyev7329e022014-02-27 14:47:22 -080079 typedef std::map< unix_stream::Endpoint, shared_ptr<UnixStreamChannel> > ChannelMap;
80 ChannelMap m_channels;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010081};
82
83} // namespace nfd
84
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080085#endif // NFD_FACE_UNIX_STREAM_FACTORY_HPP