rename easyPVACPP to pvaClientCPP; this means repository and all names;
This commit is contained in:
230
src/pvaClientGet.cpp
Normal file
230
src/pvaClientGet.cpp
Normal file
@@ -0,0 +1,230 @@
|
||||
/* pvaClientGet.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
*/
|
||||
/**
|
||||
* @author mrk
|
||||
* @date 2015.02
|
||||
*/
|
||||
#define epicsExportSharedSymbols
|
||||
|
||||
#include <sstream>
|
||||
#include <pv/event.h>
|
||||
#include <pv/pvaClient.h>
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvaClient {
|
||||
|
||||
|
||||
class ChannelGetRequesterImpl : public ChannelGetRequester
|
||||
{
|
||||
PvaClientGet * pvaClientGet;
|
||||
public:
|
||||
ChannelGetRequesterImpl(PvaClientGet * pvaClientGet)
|
||||
: pvaClientGet(pvaClientGet) {}
|
||||
string getRequesterName()
|
||||
{return pvaClientGet->getRequesterName();}
|
||||
void message(string const & message,MessageType messageType)
|
||||
{pvaClientGet->message(message,messageType);}
|
||||
void channelGetConnect(
|
||||
const Status& status,
|
||||
ChannelGet::shared_pointer const & channelGet,
|
||||
StructureConstPtr const & structure)
|
||||
{pvaClientGet->channelGetConnect(status,channelGet,structure);}
|
||||
void getDone(
|
||||
const Status& status,
|
||||
ChannelGet::shared_pointer const & channelGet,
|
||||
PVStructurePtr const & pvStructure,
|
||||
BitSetPtr const & bitSet)
|
||||
{pvaClientGet->getDone(status,channelGet,pvStructure,bitSet);}
|
||||
};
|
||||
|
||||
PvaClientGet::PvaClientGet(
|
||||
PvaClientPtr const &pvaClient,
|
||||
PvaClientChannelPtr const & pvaClientChannel,
|
||||
Channel::shared_pointer const & channel,
|
||||
PVStructurePtr const &pvRequest)
|
||||
: pvaClient(pvaClient),
|
||||
pvaClientChannel(pvaClientChannel),
|
||||
channel(channel),
|
||||
pvRequest(pvRequest),
|
||||
isDestroyed(false),
|
||||
connectState(connectIdle),
|
||||
getState(getIdle)
|
||||
{
|
||||
}
|
||||
|
||||
PvaClientGet::~PvaClientGet()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
void PvaClientGet::checkGetState()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
|
||||
if(connectState==connectIdle) connect();
|
||||
if(getState==getIdle) get();
|
||||
}
|
||||
|
||||
// from ChannelGetRequester
|
||||
string PvaClientGet::getRequesterName()
|
||||
{
|
||||
PvaClientPtr yyy = pvaClient.lock();
|
||||
if(!yyy) throw std::runtime_error("pvaClient was destroyed");
|
||||
return yyy->getRequesterName();
|
||||
}
|
||||
|
||||
void PvaClientGet::message(string const & message,MessageType messageType)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
|
||||
PvaClientPtr yyy = pvaClient.lock();
|
||||
if(!yyy) throw std::runtime_error("pvaClient was destroyed");
|
||||
yyy->message(message, messageType);
|
||||
}
|
||||
|
||||
void PvaClientGet::channelGetConnect(
|
||||
const Status& status,
|
||||
ChannelGet::shared_pointer const & channelGet,
|
||||
StructureConstPtr const & structure)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
|
||||
channelGetConnectStatus = status;
|
||||
this->channelGet = channelGet;
|
||||
if(status.isOK()) {
|
||||
pvaClientData = PvaClientGetData::create(structure);
|
||||
pvaClientData->setMessagePrefix(channel->getChannelName());
|
||||
}
|
||||
waitForConnect.signal();
|
||||
|
||||
}
|
||||
|
||||
void PvaClientGet::getDone(
|
||||
const Status& status,
|
||||
ChannelGet::shared_pointer const & channelGet,
|
||||
PVStructurePtr const & pvStructure,
|
||||
BitSetPtr const & bitSet)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
|
||||
channelGetStatus = status;
|
||||
if(status.isOK()) {
|
||||
pvaClientData->setData(pvStructure,bitSet);
|
||||
}
|
||||
waitForGet.signal();
|
||||
}
|
||||
|
||||
|
||||
// from PvaClientGet
|
||||
void PvaClientGet::destroy()
|
||||
{
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) return;
|
||||
isDestroyed = true;
|
||||
}
|
||||
if(channelGet) channelGet->destroy();
|
||||
channelGet.reset();
|
||||
}
|
||||
|
||||
void PvaClientGet::connect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
|
||||
issueConnect();
|
||||
Status status = waitConnect();
|
||||
if(status.isOK()) return;
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientGet::connect " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void PvaClientGet::issueConnect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
|
||||
if(connectState!=connectIdle) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " pvaClientGet already connected ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
getRequester = ChannelGetRequester::shared_pointer(new ChannelGetRequesterImpl(this));
|
||||
connectState = connectActive;
|
||||
channelGet = channel->createChannelGet(getRequester,pvRequest);
|
||||
}
|
||||
|
||||
Status PvaClientGet::waitConnect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
|
||||
if(connectState!=connectActive) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " pvaClientGet illegal connect state ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
waitForConnect.wait();
|
||||
if(channelGetConnectStatus.isOK()){
|
||||
connectState = connected;
|
||||
return Status::Ok;
|
||||
}
|
||||
connectState = connectIdle;
|
||||
return Status(Status::STATUSTYPE_ERROR,channelGetConnectStatus.getMessage());
|
||||
}
|
||||
|
||||
void PvaClientGet::get()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
|
||||
issueGet();
|
||||
Status status = waitGet();
|
||||
if(status.isOK()) return;
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientGet::get " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void PvaClientGet::issueGet()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
|
||||
if(connectState==connectIdle) connect();
|
||||
if(getState!=getIdle) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientGet::issueGet get aleady active ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
getState = getActive;
|
||||
channelGet->get();
|
||||
}
|
||||
|
||||
Status PvaClientGet::waitGet()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
|
||||
if(getState!=getActive){
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientGet::waitGet llegal get state";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
waitForGet.wait();
|
||||
getState = getIdle;
|
||||
if(channelGetStatus.isOK()) {
|
||||
return Status::Ok;
|
||||
}
|
||||
return Status(Status::STATUSTYPE_ERROR,channelGetStatus.getMessage());
|
||||
}
|
||||
PvaClientGetDataPtr PvaClientGet::getData()
|
||||
{
|
||||
checkGetState();
|
||||
return pvaClientData;
|
||||
}
|
||||
|
||||
PvaClientGetPtr PvaClientGet::create(
|
||||
PvaClientPtr const &pvaClient,
|
||||
PvaClientChannelPtr const & pvaClientChannel,
|
||||
Channel::shared_pointer const & channel,
|
||||
PVStructurePtr const &pvRequest)
|
||||
{
|
||||
PvaClientGetPtr epv(new PvaClientGet(pvaClient,pvaClientChannel,channel,pvRequest));
|
||||
return epv;
|
||||
}
|
||||
|
||||
}}
|
||||
Reference in New Issue
Block a user