feat: afterInit integration to the IOC shell.
The command allows to define boot routines before the iocInit.
This commit is contained in:
committed by
Andrew Johnson
parent
3d7a6b0b50
commit
77140abe70
@@ -4,7 +4,7 @@
|
||||
# Copyright (c) 2002 The Regents of the University of California, as
|
||||
# Operator of Los Alamos National Laboratory.
|
||||
# EPICS BASE is distributed subject to a Software License Agreement found
|
||||
# in file LICENSE that is included with this distribution.
|
||||
# in file LICENSE that is included with this distribution.
|
||||
#*************************************************************************
|
||||
|
||||
# This is a Makefile fragment, see src/ioc/Makefile.
|
||||
@@ -13,6 +13,7 @@ SRC_DIRS += $(IOCDIR)/misc
|
||||
|
||||
DBD += system.dbd
|
||||
DBD += dlload.dbd
|
||||
DBD += afterInit.dbd
|
||||
DBD += dbCore.dbd
|
||||
|
||||
INC += epicsRelease.h
|
||||
@@ -25,6 +26,7 @@ dbCore_SRCS += iocInit.c
|
||||
dbCore_SRCS += miscIocRegister.c
|
||||
dbCore_SRCS += dlload.c
|
||||
dbCore_SRCS += iocshRegisterCommon.c
|
||||
dbCore_SRCS += afterInit.c
|
||||
dbCore_SRCS += registerAllRecordDeviceDrivers.cpp
|
||||
|
||||
miscIocRegister_CFLAGS_iOS = -DSYSTEM_UNAVAILABLE
|
||||
|
||||
91
modules/database/src/ioc/misc/afterInit.c
Normal file
91
modules/database/src/ioc/misc/afterInit.c
Normal file
@@ -0,0 +1,91 @@
|
||||
/* Copyright (C) 2020 Dirk Zimoch */
|
||||
/* Copyright (C) 2020-2023 European Spallation Source, ERIC */
|
||||
|
||||
#include <dbAccess.h>
|
||||
#include <epicsExport.h>
|
||||
#include <epicsStdio.h>
|
||||
#include <epicsString.h>
|
||||
#include <errlog.h>
|
||||
#include <errno.h>
|
||||
#include <initHooks.h>
|
||||
#include <iocsh.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct cmditem {
|
||||
struct cmditem *next;
|
||||
char *cmd;
|
||||
};
|
||||
|
||||
struct cmditem *cmdlist, **cmdlast = &cmdlist;
|
||||
|
||||
void afterInitHook(initHookState state) {
|
||||
if (state != initHookAfterIocRunning) return;
|
||||
|
||||
struct cmditem *item = cmdlist;
|
||||
struct cmditem *next = NULL;
|
||||
while (item) {
|
||||
printf("%s\n", item->cmd);
|
||||
if (iocshCmd(item->cmd)) {
|
||||
errlogPrintf("afterInit: Command '%s' failed to run\n", item->cmd);
|
||||
};
|
||||
next = item->next;
|
||||
free(item->cmd);
|
||||
free(item);
|
||||
item = next;
|
||||
}
|
||||
}
|
||||
|
||||
static struct cmditem *newItem(char *cmd) {
|
||||
struct cmditem *item;
|
||||
item = malloc(sizeof(struct cmditem));
|
||||
if (item == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
item->cmd = epicsStrDup(cmd);
|
||||
item->next = NULL;
|
||||
|
||||
*cmdlast = item;
|
||||
cmdlast = &item->next;
|
||||
return item;
|
||||
}
|
||||
|
||||
static const iocshFuncDef afterInitDef = {
|
||||
"afterInit", 1,
|
||||
(const iocshArg *[]){
|
||||
&(iocshArg){"commandline", iocshArgString},
|
||||
}};
|
||||
|
||||
static void afterInitFunc(const iocshArgBuf *args) {
|
||||
static int first_time = 1;
|
||||
char *cmd;
|
||||
|
||||
if (first_time) {
|
||||
first_time = 0;
|
||||
initHookRegister(afterInitHook);
|
||||
}
|
||||
if (interruptAccept) {
|
||||
errlogPrintf("afterInit can only be used before iocInit\n");
|
||||
return;
|
||||
}
|
||||
|
||||
cmd = args[0].sval;
|
||||
if (!cmd || !cmd[0]) {
|
||||
errlogPrintf("Usage: afterInit \"command\"\n");
|
||||
return;
|
||||
}
|
||||
struct cmditem *item = newItem(cmd);
|
||||
|
||||
if (!item)
|
||||
errlogPrintf("afterInit: error adding command %s; %s", cmd,
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
static void afterInitRegister(void) {
|
||||
static int firstTime = 1;
|
||||
if (firstTime) {
|
||||
firstTime = 0;
|
||||
iocshRegister(&afterInitDef, afterInitFunc);
|
||||
}
|
||||
}
|
||||
epicsExportRegistrar(afterInitRegister);
|
||||
1
modules/database/src/ioc/misc/afterInit.dbd
Normal file
1
modules/database/src/ioc/misc/afterInit.dbd
Normal file
@@ -0,0 +1 @@
|
||||
registrar(afterInitRegister)
|
||||
@@ -18,6 +18,7 @@ DBD += softIoc.dbd
|
||||
|
||||
softIoc_DBD += base.dbd
|
||||
softIoc_DBD += dlload.dbd
|
||||
softIoc_DBD += afterInit.dbd
|
||||
softIoc_DBD += system.dbd
|
||||
|
||||
softIoc_SRCS += softIoc_registerRecordDeviceDriver.cpp
|
||||
@@ -29,4 +30,3 @@ softIoc_LIBS = $(EPICS_BASE_IOC_LIBS)
|
||||
DB += softIocExit.db
|
||||
|
||||
CLEANS += epicsInstallDir.h
|
||||
|
||||
|
||||
Reference in New Issue
Block a user