V4 View Generated Code

From EPICSWIKI

This page shows the code that will be generated from a Record View.

Each view maps to a separate property catalog that gives access to a particular set of fields of the record as a hierarchy. Taking as a simple example the following record definition:

record(rdouble) extends iocRecord {
    field(value, float64)
    field(units, string)
    view(value) {
        property(value, value) {
            property(units, units)
            property(timestamp, timeStamp)
            property(alarmSeverity, alarmSeverity)
            property(alarmStatus, alarmStatus)
        }
    }
}

This very simple record type defines a single value view with 5 properties, of which 4 are subordinate to the main value property. The following code would be generated from the above DBD definition to implement the view as a property catalog for use by the Data Access interface to the CA Server. I am using a simplified form of the old Data Access interface because of a lack of documentation on the new version.

class rdouble_view_value_value : public propertyCatalog {
public:
    rdouble_view_value_value(rdoubleRecord &);
    void traverse(dataViewer &);
    void find(const propertyId &, dataViewer &);
    // this isn't exactly Jeff's interface, but it shows the idea
private:
    rdoubleRecord &r;
};
rdouble_view_value_value::rdouble_view_value_value(rdoubleRecord &r_in)
    : r(r_in) {}
void rdouble_cat_value_value::traverse(dataViewer & v) {
    v.reveal(pidUnits, r.units);
    v.reveal(pidTimestamp, r.timestamp);
    v.reveal(pidAlarmSeverity, r.alarmSeverity);
    v.reveal(pidAlarmStatus, r.alarmStatus);
}
void rdouble_cat_value_value::find(const propertyId & p, dataViewer & v) {
    if (p == pidUnits)
        v.reveal(pidUnits, r.units);
    else if (p == pidTimestamp)
        v.reveal(pidTimestamp, r.timestamp);
    else if (p == pidAlarmSeverity)
        v.reveal(pidAlarmSeverity, r.alarmSeverity);
    else if (p == pidAlarmStatus)
        v.reveal(pidAlarmStatus, r.alarmStatus);
    else
        // ... ?
}
class rdouble_view_value : public propertyCatalog {
public:
    rdouble_view_value(rdoubleRecord &record);
    void traverse(dataViewer &);
    void find(const propertyId &, dataViewer &);
    // this isn't exactly Jeff's interface, but it shows the idea
private:
    rdoubleRecord &r;
    rdouble_view_value_value view_value_value;
};
rdouble_view_value::rdouble_view_value(rdoubleRecord &r_in)
    : r(r_in), view_value_value(r_in) {}
void rdouble_cat_value::traverse(dataViewer & v) {
    v.reveal(pidValue, r.value, view_value_value);
}
void rdouble_cat_value_value::find(const propertyId & p, dataViewer & v) {
    if (p == pidValue)
        v.reveal(pidValue, r.value, view_value_value);
    else
        // ... ?
}