Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 7 | #ifndef NFD_FACE_UNIX_STREAM_FACTORY_HPP |
| 8 | #define NFD_FACE_UNIX_STREAM_FACTORY_HPP |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 9 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 10 | #include "protocol-factory.hpp" |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 11 | #include "unix-stream-channel.hpp" |
| 12 | |
| 13 | namespace nfd { |
| 14 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 15 | class UnixStreamFactory : public ProtocolFactory |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 16 | { |
| 17 | public: |
| 18 | /** |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 19 | * \brief Exception of UnixStreamFactory |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 20 | */ |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 21 | struct Error : public ProtocolFactory::Error |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 22 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 23 | Error(const std::string& what) : ProtocolFactory::Error(what) {} |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 24 | }; |
| 25 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 26 | /** |
| 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 Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 36 | * \throws UnixStreamFactory::Error |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 37 | */ |
| 38 | shared_ptr<UnixStreamChannel> |
| 39 | create(const std::string& unixSocketPath); |
| 40 | |
| 41 | private: |
| 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 | |
| 53 | private: |
Alexander Afanasyev | 7329e02 | 2014-02-27 14:47:22 -0800 | [diff] [blame] | 54 | typedef std::map< unix_stream::Endpoint, shared_ptr<UnixStreamChannel> > ChannelMap; |
| 55 | ChannelMap m_channels; |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | } // namespace nfd |
| 59 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 60 | #endif // NFD_FACE_UNIX_STREAM_FACTORY_HPP |