Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -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 | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2022, Regents of the University of California. |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -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/>. |
| 18 | */ |
| 19 | |
Davide Pesavento | e18d368 | 2019-01-24 22:10:30 -0500 | [diff] [blame] | 20 | #ifndef REPO_STORAGE_REPO_STORAGE_HPP |
| 21 | #define REPO_STORAGE_REPO_STORAGE_HPP |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 22 | |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 23 | #include "storage.hpp" |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 24 | #include "../repo-command-parameter.hpp" |
| 25 | |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 26 | #include <ndn-cxx/util/signal.hpp> |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 27 | |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 28 | namespace repo { |
| 29 | |
| 30 | /** |
| 31 | * @brief RepoStorage handles the storage part of whole repo, |
| 32 | * including index and database |
| 33 | */ |
| 34 | class RepoStorage : noncopyable |
| 35 | { |
| 36 | public: |
| 37 | class Error : public std::runtime_error |
| 38 | { |
| 39 | public: |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 40 | using std::runtime_error::runtime_error; |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
Alexander Afanasyev | 5c16cc2 | 2019-04-02 14:17:12 -0400 | [diff] [blame] | 43 | explicit |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 44 | RepoStorage(Storage& store); |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 45 | |
| 46 | /** |
Alexander Afanasyev | 5c16cc2 | 2019-04-02 14:17:12 -0400 | [diff] [blame] | 47 | * @brief Notify about existing data |
| 48 | * |
| 49 | * Note, this cannot be in constructor, as have to be called after signal is connected |
| 50 | */ |
| 51 | void |
| 52 | notifyAboutExistingData(); |
| 53 | |
| 54 | /** |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 55 | * @brief insert data into repo |
| 56 | */ |
| 57 | bool |
| 58 | insertData(const Data& data); |
| 59 | |
| 60 | /** |
| 61 | * @brief delete data from repo |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 62 | * @param name from interest, use it as a prefix to find entry needed to be erased in repo |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 63 | * @return if deletion in either index or database fail, return -1, |
| 64 | * otherwise return the number of erased entries |
| 65 | */ |
| 66 | ssize_t |
| 67 | deleteData(const Name& name); |
| 68 | |
| 69 | /** |
| 70 | * @brief delete data from repo |
| 71 | * @param interest used to find entry needed to be erased in repo |
| 72 | * @return if deletion in either index or database fail, return -1, |
| 73 | * otherwise return the number of erased entries |
| 74 | */ |
| 75 | ssize_t |
| 76 | deleteData(const Interest& interest); |
| 77 | |
| 78 | /** |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 79 | * @brief read data from repo |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 80 | * @param interest used to request data |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 81 | * @return std::shared_ptr<Data> |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 82 | */ |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 83 | std::shared_ptr<Data> |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 84 | readData(const Interest& interest) const; |
| 85 | |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 86 | public: |
| 87 | ndn::util::Signal<RepoStorage, ndn::Name> afterDataInsertion; |
| 88 | ndn::util::Signal<RepoStorage, ndn::Name> afterDataDeletion; |
| 89 | |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 90 | private: |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 91 | Storage& m_storage; |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 92 | static constexpr int NOTFOUND = -1; |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | } // namespace repo |
| 96 | |
Davide Pesavento | e18d368 | 2019-01-24 22:10:30 -0500 | [diff] [blame] | 97 | #endif // REPO_STORAGE_REPO_STORAGE_HPP |