This is Unofficial EPICS BASE Doxygen Site
softMain.cpp File Reference
#include <iostream>
#include <string>
#include <list>
#include <stdexcept>
#include <epicsGetopt.h>
#include "registryFunction.h"
#include "epicsThread.h"
#include "epicsExit.h"
#include "epicsStdio.h"
#include "epicsString.h"
#include "dbStaticLib.h"
#include "subRecord.h"
#include "dbAccess.h"
#include "asDbLib.h"
#include "iocInit.h"
#include "iocsh.h"
#include "osiFileName.h"
#include "epicsInstallDir.h"
+ Include dependency graph for softMain.cpp:

Go to the source code of this file.

Macros

#define EPICS_BASE   "/"
 
#define DBD_BASE   "dbd" OSI_PATH_SEPARATOR "softIoc.dbd"
 
#define EXIT_BASE   "db" OSI_PATH_SEPARATOR "softIocExit.db"
 
#define DBD_FILE_REL   ".." OSI_PATH_SEPARATOR ".." OSI_PATH_SEPARATOR DBD_BASE
 
#define EXIT_FILE_REL   ".." OSI_PATH_SEPARATOR ".." OSI_PATH_SEPARATOR EXIT_BASE
 
#define DBD_FILE   EPICS_BASE OSI_PATH_SEPARATOR DBD_BASE
 
#define EXIT_FILE   EPICS_BASE OSI_PATH_SEPARATOR EXIT_BASE
 

Functions

int softIoc_registerRecordDeviceDriver (struct dbBase *pdbbase)
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

#define DBD_BASE   "dbd" OSI_PATH_SEPARATOR "softIoc.dbd"

Definition at line 40 of file softMain.cpp.

#define DBD_FILE   EPICS_BASE OSI_PATH_SEPARATOR DBD_BASE

Definition at line 44 of file softMain.cpp.

#define DBD_FILE_REL   ".." OSI_PATH_SEPARATOR ".." OSI_PATH_SEPARATOR DBD_BASE

Definition at line 42 of file softMain.cpp.

#define EPICS_BASE   "/"

Definition at line 36 of file softMain.cpp.

#define EXIT_BASE   "db" OSI_PATH_SEPARATOR "softIocExit.db"

Definition at line 41 of file softMain.cpp.

#define EXIT_FILE   EPICS_BASE OSI_PATH_SEPARATOR EXIT_BASE

Definition at line 45 of file softMain.cpp.

#define EXIT_FILE_REL   ".." OSI_PATH_SEPARATOR ".." OSI_PATH_SEPARATOR EXIT_BASE

Definition at line 43 of file softMain.cpp.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 116 of file softMain.cpp.

