rudimentary config calls added in experimental binary
[metaproxy-moved-to-github.git] / src / ex_libxml2_conf.cpp
1 /* $Id: ex_libxml2_conf.cpp,v 1.1 2005-10-24 13:31:36 marc Exp $
2    Copyright (c) 2005, Index Data.
3
4 %LICENSE%
5  */
6
7 #include <iostream>
8 #include <stdexcept>
9
10 #include <boost/program_options.hpp>
11 namespace po = boost::program_options;
12
13
14 class Config 
15 {
16    public:
17       Config(int argc, char **argv)
18       {
19          
20          po::options_description generic("Generic options");
21          generic.add_options()
22             ("help,h", "produce help message")
23             ("version,v", "version number")
24             ;
25
26          po::options_description config("Config options");
27          config.add_options()
28             ("config,c", po::value<std::string>(&m_config)->default_value("ex_libxml2_conf.xml"),
29              "config XML file path (string)")
30             ("duration,d", po::value<int>(&m_duration)->default_value(3),
31              "number of seconds for server to exist (int)")
32             //("commands", po::value< std::vector<std::string> >(), 
33             //  "listener ports (string)")
34             ;
35          
36          //po::positional_options_description p;
37          // p.add("port", -1);
38          
39          po::options_description cmdline_options;
40          cmdline_options.add(generic).add(config);
41          po::variables_map vm;        
42
43          try 
44          {
45             //po::store(po::command_line_parser(argc, argv).
46             //       options(cmdline_options).positional(p).run(), vm);
47             //po::store(po::command_line_parser(argc, argv).
48             //     options(cmdline_options).run(), vm);
49             po::store(po::parse_command_line(argc, argv,  cmdline_options), vm);
50             po::notify(vm);    
51          }
52          catch ( po::invalid_command_line_syntax &e) {      
53             std::cerr << "ex_libxml2_conf error: " << e.what() << std::endl;
54             std::cerr << generic << config << std::endl;
55             std::exit(1);
56         }
57          catch ( po::invalid_option_value &e) {      
58             //std::cerr << "ex_libxml2_conf error: " << e.what() << std::endl;
59             std::cerr << "invalid option value" << std::endl;
60             std::cerr << generic << config << std::endl;
61             std::exit(1);
62          }
63          catch ( po::unknown_option &e) {      
64             std::cerr << "ex_libxml2_conf error: " << e.what() << std::endl;
65             std::cerr << generic << config << std::endl;
66            std::exit(1);
67          }
68          
69          std::cout << "ex_libxml2_conf ";
70          
71          if (vm.count("help")) {
72             std::cout << "--help" << std::endl;
73             std::cout << generic << config << std::endl;
74             std::exit(0);
75          }
76          
77         if (vm.count("version")) {
78            std::cout << "--version" << std::endl;
79            std::exit(0);
80         }
81         
82         if (vm.count("duration")) {
83            std::cout << "--duration " 
84                      << vm["duration"].as<int>() << " ";
85         }
86         if (vm.count("config")) {
87            std::cout << "--config " 
88                      << vm["config"].as<std::string>() << " ";
89         }
90         
91         std::cout << std::endl;
92
93         //if (vm.count("port"))
94         //{
95         //    std::vector<std::string> ports = 
96         //       vm["port"].as< std::vector<std::string> >();
97         //    
98         //    for (size_t i = 0; i<ports.size(); i++)
99         //       std::cout << "port " << i << " " << ports[i] << std::endl;
100             
101         //}
102       }
103       
104    public:
105       std::string config()
106       {
107          return m_config;
108       }
109       int duration()
110       {
111          return m_duration;
112       }
113       
114
115    private:
116       std::string m_config;
117       int m_duration;      
118       //xmlDoc * m_conf_doc;
119  
120       bool load_xml_doc()
121       {
122          return true;
123       }
124       
125 };
126
127
128
129 int main(int argc, char **argv)
130 {
131    //try 
132    //{
133
134    Config conf(argc, argv);
135
136    std::cout << "config " << conf.config() << std::endl;
137    std::cout << "duration " << conf.duration() << std::endl;
138    
139
140         // }
141         //catch ( ... ) {
142         //std::cerr << "Unknown Exception" << std::endl;
143         //throw();
144         //std::exit(1);
145         //}
146    std::exit(0);
147 }
148
149
150
151
152 /*
153  * Local variables:
154  * c-basic-offset: 4
155  * indent-tabs-mode: nil
156  * c-file-style: "stroustrup"
157  * End:
158  * vim: shiftwidth=4 tabstop=8 expandtab
159  */