blob: 48359d4db504274edbe390cffa916fd01dcd3a57 [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (C) 2014 Regents of the University of California.
* See COPYING for copyright and distribution information.
*/
#ifndef REPO_STORAGE_STORAGE_HANDLE_HPP
#define REPO_STORAGE_STORAGE_HANDLE_HPP
#include <string>
#include <stdexcept>
#include <ndn-cpp-dev/interest.hpp>
#include <ndn-cpp-dev/name.hpp>
#include <ndn-cpp-dev/data.hpp>
#include <ndn-cpp-dev/selectors.hpp>
#include <ndn-cpp-dev/key-locator.hpp>
#include "storage-method.hpp"
namespace repo {
using ndn::Interest;
using ndn::Name;
using ndn::Data;
using ndn::Selectors;
using ndn::KeyLocator;
using ndn::Block;
using ndn::Exclude;
using std::vector;
using std::string;
using boost::noncopyable;
/**   
 * @brief this class defines handles to read, insert and delete data packets in storage media
*/
class StorageHandle : noncopyable
{
public:
class Error : public std::runtime_error
{
public:
explicit
Error(const std::string& what)
: std::runtime_error(what)
{
}
};
/**
* @brief Create a basic class object the specified storage type
*/
explicit
StorageHandle(StorageMethod storageMethod);
virtual
~StorageHandle();
/**
* @return storage method defined in storage-define.hpp
*/
StorageMethod
getStorageMethod() const;
/**
* @brief insert data
* @return true on success, false otherwise
*/
virtual bool
insertData(const Data& data) = 0;
/**
* @brief delete the data that exactly matches the name
* @return true on success, false otherwise
* @note It's considered successful if Data doesn't exist.
*/
virtual bool
deleteData(const Name& name) = 0;
/**
* @brief find data according to the interest. This interest may contain selectors.
* @param[out] data Data matching Interest.
* @return true if Data is found, false otherwise
*/
virtual bool
readData(const Interest& interest, Data& data) = 0;
/**
* @return if storage media has data packets with this name, return true, else return false
*/
virtual bool
hasName(const Name& name) = 0;
/**
* @brief select any data conforms to the selector
* @param[out] names Data names matching @p name and @p selectors.
* @return true if at least one Data is found, false otherwise
*/
virtual bool
readNameAny(const Name& name, const Selectors& selectors, vector<Name>& names) = 0;
private:
StorageMethod m_storageMethod;
};
inline
StorageHandle::StorageHandle(StorageMethod storageMethod)
: m_storageMethod(storageMethod)
{
}
inline
StorageHandle::~StorageHandle()
{
}
inline StorageMethod
StorageHandle::getStorageMethod() const
{
return m_storageMethod;
}
} // namespace repo
#endif // REPO_STORAGE_STORAGE_HANDLE_HPP