Change interface to ...Show functions, minor refactoring
* ...Show functions take an indent argument (number of spaces to print in front of each line) instead of a char* intro to avoid allocation at each level, replacing '\t' with 8 spaces in top level code where necessary * Refactor element_size -> field_size (as used in dbAddr), also in dbChannel functions * Fix: wrong macro name in unused part of db_field_log.h
This commit is contained in:
committed by
Michael Davidsaver
parent
317065dadb
commit
6e58dcfab6
@@ -504,13 +504,13 @@ static void channel_register_post(chFilter *filter,
|
||||
p->pif->channelRegisterPost(filter->chan, f->puser, cb_out, arg_out, probe);
|
||||
}
|
||||
|
||||
static void channel_report(chFilter *filter, const char *intro, int level)
|
||||
static void channel_report(chFilter *filter, int level, const unsigned short indent)
|
||||
{
|
||||
chfPlugin *p = (chfPlugin*) filter->plug->puser;
|
||||
chfFilter *f = (chfFilter*) filter->puser;
|
||||
|
||||
if (p->pif->channel_report)
|
||||
p->pif->channel_report(filter->chan, f->puser, intro, level);
|
||||
p->pif->channel_report(filter->chan, f->puser, level, indent);
|
||||
}
|
||||
|
||||
static void channel_close(chFilter *filter)
|
||||
|
||||
@@ -195,10 +195,10 @@ typedef struct chfPluginIf {
|
||||
*
|
||||
* @param chan dbChannel for which the report is requested.
|
||||
* @param pvt Pointer to private structure.
|
||||
* @param intro Line header string to be printed at the beginning of each line.
|
||||
* @param level Interest level.
|
||||
* @param indent Number of spaces to print before each output line.
|
||||
*/
|
||||
void (* channel_report) (dbChannel *chan, void *pvt, const char *intro, int level);
|
||||
void (* channel_report) (dbChannel *chan, void *pvt, int level, const unsigned short indent);
|
||||
|
||||
/* FIXME: More filter routines here ... */
|
||||
|
||||
|
||||
@@ -839,7 +839,7 @@ long epicsShareAPI dbGet(DBADDR *paddr, short dbrType,
|
||||
} else {
|
||||
DBADDR localAddr = *paddr; /* Structure copy */
|
||||
localAddr.field_type = pfl->field_type;
|
||||
localAddr.field_size = pfl->element_size;
|
||||
localAddr.field_size = pfl->field_size;
|
||||
localAddr.no_elements = pfl->no_elements;
|
||||
if (pfl->type == dbfl_type_val)
|
||||
localAddr.pfield = (char *) &pfl->u.v.field;
|
||||
@@ -875,7 +875,7 @@ long epicsShareAPI dbGet(DBADDR *paddr, short dbrType,
|
||||
} else {
|
||||
DBADDR localAddr = *paddr; /* Structure copy */
|
||||
localAddr.field_type = pfl->field_type;
|
||||
localAddr.field_size = pfl->element_size;
|
||||
localAddr.field_size = pfl->field_size;
|
||||
localAddr.no_elements = pfl->no_elements;
|
||||
if (pfl->type == dbfl_type_val)
|
||||
localAddr.pfield = (char *) &pfl->u.v.field;
|
||||
|
||||
@@ -469,7 +469,7 @@ long dbChannelOpen(dbChannel *chan)
|
||||
db_field_log p;
|
||||
probe.field_type = dbChannelFieldType(chan);
|
||||
probe.no_elements = dbChannelElements(chan);
|
||||
probe.element_size = dbChannelElementSize(chan);
|
||||
probe.field_size = dbChannelFieldSize(chan);
|
||||
p = probe;
|
||||
|
||||
/*
|
||||
@@ -507,7 +507,7 @@ long dbChannelOpen(dbChannel *chan)
|
||||
|
||||
/* Save probe results */
|
||||
chan->final_no_elements = probe.no_elements;
|
||||
chan->final_element_size = probe.element_size;
|
||||
chan->final_field_size = probe.field_size;
|
||||
chan->final_type = probe.field_type;
|
||||
chan->dbr_final_type = dbDBRnewToDBRold[mapDBFToDBR[probe.field_type]];
|
||||
|
||||
@@ -547,7 +547,7 @@ short dbChannelExportType(dbChannel *chan)
|
||||
return chan->addr.dbr_field_type;
|
||||
}
|
||||
|
||||
short dbChannelElementSize(dbChannel *chan)
|
||||
short dbChannelFieldSize(dbChannel *chan)
|
||||
{
|
||||
return chan->addr.field_size;
|
||||
}
|
||||
@@ -567,9 +567,9 @@ short dbChannelFinalExportType(dbChannel *chan)
|
||||
return chan->dbr_final_type;
|
||||
}
|
||||
|
||||
short dbChannelFinalElementSize(dbChannel *chan)
|
||||
short dbChannelFinalFieldSize(dbChannel *chan)
|
||||
{
|
||||
return chan->final_element_size;
|
||||
return chan->final_field_size;
|
||||
}
|
||||
|
||||
short dbChannelSpecial(dbChannel *chan)
|
||||
@@ -624,24 +624,41 @@ long dbChannelPutField(dbChannel *chan, short type, const void *pbuffer,
|
||||
return dbPutField(&chan->addr, type, pbuffer, nRequest);
|
||||
}
|
||||
|
||||
void dbChannelShow(dbChannel *chan, const char *intro, int level)
|
||||
void dbChannelShow(dbChannel *chan, int level, const unsigned short indent)
|
||||
{
|
||||
long elems = chan->addr.no_elements;
|
||||
long felems = chan->final_no_elements;
|
||||
int count = ellCount(&chan->filters);
|
||||
printf("%schannel name: %s\n", intro, chan->name);
|
||||
int pre = ellCount(&chan->pre_chain);
|
||||
int post = ellCount(&chan->post_chain);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < indent; i++) printf(" ");
|
||||
printf("channel name: %s\n", chan->name);
|
||||
for (i = 0; i < indent; i++) printf(" ");
|
||||
/* FIXME: show field_type as text */
|
||||
printf("%s field_type=%d, %ld element%s, %d filter%s\n",
|
||||
intro, chan->addr.field_type, elems, elems == 1 ? "" : "s",
|
||||
count, count == 1 ? "" : "s");
|
||||
printf(" field_type=%d (%dB), %ld element%s, %d filter%s",
|
||||
chan->addr.field_type, chan->addr.field_size, elems, elems == 1 ? "" : "s",
|
||||
count, count == 1 ? "" : "s");
|
||||
if (count)
|
||||
printf(" (%d pre eventq, %d post eventq)\n", pre, post);
|
||||
else
|
||||
printf("\n");
|
||||
if (level > 0)
|
||||
dbChannelFilterShow(chan, intro, level - 1);
|
||||
dbChannelFilterShow(chan, level - 1, indent + 2);
|
||||
if (count) {
|
||||
for (i = 0; i < indent; i++) printf(" ");
|
||||
/* FIXME: show field_type as text */
|
||||
printf(" final field_type=%d (%dB), %ld element%s\n",
|
||||
chan->final_type, chan->final_field_size, felems, felems == 1 ? "" : "s");
|
||||
}
|
||||
}
|
||||
|
||||
void dbChannelFilterShow(dbChannel *chan, const char *intro, int level)
|
||||
void dbChannelFilterShow(dbChannel *chan, int level, const unsigned short indent)
|
||||
{
|
||||
chFilter *filter = (chFilter *) ellFirst(&chan->filters);
|
||||
while (filter) {
|
||||
filter->plug->fif->channel_report(filter, intro, level);
|
||||
filter->plug->fif->channel_report(filter, level, indent);
|
||||
filter = (chFilter *) ellNext(&filter->list_node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ typedef struct dbChannel {
|
||||
const char *name;
|
||||
dbAddr addr; /* address structure for record/field */
|
||||
long final_no_elements; /* final number of elements (arrays) */
|
||||
short final_element_size; /* final size of element */
|
||||
short final_field_size; /* final size of element */
|
||||
short final_type; /* final type of database field */
|
||||
short dbr_final_type; /* final field type as seen by database request */
|
||||
ELLLIST filters; /* list of filters as created from JSON */
|
||||
@@ -107,7 +107,7 @@ typedef struct chFilterIf {
|
||||
long (* channel_open)(chFilter *filter);
|
||||
void (* channel_register_pre) (chFilter *filter, chPostEventFunc **cb_out, void **arg_out, db_field_log *probe);
|
||||
void (* channel_register_post)(chFilter *filter, chPostEventFunc **cb_out, void **arg_out, db_field_log *probe);
|
||||
void (* channel_report)(chFilter *filter, const char *intro, int level);
|
||||
void (* channel_report)(chFilter *filter, int level, const unsigned short indent);
|
||||
/* FIXME: More filter routines here ... */
|
||||
void (* channel_close)(chFilter *filter);
|
||||
} chFilterIf;
|
||||
@@ -146,7 +146,7 @@ epicsShareFunc struct dbFldDes * dbChannelFldDes(dbChannel *chan);
|
||||
epicsShareFunc long dbChannelElements(dbChannel *chan);
|
||||
epicsShareFunc short dbChannelFieldType(dbChannel *chan);
|
||||
epicsShareFunc short dbChannelExportType(dbChannel *chan);
|
||||
epicsShareFunc short dbChannelElementSize(dbChannel *chan);
|
||||
epicsShareFunc short dbChannelFieldSize(dbChannel *chan);
|
||||
epicsShareFunc long dbChannelFinalElements(dbChannel *chan);
|
||||
epicsShareFunc short dbChannelFinalFieldType(dbChannel *chan);
|
||||
epicsShareFunc short dbChannelFinalExportType(dbChannel *chan);
|
||||
@@ -161,10 +161,10 @@ epicsShareFunc long dbChannelPut(dbChannel *chan, short type,
|
||||
const void *pbuffer, long nRequest);
|
||||
epicsShareFunc long dbChannelPutField(dbChannel *chan, short type,
|
||||
const void *pbuffer, long nRequest);
|
||||
epicsShareFunc void dbChannelShow(dbChannel *chan, const char *intro,
|
||||
int level);
|
||||
epicsShareFunc void dbChannelFilterShow(dbChannel *chan, const char *intro,
|
||||
int level);
|
||||
epicsShareFunc void dbChannelShow(dbChannel *chan, int level,
|
||||
const unsigned short indent);
|
||||
epicsShareFunc void dbChannelFilterShow(dbChannel *chan, int level,
|
||||
const unsigned short indent);
|
||||
epicsShareFunc void dbChannelDelete(dbChannel *chan);
|
||||
|
||||
epicsShareFunc void dbRegisterFilter(const char *key, const chFilterIf *fif, void *puser);
|
||||
|
||||
@@ -155,12 +155,12 @@ void dbChannelIO::show (
|
||||
dbChannelRecord ( this->dbch ) -> name );
|
||||
|
||||
if ( level > 0u ) {
|
||||
printf ( "\ttype %s, element count %li, field at %p\n",
|
||||
printf ( " type %s, element count %li, field at %p\n",
|
||||
dbf_type_to_text ( dbChannelExportType ( this->dbch ) ),
|
||||
dbChannelElements ( this->dbch ),
|
||||
dbChannelField ( this->dbch ) );
|
||||
if ( level > 1u ) {
|
||||
dbChannelFilterShow ( this->dbch, "\t", level - 2u );
|
||||
dbChannelFilterShow ( this->dbch, level - 2u, 8 );
|
||||
this->serviceIO.show ( level - 2u );
|
||||
this->serviceIO.showAllIO ( *this, level - 2u );
|
||||
}
|
||||
|
||||
@@ -425,7 +425,7 @@ dbEventSubscription epicsShareAPI db_add_event (
|
||||
* there upon wakeup)
|
||||
*/
|
||||
if( dbChannelElements(chan) == 1 &&
|
||||
dbChannelElementSize(chan) <= sizeof(union native_value)) {
|
||||
dbChannelFieldSize(chan) <= sizeof(union native_value)) {
|
||||
pevent->useValque = TRUE;
|
||||
}
|
||||
else {
|
||||
@@ -649,7 +649,7 @@ db_field_log* epicsShareAPI db_create_event_log (struct evSubscrip *pevent)
|
||||
*/
|
||||
memcpy(&pLog->u.v.field,
|
||||
dbChannelField(chan),
|
||||
dbChannelElementSize(chan));
|
||||
dbChannelFieldSize(chan));
|
||||
} else {
|
||||
pLog->type = dbfl_type_rec;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ union native_value {
|
||||
long dbf_long;
|
||||
double dbf_double;
|
||||
#ifdef DB_EVENT_LOG_STRINGS
|
||||
char dbf_string[MAXSTRINGSIZE];
|
||||
char dbf_string[MAX_STRING_SIZE];
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -86,7 +86,7 @@ typedef struct db_field_log {
|
||||
unsigned short stat; /* Alarm Status */
|
||||
unsigned short sevr; /* Alarm Severity */
|
||||
short field_type; /* DBF type of data */
|
||||
short element_size; /* Data size */
|
||||
short field_size; /* Data size */
|
||||
long no_elements; /* No of array elements */
|
||||
union {
|
||||
struct dbfl_val v;
|
||||
|
||||
@@ -54,7 +54,7 @@ int gft(char *pname)
|
||||
printf("Record Address: 0x%p\n", precord);
|
||||
printf(" Export Type: %d\n", type);
|
||||
printf(" Field Address: 0x%p\n", dbChannelField(chan));
|
||||
printf(" Field Size: %d\n", dbChannelElementSize(chan));
|
||||
printf(" Field Size: %d\n", dbChannelFieldSize(chan));
|
||||
printf(" No Elements: %ld\n", elements);
|
||||
|
||||
if (elements > MAX_ELEMS)
|
||||
@@ -108,7 +108,7 @@ int epicsShareAPI pft(char *pname, char *pvalue)
|
||||
printf("Record Address: 0x%p\n", precord);
|
||||
printf(" Export Type: %d\n", type);
|
||||
printf(" Field Address: 0x%p\n", dbChannelField(chan));
|
||||
printf(" Field Size: %d\n", dbChannelElementSize(chan));
|
||||
printf(" Field Size: %d\n", dbChannelFieldSize(chan));
|
||||
printf(" No Elements: %ld\n", elements);
|
||||
|
||||
if (dbChannel_put(chan, DBR_STRING,pvalue, 1) < 0)
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#define PATTERN 0x55555555
|
||||
#define TYPE_START 0xAAA
|
||||
#define R_INTRO "abc"
|
||||
#define R_LEVEL 42
|
||||
|
||||
/* Expected / actually run callback bit definitions */
|
||||
@@ -348,10 +347,9 @@ static void channelRegisterPost(dbChannel *chan, void *user,
|
||||
*arg_out = user;
|
||||
}
|
||||
|
||||
static void channel_report(dbChannel *chan, void *user, const char *intro, int level)
|
||||
static void channel_report(dbChannel *chan, void *user, int level, const unsigned short indent)
|
||||
{
|
||||
testOk(user == puser1 || user == puser2, "channel_report: user pointer valid");
|
||||
testOk(!(strcmp(intro, R_INTRO)), "channel_report: intro string correct");
|
||||
testOk(level == R_LEVEL - 1, "channel_report: level correct");
|
||||
if (user == puser1) {
|
||||
testOk(e1 & e_report, "channel_report (1) called");
|
||||
@@ -439,7 +437,7 @@ MAIN(chfPluginTest)
|
||||
dbChannel *pch;
|
||||
db_field_log *pfl;
|
||||
|
||||
testPlan(1783);
|
||||
testPlan(1754);
|
||||
|
||||
db_init_events();
|
||||
|
||||
@@ -654,7 +652,7 @@ MAIN(chfPluginTest)
|
||||
db_delete_field_log(pfl); \
|
||||
if (!testOk(c1 == e1, "run filter chains: all expected calls happened")) testDiag("expected %#x - called %#x", e1, c1); \
|
||||
e1 = e_report; c1 = 0; \
|
||||
dbChannelShow(pch, R_INTRO, R_LEVEL); \
|
||||
dbChannelShow(pch, R_LEVEL, 0); \
|
||||
if (!testOk(c1 == e1, "report: all expected calls happened")) testDiag("expected %#x - called %#x", e1, c1); \
|
||||
e1 = e_close | e_free; c1 = 0; \
|
||||
if (pch) dbChannelDelete(pch); \
|
||||
@@ -686,7 +684,7 @@ MAIN(chfPluginTest)
|
||||
if (!testOk(c2 == e2, "run filter chains (2): all expected calls happened")) testDiag("expected %#x - called %#x", e2, c2); \
|
||||
e1 = e_report; c1 = 0; \
|
||||
e2 = e_report; c2 = 0; \
|
||||
dbChannelShow(pch, R_INTRO, R_LEVEL); \
|
||||
dbChannelShow(pch, R_LEVEL, 0); \
|
||||
if (!testOk(c1 == e1, "report (1): all expected calls happened")) testDiag("expected %#x - called %#x", e1, c1); \
|
||||
if (!testOk(c2 == e2, "report (2): all expected calls happened")) testDiag("expected %#x - called %#x", e2, c2); \
|
||||
e1 = e_close | e_free; c1 = 0; \
|
||||
|
||||
@@ -132,7 +132,7 @@ void c_reg_post(chFilter *filter, chPostEventFunc **cb_out, void **arg_out, db_f
|
||||
{
|
||||
testOk(e & e_reg_post, "channel_register_post called");
|
||||
}
|
||||
void c_report(chFilter *filter, const char *intro, int level)
|
||||
void c_report(chFilter *filter, int level, const unsigned short indent)
|
||||
{
|
||||
testOk(e & e_report, "channel_report called, level = %d", level);
|
||||
}
|
||||
@@ -214,7 +214,7 @@ MAIN(dbChannelTest)
|
||||
testOk1(!!(pch = dbChannelCreate("x.{\"scalar\":null}")));
|
||||
|
||||
e = e_report;
|
||||
dbChannelShow(pch, "# ", 1);
|
||||
dbChannelShow(pch, 1, 2);
|
||||
|
||||
e = e_close;
|
||||
if (pch) dbChannelDelete(pch);
|
||||
|
||||
@@ -355,8 +355,8 @@ static void showChanList (
|
||||
epicsMutexMustLock ( client->chanListLock );
|
||||
pciu = (struct channel_in_use *) pList->node.next;
|
||||
while ( pciu ){
|
||||
dbChannelShow ( pciu->dbch, "\t", level );
|
||||
printf( "\t # on eventq=%d, access=%c%c\n",
|
||||
dbChannelShow ( pciu->dbch, level, 8 );
|
||||
printf( " # on eventq=%d, access=%c%c\n",
|
||||
ellCount ( &pciu->eventq ),
|
||||
asCheckGet ( pciu->asClientPVT ) ? 'r': '-',
|
||||
rsrvCheckPut ( pciu ) ? 'w': '-' );
|
||||
|
||||
Reference in New Issue
Block a user