blob: 863f29ae8b196e0efcec7daca12c473fcbf02de2 [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,
Chengyu Fan92440162015-07-09 14:43:31 -060075 const ndn::Name& prefix,
76 const std::vector<std::string>& nameFields) = 0;
Chengyu Fanb25835b2015-04-28 17:09:35 -060077
78protected:
79
80 /**
81 * Callback function that handles the section parsing jobs
82 */
83 virtual void
84 onConfig(const util::ConfigSection& section,
85 bool isDryDun,
86 const std::string& fileName,
87 const ndn::Name& prefix) = 0;
88
89 // @{ (onData and onTimeout) and/or onInterest should be overwritten at a minimum
Alison Craig2a4d5282015-04-10 12:00:02 -060090
91 /**
92 * Timeout from a Data request
93 *
94 * @param interest: Interest that failed to be satisfied (within the timelimit)
95 */
96 virtual void
97 onTimeout(const ndn::Interest& interest);
98
Alison Craig2a4d5282015-04-10 12:00:02 -060099 /**
100 * Callback that should/can be used to evaluate that the Interest Filter has been correctly set up
101 *
102 * @param prefix: Name that will be routed to this class
103 */
104 virtual void
105 onRegisterSuccess(const ndn::Name& prefix);
106
107 /**
108 * Callback that should/can be used to evaluate that the Interest Filter has been correctly set up
109 *
110 * @param prefix: Name that failed to route
111 * @param reason: String explanation as to why the failure occured
112 */
113 virtual void
114 onRegisterFailure(const ndn::Name& prefix, const std::string& reason);
115
Chengyu Fanb25835b2015-04-28 17:09:35 -0600116protected:
Alison Craig2a4d5282015-04-10 12:00:02 -0600117 // Face to communicate with
Chengyu Fanb25835b2015-04-28 17:09:35 -0600118 const std::shared_ptr<ndn::Face> m_face;
119 // KeyChain used for data signing
120 const std::shared_ptr<ndn::KeyChain> m_keyChain;
Alison Craig2a4d5282015-04-10 12:00:02 -0600121 ndn::Name m_prefix;
Chengyu Fanb25835b2015-04-28 17:09:35 -0600122 // Name for the signing key
123 ndn::Name m_signingId;
Chengyu Fan92440162015-07-09 14:43:31 -0600124 std::vector<std::string> m_nameFields;
Alison Craig2a4d5282015-04-10 12:00:02 -0600125}; // class CatalogAdapter
126
Alison Craig2a4d5282015-04-10 12:00:02 -0600127
128} // namespace util
129} // namespace atmos
130
131#endif //ATMOS_UTIL_CATALOG_ADAPTER_HPP