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