epics-base / pvDataCPP

pvDataCPP is an EPICS V4 C++ module
https://epics-base.github.io/pvDataCPP/
Other
6 stars 16 forks source link

add PVRequestMapper #56

Closed mdavidsaver closed 5 years ago

mdavidsaver commented 6 years ago

Utility for pvRequest .field mangling in ChannelProvider implementations, either my or @mrkraimer preferred schemes can be selected with an enum. As per #51 this API is intended as a replacement of pvCopy, and the simpler extractRequestMask() I added previously.

A PVRequestMapper holds a precomputed mapping between two Structures, referred to as "Base" and "Requested".

The API itself revolves around the PVRequestMapper::copyBaseToRequested() and PVRequestMapper::copyBaseFromRequested() methods which allow masked shallow copying between PVStructures of the two types.

So a minimal usage would look like

// eg. during ChannelGet setup
PVStructurePtr mybase = ...; // some server internal structure
PVStructurePtr pvRequest = ...; // A client provided request

PVRequestMapper mapper(*mybase, *pvRequest); // precompute mapping and save for later use

// ... eg. later during ChannelGet::get()

BitSet valid = ...; // those fields of mybase which may actually be sent. (eg. having non-default values)
BitSet uvalid; // mapping of bit mask onto Requested Structure
PVStructurePtr userval(mapper.buildRequested());

mapper.copyBaseToRequested(*mybase, valid, *userval, uvalid); // copying.  userval and uvalid modified

There are a couple of differences in behavior vs. pvCopy which I know of (and probably some I don't).

Currently this API has been added in the SharedPV (aka. simplified server api) in pvAccessCPP. cf. https://github.com/mdavidsaver/pvAccessCPP/tree/inprog . I'm planning to use it as well in QSRV, and perhaps P2P.