db: Use dbServer API

Setting TPRO now prints user@hostname instead of the thread
name when a record is processed as a result of a caput.

Also added the dbsr command, which currently just calls casr but
will call all registered server report routines (e.g. pvaSrv).
This commit is contained in:
Andrew Johnson
2014-05-29 17:11:31 -05:00
parent fc8ad6b9ec
commit dbe2a890ec
2 changed files with 50 additions and 23 deletions

View File

@@ -59,6 +59,7 @@
#include "dbNotify.h"
#include "dbAccessDefs.h"
#include "recGbl.h"
#include "dbServer.h"
epicsShareDef struct dbBase *pdbbase = 0;
epicsShareDef volatile int interruptAccept=FALSE;
@@ -454,6 +455,7 @@ long dbProcess(dbCommon *precord)
struct rset *prset = precord->rset;
dbRecordType *pdbRecordType = precord->rdes;
unsigned char tpro = precord->tpro;
char context[20] = "";
long status = 0;
int *ptrace;
int set_trace = FALSE;
@@ -484,23 +486,33 @@ long dbProcess(dbCommon *precord)
/* check for trace processing*/
if (tpro) {
if(*ptrace==0) {
if (!*ptrace) {
*ptrace = 1;
set_trace = TRUE;
}
}
if (*ptrace) {
/* Identify this thread's client from server layer */
if (dbServerClient(context, sizeof(context))) {
/* No client, use thread name */
strncpy(context, epicsThreadGetNameSelf(), sizeof(context));
context[sizeof(context) - 1] = 0;
}
}
/* If already active dont process */
if (precord->pact) {
unsigned short monitor_mask;
unsigned short monitor_mask;
if (*ptrace)
printf("%s: Active %s\n",
epicsThreadGetNameSelf(), precord->name);
printf("%s: Active %s\n", context, precord->name);
/* raise scan alarm after MAX_LOCK times */
if (precord->stat==SCAN_ALARM) goto all_done;
if (precord->lcnt++ !=MAX_LOCK) goto all_done;
if (precord->sevr>=INVALID_ALARM) goto all_done;
if ((precord->stat == SCAN_ALARM) ||
(precord->lcnt++ < MAX_LOCK) ||
(precord->sevr >= INVALID_ALARM)) goto all_done;
recGblSetSevr(precord, SCAN_ALARM, INVALID_ALARM);
monitor_mask = recGblResetAlarms(precord);
monitor_mask |= DBE_VALUE|DBE_LOG;
@@ -510,7 +522,8 @@ long dbProcess(dbCommon *precord)
monitor_mask);
goto all_done;
}
else precord->lcnt = 0;
else
precord->lcnt = 0;
/*
* Check the record disable link. A record will not be
@@ -521,9 +534,8 @@ long dbProcess(dbCommon *precord)
/* if disabled check disable alarm severity and return success */
if (precord->disa == precord->disv) {
if(*ptrace)
printf("%s: Disabled %s\n",
epicsThreadGetNameSelf(), precord->name);
if (*ptrace)
printf("%s: Disabled %s\n", context, precord->name);
/*take care of caching and notifyCompletion*/
precord->rpro = FALSE;
@@ -531,7 +543,9 @@ long dbProcess(dbCommon *precord)
callNotifyCompletion = TRUE;
/* raise disable alarm */
if (precord->stat==DISABLE_ALARM) goto all_done;
if (precord->stat == DISABLE_ALARM)
goto all_done;
precord->sevr = precord->diss;
precord->stat = DISABLE_ALARM;
precord->nsev = 0;
@@ -547,29 +561,34 @@ long dbProcess(dbCommon *precord)
/* locate record processing routine */
/* FIXME: put this in iocInit() !!! */
if (!(prset=precord->rset) || !(prset->process)) {
if (!prset || !prset->process) {
callNotifyCompletion = TRUE;
precord->pact=1;/*set pact TRUE so error is issued only once*/
precord->pact = 1;/*set pact so error is issued only once*/
recGblRecordError(S_db_noRSET, (void *)precord, "dbProcess");
status = S_db_noRSET;
if (*ptrace)
printf("%s: No RSET for %s\n",
epicsThreadGetNameSelf(), precord->name);
printf("%s: No RSET for %s\n", context, precord->name);
goto all_done;
}
if(*ptrace)
printf("%s: Process %s\n",
epicsThreadGetNameSelf(), precord->name);
if (*ptrace)
printf("%s: Process %s\n", context, precord->name);
/* process record */
status = (*prset->process)(precord);
status = prset->process(precord);
/* Print record's fields if PRINT_MASK set in breakpoint field */
if (lset_stack_count != 0) {
dbPrint(precord);
}
all_done:
if (set_trace) *ptrace = 0;
if(callNotifyCompletion && precord->ppn) dbNotifyCompletion(precord);
return(status);
if (set_trace)
*ptrace = 0;
if (callNotifyCompletion && precord->ppn)
dbNotifyCompletion(precord);
return status;
}
/*

View File

@@ -18,6 +18,7 @@
#include "db_test.h"
#include "dbLock.h"
#include "dbScan.h"
#include "dbServer.h"
#include "dbNotify.h"
#include "callback.h"
#include "dbIocRegister.h"
@@ -90,6 +91,12 @@ static const iocshArg * const dbapArgs[1] = {&dbapArg0};
static const iocshFuncDef dbapFuncDef = {"dbap",1,dbapArgs};
static void dbapCallFunc(const iocshArgBuf *args) { dbap(args[0].sval);}
/* dbsr */
static const iocshArg dbsrArg0 = { "interest level",iocshArgInt};
static const iocshArg * const dbsrArgs[1] = {&dbsrArg0};
static const iocshFuncDef dbsrFuncDef = {"dbsr",1,dbsrArgs};
static void dbsrCallFunc(const iocshArgBuf *args) { dbsr(args[0].ival);}
/* dbcar */
static const iocshArg dbcarArg0 = { "record name",iocshArgString};
static const iocshArg dbcarArg1 = { "level",iocshArgInt};
@@ -360,6 +367,7 @@ void dbIocRegister(void)
iocshRegister(&dbpFuncDef,dbpCallFunc);
iocshRegister(&dbapFuncDef,dbapCallFunc);
iocshRegister(&dbsrFuncDef,dbsrCallFunc);
iocshRegister(&dbcarFuncDef,dbcarCallFunc);
iocshRegister(&dbelFuncDef,dbelCallFunc);