Skip to content

Commit

Permalink
Split up dbcar so that it can use a callback function
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-ess committed Oct 26, 2023
1 parent b41787b commit 98e5f7b
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 74 deletions.
167 changes: 95 additions & 72 deletions modules/database/src/ioc/db/dbCaTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,101 @@
#include "dbCa.h"
#include "dbCaPvt.h"
#include "dbCaTest.h"
#include "dbCommon.h"
#include "db_convert.h"
#include "dbLock.h"
#include "link.h"


typedef struct ca_counts {
int level;
int ncalinks;
int nconnected;
unsigned long nDisconnect;
unsigned long nNoWrite;
int noReadAccess;
int noWriteAccess;
} ca_counts;

void print_ca_data(dbCommon *precord, dbFldDes *pdbFldDes, DBLINK* plink, void* pvt) {
caLink* pca;
ca_counts *counts = (ca_counts*)pvt;

counts->ncalinks++;
pca = (caLink *)plink->value.pv_link.pvt;
if (pca && pca->chid && (ca_field_type(pca->chid) != TYPENOTCONN))
{
counts->nconnected++;
counts->nDisconnect += pca->nDisconnect;
counts->nNoWrite += pca->nNoWrite;
if (!ca_read_access(pca->chid))
counts->noReadAccess++;
if (!ca_write_access(pca->chid))
counts->noWriteAccess++;
if (counts->level > 1)
{
int rw = ca_read_access(pca->chid) |
ca_write_access(pca->chid) << 1;
static const char *rights[4] = {
"No Access", "Read Only",
"Write Only", "Read/Write"};
int mask = plink->value.pv_link.pvlMask;
printf("%28s.%-4s ==> %-28s (%lu, %lu)\n",
precord->name,
pdbFldDes->name,
plink->value.pv_link.pvname,
pca->nDisconnect,
pca->nNoWrite);
printf("%21s [%s%s%s%s] host %s, %s\n", "",
mask & pvlOptInpNative ? "IN" : " ",
mask & pvlOptInpString ? "IS" : " ",
mask & pvlOptOutNative ? "ON" : " ",
mask & pvlOptOutString ? "OS" : " ",
ca_host_name(pca->chid),
rights[rw]);
}
}
else
{
if (counts->level > 0)
{
printf("%28s.%-4s --> %-28s (%lu, %lu)\n",
precord->name,
pdbFldDes->name,
plink->value.pv_link.pvname,
pca ? pca->nDisconnect : 0,
pca ? pca->nNoWrite : 0);
}
}
}

long process_ca_record_links(DBENTRY *pdbentry, void *pvt, void (*callback)(dbCommon *, dbFldDes *, DBLINK *, void *))
{
dbCommon *precord;
dbRecordType *pdbRecordType;
dbFldDes *pdbFldDes;
DBLINK *plink;
int j;

pdbRecordType = pdbentry->precordType;
precord = (dbCommon *)pdbentry->precnode->precord;
dbScanLock(precord);
for (j = 0; j < pdbRecordType->no_links; j++)
{
pdbFldDes = pdbRecordType->papFldDes[pdbRecordType->link_ind[j]];
plink = (DBLINK *)((char *)precord + pdbFldDes->offset);
if (plink->type == CA_LINK)
{
callback(precord, pdbFldDes, plink, pvt);
}
}
dbScanUnlock(precord);
}

