Esempio n. 1
0
// Union fields
void PvObject::setUnion(const std::string& key, const PvObject& value)
{
    epics::pvData::PVUnionPtr pvUnionPtr = PyPvDataUtility::getUnionField(key, pvStructurePtr);
    std::string keyFrom = PyPvDataUtility::getValueOrSingleFieldName(value.getPvStructurePtr());
    epics::pvData::PVFieldPtr pvFrom = PyPvDataUtility::getSubField(keyFrom, value.getPvStructurePtr());
    PyPvDataUtility::setUnionField(pvFrom, pvUnionPtr);
}
Esempio n. 2
0
PvUnion::PvUnion(const PvObject& pvObject)
    : PvObject(createUnionStructureDict(const_cast<PvObject*>(&pvObject)->getStructureDict())),
      unionPtr(epics::pvData::getFieldCreate()->createUnion(
                   pvObject.getPvStructurePtr()->getStructure()->getFieldNames(),
                   pvObject.getPvStructurePtr()->getStructure()->getFields()))
{
    dataType = PvType::Union;
}
Esempio n. 3
0
// UnionArray fields
void PvObject::setUnionArray(const std::string& key, const boost::python::list& pyList)
{
    epics::pvData::PVUnionArrayPtr pvUnionArrayPtr = PyPvDataUtility::getUnionArrayField(key, pvStructurePtr);
    epics::pvData::UnionConstPtr unionPtr = pvUnionArrayPtr->getUnionArray()->getUnion();
    int listSize = boost::python::len(pyList);
    epics::pvData::PVUnionArray::svector data(listSize);
    for(size_t i = 0; i < data.size(); ++i) {
        epics::pvData::PVUnionPtr pvUnionPtr = epics::pvData::getPVDataCreate()->createPVUnion(unionPtr);
        boost::python::object pyObject = pyList[i];
        boost::python::extract<boost::python::tuple> extractTuple(pyObject);
        if (extractTuple.check()) {
            boost::python::tuple pyTuple = extractTuple();
            // Extract dictionary within tuple
            if (boost::python::len(pyTuple) != 1) {
                throw InvalidArgument("PV union tuple must have exactly one element.");
            }
            boost::python::object pyObject = pyTuple[0];
            boost::python::dict pyDict = PyUtility::extractValueFromPyObject<boost::python::dict>(pyObject);
            PyPvDataUtility::pyDictToUnion(pyDict, pvUnionPtr);
            data[i] = pvUnionPtr;
            continue;
        } 

        boost::python::extract<boost::python::dict> extractDict(pyObject);
        if (extractDict.check()) {
            boost::python::dict pyDict = extractDict();
            PyPvDataUtility::pyDictToUnion(pyDict, pvUnionPtr);
            data[i] = pvUnionPtr;
            continue;
        } 

        boost::python::extract<PvObject> extractPvObject(pyObject);
        if (extractPvObject.check()) {
            PvObject pvObject = extractPvObject();
            std::string keyFrom = PyPvDataUtility::getValueOrSingleFieldName(pvObject.getPvStructurePtr());
            epics::pvData::PVFieldPtr pvFrom = PyPvDataUtility::getSubField(keyFrom, pvObject.getPvStructurePtr());
            PyPvDataUtility::setUnionField(pvFrom, pvUnionPtr);
            data[i] = pvUnionPtr;
            continue;
        }

        throw InvalidArgument("Python object representing an union must be PvObject, tuple containing dictionary, or dictionary."); 
    } 

    pvUnionArrayPtr->replace(freeze(data));
}
Esempio n. 4
0
RpcClient::RpcClient(const std::string& channelName_, const PvObject& pvRequestObject) :
    PvaClient(),
    rpcClientInitialized(false),
    rpcClient(),
    channelName(channelName_)
{
    pvRequest = pvRequestObject.getPvStructurePtr();
}
Esempio n. 5
0
NtTable::NtTable(const PvObject& pvObject)
    : NtType(pvObject.getPvStructurePtr()),
    nColumns(0)
{
    PyPvDataUtility::checkFieldExists(LabelsFieldKey, pvStructurePtr);
    PyPvDataUtility::checkFieldExists(ValueFieldKey, pvStructurePtr);
    set(pvObject);
    epics::pvData::PVScalarArrayPtr pvScalarArrayPtr = PyPvDataUtility::getScalarArrayField(LabelsFieldKey, epics::pvData::pvString, pvStructurePtr);
    nColumns = pvScalarArrayPtr->getLength();
}