1 /* $Id: metaproxy_prog.cpp,v 1.7 2006-11-29 22:37:08 marc Exp $
2 Copyright (c) 2005-2006, Index Data.
4 See the LICENSE file for details
9 #include <boost/program_options.hpp>
10 namespace po = boost::program_options;
14 #include <libxml/xinclude.h>
17 #include "package.hpp"
18 #include "router_flexml.hpp"
19 #include "factory_static.hpp"
21 namespace mp = metaproxy_1;
23 int main(int argc, char **argv)
27 po::options_description desc("Allowed options");
29 ("help,h", "produce help message")
30 ("version,V", "show version")
31 ("config", po::value< std::vector<std::string> >(), "xml config")
34 po::positional_options_description p;
38 po::store(po::command_line_parser(argc, argv).
39 options(desc).positional(p).run(), vm);
42 if (vm.count("help")) {
43 std::cout << desc << "\n";
46 if (vm.count("version")) {
47 std::cout << "Metaproxy " VERSION "\n";
51 if (vm.count("config"))
53 std::vector<std::string> config_fnames =
54 vm["config"].as< std::vector<std::string> >();
56 if (config_fnames.size() != 1)
58 std::cerr << "Only one configuration must be given\n";
62 // need to parse with xinclude tags
63 // XML_PARSE_XINCLUDE XML_PARSE_NOBLANKS
64 // XML_PARSE_NSCLEAN XML_PARSE_NONET
65 doc = xmlReadFile(config_fnames[0].c_str(),
67 XML_PARSE_XINCLUDE + XML_PARSE_NOBLANKS
68 + XML_PARSE_NSCLEAN + XML_PARSE_NONET );
72 std::cerr << "XML parsing failed\n";
75 // and perform Xinclude then
76 if (xmlXIncludeProcess(doc) <= 0) {
77 std::cerr << "XInclude processing failed\n";
83 std::cerr << "No configuration given\n";
89 mp::FactoryStatic factory;
90 mp::RouterFleXML router(doc, factory);
92 pack.router(router).move();
94 catch (std::runtime_error &e) {
95 std::cerr << "std::runtime error: " << e.what() << "\n";
101 catch (po::unknown_option &e) {
102 std::cerr << e.what() << "; use --help for list of options\n";
105 catch (std::logic_error &e) {
106 std::cerr << "std::logic error: " << e.what() << "\n";
109 catch (std::runtime_error &e) {
110 std::cerr << "std::runtime error: " << e.what() << "\n";
114 std::cerr << "Unknown Exception" << std::endl;
124 * indent-tabs-mode: nil
125 * c-file-style: "stroustrup"
127 * vim: shiftwidth=4 tabstop=8 expandtab