blob: bc2ecbe30aab39b115a1609c302a6801b008910b [file] [log] [blame]
Weiqi Shif0330d52014-07-09 10:54:27 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, Regents of the University of California.
4 *
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
20#ifndef REPO_STORAGE_REPO_STORE_HPP
21#define REPO_STORAGE_REPO_STORE_HPP
22
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>
29
30#include <queue>
31
32namespace repo {
33
34/**
35 * @brief RepoStorage handles the storage part of whole repo,
36 * including index and database
37 */
38class RepoStorage : noncopyable
39{
40public:
41 class Error : public std::runtime_error
42 {
43 public:
44 explicit
45 Error(const std::string& what)
46 : std::runtime_error(what)
47 {
48 }
49 };
50
51public:
52 RepoStorage(const int64_t& nMaxPackets, Storage& store);
53
54 /**
55 * @brief rebuild index from database
56 */
57 void
58 initialize();
59
60 /**
61 * @brief insert data into repo
62 */
63 bool
64 insertData(const Data& data);
65
66 /**
67 * @brief delete data from repo
68 * @param name used to find entry needed to be erased in repo
69 * @return if deletion in either index or database fail, return -1,
70 * otherwise return the number of erased entries
71 */
72 ssize_t
73 deleteData(const Name& name);
74
75 /**
76 * @brief delete data from repo
77 * @param interest used to find entry needed to be erased in repo
78 * @return if deletion in either index or database fail, return -1,
79 * otherwise return the number of erased entries
80 */
81 ssize_t
82 deleteData(const Interest& interest);
83
84 /**
85 * @brief read data from repo
86 * @param interest used to request data
Wentao Shanga8f3c402014-10-30 14:03:27 -070087 * @return std::shared_ptr<Data>
Weiqi Shif0330d52014-07-09 10:54:27 -070088 */
Wentao Shanga8f3c402014-10-30 14:03:27 -070089 std::shared_ptr<Data>
Weiqi Shif0330d52014-07-09 10:54:27 -070090 readData(const Interest& interest) const;
91
92private:
93 Index m_index;
94 Storage& m_storage;
Weiqi Shif0330d52014-07-09 10:54:27 -070095};
96
97} // namespace repo
98
99#endif // REPO_REPO_STORE_HPP