virtual void request(epics::pvData::PVStructure::shared_pointer const & pvArgument)
    {
        try
        {
            m_rpcService->request(pvArgument, shared_from_this());
        }
        catch (std::exception& ex)
        {
            // handle user unexpected errors
            Status errorStatus(Status::STATUSTYPE_FATAL, ex.what());

            m_channelRPCRequester->requestDone(errorStatus, shared_from_this(), PVStructure::shared_pointer());

            if (m_lastRequest.get())
                destroy();
        }
        catch (...)
        {
            // handle user unexpected errors
            Status errorStatus(Status::STATUSTYPE_FATAL,
                               "Unexpected exception caught while calling RPCServiceAsync.request(PVStructure, RPCResponseCallback).");

            m_channelRPCRequester->requestDone(errorStatus, shared_from_this(), PVStructure::shared_pointer());

            if (m_lastRequest.get())
                destroy();
        }

        // we wait for callback to be called
    }
void ChannelRPCLocal::processRequest(
    RPCServiceAsync::shared_pointer const & service,
    PVStructurePtr const & pvArgument)
{
    try
    {
        service->request(pvArgument, getPtrSelf());
    }
    catch (std::exception& ex)
    {
        // handle user unexpected errors
        Status errorStatus(Status::STATUSTYPE_FATAL, ex.what());
        ChannelRPCRequester::shared_pointer requester = channelRPCRequester.lock();
        if(requester) requester->requestDone(errorStatus, getPtrSelf(), PVStructurePtr());
        if (isLastRequest.get())
            destroy();
    }
    catch (...)
    {
        // handle user unexpected errors
        Status errorStatus(Status::STATUSTYPE_FATAL,
                           "Unexpected exception caught while calling RPCServiceAsync.request(PVStructure, RPCResponseCallback).");
        ChannelRPCRequester::shared_pointer requester = channelRPCRequester.lock();
        if(requester) requester->requestDone(errorStatus, shared_from_this(), PVStructurePtr());

        if (isLastRequest.get())
            destroy();
    }

    // we wait for callback to be called
}
ChannelRPCLocalPtr ChannelRPCLocal::create(
    ChannelLocalPtr const &channelLocal,
    ChannelRPCRequester::shared_pointer const & channelRPCRequester,
    PVStructurePtr const & pvRequest,
    PVRecordPtr const &pvRecord)
{
    Service::shared_pointer service = pvRecord->getService(pvRequest);
    if (!service)
    {
        Status status(Status::STATUSTYPE_ERROR,
            "ChannelRPC not supported");
            channelRPCRequester->channelRPCConnect(status,ChannelRPCLocalPtr());
        return ChannelRPCLocalPtr();
    }

    if (!channelRPCRequester)
        throw std::invalid_argument("channelRPCRequester == null");

    // TODO use std::make_shared
    ChannelRPCLocalPtr rpc(
        new ChannelRPCLocal(channelLocal, channelRPCRequester, service, pvRecord)
    );
    channelRPCRequester->channelRPCConnect(Status::Ok, rpc);
    if(pvRecord->getTraceLevel()>0)
    {
        cout << "ChannelRPCLocal::create";
        cout << " recordName " << pvRecord->getRecordName() << endl;
    }
    return rpc;
}
    virtual void requestDone(Status const & status,
        PVStructurePtr const & result)
    {
        ChannelRPCRequester::shared_pointer requester = channelRPCRequester.lock();
        if(!requester) return;
        requester->requestDone(status, getPtrSelf(), result);

        if (isLastRequest.get())
            destroy();
    }
