This is Unofficial EPICS BASE Doxygen Site
softMain.cpp File Reference
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "registryFunction.h"
#include "epicsThread.h"
#include "epicsExit.h"
#include "epicsStdio.h"
#include "dbStaticLib.h"
#include "subRecord.h"
#include "dbAccess.h"
#include "asDbLib.h"
#include "iocInit.h"
#include "iocsh.h"
+ Include dependency graph for softMain.cpp:

Go to the source code of this file.

Macros

#define DBD_FILE   FINAL_LOCATION "/dbd/softIocPVA.dbd"
 
#define EXIT_FILE   FINAL_LOCATION "/db/softIocExit.db"
 

Functions

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

Variables

const char * arg0
 
const char * base_dbd = DBD_FILE
 
const char * exit_db = EXIT_FILE
 

Macro Definition Documentation

#define DBD_FILE   FINAL_LOCATION "/dbd/softIocPVA.dbd"

Definition at line 80 of file softMain.cpp.

#define EXIT_FILE   FINAL_LOCATION "/db/softIocExit.db"

Definition at line 81 of file softMain.cpp.

Function Documentation

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

Definition at line 112 of file softMain.cpp.

113 {
114  char *dbd_file = const_cast<char*>(base_dbd);
115  char *macros = NULL;
116  char xmacro[PVNAME_STRINGSZ + 4];
117  int startIocsh = 1; /* default = start shell */
118  int loadedDb = 0;
119 
120  arg0 = strrchr(*argv, '/');
121  if (!arg0) {
122  arg0 = *argv;
123  } else {
124  ++arg0; /* skip the '/' */
125  }
126 
127  --argc, ++argv;
128 
129  /* Do this here in case the dbd file not available */
130  if (argc>0 && **argv=='-' && (*argv)[1]=='h') {
131  usage(EXIT_SUCCESS);
132  }
133 
134  if (argc>1 && **argv=='-' && (*argv)[1]=='D') {
135  dbd_file = *++argv;
136  argc -= 2;
137  ++argv;
138  }
139 
140  if (dbLoadDatabase(dbd_file, NULL, NULL)) {
141  epicsExit(EXIT_FAILURE);
142  }
143 
145  registryFunctionAdd("exit", (REGISTRYFUNCTION) exitSubroutine);
146 
147  while (argc>1 && **argv == '-') {
148  switch ((*argv)[1]) {
149  case 'a':
150  if (macros) asSetSubstitutions(macros);
151  asSetFilename(*++argv);
152  --argc;
153  break;
154 
155  case 'd':
156  if (dbLoadRecords(*++argv, macros)) {
157  epicsExit(EXIT_FAILURE);
158  }
159  loadedDb = 1;
160  --argc;
161  break;
162 
163  case 'h':
164  usage(EXIT_SUCCESS);
165 
166  case 'm':
167  macros = *++argv;
168  --argc;
169  break;
170 
171  case 'S':
172  startIocsh = 0;
173  break;
174 
175  case 's':
176  break;
177 
178  case 'x':
179  epicsSnprintf(xmacro, sizeof xmacro, "IOC=%s", *++argv);
180  if (dbLoadRecords(exit_db, xmacro)) {
181  epicsExit(EXIT_FAILURE);
182  }
183  loadedDb = 1;
184  --argc;
185  break;
186 
187  default:
188  printf("%s: option '%s' not recognized\n", arg0, *argv);
189  usage(EXIT_FAILURE);
190  }
191  --argc;
192  ++argv;
193  }
194 
195  if (argc>0 && **argv=='-') {
196  switch((*argv)[1]) {
197  case 'a':
198  case 'd':
199  case 'm':
200  case 'x':
201  printf("%s: missing argument to option '%s'\n", arg0, *argv);
202  usage(EXIT_FAILURE);
203 
204  case 'h':
205  usage(EXIT_SUCCESS);
206 
207  case 'S':
208  startIocsh = 0;
209  break;
210 
211  case 's':
212  break;
213 
214  default:
215  printf("%s: option '%s' not recognized\n", arg0, *argv);
216  usage(EXIT_FAILURE);
217  }
218  --argc;
219  ++argv;
220  }
221 
222  if (loadedDb) {
223  iocInit();
224  epicsThreadSleep(0.2);
225  }
226 
227  /* run user's startup script */
228  if (argc>0) {
229  if (iocsh(*argv)) epicsExit(EXIT_FAILURE);
230  epicsThreadSleep(0.2);
231  loadedDb = 1; /* Give it the benefit of the doubt... */
232  }
233 
234  /* start an interactive shell if it was requested */
235  if (startIocsh) {
236  iocsh(NULL);
237  } else {
238  if (loadedDb) {
240  } else {
241  printf("%s: Nothing to do!\n", arg0);
242  usage(EXIT_FAILURE);
243  }
244  }
245  epicsExit(EXIT_SUCCESS);
246  /*Note that the following statement will never be executed*/
247  return 0;
248 }
#define PVNAME_STRINGSZ
Size of a record name including the nil terminator.
Definition: dbDefs.h:72
void(* REGISTRYFUNCTION)(void)
#define printf
Definition: epicsStdio.h:41
#define NULL
Definition: catime.c:38
int asSetSubstitutions(const char *substitutions)
Definition: asDbLib.c:91
int epicsStdCall iocsh(const char *pathname)
Definition: iocsh.cpp:1011
int softIocPVA_registerRecordDeviceDriver(struct dbBase *pdbbase)
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
const char * arg0
Definition: softMain.cpp:89
epicsShareFunc int registryFunctionAdd(const char *name, REGISTRYFUNCTION func)
const char * base_dbd
Definition: softMain.cpp:90
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
int asSetFilename(const char *acf)
Definition: asDbLib.c:70
const char * exit_db
Definition: softMain.cpp:91
void usage(void)
Definition: cainfo.c:36
LIBCOM_API int epicsStdCall epicsSnprintf(char *str, size_t size, const char *format,...) EPICS_PRINTF_STYLE(3
int softIocPVA_registerRecordDeviceDriver ( struct dbBase pdbbase)

Variable Documentation

const char* arg0

Definition at line 89 of file softMain.cpp.

const char* base_dbd = DBD_FILE

Definition at line 90 of file softMain.cpp.

const char* exit_db = EXIT_FILE

Definition at line 91 of file softMain.cpp.