Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | e1e6f2a | 2014-04-25 11:28:12 -0700 | [diff] [blame] | 3 | * 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 Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 18 | */ |
Alexander Afanasyev | e1e6f2a | 2014-04-25 11:28:12 -0700 | [diff] [blame] | 19 | |
Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 20 | #include "read-handle.hpp" |
| 21 | |
| 22 | namespace repo { |
| 23 | |
| 24 | void |
| 25 | ReadHandle::onInterest(const Name& prefix, const Interest& interest) |
| 26 | { |
| 27 | Data data; |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 28 | if (getStorageHandle().readData(interest, data)) { |
| 29 | getFace().put(data); |
Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 30 | } |
| 31 | } |
| 32 | |
| 33 | void |
Wentao Shang | 91fb4f2 | 2014-05-20 10:55:22 -0700 | [diff] [blame^] | 34 | ReadHandle::onRegisterSuccess(const Name& prefix) |
| 35 | { |
| 36 | std::cerr << "Successfully registered prefix " << prefix << std::endl; |
| 37 | } |
| 38 | |
| 39 | void |
Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 40 | ReadHandle::onRegisterFailed(const Name& prefix, const std::string& reason) |
| 41 | { |
| 42 | std::cerr << "ERROR: Failed to register prefix in local hub's daemon" << std::endl; |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 43 | getFace().shutdown(); |
Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | void |
| 47 | ReadHandle::listen(const Name& prefix) |
| 48 | { |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 49 | getFace().setInterestFilter(prefix, |
| 50 | bind(&ReadHandle::onInterest, this, _1, _2), |
Wentao Shang | 91fb4f2 | 2014-05-20 10:55:22 -0700 | [diff] [blame^] | 51 | bind(&ReadHandle::onRegisterSuccess, this, _1), |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 52 | bind(&ReadHandle::onRegisterFailed, this, _1, _2)); |
Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | } //namespace repo |