blob: b75de2cf60e0799e452321269e45e36b4a55effd [file] [log] [blame]
Shuo Chen7c6b4d72014-03-26 15:20:30 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyeve1e6f2a2014-04-25 11:28:12 -07003 * 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/>.
Shuo Chen7c6b4d72014-03-26 15:20:30 -070018 */
19
20#ifndef REPO_STORAGE_STORAGE_HANDLE_HPP
21#define REPO_STORAGE_STORAGE_HANDLE_HPP
22
Alexander Afanasyev39d98072014-05-04 12:46:29 -070023#include "common.hpp"
Shuo Chen7c6b4d72014-03-26 15:20:30 -070024#include "storage-method.hpp"
25
26namespace repo {
27
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070028/**
29 * @brief this class defines handles to read, insert and delete data packets in storage media
Shuo Chen7c6b4d72014-03-26 15:20:30 -070030 */
31
32class StorageHandle : noncopyable
33{
34public:
35 class Error : public std::runtime_error
36 {
37 public:
38 explicit
39 Error(const std::string& what)
40 : std::runtime_error(what)
41 {
42 }
43 };
44
45 /**
46 * @brief Create a basic class object the specified storage type
47 */
48 explicit
49 StorageHandle(StorageMethod storageMethod);
50
51 virtual
52 ~StorageHandle();
53
54 /**
55 * @return storage method defined in storage-define.hpp
56 */
57 StorageMethod
58 getStorageMethod() const;
59
60 /**
61 * @brief insert data
62 * @return true on success, false otherwise
63 */
64 virtual bool
65 insertData(const Data& data) = 0;
66
67 /**
68 * @brief delete the data that exactly matches the name
69 * @return true on success, false otherwise
70 * @note It's considered successful if Data doesn't exist.
71 */
72 virtual bool
73 deleteData(const Name& name) = 0;
74
75 /**
76 * @brief find data according to the interest. This interest may contain selectors.
77 * @param[out] data Data matching Interest.
78 * @return true if Data is found, false otherwise
79 */
80 virtual bool
81 readData(const Interest& interest, Data& data) = 0;
82
83 /**
84 * @return if storage media has data packets with this name, return true, else return false
85 */
86 virtual bool
87 hasName(const Name& name) = 0;
88
89 /**
90 * @brief select any data conforms to the selector
91 * @param[out] names Data names matching @p name and @p selectors.
92 * @return true if at least one Data is found, false otherwise
93 */
94 virtual bool
95 readNameAny(const Name& name, const Selectors& selectors, vector<Name>& names) = 0;
96
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070097 /**
98 * @brief Get the number of Data packets stored
99 */
100 virtual size_t
101 size() = 0;
102
Shuo Chen7c6b4d72014-03-26 15:20:30 -0700103private:
104 StorageMethod m_storageMethod;
105};
106
107inline
108StorageHandle::StorageHandle(StorageMethod storageMethod)
109 : m_storageMethod(storageMethod)
110{
111}
112
113inline
114StorageHandle::~StorageHandle()
115{
116}
117
118inline StorageMethod
119StorageHandle::getStorageMethod() const
120{
121 return m_storageMethod;
122}
123
124} // namespace repo
125
126#endif // REPO_STORAGE_STORAGE_HANDLE_HPP