117 {
118  try {
119  std::string dbd_file(DBD_FILE),
120  exit_file(EXIT_FILE),
121  macros, // scratch space for macros (may be given more than once)
122  xmacro;
123  bool interactive = true;
124  bool loadedDb = false;
125 
126  // attempt to compute relative paths
127  {
128  std::string prefix;
129  char *cprefix = epicsGetExecDir();
130  if(cprefix) {
131  try {
132  prefix = cprefix;
133  free(cprefix);
134  } catch(...) {
135  free(cprefix);
136  throw;
137  }
138  }
139 
140  dbd_file = prefix + DBD_FILE_REL;
141  exit_file = prefix + EXIT_FILE_REL;
142  }
143 
144  int opt;
145 
146  while ((opt = getopt(argc, argv, "ha:D:d:m:Ssx:")) != -1) {
147  switch (opt) {
148  case 'h': /* Print usage */
149  usage(argv[0], dbd_file);
150  epicsExit(0);
151  return 0;
152  default:
153  usage(argv[0], dbd_file);
154  std::cerr<<"Unknown argument: -"<<char(opt)<<"\n";
155  epicsExit(2);
156  return 2;
157  case 'a':
158  lazy_dbd(dbd_file);
159  if (!macros.empty()) {
160  if(asSetSubstitutions(macros.c_str()))
161  throw std::bad_alloc();
162  std::cout<<"asSetSubstitutions(\""<<macros<<"\")\n";
163  }
164  if(asSetFilename(optarg))
165  throw std::bad_alloc();
166  std::cout<<"asSetFilename(\""<<optarg<<"\")\n";
167  break;
168  case 'D':
169  if(lazy_dbd_loaded) {
170  throw std::runtime_error("-D specified too late. softIoc.dbd already loaded.\n");
171  }
172  dbd_file = optarg;
173  break;
174  case 'd':
175  lazy_dbd(dbd_file);
176  errIf(dbLoadRecords(optarg, macros.c_str()),
177  std::string("Failed to load: ")+optarg);
178  std::cout<<"dbLoadRecords(\""<<optarg<<"\"";
179  if(!macros.empty())
180  std::cout<<", \""<<macros<<"\"";
181  std::cout<<")\n";
182  loadedDb = true;
183  break;
184  case 'm':
185  macros = optarg;
186  break;
187  case 'S':
188  interactive = false;
189  break;
190  case 's':
191  break; // historical
192  case 'x':
193  lazy_dbd(dbd_file);
194  xmacro = "IOC=";
195  xmacro += optarg;
196  errIf(dbLoadRecords(exit_file.c_str(), xmacro.c_str()),
197  std::string("Failed to load: ")+exit_file);
198  loadedDb = true;
199  break;
200  }
201  }
202 
203  lazy_dbd(dbd_file);
204 
205  if(optind<argc) {
206  // run script
207  // ignore any extra positional args (historical)
208 
209  std::cout<<"# Begin "<<argv[optind]<<"\n";
210  errIf(iocsh(argv[optind]),
211  std::string("Error in ")+argv[optind]);
212  std::cout<<"# End "<<argv[optind]<<"\n";
213 
214  epicsThreadSleep(0.2);
215  loadedDb = true; /* Give it the benefit of the doubt... */
216  }
217 
218  if (loadedDb) {
219  std::cout<<"iocInit()\n";
220  iocInit();
221  epicsThreadSleep(0.2);
222  }
223 
224  if(interactive) {
225  std::cout.flush();
226  std::cerr.flush();
227  if(iocsh(NULL)) {
228  epicsExit(1);
229  return 1;
230  }
231 
232  } else {
233  if (loadedDb) {
235 
236  } else {
237  usage(argv[0], dbd_file);
238  std::cerr<<"Nothing to do!\n";
239  epicsExit(1);
240  return 1;
241  }
242  }
243 
244  epicsExit(0);
245  return 0;
246 
247  }catch(std::exception& e){
248  std::cerr<<"Error: "<<e.what()<<"\n";
249  epicsExit(2);
250  return 2;
251  }
252 }
int getopt(int nargc, char *const *nargv, const char *ostr)
Definition: epicsGetopt.c:65
int optind
Definition: epicsGetopt.c:50
int interactive
Definition: flex.c:67
#define NULL
Definition: catime.c:38
LIBCOM_API char * epicsGetExecDir(void)
Definition: osdgetexec.c:38
int asSetSubstitutions(const char *substitutions)
Definition: asDbLib.c:91
int epicsStdCall iocsh(const char *pathname)
Definition: iocsh.cpp:1011
#define EXIT_FILE_REL
Definition: softMain.cpp:43
LIBCOM_API void epicsExit(int status)
Calls epicsExitCallAtExits(), then the OS exit() routine.
Definition: epicsExit.c:182
LIBCOM_API void epicsStdCall epicsThreadExitMain(void)
Definition: osdThread.c:683
int iocInit(void)
Definition: iocInit.c:108
LIBCOM_API void epicsStdCall epicsThreadSleep(double seconds)
Block the calling thread for at least the specified time.
Definition: osdThread.c:790
#define EXIT_FILE
Definition: softMain.cpp:45
int asSetFilename(const char *acf)
Definition: asDbLib.c:70
char * optarg
Definition: epicsGetopt.c:55
void usage(void)
Definition: cainfo.c:36
#define DBD_FILE_REL
Definition: softMain.cpp:42
#define DBD_FILE
Definition: softMain.cpp:44
int softIoc_registerRecordDeviceDriver ( struct dbBase pdbbase)