00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00026 #include "config.h"
00027 #include "Configurator.h"
00028 #include <rcudb/Server.h>
00029 #include <rcudb/Sql.h>
00030 #include <rcuxx/Rcu.h>
00031 #include <rcuxx/Bc.h>
00032 #include <rcuxx/Fmd.h>
00033 #include <rcuxx/Altro.h>
00034 #include "Rcu.h"
00035 #include "Bc.h"
00036 #include "Fmd.h"
00037 #include "Altro.h"
00038 #include <stdexcept>
00039 #include <iostream>
00040 #include "Options.h"
00041
00046 int
00047 main(int argc, char** argv)
00048 {
00049 using namespace RcuConf;
00050 Option<bool> hOpt('h', "help", "Show this help", false,false);
00051 Option<bool> VOpt('V', "version", "Show version number", false,false);
00052 Option<bool> fOpt('f', "fmd", "Use the FMD", false,false);
00053 Option<std::string> dOpt('d', "debug", "Debugging output");
00054 Option<bool> eOpt('e', "emul", "Emulation output", false,false);
00055 Option<unsigned> tOpt('t', "tag", "Tag to use\t", 0);
00056 Option<unsigned> xOpt('x', "x", "X coordinate\t", 0);
00057 Option<unsigned> yOpt('y', "y", "Y coordinate\t", 0);
00058 Option<unsigned> zOpt('z', "z", "Z coordinate\t", 0);
00059 Option<std::string> cOpt('c', "db", "Database connection url",
00060 "mysql://config@localhost/RCU");
00061 Option<std::string> uOpt('r', "rcu", "Rcu++ connection url",
00062 "fee://localhost/FMD1");
00063 CommandLine cl("");
00064 cl.Add(hOpt);
00065 cl.Add(VOpt);
00066 cl.Add(cOpt);
00067 cl.Add(tOpt);
00068 cl.Add(xOpt);
00069 cl.Add(yOpt);
00070 cl.Add(zOpt);
00071 cl.Add(fOpt);
00072 cl.Add(uOpt);
00073 cl.Add(dOpt);
00074 cl.Add(eOpt);
00075
00076 if (!cl.Process(argc, argv)) return 1;
00077 if (hOpt.IsSet()) {
00078 cl.Help();
00079 return 0;
00080 }
00081 if (VOpt.IsSet()) {
00082 std::cout << "rcuconf version " << VERSION << std::endl;
00083 return 0;
00084 }
00085
00086
00087 std::string con = cOpt;
00088 std::string url = uOpt;
00089 std::string deb = dOpt;
00090 try {
00091
00092 RcuDb::Server* server = RcuDb::Server::Connect(con);
00093 if (!server)
00094 throw std::runtime_error("Failed to open connection to server!");
00095
00096 std::cout << "Debug string: " << deb << " "
00097 << deb.find("rcu") << " "
00098 << (deb.find("rcu") != std::string::npos) << std::endl;
00099
00100 Rcuxx::Rcu* rcu = Rcuxx::Rcu::Open(url.c_str(), eOpt.IsSet(),
00101 deb.find("rcu")!=std::string::npos);
00102 if (!rcu)
00103 throw std::runtime_error("Failed to open connection to RCU");
00104 if (deb.find("backend") != std::string::npos)
00105 rcu->SetDebug(Rcuxx::Rcu::kBackend, 1);
00106
00107
00108 Rcuxx::Bc* bc = 0;
00109 if (fOpt.IsSet()) bc = new Rcuxx::Fmd(*rcu);
00110 else bc = new Rcuxx::Bc(*rcu);
00111 bc->SetDebug(deb.find("bc") != std::string::npos ||
00112 (fOpt.IsSet() && deb.find("fmd") != std::string::npos));
00113
00114 Rcuxx::Altro altro(*rcu);
00115 altro.SetDebug(deb.find("altro") != std::string::npos);
00116
00117
00118 Rcu rcuComp(*rcu);
00119 Bc bcComp(*bc);
00120 Altro altroComp(altro);
00121
00122
00123
00124 Configurator configurator(*server, rcuComp, bcComp, altroComp);
00125
00126
00127 int ret = configurator.Write(tOpt, xOpt, yOpt, zOpt);
00128 if (ret < 0)
00129 throw std::runtime_error(configurator.ErrorString());
00130
00131 const Rcuxx::Rcu::Block_t& b = rcu->GetBlock();
00132 std::cout << "Block: " << std::endl;
00133 for (int i = 0; i < ret; i++){
00134 std::cout << "\t" << i << "\t0x" << std::setfill('0')
00135 << std::hex << std::setw(8) << b[i] << std::dec
00136 << std::setfill(' ') << std::endl;
00137 }
00138 }
00139 catch (std::exception& e) {
00140 std::cerr << e.what() << std::endl;
00141 return 1;
00142 }
00143 return 0;
00144 }
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155