blob: 510b087da41439c50026a2c79d3fd244073ef23a [file] [log] [blame]
Yanbiao Li4ee73d42015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "internal-client-face.hpp"
27#include "internal-face.hpp"
28#include "core/global-io.hpp"
29
30#include <ndn-cxx/management/nfd-local-control-header.hpp>
31
32namespace nfd {
33
34void
35InternalClientFace::Transport::receive(const Block& block)
36{
37 if (m_receiveCallback) {
38 m_receiveCallback(block);
39 }
40}
41
42void
43InternalClientFace::Transport::close()
44{
45}
46
47void
48InternalClientFace::Transport::send(const Block& wire)
49{
50 onSendBlock(wire);
51}
52
53void
54InternalClientFace::Transport::send(const Block& header, const Block& payload)
55{
56 ndn::EncodingBuffer encoder(header.size() + payload.size(), header.size() + payload.size());
57 encoder.appendByteArray(header.wire(), header.size());
58 encoder.appendByteArray(payload.wire(), payload.size());
59
60 this->send(encoder.block());
61}
62
63void
64InternalClientFace::Transport::pause()
65{
66}
67
68void
69InternalClientFace::Transport::resume()
70{
71}
72
73InternalClientFace::InternalClientFace(const shared_ptr<InternalFace>& face,
74 const shared_ptr<InternalClientFace::Transport>& transport,
75 ndn::KeyChain& keyChain)
76 : ndn::Face(transport, getGlobalIoService(), keyChain)
77 , m_face(face)
78 , m_transport(transport)
79{
80 construct();
81}
82
83void
84InternalClientFace::construct()
85{
86 m_face->onSendInterest.connect(bind(&InternalClientFace::receive<Interest>, this, _1));
87 m_face->onSendData.connect(bind(&InternalClientFace::receive<Data>, this, _1));
88 m_transport->onSendBlock.connect(bind(&InternalFace::receive, m_face, _1));
89}
90
91shared_ptr<InternalClientFace>
92makeInternalClientFace(const shared_ptr<InternalFace>& face,
93 ndn::KeyChain& keyChain)
94{
95 auto transport = make_shared<InternalClientFace::Transport>();
96 return shared_ptr<InternalClientFace>(new InternalClientFace(face, transport, keyChain));
97}
98
99} // namespace nfd