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