blob: 2b033589026b7b9481467125e7ad7adbd88febe0 [file] [log] [blame]
Alison Craig2a4d5282015-04-10 12:00:02 -06001/** NDN-Atmos: Cataloging Service for distributed data originally developed
2 * for atmospheric science data
3 * Copyright (C) 2015 Colorado State University
4 *
5 * NDN-Atmos is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * NDN-Atmos is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NDN-Atmos. If not, see <http://www.gnu.org/licenses/>.
17**/
18
19#ifndef ATMOS_UTIL_CATALOG_ADAPTER_HPP
20#define ATMOS_UTIL_CATALOG_ADAPTER_HPP
21
22#include <ndn-cxx/data.hpp>
23#include <ndn-cxx/face.hpp>
24#include <ndn-cxx/interest.hpp>
25#include <ndn-cxx/name.hpp>
26#include <ndn-cxx/security/key-chain.hpp>
Chengyu Fanb25835b2015-04-28 17:09:35 -060027#include <ndn-cxx/encoding/block.hpp>
Alison Craig2a4d5282015-04-10 12:00:02 -060028
29#include <memory>
30#include <string>
31
Alison Craig2a4d5282015-04-10 12:00:02 -060032#include <iostream>
Chengyu Fanb25835b2015-04-28 17:09:35 -060033#include "util/config-file.hpp"
34
Alison Craig2a4d5282015-04-10 12:00:02 -060035
36namespace atmos {
37namespace util {
38
39/**
40 * Catalog Adapter acts as a common interface for Classes that need to register as Interest Filters
41 *
42 * Both QueryAdapter and PublisherAdapter use this as a template to allow consistancy between
43 * their designs and flow-control
44 */
Alison Craig2a4d5282015-04-10 12:00:02 -060045class CatalogAdapter {
46public:
Chengyu Fanb25835b2015-04-28 17:09:35 -060047 class Error : public std::runtime_error
48 {
49 public:
50 explicit
51 Error(const std::string& what)
52 : std::runtime_error(what)
53 {
54 }
55 };
Alison Craig2a4d5282015-04-10 12:00:02 -060056
57 /**
Chengyu Fanb25835b2015-04-28 17:09:35 -060058 * Constructor
59 * @param face: Face that will be used for NDN communications
60 * @param keyChain: KeyChain that will be used for data signing
Alison Craig2a4d5282015-04-10 12:00:02 -060061 */
Chengyu Fanb25835b2015-04-28 17:09:35 -060062 CatalogAdapter(const std::shared_ptr<ndn::Face>& face,
63 const std::shared_ptr<ndn::KeyChain>& keyChain);
64
Alison Craig2a4d5282015-04-10 12:00:02 -060065 virtual
66 ~CatalogAdapter();
67
Alison Craig2a4d5282015-04-10 12:00:02 -060068 /**
Chengyu Fanb25835b2015-04-28 17:09:35 -060069 * Helper function that sets the configuration section handler
70 * @param config: ConfigFile object to set the handler
71 * @param prefix: Catalog prefix
Alison Craig2a4d5282015-04-10 12:00:02 -060072 */
73 virtual void
Chengyu Fanb25835b2015-04-28 17:09:35 -060074 setConfigFile(util::ConfigFile& config,
75 const ndn::Name& prefix) = 0;
76
77protected:
78
79 /**
80 * Callback function that handles the section parsing jobs
81 */
82 virtual void
83 onConfig(const util::ConfigSection& section,
84 bool isDryDun,
85 const std::string& fileName,
86 const ndn::Name& prefix) = 0;
87
88 // @{ (onData and onTimeout) and/or onInterest should be overwritten at a minimum
Alison Craig2a4d5282015-04-10 12:00:02 -060089
90 /**
91 * Timeout from a Data request
92 *
93 * @param interest: Interest that failed to be satisfied (within the timelimit)
94 */
95 virtual void
96 onTimeout(const ndn::Interest& interest);
97
Alison Craig2a4d5282015-04-10 12:00:02 -060098 /**
99 * Callback that should/can be used to evaluate that the Interest Filter has been correctly set up
100 *
101 * @param prefix: Name that will be routed to this class
102 */
103 virtual void
104 onRegisterSuccess(const ndn::Name& prefix);
105
106 /**
107 * Callback that should/can be used to evaluate that the Interest Filter has been correctly set up
108 *
109 * @param prefix: Name that failed to route
110 * @param reason: String explanation as to why the failure occured
111 */
112 virtual void
113 onRegisterFailure(const ndn::Name& prefix, const std::string& reason);
114
Chengyu Fanb25835b2015-04-28 17:09:35 -0600115protected:
Alison Craig2a4d5282015-04-10 12:00:02 -0600116 // Face to communicate with
Chengyu Fanb25835b2015-04-28 17:09:35 -0600117 const std::shared_ptr<ndn::Face> m_face;
118 // KeyChain used for data signing
119 const std::shared_ptr<ndn::KeyChain> m_keyChain;
Alison Craig2a4d5282015-04-10 12:00:02 -0600120 ndn::Name m_prefix;
Chengyu Fanb25835b2015-04-28 17:09:35 -0600121 // Name for the signing key
122 ndn::Name m_signingId;
Alison Craig2a4d5282015-04-10 12:00:02 -0600123}; // class CatalogAdapter
124
Alison Craig2a4d5282015-04-10 12:00:02 -0600125
126} // namespace util
127} // namespace atmos
128
129#endif //ATMOS_UTIL_CATALOG_ADAPTER_HPP