move initHooks to libCom

This commit is contained in:
Michael Davidsaver
2018-06-27 18:00:14 -07:00
parent d77a96d23d
commit dc310a4238
4 changed files with 3 additions and 3 deletions
-2
View File
@@ -35,7 +35,6 @@ INC += dbTest.h
INC += dbCaTest.h
INC += db_test.h
INC += db_field_log.h
INC += initHooks.h
INC += recGbl.h
INC += dbIocRegister.h
INC += chfPlugin.h
@@ -86,7 +85,6 @@ dbCore_SRCS += recGbl.c
dbCore_SRCS += callback.c
dbCore_SRCS += dbCa.c
dbCore_SRCS += dbCaTest.c
dbCore_SRCS += initHooks.c
dbCore_SRCS += cvtBpt.c
dbCore_SRCS += dbContext.cpp
dbCore_SRCS += dbChannelIO.cpp
-138
View File
@@ -1,138 +0,0 @@
/*************************************************************************\
* Copyright (c) 2009 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* 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.
\*************************************************************************/
/*
* Authors: Benjamin Franksen (BESY) and Marty Kraimer
* Date: 06-01-91
* major Revision: 07JuL97
*/
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include "dbDefs.h"
#include "ellLib.h"
#include "epicsMutex.h"
#include "epicsThread.h"
#define epicsExportSharedSymbols
#include "initHooks.h"
typedef struct initHookLink {
ELLNODE node;
initHookFunction func;
} initHookLink;
static ELLLIST functionList = ELLLIST_INIT;
static epicsMutexId listLock;
/*
* Lazy initialization functions
*/
static void initHookOnce(void *arg)
{
listLock = epicsMutexMustCreate();
}
static void initHookInit(void)
{
static epicsThreadOnceId onceFlag = EPICS_THREAD_ONCE_INIT;
epicsThreadOnce(&onceFlag, initHookOnce, NULL);
}
/*
* To be called before iocInit reaches state desired.
*/
int initHookRegister(initHookFunction func)
{
initHookLink *newHook;
if (!func) return 0;
initHookInit();
newHook = (initHookLink *)malloc(sizeof(initHookLink));
if (!newHook) {
printf("Cannot malloc a new initHookLink\n");
return -1;
}
newHook->func = func;
epicsMutexMustLock(listLock);
ellAdd(&functionList, &newHook->node);
epicsMutexUnlock(listLock);
return 0;
}
/*
* Called by iocInit at various points during initialization.
* This function must only be called by iocInit and relatives.
*/
void initHookAnnounce(initHookState state)
{
initHookLink *hook;
initHookInit();
epicsMutexMustLock(listLock);
hook = (initHookLink *)ellFirst(&functionList);
epicsMutexUnlock(listLock);
while (hook != NULL) {
hook->func(state);
epicsMutexMustLock(listLock);
hook = (initHookLink *)ellNext(&hook->node);
epicsMutexUnlock(listLock);
}
}
void initHookFree(void)
{
initHookInit();
epicsMutexMustLock(listLock);
ellFree(&functionList);
epicsMutexUnlock(listLock);
}
/*
* Call any time you want to print out a state name.
*/
const char *initHookName(int state)
{
const char *stateName[] = {
"initHookAtIocBuild",
"initHookAtBeginning",
"initHookAfterCallbackInit",
"initHookAfterCaLinkInit",
"initHookAfterInitDrvSup",
"initHookAfterInitRecSup",
"initHookAfterInitDevSup",
"initHookAfterInitDatabase",
"initHookAfterFinishDevSup",
"initHookAfterScanInit",
"initHookAfterInitialProcess",
"initHookAfterCaServerInit",
"initHookAfterIocBuilt",
"initHookAtIocRun",
"initHookAfterDatabaseRunning",
"initHookAfterCaServerRunning",
"initHookAfterIocRunning",
"initHookAtIocPause",
"initHookAfterCaServerPaused",
"initHookAfterDatabasePaused",
"initHookAfterIocPaused",
"initHookAfterInterruptAccept",
"initHookAtEnd"
};
if (state < 0 || state >= NELEMENTS(stateName)) {
return "Not an initHookState";
}
return stateName[state];
}
-68
View File
@@ -1,68 +0,0 @@
/*************************************************************************\
* Copyright (c) 2009 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* 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.
\*************************************************************************/
/*
* Authors: Benjamin Franksen (BESY) and Marty Kraimer
* Date: 06-01-91
* major Revision: 07JuL97
*/
#ifndef INC_initHooks_H
#define INC_initHooks_H
#include "shareLib.h"
#ifdef __cplusplus
extern "C" {
#endif
/* This enum must agree with the array of names defined in initHookName() */
typedef enum {
initHookAtIocBuild = 0, /* Start of iocBuild/iocInit commands */
initHookAtBeginning,
initHookAfterCallbackInit,
initHookAfterCaLinkInit,
initHookAfterInitDrvSup,
initHookAfterInitRecSup,
initHookAfterInitDevSup,
initHookAfterInitDatabase,
initHookAfterFinishDevSup,
initHookAfterScanInit,
initHookAfterInitialProcess,
initHookAfterCaServerInit,
initHookAfterIocBuilt, /* End of iocBuild command */
initHookAtIocRun, /* Start of iocRun command */
initHookAfterDatabaseRunning,
initHookAfterCaServerRunning,
initHookAfterIocRunning, /* End of iocRun/iocInit commands */
initHookAtIocPause, /* Start of iocPause command */
initHookAfterCaServerPaused,
initHookAfterDatabasePaused,
initHookAfterIocPaused, /* End of iocPause command */
/* Deprecated states, provided for backwards compatibility.
* These states are announced at the same point they were before,
* but will not be repeated if the IOC gets paused and restarted.
*/
initHookAfterInterruptAccept, /* After initHookAfterDatabaseRunning */
initHookAtEnd, /* Before initHookAfterIocRunning */
} initHookState;
typedef void (*initHookFunction)(initHookState state);
epicsShareFunc int initHookRegister(initHookFunction func);
epicsShareFunc void initHookAnnounce(initHookState state);
epicsShareFunc const char *initHookName(int state);
epicsShareFunc void initHookFree(void);
#ifdef __cplusplus
}
#endif
#endif /* INC_initHooks_H */