Line data Source code
1 : #include <stdlib.h>
2 :
3 : #include <iostream>
4 : #include <string>
5 :
6 : #include "conffwk/Configuration.hpp"
7 : #include "conffwk/ConfigObject.hpp"
8 :
9 : using namespace dunedaq::conffwk;
10 :
11 0 : ERS_DECLARE_ISSUE(
12 : conffwk_test_object,
13 : BadCommandLine,
14 : "bad command line: " << reason,
15 : ((const char*)reason)
16 : )
17 :
18 0 : ERS_DECLARE_ISSUE(
19 : conffwk_test_object,
20 : ConfigException,
21 : "caught dunedaq::conffwk::Exception exception",
22 : )
23 :
24 : static void
25 0 : usage()
26 : {
27 0 : std::cout <<
28 : "Usage: conffwk_test_object -d | --database dbspec\n"
29 : " -c | --class-name class\n"
30 : " -o | --object-id object\n"
31 : "\n"
32 : "Options/Arguments:\n"
33 : " -d dbspec database specification in format plugin-name:parameters\n"
34 : " -c class name of the class to dump\n"
35 : " -o object optional id of the object to dump\n"
36 : "\n"
37 : "Description:\n"
38 0 : " The utility tests object existence.\n\n";
39 :
40 0 : }
41 :
42 : static void
43 0 : no_param(const char * s)
44 : {
45 0 : std::ostringstream text;
46 0 : text << "no parameter for " << s << " provided";
47 0 : ers::fatal(conffwk_test_object::BadCommandLine(ERS_HERE, text.str().c_str()));
48 0 : exit(EXIT_FAILURE);
49 0 : }
50 :
51 :
52 0 : int main(int argc, char *argv[])
53 : {
54 0 : const char * db_name = 0;
55 0 : const char * class_name = 0;
56 0 : const char * object_id = 0;
57 :
58 0 : for(int i = 1; i < argc; i++) {
59 0 : const char * cp = argv[i];
60 :
61 0 : if(!strcmp(cp, "-h") || !strcmp(cp, "--help")) {
62 0 : usage();
63 0 : return 0;
64 : }
65 0 : else if(!strcmp(cp, "-d") || !strcmp(cp, "--database")) {
66 0 : if(++i == argc) { no_param(cp); } else { db_name = argv[i]; }
67 : }
68 0 : else if(!strcmp(cp, "-c") || !strcmp(cp, "--class-name")) {
69 0 : if(++i == argc) { no_param(cp); } else { class_name = argv[i]; }
70 : }
71 0 : else if(!strcmp(cp, "-o") || !strcmp(cp, "--object-id")) {
72 0 : if(++i == argc) { no_param(cp); } else { object_id = argv[i]; }
73 : }
74 : else {
75 0 : std::ostringstream text;
76 0 : text << "unexpected parameter: \'" << cp << "\'; run command with --help to see valid command line options.";
77 0 : ers::fatal(conffwk_test_object::BadCommandLine(ERS_HERE, text.str().c_str()));
78 0 : return (EXIT_FAILURE);
79 0 : }
80 : }
81 :
82 0 : if(!db_name) {
83 0 : ers::fatal(conffwk_test_object::BadCommandLine(ERS_HERE, "no database name given"));
84 0 : return (EXIT_FAILURE);
85 : }
86 :
87 0 : if(!class_name) {
88 0 : ers::fatal(conffwk_test_object::BadCommandLine(ERS_HERE, "no class name given"));
89 0 : return (EXIT_FAILURE);
90 : }
91 :
92 0 : if(!object_id) {
93 0 : ers::fatal(conffwk_test_object::BadCommandLine(ERS_HERE, "no object id given"));
94 0 : return (EXIT_FAILURE);
95 : }
96 :
97 0 : try {
98 0 : Configuration db(db_name);
99 :
100 0 : if(db.test_object(class_name, object_id)) {
101 0 : std::cout << "object \'" << object_id << '@' << class_name << "\' exists" << std::endl;
102 : }
103 : else {
104 0 : std::cout << "object \'" << object_id << '@' << class_name << "\' does not exist" << std::endl;
105 : }
106 :
107 0 : return 0;
108 0 : }
109 0 : catch (dunedaq::conffwk::Exception & ex) {
110 0 : ers::fatal(conffwk_test_object::ConfigException(ERS_HERE, ex));
111 0 : }
112 :
113 0 : return (EXIT_FAILURE);
114 : }
|