Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 1 | /** 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 Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 27 | #include <ndn-cxx/encoding/block.hpp> |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 28 | |
| 29 | #include <memory> |
| 30 | #include <string> |
| 31 | |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 32 | #include <iostream> |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 33 | #include "util/config-file.hpp" |
| 34 | |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 35 | |
| 36 | namespace atmos { |
| 37 | namespace 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 Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 45 | class CatalogAdapter { |
| 46 | public: |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 47 | 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 Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 56 | |
| 57 | /** |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 58 | * Constructor |
| 59 | * @param face: Face that will be used for NDN communications |
| 60 | * @param keyChain: KeyChain that will be used for data signing |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 61 | */ |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 62 | CatalogAdapter(const std::shared_ptr<ndn::Face>& face, |
| 63 | const std::shared_ptr<ndn::KeyChain>& keyChain); |
| 64 | |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 65 | virtual |
| 66 | ~CatalogAdapter(); |
| 67 | |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 68 | /** |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 69 | * Helper function that sets the configuration section handler |
| 70 | * @param config: ConfigFile object to set the handler |
| 71 | * @param prefix: Catalog prefix |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 72 | */ |
| 73 | virtual void |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 74 | setConfigFile(util::ConfigFile& config, |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame^] | 75 | const ndn::Name& prefix, |
| 76 | const std::vector<std::string>& nameFields) = 0; |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 77 | |
| 78 | protected: |
| 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 Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 90 | |
| 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 Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 99 | /** |
| 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 Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 116 | protected: |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 117 | // Face to communicate with |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 118 | const std::shared_ptr<ndn::Face> m_face; |
| 119 | // KeyChain used for data signing |
| 120 | const std::shared_ptr<ndn::KeyChain> m_keyChain; |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 121 | ndn::Name m_prefix; |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 122 | // Name for the signing key |
| 123 | ndn::Name m_signingId; |
Chengyu Fan | 9244016 | 2015-07-09 14:43:31 -0600 | [diff] [blame^] | 124 | std::vector<std::string> m_nameFields; |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 125 | }; // class CatalogAdapter |
| 126 | |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 127 | |
| 128 | } // namespace util |
| 129 | } // namespace atmos |
| 130 | |
| 131 | #endif //ATMOS_UTIL_CATALOG_ADAPTER_HPP |