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