Rename from yp2 to metaproxy. The namespace for all definitions
[metaproxy-moved-to-github.git] / src / metaproxy_prog.cpp
1 /* $Id: metaproxy_prog.cpp,v 1.1 2006-03-16 10:40:59 adam Exp $
2    Copyright (c) 2005-2006, 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 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             try {
72                 mp::FactoryStatic factory;
73                 mp::RouterFleXML router(doc, factory);
74                 mp::Package pack;
75                 pack.router(router).move();
76             }
77             catch (std::runtime_error &e) {
78                 std::cout << "std::runtime error: " << e.what() << "\n";
79                 exit(1);
80             }
81             xmlFreeDoc(doc);
82         }
83     }
84     catch ( ... ) {
85         std::cerr << "Unknown Exception" << std::endl;
86         std::exit(1);
87     }
88     std::exit(0);
89 }
90
91
92 /*
93  * Local variables:
94  * c-basic-offset: 4
95  * indent-tabs-mode: nil
96  * c-file-style: "stroustrup"
97  * End:
98  * vim: shiftwidth=4 tabstop=8 expandtab
99  */