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 | eb0422c | 2015-03-04 16:34:14 -0700 | [diff] [blame] | 27 | |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 28 | #ifdef HAVE_LOG4CXX |
| 29 | INIT_LOGGER("atmos-catalog::Main"); |
| 30 | #endif |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 31 | |
| 32 | void |
| 33 | usage() |
Chengyu Fan | eb0422c | 2015-03-04 16:34:14 -0700 | [diff] [blame] | 34 | { |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 35 | std::cout << "\n Usage:\n atmos-catalog " |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 36 | "[-h] [-f config file] \n" |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 37 | " [-f config file] - set the configuration file\n" |
| 38 | " [-h] - print help and exit\n" |
| 39 | "\n"; |
| 40 | } |
| 41 | |
| 42 | int |
| 43 | main(int argc, char** argv) |
| 44 | { |
| 45 | int option; |
| 46 | std::string configFile(DEFAULT_CONFIG_FILE); |
| 47 | |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 48 | #ifdef HAVE_LOG4CXX |
| 49 | log4cxx::PropertyConfigurator::configure(LOG4CXX_CONFIG_FILE); |
| 50 | #endif |
| 51 | |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 52 | while ((option = getopt(argc, argv, "f:h")) != -1) { |
| 53 | switch (option) { |
| 54 | case 'f': |
| 55 | configFile.assign(optarg); |
| 56 | break; |
| 57 | case 'h': |
| 58 | default: |
| 59 | usage(); |
| 60 | return 0; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | argc -= optind; |
| 65 | argv += optind; |
| 66 | if (argc != 0) { |
| 67 | usage(); |
| 68 | return 1; |
| 69 | } |
| 70 | |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 71 | std::shared_ptr<ndn::Face> face(new ndn::Face()); |
| 72 | std::shared_ptr<ndn::KeyChain> keyChain(new ndn::KeyChain()); |
Chengyu Fan | 8b92f12 | 2015-03-09 22:13:36 -0600 | [diff] [blame] | 73 | |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 74 | std::unique_ptr<atmos::util::CatalogAdapter> |
| 75 | queryAdapter(new atmos::query::QueryAdapter<MYSQL>(face, keyChain)); |
| 76 | std::unique_ptr<atmos::util::CatalogAdapter> |
| 77 | publishAdapter(new atmos::publish::PublishAdapter<MYSQL>(face, keyChain)); |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 78 | |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 79 | atmos::catalog::Catalog catalogInstance(face, keyChain, configFile); |
| 80 | catalogInstance.addAdapter(queryAdapter); |
| 81 | catalogInstance.addAdapter(publishAdapter); |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 82 | |
Chengyu Fan | 71b712b | 2015-09-09 22:13:56 -0600 | [diff] [blame] | 83 | try { |
| 84 | catalogInstance.initialize(); |
| 85 | } |
| 86 | catch (std::exception& e) { |
| 87 | std::cout << e.what() << std::endl; |
| 88 | } |
| 89 | |
| 90 | #ifndef NDEBUG |
| 91 | try { |
| 92 | #endif |
| 93 | face->processEvents(); |
| 94 | #ifndef NDEBUG |
| 95 | } |
| 96 | catch (std::exception& e) { |
| 97 | _LOG_DEBUG(e.what()); |
| 98 | } |
| 99 | #endif |
Chengyu Fan | 8b92f12 | 2015-03-09 22:13:36 -0600 | [diff] [blame] | 100 | |
Chengyu Fan | eb0422c | 2015-03-04 16:34:14 -0700 | [diff] [blame] | 101 | return 0; |
| 102 | } |