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 | /* |
| 3 | * Copyright (c) 2014-2018, 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 | |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 20 | #ifndef REPO_REPO_STORAGE_HPP |
| 21 | #define REPO_REPO_STORAGE_HPP |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 22 | |
| 23 | #include "../common.hpp" |
| 24 | #include "storage.hpp" |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 25 | #include "../repo-command-parameter.hpp" |
| 26 | |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 27 | #include <ndn-cxx/util/signal.hpp> |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 28 | |
| 29 | #include <queue> |
| 30 | |
| 31 | namespace repo { |
| 32 | |
| 33 | /** |
| 34 | * @brief RepoStorage handles the storage part of whole repo, |
| 35 | * including index and database |
| 36 | */ |
| 37 | class RepoStorage : noncopyable |
| 38 | { |
| 39 | public: |
| 40 | class Error : public std::runtime_error |
| 41 | { |
| 42 | public: |
| 43 | explicit |
| 44 | Error(const std::string& what) |
| 45 | : std::runtime_error(what) |
| 46 | { |
| 47 | } |
| 48 | }; |
| 49 | |
| 50 | public: |
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 | /** |
| 54 | * @brief insert data into repo |
| 55 | */ |
| 56 | bool |
| 57 | insertData(const Data& data); |
| 58 | |
| 59 | /** |
| 60 | * @brief delete data from repo |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame^] | 61 | * @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] | 62 | * @return if deletion in either index or database fail, return -1, |
| 63 | * otherwise return the number of erased entries |
| 64 | */ |
| 65 | ssize_t |
| 66 | deleteData(const Name& name); |
| 67 | |
| 68 | /** |
| 69 | * @brief delete data from repo |
| 70 | * @param interest used to find entry needed to be erased in repo |
| 71 | * @return if deletion in either index or database fail, return -1, |
| 72 | * otherwise return the number of erased entries |
| 73 | */ |
| 74 | ssize_t |
| 75 | deleteData(const Interest& interest); |
| 76 | |
| 77 | /** |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame^] | 78 | * @brief read data from repo |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 79 | * @param interest used to request data |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 80 | * @return std::shared_ptr<Data> |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 81 | */ |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 82 | std::shared_ptr<Data> |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 83 | readData(const Interest& interest) const; |
| 84 | |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 85 | public: |
| 86 | ndn::util::Signal<RepoStorage, ndn::Name> afterDataInsertion; |
| 87 | ndn::util::Signal<RepoStorage, ndn::Name> afterDataDeletion; |
| 88 | |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 89 | private: |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 90 | Storage& m_storage; |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame^] | 91 | const int NOTFOUND = -1; |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | } // namespace repo |
| 95 | |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 96 | #endif // REPO_REPO_STORAGE_HPP |