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 | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 28 | |
| 29 | void |
| 30 | usage() |
Chengyu Fan | eb0422c | 2015-03-04 16:34:14 -0700 | [diff] [blame] | 31 | { |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 32 | std::cout << "\n Usage:\n atmos-catalog " |
| 33 | "[-h] [-f config file] " |
| 34 | " [-f config file] - set the configuration file\n" |
| 35 | " [-h] - print help and exit\n" |
| 36 | "\n"; |
| 37 | } |
| 38 | |
| 39 | int |
| 40 | main(int argc, char** argv) |
| 41 | { |
| 42 | int option; |
| 43 | std::string configFile(DEFAULT_CONFIG_FILE); |
| 44 | |
| 45 | while ((option = getopt(argc, argv, "f:h")) != -1) { |
| 46 | switch (option) { |
| 47 | case 'f': |
| 48 | configFile.assign(optarg); |
| 49 | break; |
| 50 | case 'h': |
| 51 | default: |
| 52 | usage(); |
| 53 | return 0; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | argc -= optind; |
| 58 | argv += optind; |
| 59 | if (argc != 0) { |
| 60 | usage(); |
| 61 | return 1; |
| 62 | } |
| 63 | |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 64 | std::shared_ptr<ndn::Face> face(new ndn::Face()); |
| 65 | std::shared_ptr<ndn::KeyChain> keyChain(new ndn::KeyChain()); |
Chengyu Fan | 8b92f12 | 2015-03-09 22:13:36 -0600 | [diff] [blame] | 66 | |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 67 | std::unique_ptr<atmos::util::CatalogAdapter> |
| 68 | queryAdapter(new atmos::query::QueryAdapter<MYSQL>(face, keyChain)); |
| 69 | std::unique_ptr<atmos::util::CatalogAdapter> |
| 70 | publishAdapter(new atmos::publish::PublishAdapter<MYSQL>(face, keyChain)); |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 71 | |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 72 | atmos::catalog::Catalog catalogInstance(face, keyChain, configFile); |
| 73 | catalogInstance.addAdapter(queryAdapter); |
| 74 | catalogInstance.addAdapter(publishAdapter); |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 75 | |
Chengyu Fan | b25835b | 2015-04-28 17:09:35 -0600 | [diff] [blame] | 76 | catalogInstance.initialize(); |
Alison Craig | 2a4d528 | 2015-04-10 12:00:02 -0600 | [diff] [blame] | 77 | face->processEvents(); |
Chengyu Fan | 8b92f12 | 2015-03-09 22:13:36 -0600 | [diff] [blame] | 78 | |
Chengyu Fan | eb0422c | 2015-03-04 16:34:14 -0700 | [diff] [blame] | 79 | return 0; |
| 80 | } |