Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | bb058c0 | 2018-02-15 22:49:24 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | b691ba1 | 2025-01-02 23:55:16 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2025, Regents of the University of California. |
Alexander Afanasyev | e1e6f2a | 2014-04-25 11:28:12 -0700 | [diff] [blame] | 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 | */ |
| 19 | |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 20 | #ifndef REPO_HANDLES_READ_HANDLE_HPP |
| 21 | #define REPO_HANDLES_READ_HANDLE_HPP |
Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 22 | |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 23 | #include "common.hpp" |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 24 | #include "storage/repo-storage.hpp" |
Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 25 | |
| 26 | namespace repo { |
| 27 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 28 | class ReadHandle : public noncopyable |
Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 29 | { |
Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 30 | public: |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 31 | using DataPrefixRegistrationCallback = std::function<void(const ndn::Name&)>; |
| 32 | using DataPrefixUnregistrationCallback = std::function<void(const ndn::Name&)>; |
Davide Pesavento | 7df36bd | 2023-10-28 19:32:43 -0400 | [diff] [blame] | 33 | |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 34 | struct RegisteredDataPrefix |
Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 35 | { |
Junxiao Shi | c44331e | 2019-01-31 16:27:27 +0000 | [diff] [blame] | 36 | ndn::RegisteredPrefixHandle hdl; |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 37 | int useCount; |
| 38 | }; |
| 39 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 40 | ReadHandle(Face& face, RepoStorage& storageHandle, size_t prefixSubsetLength); |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 41 | |
| 42 | void |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 43 | listen(const Name& prefix); |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 44 | |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 45 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 46 | const std::map<ndn::Name, RegisteredDataPrefix>& |
| 47 | getRegisteredPrefixes() |
| 48 | { |
| 49 | return m_insertedDataPrefixes; |
Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 52 | /** |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 53 | * @param name Full name of the deleted Data |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 54 | */ |
| 55 | void |
| 56 | onDataDeleted(const Name& name); |
| 57 | |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 58 | void |
| 59 | onDataInserted(const Name& name); |
Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 60 | |
Alexander Afanasyev | bb058c0 | 2018-02-15 22:49:24 +0000 | [diff] [blame] | 61 | void |
| 62 | connectAutoListen(); |
| 63 | |
Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 64 | private: |
| 65 | /** |
Shuo Chen | 29c77fe | 2014-03-18 11:29:41 -0700 | [diff] [blame] | 66 | * @brief Read data from backend storage |
Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 67 | */ |
| 68 | void |
| 69 | onInterest(const Name& prefix, const Interest& interest); |
| 70 | |
| 71 | void |
| 72 | onRegisterFailed(const Name& prefix, const std::string& reason); |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 73 | |
| 74 | private: |
| 75 | size_t m_prefixSubsetLength; |
| 76 | std::map<ndn::Name, RegisteredDataPrefix> m_insertedDataPrefixes; |
Davide Pesavento | b496642 | 2023-08-10 21:15:32 -0400 | [diff] [blame] | 77 | ndn::signal::ScopedConnection afterDataDeletionConnection; |
| 78 | ndn::signal::ScopedConnection afterDataInsertionConnection; |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 79 | Face& m_face; |
| 80 | RepoStorage& m_storageHandle; |
Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 83 | } // namespace repo |
Shuo Chen | 9c2477f | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 84 | |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 85 | #endif // REPO_HANDLES_READ_HANDLE_HPP |