Exemple #5
0
ChannelRPC::shared_pointer ChannelBase::createChannelRPC(
        ChannelRPCRequester::shared_pointer const & channelRPCRequester,
        PVStructure::shared_pointer const & pvRequest)
{
    Status status(Status::STATUSTYPE_ERROR,
        String("ChannelRPC not supported"));
    channelRPCRequester->channelRPCConnect(status,ChannelRPC::shared_pointer());
    return ChannelRPC::shared_pointer();
}
Exemple #6
0
ChannelRPC::shared_pointer CAChannel::createChannelRPC(
        ChannelRPCRequester::shared_pointer const & channelRPCRequester,
        epics::pvData::PVStructure::shared_pointer const & /*pvRequest*/)
{
    Status errorStatus(Status::STATUSTYPE_ERROR, "not supported");
    ChannelRPC::shared_pointer nullChannelRPC;
    EXCEPTION_GUARD(channelRPCRequester->channelRPCConnect(errorStatus, nullChannelRPC));
    return nullChannelRPC;
}
epics::pvAccess::ChannelRPC::shared_pointer ChannelImpl::createChannelRPC(
    ChannelRPCRequester::shared_pointer const &channelRPCRequester,
    PVStructure::shared_pointer const &pvRequest)
{
    ChannelRPC *channel = new ChannelRPCImpl(getPtrSelf(),channelRPCRequester,serviceRPC);
    ChannelRPC::shared_pointer channelRPC(channel);
    addChannelRPC(channelRPC);
    channelRPCRequester->channelRPCConnect(Status::Ok,channelRPC);
    return channelRPC;
}
    virtual void requestDone(
        epics::pvData::Status const & status,
        epics::pvData::PVStructure::shared_pointer const & result
    )
    {
        m_channelRPCRequester->requestDone(status, shared_from_this(), result);

        if (m_lastRequest.get())
            destroy();
    }
void ChannelRPCLocal::processRequest(
    RPCService::shared_pointer const & service,
    PVStructurePtr const & pvArgument)
{
    PVStructurePtr result;
    Status status = Status::Ok;
    bool ok = true;
    try
    {
        result = service->request(pvArgument);
    }
    catch (RPCRequestException& rre)
    {
        status = Status(rre.getStatus(), rre.what());
        ok = false;
    }
    catch (std::exception& ex)
    {
        status = Status(Status::STATUSTYPE_FATAL, ex.what());
        ok = false;
    }
    catch (...)
    {
        // handle user unexpected errors
        status = Status(Status::STATUSTYPE_FATAL, "Unexpected exception caught while calling RPCService.request(PVStructure).");
        ok = false;
    }
    
    // check null result
    if (ok && !result)
    {
        status = Status(Status::STATUSTYPE_FATAL, "RPCService.request(PVStructure) returned null.");
    }
    ChannelRPCRequester::shared_pointer requester = channelRPCRequester.lock();
    if(requester) requester->requestDone(status, getPtrSelf(), result);
        
    if (isLastRequest.get())
        destroy();
}
Exemple #10
0
    virtual ChannelRPC::shared_pointer createChannelRPC(
        ChannelRPCRequester::shared_pointer const & channelRPCRequester,
        epics::pvData::PVStructure::shared_pointer const & /*pvRequest*/)
    {
        // nothing expected to be in pvRequest

        if (channelRPCRequester.get() == 0)
            throw std::invalid_argument("channelRPCRequester == null");

        if (m_destroyed.get())
        {
            ChannelRPC::shared_pointer nullPtr;
            channelRPCRequester->channelRPCConnect(epics::pvData::Status(epics::pvData::Status::STATUSTYPE_ERROR, "channel destroyed"), nullPtr);
            return nullPtr;
        }

        // TODO use std::make_shared
        std::tr1::shared_ptr<ChannelRPCServiceImpl> tp(
            new ChannelRPCServiceImpl(shared_from_this(), channelRPCRequester, m_rpcService)
        );
        ChannelRPC::shared_pointer channelRPCImpl = tp;
        channelRPCRequester->channelRPCConnect(Status::Ok, channelRPCImpl);
        return channelRPCImpl;
    }
