Line data Source code
1 : /// Including DBE
2 : #include "dbe/MainWindow.hpp"
3 : #include "dbe/MyApplication.hpp"
4 : /// Including QT Headers
5 : #include <QApplication>
6 : /// Including BOOST
7 : #include <boost/program_options.hpp>
8 :
9 : #include <memory>
10 :
11 : #include "dbe/msghandler.hpp"
12 : #include "dbe/messenger.hpp"
13 : #include "dbe/types.hpp"
14 : #include "dbe/confaccessor.hpp"
15 :
16 : template class ::lutils::program::msghandler<dbe::interface::messenger::qt>;
17 :
18 : namespace bop = boost::program_options;
19 :
20 0 : int main(int argc, char *argv[])
21 : {
22 : /// Setting language variable to english(otherwise , is interpreted as . in numbers)
23 0 : setenv("LC_ALL", "C", 1);
24 :
25 0 : std::unique_ptr<dbe::MyApplication> myapp(new dbe::MyApplication(argc, argv));
26 :
27 0 : dbe::confaccessor::init();
28 :
29 0 : std::string configv;
30 0 : std::string oksfn;
31 0 : std::string rdbrl;
32 0 : std::string roksrl;
33 0 : QMap<QString, QString> argmap;
34 :
35 0 : bop::options_description options_description("Allowed options", 128);
36 :
37 0 : options_description.add_options()
38 0 : ("help,h", "Provide help message")
39 :
40 : // ("version,v", bop::value<std::string>(&configv)->default_value(configv),
41 : // "OKS version to load (when the GIT back-end is used - valid only in file mode)")
42 :
43 0 : ("file,f", bop::value<std::string>(&oksfn)->default_value(oksfn),
44 : "OKS database file name")
45 :
46 : // ("rdb,r", bop::value<std::string>(&rdbrl)->default_value(rdbrl),
47 : // "RDB resource locator (e.g. rdbServerName@partitionName)")
48 :
49 : // ("roksrl,o",bop::value<std::string>(&roksrl)->default_value(roksrl),
50 : // "ROKS resource locator (e.g. oracle://atlas_oks/r:atlas_oks_archive:<schema version>:<data version>)")
51 : ;
52 :
53 0 : bop::variables_map options_map;
54 :
55 0 : try {
56 0 : bop::parsed_options parsed = bop::command_line_parser(argc, argv).options(options_description).allow_unregistered().run();
57 :
58 : // This is to properly catch any positional argument (not supported)
59 0 : const auto& unknown = bop::collect_unrecognized(parsed.options, bop::include_positional);
60 0 : if(unknown.size() != 0) {
61 0 : std::cerr << "Incorrect command line argument, unrecognized options: ";
62 0 : for(const auto& o : unknown) {
63 0 : std::cerr << o << " ";
64 : }
65 0 : std::cerr << std::endl;
66 :
67 : return EXIT_FAILURE;
68 : }
69 :
70 0 : bop::store(parsed, options_map);
71 0 : bop::notify(options_map);
72 :
73 0 : auto display_help_message = [&options_description]()
74 : {
75 0 : std::cout
76 0 : << "DBE: TDAQ online configuration database editor"
77 0 : << std::endl
78 0 : << std::endl
79 0 : << "Usage: dbe [options]"
80 0 : << std::endl
81 0 : << std::endl
82 0 : << options_description
83 0 : << std::endl;
84 0 : };
85 :
86 0 : if(options_map.count("help")) {
87 0 : display_help_message();
88 : return EXIT_SUCCESS;
89 : }
90 :
91 0 : argmap.insert("f", QString::fromStdString(oksfn));
92 : // argmap.insert("r", QString::fromStdString(rdbrl));
93 : // argmap.insert("o", QString::fromStdString(roksrl));
94 : // argmap.insert("v", QString::fromStdString(configv));
95 :
96 0 : }
97 0 : catch(std::exception const & e) {
98 0 : std::cerr << "Incorrect command line argument: " << e.what() << std::endl;
99 0 : return EXIT_FAILURE;
100 0 : }
101 :
102 0 : std::unique_ptr<dbe::MainWindow> window(new dbe::MainWindow(argmap));
103 0 : try
104 : {
105 0 : window->show();
106 0 : return myapp->exec();
107 : }
108 0 : catch (std::exception const & e)
109 : {
110 0 : std::cerr << "Exception: " << e.what() << std::endl;
111 0 : }
112 0 : catch (...)
113 : {
114 0 : std::cerr << "Unknown Exception" << std::endl;
115 0 : }
116 :
117 : return EXIT_FAILURE;
118 0 : }
|