blob: ef857d8fbbc93f468e41fb4ba364c7dfdbd7c834 [file] [log] [blame]
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +01001/* -*- 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 Afanasyev0eb70652014-02-27 18:35:07 -08007#ifndef NFD_FACE_UNIX_STREAM_FACTORY_HPP
8#define NFD_FACE_UNIX_STREAM_FACTORY_HPP
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +01009
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080010#include "protocol-factory.hpp"
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010011#include "unix-stream-channel.hpp"
12
13namespace nfd {
14
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080015class UnixStreamFactory : public ProtocolFactory
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010016{
17public:
18 /**
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080019 * \brief Exception of UnixStreamFactory
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010020 */
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080021 struct Error : public ProtocolFactory::Error
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010022 {
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080023 Error(const std::string& what) : ProtocolFactory::Error(what) {}
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010024 };
25
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010026 /**
27 * \brief Create stream-oriented Unix channel using specified socket path
28 *
29 * If this method is called twice with the same path, only one channel
30 * will be created. The second call will just retrieve the existing
31 * channel.
32 *
33 * \returns always a valid pointer to a UnixStreamChannel object,
34 * an exception will be thrown if the channel cannot be created.
35 *
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080036 * \throws UnixStreamFactory::Error
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010037 */
38 shared_ptr<UnixStreamChannel>
Alexander Afanasyevd6655302014-02-28 08:41:28 -080039 createChannel(const std::string& unixSocketPath);
40
41 // from Factory
42
43 virtual void
44 createFace(const FaceUri& uri,
45 const FaceCreatedCallback& onCreated,
46 const FaceConnectFailedCallback& onConnectFailed);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010047
48private:
49 /**
50 * \brief Look up UnixStreamChannel using specified endpoint
51 *
52 * \returns shared pointer to the existing UnixStreamChannel object
53 * or empty shared pointer when such channel does not exist
54 *
55 * \throws never
56 */
57 shared_ptr<UnixStreamChannel>
Alexander Afanasyevd6655302014-02-28 08:41:28 -080058 findChannel(const unix_stream::Endpoint& endpoint);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010059
60private:
Alexander Afanasyev7329e022014-02-27 14:47:22 -080061 typedef std::map< unix_stream::Endpoint, shared_ptr<UnixStreamChannel> > ChannelMap;
62 ChannelMap m_channels;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010063};
64
65} // namespace nfd
66
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080067#endif // NFD_FACE_UNIX_STREAM_FACTORY_HPP