blob: 767db6febd6b6ea1f7b429ea1fe44f61ce6b8269 [file] [log] [blame]
Shuo Chen7c6b4d72014-03-26 15:20:30 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Regents of the University of California.
4 * See COPYING for copyright and distribution information.
5 */
6
7#ifndef REPO_STORAGE_STORAGE_HANDLE_HPP
8#define REPO_STORAGE_STORAGE_HANDLE_HPP
9
10#include <string>
11#include <stdexcept>
12
13#include <ndn-cpp-dev/interest.hpp>
14#include <ndn-cpp-dev/name.hpp>
15#include <ndn-cpp-dev/data.hpp>
16#include <ndn-cpp-dev/selectors.hpp>
17#include <ndn-cpp-dev/key-locator.hpp>
18
19#include "storage-method.hpp"
20
21namespace repo {
22
23using ndn::Interest;
24using ndn::Name;
25using ndn::Data;
26using ndn::Selectors;
27using ndn::KeyLocator;
28using ndn::Block;
29using ndn::Exclude;
30
31using std::vector;
32using std::string;
33using boost::noncopyable;
34
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -070035/**
36 * @brief this class defines handles to read, insert and delete data packets in storage media
Shuo Chen7c6b4d72014-03-26 15:20:30 -070037 */
38
39class StorageHandle : 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
52 /**
53 * @brief Create a basic class object the specified storage type
54 */
55 explicit
56 StorageHandle(StorageMethod storageMethod);
57
58 virtual
59 ~StorageHandle();
60
61 /**
62 * @return storage method defined in storage-define.hpp
63 */
64 StorageMethod
65 getStorageMethod() const;
66
67 /**
68 * @brief insert data
69 * @return true on success, false otherwise
70 */
71 virtual bool
72 insertData(const Data& data) = 0;
73
74 /**
75 * @brief delete the data that exactly matches the name
76 * @return true on success, false otherwise
77 * @note It's considered successful if Data doesn't exist.
78 */
79 virtual bool
80 deleteData(const Name& name) = 0;
81
82 /**
83 * @brief find data according to the interest. This interest may contain selectors.
84 * @param[out] data Data matching Interest.
85 * @return true if Data is found, false otherwise
86 */
87 virtual bool
88 readData(const Interest& interest, Data& data) = 0;
89
90 /**
91 * @return if storage media has data packets with this name, return true, else return false
92 */
93 virtual bool
94 hasName(const Name& name) = 0;
95
96 /**
97 * @brief select any data conforms to the selector
98 * @param[out] names Data names matching @p name and @p selectors.
99 * @return true if at least one Data is found, false otherwise
100 */
101 virtual bool
102 readNameAny(const Name& name, const Selectors& selectors, vector<Name>& names) = 0;
103
Alexander Afanasyevb0c78ea2014-04-15 18:12:04 -0700104 /**
105 * @brief Get the number of Data packets stored
106 */
107 virtual size_t
108 size() = 0;
109
Shuo Chen7c6b4d72014-03-26 15:20:30 -0700110private:
111 StorageMethod m_storageMethod;
112};
113
114inline
115StorageHandle::StorageHandle(StorageMethod storageMethod)
116 : m_storageMethod(storageMethod)
117{
118}
119
120inline
121StorageHandle::~StorageHandle()
122{
123}
124
125inline StorageMethod
126StorageHandle::getStorageMethod() const
127{
128 return m_storageMethod;
129}
130
131} // namespace repo
132
133#endif // REPO_STORAGE_STORAGE_HANDLE_HPP