Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | f43a03e | 2018-02-21 22:04:21 -0500 | [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 | |
| 20 | #ifndef REPO_STORAGE_STORAGE_HPP |
| 21 | #define REPO_STORAGE_STORAGE_HPP |
Davide Pesavento | f43a03e | 2018-02-21 22:04:21 -0500 | [diff] [blame] | 22 | |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 23 | #include "../common.hpp" |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame^] | 24 | #include <string> |
| 25 | #include <iostream> |
| 26 | #include <stdlib.h> |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 27 | |
| 28 | namespace repo { |
| 29 | |
| 30 | /** |
| 31 | * @brief Storage is a virtual abstract class which will be called by SqliteStorage |
| 32 | */ |
| 33 | class Storage : noncopyable |
| 34 | { |
| 35 | public: |
| 36 | class Error : public std::runtime_error |
| 37 | { |
| 38 | public: |
| 39 | explicit |
| 40 | Error(const std::string& what) |
| 41 | : std::runtime_error(what) |
| 42 | { |
| 43 | } |
| 44 | }; |
| 45 | |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 46 | class ItemMeta |
| 47 | { |
| 48 | public: |
| 49 | int64_t id; |
| 50 | Name fullName; |
| 51 | ndn::ConstBufferPtr keyLocatorHash; |
| 52 | }; |
| 53 | |
Davide Pesavento | f43a03e | 2018-02-21 22:04:21 -0500 | [diff] [blame] | 54 | public: |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 55 | virtual |
Davide Pesavento | f43a03e | 2018-02-21 22:04:21 -0500 | [diff] [blame] | 56 | ~Storage() = default; |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * @brief put the data into database |
| 60 | * @param data the data should be inserted into databse |
| 61 | */ |
| 62 | virtual int64_t |
| 63 | insert(const Data& data) = 0; |
| 64 | |
| 65 | /** |
| 66 | * @brief remove the entry in the database by using id |
| 67 | * @param id id number of entry in the database |
| 68 | */ |
| 69 | virtual bool |
| 70 | erase(const int64_t id) = 0; |
| 71 | |
| 72 | /** |
| 73 | * @brief get the data from database |
| 74 | * @param id id number of each entry in the database, used to find the data |
| 75 | */ |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 76 | virtual std::shared_ptr<Data> |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 77 | read(const int64_t id) = 0; |
| 78 | |
| 79 | /** |
| 80 | * @brief return the size of database |
| 81 | */ |
| 82 | virtual int64_t |
| 83 | size() = 0; |
| 84 | |
| 85 | /** |
| 86 | * @brief enumerate each entry in database and call the function |
| 87 | * insertItemToIndex to reubuild index from database |
| 88 | */ |
| 89 | virtual void |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 90 | fullEnumerate(const std::function<void(const Storage::ItemMeta)>& f) = 0; |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | } // namespace repo |
| 94 | |
Davide Pesavento | f43a03e | 2018-02-21 22:04:21 -0500 | [diff] [blame] | 95 | #endif // REPO_STORAGE_STORAGE_HPP |