blob: 4b26a3fa967abee0fb187041fafd12f8db3adc32 [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>
39 create(const std::string& unixSocketPath);
40
41private:
42 /**
43 * \brief Look up UnixStreamChannel using specified endpoint
44 *
45 * \returns shared pointer to the existing UnixStreamChannel object
46 * or empty shared pointer when such channel does not exist
47 *
48 * \throws never
49 */
50 shared_ptr<UnixStreamChannel>
51 find(const unix_stream::Endpoint& endpoint);
52
53private:
Alexander Afanasyev7329e022014-02-27 14:47:22 -080054 typedef std::map< unix_stream::Endpoint, shared_ptr<UnixStreamChannel> > ChannelMap;
55 ChannelMap m_channels;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010056};
57
58} // namespace nfd
59
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080060#endif // NFD_FACE_UNIX_STREAM_FACTORY_HPP