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 |
Chengyu Fan | eb0422c | 2015-03-04 16:34:14 -0700 | [diff] [blame] | 4 | * |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 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. |
Chengyu Fan | eb0422c | 2015-03-04 16:34:14 -0700 | [diff] [blame] | 9 | * |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 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. |
Chengyu Fan | eb0422c | 2015-03-04 16:34:14 -0700 | [diff] [blame] | 14 | * |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 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/>. |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 17 | **/ |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 18 | |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 19 | #include "config.hpp" |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 20 | #include "catalog/catalog.hpp" |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 21 | #include "query/query-adapter.hpp" |
| 22 | #include "publish/publish-adapter.hpp" |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 23 | |
| 24 | #include <memory> |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 25 | #include <getopt.h> |
| 26 | #include <ndn-cxx/face.hpp> |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 27 | #include <ChronoSync/socket.hpp> |
Chengyu Fan | eb0422c | 2015-03-04 16:34:14 -0700 | [diff] [blame] | 28 | |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 29 | #ifdef HAVE_LOG4CXX |
| 30 | INIT_LOGGER("atmos-catalog::Main"); |
| 31 | #endif |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 32 | |
| 33 | void |
| 34 | usage() |
Chengyu Fan | eb0422c | 2015-03-04 16:34:14 -0700 | [diff] [blame] | 35 | { |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 36 | std::cout << "\n Usage:\n atmos-catalog " |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 37 | "[-h] [-f config file] \n" |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 38 | " [-f config file] - set the configuration file\n" |
| 39 | " [-h] - print help and exit\n" |
| 40 | "\n"; |
| 41 | } |
| 42 | |
| 43 | int |
| 44 | main(int argc, char** argv) |
| 45 | { |
| 46 | int option; |
| 47 | std::string configFile(DEFAULT_CONFIG_FILE); |
| 48 | |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 49 | #ifdef HAVE_LOG4CXX |
| 50 | log4cxx::PropertyConfigurator::configure(LOG4CXX_CONFIG_FILE); |
| 51 | #endif |
| 52 | |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 53 | while ((option = getopt(argc, argv, "f:h")) != -1) { |
| 54 | switch (option) { |
| 55 | case 'f': |
| 56 | configFile.assign(optarg); |
| 57 | break; |
| 58 | case 'h': |
| 59 | default: |
| 60 | usage(); |
| 61 | return 0; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | argc -= optind; |
| 66 | argv += optind; |
| 67 | if (argc != 0) { |
| 68 | usage(); |
| 69 | return 1; |
| 70 | } |
| 71 | |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 72 | std::shared_ptr<ndn::Face> face(new ndn::Face()); |
| 73 | std::shared_ptr<ndn::KeyChain> keyChain(new ndn::KeyChain()); |
Chengyu Fan | 8b92f12 | 2015-03-09 22:13:36 -0600 | [diff] [blame] | 74 | |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 75 | // For now, share chronosync::Socket in both queryAdapter and publishAdapter |
| 76 | // to allow queryAdapter to get the digest. |
| 77 | // We may have to save digest in Database later |
| 78 | std::shared_ptr<chronosync::Socket> syncSocket; |
| 79 | |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 80 | std::unique_ptr<atmos::util::CatalogAdapter> |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame^] | 81 | queryAdapter(new atmos::query::QueryAdapter<ConnectionPool_T>(face, keyChain, syncSocket)); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 82 | std::unique_ptr<atmos::util::CatalogAdapter> |
Chengyu Fan | 31737f1 | 2016-01-12 21:08:50 -0700 | [diff] [blame^] | 83 | publishAdapter(new atmos::publish::PublishAdapter<ConnectionPool_T>(face, keyChain, syncSocket)); |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 84 | |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 85 | atmos::catalog::Catalog catalogInstance(face, keyChain, configFile); |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 86 | catalogInstance.addAdapter(publishAdapter); |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 87 | catalogInstance.addAdapter(queryAdapter); |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 88 | |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 89 | try { |
| 90 | catalogInstance.initialize(); |
| 91 | } |
| 92 | catch (std::exception& e) { |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 93 | _LOG_ERROR(e.what()); |
| 94 | return 1; |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | #ifndef NDEBUG |
| 98 | try { |
| 99 | #endif |
| 100 | face->processEvents(); |
| 101 | #ifndef NDEBUG |
| 102 | } |
| 103 | catch (std::exception& e) { |
Chengyu Fan | cfb80c7 | 2015-10-19 16:50:04 -0600 | [diff] [blame] | 104 | _LOG_ERROR(e.what()); |
| 105 | return 1; |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 106 | } |
| 107 | #endif |
Chengyu Fan | 8b92f12 | 2015-03-09 22:13:36 -0600 | [diff] [blame] | 108 | |
Chengyu Fan | eb0422c | 2015-03-04 16:34:14 -0700 | [diff] [blame] | 109 | return 0; |
| 110 | } |