00001
00002
00003 #include "config/ConfigObject.h"
00004 #include "oksconfig/OksConfiguration.h"
00005
00006 #include "Barrel.h"
00007 #include "Channel.h"
00008 #include "Crate.h"
00009 #include "Geography.h"
00010 #include "GeographyMUR.h"
00011 #include "Partition.h"
00012 #include "Power.h"
00013 #include "PowerCard.h"
00014 #include "PowerChannel.h"
00015 #include "PowerCrate.h"
00016 #include "PowerParam.h"
00017 #include "Rod.h"
00018 #include "RodMUR.h"
00019 #include "RodModule.h"
00020 #include "RodRModule.h"
00021 #include "Row.h"
00022 #include "SCT_Chip.h"
00023 #include "SCT_Module.h"
00024 #include "Slave.h"
00025 #include "Tim.h"
00026
00027
00028 static void usage(const char * s)
00029 {
00030 std::cout << s << " -d db-name -c class-name [-q query | -i object-id] [-t]\n"
00031 "\n"
00032 "Options/Arguments:\n"
00033 " -d | --data db-name mandatory name of the database\n"
00034 " -c | --class-name class-name mandatory name of class\n"
00035 " -q | --query query optional query to select class objects\n"
00036 " -i | --object-id object-id optional identity to select one object\n"
00037 " -t | --init-children all referenced objects are inited (is used\n"
00038 " for debug purposes and performance measurements)\n"
00039 " -h | --help print this message\n"
00040 "\n"
00041 "Description:\n"
00042 " The program prints out object(s) of given class.\n"
00043 " If no query or object id is provided, all objects of the class are printed.\n"
00044 " It is automatically generated by genconfig utility.\n"
00045 "\n";
00046 }
00047
00048 static void no_param(const char * s)
00049 {
00050 std::cerr << "ERROR: no parameter for " << s << " provided\n\n";
00051 exit (EXIT_FAILURE);
00052 }
00053
00054 int main(int argc, char *argv[])
00055 {
00056
00057
00058 const char * db_name = 0;
00059 const char * object_id = 0;
00060 const char * query = "";
00061 std::string class_name;
00062 bool init_children = false;
00063
00064 for(int i = 1; i < argc; i++) {
00065 const char * cp = argv[i];
00066 if(!strcmp(cp, "-h") || !strcmp(cp, "--help")) {
00067 usage(argv[0]);
00068 return 0;
00069 }
00070 if(!strcmp(cp, "-t") || !strcmp(cp, "--init-children")) {
00071 init_children = true;
00072 }
00073 else if(!strcmp(cp, "-d") || !strcmp(cp, "--data")) {
00074 if(++i == argc) { no_param(cp); } else { db_name = argv[i]; }
00075 }
00076 else if(!strcmp(cp, "-c") || !strcmp(cp, "--class-name")) {
00077 if(++i == argc) { no_param(cp); } else { class_name = argv[i]; }
00078 }
00079 else if(!strcmp(cp, "-i") || !strcmp(cp, "--object-id")) {
00080 if(++i == argc) { no_param(cp); } else { object_id = argv[i]; }
00081 }
00082 else if(!strcmp(cp, "-q") || !strcmp(cp, "--query")) {
00083 if(++i == argc) { no_param(cp); } else { query = argv[i]; }
00084 }
00085 else {
00086 std::cerr << "ERROR: bad parameter " << cp << std::endl;
00087 usage(argv[0]);
00088 return (EXIT_FAILURE);
00089 }
00090 }
00091
00092 if(db_name == 0) {
00093 std::cerr << "ERROR: no database name provided\n";
00094 return (EXIT_FAILURE);
00095 }
00096
00097 if(class_name.empty()) {
00098 std::cerr << "ERROR: no class name provided\n";
00099 return (EXIT_FAILURE);
00100 }
00101
00102 if(*query != 0 && object_id != 0) {
00103 std::cerr << "ERROR: only one parameter -i or -q can be provided\n";
00104 return (EXIT_FAILURE);
00105 }
00106
00107
00108 OksConfiguration impl_conf;
00109
00110 {
00111 ::Configuration conf(db_name, &impl_conf);
00112
00113 if(!conf.loaded()) {
00114 std::cerr << "Can not load database: " << db_name << std::endl;
00115 return (EXIT_FAILURE);
00116 }
00117
00118 std::vector< ::ConfigObject > objects;
00119
00120 if(object_id) {
00121 ::ConfigObject obj;
00122 if(conf.get(class_name, object_id, obj) == false) {
00123 std::cerr << "Can not get object \'" << object_id << "\' of class \'" << class_name << "\'\n";
00124 return (EXIT_FAILURE);
00125 }
00126 objects.push_back(obj);
00127 }
00128 else {
00129 if(conf.get(class_name, objects, query) == false) {
00130 std::cerr << "Can not get objects of class \'" << class_name << "\'\n";
00131 return (EXIT_FAILURE);
00132 }
00133 }
00134
00135 for(std::vector< ::ConfigObject >::iterator i = objects.begin(); i != objects.end(); ++i) {
00136 if(class_name == "Barrel") {
00137 std::cout << *conf.get<SCTDAL::Barrel>(*i, init_children) << std::endl;
00138 }
00139 else if(class_name == "Channel") {
00140 std::cout << *conf.get<SCTDAL::Channel>(*i, init_children) << std::endl;
00141 }
00142 else if(class_name == "Crate") {
00143 std::cout << *conf.get<SCTDAL::Crate>(*i, init_children) << std::endl;
00144 }
00145 else if(class_name == "Geography") {
00146 std::cout << *conf.get<SCTDAL::Geography>(*i, init_children) << std::endl;
00147 }
00148 else if(class_name == "GeographyMUR") {
00149 std::cout << *conf.get<SCTDAL::GeographyMUR>(*i, init_children) << std::endl;
00150 }
00151 else if(class_name == "Partition") {
00152 std::cout << *conf.get<SCTDAL::Partition>(*i, init_children) << std::endl;
00153 }
00154 else if(class_name == "Power") {
00155 std::cout << *conf.get<SCTDAL::Power>(*i, init_children) << std::endl;
00156 }
00157 else if(class_name == "PowerCard") {
00158 std::cout << *conf.get<SCTDAL::PowerCard>(*i, init_children) << std::endl;
00159 }
00160 else if(class_name == "PowerChannel") {
00161 std::cout << *conf.get<SCTDAL::PowerChannel>(*i, init_children) << std::endl;
00162 }
00163 else if(class_name == "PowerCrate") {
00164 std::cout << *conf.get<SCTDAL::PowerCrate>(*i, init_children) << std::endl;
00165 }
00166 else if(class_name == "PowerParam") {
00167 std::cout << *conf.get<SCTDAL::PowerParam>(*i, init_children) << std::endl;
00168 }
00169 else if(class_name == "Rod") {
00170 std::cout << *conf.get<SCTDAL::Rod>(*i, init_children) << std::endl;
00171 }
00172 else if(class_name == "RodMUR") {
00173 std::cout << *conf.get<SCTDAL::RodMUR>(*i, init_children) << std::endl;
00174 }
00175 else if(class_name == "RodModule") {
00176 std::cout << *conf.get<SCTDAL::RodModule>(*i, init_children) << std::endl;
00177 }
00178 else if(class_name == "RodRModule") {
00179 std::cout << *conf.get<SCTDAL::RodRModule>(*i, init_children) << std::endl;
00180 }
00181 else if(class_name == "Row") {
00182 std::cout << *conf.get<SCTDAL::Row>(*i, init_children) << std::endl;
00183 }
00184 else if(class_name == "SCT_Chip") {
00185 std::cout << *conf.get<SCTDAL::SCT_Chip>(*i, init_children) << std::endl;
00186 }
00187 else if(class_name == "SCT_Module") {
00188 std::cout << *conf.get<SCTDAL::SCT_Module>(*i, init_children) << std::endl;
00189 }
00190 else if(class_name == "Slave") {
00191 std::cout << *conf.get<SCTDAL::Slave>(*i, init_children) << std::endl;
00192 }
00193 else if(class_name == "Tim") {
00194 std::cout << *conf.get<SCTDAL::Tim>(*i, init_children) << std::endl;
00195 }
00196 else {
00197 std::cerr << "ERROR: do not know how to dump object of " << class_name << " class\n";
00198 return (EXIT_FAILURE);
00199 }
00200 }
00201 }
00202
00203 return 0;
00204 }