blob: fe355ad45306fb9752a2466479b60e3d9956ae65 [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:
Alexander Afanasyev5c16cc22019-04-02 14:17:12 -040050 explicit
weijia yuan3aa8d2b2018-03-06 15:35:57 -080051 RepoStorage(Storage& store);
Weiqi Shif0330d52014-07-09 10:54:27 -070052
53 /**
Alexander Afanasyev5c16cc22019-04-02 14:17:12 -040054 * @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 Shif0330d52014-07-09 10:54:27 -070062 * @brief insert data into repo
63 */
64 bool
65 insertData(const Data& data);
66
67 /**
68 * @brief delete data from repo
weijia yuan3aa8d2b2018-03-06 15:35:57 -080069 * @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 -070070 * @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 yuan3aa8d2b2018-03-06 15:35:57 -080086 * @brief read data from repo
Weiqi Shif0330d52014-07-09 10:54:27 -070087 * @param interest used to request data
Wentao Shanga8f3c402014-10-30 14:03:27 -070088 * @return std::shared_ptr<Data>
Weiqi Shif0330d52014-07-09 10:54:27 -070089 */
Wentao Shanga8f3c402014-10-30 14:03:27 -070090 std::shared_ptr<Data>
Weiqi Shif0330d52014-07-09 10:54:27 -070091 readData(const Interest& interest) const;
92
Nick Gordon190e4dc2017-10-04 16:54:10 -050093public:
94 ndn::util::Signal<RepoStorage, ndn::Name> afterDataInsertion;
95 ndn::util::Signal<RepoStorage, ndn::Name> afterDataDeletion;
96
Weiqi Shif0330d52014-07-09 10:54:27 -070097private:
Weiqi Shif0330d52014-07-09 10:54:27 -070098 Storage& m_storage;
weijia yuan3aa8d2b2018-03-06 15:35:57 -080099 const int NOTFOUND = -1;
Weiqi Shif0330d52014-07-09 10:54:27 -0700100};
101
102} // namespace repo
103
Davide Pesaventoe18d3682019-01-24 22:10:30 -0500104#endif // REPO_STORAGE_REPO_STORAGE_HPP