blob: 83133e29b82943e10da02cf9e92120bfe0444540 [file] [log] [blame]
Shuo Chen9c2477f2014-03-13 15:01:06 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyeve1e6f2a2014-04-25 11:28:12 -07003 * Copyright (c) 2014, Regents of the University of California.
4 *
5 * This file is part of NDN repo-ng (Next generation of NDN repository).
6 * See AUTHORS.md for complete list of repo-ng authors and contributors.
7 *
8 * repo-ng is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Shuo Chen9c2477f2014-03-13 15:01:06 -070018 */
Alexander Afanasyeve1e6f2a2014-04-25 11:28:12 -070019
Shuo Chen9c2477f2014-03-13 15:01:06 -070020#include "read-handle.hpp"
21
22namespace repo {
23
24void
25ReadHandle::onInterest(const Name& prefix, const Interest& interest)
26{
Shuo Chen9c2477f2014-03-13 15:01:06 -070027
Weiqi Shif0330d52014-07-09 10:54:27 -070028 shared_ptr<ndn::Data> data = getStorageHandle().readData(interest);
29 if (data != NULL) {
30 getFace().put(*data);
31 }
Wentao Shang91fb4f22014-05-20 10:55:22 -070032}
33
34void
Shuo Chen9c2477f2014-03-13 15:01:06 -070035ReadHandle::onRegisterFailed(const Name& prefix, const std::string& reason)
36{
37 std::cerr << "ERROR: Failed to register prefix in local hub's daemon" << std::endl;
Shuo Chen29c77fe2014-03-18 11:29:41 -070038 getFace().shutdown();
Shuo Chen9c2477f2014-03-13 15:01:06 -070039}
40
41void
42ReadHandle::listen(const Name& prefix)
43{
Weiqi Shif0330d52014-07-09 10:54:27 -070044 ndn::InterestFilter filter(prefix);
45 getFace().setInterestFilter(filter,
Shuo Chen29c77fe2014-03-18 11:29:41 -070046 bind(&ReadHandle::onInterest, this, _1, _2),
47 bind(&ReadHandle::onRegisterFailed, this, _1, _2));
Shuo Chen9c2477f2014-03-13 15:01:06 -070048}
49
50} //namespace repo