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, |
| 75 | const ndn::Name& prefix) = 0; |
| 76 | |
| 77 | protected: |
| 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 Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 89 | |
| 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 Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 98 | /** |
| 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 Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame^] | 115 | protected: |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 116 | // Face to communicate with |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame^] | 117 | const std::shared_ptr<ndn::Face> m_face; |
| 118 | // KeyChain used for data signing |
| 119 | const std::shared_ptr<ndn::KeyChain> m_keyChain; |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 120 | ndn::Name m_prefix; |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame^] | 121 | // Name for the signing key |
| 122 | ndn::Name m_signingId; |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 123 | }; // class CatalogAdapter |
| 124 | |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 125 | |
| 126 | } // namespace util |
| 127 | } // namespace atmos |
| 128 | |
| 129 | #endif //ATMOS_UTIL_CATALOG_ADAPTER_HPP |