blob: ec5faa73dabd2e3a867371384be42acc9db79daa [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"
25#include "index.hpp"
26#include "../repo-command-parameter.hpp"
27
28#include <ndn-cxx/exclude.hpp>
Nick Gordon190e4dc2017-10-04 16:54:10 -050029#include <ndn-cxx/util/signal.hpp>
Weiqi Shif0330d52014-07-09 10:54:27 -070030
31#include <queue>
32
33namespace repo {
34
35/**
36 * @brief RepoStorage handles the storage part of whole repo,
37 * including index and database
38 */
39class RepoStorage : noncopyable
40{
41public:
42 class Error : public std::runtime_error
43 {
44 public:
45 explicit
46 Error(const std::string& what)
47 : std::runtime_error(what)
48 {
49 }
50 };
51
52public:
53 RepoStorage(const int64_t& nMaxPackets, Storage& store);
54
55 /**
56 * @brief rebuild index from database
57 */
58 void
59 initialize();
60
61 /**
62 * @brief insert data into repo
63 */
64 bool
65 insertData(const Data& data);
66
67 /**
68 * @brief delete data from repo
69 * @param name 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 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 /**
86 * @brief read data from repo
87 * @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
Alexander Afanasyevbb058c02018-02-15 22:49:24 +000093private:
94 void
95 insertItemToIndex(const Storage::ItemMeta& item);
96
Nick Gordon190e4dc2017-10-04 16:54:10 -050097public:
98 ndn::util::Signal<RepoStorage, ndn::Name> afterDataInsertion;
99 ndn::util::Signal<RepoStorage, ndn::Name> afterDataDeletion;
100
Weiqi Shif0330d52014-07-09 10:54:27 -0700101private:
102 Index m_index;
103 Storage& m_storage;
Weiqi Shif0330d52014-07-09 10:54:27 -0700104};
105
106} // namespace repo
107
Nick Gordon190e4dc2017-10-04 16:54:10 -0500108#endif // REPO_REPO_STORAGE_HPP