blob: 8a00bde66391cf321ebbe20659b69744f71460d4 [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
Alexander Afanasyev0eb70652014-02-27 18:35:07 -08007#ifndef NFD_FACE_PROTOCOL_FACTORY_HPP
8#define NFD_FACE_PROTOCOL_FACTORY_HPP
Alexander Afanasyeva9034b02014-01-26 18:32:02 -08009
10#include "common.hpp"
Alexander Afanasyevd6655302014-02-28 08:41:28 -080011#include "core/face-uri.hpp"
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080012
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080013namespace nfd {
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080014
Alexander Afanasyevd6655302014-02-28 08:41:28 -080015class Face;
16
17/**
18 * \brief Prototype for the callback called when face is created
19 * (as a response to incoming connection or after connection
20 * is established)
21 */
22typedef function<void(const shared_ptr<Face>& newFace)> FaceCreatedCallback;
23
24/**
25 * \brief Prototype for the callback that is called when face is failed to
26 * get created
27 */
28typedef function<void(const std::string& reason)> FaceConnectFailedCallback;
29
30
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080031class ProtocolFactory
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080032{
33public:
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080034 /**
35 * \brief Base class for all exceptions thrown by channel factories
36 */
37 struct Error : public std::runtime_error
38 {
39 Error(const std::string& what) : std::runtime_error(what) {}
40 };
Alexander Afanasyevd6655302014-02-28 08:41:28 -080041
42 /** \brief Try to create Face using the supplied Face URI
43 *
44 * This method should automatically choose channel, based on supplied Face URI
45 * and create face.
46 *
47 * \throws Factory::Error if Factory does not support connect operation
48 */
49 virtual void
50 createFace(const FaceUri& uri,
51 const FaceCreatedCallback& onCreated,
52 const FaceConnectFailedCallback& onConnectFailed) = 0;
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080053};
54
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080055} // namespace nfd
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080056
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080057#endif // NFD_FACE_PROTOCOL_FACTORY_HPP