blob: 7655315ceee41050baa9ea80c367e60cc48f8ee9 [file] [log] [blame]
Alison Craig2a4d5282015-04-10 12:00:02 -06001/** NDN-Atmos: Cataloging Service for distributed data originally developed
2 * for atmospheric science data
3 * Copyright (C) 2015 Colorado State University
Chengyu Faneb0422c2015-03-04 16:34:14 -07004 *
Alison Craig2a4d5282015-04-10 12:00:02 -06005 * 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 Faneb0422c2015-03-04 16:34:14 -07009 *
Alison Craig2a4d5282015-04-10 12:00:02 -060010 * 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 Faneb0422c2015-03-04 16:34:14 -070014 *
Alison Craig2a4d5282015-04-10 12:00:02 -060015 * 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 Fanb25835b2015-04-28 17:09:35 -060017 **/
Alison Craig2a4d5282015-04-10 12:00:02 -060018
Chengyu Fanb25835b2015-04-28 17:09:35 -060019#include "config.hpp"
Alison Craig2a4d5282015-04-10 12:00:02 -060020#include "catalog/catalog.hpp"
Chengyu Fanb25835b2015-04-28 17:09:35 -060021#include "query/query-adapter.hpp"
22#include "publish/publish-adapter.hpp"
Alison Craig2a4d5282015-04-10 12:00:02 -060023
24#include <memory>
Chengyu Fanb25835b2015-04-28 17:09:35 -060025#include <getopt.h>
26#include <ndn-cxx/face.hpp>
Chengyu Faneb0422c2015-03-04 16:34:14 -070027
Chengyu Fan71b712b2015-09-09 22:13:56 -060028#ifdef HAVE_LOG4CXX
29 INIT_LOGGER("atmos-catalog::Main");
30#endif
Chengyu Fanb25835b2015-04-28 17:09:35 -060031
32void
33usage()
Chengyu Faneb0422c2015-03-04 16:34:14 -070034{
Chengyu Fanb25835b2015-04-28 17:09:35 -060035 std::cout << "\n Usage:\n atmos-catalog "
Chengyu Fan71b712b2015-09-09 22:13:56 -060036 "[-h] [-f config file] \n"
Chengyu Fanb25835b2015-04-28 17:09:35 -060037 " [-f config file] - set the configuration file\n"
38 " [-h] - print help and exit\n"
39 "\n";
40}
41
42int
43main(int argc, char** argv)
44{
45 int option;
46 std::string configFile(DEFAULT_CONFIG_FILE);
47
Chengyu Fan71b712b2015-09-09 22:13:56 -060048#ifdef HAVE_LOG4CXX
49 log4cxx::PropertyConfigurator::configure(LOG4CXX_CONFIG_FILE);
50#endif
51
Chengyu Fanb25835b2015-04-28 17:09:35 -060052 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 Craig2a4d5282015-04-10 12:00:02 -060071 std::shared_ptr<ndn::Face> face(new ndn::Face());
72 std::shared_ptr<ndn::KeyChain> keyChain(new ndn::KeyChain());
Chengyu Fan8b92f122015-03-09 22:13:36 -060073
Chengyu Fanb25835b2015-04-28 17:09:35 -060074 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 Craig2a4d5282015-04-10 12:00:02 -060078
Chengyu Fanb25835b2015-04-28 17:09:35 -060079 atmos::catalog::Catalog catalogInstance(face, keyChain, configFile);
80 catalogInstance.addAdapter(queryAdapter);
81 catalogInstance.addAdapter(publishAdapter);
Alison Craig2a4d5282015-04-10 12:00:02 -060082
Chengyu Fan71b712b2015-09-09 22:13:56 -060083 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 Fan8b92f122015-03-09 22:13:36 -0600100
Chengyu Faneb0422c2015-03-04 16:34:14 -0700101 return 0;
102}