blob: 04932ca6402d50221e969340ca19c63f6b9a92c3 [file] [log] [blame]
Alexander Afanasyeva9034b02014-01-26 18:32:02 -08001/* -*- 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
13namespace ndn {
14
15class TcpChannelFactory : public ChannelFactory<tcp::Endpoint, TcpChannel>
16{
17public:
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
26 /**
27 * \brief Create TCP-based channel using tcp::Endpoint
28 *
29 * tcp::Endpoint is really an alias for boost::asio::ip::tcp::endpoint.
30 *
31 * If this method called twice with the same endpoint, only one channel
32 * will be created. The second call will just retrieve the existing
33 * channel.
34 *
35 * \returns always a valid pointer to a TcpChannel object, an exception
36 * is thrown if it cannot be created.
37 *
38 * \throws TcpChannelFactory::Error
39 *
40 * \see http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/reference/ip__tcp/endpoint.html
41 * for details on ways to create tcp::Endpoint
42 */
43 shared_ptr<TcpChannel>
44 create(const tcp::Endpoint& localEndpoint);
45
46 /**
47 * \brief Create TCP-based channel using specified host and port number
48 *
49 * This method will attempt to resolve the provided host and port numbers
50 * and will throw TcpChannelFactory::Error when channel cannot be created.
51 *
52 * Note that this call will **BLOCK** until resolution is done or failed.
53 *
54 * \throws TcpChannelFactory::Error
55 */
56 shared_ptr<TcpChannel>
57 create(const std::string& localHost, const std::string& localPort);
58
59 /**
60 * \brief Look up TcpChannel using specified local endpoint
61 *
62 * \returns shared pointer to the existing TcpChannel object
63 * or empty shared pointer when such channel does not exist
64 *
65 * \throws never
66 */
67 shared_ptr<TcpChannel>
68 find(const tcp::Endpoint& localEndpoint);
69};
70
71} // namespace ndn
72
73#endif // NFD_FACE_TCP_CHANNEL_FACTORY_HPP