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> |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 39 | 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 Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 47 | |
| 48 | private: |
| 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 Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 58 | findChannel(const unix_stream::Endpoint& endpoint); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 59 | |
| 60 | private: |
Alexander Afanasyev | 7329e02 | 2014-02-27 14:47:22 -0800 | [diff] [blame] | 61 | typedef std::map< unix_stream::Endpoint, shared_ptr<UnixStreamChannel> > ChannelMap; |
| 62 | ChannelMap m_channels; |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | } // namespace nfd |
| 66 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 67 | #endif // NFD_FACE_UNIX_STREAM_FACTORY_HPP |