blob: 5934b12d2e4aaaaeb465c9f9abf62fec373b868f [file] [log] [blame]
Weiqi Shif0330d52014-07-09 10:54:27 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyevbb058c02018-02-15 22:49:24 +00002/*
Davide Pesaventoe18d3682019-01-24 22:10:30 -05003 * Copyright (c) 2014-2019, Regents of the University of California.
Weiqi Shif0330d52014-07-09 10:54:27 -07004 *
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 Pesaventoe18d3682019-01-24 22:10:30 -050020#ifndef REPO_STORAGE_REPO_STORAGE_HPP
21#define REPO_STORAGE_REPO_STORAGE_HPP
Weiqi Shif0330d52014-07-09 10:54:27 -070022
Weiqi Shif0330d52014-07-09 10:54:27 -070023#include "storage.hpp"
Weiqi Shif0330d52014-07-09 10:54:27 -070024#include "../repo-command-parameter.hpp"
25
Nick Gordon190e4dc2017-10-04 16:54:10 -050026#include <ndn-cxx/util/signal.hpp>
Weiqi Shif0330d52014-07-09 10:54:27 -070027
28#include <queue>
29
30namespace repo {
31
32/**
33 * @brief RepoStorage handles the storage part of whole repo,
34 * including index and database
35 */
36class RepoStorage : noncopyable
37{
38public:
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
49public:
weijia yuan3aa8d2b2018-03-06 15:35:57 -080050 RepoStorage(Storage& store);
Weiqi Shif0330d52014-07-09 10:54:27 -070051
52 /**
53 * @brief insert data into repo
54 */
55 bool
56 insertData(const Data& data);
57
58 /**
59 * @brief delete data from repo
weijia yuan3aa8d2b2018-03-06 15:35:57 -080060 * @param name from interest, use it as a prefix to find entry needed to be erased in repo
Weiqi Shif0330d52014-07-09 10:54:27 -070061 * @return if deletion in either index or database fail, return -1,
62 * otherwise return the number of erased entries
63 */
64 ssize_t
65 deleteData(const Name& name);
66
67 /**
68 * @brief delete data from repo
69 * @param interest used to find entry needed to be erased in repo
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 Interest& interest);
75
76 /**
weijia yuan3aa8d2b2018-03-06 15:35:57 -080077 * @brief read data from repo
Weiqi Shif0330d52014-07-09 10:54:27 -070078 * @param interest used to request data
Wentao Shanga8f3c402014-10-30 14:03:27 -070079 * @return std::shared_ptr<Data>
Weiqi Shif0330d52014-07-09 10:54:27 -070080 */
Wentao Shanga8f3c402014-10-30 14:03:27 -070081 std::shared_ptr<Data>
Weiqi Shif0330d52014-07-09 10:54:27 -070082 readData(const Interest& interest) const;
83
Nick Gordon190e4dc2017-10-04 16:54:10 -050084public:
85 ndn::util::Signal<RepoStorage, ndn::Name> afterDataInsertion;
86 ndn::util::Signal<RepoStorage, ndn::Name> afterDataDeletion;
87
Weiqi Shif0330d52014-07-09 10:54:27 -070088private:
Weiqi Shif0330d52014-07-09 10:54:27 -070089 Storage& m_storage;
weijia yuan3aa8d2b2018-03-06 15:35:57 -080090 const int NOTFOUND = -1;
Weiqi Shif0330d52014-07-09 10:54:27 -070091};
92
93} // namespace repo
94
Davide Pesaventoe18d3682019-01-24 22:10:30 -050095#endif // REPO_STORAGE_REPO_STORAGE_HPP