blob: 48359d4db504274edbe390cffa916fd01dcd3a57 [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
35/**   
36 * @brief this class defines handles to read, insert and delete data packets in storage media
37 */
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
104private:
105 StorageMethod m_storageMethod;
106};
107
108inline
109StorageHandle::StorageHandle(StorageMethod storageMethod)
110 : m_storageMethod(storageMethod)
111{
112}
113
114inline
115StorageHandle::~StorageHandle()
116{
117}
118
119inline StorageMethod
120StorageHandle::getStorageMethod() const
121{
122 return m_storageMethod;
123}
124
125} // namespace repo
126
127#endif // REPO_STORAGE_STORAGE_HANDLE_HPP