RouterFleXML now reads XML simple config and make proper runtime
[metaproxy-moved-to-github.git] / src / ex_router_flexml.cpp
1 /* $Id: ex_router_flexml.cpp,v 1.6 2006-01-09 13:43:59 adam Exp $
2    Copyright (c) 2005, Index Data.
3
4 %LICENSE%
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 int main(int argc, char **argv)
21 {
22     try 
23     {
24
25         po::options_description desc("Allowed options");
26         desc.add_options()
27             ("help", "produce help message")
28             ("config", po::value< std::vector<std::string> >(), "xml config")
29             ;
30         
31         po::positional_options_description p;
32         p.add("config", -1);
33         
34         po::variables_map vm;        
35         po::store(po::command_line_parser(argc, argv).
36                   options(desc).positional(p).run(), vm);
37         po::notify(vm);    
38         
39         if (vm.count("help")) {
40             std::cout << desc << "\n";
41             return 1;
42         }
43         
44         xmlDocPtr doc = 0;
45         if (vm.count("config"))
46         {
47             std::vector<std::string> config_fnames = 
48                 vm["config"].as< std::vector<std::string> >();
49
50             if (config_fnames.size() != 1)
51             {
52                 std::cerr << "Only one configuration must be given\n";
53                 std::exit(1);
54             }
55             
56             doc = xmlParseFile(config_fnames[0].c_str());
57             if (!doc)
58             {
59                 std::cerr << "xmlParseFile failed\n";
60                 std::exit(1);
61             }
62         }
63         else
64         {
65             std::cerr << "No configuration given\n";
66             std::exit(1);
67         }
68         if (doc)
69         {
70             yp2::FactoryStatic factory;
71             yp2::RouterFleXML router(doc, factory);
72
73             yp2::Package pack;
74          
75             pack.router(router).move();
76
77             xmlFreeDoc(doc);
78         }
79     }
80     catch ( ... ) {
81         std::cerr << "Unknown Exception" << std::endl;
82         throw;
83         std::exit(1);
84     }
85     std::exit(0);
86 }
87
88
89
90
91 /*
92  * Local variables:
93  * c-basic-offset: 4
94  * indent-tabs-mode: nil
95  * c-file-style: "stroustrup"
96  * End:
97  * vim: shiftwidth=4 tabstop=8 expandtab
98  */