long dbcar(char *precordname, int level)
{
DBENTRY dbentry;
DBENTRY *pdbentry=&dbentry;
long status;
dbCommon *precord;
dbRecordType *pdbRecordType;
dbFldDes *pdbFldDes;
DBLINK *plink;
int ncalinks=0;
int nconnected=0;
int noReadAccess=0;
int noWriteAccess=0;
unsigned long nDisconnect=0;
unsigned long nNoWrite=0;
caLink *pca;
int j;
ca_counts counts = {level,0,0,0,0,0,0};

if (!precordname || precordname[0] == '\0' || !strcmp(precordname, "*")) {
precordname = NULL;
Expand All @@ -83,75 +155,26 @@ long dbcar(char *precordname, int level)
if (precordname ?
!strcmp(precordname, dbGetRecordName(pdbentry)) :
!dbIsAlias(pdbentry)) {
pdbRecordType = pdbentry->precordType;
precord = (dbCommon *)pdbentry->precnode->precord;
dbScanLock(precord);
for (j=0; j<pdbRecordType->no_links; j++) {
pdbFldDes = pdbRecordType->papFldDes[pdbRecordType->link_ind[j]];
plink = (DBLINK *)((char *)precord + pdbFldDes->offset);
if (plink->type == CA_LINK) {
ncalinks++;
pca = (caLink *)plink->value.pv_link.pvt;
if (pca
&& pca->chid
&& (ca_field_type(pca->chid) != TYPENOTCONN)) {
nconnected++;
nDisconnect += pca->nDisconnect;
nNoWrite += pca->nNoWrite;
if (!ca_read_access(pca->chid)) noReadAccess++;
if (!ca_write_access(pca->chid)) noWriteAccess++;
if (level>1) {
int rw = ca_read_access(pca->chid) |
ca_write_access(pca->chid) << 1;
static const char *rights[4] = {
"No Access", "Read Only",
"Write Only", "Read/Write"
};
int mask = plink->value.pv_link.pvlMask;
printf("%28s.%-4s ==> %-28s (%lu, %lu)\n",
precord->name,
pdbFldDes->name,
plink->value.pv_link.pvname,
pca->nDisconnect,
pca->nNoWrite);
printf("%21s [%s%s%s%s] host %s, %s\n", "",
mask & pvlOptInpNative ? "IN" : " ",
mask & pvlOptInpString ? "IS" : " ",
mask & pvlOptOutNative ? "ON" : " ",
mask & pvlOptOutString ? "OS" : " ",
ca_host_name(pca->chid),
rights[rw]);
}
} else {
if (level>0) {
printf("%28s.%-4s --> %-28s (%lu, %lu)\n",
precord->name,
pdbFldDes->name,
plink->value.pv_link.pvname,
pca ? pca->nDisconnect : 0,
pca ? pca->nNoWrite : 0);
}
}
}
}
dbScanUnlock(precord);

process_ca_record_links(pdbentry, &counts, print_ca_data);

if (precordname) goto done;
}
status = dbNextRecord(pdbentry);
}
status = dbNextRecordType(pdbentry);
}
done:
if ((level > 1 && nconnected > 0) ||
(level > 0 && ncalinks != nconnected)) printf("\n");
if ((level > 1 && counts.nconnected > 0) ||
(level > 0 && counts.ncalinks != counts.nconnected)) printf("\n");
printf("Total %d CA link%s; ",
ncalinks, (ncalinks != 1) ? "s" : "");
counts.ncalinks, (counts.ncalinks != 1) ? "s" : "");
printf("%d connected, %d not connected.\n",
nconnected, (ncalinks - nconnected));
counts.nconnected, (counts.ncalinks - counts.nconnected));
printf(" %d can't read, %d can't write.",
noReadAccess, noWriteAccess);
counts.noReadAccess, counts.noWriteAccess);
printf(" (%lu disconnects, %lu writes prohibited)\n\n",
nDisconnect, nNoWrite);
counts.nDisconnect, counts.nNoWrite);
dbFinishEntry(pdbentry);

if ( level > 2 && dbCaClientContext != 0 ) {
Expand Down
7 changes: 5 additions & 2 deletions modules/database/src/ioc/db/dbCaTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
#define INC_dbCaTest_H

#include "dbCoreAPI.h"
#include "dbCommon.h"
#include "dbStaticLib.h"

#ifdef __cplusplus
extern "C" {
#endif

DBCORE_API long dbcar(char *recordname,int level);
DBCORE_API void dbcaStats(int *pchans, int *pdiscon);
DBCORE_API long process_ca_record_links(DBENTRY *pdbentry, void *pvt, void (*callback)(dbCommon *, dbFldDes *, DBLINK *, void *));
DBCORE_API long dbcar(char *recordname, int level);
DBCORE_API void dbcaStats(int *pchans, int *pdiscon);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 98e5f7b

Please sign in to comment.