blob: 5525f24f582e5bd649a282948e4da36d7439f829 [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 Fancfb80c72015-10-19 16:50:04 -060027#include <ChronoSync/socket.hpp>
Chengyu Faneb0422c2015-03-04 16:34:14 -070028
Chengyu Fan71b712b2015-09-09 22:13:56 -060029#ifdef HAVE_LOG4CXX
30 INIT_LOGGER("atmos-catalog::Main");
31#endif
Chengyu Fanb25835b2015-04-28 17:09:35 -060032
33void
34usage()
Chengyu Faneb0422c2015-03-04 16:34:14 -070035{
Chengyu Fanb25835b2015-04-28 17:09:35 -060036 std::cout << "\n Usage:\n atmos-catalog "
Chengyu Fan71b712b2015-09-09 22:13:56 -060037 "[-h] [-f config file] \n"
Chengyu Fanb25835b2015-04-28 17:09:35 -060038 " [-f config file] - set the configuration file\n"
39 " [-h] - print help and exit\n"
40 "\n";
41}
42
43int
44main(int argc, char** argv)
45{
46 int option;
47 std::string configFile(DEFAULT_CONFIG_FILE);
48
Chengyu Fan71b712b2015-09-09 22:13:56 -060049#ifdef HAVE_LOG4CXX
50 log4cxx::PropertyConfigurator::configure(LOG4CXX_CONFIG_FILE);
51#endif
52
Chengyu Fanb25835b2015-04-28 17:09:35 -060053 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 Craig2a4d5282015-04-10 12:00:02 -060072 std::shared_ptr<ndn::Face> face(new ndn::Face());
73 std::shared_ptr<ndn::KeyChain> keyChain(new ndn::KeyChain());
Chengyu Fan8b92f122015-03-09 22:13:36 -060074
Chengyu Fancfb80c72015-10-19 16:50:04 -060075 // 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 Fanb25835b2015-04-28 17:09:35 -060080 std::unique_ptr<atmos::util::CatalogAdapter>
Chengyu Fan31737f12016-01-12 21:08:50 -070081 queryAdapter(new atmos::query::QueryAdapter<ConnectionPool_T>(face, keyChain, syncSocket));
Chengyu Fanb25835b2015-04-28 17:09:35 -060082 std::unique_ptr<atmos::util::CatalogAdapter>
Chengyu Fan31737f12016-01-12 21:08:50 -070083 publishAdapter(new atmos::publish::PublishAdapter<ConnectionPool_T>(face, keyChain, syncSocket));
Alison Craig2a4d5282015-04-10 12:00:02 -060084
Chengyu Fanb25835b2015-04-28 17:09:35 -060085 atmos::catalog::Catalog catalogInstance(face, keyChain, configFile);
Chengyu Fanb25835b2015-04-28 17:09:35 -060086 catalogInstance.addAdapter(publishAdapter);
Chengyu Fancfb80c72015-10-19 16:50:04 -060087 catalogInstance.addAdapter(queryAdapter);
Alison Craig2a4d5282015-04-10 12:00:02 -060088
Chengyu Fan71b712b2015-09-09 22:13:56 -060089 try {
90 catalogInstance.initialize();
91 }
92 catch (std::exception& e) {
Chengyu Fancfb80c72015-10-19 16:50:04 -060093 _LOG_ERROR(e.what());
94 return 1;
Chengyu Fan71b712b2015-09-09 22:13:56 -060095 }
96
97#ifndef NDEBUG
98 try {
99#endif
100 face->processEvents();
101#ifndef NDEBUG
102 }
103 catch (std::exception& e) {
Chengyu Fancfb80c72015-10-19 16:50:04 -0600104 _LOG_ERROR(e.what());
105 return 1;
Chengyu Fan71b712b2015-09-09 22:13:56 -0600106 }
107#endif
Chengyu Fan8b92f122015-03-09 22:13:36 -0600108
Chengyu Faneb0422c2015-03-04 16:34:14 -0700109 return 0;
110}