blob: 39e576d4c600f2f19129cc2393fcb4746e47e83f [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/*
3 * Copyright (c) 2014-2018, 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
Nick Gordon190e4dc2017-10-04 16:54:10 -050020#ifndef REPO_REPO_STORAGE_HPP
21#define REPO_REPO_STORAGE_HPP
Weiqi Shif0330d52014-07-09 10:54:27 -070022
23#include "../common.hpp"
24#include "storage.hpp"
Weiqi Shif0330d52014-07-09 10:54:27 -070025#include "../repo-command-parameter.hpp"
26
Nick Gordon190e4dc2017-10-04 16:54:10 -050027#include <ndn-cxx/util/signal.hpp>
Weiqi Shif0330d52014-07-09 10:54:27 -070028
29#include <queue>
30
31namespace repo {
32
33/**
34 * @brief RepoStorage handles the storage part of whole repo,
35 * including index and database
36 */
37class RepoStorage : noncopyable
38{
39public:
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
50public:
weijia yuan3aa8d2b2018-03-06 15:35:57 -080051 RepoStorage(Storage& store);
Weiqi Shif0330d52014-07-09 10:54:27 -070052
53 /**
54 * @brief insert data into repo
55 */
56 bool
57 insertData(const Data& data);
58
59 /**
60 * @brief delete data from repo
weijia yuan3aa8d2b2018-03-06 15:35:57 -080061 * @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 -070062 * @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 yuan3aa8d2b2018-03-06 15:35:57 -080078 * @brief read data from repo
Weiqi Shif0330d52014-07-09 10:54:27 -070079 * @param interest used to request data
Wentao Shanga8f3c402014-10-30 14:03:27 -070080 * @return std::shared_ptr<Data>
Weiqi Shif0330d52014-07-09 10:54:27 -070081 */
Wentao Shanga8f3c402014-10-30 14:03:27 -070082 std::shared_ptr<Data>
Weiqi Shif0330d52014-07-09 10:54:27 -070083 readData(const Interest& interest) const;
84
Nick Gordon190e4dc2017-10-04 16:54:10 -050085public:
86 ndn::util::Signal<RepoStorage, ndn::Name> afterDataInsertion;
87 ndn::util::Signal<RepoStorage, ndn::Name> afterDataDeletion;
88
Weiqi Shif0330d52014-07-09 10:54:27 -070089private:
Weiqi Shif0330d52014-07-09 10:54:27 -070090 Storage& m_storage;
weijia yuan3aa8d2b2018-03-06 15:35:57 -080091 const int NOTFOUND = -1;
Weiqi Shif0330d52014-07-09 10:54:27 -070092};
93
94} // namespace repo
95
Nick Gordon190e4dc2017-10-04 16:54:10 -050096#endif // REPO_REPO_STORAGE_HPP