1 /* $Id: metaproxy_prog.cpp,v 1.10 2007-05-09 21:23:09 adam Exp $
2 Copyright (c) 2005-2007, Index Data.
4 This file is part of Metaproxy.
6 Metaproxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with Metaproxy; see the file LICENSE. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include <boost/program_options.hpp>
25 namespace po = boost::program_options;
29 #include <libxml/xinclude.h>
32 #include "package.hpp"
33 #include "router_flexml.hpp"
34 #include "factory_static.hpp"
36 namespace mp = metaproxy_1;
38 int main(int argc, char **argv)
42 po::options_description desc("Allowed options");
44 ("help,h", "produce help message")
45 ("version,V", "show version")
46 ("config", po::value< std::vector<std::string> >(), "xml config")
49 po::positional_options_description p;
53 po::store(po::command_line_parser(argc, argv).
54 options(desc).positional(p).run(), vm);
57 if (vm.count("help")) {
58 std::cout << desc << "\n";
61 if (vm.count("version")) {
62 std::cout << "Metaproxy " VERSION "\n";
66 if (vm.count("config"))
68 std::vector<std::string> config_fnames =
69 vm["config"].as< std::vector<std::string> >();
71 if (config_fnames.size() != 1)
73 std::cerr << "Only one configuration must be given\n";
77 // need to parse with xinclude tags
78 // XML_PARSE_XINCLUDE XML_PARSE_NOBLANKS
79 // XML_PARSE_NSCLEAN XML_PARSE_NONET
80 doc = xmlReadFile(config_fnames[0].c_str(),
82 XML_PARSE_XINCLUDE + XML_PARSE_NOBLANKS
83 + XML_PARSE_NSCLEAN + XML_PARSE_NONET );
87 std::cerr << "XML parsing failed\n";
90 // and perform Xinclude then
91 if (xmlXIncludeProcess(doc) > 0) {
92 std::cerr << "processing XInclude directive\n";
97 std::cerr << "No configuration given\n";
103 mp::FactoryStatic factory;
104 mp::RouterFleXML router(doc, factory);
106 pack.router(router).move();
108 catch (std::runtime_error &e) {
109 std::cerr << "std::runtime error: " << e.what() << "\n";
115 catch (po::unknown_option &e) {
116 std::cerr << e.what() << "; use --help for list of options\n";
119 catch (std::logic_error &e) {
120 std::cerr << "std::logic error: " << e.what() << "\n";
123 catch (std::runtime_error &e) {
124 std::cerr << "std::runtime error: " << e.what() << "\n";
128 std::cerr << "Unknown Exception" << std::endl;
138 * indent-tabs-mode: nil
139 * c-file-style: "stroustrup"
141 * vim: shiftwidth=4 tabstop=8 expandtab