blob: 597daa81e6dc56687159a0450d4eb7e36e2e45fa [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 Pesaventob4966422023-08-10 21:15:32 -04003 * Copyright (c) 2014-2023, 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
Weiqi Shif0330d52014-07-09 10:54:27 -070028namespace repo {
29
30/**
31 * @brief RepoStorage handles the storage part of whole repo,
32 * including index and database
33 */
34class RepoStorage : noncopyable
35{
36public:
37 class Error : public std::runtime_error
38 {
39 public:
Davide Pesavento11904062022-04-14 22:33:28 -040040 using std::runtime_error::runtime_error;
Weiqi Shif0330d52014-07-09 10:54:27 -070041 };
42
Alexander Afanasyev5c16cc22019-04-02 14:17:12 -040043 explicit
weijia yuan3aa8d2b2018-03-06 15:35:57 -080044 RepoStorage(Storage& store);
Weiqi Shif0330d52014-07-09 10:54:27 -070045
46 /**
Alexander Afanasyev5c16cc22019-04-02 14:17:12 -040047 * @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 Shif0330d52014-07-09 10:54:27 -070055 * @brief insert data into repo
56 */
57 bool
58 insertData(const Data& data);
59
60 /**
61 * @brief delete data from repo
weijia yuan3aa8d2b2018-03-06 15:35:57 -080062 * @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 -070063 * @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 yuan3aa8d2b2018-03-06 15:35:57 -080079 * @brief read data from repo
Weiqi Shif0330d52014-07-09 10:54:27 -070080 * @param interest used to request data
Wentao Shanga8f3c402014-10-30 14:03:27 -070081 * @return std::shared_ptr<Data>
Weiqi Shif0330d52014-07-09 10:54:27 -070082 */
Wentao Shanga8f3c402014-10-30 14:03:27 -070083 std::shared_ptr<Data>
Weiqi Shif0330d52014-07-09 10:54:27 -070084 readData(const Interest& interest) const;
85
Nick Gordon190e4dc2017-10-04 16:54:10 -050086public:
Davide Pesaventob4966422023-08-10 21:15:32 -040087 ndn::signal::Signal<RepoStorage, ndn::Name> afterDataInsertion;
88 ndn::signal::Signal<RepoStorage, ndn::Name> afterDataDeletion;
Nick Gordon190e4dc2017-10-04 16:54:10 -050089
Weiqi Shif0330d52014-07-09 10:54:27 -070090private:
Weiqi Shif0330d52014-07-09 10:54:27 -070091 Storage& m_storage;
Davide Pesavento11904062022-04-14 22:33:28 -040092 static constexpr int NOTFOUND = -1;
Weiqi Shif0330d52014-07-09 10:54:27 -070093};
94
95} // namespace repo
96
Davide Pesaventoe18d3682019-01-24 22:10:30 -050097#endif // REPO_STORAGE_REPO_STORAGE_HPP