blob: bf141173cf39b3c8ed314cb51ff2515dcd8a3def [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
7#ifndef NFD_FACE_UNIX_STREAM_CHANNEL_FACTORY_HPP
8#define NFD_FACE_UNIX_STREAM_CHANNEL_FACTORY_HPP
9
10#include "channel-factory.hpp"
11#include "unix-stream-channel.hpp"
12
13namespace nfd {
14
Alexander Afanasyev7329e022014-02-27 14:47:22 -080015class UnixStreamChannelFactory : public ChannelFactory
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010016{
17public:
18 /**
19 * \brief Exception of UnixStreamChannelFactory
20 */
Alexander Afanasyev7329e022014-02-27 14:47:22 -080021 struct Error : public ChannelFactory::Error
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010022 {
Alexander Afanasyev7329e022014-02-27 14:47:22 -080023 Error(const std::string& what) : ChannelFactory::Error(what) {}
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010024 };
25
26 explicit
Alexander Afanasyev7329e022014-02-27 14:47:22 -080027 UnixStreamChannelFactory();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010028
29 /**
30 * \brief Create stream-oriented Unix channel using specified socket path
31 *
32 * If this method is called twice with the same path, only one channel
33 * will be created. The second call will just retrieve the existing
34 * channel.
35 *
36 * \returns always a valid pointer to a UnixStreamChannel object,
37 * an exception will be thrown if the channel cannot be created.
38 *
39 * \throws UnixStreamChannelFactory::Error
40 */
41 shared_ptr<UnixStreamChannel>
42 create(const std::string& unixSocketPath);
43
44private:
45 /**
46 * \brief Look up UnixStreamChannel using specified endpoint
47 *
48 * \returns shared pointer to the existing UnixStreamChannel object
49 * or empty shared pointer when such channel does not exist
50 *
51 * \throws never
52 */
53 shared_ptr<UnixStreamChannel>
54 find(const unix_stream::Endpoint& endpoint);
55
56private:
Alexander Afanasyev7329e022014-02-27 14:47:22 -080057 typedef std::map< unix_stream::Endpoint, shared_ptr<UnixStreamChannel> > ChannelMap;
58 ChannelMap m_channels;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010059};
60
61} // namespace nfd
62
63#endif // NFD_FACE_UNIX_STREAM_CHANNEL_FACTORY_HPP