blob: 04b101d0b7dce166f4d71ea924beda54b863e4e4 [file] [log] [blame]
/** NDN-Atmos: Cataloging Service for distributed data originally developed
* for atmospheric science data
* Copyright (C) 2015 Colorado State University
*
* NDN-Atmos is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NDN-Atmos is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NDN-Atmos. If not, see <http://www.gnu.org/licenses/>.
**/
#ifndef ATMOS_UTIL_CATALOG_ADAPTER_HPP
#define ATMOS_UTIL_CATALOG_ADAPTER_HPP
#include <ndn-cxx/data.hpp>
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/interest.hpp>
#include <ndn-cxx/name.hpp>
#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/encoding/block.hpp>
#include <memory>
#include <string>
#include <iostream>
#include "util/config-file.hpp"
namespace atmos {
namespace util {
/**
* Catalog Adapter acts as a common interface for Classes that need to register as Interest Filters
*
* Both QueryAdapter and PublisherAdapter use this as a template to allow consistancy between
* their designs and flow-control
*/
class CatalogAdapter {
public:
class Error : public std::runtime_error
{
public:
explicit
Error(const std::string& what)
: std::runtime_error(what)
{
}
};
/**
* Constructor
* @param face: Face that will be used for NDN communications
* @param keyChain: KeyChain that will be used for data signing
*/
CatalogAdapter(const std::shared_ptr<ndn::Face>& face,
const std::shared_ptr<ndn::KeyChain>& keyChain);
virtual
~CatalogAdapter();
/**
* Helper function that sets the configuration section handler
* @param config: ConfigFile object to set the handler
* @param prefix: Catalog prefix
* @param nameFields: string vector that contains filter category names
* @param databaseTable: table name in the database
*/
virtual void
setConfigFile(util::ConfigFile& config,
const ndn::Name& prefix,
const std::vector<std::string>& nameFields,
const std::string& databaseTable) = 0;
protected:
/**
* Callback function that handles the section parsing jobs
*/
virtual void
onConfig(const util::ConfigSection& section,
bool isDryDun,
const std::string& fileName,
const ndn::Name& prefix) = 0;
// @{ (onData and onTimeout) and/or onInterest should be overwritten at a minimum
/**
* Timeout from a Data request
*
* @param interest: Interest that failed to be satisfied (within the timelimit)
*/
virtual void
onTimeout(const ndn::Interest& interest);
/**
* Callback that should/can be used to evaluate that the Interest Filter has been correctly set up
*
* @param prefix: Name that will be routed to this class
*/
virtual void
onRegisterSuccess(const ndn::Name& prefix);
/**
* Callback that should/can be used to evaluate that the Interest Filter has been correctly set up
*
* @param prefix: Name that failed to route
* @param reason: String explanation as to why the failure occured
*/
virtual void
onRegisterFailure(const ndn::Name& prefix, const std::string& reason);
protected:
// Face to communicate with
const std::shared_ptr<ndn::Face> m_face;
// KeyChain used for data signing
const std::shared_ptr<ndn::KeyChain> m_keyChain;
ndn::Name m_prefix;
// Name for the signing key
ndn::Name m_signingId;
std::vector<std::string> m_nameFields;
std::string m_databaseTable;
}; // class CatalogAdapter
} // namespace util
} // namespace atmos
#endif //ATMOS_UTIL_CATALOG_ADAPTER_HPP