blob: 04b101d0b7dce166f4d71ea924beda54b863e4e4 [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
Chengyu Fancfb80c72015-10-19 16:50:04 -060059 * @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
Chengyu Fanf4c747a2015-08-18 13:56:01 -060072 * @param nameFields: string vector that contains filter category names
73 * @param databaseTable: table name in the database
Alison Craig2a4d5282015-04-10 12:00:02 -060074 */
75 virtual void
Chengyu Fanb25835b2015-04-28 17:09:35 -060076 setConfigFile(util::ConfigFile& config,
Chengyu Fan92440162015-07-09 14:43:31 -060077 const ndn::Name& prefix,
Chengyu Fanf4c747a2015-08-18 13:56:01 -060078 const std::vector<std::string>& nameFields,
79 const std::string& databaseTable) = 0;
Chengyu Fanb25835b2015-04-28 17:09:35 -060080
81protected:
82
83 /**
84 * Callback function that handles the section parsing jobs
85 */
86 virtual void
87 onConfig(const util::ConfigSection& section,
88 bool isDryDun,
89 const std::string& fileName,
90 const ndn::Name& prefix) = 0;
91
92 // @{ (onData and onTimeout) and/or onInterest should be overwritten at a minimum
Alison Craig2a4d5282015-04-10 12:00:02 -060093
94 /**
95 * Timeout from a Data request
96 *
97 * @param interest: Interest that failed to be satisfied (within the timelimit)
98 */
99 virtual void
100 onTimeout(const ndn::Interest& interest);
101
Alison Craig2a4d5282015-04-10 12:00:02 -0600102 /**
103 * Callback that should/can be used to evaluate that the Interest Filter has been correctly set up
104 *
105 * @param prefix: Name that will be routed to this class
106 */
107 virtual void
108 onRegisterSuccess(const ndn::Name& prefix);
109
110 /**
111 * Callback that should/can be used to evaluate that the Interest Filter has been correctly set up
112 *
113 * @param prefix: Name that failed to route
114 * @param reason: String explanation as to why the failure occured
115 */
116 virtual void
117 onRegisterFailure(const ndn::Name& prefix, const std::string& reason);
118
Chengyu Fanb25835b2015-04-28 17:09:35 -0600119protected:
Alison Craig2a4d5282015-04-10 12:00:02 -0600120 // Face to communicate with
Chengyu Fanb25835b2015-04-28 17:09:35 -0600121 const std::shared_ptr<ndn::Face> m_face;
122 // KeyChain used for data signing
123 const std::shared_ptr<ndn::KeyChain> m_keyChain;
Alison Craig2a4d5282015-04-10 12:00:02 -0600124 ndn::Name m_prefix;
Chengyu Fanb25835b2015-04-28 17:09:35 -0600125 // Name for the signing key
126 ndn::Name m_signingId;
Chengyu Fan92440162015-07-09 14:43:31 -0600127 std::vector<std::string> m_nameFields;
Chengyu Fanf4c747a2015-08-18 13:56:01 -0600128 std::string m_databaseTable;
Alison Craig2a4d5282015-04-10 12:00:02 -0600129}; // class CatalogAdapter
130
Alison Craig2a4d5282015-04-10 12:00:02 -0600131
132} // namespace util
133} // namespace atmos
134
135#endif //ATMOS_UTIL_CATALOG_ADAPTER_HPP