void ChannelRPCImpl::message(String message,MessageType messageType)
{
    channelRPCRequester->message(message,messageType);
}
String ChannelRPCImpl::getRequesterName() 
{
    return channelRPCRequester->getRequesterName();
}
Exemple #13
0
void ExampleServiceRPC::request(
    ChannelRPCRequester::shared_pointer const & channelRPCRequester,
    epics::pvData::PVStructure::shared_pointer const & pvArgument)
{
    String buffer;
    PVStringPtr pvfunction = pvArgument->getStringField("function");
    PVStringArrayPtr pvnames = static_pointer_cast<PVStringArray>
        (pvArgument->getScalarArrayField("names",pvString));
    PVStringArrayPtr pvvalues = static_pointer_cast<PVStringArray>
        (pvArgument->getScalarArrayField("values",pvString));
    buffer += "pvArgument ";
    bool is = true;
    if(pvfunction==0) is = false;
    if(pvnames==0) is = false;
    if(pvvalues==0) is = false;
    if(is) {
        buffer += "is a NTNameValue\n";
    } else {
        buffer += "is not a NTNameValue\n ";
    }
    pvArgument->toString(&buffer);
    printf("%s\n",buffer.c_str());
    StandardFieldPtr standardField = getStandardField();
    StandardPVFieldPtr standardPVField = getStandardPVField();
    FieldCreatePtr  fieldCreate = getFieldCreate();
    PVDataCreatePtr  pvDataCreate = getPVDataCreate();
    size_t n = 5;
    FieldConstPtrArray fields;
    StringArray names;
    fields.reserve(n);
    names.reserve(n);
    names.push_back("alarm");
    names.push_back("timeStamp");
    names.push_back("label");
    names.push_back("position");
    names.push_back("alarms");
StructureConstPtr xxx = standardField->alarm();
printf("xxx %p\n",xxx.get());
    fields.push_back(standardField->alarm());
    fields.push_back(standardField->timeStamp());
    fields.push_back(fieldCreate->createScalarArray(pvString));
    fields.push_back(fieldCreate->createScalarArray(pvDouble));
    fields.push_back(fieldCreate->createStructureArray(standardField->alarm()));
    StructureConstPtr structure = fieldCreate->createStructure(names,fields);
printf("structure %p\n",structure.get());
buffer.clear();
structure->toString(&buffer);
printf("structure\n%s\n",buffer.c_str());
    PVStructurePtr pvStructure = pvDataCreate->createPVStructure(structure);
    PVTimeStamp pvTimeStamp;
    TimeStamp timeStamp;
    pvTimeStamp.attach(pvStructure->getStructureField("timeStamp"));
    timeStamp.getCurrent();
    pvTimeStamp.set(timeStamp);
    StringArray label;
    label.reserve(2);
    for(int i=0; i<2; i++) {
        label.push_back(names[i+3]);
    }
    PVStringArrayPtr pvLabel = static_pointer_cast<PVStringArray>
        (pvStructure->getScalarArrayField("label",pvString));
    pvLabel->put(0,2,label,0);
    PVDoubleArrayPtr pvPositions = static_pointer_cast<PVDoubleArray>
        (pvStructure->getScalarArrayField("position",pvDouble));
    double positions[2];
    positions[0] = 1.0;
    positions[1] = 2.0;
    pvPositions->put(0,2,positions,0);
    PVStructureArrayPtr pvAlarms = static_pointer_cast<PVStructureArray>
        (pvStructure->getStructureArrayField("alarms"));
    PVAlarm pvAlarm;
    Alarm alarm;
    PVStructurePtrArray palarms;
    size_t na=2;
    palarms.reserve(na);
    for(size_t i=0; i<na; i++) {
        palarms.push_back(pvDataCreate->createPVStructure(standardField->alarm()));
    }
    for(size_t i=0; i<na; i++) {
        pvAlarm.attach(palarms[i]);
        alarm.setMessage("test");
        alarm.setSeverity(majorAlarm);
        alarm.setStatus(clientStatus);
        pvAlarm.set(alarm);
    }
    pvAlarms->put(0,2,palarms,0);
    String labels[2];
    labels[0] = pvPositions->getFieldName();
    labels[1] = pvAlarms->getFieldName();
    pvLabel->put(0,2,labels,0);
    buffer.erase();
    pvStructure->toString(&buffer);
    printf("%s\n",buffer.c_str());
    channelRPCRequester->requestDone(Status::Ok,pvStructure);
}