Shuo Chen | 7c6b4d7 | 2014-03-26 15:20:30 -0700 | [diff] [blame] | 1 | /* -*- 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 | |
| 21 | namespace repo { |
| 22 | |
| 23 | using ndn::Interest; |
| 24 | using ndn::Name; |
| 25 | using ndn::Data; |
| 26 | using ndn::Selectors; |
| 27 | using ndn::KeyLocator; |
| 28 | using ndn::Block; |
| 29 | using ndn::Exclude; |
| 30 | |
| 31 | using std::vector; |
| 32 | using std::string; |
| 33 | using boost::noncopyable; |
| 34 | |
Alexander Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame^] | 35 | /** |
| 36 | * @brief this class defines handles to read, insert and delete data packets in storage media |
Shuo Chen | 7c6b4d7 | 2014-03-26 15:20:30 -0700 | [diff] [blame] | 37 | */ |
| 38 | |
| 39 | class StorageHandle : noncopyable |
| 40 | { |
| 41 | public: |
| 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 Afanasyev | b0c78ea | 2014-04-15 18:12:04 -0700 | [diff] [blame^] | 104 | /** |
| 105 | * @brief Get the number of Data packets stored |
| 106 | */ |
| 107 | virtual size_t |
| 108 | size() = 0; |
| 109 | |
Shuo Chen | 7c6b4d7 | 2014-03-26 15:20:30 -0700 | [diff] [blame] | 110 | private: |
| 111 | StorageMethod m_storageMethod; |
| 112 | }; |
| 113 | |
| 114 | inline |
| 115 | StorageHandle::StorageHandle(StorageMethod storageMethod) |
| 116 | : m_storageMethod(storageMethod) |
| 117 | { |
| 118 | } |
| 119 | |
| 120 | inline |
| 121 | StorageHandle::~StorageHandle() |
| 122 | { |
| 123 | } |
| 124 | |
| 125 | inline StorageMethod |
| 126 | StorageHandle::getStorageMethod() const |
| 127 | { |
| 128 | return m_storageMethod; |
| 129 | } |
| 130 | |
| 131 | } // namespace repo |
| 132 | |
| 133 | #endif // REPO_STORAGE_STORAGE_HANDLE_HPP |