blob: 8d0a6e7e736174bd8932c394d89d53a79b3b1dfe [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
7#ifndef NFD_FACE_UNIX_STREAM_CHANNEL_FACTORY_HPP
8#define NFD_FACE_UNIX_STREAM_CHANNEL_FACTORY_HPP
9
10#include "channel-factory.hpp"
11#include "unix-stream-channel.hpp"
12
13namespace nfd {
14
15class UnixStreamChannelFactory : public ChannelFactory<unix_stream::Endpoint, UnixStreamChannel>
16{
17public:
18 /**
19 * \brief Exception of UnixStreamChannelFactory
20 */
21 struct Error : public ChannelFactory<unix_stream::Endpoint, UnixStreamChannel>::Error
22 {
23 Error(const std::string& what)
24 : ChannelFactory<unix_stream::Endpoint, UnixStreamChannel>::Error(what)
25 {
26 }
27 };
28
29 explicit
30 UnixStreamChannelFactory(boost::asio::io_service& ioService);
31
32 /**
33 * \brief Create stream-oriented Unix channel using specified socket path
34 *
35 * If this method is called twice with the same path, only one channel
36 * will be created. The second call will just retrieve the existing
37 * channel.
38 *
39 * \returns always a valid pointer to a UnixStreamChannel object,
40 * an exception will be thrown if the channel cannot be created.
41 *
42 * \throws UnixStreamChannelFactory::Error
43 */
44 shared_ptr<UnixStreamChannel>
45 create(const std::string& unixSocketPath);
46
47private:
48 /**
49 * \brief Look up UnixStreamChannel using specified endpoint
50 *
51 * \returns shared pointer to the existing UnixStreamChannel object
52 * or empty shared pointer when such channel does not exist
53 *
54 * \throws never
55 */
56 shared_ptr<UnixStreamChannel>
57 find(const unix_stream::Endpoint& endpoint);
58
59private:
60 boost::asio::io_service& m_ioService;
61};
62
63} // namespace nfd
64
65#endif // NFD_FACE_UNIX_STREAM_CHANNEL_FACTORY_HPP