Hi Dirk,
On 4/3/19 8:31 AM, Dirk Zimoch via Core-talk wrote:
I have seen that dbGetFieldType() and dbGetLinkType() are about to be
removed. What is the replacement for dbGetLinkType()? I want to find
out if a field is a PV link.
Those routines were deleted before the 7.0.2.1 release that was
published (although not formally announced) on March 20th. They were the
last vestiges of the dbStatic "Forms" support routines.
EPICS 7 now has extensible link types that don't map to the old "if it
isn't a constant or a DB link it must be a CA link" rules. We started
introducing these changes in 3.15.1 (the dbLink.h header was created in
2012 and first published in the 3.15.0.1 developer release in 2014). You
can now develop your own link types, and the IOC code can't know how to
look inside the link data structures for those links. We still support
the old CA and DB link types though, so code that sticks its fingers
into them will generally still work, but we don't let you do that with
the new link types.
The following new routines in dbLink.h allow you to examine the link
support that is attached to a particular link field:
int dbLinkIsDefined(const struct link *plink); /* 0 or 1 */
int dbLinkIsConstant(const struct link *plink); /* 0 or 1 */
int dbLinkIsVolatile(const struct link *plink); /* 0 or 1 */
int dbIsLinkConnected(const struct link *plink); /* 0 or 1 */
The first one dbLinkIsDefined() tells you whether the field is attached
to a link support at all. The next two give you some characteristics of
the link type; a constant link only provides a value at record
initialization time, so is comparable to the old DCT_LINK_CONSTANT; a
volatile link is one that may disconnect and reconnect at runtime (a DB
link is not volatile, while CA and pva links are since the server they
talk to can go down).
You can call the routine dbIsLinkConnected() to find out whether a
volatile link is currently connected to its target or not, although
there is of course no guarantee that the connection state won't change
immediately after the routine has returned. The calcout record now uses
this routine to populate the fields that allow you to see the connection
state of its link fields.
You can find out more about the other routines in dbLink.h by reading
the Doxygen comments that appear above the equivalent function pointers
in the definition of struct lset. I haven't talked about dbJLink.h which
is how new link types get to parse their addresses.
I use it in a utility function "dbll" (database list links) to show
which records link to given records or field: dbll recordpattern[.field]
The core of the function is:
for (status = dbFirstRecordType(&dbEntry); !status; status =
dbNextRecordType(&dbEntry))
for (status = dbFirstRecord(&dbEntry); !status; status =
dbNextRecord(&dbEntry))
{
#if EPICS_VERSION*10000+EPICS_REVISION*100+EPICS_MODIFICATION >= 31411
if (dbIsAlias(&dbEntry)) continue;
#endif
for (status = dbFirstField(&dbEntry, 0); !status; status =
dbNextField(&dbEntry, 0))
{
if (dbGetLinkType(&dbEntry) == DCT_LINK_PV)
{
const char* target = ((DBLINK
*)dbEntry.pfield)->value.pv_link.pvname;
if (!match || (
(strchr(target, '.') ? 1 : 0) == (d ? 1 : 0) ?
epicsStrGlobMatch(target, match) :
alt_match ? epicsStrGlobMatch(target,
alt_match) : 0))
{
printf("%s.%s ==> %s\n",
dbGetRecordName(&dbEntry), dbGetFieldName(&dbEntry),
dbGetString(&dbEntry));
}
}
}
}
dbFinishEntry(&dbEntry);
You can look at ((DBLINK *)dbEntry.pfield)->type which gives you one of
the link type constants defined at the top of link.h. The above
dbGetLinkType(&dbEntry) == DCT_LINK_PV condition is equivalent to that
type being any of PV_LINK, PN_LINK, DB_LINK or CA_LINK, which are
compatible with the old meanings.
There is now a faster way to find all the DB links that point to a
particular record though, the dbDbLink.c code now keeps an ELList of
those links for the new lock-set code in dbLock.c to use. I would be
happy to see a version of your "dbll" utility which uses those
back-links added to dbDbLink.c. If you're interested in contributing
such a utility to Base please let us know (both Michael and I have been
working in different parts of the link code recently).
- Andrew
--
Arguing for surveillance because you have nothing to hide is no
different than making the claim, "I don't care about freedom of
speech because I have nothing to say." -- Edward Snowdon