rename easyPVACPP to pvaClientCPP; this means repository and all names;
This commit is contained in:
292
src/pvaClientPut.cpp
Normal file
292
src/pvaClientPut.cpp
Normal file
@@ -0,0 +1,292 @@
|
||||
/* pvaClientPut.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 ChannelPutRequesterImpl : public ChannelPutRequester
|
||||
{
|
||||
PvaClientPut * pvaClientPut;
|
||||
public:
|
||||
ChannelPutRequesterImpl(PvaClientPut * pvaClientPut)
|
||||
: pvaClientPut(pvaClientPut) {}
|
||||
string getRequesterName()
|
||||
{return pvaClientPut->getRequesterName();}
|
||||
void message(string const & message,MessageType messageType)
|
||||
{pvaClientPut->message(message,messageType);}
|
||||
void channelPutConnect(
|
||||
const Status& status,
|
||||
ChannelPut::shared_pointer const & channelPut,
|
||||
StructureConstPtr const & structure)
|
||||
{pvaClientPut->channelPutConnect(status,channelPut,structure);}
|
||||
void getDone(
|
||||
const Status& status,
|
||||
ChannelPut::shared_pointer const & channelPut,
|
||||
PVStructurePtr const & pvStructure,
|
||||
BitSetPtr const & bitSet)
|
||||
{pvaClientPut->getDone(status,channelPut,pvStructure,bitSet);}
|
||||
void putDone(
|
||||
const Status& status,
|
||||
ChannelPut::shared_pointer const & channelPut)
|
||||
{pvaClientPut->putDone(status,channelPut);}
|
||||
};
|
||||
|
||||
PvaClientPut::PvaClientPut(
|
||||
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),
|
||||
putState(putIdle)
|
||||
{
|
||||
}
|
||||
|
||||
PvaClientPut::~PvaClientPut()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
void PvaClientPut::checkPutState()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
if(connectState==connectIdle){
|
||||
connect();
|
||||
get();
|
||||
}
|
||||
}
|
||||
|
||||
// from ChannelPutRequester
|
||||
string PvaClientPut::getRequesterName()
|
||||
{
|
||||
PvaClientPtr yyy = pvaClient.lock();
|
||||
if(!yyy) throw std::runtime_error("pvaClient was destroyed");
|
||||
return yyy->getRequesterName();
|
||||
}
|
||||
|
||||
void PvaClientPut::message(string const & message,MessageType messageType)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
PvaClientPtr yyy = pvaClient.lock();
|
||||
if(!yyy) throw std::runtime_error("pvaClient was destroyed");
|
||||
yyy->message(message, messageType);
|
||||
}
|
||||
|
||||
void PvaClientPut::channelPutConnect(
|
||||
const Status& status,
|
||||
ChannelPut::shared_pointer const & channelPut,
|
||||
StructureConstPtr const & structure)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
channelPutConnectStatus = status;
|
||||
this->channelPut = channelPut;
|
||||
if(status.isOK()) {
|
||||
pvaClientData = PvaClientPutData::create(structure);
|
||||
pvaClientData->setMessagePrefix(pvaClientChannel.lock()->getChannelName());
|
||||
}
|
||||
waitForConnect.signal();
|
||||
|
||||
}
|
||||
|
||||
void PvaClientPut::getDone(
|
||||
const Status& status,
|
||||
ChannelPut::shared_pointer const & channelPut,
|
||||
PVStructurePtr const & pvStructure,
|
||||
BitSetPtr const & bitSet)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
channelGetPutStatus = status;
|
||||
if(status.isOK()) {
|
||||
PVStructurePtr pvs = pvaClientData->getPVStructure();
|
||||
pvs->copyUnchecked(*pvStructure,*bitSet);
|
||||
BitSetPtr bs = pvaClientData->getBitSet();
|
||||
bs->clear();
|
||||
*bs |= *bitSet;
|
||||
}
|
||||
waitForGetPut.signal();
|
||||
}
|
||||
|
||||
void PvaClientPut::putDone(
|
||||
const Status& status,
|
||||
ChannelPut::shared_pointer const & channelPut)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
channelGetPutStatus = status;
|
||||
waitForGetPut.signal();
|
||||
}
|
||||
|
||||
|
||||
// from PvaClientPut
|
||||
void PvaClientPut::destroy()
|
||||
{
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) return;
|
||||
isDestroyed = true;
|
||||
}
|
||||
if(channelPut) channelPut->destroy();
|
||||
channelPut.reset();
|
||||
}
|
||||
|
||||
void PvaClientPut::connect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
issueConnect();
|
||||
Status status = waitConnect();
|
||||
if(status.isOK()) return;
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPut::connect " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void PvaClientPut::issueConnect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
if(connectState!=connectIdle) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " pvaClientPut already connected ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
putRequester = ChannelPutRequester::shared_pointer(new ChannelPutRequesterImpl(this));
|
||||
connectState = connectActive;
|
||||
channelPut = channel->createChannelPut(putRequester,pvRequest);
|
||||
}
|
||||
|
||||
Status PvaClientPut::waitConnect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
if(connectState!=connectActive) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " pvaClientPut illegal connect state ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
waitForConnect.wait();
|
||||
if(channelPutConnectStatus.isOK()) {
|
||||
connectState = connected;
|
||||
return Status::Ok;
|
||||
}
|
||||
connectState = connectIdle;
|
||||
return Status(Status::STATUSTYPE_ERROR,channelPutConnectStatus.getMessage());
|
||||
}
|
||||
|
||||
void PvaClientPut::get()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
issueGet();
|
||||
Status status = waitGet();
|
||||
if(status.isOK()) return;
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPut::get " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void PvaClientPut::issueGet()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
if(connectState==connectIdle) connect();
|
||||
if(putState!=putIdle) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPut::issueGet get or put aleady active ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
putState = getActive;
|
||||
pvaClientData->getBitSet()->clear();
|
||||
channelPut->get();
|
||||
}
|
||||
|
||||
Status PvaClientPut::waitGet()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
if(putState!=getActive){
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPut::waitGet llegal put state";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
waitForGetPut.wait();
|
||||
putState = putIdle;
|
||||
if(channelGetPutStatus.isOK()) {
|
||||
return Status::Ok;
|
||||
}
|
||||
return Status(Status::STATUSTYPE_ERROR,channelGetPutStatus.getMessage());
|
||||
}
|
||||
|
||||
void PvaClientPut::put()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
issuePut();
|
||||
Status status = waitPut();
|
||||
if(status.isOK()) return;
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPut::put " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void PvaClientPut::issuePut()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
if(connectState==connectIdle) connect();
|
||||
if(putState!=putIdle) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPut::issueGet get or put aleady active ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
putState = putActive;
|
||||
channelPut->put(pvaClientData->getPVStructure(),pvaClientData->getBitSet());
|
||||
}
|
||||
|
||||
Status PvaClientPut::waitPut()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
if(putState!=putActive){
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPut::waitPut llegal put state";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
waitForGetPut.wait();
|
||||
putState = putIdle;
|
||||
if(channelGetPutStatus.isOK()) {
|
||||
pvaClientData->getBitSet()->clear();
|
||||
return Status::Ok;
|
||||
}
|
||||
return Status(Status::STATUSTYPE_ERROR,channelGetPutStatus.getMessage());
|
||||
}
|
||||
|
||||
PvaClientPutDataPtr PvaClientPut::getData()
|
||||
{
|
||||
checkPutState();
|
||||
return pvaClientData;
|
||||
}
|
||||
|
||||
PvaClientPutPtr PvaClientPut::create(
|
||||
PvaClientPtr const &pvaClient,
|
||||
PvaClientChannelPtr const & pvaClientChannel,
|
||||
Channel::shared_pointer const & channel,
|
||||
PVStructurePtr const &pvRequest)
|
||||
{
|
||||
PvaClientPutPtr epv(new PvaClientPut(pvaClient,pvaClientChannel,channel,pvRequest));
|
||||
return epv;
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
Reference in New Issue
Block a user