da9fd09092aa68789e7d43cf04846f30ec5baf03
[metaproxy-moved-to-github.git] / src / ex_router_flexml.cpp
1 /* $Id: ex_router_flexml.cpp,v 1.9 2006-06-10 14:29:12 adam Exp $
2    Copyright (c) 2005-2006, Index Data.
3
4    See the LICENSE file for details
5  */
6
7 #include "config.hpp"
8
9 #include <boost/program_options.hpp>
10 namespace po = boost::program_options;
11
12 #include <iostream>
13 #include <stdexcept>
14
15 #include "filter.hpp"
16 #include "package.hpp"
17 #include "router_flexml.hpp"
18 #include "factory_static.hpp"
19
20 namespace mp = metaproxy_1;
21
22 int main(int argc, char **argv)
23 {
24     try 
25     {
26         po::options_description desc("Allowed options");
27         desc.add_options()
28             ("help", "produce help message")
29             ("config", po::value< std::vector<std::string> >(), "xml config")
30             ;
31         
32         po::positional_options_description p;
33         p.add("config", -1);
34         
35         po::variables_map vm;        
36         po::store(po::command_line_parser(argc, argv).
37                   options(desc).positional(p).run(), vm);
38         po::notify(vm);    
39         
40         if (vm.count("help")) {
41             std::cout << desc << "\n";
42             return 1;
43         }
44         
45         xmlDocPtr doc = 0;
46         if (vm.count("config"))
47         {
48             std::vector<std::string> config_fnames = 
49                 vm["config"].as< std::vector<std::string> >();
50
51             if (config_fnames.size() != 1)
52             {
53                 std::cerr << "Only one configuration must be given\n";
54                 std::exit(1);
55             }
56             
57             doc = xmlParseFile(config_fnames[0].c_str());
58             if (!doc)
59             {
60                 std::cerr << "xmlParseFile failed\n";
61                 std::exit(1);
62             }
63         }
64         else
65         {
66             std::cerr << "No configuration given\n";
67             std::exit(1);
68         }
69         if (doc)
70         {
71             mp::FactoryStatic factory;
72             mp::RouterFleXML router(doc, factory);
73
74             mp::Package pack;
75          
76             pack.router(router).move();
77
78             xmlFreeDoc(doc);
79         }
80     }
81     catch ( ... ) {
82         std::cerr << "Unknown Exception" << std::endl;
83         throw;
84         std::exit(1);
85     }
86     std::exit(0);
87 }
88
89
90 /*
91  * Local variables:
92  * c-basic-offset: 4
93  * indent-tabs-mode: nil
94  * c-file-style: "stroustrup"
95  * End:
96  * vim: shiftwidth=4 tabstop=8 expandtab
97  */