Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Regents of the University of California. |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | #include "read-handle.hpp" |
| 7 | |
| 8 | namespace repo { |
| 9 | |
| 10 | void |
| 11 | ReadHandle::onInterest(const Name& prefix, const Interest& interest) |
| 12 | { |
| 13 | Data data; |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 14 | if (getStorageHandle().readData(interest, data)) { |
| 15 | getFace().put(data); |
Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 16 | } |
| 17 | } |
| 18 | |
| 19 | void |
| 20 | ReadHandle::onRegisterFailed(const Name& prefix, const std::string& reason) |
| 21 | { |
| 22 | 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] | 23 | getFace().shutdown(); |
Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | void |
| 27 | ReadHandle::listen(const Name& prefix) |
| 28 | { |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 29 | getFace().setInterestFilter(prefix, |
| 30 | bind(&ReadHandle::onInterest, this, _1, _2), |
| 31 | bind(&ReadHandle::onRegisterFailed, this, _1, _2)); |
Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | } //namespace repo |