Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [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 | |
| 7 | #ifndef NFD_FACE_TCP_CHANNEL_FACTORY_HPP |
| 8 | #define NFD_FACE_TCP_CHANNEL_FACTORY_HPP |
| 9 | |
| 10 | #include "channel-factory.hpp" |
| 11 | #include "tcp-channel.hpp" |
| 12 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 13 | namespace nfd { |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 14 | |
| 15 | class TcpChannelFactory : public ChannelFactory<tcp::Endpoint, TcpChannel> |
| 16 | { |
| 17 | public: |
| 18 | /** |
| 19 | * \brief Exception of TcpChannelFactory |
| 20 | */ |
| 21 | struct Error : public ChannelFactory::Error |
| 22 | { |
| 23 | Error(const std::string& what) : ChannelFactory::Error(what) {} |
| 24 | }; |
| 25 | |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 26 | TcpChannelFactory(boost::asio::io_service& ioService); |
| 27 | |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 28 | /** |
| 29 | * \brief Create TCP-based channel using tcp::Endpoint |
| 30 | * |
| 31 | * tcp::Endpoint is really an alias for boost::asio::ip::tcp::endpoint. |
| 32 | * |
| 33 | * If this method called twice with the same endpoint, only one channel |
| 34 | * will be created. The second call will just retrieve the existing |
| 35 | * channel. |
| 36 | * |
| 37 | * \returns always a valid pointer to a TcpChannel object, an exception |
| 38 | * is thrown if it cannot be created. |
| 39 | * |
| 40 | * \throws TcpChannelFactory::Error |
| 41 | * |
| 42 | * \see http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/reference/ip__tcp/endpoint.html |
| 43 | * for details on ways to create tcp::Endpoint |
| 44 | */ |
| 45 | shared_ptr<TcpChannel> |
| 46 | create(const tcp::Endpoint& localEndpoint); |
| 47 | |
| 48 | /** |
| 49 | * \brief Create TCP-based channel using specified host and port number |
| 50 | * |
| 51 | * This method will attempt to resolve the provided host and port numbers |
| 52 | * and will throw TcpChannelFactory::Error when channel cannot be created. |
| 53 | * |
| 54 | * Note that this call will **BLOCK** until resolution is done or failed. |
| 55 | * |
| 56 | * \throws TcpChannelFactory::Error |
| 57 | */ |
| 58 | shared_ptr<TcpChannel> |
| 59 | create(const std::string& localHost, const std::string& localPort); |
| 60 | |
| 61 | /** |
| 62 | * \brief Look up TcpChannel using specified local endpoint |
| 63 | * |
| 64 | * \returns shared pointer to the existing TcpChannel object |
| 65 | * or empty shared pointer when such channel does not exist |
| 66 | * |
| 67 | * \throws never |
| 68 | */ |
| 69 | shared_ptr<TcpChannel> |
| 70 | find(const tcp::Endpoint& localEndpoint); |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 71 | |
| 72 | private: |
| 73 | boost::asio::io_service& m_ioService; |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 74 | }; |
| 75 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 76 | } // namespace nfd |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 77 | |
| 78 | #endif // NFD_FACE_TCP_CHANNEL_FACTORY_HPP |