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