Skip to content

Commit

Permalink
Add -v (verbose) flag to softIocPVA
Browse files Browse the repository at this point in the history
Only display the startup steps with -v
Print each step *before* running it, so any error messages follow.
  • Loading branch information
anjohnson committed Oct 29, 2020
1 parent d100eac commit 0e77203
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions pdbApp/softMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ extern "C" int softIocPVA_registerRecordDeviceDriver(struct dbBase *pdbbase);

namespace {

bool verbose = false;

static void exitSubroutine(subRecord *precord) {
epicsExitLater((precord->a == 0.0) ? EXIT_SUCCESS : EXIT_FAILURE);
}

void usage(const char *arg0, const std::string& base_dbd) {
std::cout<<"Usage: "<<arg0<<
" [-D softIocPVA.dbd] [-h] [-S] [-s] [-a ascf]\n"
" [-D softIocPVA.dbd] [-h] [-S] [-s] [-v] [-a ascf]\n"
"[-m macro=value,macro2=value2] [-d file.db]\n"
"[-x prefix] [st.cmd]\n"
"\n"
Expand All @@ -69,6 +71,8 @@ void usage(const char *arg0, const std::string& base_dbd) {
"\n"
" -s Previously caused a shell to be started. Now accepted and ignored.\n"
"\n"
" -v Verbose, display steps taken during startup.\n"
"\n"
" -a <acf> Access Security configuration file. Macro substitution is\n"
" performed.\n"
"\n"
Expand Down Expand Up @@ -106,12 +110,14 @@ void lazy_dbd(const std::string& dbd_file) {
if(lazy_dbd_loaded) return;
lazy_dbd_loaded = true;

if (verbose)
std::cout<<"dbLoadDatabase(\""<<dbd_file<<"\")\n";
errIf(dbLoadDatabase(dbd_file.c_str(), NULL, NULL),
std::string("Failed to load DBD file: ")+dbd_file);
std::cout<<"dbLoadDatabase(\""<<dbd_file<<"\")\n";

if (verbose)
std::cout<<"softIocPVA_registerRecordDeviceDriver(pdbbase)\n";
softIocPVA_registerRecordDeviceDriver(pdbbase);
std::cout<<"softIocPVA_registerRecordDeviceDriver(pdbbase)\n";
registryFunctionAdd("exit", (REGISTRYFUNCTION) exitSubroutine);
}

Expand Down Expand Up @@ -149,7 +155,7 @@ int main(int argc, char *argv[])

int opt;

while ((opt = getopt(argc, argv, "ha:D:d:m:Ssx:")) != -1) {
while ((opt = getopt(argc, argv, "ha:D:d:m:Ssx:v")) != -1) {
switch (opt) {
case 'h': /* Print usage */
usage(argv[0], dbd_file);
Expand All @@ -163,13 +169,15 @@ int main(int argc, char *argv[])
case 'a':
lazy_dbd(dbd_file);
if (!macros.empty()) {
if (verbose)
std::cout<<"asSetSubstitutions(\""<<macros<<"\")\n";
if(asSetSubstitutions(macros.c_str()))
throw std::bad_alloc();
std::cout<<"asSetSubstitutions(\""<<macros<<"\")\n";
}
if (verbose)
std::cout<<"asSetFilename(\""<<optarg<<"\")\n";
if(asSetFilename(optarg))
throw std::bad_alloc();
std::cout<<"asSetFilename(\""<<optarg<<"\")\n";
break;
case 'D':
if(lazy_dbd_loaded) {
Expand All @@ -179,12 +187,14 @@ int main(int argc, char *argv[])
break;
case 'd':
lazy_dbd(dbd_file);
if (verbose) {
std::cout<<"dbLoadRecords(\""<<optarg<<"\"";
if(!macros.empty())
std::cout<<", \""<<macros<<"\"";
std::cout<<")\n";
}
errIf(dbLoadRecords(optarg, macros.c_str()),
std::string("Failed to load: ")+optarg);
std::cout<<"dbLoadRecords(\""<<optarg<<"\"";
if(!macros.empty())
std::cout<<", \""<<macros<<"\"";
std::cout<<")\n";
loadedDb = true;
break;
case 'm':
Expand All @@ -195,6 +205,9 @@ int main(int argc, char *argv[])
break;
case 's':
break; // historical
case 'v':
verbose = true;
break;
case 'x':
lazy_dbd(dbd_file);
xmacro = "IOC=";
Expand All @@ -212,17 +225,20 @@ int main(int argc, char *argv[])
// run script
// ignore any extra positional args (historical)

std::cout<<"# Begin "<<argv[optind]<<"\n";
if (verbose)
std::cout<<"# Begin "<<argv[optind]<<"\n";
errIf(iocsh(argv[optind]),
std::string("Error in ")+argv[optind]);
std::cout<<"# End "<<argv[optind]<<"\n";
if (verbose)
std::cout<<"# End "<<argv[optind]<<"\n";

epicsThreadSleep(0.2);
loadedDb = true; /* Give it the benefit of the doubt... */
}

if (loadedDb) {
std::cout<<"iocInit()\n";
if (verbose)
std::cout<<"iocInit()\n";
iocInit();
epicsThreadSleep(0.2);
}
Expand Down

0 comments on commit 0e77203

Please sign in to comment.