rename easyPVACPP to pvaClientCPP; this means repository and all names;
This commit is contained in:
+19
-20
@@ -3,29 +3,28 @@
|
||||
TOP = ..
|
||||
include $(TOP)/configure/CONFIG
|
||||
|
||||
LIBRARY += easyPVA
|
||||
LIBRARY += pvaClient
|
||||
|
||||
INC += easyPVA.h
|
||||
INC += easyMultiDouble.h
|
||||
INC += easyNTMultiChannel.h
|
||||
INC += pvaClient.h
|
||||
INC += pvaClientMultiDouble.h
|
||||
INC += pvaClientNTMultiChannel.h
|
||||
|
||||
LIBSRCS += easyPVA.cpp
|
||||
LIBSRCS += easyPutData.cpp
|
||||
LIBSRCS += easyGetData.cpp
|
||||
LIBSRCS += easyMonitorData.cpp
|
||||
LIBSRCS += easyChannel.cpp
|
||||
LIBSRCS += easyProcess.cpp
|
||||
LIBSRCS += easyGet.cpp
|
||||
LIBSRCS += easyPut.cpp
|
||||
LIBSRCS += easyMonitor.cpp
|
||||
LIBSRCS += easyPutGet.cpp
|
||||
LIBSRCS += easyMultiChannel.cpp
|
||||
LIBSRCS += easyMultiDouble.cpp
|
||||
LIBSRCS += easyNTMultiChannel.cpp
|
||||
#LIBSRCS += easyRPC.cpp
|
||||
LIBSRCS += pvaClient.cpp
|
||||
LIBSRCS += pvaClientPutData.cpp
|
||||
LIBSRCS += pvaClientGetData.cpp
|
||||
LIBSRCS += pvaClientMonitorData.cpp
|
||||
LIBSRCS += pvaClientChannel.cpp
|
||||
LIBSRCS += pvaClientProcess.cpp
|
||||
LIBSRCS += pvaClientGet.cpp
|
||||
LIBSRCS += pvaClientPut.cpp
|
||||
LIBSRCS += pvaClientMonitor.cpp
|
||||
LIBSRCS += pvaClientPutGet.cpp
|
||||
LIBSRCS += pvaClientMultiChannel.cpp
|
||||
LIBSRCS += pvaClientMultiDouble.cpp
|
||||
LIBSRCS += pvaClientNTMultiChannel.cpp
|
||||
|
||||
easyPVA_LIBS += pvAccess pvData nt Com
|
||||
easyPVA_LIBS += $(EPICS_BASE_IOC_LIBS)
|
||||
pvaClient_LIBS += pvAccess pvData nt Com
|
||||
pvaClient_LIBS += $(EPICS_BASE_IOC_LIBS)
|
||||
|
||||
include $(TOP)/configure/RULES
|
||||
|
||||
|
||||
@@ -1,495 +0,0 @@
|
||||
/* easyChannel.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 <map>
|
||||
#include <sstream>
|
||||
#include <pv/event.h>
|
||||
#include <pv/lock.h>
|
||||
#include <pv/easyPVA.h>
|
||||
#include <pv/createRequest.h>
|
||||
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace easyPVA {
|
||||
|
||||
|
||||
class EasyGetCache
|
||||
{
|
||||
public:
|
||||
EasyGetCache(){}
|
||||
~EasyGetCache();
|
||||
void destroy() {
|
||||
easyGetMap.clear();
|
||||
}
|
||||
EasyGetPtr getGet(string const & request);
|
||||
void addGet(string const & request,EasyGetPtr const & easyGet);
|
||||
private:
|
||||
map<string,EasyGetPtr> easyGetMap;
|
||||
};
|
||||
|
||||
EasyGetCache::~EasyGetCache()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
EasyGetPtr EasyGetCache::getGet(string const & request)
|
||||
{
|
||||
map<string,EasyGetPtr>::iterator iter = easyGetMap.find(request);
|
||||
if(iter!=easyGetMap.end()) return iter->second;
|
||||
return EasyGetPtr();
|
||||
}
|
||||
|
||||
void EasyGetCache::addGet(string const & request,EasyGetPtr const & easyGet)
|
||||
{
|
||||
easyGetMap.insert(std::pair<string,EasyGetPtr>(
|
||||
request,easyGet));
|
||||
}
|
||||
|
||||
|
||||
class EasyPutCache
|
||||
{
|
||||
public:
|
||||
EasyPutCache(){}
|
||||
~EasyPutCache();
|
||||
void destroy() {
|
||||
easyPutMap.clear();
|
||||
}
|
||||
EasyPutPtr getPut(string const & request);
|
||||
void addPut(string const & request,EasyPutPtr const & easyPut);
|
||||
private:
|
||||
map<string,EasyPutPtr> easyPutMap;
|
||||
};
|
||||
|
||||
EasyPutCache::~EasyPutCache()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
EasyPutPtr EasyPutCache::getPut(string const & request)
|
||||
{
|
||||
map<string,EasyPutPtr>::iterator iter = easyPutMap.find(request);
|
||||
if(iter!=easyPutMap.end()) return iter->second;
|
||||
return EasyPutPtr();
|
||||
}
|
||||
|
||||
void EasyPutCache::addPut(string const & request,EasyPutPtr const & easyPut)
|
||||
{
|
||||
easyPutMap.insert(std::pair<string,EasyPutPtr>(
|
||||
request,easyPut));
|
||||
}
|
||||
|
||||
class ChannelRequesterImpl : public ChannelRequester
|
||||
{
|
||||
EasyChannel *easyChannel;
|
||||
public:
|
||||
ChannelRequesterImpl(EasyChannel *easyChannel)
|
||||
: easyChannel(easyChannel) {}
|
||||
void channelCreated(
|
||||
const Status& status,
|
||||
Channel::shared_pointer const & channel)
|
||||
{ easyChannel->channelCreated(status,channel); }
|
||||
void channelStateChange(
|
||||
Channel::shared_pointer const & channel,
|
||||
Channel::ConnectionState connectionState)
|
||||
{easyChannel->channelStateChange(channel,connectionState);}
|
||||
tr1::shared_ptr<Channel> getChannel() {return easyChannel->getChannel();}
|
||||
string getRequesterName()
|
||||
{return easyChannel->getRequesterName();}
|
||||
void message(
|
||||
string const & message,
|
||||
MessageType messageType)
|
||||
{ easyChannel->message(message,messageType); }
|
||||
void destroy() {easyChannel->destroy();}
|
||||
};
|
||||
|
||||
|
||||
EasyChannel::EasyChannel(
|
||||
EasyPVAPtr const &easyPVA,
|
||||
string const & channelName,
|
||||
string const & providerName)
|
||||
: easyPVA(easyPVA),
|
||||
channelName(channelName),
|
||||
providerName(providerName),
|
||||
connectState(connectIdle),
|
||||
isDestroyed(false),
|
||||
createRequest(CreateRequest::create()),
|
||||
easyGetCache(new EasyGetCache()),
|
||||
easyPutCache(new EasyPutCache())
|
||||
{}
|
||||
|
||||
EasyChannel::~EasyChannel()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
void EasyChannel::channelCreated(const Status& status, Channel::shared_pointer const & channel)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyChannel was destroyed");
|
||||
if(status.isOK()) {
|
||||
this->channel = channel;
|
||||
return;
|
||||
}
|
||||
cout << "EasyChannel::channelCreated status " << status.getMessage() << " why??\n";
|
||||
}
|
||||
|
||||
void EasyChannel::channelStateChange(
|
||||
Channel::shared_pointer const & channel,
|
||||
Channel::ConnectionState connectionState)
|
||||
{
|
||||
if(isDestroyed) return;
|
||||
bool waitingForConnect = false;
|
||||
if(connectState==connectActive) waitingForConnect = true;
|
||||
if(connectionState!=Channel::CONNECTED) {
|
||||
string mess(channelName +
|
||||
" connection state " + Channel::ConnectionStateNames[connectionState]);
|
||||
message(mess,errorMessage);
|
||||
channelConnectStatus = Status(Status::STATUSTYPE_ERROR,mess);
|
||||
connectState = notConnected;
|
||||
} else {
|
||||
connectState = connected;
|
||||
}
|
||||
if(waitingForConnect) waitForConnect.signal();
|
||||
}
|
||||
|
||||
string EasyChannel::getRequesterName()
|
||||
{
|
||||
EasyPVAPtr yyy = easyPVA.lock();
|
||||
if(!yyy) throw std::runtime_error("EasyPVA was destroyed");
|
||||
return yyy->getRequesterName();
|
||||
}
|
||||
|
||||
void EasyChannel::message(
|
||||
string const & message,
|
||||
MessageType messageType)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyChannel was destroyed");
|
||||
EasyPVAPtr yyy = easyPVA.lock();
|
||||
if(!yyy) throw std::runtime_error("EasyPVA was destroyed");
|
||||
yyy->message(message, messageType);
|
||||
}
|
||||
|
||||
void EasyChannel::destroy()
|
||||
{
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) return;
|
||||
isDestroyed = true;
|
||||
}
|
||||
if(channel) channel->destroy();
|
||||
channel.reset();
|
||||
easyGetCache.reset();
|
||||
easyPutCache.reset();
|
||||
}
|
||||
|
||||
string EasyChannel::getChannelName()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyChannel was destroyed");
|
||||
return channelName;
|
||||
}
|
||||
|
||||
Channel::shared_pointer EasyChannel::getChannel()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyChannel was destroyed");
|
||||
return channel;
|
||||
}
|
||||
|
||||
void EasyChannel::connect(double timeout)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyChannel was destroyed");
|
||||
issueConnect();
|
||||
Status status = waitConnect(timeout);
|
||||
if(status.isOK()) return;
|
||||
stringstream ss;
|
||||
ss << "channel " << getChannelName() << " EasyChannel::connect " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void EasyChannel::issueConnect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyChannel was destroyed");
|
||||
if(connectState!=connectIdle) {
|
||||
throw std::runtime_error("easyChannel already connected");
|
||||
}
|
||||
channelRequester = ChannelRequester::shared_pointer(new ChannelRequesterImpl(this));
|
||||
|
||||
channelConnectStatus = Status(
|
||||
Status::STATUSTYPE_ERROR,
|
||||
getChannelName() + " createChannel failed");
|
||||
connectState = connectActive;
|
||||
ChannelProviderRegistry::shared_pointer reg = getChannelProviderRegistry();
|
||||
ChannelProvider::shared_pointer provider = reg->getProvider(providerName);
|
||||
if(!provider) {
|
||||
throw std::runtime_error(getChannelName() + " provider " + providerName + " not registered");
|
||||
}
|
||||
channel = provider->createChannel(channelName,channelRequester,ChannelProvider::PRIORITY_DEFAULT);
|
||||
if(!channel) {
|
||||
throw std::runtime_error(channelConnectStatus.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
Status EasyChannel::waitConnect(double timeout)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyChannel was destroyed");
|
||||
waitForConnect.wait(timeout);
|
||||
if(connectState==connected) return Status::Ok;
|
||||
return Status(Status::STATUSTYPE_ERROR,channelConnectStatus.getMessage());
|
||||
}
|
||||
|
||||
EasyFieldPtr EasyChannel::createField()
|
||||
{
|
||||
return createField("");
|
||||
}
|
||||
|
||||
EasyFieldPtr EasyChannel::createField(string const & subField)
|
||||
{
|
||||
throw std::runtime_error("EasyChannel::createField not implemented");
|
||||
}
|
||||
|
||||
EasyProcessPtr EasyChannel::createProcess()
|
||||
{
|
||||
return createProcess("");
|
||||
}
|
||||
|
||||
EasyProcessPtr EasyChannel::createProcess(string const & request)
|
||||
{
|
||||
PVStructurePtr pvRequest = createRequest->createRequest(request);
|
||||
if(!pvRequest) {
|
||||
stringstream ss;
|
||||
ss << "channel " << getChannelName();
|
||||
ss << " EasyChannel::createProcess invalid pvRequest: " + createRequest->getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
return createProcess(pvRequest);
|
||||
}
|
||||
|
||||
EasyProcessPtr EasyChannel::createProcess(PVStructurePtr const & pvRequest)
|
||||
{
|
||||
if(connectState!=connected) connect(5.0);
|
||||
if(connectState!=connected) throw std::runtime_error("EasyChannel::creatProcess not connected");
|
||||
EasyPVAPtr yyy = easyPVA.lock();
|
||||
if(!yyy) throw std::runtime_error("EasyPVA was destroyed");
|
||||
return EasyProcess::create(yyy,getPtrSelf(),channel,pvRequest);
|
||||
}
|
||||
|
||||
EasyGetPtr EasyChannel::get() {return get("value,alarm,timeStamp");}
|
||||
|
||||
EasyGetPtr EasyChannel::get(string const & request)
|
||||
{
|
||||
EasyGetPtr easyGet = easyGetCache->getGet(request);
|
||||
if(easyGet) return easyGet;
|
||||
easyGet = createGet(request);
|
||||
easyGet->connect();
|
||||
easyGetCache->addGet(request,easyGet);
|
||||
return easyGet;
|
||||
}
|
||||
|
||||
EasyGetPtr EasyChannel::createGet()
|
||||
{
|
||||
return EasyChannel::createGet("value,alarm,timeStamp");
|
||||
}
|
||||
|
||||
EasyGetPtr EasyChannel::createGet(string const & request)
|
||||
{
|
||||
PVStructurePtr pvRequest = createRequest->createRequest(request);
|
||||
if(!pvRequest) {
|
||||
stringstream ss;
|
||||
ss << "channel " << getChannelName();
|
||||
ss << " EasyChannel::createGet invalid pvRequest: " + createRequest->getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
return createGet(pvRequest);
|
||||
}
|
||||
|
||||
EasyGetPtr EasyChannel::createGet(PVStructurePtr const & pvRequest)
|
||||
{
|
||||
if(connectState!=connected) connect(5.0);
|
||||
if(connectState!=connected) throw std::runtime_error("EasyChannel::creatGet not connected");
|
||||
EasyPVAPtr yyy = easyPVA.lock();
|
||||
if(!yyy) throw std::runtime_error("EasyPVA was destroyed");
|
||||
return EasyGet::create(yyy,getPtrSelf(),channel,pvRequest);
|
||||
}
|
||||
|
||||
EasyPutPtr EasyChannel::put() {return put("value");}
|
||||
|
||||
EasyPutPtr EasyChannel::put(string const & request)
|
||||
{
|
||||
EasyPutPtr easyPut = easyPutCache->getPut(request);
|
||||
if(easyPut) return easyPut;
|
||||
easyPut = createPut(request);
|
||||
easyPut->connect();
|
||||
easyPut->get();
|
||||
easyPutCache->addPut(request,easyPut);
|
||||
return easyPut;
|
||||
}
|
||||
|
||||
EasyPutPtr EasyChannel::createPut()
|
||||
{
|
||||
return createPut("value");
|
||||
}
|
||||
|
||||
EasyPutPtr EasyChannel::createPut(string const & request)
|
||||
{
|
||||
PVStructurePtr pvRequest = createRequest->createRequest(request);
|
||||
if(!pvRequest) {
|
||||
stringstream ss;
|
||||
ss << "channel " << getChannelName();
|
||||
ss << " EasyChannel::createPut invalid pvRequest: " + createRequest->getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
return createPut(pvRequest);
|
||||
}
|
||||
|
||||
EasyPutPtr EasyChannel::createPut(PVStructurePtr const & pvRequest)
|
||||
{
|
||||
if(connectState!=connected) connect(5.0);
|
||||
if(connectState!=connected) throw std::runtime_error("EasyChannel::creatPut not connected");
|
||||
EasyPVAPtr yyy = easyPVA.lock();
|
||||
if(!yyy) throw std::runtime_error("EasyPVA was destroyed");
|
||||
return EasyPut::create(yyy,getPtrSelf(),channel,pvRequest);
|
||||
}
|
||||
|
||||
EasyPutGetPtr EasyChannel::createPutGet()
|
||||
{
|
||||
return createPutGet("putField(argument)getField(result)");
|
||||
}
|
||||
|
||||
EasyPutGetPtr EasyChannel::createPutGet(string const & request)
|
||||
{
|
||||
PVStructurePtr pvRequest = createRequest->createRequest(request);
|
||||
if(!pvRequest) {
|
||||
stringstream ss;
|
||||
ss << "channel " << getChannelName();
|
||||
ss << " EasyChannel::createPutGet invalid pvRequest: " + createRequest->getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
return createPutGet(pvRequest);
|
||||
}
|
||||
|
||||
EasyPutGetPtr EasyChannel::createPutGet(PVStructurePtr const & pvRequest)
|
||||
{
|
||||
if(connectState!=connected) connect(5.0);
|
||||
if(connectState!=connected) throw std::runtime_error("EasyChannel::creatPutGet not connected");
|
||||
EasyPVAPtr yyy = easyPVA.lock();
|
||||
if(!yyy) throw std::runtime_error("EasyPVA was destroyed");
|
||||
return EasyPutGet::create(yyy,getPtrSelf(),channel,pvRequest);
|
||||
}
|
||||
|
||||
EasyRPCPtr EasyChannel::createRPC()
|
||||
{
|
||||
return createRPC("");
|
||||
}
|
||||
|
||||
EasyRPCPtr EasyChannel::createRPC(string const & request)
|
||||
{
|
||||
PVStructurePtr pvRequest = createRequest->createRequest(request);
|
||||
if(!pvRequest) {
|
||||
stringstream ss;
|
||||
ss << "channel " << getChannelName();
|
||||
ss << " EasyChannel::createRPC invalid pvRequest: " + createRequest->getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
return createRPC(pvRequest);
|
||||
}
|
||||
|
||||
EasyRPCPtr EasyChannel::createRPC(PVStructurePtr const & pvRequest)
|
||||
{
|
||||
throw std::runtime_error("EasyChannel::createRPC not implemented");
|
||||
}
|
||||
|
||||
EasyArrayPtr EasyChannel::createArray()
|
||||
{
|
||||
return createArray("value");
|
||||
}
|
||||
|
||||
EasyArrayPtr EasyChannel::createArray(string const & request)
|
||||
{
|
||||
PVStructurePtr pvRequest = createRequest->createRequest(request);
|
||||
if(!pvRequest) {
|
||||
stringstream ss;
|
||||
ss << "channel " << getChannelName();
|
||||
ss << " EasyChannel::createArray invalid pvRequest: " + createRequest->getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
return createArray(pvRequest);
|
||||
}
|
||||
|
||||
EasyArrayPtr EasyChannel::createArray(PVStructurePtr const & pvRequest)
|
||||
{
|
||||
throw std::runtime_error("EasyChannel::createArray not implemented");
|
||||
}
|
||||
|
||||
|
||||
EasyMonitorPtr EasyChannel::monitor() {return monitor("value,alarm,timeStamp");}
|
||||
|
||||
EasyMonitorPtr EasyChannel::monitor(string const & request)
|
||||
{
|
||||
EasyMonitorPtr easyMonitor = createMonitor(request);
|
||||
easyMonitor->connect();
|
||||
easyMonitor->start();
|
||||
return easyMonitor;
|
||||
}
|
||||
|
||||
EasyMonitorPtr EasyChannel::monitor(EasyMonitorRequesterPtr const & easyMonitorRequester)
|
||||
{ return monitor("value,alarm,timeStamp",easyMonitorRequester);
|
||||
}
|
||||
|
||||
EasyMonitorPtr EasyChannel::monitor(string const & request,
|
||||
EasyMonitorRequesterPtr const & easyMonitorRequester)
|
||||
{
|
||||
EasyMonitorPtr easyMonitor = createMonitor(request);
|
||||
easyMonitor->connect();
|
||||
easyMonitor->setRequester(easyMonitorRequester);
|
||||
easyMonitor->start();
|
||||
return easyMonitor;
|
||||
}
|
||||
|
||||
EasyMonitorPtr EasyChannel::createMonitor()
|
||||
{
|
||||
return createMonitor("value,alarm,timeStamp");
|
||||
}
|
||||
|
||||
EasyMonitorPtr EasyChannel::createMonitor(string const & request)
|
||||
{
|
||||
PVStructurePtr pvRequest = createRequest->createRequest(request);
|
||||
if(!pvRequest) {
|
||||
stringstream ss;
|
||||
ss << "channel " << getChannelName();
|
||||
ss << " EasyChannel::createMonitor invalid pvRequest: " + createRequest->getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
return createMonitor(pvRequest);
|
||||
}
|
||||
|
||||
EasyMonitorPtr EasyChannel::createMonitor(PVStructurePtr const & pvRequest)
|
||||
{
|
||||
if(connectState!=connected) connect(5.0);
|
||||
if(connectState!=connected) throw std::runtime_error("EasyChannel::createMonitor not connected");
|
||||
EasyPVAPtr yyy = easyPVA.lock();
|
||||
if(!yyy) throw std::runtime_error("EasyPVA was destroyed");
|
||||
return EasyMonitor::create(yyy,getPtrSelf(),channel,pvRequest);
|
||||
}
|
||||
|
||||
|
||||
EasyChannelPtr EasyChannel::create(
|
||||
EasyPVAPtr const &easyPVA,
|
||||
string const & channelName,
|
||||
string const & providerName)
|
||||
{
|
||||
EasyChannelPtr channel(new EasyChannel(easyPVA,channelName,providerName));
|
||||
return channel;
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -1,250 +0,0 @@
|
||||
/* easyMonitor.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.03
|
||||
*/
|
||||
#define epicsExportSharedSymbols
|
||||
|
||||
#include <sstream>
|
||||
#include <pv/event.h>
|
||||
#include <pv/easyPVA.h>
|
||||
#include <pv/bitSetUtil.h>
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace easyPVA {
|
||||
|
||||
|
||||
class ChannelMonitorRequester : public MonitorRequester
|
||||
{
|
||||
EasyMonitor * easyMonitor;
|
||||
public:
|
||||
ChannelMonitorRequester(EasyMonitor * easyMonitor)
|
||||
: easyMonitor(easyMonitor) {}
|
||||
string getRequesterName()
|
||||
{return easyMonitor->getRequesterName();}
|
||||
void message(string const & message,MessageType messageType)
|
||||
{easyMonitor->message(message,messageType);}
|
||||
void monitorConnect(
|
||||
const Status& status,
|
||||
Monitor::shared_pointer const & monitor,
|
||||
StructureConstPtr const & structure)
|
||||
{easyMonitor->monitorConnect(status,monitor,structure);}
|
||||
void monitorEvent(MonitorPtr const & monitor)
|
||||
{
|
||||
easyMonitor->monitorEvent(monitor);
|
||||
}
|
||||
void unlisten(MonitorPtr const & monitor)
|
||||
{easyMonitor->unlisten();}
|
||||
};
|
||||
|
||||
EasyMonitor::EasyMonitor(
|
||||
EasyPVAPtr const &pva,
|
||||
EasyChannelPtr const & easyChannel,
|
||||
Channel::shared_pointer const & channel,
|
||||
PVStructurePtr const &pvRequest)
|
||||
: easyPVA(pva),
|
||||
easyChannel(easyChannel),
|
||||
channel(channel),
|
||||
pvRequest(pvRequest),
|
||||
isDestroyed(false),
|
||||
connectState(connectIdle),
|
||||
userPoll(false),
|
||||
userWait(false)
|
||||
{
|
||||
}
|
||||
|
||||
EasyMonitor::~EasyMonitor()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
void EasyMonitor::checkMonitorState()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyMonitor was destroyed");
|
||||
if(connectState==connectIdle) connect();
|
||||
if(connectState==connected) start();
|
||||
}
|
||||
|
||||
// from MonitorRequester
|
||||
string EasyMonitor::getRequesterName()
|
||||
{
|
||||
EasyPVAPtr yyy = easyPVA.lock();
|
||||
if(!yyy) throw std::runtime_error("easyPVA was destroyed");
|
||||
return yyy->getRequesterName();
|
||||
}
|
||||
|
||||
void EasyMonitor::message(string const & message,MessageType messageType)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyMonitor was destroyed");
|
||||
EasyPVAPtr yyy = easyPVA.lock();
|
||||
if(!yyy) throw std::runtime_error("easyPVA was destroyed");
|
||||
yyy->message(message, messageType);
|
||||
}
|
||||
|
||||
void EasyMonitor::monitorConnect(
|
||||
const Status& status,
|
||||
Monitor::shared_pointer const & monitor,
|
||||
StructureConstPtr const & structure)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyMonitor was destroyed");
|
||||
connectStatus = status;
|
||||
this->monitor = monitor;
|
||||
if(status.isOK()) {
|
||||
easyData = EasyMonitorData::create(structure);
|
||||
easyData->setMessagePrefix(channel->getChannelName());
|
||||
}
|
||||
waitForConnect.signal();
|
||||
|
||||
}
|
||||
|
||||
void EasyMonitor::monitorEvent(MonitorPtr const & monitor)
|
||||
{
|
||||
EasyMonitorRequesterPtr req = easyMonitorRequester.lock();
|
||||
if(req) req->event(getPtrSelf());
|
||||
if(userWait) waitForEvent.signal();
|
||||
}
|
||||
|
||||
void EasyMonitor::unlisten()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
// from EasyMonitor
|
||||
void EasyMonitor::destroy()
|
||||
{
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) return;
|
||||
isDestroyed = true;
|
||||
}
|
||||
if(monitor) monitor->destroy();
|
||||
monitor.reset();
|
||||
}
|
||||
|
||||
void EasyMonitor::connect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyMonitor was destroyed");
|
||||
issueConnect();
|
||||
Status status = waitConnect();
|
||||
if(status.isOK()) return;
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyMonitor::connect " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void EasyMonitor::issueConnect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyMonitor was destroyed");
|
||||
if(connectState!=connectIdle) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " easyMonitor already connected ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
monitorRequester = ChannelMonitorRequester::shared_pointer(new ChannelMonitorRequester(this));
|
||||
connectState = connectActive;
|
||||
monitor = channel->createMonitor(monitorRequester,pvRequest);
|
||||
}
|
||||
|
||||
Status EasyMonitor::waitConnect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyMonitor was destroyed");
|
||||
if(connectState!=connectActive) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " easyMonitor illegal connect state ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
waitForConnect.wait();
|
||||
if(connectStatus.isOK()){
|
||||
connectState = connected;
|
||||
return Status::Ok;
|
||||
}
|
||||
connectState = connectIdle;
|
||||
return Status(Status::STATUSTYPE_ERROR,connectStatus.getMessage());
|
||||
}
|
||||
|
||||
void EasyMonitor::setRequester(EasyMonitorRequesterPtr const & easyMonitorrRequester)
|
||||
{
|
||||
this->easyMonitorRequester = easyMonitorrRequester;
|
||||
}
|
||||
|
||||
void EasyMonitor::start()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyMonitor was destroyed");
|
||||
if(connectState==monitorStarted) return;
|
||||
if(connectState==connectIdle) connect();
|
||||
if(connectState!=connected) throw std::runtime_error("EasyMonitor::start illegal state");
|
||||
connectState = monitorStarted;
|
||||
monitor->start();
|
||||
}
|
||||
|
||||
|
||||
void EasyMonitor::stop()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyMonitor was destroyed");
|
||||
if(connectState!=monitorStarted) return;
|
||||
connectState = connected;
|
||||
monitor->stop();
|
||||
}
|
||||
|
||||
bool EasyMonitor::poll()
|
||||
{
|
||||
checkMonitorState();
|
||||
if(connectState!=monitorStarted) throw std::runtime_error("EasyMonitor::poll illegal state");
|
||||
if(userPoll) throw std::runtime_error("EasyMonitor::poll did not release last");
|
||||
monitorElement = monitor->poll();
|
||||
if(!monitorElement) return false;
|
||||
userPoll = true;
|
||||
easyData->setData(monitorElement);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EasyMonitor::waitEvent(double secondsToWait)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyMonitor was destroyed");
|
||||
if(connectState!=monitorStarted) throw std::runtime_error("EasyMonitor::poll illegal state");
|
||||
if(poll()) return true;
|
||||
userWait = true;
|
||||
if(secondsToWait==0.0) {
|
||||
waitForEvent.wait();
|
||||
} else {
|
||||
waitForEvent.wait(secondsToWait);
|
||||
}
|
||||
userWait = false;
|
||||
return poll();
|
||||
}
|
||||
|
||||
void EasyMonitor::releaseEvent()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyMonitor was destroyed");
|
||||
if(connectState!=monitorStarted) throw std::runtime_error("EasyMonitor::poll illegal state");
|
||||
if(!userPoll) throw std::runtime_error("EasyMonitor::releaseEvent did not call poll");
|
||||
userPoll = false;
|
||||
monitor->release(monitorElement);
|
||||
}
|
||||
|
||||
EasyMonitorDataPtr EasyMonitor::getData()
|
||||
{
|
||||
checkMonitorState();
|
||||
return easyData;
|
||||
}
|
||||
|
||||
EasyMonitorPtr EasyMonitor::create(
|
||||
EasyPVAPtr const &pva,
|
||||
EasyChannelPtr const & easyChannel,
|
||||
Channel::shared_pointer const & channel,
|
||||
PVStructurePtr const &pvRequest)
|
||||
{
|
||||
EasyMonitorPtr epv(new EasyMonitor(pva,easyChannel,channel,pvRequest));
|
||||
return epv;
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -1,165 +0,0 @@
|
||||
/* easyMultiChannel.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 <map>
|
||||
#include <sstream>
|
||||
#include <pv/event.h>
|
||||
#include <pv/lock.h>
|
||||
#include <pv/easyPVA.h>
|
||||
#include <pv/createRequest.h>
|
||||
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace easyPVA {
|
||||
|
||||
|
||||
|
||||
EasyMultiChannel::EasyMultiChannel(
|
||||
EasyPVAPtr const &easyPVA,
|
||||
PVStringArrayPtr const & channelName,
|
||||
string const & providerName)
|
||||
: easyPVA(easyPVA),
|
||||
channelName(channelName),
|
||||
providerName(providerName),
|
||||
numChannel(channelName->getLength()),
|
||||
isConnected(getPVDataCreate()->createPVScalarArray<PVBooleanArray>()),
|
||||
isDestroyed(false)
|
||||
{
|
||||
}
|
||||
|
||||
EasyMultiChannel::~EasyMultiChannel()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
void EasyMultiChannel::destroy()
|
||||
{
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) return;
|
||||
isDestroyed = true;
|
||||
}
|
||||
easyChannelArray.reset();
|
||||
}
|
||||
|
||||
PVStringArrayPtr EasyMultiChannel::getChannelNames()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyMultiChannel was destroyed");
|
||||
return channelName;
|
||||
}
|
||||
|
||||
Status EasyMultiChannel::connect(double timeout,size_t maxNotConnected)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyMultiChannel was destroyed");
|
||||
if(easyChannelArray) throw std::runtime_error("easyMultiChannel already connected");
|
||||
EasyPVAPtr easy = easyPVA.lock();
|
||||
if(!easy) return Status(Status::STATUSTYPE_ERROR,"easyPVA is gone");
|
||||
shared_vector<EasyChannelPtr> easyChannel(numChannel,EasyChannelPtr());
|
||||
PVStringArray::const_svector channelNames = channelName->view();
|
||||
shared_vector<boolean> isConnected(numChannel,false);
|
||||
for(size_t i=0; i< numChannel; ++i) {
|
||||
easyChannel[i] = easy->createChannel(channelNames[i],providerName);
|
||||
easyChannel[i]->issueConnect();
|
||||
}
|
||||
Status returnStatus = Status::Ok;
|
||||
Status status = Status::Ok;
|
||||
size_t numBad = 0;
|
||||
for(size_t i=0; i< numChannel; ++i) {
|
||||
if(numBad==0) {
|
||||
status = easyChannel[i]->waitConnect(timeout);
|
||||
} else {
|
||||
status = easyChannel[i]->waitConnect(.001);
|
||||
}
|
||||
if(status.isOK()) {
|
||||
++numConnected;
|
||||
isConnected[i] = true;
|
||||
continue;
|
||||
}
|
||||
if(returnStatus.isOK()) returnStatus = status;
|
||||
++numBad;
|
||||
if(numBad>maxNotConnected) break;
|
||||
}
|
||||
easyChannelArray = EasyChannelArrayPtr(new EasyChannelArray(freeze(easyChannel)));
|
||||
this->isConnected->replace(freeze(isConnected));
|
||||
return numBad>maxNotConnected ? returnStatus : Status::Ok;
|
||||
}
|
||||
|
||||
|
||||
bool EasyMultiChannel::allConnected()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyMultiChannel was destroyed");
|
||||
if(!easyChannelArray) throw std::runtime_error("easyMultiChannel not connected");
|
||||
if(numConnected==numChannel) return true;
|
||||
return (numConnected==numChannel) ? true : false;
|
||||
}
|
||||
|
||||
bool EasyMultiChannel::connectionChange()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyMultiChannel was destroyed");
|
||||
if(!easyChannelArray) throw std::runtime_error("easyMultiChannel not connected");
|
||||
if(numConnected==numChannel) return true;
|
||||
PVBooleanArray::const_svector isConnected = this->isConnected->view();
|
||||
shared_vector<const EasyChannelPtr> channels = *easyChannelArray.get();
|
||||
for(size_t i=0; i<numChannel; ++i) {
|
||||
const EasyChannelPtr easyChannel = channels[i];
|
||||
Channel::shared_pointer channel = easyChannel->getChannel();
|
||||
Channel::ConnectionState stateNow = channel->getConnectionState();
|
||||
bool connectedNow = stateNow==Channel::CONNECTED ? true : false;
|
||||
if(connectedNow!=isConnected[i]) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
PVBooleanArrayPtr EasyMultiChannel::getIsConnected()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyMultiChannel was destroyed");
|
||||
if(!easyChannelArray) throw std::runtime_error("easyMultiChannel not connected");
|
||||
if(!connectionChange()) return isConnected;
|
||||
shared_vector<boolean> isConnected(numChannel,false);
|
||||
shared_vector<const EasyChannelPtr> channels = *easyChannelArray.get();
|
||||
for(size_t i=0; i<numChannel; ++i) {
|
||||
const EasyChannelPtr easyChannel = channels[i];
|
||||
Channel::shared_pointer channel = easyChannel->getChannel();
|
||||
Channel::ConnectionState stateNow = channel->getConnectionState();
|
||||
if(stateNow==Channel::CONNECTED) isConnected[i] = true;
|
||||
}
|
||||
this->isConnected->replace(freeze(isConnected));
|
||||
return this->isConnected;
|
||||
}
|
||||
|
||||
EasyChannelArrayWPtr EasyMultiChannel::getEasyChannelArray()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyMultiChannel was destroyed");
|
||||
if(!easyChannelArray) throw std::runtime_error("easyMultiChannel not connected");
|
||||
return easyChannelArray;
|
||||
}
|
||||
|
||||
EasyPVA::weak_pointer EasyMultiChannel::getEasyPVA()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyMultiChannel was destroyed");
|
||||
return easyPVA;
|
||||
}
|
||||
|
||||
EasyMultiChannelPtr EasyMultiChannel::create(
|
||||
EasyPVAPtr const &easyPVA,
|
||||
PVStringArrayPtr const & channelNames,
|
||||
string const & providerName)
|
||||
{
|
||||
EasyMultiChannelPtr channel(new EasyMultiChannel(easyPVA,channelNames,providerName));
|
||||
return channel;
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -1,138 +0,0 @@
|
||||
/* easyMultiDouble.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.03
|
||||
*/
|
||||
|
||||
#include <pv/easyMultiDouble.h>
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace easyPVA {
|
||||
|
||||
EasyMultiDoublePtr EasyMultiDouble::create(
|
||||
EasyPVAPtr const & easyPVA,
|
||||
PVStringArrayPtr const & channelName,
|
||||
double timeout,
|
||||
std::string const & providerName)
|
||||
{
|
||||
EasyMultiChannelPtr easyMultiChannel(
|
||||
EasyMultiChannel::create(easyPVA,channelName,providerName));
|
||||
Status status = easyMultiChannel->connect(timeout,0);
|
||||
if(!status.isOK()) throw std::runtime_error(status.getMessage());
|
||||
return EasyMultiDoublePtr(new EasyMultiDouble(easyMultiChannel));
|
||||
}
|
||||
|
||||
EasyMultiDouble::EasyMultiDouble(EasyMultiChannelPtr const &easyMultiChannel)
|
||||
:
|
||||
easyMultiChannel(easyMultiChannel)
|
||||
{}
|
||||
|
||||
EasyMultiDouble::~EasyMultiDouble()
|
||||
{
|
||||
}
|
||||
|
||||
void EasyMultiDouble::createGet()
|
||||
{
|
||||
EasyChannelArrayPtr easyChannelArray = easyMultiChannel->getEasyChannelArray().lock();
|
||||
if(!easyChannelArray) throw std::runtime_error("easyChannelArray is gone");
|
||||
shared_vector<const EasyChannelPtr> easyChannels = *easyChannelArray;
|
||||
size_t numChannel = easyChannels.size();
|
||||
easyGet = std::vector<EasyGetPtr>(numChannel,EasyGetPtr());
|
||||
bool allOK = true;
|
||||
string message;
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
easyGet[i] = easyChannels[i]->createGet("value");
|
||||
easyGet[i]->issueConnect();
|
||||
}
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
Status status = easyGet[i]->waitConnect();
|
||||
if(!status.isOK()) {
|
||||
message = "connect status " + status.getMessage();
|
||||
allOK = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!allOK) throw std::runtime_error(message);
|
||||
}
|
||||
|
||||
void EasyMultiDouble::createPut()
|
||||
{
|
||||
EasyChannelArrayPtr easyChannelArray = easyMultiChannel->getEasyChannelArray().lock();
|
||||
if(!easyChannelArray) throw std::runtime_error("easyChannelArray is gone");
|
||||
shared_vector<const EasyChannelPtr> easyChannels = *easyChannelArray;
|
||||
size_t numChannel = easyChannels.size();
|
||||
easyPut = std::vector<EasyPutPtr>(numChannel,EasyPutPtr());
|
||||
bool allOK = true;
|
||||
string message;
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
easyPut[i] = easyChannels[i]->createPut("value");
|
||||
easyPut[i]->issueConnect();
|
||||
}
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
Status status = easyPut[i]->waitConnect();
|
||||
if(!status.isOK()) {
|
||||
message = "connect status " + status.getMessage();
|
||||
allOK = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!allOK) throw std::runtime_error(message);
|
||||
}
|
||||
|
||||
epics::pvData::shared_vector<double> EasyMultiDouble::get()
|
||||
{
|
||||
if(easyGet.empty()) createGet();
|
||||
shared_vector<const string> channelNames = easyMultiChannel->getChannelNames()->view();
|
||||
size_t numChannel = channelNames.size();
|
||||
epics::pvData::shared_vector<double> data(channelNames.size());
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
easyGet[i]->issueGet();
|
||||
}
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
Status status = easyGet[i]->waitGet();
|
||||
if(!status.isOK()) {
|
||||
string message = channelNames[i] + " " + status.getMessage();
|
||||
throw std::runtime_error(message);
|
||||
}
|
||||
data[i] = easyGet[i]->getData()->getDouble();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
void EasyMultiDouble::put(shared_vector<double> const &value)
|
||||
{
|
||||
if(easyPut.empty()) createPut();
|
||||
shared_vector<const string> channelNames = easyMultiChannel->getChannelNames()->view();
|
||||
size_t numChannel = channelNames.size();
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
easyPut[i]->getData()->putDouble(value[i]);
|
||||
easyPut[i]->issuePut();
|
||||
}
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
Status status = easyPut[i]->waitPut();
|
||||
if(!status.isOK()) {
|
||||
string message = channelNames[i] + " " + status.getMessage();
|
||||
throw std::runtime_error(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
-199
@@ -1,199 +0,0 @@
|
||||
/* easyPVA.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 <map>
|
||||
#include <pv/easyPVA.h>
|
||||
#include <pv/createRequest.h>
|
||||
#include <pv/clientFactory.h>
|
||||
#include <pv/caProvider.h>
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::pvAccess::ca;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace easyPVA {
|
||||
|
||||
static FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
static const string easyPVAName = "easyPVA";
|
||||
static const string defaultProvider = "pva";
|
||||
static UnionConstPtr variantUnion = fieldCreate->createVariantUnion();
|
||||
|
||||
namespace easyPVAPvt {
|
||||
|
||||
static size_t numberEasyPVA = 0;
|
||||
static bool firstTime = true;
|
||||
static Mutex mutex;
|
||||
|
||||
class StartStopClientFactory {
|
||||
public:
|
||||
static void EasyPVABeingConstructed()
|
||||
{
|
||||
bool saveFirst = false;
|
||||
{
|
||||
Lock xx(mutex);
|
||||
++numberEasyPVA;
|
||||
saveFirst = firstTime;
|
||||
firstTime = false;
|
||||
}
|
||||
if(saveFirst) {
|
||||
ClientFactory::start();
|
||||
CAClientFactory::start();
|
||||
}
|
||||
}
|
||||
|
||||
static void EasyPVABeingDestroyed() {
|
||||
size_t numLeft = 0;
|
||||
{
|
||||
Lock xx(mutex);
|
||||
--numberEasyPVA;
|
||||
numLeft = numberEasyPVA;
|
||||
}
|
||||
if(numLeft<=0) {
|
||||
ClientFactory::stop();
|
||||
CAClientFactory::stop();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace easyPVAPvt
|
||||
|
||||
class EasyChannelCache
|
||||
{
|
||||
public:
|
||||
EasyChannelCache(){}
|
||||
~EasyChannelCache(){
|
||||
destroy();
|
||||
}
|
||||
void destroy() {
|
||||
easyChannelMap.clear();
|
||||
}
|
||||
EasyChannelPtr getChannel(string const & channelName);
|
||||
void addChannel(EasyChannelPtr const & easyChannel);
|
||||
void removeChannel(string const & channelName);
|
||||
private:
|
||||
map<string,EasyChannelPtr> easyChannelMap;
|
||||
};
|
||||
|
||||
EasyChannelPtr EasyChannelCache::getChannel(string const & channelName)
|
||||
{
|
||||
map<string,EasyChannelPtr>::iterator iter = easyChannelMap.find(channelName);
|
||||
if(iter!=easyChannelMap.end()) return iter->second;
|
||||
return EasyChannelPtr();
|
||||
}
|
||||
|
||||
void EasyChannelCache::addChannel(EasyChannelPtr const & easyChannel)
|
||||
{
|
||||
easyChannelMap.insert(std::pair<string,EasyChannelPtr>(
|
||||
easyChannel->getChannelName(),easyChannel));
|
||||
}
|
||||
|
||||
void EasyChannelCache::removeChannel(string const & channelName)
|
||||
{
|
||||
map<string,EasyChannelPtr>::iterator iter = easyChannelMap.find(channelName);
|
||||
if(iter!=easyChannelMap.end()) easyChannelMap.erase(iter);
|
||||
}
|
||||
|
||||
using namespace epics::easyPVA::easyPVAPvt;
|
||||
|
||||
EasyPVAPtr EasyPVA::create()
|
||||
{
|
||||
EasyPVAPtr xx(new EasyPVA());
|
||||
StartStopClientFactory::EasyPVABeingConstructed();
|
||||
return xx;
|
||||
}
|
||||
|
||||
PVStructurePtr EasyPVA::createRequest(string const &request)
|
||||
{
|
||||
CreateRequest::shared_pointer createRequest = CreateRequest::create();
|
||||
PVStructurePtr pvRequest = createRequest->createRequest(request);
|
||||
if(!pvRequest) {
|
||||
throw std::invalid_argument("invalid pvRequest: " + createRequest->getMessage());
|
||||
}
|
||||
return pvRequest;
|
||||
}
|
||||
|
||||
EasyPVA::EasyPVA()
|
||||
: easyChannelCache(new EasyChannelCache()),
|
||||
isDestroyed(false)
|
||||
{
|
||||
}
|
||||
|
||||
EasyPVA::~EasyPVA() {
|
||||
destroy();
|
||||
}
|
||||
|
||||
void EasyPVA::destroy()
|
||||
{
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) return;
|
||||
isDestroyed = true;
|
||||
}
|
||||
easyChannelCache.reset();
|
||||
channelList.clear();
|
||||
multiChannelList.clear();
|
||||
StartStopClientFactory::EasyPVABeingDestroyed();
|
||||
}
|
||||
|
||||
string EasyPVA:: getRequesterName()
|
||||
{
|
||||
static string name("easyPVA");
|
||||
return name;
|
||||
}
|
||||
|
||||
void EasyPVA::message(
|
||||
string const & message,
|
||||
MessageType messageType)
|
||||
{
|
||||
cout << getMessageTypeName(messageType) << " " << message << endl;
|
||||
}
|
||||
|
||||
EasyChannelPtr EasyPVA::channel(
|
||||
std::string const & channelName,
|
||||
std::string const & providerName,
|
||||
double timeOut)
|
||||
{
|
||||
EasyChannelPtr easyChannel = easyChannelCache->getChannel(channelName);
|
||||
if(easyChannel) return easyChannel;
|
||||
easyChannel = createChannel(channelName,providerName);
|
||||
easyChannel->connect(timeOut);
|
||||
easyChannelCache->addChannel(easyChannel);
|
||||
return easyChannel;
|
||||
}
|
||||
|
||||
EasyChannelPtr EasyPVA::createChannel(string const & channelName)
|
||||
{
|
||||
return EasyChannel::create(getPtrSelf(),channelName);
|
||||
}
|
||||
|
||||
EasyChannelPtr EasyPVA::createChannel(string const & channelName, string const & providerName)
|
||||
{
|
||||
return EasyChannel::create(getPtrSelf(),channelName,providerName);
|
||||
}
|
||||
|
||||
EasyMultiChannelPtr EasyPVA::createMultiChannel(
|
||||
epics::pvData::PVStringArrayPtr const & channelNames)
|
||||
{
|
||||
return createMultiChannel(channelNames,"pva");
|
||||
}
|
||||
|
||||
EasyMultiChannelPtr EasyPVA::createMultiChannel(
|
||||
epics::pvData::PVStringArrayPtr const & channelNames,
|
||||
std::string const & providerName)
|
||||
{
|
||||
return EasyMultiChannel::create(getPtrSelf(),channelNames,providerName);
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
/* pvaClient.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 <map>
|
||||
#include <pv/pvaClient.h>
|
||||
#include <pv/createRequest.h>
|
||||
#include <pv/clientFactory.h>
|
||||
#include <pv/caProvider.h>
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::pvAccess::ca;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvaClient {
|
||||
|
||||
static FieldCreatePtr fieldCreate = getFieldCreate();
|
||||
static const string pvaClientName = "pvaClient";
|
||||
static const string defaultProvider = "pva";
|
||||
static UnionConstPtr variantUnion = fieldCreate->createVariantUnion();
|
||||
|
||||
namespace pvaClientPvt {
|
||||
|
||||
static size_t numberPvaClient = 0;
|
||||
static bool firstTime = true;
|
||||
static Mutex mutex;
|
||||
|
||||
class StartStopClientFactory {
|
||||
public:
|
||||
static void PvaClientBeingConstructed()
|
||||
{
|
||||
bool saveFirst = false;
|
||||
{
|
||||
Lock xx(mutex);
|
||||
++numberPvaClient;
|
||||
saveFirst = firstTime;
|
||||
firstTime = false;
|
||||
}
|
||||
if(saveFirst) {
|
||||
ClientFactory::start();
|
||||
CAClientFactory::start();
|
||||
}
|
||||
}
|
||||
|
||||
static void PvaClientBeingDestroyed() {
|
||||
size_t numLeft = 0;
|
||||
{
|
||||
Lock xx(mutex);
|
||||
--numberPvaClient;
|
||||
numLeft = numberPvaClient;
|
||||
}
|
||||
if(numLeft<=0) {
|
||||
ClientFactory::stop();
|
||||
CAClientFactory::stop();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace pvaClientPvt
|
||||
|
||||
class PvaClientChannelCache
|
||||
{
|
||||
public:
|
||||
PvaClientChannelCache(){}
|
||||
~PvaClientChannelCache(){
|
||||
destroy();
|
||||
}
|
||||
void destroy() {
|
||||
pvaClientChannelMap.clear();
|
||||
}
|
||||
PvaClientChannelPtr getChannel(string const & channelName);
|
||||
void addChannel(PvaClientChannelPtr const & pvaClientChannel);
|
||||
void removeChannel(string const & channelName);
|
||||
private:
|
||||
map<string,PvaClientChannelPtr> pvaClientChannelMap;
|
||||
};
|
||||
|
||||
PvaClientChannelPtr PvaClientChannelCache::getChannel(string const & channelName)
|
||||
{
|
||||
map<string,PvaClientChannelPtr>::iterator iter = pvaClientChannelMap.find(channelName);
|
||||
if(iter!=pvaClientChannelMap.end()) return iter->second;
|
||||
return PvaClientChannelPtr();
|
||||
}
|
||||
|
||||
void PvaClientChannelCache::addChannel(PvaClientChannelPtr const & pvaClientChannel)
|
||||
{
|
||||
pvaClientChannelMap.insert(std::pair<string,PvaClientChannelPtr>(
|
||||
pvaClientChannel->getChannelName(),pvaClientChannel));
|
||||
}
|
||||
|
||||
void PvaClientChannelCache::removeChannel(string const & channelName)
|
||||
{
|
||||
map<string,PvaClientChannelPtr>::iterator iter = pvaClientChannelMap.find(channelName);
|
||||
if(iter!=pvaClientChannelMap.end()) pvaClientChannelMap.erase(iter);
|
||||
}
|
||||
|
||||
using namespace epics::pvaClient::pvaClientPvt;
|
||||
|
||||
PvaClientPtr PvaClient::create()
|
||||
{
|
||||
PvaClientPtr xx(new PvaClient());
|
||||
StartStopClientFactory::PvaClientBeingConstructed();
|
||||
return xx;
|
||||
}
|
||||
|
||||
PVStructurePtr PvaClient::createRequest(string const &request)
|
||||
{
|
||||
CreateRequest::shared_pointer createRequest = CreateRequest::create();
|
||||
PVStructurePtr pvRequest = createRequest->createRequest(request);
|
||||
if(!pvRequest) {
|
||||
throw std::invalid_argument("invalid pvRequest: " + createRequest->getMessage());
|
||||
}
|
||||
return pvRequest;
|
||||
}
|
||||
|
||||
PvaClient::PvaClient()
|
||||
: pvaClientChannelCache(new PvaClientChannelCache()),
|
||||
isDestroyed(false)
|
||||
{
|
||||
}
|
||||
|
||||
PvaClient::~PvaClient() {
|
||||
destroy();
|
||||
}
|
||||
|
||||
void PvaClient::destroy()
|
||||
{
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) return;
|
||||
isDestroyed = true;
|
||||
}
|
||||
pvaClientChannelCache.reset();
|
||||
channelList.clear();
|
||||
multiChannelList.clear();
|
||||
StartStopClientFactory::PvaClientBeingDestroyed();
|
||||
}
|
||||
|
||||
string PvaClient:: getRequesterName()
|
||||
{
|
||||
static string name("pvaClient");
|
||||
return name;
|
||||
}
|
||||
|
||||
void PvaClient::message(
|
||||
string const & message,
|
||||
MessageType messageType)
|
||||
{
|
||||
cout << getMessageTypeName(messageType) << " " << message << endl;
|
||||
}
|
||||
|
||||
PvaClientChannelPtr PvaClient::channel(
|
||||
std::string const & channelName,
|
||||
std::string const & providerName,
|
||||
double timeOut)
|
||||
{
|
||||
PvaClientChannelPtr pvaClientChannel = pvaClientChannelCache->getChannel(channelName);
|
||||
if(pvaClientChannel) return pvaClientChannel;
|
||||
pvaClientChannel = createChannel(channelName,providerName);
|
||||
pvaClientChannel->connect(timeOut);
|
||||
pvaClientChannelCache->addChannel(pvaClientChannel);
|
||||
return pvaClientChannel;
|
||||
}
|
||||
|
||||
PvaClientChannelPtr PvaClient::createChannel(string const & channelName)
|
||||
{
|
||||
return PvaClientChannel::create(getPtrSelf(),channelName);
|
||||
}
|
||||
|
||||
PvaClientChannelPtr PvaClient::createChannel(string const & channelName, string const & providerName)
|
||||
{
|
||||
return PvaClientChannel::create(getPtrSelf(),channelName,providerName);
|
||||
}
|
||||
|
||||
PvaClientMultiChannelPtr PvaClient::createMultiChannel(
|
||||
epics::pvData::PVStringArrayPtr const & channelNames)
|
||||
{
|
||||
return createMultiChannel(channelNames,"pvaClient");
|
||||
}
|
||||
|
||||
PvaClientMultiChannelPtr PvaClient::createMultiChannel(
|
||||
epics::pvData::PVStringArrayPtr const & channelNames,
|
||||
std::string const & providerName)
|
||||
{
|
||||
return PvaClientMultiChannel::create(getPtrSelf(),channelNames,providerName);
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
+285
-285
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,495 @@
|
||||
/* pvaClientChannel.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 <map>
|
||||
#include <sstream>
|
||||
#include <pv/event.h>
|
||||
#include <pv/lock.h>
|
||||
#include <pv/pvaClient.h>
|
||||
#include <pv/createRequest.h>
|
||||
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvaClient {
|
||||
|
||||
|
||||
class PvaClientGetCache
|
||||
{
|
||||
public:
|
||||
PvaClientGetCache(){}
|
||||
~PvaClientGetCache();
|
||||
void destroy() {
|
||||
pvaClientGetMap.clear();
|
||||
}
|
||||
PvaClientGetPtr getGet(string const & request);
|
||||
void addGet(string const & request,PvaClientGetPtr const & pvaClientGet);
|
||||
private:
|
||||
map<string,PvaClientGetPtr> pvaClientGetMap;
|
||||
};
|
||||
|
||||
PvaClientGetCache::~PvaClientGetCache()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
PvaClientGetPtr PvaClientGetCache::getGet(string const & request)
|
||||
{
|
||||
map<string,PvaClientGetPtr>::iterator iter = pvaClientGetMap.find(request);
|
||||
if(iter!=pvaClientGetMap.end()) return iter->second;
|
||||
return PvaClientGetPtr();
|
||||
}
|
||||
|
||||
void PvaClientGetCache::addGet(string const & request,PvaClientGetPtr const & pvaClientGet)
|
||||
{
|
||||
pvaClientGetMap.insert(std::pair<string,PvaClientGetPtr>(
|
||||
request,pvaClientGet));
|
||||
}
|
||||
|
||||
|
||||
class PvaClientPutCache
|
||||
{
|
||||
public:
|
||||
PvaClientPutCache(){}
|
||||
~PvaClientPutCache();
|
||||
void destroy() {
|
||||
pvaClientPutMap.clear();
|
||||
}
|
||||
PvaClientPutPtr getPut(string const & request);
|
||||
void addPut(string const & request,PvaClientPutPtr const & pvaClientPut);
|
||||
private:
|
||||
map<string,PvaClientPutPtr> pvaClientPutMap;
|
||||
};
|
||||
|
||||
PvaClientPutCache::~PvaClientPutCache()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
PvaClientPutPtr PvaClientPutCache::getPut(string const & request)
|
||||
{
|
||||
map<string,PvaClientPutPtr>::iterator iter = pvaClientPutMap.find(request);
|
||||
if(iter!=pvaClientPutMap.end()) return iter->second;
|
||||
return PvaClientPutPtr();
|
||||
}
|
||||
|
||||
void PvaClientPutCache::addPut(string const & request,PvaClientPutPtr const & pvaClientPut)
|
||||
{
|
||||
pvaClientPutMap.insert(std::pair<string,PvaClientPutPtr>(
|
||||
request,pvaClientPut));
|
||||
}
|
||||
|
||||
class ChannelRequesterImpl : public ChannelRequester
|
||||
{
|
||||
PvaClientChannel *pvaClientChannel;
|
||||
public:
|
||||
ChannelRequesterImpl(PvaClientChannel *pvaClientChannel)
|
||||
: pvaClientChannel(pvaClientChannel) {}
|
||||
void channelCreated(
|
||||
const Status& status,
|
||||
Channel::shared_pointer const & channel)
|
||||
{ pvaClientChannel->channelCreated(status,channel); }
|
||||
void channelStateChange(
|
||||
Channel::shared_pointer const & channel,
|
||||
Channel::ConnectionState connectionState)
|
||||
{pvaClientChannel->channelStateChange(channel,connectionState);}
|
||||
tr1::shared_ptr<Channel> getChannel() {return pvaClientChannel->getChannel();}
|
||||
string getRequesterName()
|
||||
{return pvaClientChannel->getRequesterName();}
|
||||
void message(
|
||||
string const & message,
|
||||
MessageType messageType)
|
||||
{ pvaClientChannel->message(message,messageType); }
|
||||
void destroy() {pvaClientChannel->destroy();}
|
||||
};
|
||||
|
||||
|
||||
PvaClientChannel::PvaClientChannel(
|
||||
PvaClientPtr const &pvaClient,
|
||||
string const & channelName,
|
||||
string const & providerName)
|
||||
: pvaClient(pvaClient),
|
||||
channelName(channelName),
|
||||
providerName(providerName),
|
||||
connectState(connectIdle),
|
||||
isDestroyed(false),
|
||||
createRequest(CreateRequest::create()),
|
||||
pvaClientGetCache(new PvaClientGetCache()),
|
||||
pvaClientPutCache(new PvaClientPutCache())
|
||||
{}
|
||||
|
||||
PvaClientChannel::~PvaClientChannel()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
void PvaClientChannel::channelCreated(const Status& status, Channel::shared_pointer const & channel)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientChannel was destroyed");
|
||||
if(status.isOK()) {
|
||||
this->channel = channel;
|
||||
return;
|
||||
}
|
||||
cout << "PvaClientChannel::channelCreated status " << status.getMessage() << " why??\n";
|
||||
}
|
||||
|
||||
void PvaClientChannel::channelStateChange(
|
||||
Channel::shared_pointer const & channel,
|
||||
Channel::ConnectionState connectionState)
|
||||
{
|
||||
if(isDestroyed) return;
|
||||
bool waitingForConnect = false;
|
||||
if(connectState==connectActive) waitingForConnect = true;
|
||||
if(connectionState!=Channel::CONNECTED) {
|
||||
string mess(channelName +
|
||||
" connection state " + Channel::ConnectionStateNames[connectionState]);
|
||||
message(mess,errorMessage);
|
||||
channelConnectStatus = Status(Status::STATUSTYPE_ERROR,mess);
|
||||
connectState = notConnected;
|
||||
} else {
|
||||
connectState = connected;
|
||||
}
|
||||
if(waitingForConnect) waitForConnect.signal();
|
||||
}
|
||||
|
||||
string PvaClientChannel::getRequesterName()
|
||||
{
|
||||
PvaClientPtr yyy = pvaClient.lock();
|
||||
if(!yyy) throw std::runtime_error("PvaClient was destroyed");
|
||||
return yyy->getRequesterName();
|
||||
}
|
||||
|
||||
void PvaClientChannel::message(
|
||||
string const & message,
|
||||
MessageType messageType)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientChannel was destroyed");
|
||||
PvaClientPtr yyy = pvaClient.lock();
|
||||
if(!yyy) throw std::runtime_error("PvaClient was destroyed");
|
||||
yyy->message(message, messageType);
|
||||
}
|
||||
|
||||
void PvaClientChannel::destroy()
|
||||
{
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) return;
|
||||
isDestroyed = true;
|
||||
}
|
||||
if(channel) channel->destroy();
|
||||
channel.reset();
|
||||
pvaClientGetCache.reset();
|
||||
pvaClientPutCache.reset();
|
||||
}
|
||||
|
||||
string PvaClientChannel::getChannelName()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientChannel was destroyed");
|
||||
return channelName;
|
||||
}
|
||||
|
||||
Channel::shared_pointer PvaClientChannel::getChannel()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientChannel was destroyed");
|
||||
return channel;
|
||||
}
|
||||
|
||||
void PvaClientChannel::connect(double timeout)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientChannel was destroyed");
|
||||
issueConnect();
|
||||
Status status = waitConnect(timeout);
|
||||
if(status.isOK()) return;
|
||||
stringstream ss;
|
||||
ss << "channel " << getChannelName() << " PvaClientChannel::connect " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void PvaClientChannel::issueConnect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientChannel was destroyed");
|
||||
if(connectState!=connectIdle) {
|
||||
throw std::runtime_error("pvaClientChannel already connected");
|
||||
}
|
||||
channelRequester = ChannelRequester::shared_pointer(new ChannelRequesterImpl(this));
|
||||
|
||||
channelConnectStatus = Status(
|
||||
Status::STATUSTYPE_ERROR,
|
||||
getChannelName() + " createChannel failed");
|
||||
connectState = connectActive;
|
||||
ChannelProviderRegistry::shared_pointer reg = getChannelProviderRegistry();
|
||||
ChannelProvider::shared_pointer provider = reg->getProvider(providerName);
|
||||
if(!provider) {
|
||||
throw std::runtime_error(getChannelName() + " provider " + providerName + " not registered");
|
||||
}
|
||||
channel = provider->createChannel(channelName,channelRequester,ChannelProvider::PRIORITY_DEFAULT);
|
||||
if(!channel) {
|
||||
throw std::runtime_error(channelConnectStatus.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
Status PvaClientChannel::waitConnect(double timeout)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientChannel was destroyed");
|
||||
waitForConnect.wait(timeout);
|
||||
if(connectState==connected) return Status::Ok;
|
||||
return Status(Status::STATUSTYPE_ERROR,channelConnectStatus.getMessage());
|
||||
}
|
||||
|
||||
PvaClientFieldPtr PvaClientChannel::createField()
|
||||
{
|
||||
return createField("");
|
||||
}
|
||||
|
||||
PvaClientFieldPtr PvaClientChannel::createField(string const & subField)
|
||||
{
|
||||
throw std::runtime_error("PvaClientChannel::createField not implemented");
|
||||
}
|
||||
|
||||
PvaClientProcessPtr PvaClientChannel::createProcess()
|
||||
{
|
||||
return createProcess("");
|
||||
}
|
||||
|
||||
PvaClientProcessPtr PvaClientChannel::createProcess(string const & request)
|
||||
{
|
||||
PVStructurePtr pvRequest = createRequest->createRequest(request);
|
||||
if(!pvRequest) {
|
||||
stringstream ss;
|
||||
ss << "channel " << getChannelName();
|
||||
ss << " PvaClientChannel::createProcess invalid pvRequest: " + createRequest->getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
return createProcess(pvRequest);
|
||||
}
|
||||
|
||||
PvaClientProcessPtr PvaClientChannel::createProcess(PVStructurePtr const & pvRequest)
|
||||
{
|
||||
if(connectState!=connected) connect(5.0);
|
||||
if(connectState!=connected) throw std::runtime_error("PvaClientChannel::creatProcess not connected");
|
||||
PvaClientPtr yyy = pvaClient.lock();
|
||||
if(!yyy) throw std::runtime_error("PvaClient was destroyed");
|
||||
return PvaClientProcess::create(yyy,getPtrSelf(),channel,pvRequest);
|
||||
}
|
||||
|
||||
PvaClientGetPtr PvaClientChannel::get() {return get("value,alarm,timeStamp");}
|
||||
|
||||
PvaClientGetPtr PvaClientChannel::get(string const & request)
|
||||
{
|
||||
PvaClientGetPtr pvaClientGet = pvaClientGetCache->getGet(request);
|
||||
if(pvaClientGet) return pvaClientGet;
|
||||
pvaClientGet = createGet(request);
|
||||
pvaClientGet->connect();
|
||||
pvaClientGetCache->addGet(request,pvaClientGet);
|
||||
return pvaClientGet;
|
||||
}
|
||||
|
||||
PvaClientGetPtr PvaClientChannel::createGet()
|
||||
{
|
||||
return PvaClientChannel::createGet("value,alarm,timeStamp");
|
||||
}
|
||||
|
||||
PvaClientGetPtr PvaClientChannel::createGet(string const & request)
|
||||
{
|
||||
PVStructurePtr pvRequest = createRequest->createRequest(request);
|
||||
if(!pvRequest) {
|
||||
stringstream ss;
|
||||
ss << "channel " << getChannelName();
|
||||
ss << " PvaClientChannel::createGet invalid pvRequest: " + createRequest->getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
return createGet(pvRequest);
|
||||
}
|
||||
|
||||
PvaClientGetPtr PvaClientChannel::createGet(PVStructurePtr const & pvRequest)
|
||||
{
|
||||
if(connectState!=connected) connect(5.0);
|
||||
if(connectState!=connected) throw std::runtime_error("PvaClientChannel::creatGet not connected");
|
||||
PvaClientPtr yyy = pvaClient.lock();
|
||||
if(!yyy) throw std::runtime_error("PvaClient was destroyed");
|
||||
return PvaClientGet::create(yyy,getPtrSelf(),channel,pvRequest);
|
||||
}
|
||||
|
||||
PvaClientPutPtr PvaClientChannel::put() {return put("value");}
|
||||
|
||||
PvaClientPutPtr PvaClientChannel::put(string const & request)
|
||||
{
|
||||
PvaClientPutPtr pvaClientPut = pvaClientPutCache->getPut(request);
|
||||
if(pvaClientPut) return pvaClientPut;
|
||||
pvaClientPut = createPut(request);
|
||||
pvaClientPut->connect();
|
||||
pvaClientPut->get();
|
||||
pvaClientPutCache->addPut(request,pvaClientPut);
|
||||
return pvaClientPut;
|
||||
}
|
||||
|
||||
PvaClientPutPtr PvaClientChannel::createPut()
|
||||
{
|
||||
return createPut("value");
|
||||
}
|
||||
|
||||
PvaClientPutPtr PvaClientChannel::createPut(string const & request)
|
||||
{
|
||||
PVStructurePtr pvRequest = createRequest->createRequest(request);
|
||||
if(!pvRequest) {
|
||||
stringstream ss;
|
||||
ss << "channel " << getChannelName();
|
||||
ss << " PvaClientChannel::createPut invalid pvRequest: " + createRequest->getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
return createPut(pvRequest);
|
||||
}
|
||||
|
||||
PvaClientPutPtr PvaClientChannel::createPut(PVStructurePtr const & pvRequest)
|
||||
{
|
||||
if(connectState!=connected) connect(5.0);
|
||||
if(connectState!=connected) throw std::runtime_error("PvaClientChannel::creatPut not connected");
|
||||
PvaClientPtr yyy = pvaClient.lock();
|
||||
if(!yyy) throw std::runtime_error("PvaClient was destroyed");
|
||||
return PvaClientPut::create(yyy,getPtrSelf(),channel,pvRequest);
|
||||
}
|
||||
|
||||
PvaClientPutGetPtr PvaClientChannel::createPutGet()
|
||||
{
|
||||
return createPutGet("putField(argument)getField(result)");
|
||||
}
|
||||
|
||||
PvaClientPutGetPtr PvaClientChannel::createPutGet(string const & request)
|
||||
{
|
||||
PVStructurePtr pvRequest = createRequest->createRequest(request);
|
||||
if(!pvRequest) {
|
||||
stringstream ss;
|
||||
ss << "channel " << getChannelName();
|
||||
ss << " PvaClientChannel::createPutGet invalid pvRequest: " + createRequest->getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
return createPutGet(pvRequest);
|
||||
}
|
||||
|
||||
PvaClientPutGetPtr PvaClientChannel::createPutGet(PVStructurePtr const & pvRequest)
|
||||
{
|
||||
if(connectState!=connected) connect(5.0);
|
||||
if(connectState!=connected) throw std::runtime_error("PvaClientChannel::creatPutGet not connected");
|
||||
PvaClientPtr yyy = pvaClient.lock();
|
||||
if(!yyy) throw std::runtime_error("PvaClient was destroyed");
|
||||
return PvaClientPutGet::create(yyy,getPtrSelf(),channel,pvRequest);
|
||||
}
|
||||
|
||||
PvaClientRPCPtr PvaClientChannel::createRPC()
|
||||
{
|
||||
return createRPC("");
|
||||
}
|
||||
|
||||
PvaClientRPCPtr PvaClientChannel::createRPC(string const & request)
|
||||
{
|
||||
PVStructurePtr pvRequest = createRequest->createRequest(request);
|
||||
if(!pvRequest) {
|
||||
stringstream ss;
|
||||
ss << "channel " << getChannelName();
|
||||
ss << " PvaClientChannel::createRPC invalid pvRequest: " + createRequest->getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
return createRPC(pvRequest);
|
||||
}
|
||||
|
||||
PvaClientRPCPtr PvaClientChannel::createRPC(PVStructurePtr const & pvRequest)
|
||||
{
|
||||
throw std::runtime_error("PvaClientChannel::createRPC not implemented");
|
||||
}
|
||||
|
||||
PvaClientArrayPtr PvaClientChannel::createArray()
|
||||
{
|
||||
return createArray("value");
|
||||
}
|
||||
|
||||
PvaClientArrayPtr PvaClientChannel::createArray(string const & request)
|
||||
{
|
||||
PVStructurePtr pvRequest = createRequest->createRequest(request);
|
||||
if(!pvRequest) {
|
||||
stringstream ss;
|
||||
ss << "channel " << getChannelName();
|
||||
ss << " PvaClientChannel::createArray invalid pvRequest: " + createRequest->getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
return createArray(pvRequest);
|
||||
}
|
||||
|
||||
PvaClientArrayPtr PvaClientChannel::createArray(PVStructurePtr const & pvRequest)
|
||||
{
|
||||
throw std::runtime_error("PvaClientChannel::createArray not implemented");
|
||||
}
|
||||
|
||||
|
||||
PvaClientMonitorPtr PvaClientChannel::monitor() {return monitor("value,alarm,timeStamp");}
|
||||
|
||||
PvaClientMonitorPtr PvaClientChannel::monitor(string const & request)
|
||||
{
|
||||
PvaClientMonitorPtr pvaClientMonitor = createMonitor(request);
|
||||
pvaClientMonitor->connect();
|
||||
pvaClientMonitor->start();
|
||||
return pvaClientMonitor;
|
||||
}
|
||||
|
||||
PvaClientMonitorPtr PvaClientChannel::monitor(PvaClientMonitorRequesterPtr const & pvaClientMonitorRequester)
|
||||
{ return monitor("value,alarm,timeStamp",pvaClientMonitorRequester);
|
||||
}
|
||||
|
||||
PvaClientMonitorPtr PvaClientChannel::monitor(string const & request,
|
||||
PvaClientMonitorRequesterPtr const & pvaClientMonitorRequester)
|
||||
{
|
||||
PvaClientMonitorPtr pvaClientMonitor = createMonitor(request);
|
||||
pvaClientMonitor->connect();
|
||||
pvaClientMonitor->setRequester(pvaClientMonitorRequester);
|
||||
pvaClientMonitor->start();
|
||||
return pvaClientMonitor;
|
||||
}
|
||||
|
||||
PvaClientMonitorPtr PvaClientChannel::createMonitor()
|
||||
{
|
||||
return createMonitor("value,alarm,timeStamp");
|
||||
}
|
||||
|
||||
PvaClientMonitorPtr PvaClientChannel::createMonitor(string const & request)
|
||||
{
|
||||
PVStructurePtr pvRequest = createRequest->createRequest(request);
|
||||
if(!pvRequest) {
|
||||
stringstream ss;
|
||||
ss << "channel " << getChannelName();
|
||||
ss << " PvaClientChannel::createMonitor invalid pvRequest: " + createRequest->getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
return createMonitor(pvRequest);
|
||||
}
|
||||
|
||||
PvaClientMonitorPtr PvaClientChannel::createMonitor(PVStructurePtr const & pvRequest)
|
||||
{
|
||||
if(connectState!=connected) connect(5.0);
|
||||
if(connectState!=connected) throw std::runtime_error("PvaClientChannel::createMonitor not connected");
|
||||
PvaClientPtr yyy = pvaClient.lock();
|
||||
if(!yyy) throw std::runtime_error("PvaClient was destroyed");
|
||||
return PvaClientMonitor::create(yyy,getPtrSelf(),channel,pvRequest);
|
||||
}
|
||||
|
||||
|
||||
PvaClientChannelPtr PvaClientChannel::create(
|
||||
PvaClientPtr const &pvaClient,
|
||||
string const & channelName,
|
||||
string const & providerName)
|
||||
{
|
||||
PvaClientChannelPtr channel(new PvaClientChannel(pvaClient,channelName,providerName));
|
||||
return channel;
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* easyGet.cpp */
|
||||
/* pvaClientGet.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
@@ -12,46 +12,46 @@
|
||||
|
||||
#include <sstream>
|
||||
#include <pv/event.h>
|
||||
#include <pv/easyPVA.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 easyPVA {
|
||||
namespace epics { namespace pvaClient {
|
||||
|
||||
|
||||
class ChannelGetRequesterImpl : public ChannelGetRequester
|
||||
{
|
||||
EasyGet * easyGet;
|
||||
PvaClientGet * pvaClientGet;
|
||||
public:
|
||||
ChannelGetRequesterImpl(EasyGet * easyGet)
|
||||
: easyGet(easyGet) {}
|
||||
ChannelGetRequesterImpl(PvaClientGet * pvaClientGet)
|
||||
: pvaClientGet(pvaClientGet) {}
|
||||
string getRequesterName()
|
||||
{return easyGet->getRequesterName();}
|
||||
{return pvaClientGet->getRequesterName();}
|
||||
void message(string const & message,MessageType messageType)
|
||||
{easyGet->message(message,messageType);}
|
||||
{pvaClientGet->message(message,messageType);}
|
||||
void channelGetConnect(
|
||||
const Status& status,
|
||||
ChannelGet::shared_pointer const & channelGet,
|
||||
StructureConstPtr const & structure)
|
||||
{easyGet->channelGetConnect(status,channelGet,structure);}
|
||||
{pvaClientGet->channelGetConnect(status,channelGet,structure);}
|
||||
void getDone(
|
||||
const Status& status,
|
||||
ChannelGet::shared_pointer const & channelGet,
|
||||
PVStructurePtr const & pvStructure,
|
||||
BitSetPtr const & bitSet)
|
||||
{easyGet->getDone(status,channelGet,pvStructure,bitSet);}
|
||||
{pvaClientGet->getDone(status,channelGet,pvStructure,bitSet);}
|
||||
};
|
||||
|
||||
EasyGet::EasyGet(
|
||||
EasyPVAPtr const &pva,
|
||||
EasyChannelPtr const & easyChannel,
|
||||
PvaClientGet::PvaClientGet(
|
||||
PvaClientPtr const &pvaClient,
|
||||
PvaClientChannelPtr const & pvaClientChannel,
|
||||
Channel::shared_pointer const & channel,
|
||||
PVStructurePtr const &pvRequest)
|
||||
: easyPVA(pva),
|
||||
easyChannel(easyChannel),
|
||||
: pvaClient(pvaClient),
|
||||
pvaClientChannel(pvaClientChannel),
|
||||
channel(channel),
|
||||
pvRequest(pvRequest),
|
||||
isDestroyed(false),
|
||||
@@ -60,67 +60,67 @@ EasyGet::EasyGet(
|
||||
{
|
||||
}
|
||||
|
||||
EasyGet::~EasyGet()
|
||||
PvaClientGet::~PvaClientGet()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
void EasyGet::checkGetState()
|
||||
void PvaClientGet::checkGetState()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
|
||||
if(connectState==connectIdle) connect();
|
||||
if(getState==getIdle) get();
|
||||
}
|
||||
|
||||
// from ChannelGetRequester
|
||||
string EasyGet::getRequesterName()
|
||||
string PvaClientGet::getRequesterName()
|
||||
{
|
||||
EasyPVAPtr yyy = easyPVA.lock();
|
||||
if(!yyy) throw std::runtime_error("easyPVA was destroyed");
|
||||
PvaClientPtr yyy = pvaClient.lock();
|
||||
if(!yyy) throw std::runtime_error("pvaClient was destroyed");
|
||||
return yyy->getRequesterName();
|
||||
}
|
||||
|
||||
void EasyGet::message(string const & message,MessageType messageType)
|
||||
void PvaClientGet::message(string const & message,MessageType messageType)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
|
||||
EasyPVAPtr yyy = easyPVA.lock();
|
||||
if(!yyy) throw std::runtime_error("easyPVA was destroyed");
|
||||
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 EasyGet::channelGetConnect(
|
||||
void PvaClientGet::channelGetConnect(
|
||||
const Status& status,
|
||||
ChannelGet::shared_pointer const & channelGet,
|
||||
StructureConstPtr const & structure)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
|
||||
channelGetConnectStatus = status;
|
||||
this->channelGet = channelGet;
|
||||
if(status.isOK()) {
|
||||
easyData = EasyGetData::create(structure);
|
||||
easyData->setMessagePrefix(channel->getChannelName());
|
||||
pvaClientData = PvaClientGetData::create(structure);
|
||||
pvaClientData->setMessagePrefix(channel->getChannelName());
|
||||
}
|
||||
waitForConnect.signal();
|
||||
|
||||
}
|
||||
|
||||
void EasyGet::getDone(
|
||||
void PvaClientGet::getDone(
|
||||
const Status& status,
|
||||
ChannelGet::shared_pointer const & channelGet,
|
||||
PVStructurePtr const & pvStructure,
|
||||
BitSetPtr const & bitSet)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
|
||||
channelGetStatus = status;
|
||||
if(status.isOK()) {
|
||||
easyData->setData(pvStructure,bitSet);
|
||||
pvaClientData->setData(pvStructure,bitSet);
|
||||
}
|
||||
waitForGet.signal();
|
||||
}
|
||||
|
||||
|
||||
// from EasyGet
|
||||
void EasyGet::destroy()
|
||||
// from PvaClientGet
|
||||
void PvaClientGet::destroy()
|
||||
{
|
||||
{
|
||||
Lock xx(mutex);
|
||||
@@ -131,23 +131,23 @@ void EasyGet::destroy()
|
||||
channelGet.reset();
|
||||
}
|
||||
|
||||
void EasyGet::connect()
|
||||
void PvaClientGet::connect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
|
||||
issueConnect();
|
||||
Status status = waitConnect();
|
||||
if(status.isOK()) return;
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyGet::connect " << status.getMessage();
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientGet::connect " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void EasyGet::issueConnect()
|
||||
void PvaClientGet::issueConnect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
|
||||
if(connectState!=connectIdle) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " easyGet already connected ";
|
||||
ss << "channel " << channel->getChannelName() << " pvaClientGet already connected ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
getRequester = ChannelGetRequester::shared_pointer(new ChannelGetRequesterImpl(this));
|
||||
@@ -155,12 +155,12 @@ void EasyGet::issueConnect()
|
||||
channelGet = channel->createChannelGet(getRequester,pvRequest);
|
||||
}
|
||||
|
||||
Status EasyGet::waitConnect()
|
||||
Status PvaClientGet::waitConnect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
|
||||
if(connectState!=connectActive) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " easyGet illegal connect state ";
|
||||
ss << "channel " << channel->getChannelName() << " pvaClientGet illegal connect state ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
waitForConnect.wait();
|
||||
@@ -172,36 +172,36 @@ Status EasyGet::waitConnect()
|
||||
return Status(Status::STATUSTYPE_ERROR,channelGetConnectStatus.getMessage());
|
||||
}
|
||||
|
||||
void EasyGet::get()
|
||||
void PvaClientGet::get()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
|
||||
issueGet();
|
||||
Status status = waitGet();
|
||||
if(status.isOK()) return;
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyGet::get " << status.getMessage();
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientGet::get " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void EasyGet::issueGet()
|
||||
void PvaClientGet::issueGet()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
|
||||
if(connectState==connectIdle) connect();
|
||||
if(getState!=getIdle) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyGet::issueGet get aleady active ";
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientGet::issueGet get aleady active ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
getState = getActive;
|
||||
channelGet->get();
|
||||
}
|
||||
|
||||
Status EasyGet::waitGet()
|
||||
Status PvaClientGet::waitGet()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
|
||||
if(getState!=getActive){
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyGet::waitGet llegal get state";
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientGet::waitGet llegal get state";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
waitForGet.wait();
|
||||
@@ -211,19 +211,19 @@ Status EasyGet::waitGet()
|
||||
}
|
||||
return Status(Status::STATUSTYPE_ERROR,channelGetStatus.getMessage());
|
||||
}
|
||||
EasyGetDataPtr EasyGet::getData()
|
||||
PvaClientGetDataPtr PvaClientGet::getData()
|
||||
{
|
||||
checkGetState();
|
||||
return easyData;
|
||||
return pvaClientData;
|
||||
}
|
||||
|
||||
EasyGetPtr EasyGet::create(
|
||||
EasyPVAPtr const &pva,
|
||||
EasyChannelPtr const & easyChannel,
|
||||
PvaClientGetPtr PvaClientGet::create(
|
||||
PvaClientPtr const &pvaClient,
|
||||
PvaClientChannelPtr const & pvaClientChannel,
|
||||
Channel::shared_pointer const & channel,
|
||||
PVStructurePtr const &pvRequest)
|
||||
{
|
||||
EasyGetPtr epv(new EasyGet(pva,easyChannel,channel,pvRequest));
|
||||
PvaClientGetPtr epv(new PvaClientGet(pvaClient,pvaClientChannel,channel,pvRequest));
|
||||
return epv;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* easyGetData.cpp */
|
||||
/* pvaClientGetData.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <typeinfo>
|
||||
|
||||
#include <sstream>
|
||||
#include <pv/easyPVA.h>
|
||||
#include <pv/pvaClient.h>
|
||||
#include <pv/createRequest.h>
|
||||
#include <pv/convert.h>
|
||||
|
||||
@@ -23,7 +23,7 @@ using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace easyPVA {
|
||||
namespace epics { namespace pvaClient {
|
||||
|
||||
|
||||
typedef std::tr1::shared_ptr<PVArray> PVArrayPtr;
|
||||
@@ -36,44 +36,46 @@ static string noArray("value is not an array");
|
||||
static string noScalarArray("value is not a scalarArray");
|
||||
static string notDoubleArray("value is not a doubleArray");
|
||||
static string notStringArray("value is not a stringArray");
|
||||
static string noAlarm("no alarm");
|
||||
static string noTimeStamp("no timeStamp");
|
||||
|
||||
EasyGetDataPtr EasyGetData::create(StructureConstPtr const & structure)
|
||||
PvaClientGetDataPtr PvaClientGetData::create(StructureConstPtr const & structure)
|
||||
{
|
||||
EasyGetDataPtr epv(new EasyGetData(structure));
|
||||
PvaClientGetDataPtr epv(new PvaClientGetData(structure));
|
||||
return epv;
|
||||
}
|
||||
|
||||
EasyGetData::EasyGetData(StructureConstPtr const & structure)
|
||||
PvaClientGetData::PvaClientGetData(StructureConstPtr const & structure)
|
||||
: structure(structure)
|
||||
{}
|
||||
|
||||
void EasyGetData::checkValue()
|
||||
void PvaClientGetData::checkValue()
|
||||
{
|
||||
if(pvValue) return;
|
||||
throw std::runtime_error(messagePrefix + noValue);
|
||||
}
|
||||
|
||||
void EasyGetData::setMessagePrefix(std::string const & value)
|
||||
void PvaClientGetData::setMessagePrefix(std::string const & value)
|
||||
{
|
||||
messagePrefix = value + " ";
|
||||
}
|
||||
|
||||
StructureConstPtr EasyGetData::getStructure()
|
||||
StructureConstPtr PvaClientGetData::getStructure()
|
||||
{return structure;}
|
||||
|
||||
PVStructurePtr EasyGetData::getPVStructure()
|
||||
PVStructurePtr PvaClientGetData::getPVStructure()
|
||||
{
|
||||
if(pvStructure) return pvStructure;
|
||||
throw std::runtime_error(messagePrefix + noStructure);
|
||||
}
|
||||
|
||||
BitSetPtr EasyGetData::getBitSet()
|
||||
BitSetPtr PvaClientGetData::getBitSet()
|
||||
{
|
||||
if(bitSet)return bitSet;
|
||||
throw std::runtime_error(messagePrefix + noStructure);
|
||||
}
|
||||
|
||||
std::ostream & EasyGetData::showChanged(std::ostream & out)
|
||||
std::ostream & PvaClientGetData::showChanged(std::ostream & out)
|
||||
{
|
||||
if(!bitSet) throw std::runtime_error(messagePrefix + noStructure);
|
||||
size_t nextSet = bitSet->nextSetBit(0);
|
||||
@@ -91,7 +93,7 @@ std::ostream & EasyGetData::showChanged(std::ostream & out)
|
||||
return out;
|
||||
}
|
||||
|
||||
void EasyGetData::setData(
|
||||
void PvaClientGetData::setData(
|
||||
PVStructurePtr const & pvStructureFrom,
|
||||
BitSetPtr const & bitSetFrom)
|
||||
{
|
||||
@@ -100,33 +102,33 @@ void EasyGetData::setData(
|
||||
pvValue = pvStructure->getSubField("value");
|
||||
}
|
||||
|
||||
bool EasyGetData::hasValue()
|
||||
bool PvaClientGetData::hasValue()
|
||||
{
|
||||
if(!pvValue) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EasyGetData::isValueScalar()
|
||||
bool PvaClientGetData::isValueScalar()
|
||||
{
|
||||
if(!pvValue) return false;
|
||||
if(pvValue->getField()->getType()==scalar) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool EasyGetData::isValueScalarArray()
|
||||
bool PvaClientGetData::isValueScalarArray()
|
||||
{
|
||||
if(!pvValue) return false;
|
||||
if(pvValue->getField()->getType()==scalarArray) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
PVFieldPtr EasyGetData::getValue()
|
||||
PVFieldPtr PvaClientGetData::getValue()
|
||||
{
|
||||
checkValue();
|
||||
return pvValue;
|
||||
}
|
||||
|
||||
PVScalarPtr EasyGetData::getScalarValue()
|
||||
PVScalarPtr PvaClientGetData::getScalarValue()
|
||||
{
|
||||
checkValue();
|
||||
PVScalarPtr pv = pvStructure->getSubField<PVScalar>("value");
|
||||
@@ -136,7 +138,7 @@ PVScalarPtr EasyGetData::getScalarValue()
|
||||
return pv;
|
||||
}
|
||||
|
||||
PVArrayPtr EasyGetData::getArrayValue()
|
||||
PVArrayPtr PvaClientGetData::getArrayValue()
|
||||
{
|
||||
checkValue();
|
||||
PVArrayPtr pv = pvStructure->getSubField<PVArray>("value");
|
||||
@@ -146,7 +148,7 @@ PVArrayPtr EasyGetData::getArrayValue()
|
||||
return pv;
|
||||
}
|
||||
|
||||
PVScalarArrayPtr EasyGetData::getScalarArrayValue()
|
||||
PVScalarArrayPtr PvaClientGetData::getScalarArrayValue()
|
||||
{
|
||||
checkValue();
|
||||
PVScalarArrayPtr pv = pvStructure->getSubField<PVScalarArray>("value");
|
||||
@@ -156,7 +158,7 @@ PVScalarArrayPtr EasyGetData::getScalarArrayValue()
|
||||
return pv;
|
||||
}
|
||||
|
||||
double EasyGetData::getDouble()
|
||||
double PvaClientGetData::getDouble()
|
||||
{
|
||||
PVScalarPtr pvScalar = getScalarValue();
|
||||
ScalarType scalarType = pvScalar->getScalar()->getScalarType();
|
||||
@@ -170,13 +172,13 @@ double EasyGetData::getDouble()
|
||||
return convert->toDouble(pvScalar);
|
||||
}
|
||||
|
||||
string EasyGetData::getString()
|
||||
string PvaClientGetData::getString()
|
||||
{
|
||||
PVScalarPtr pvScalar = getScalarValue();
|
||||
return convert->toString(pvScalar);
|
||||
}
|
||||
|
||||
shared_vector<const double> EasyGetData::getDoubleArray()
|
||||
shared_vector<const double> PvaClientGetData::getDoubleArray()
|
||||
{
|
||||
checkValue();
|
||||
PVDoubleArrayPtr pv = pvStructure->getSubField<PVDoubleArray>("value");
|
||||
@@ -186,7 +188,7 @@ shared_vector<const double> EasyGetData::getDoubleArray()
|
||||
return pv->view();
|
||||
}
|
||||
|
||||
shared_vector<const string> EasyGetData::getStringArray()
|
||||
shared_vector<const string> PvaClientGetData::getStringArray()
|
||||
{
|
||||
checkValue();
|
||||
PVStringArrayPtr pv = pvStructure->getSubField<PVStringArray>("value");
|
||||
@@ -194,7 +196,41 @@ shared_vector<const string> EasyGetData::getStringArray()
|
||||
throw std::runtime_error(messagePrefix + notStringArray);
|
||||
}
|
||||
return pv->view();
|
||||
}
|
||||
|
||||
|
||||
Alarm PvaClientGetData::getAlarm()
|
||||
{
|
||||
if(!pvStructure) {
|
||||
throw std::runtime_error(messagePrefix + noAlarm);
|
||||
}
|
||||
PVStructurePtr pvs = pvStructure->getSubField<PVStructure>("alarm");
|
||||
if(!pvs) throw std::runtime_error(messagePrefix + noAlarm);
|
||||
pvAlarm.attach(pvs);
|
||||
if(pvAlarm.isAttached()) {
|
||||
Alarm alarm;
|
||||
pvAlarm.get(alarm);
|
||||
pvAlarm.detach();
|
||||
return alarm;
|
||||
}
|
||||
throw std::runtime_error(messagePrefix + noAlarm);
|
||||
}
|
||||
|
||||
TimeStamp PvaClientGetData::getTimeStamp()
|
||||
{
|
||||
if(!pvStructure) {
|
||||
throw std::runtime_error(messagePrefix + noTimeStamp);
|
||||
}
|
||||
PVStructurePtr pvs = pvStructure->getSubField<PVStructure>("timeStamp");
|
||||
if(!pvs) throw std::runtime_error(messagePrefix + noTimeStamp);
|
||||
pvTimeStamp.attach(pvs);
|
||||
if(pvTimeStamp.isAttached()) {
|
||||
TimeStamp timeStamp;
|
||||
pvTimeStamp.get(timeStamp);
|
||||
pvTimeStamp.detach();
|
||||
return timeStamp;
|
||||
}
|
||||
throw std::runtime_error(messagePrefix + noTimeStamp);
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,250 @@
|
||||
/* pvaClientMonitor.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.03
|
||||
*/
|
||||
#define epicsExportSharedSymbols
|
||||
|
||||
#include <sstream>
|
||||
#include <pv/event.h>
|
||||
#include <pv/pvaClient.h>
|
||||
#include <pv/bitSetUtil.h>
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvaClient {
|
||||
|
||||
|
||||
class ChannelMonitorRequester : public MonitorRequester
|
||||
{
|
||||
PvaClientMonitor * pvaClientMonitor;
|
||||
public:
|
||||
ChannelMonitorRequester(PvaClientMonitor * pvaClientMonitor)
|
||||
: pvaClientMonitor(pvaClientMonitor) {}
|
||||
string getRequesterName()
|
||||
{return pvaClientMonitor->getRequesterName();}
|
||||
void message(string const & message,MessageType messageType)
|
||||
{pvaClientMonitor->message(message,messageType);}
|
||||
void monitorConnect(
|
||||
const Status& status,
|
||||
Monitor::shared_pointer const & monitor,
|
||||
StructureConstPtr const & structure)
|
||||
{pvaClientMonitor->monitorConnect(status,monitor,structure);}
|
||||
void monitorEvent(MonitorPtr const & monitor)
|
||||
{
|
||||
pvaClientMonitor->monitorEvent(monitor);
|
||||
}
|
||||
void unlisten(MonitorPtr const & monitor)
|
||||
{pvaClientMonitor->unlisten();}
|
||||
};
|
||||
|
||||
PvaClientMonitor::PvaClientMonitor(
|
||||
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),
|
||||
userPoll(false),
|
||||
userWait(false)
|
||||
{
|
||||
}
|
||||
|
||||
PvaClientMonitor::~PvaClientMonitor()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
void PvaClientMonitor::checkMonitorState()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
|
||||
if(connectState==connectIdle) connect();
|
||||
if(connectState==connected) start();
|
||||
}
|
||||
|
||||
// from MonitorRequester
|
||||
string PvaClientMonitor::getRequesterName()
|
||||
{
|
||||
PvaClientPtr yyy = pvaClient.lock();
|
||||
if(!yyy) throw std::runtime_error("pvaClient was destroyed");
|
||||
return yyy->getRequesterName();
|
||||
}
|
||||
|
||||
void PvaClientMonitor::message(string const & message,MessageType messageType)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
|
||||
PvaClientPtr yyy = pvaClient.lock();
|
||||
if(!yyy) throw std::runtime_error("pvaClient was destroyed");
|
||||
yyy->message(message, messageType);
|
||||
}
|
||||
|
||||
void PvaClientMonitor::monitorConnect(
|
||||
const Status& status,
|
||||
Monitor::shared_pointer const & monitor,
|
||||
StructureConstPtr const & structure)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
|
||||
connectStatus = status;
|
||||
this->monitor = monitor;
|
||||
if(status.isOK()) {
|
||||
pvaClientData = PvaClientMonitorData::create(structure);
|
||||
pvaClientData->setMessagePrefix(channel->getChannelName());
|
||||
}
|
||||
waitForConnect.signal();
|
||||
|
||||
}
|
||||
|
||||
void PvaClientMonitor::monitorEvent(MonitorPtr const & monitor)
|
||||
{
|
||||
PvaClientMonitorRequesterPtr req = pvaClientMonitorRequester.lock();
|
||||
if(req) req->event(getPtrSelf());
|
||||
if(userWait) waitForEvent.signal();
|
||||
}
|
||||
|
||||
void PvaClientMonitor::unlisten()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
// from PvaClientMonitor
|
||||
void PvaClientMonitor::destroy()
|
||||
{
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) return;
|
||||
isDestroyed = true;
|
||||
}
|
||||
if(monitor) monitor->destroy();
|
||||
monitor.reset();
|
||||
}
|
||||
|
||||
void PvaClientMonitor::connect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
|
||||
issueConnect();
|
||||
Status status = waitConnect();
|
||||
if(status.isOK()) return;
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientMonitor::connect " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void PvaClientMonitor::issueConnect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
|
||||
if(connectState!=connectIdle) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " pvaClientMonitor already connected ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
monitorRequester = ChannelMonitorRequester::shared_pointer(new ChannelMonitorRequester(this));
|
||||
connectState = connectActive;
|
||||
monitor = channel->createMonitor(monitorRequester,pvRequest);
|
||||
}
|
||||
|
||||
Status PvaClientMonitor::waitConnect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
|
||||
if(connectState!=connectActive) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " pvaClientMonitor illegal connect state ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
waitForConnect.wait();
|
||||
if(connectStatus.isOK()){
|
||||
connectState = connected;
|
||||
return Status::Ok;
|
||||
}
|
||||
connectState = connectIdle;
|
||||
return Status(Status::STATUSTYPE_ERROR,connectStatus.getMessage());
|
||||
}
|
||||
|
||||
void PvaClientMonitor::setRequester(PvaClientMonitorRequesterPtr const & pvaClientMonitorrRequester)
|
||||
{
|
||||
this->pvaClientMonitorRequester = pvaClientMonitorrRequester;
|
||||
}
|
||||
|
||||
void PvaClientMonitor::start()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
|
||||
if(connectState==monitorStarted) return;
|
||||
if(connectState==connectIdle) connect();
|
||||
if(connectState!=connected) throw std::runtime_error("PvaClientMonitor::start illegal state");
|
||||
connectState = monitorStarted;
|
||||
monitor->start();
|
||||
}
|
||||
|
||||
|
||||
void PvaClientMonitor::stop()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
|
||||
if(connectState!=monitorStarted) return;
|
||||
connectState = connected;
|
||||
monitor->stop();
|
||||
}
|
||||
|
||||
bool PvaClientMonitor::poll()
|
||||
{
|
||||
checkMonitorState();
|
||||
if(connectState!=monitorStarted) throw std::runtime_error("PvaClientMonitor::poll illegal state");
|
||||
if(userPoll) throw std::runtime_error("PvaClientMonitor::poll did not release last");
|
||||
monitorElement = monitor->poll();
|
||||
if(!monitorElement) return false;
|
||||
userPoll = true;
|
||||
pvaClientData->setData(monitorElement);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PvaClientMonitor::waitEvent(double secondsToWait)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
|
||||
if(connectState!=monitorStarted) throw std::runtime_error("PvaClientMonitor::poll illegal state");
|
||||
if(poll()) return true;
|
||||
userWait = true;
|
||||
if(secondsToWait==0.0) {
|
||||
waitForEvent.wait();
|
||||
} else {
|
||||
waitForEvent.wait(secondsToWait);
|
||||
}
|
||||
userWait = false;
|
||||
return poll();
|
||||
}
|
||||
|
||||
void PvaClientMonitor::releaseEvent()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
|
||||
if(connectState!=monitorStarted) throw std::runtime_error("PvaClientMonitor::poll illegal state");
|
||||
if(!userPoll) throw std::runtime_error("PvaClientMonitor::releaseEvent did not call poll");
|
||||
userPoll = false;
|
||||
monitor->release(monitorElement);
|
||||
}
|
||||
|
||||
PvaClientMonitorDataPtr PvaClientMonitor::getData()
|
||||
{
|
||||
checkMonitorState();
|
||||
return pvaClientData;
|
||||
}
|
||||
|
||||
PvaClientMonitorPtr PvaClientMonitor::create(
|
||||
PvaClientPtr const &pvaClient,
|
||||
PvaClientChannelPtr const & pvaClientChannel,
|
||||
Channel::shared_pointer const & channel,
|
||||
PVStructurePtr const &pvRequest)
|
||||
{
|
||||
PvaClientMonitorPtr epv(new PvaClientMonitor(pvaClient,pvaClientChannel,channel,pvRequest));
|
||||
return epv;
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* easyMonitorData.cpp */
|
||||
/* pvaClientMonitorData.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <typeinfo>
|
||||
|
||||
#include <sstream>
|
||||
#include <pv/easyPVA.h>
|
||||
#include <pv/pvaClient.h>
|
||||
#include <pv/createRequest.h>
|
||||
#include <pv/convert.h>
|
||||
|
||||
@@ -23,7 +23,7 @@ using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace easyPVA {
|
||||
namespace epics { namespace pvaClient {
|
||||
|
||||
|
||||
typedef std::tr1::shared_ptr<PVArray> PVArrayPtr;
|
||||
@@ -39,50 +39,50 @@ static string noScalarArray("value is not a scalarArray");
|
||||
static string notDoubleArray("value is not a doubleArray");
|
||||
static string notStringArray("value is not a stringArray");
|
||||
|
||||
EasyMonitorDataPtr EasyMonitorData::create(StructureConstPtr const & structure)
|
||||
PvaClientMonitorDataPtr PvaClientMonitorData::create(StructureConstPtr const & structure)
|
||||
{
|
||||
EasyMonitorDataPtr epv(new EasyMonitorData(structure));
|
||||
PvaClientMonitorDataPtr epv(new PvaClientMonitorData(structure));
|
||||
return epv;
|
||||
}
|
||||
|
||||
EasyMonitorData::EasyMonitorData(StructureConstPtr const & structure)
|
||||
PvaClientMonitorData::PvaClientMonitorData(StructureConstPtr const & structure)
|
||||
: structure(structure)
|
||||
{}
|
||||
|
||||
|
||||
void EasyMonitorData::checkValue()
|
||||
void PvaClientMonitorData::checkValue()
|
||||
{
|
||||
if(pvValue) return;
|
||||
throw std::runtime_error(messagePrefix + noValue);
|
||||
}
|
||||
|
||||
void EasyMonitorData::setMessagePrefix(std::string const & value)
|
||||
void PvaClientMonitorData::setMessagePrefix(std::string const & value)
|
||||
{
|
||||
messagePrefix = value + " ";
|
||||
}
|
||||
|
||||
StructureConstPtr EasyMonitorData::getStructure()
|
||||
StructureConstPtr PvaClientMonitorData::getStructure()
|
||||
{return structure;}
|
||||
|
||||
PVStructurePtr EasyMonitorData::getPVStructure()
|
||||
PVStructurePtr PvaClientMonitorData::getPVStructure()
|
||||
{
|
||||
if(pvStructure) return pvStructure;
|
||||
throw std::runtime_error(messagePrefix + noStructure);
|
||||
}
|
||||
|
||||
BitSetPtr EasyMonitorData::getChangedBitSet()
|
||||
BitSetPtr PvaClientMonitorData::getChangedBitSet()
|
||||
{
|
||||
if(!changedBitSet) throw std::runtime_error(messagePrefix + noStructure);
|
||||
return changedBitSet;
|
||||
}
|
||||
|
||||
BitSetPtr EasyMonitorData::getOverrunBitSet()
|
||||
BitSetPtr PvaClientMonitorData::getOverrunBitSet()
|
||||
{
|
||||
if(!overrunBitSet) throw std::runtime_error(messagePrefix + noStructure);
|
||||
return overrunBitSet;
|
||||
}
|
||||
|
||||
std::ostream & EasyMonitorData::showChanged(std::ostream & out)
|
||||
std::ostream & PvaClientMonitorData::showChanged(std::ostream & out)
|
||||
{
|
||||
if(!changedBitSet) throw std::runtime_error(messagePrefix + noStructure);
|
||||
size_t nextSet = changedBitSet->nextSetBit(0);
|
||||
@@ -100,7 +100,7 @@ std::ostream & EasyMonitorData::showChanged(std::ostream & out)
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream & EasyMonitorData::showOverrun(std::ostream & out)
|
||||
std::ostream & PvaClientMonitorData::showOverrun(std::ostream & out)
|
||||
{
|
||||
if(!overrunBitSet) throw std::runtime_error(messagePrefix + noStructure);
|
||||
size_t nextSet = overrunBitSet->nextSetBit(0);
|
||||
@@ -118,7 +118,7 @@ std::ostream & EasyMonitorData::showOverrun(std::ostream & out)
|
||||
return out;
|
||||
}
|
||||
|
||||
void EasyMonitorData::setData(MonitorElementPtr const & monitorElement)
|
||||
void PvaClientMonitorData::setData(MonitorElementPtr const & monitorElement)
|
||||
{
|
||||
pvStructure = monitorElement->pvStructurePtr;
|
||||
changedBitSet = monitorElement->changedBitSet;
|
||||
@@ -126,33 +126,33 @@ void EasyMonitorData::setData(MonitorElementPtr const & monitorElement)
|
||||
pvValue = pvStructure->getSubField("value");
|
||||
}
|
||||
|
||||
bool EasyMonitorData::hasValue()
|
||||
bool PvaClientMonitorData::hasValue()
|
||||
{
|
||||
if(!pvValue) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EasyMonitorData::isValueScalar()
|
||||
bool PvaClientMonitorData::isValueScalar()
|
||||
{
|
||||
if(!pvValue) return false;
|
||||
if(pvValue->getField()->getType()==scalar) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool EasyMonitorData::isValueScalarArray()
|
||||
bool PvaClientMonitorData::isValueScalarArray()
|
||||
{
|
||||
if(!pvValue) return false;
|
||||
if(pvValue->getField()->getType()==scalarArray) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
PVFieldPtr EasyMonitorData::getValue()
|
||||
PVFieldPtr PvaClientMonitorData::getValue()
|
||||
{
|
||||
checkValue();
|
||||
return pvValue;
|
||||
}
|
||||
|
||||
PVScalarPtr EasyMonitorData::getScalarValue()
|
||||
PVScalarPtr PvaClientMonitorData::getScalarValue()
|
||||
{
|
||||
checkValue();
|
||||
PVScalarPtr pv = pvStructure->getSubField<PVScalar>("value");
|
||||
@@ -162,7 +162,7 @@ PVScalarPtr EasyMonitorData::getScalarValue()
|
||||
return pv;
|
||||
}
|
||||
|
||||
PVArrayPtr EasyMonitorData::getArrayValue()
|
||||
PVArrayPtr PvaClientMonitorData::getArrayValue()
|
||||
{
|
||||
checkValue();
|
||||
PVArrayPtr pv = pvStructure->getSubField<PVArray>("value");
|
||||
@@ -172,7 +172,7 @@ PVArrayPtr EasyMonitorData::getArrayValue()
|
||||
return pv;
|
||||
}
|
||||
|
||||
PVScalarArrayPtr EasyMonitorData::getScalarArrayValue()
|
||||
PVScalarArrayPtr PvaClientMonitorData::getScalarArrayValue()
|
||||
{
|
||||
checkValue();
|
||||
PVScalarArrayPtr pv = pvStructure->getSubField<PVScalarArray>("value");
|
||||
@@ -182,7 +182,7 @@ PVScalarArrayPtr EasyMonitorData::getScalarArrayValue()
|
||||
return pv;
|
||||
}
|
||||
|
||||
double EasyMonitorData::getDouble()
|
||||
double PvaClientMonitorData::getDouble()
|
||||
{
|
||||
PVScalarPtr pvScalar = getScalarValue();
|
||||
ScalarType scalarType = pvScalar->getScalar()->getScalarType();
|
||||
@@ -196,13 +196,13 @@ double EasyMonitorData::getDouble()
|
||||
return convert->toDouble(pvScalar);
|
||||
}
|
||||
|
||||
string EasyMonitorData::getString()
|
||||
string PvaClientMonitorData::getString()
|
||||
{
|
||||
PVScalarPtr pvScalar = getScalarValue();
|
||||
return convert->toString(pvScalar);
|
||||
}
|
||||
|
||||
shared_vector<const double> EasyMonitorData::getDoubleArray()
|
||||
shared_vector<const double> PvaClientMonitorData::getDoubleArray()
|
||||
{
|
||||
checkValue();
|
||||
PVDoubleArrayPtr pv = pvStructure->getSubField<PVDoubleArray>("value");
|
||||
@@ -212,7 +212,7 @@ shared_vector<const double> EasyMonitorData::getDoubleArray()
|
||||
return pv->view();
|
||||
}
|
||||
|
||||
shared_vector<const string> EasyMonitorData::getStringArray()
|
||||
shared_vector<const string> PvaClientMonitorData::getStringArray()
|
||||
{
|
||||
checkValue();
|
||||
PVStringArrayPtr pv = pvStructure->getSubField<PVStringArray>("value");
|
||||
@@ -0,0 +1,165 @@
|
||||
/* pvaClientMultiChannel.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 <map>
|
||||
#include <sstream>
|
||||
#include <pv/event.h>
|
||||
#include <pv/lock.h>
|
||||
#include <pv/pvaClient.h>
|
||||
#include <pv/createRequest.h>
|
||||
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvaClient {
|
||||
|
||||
|
||||
|
||||
PvaClientMultiChannel::PvaClientMultiChannel(
|
||||
PvaClientPtr const &pvaClient,
|
||||
PVStringArrayPtr const & channelName,
|
||||
string const & providerName)
|
||||
: pvaClient(pvaClient),
|
||||
channelName(channelName),
|
||||
providerName(providerName),
|
||||
numChannel(channelName->getLength()),
|
||||
isConnected(getPVDataCreate()->createPVScalarArray<PVBooleanArray>()),
|
||||
isDestroyed(false)
|
||||
{
|
||||
}
|
||||
|
||||
PvaClientMultiChannel::~PvaClientMultiChannel()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
void PvaClientMultiChannel::destroy()
|
||||
{
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) return;
|
||||
isDestroyed = true;
|
||||
}
|
||||
pvaClientChannelArray.reset();
|
||||
}
|
||||
|
||||
PVStringArrayPtr PvaClientMultiChannel::getChannelNames()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientMultiChannel was destroyed");
|
||||
return channelName;
|
||||
}
|
||||
|
||||
Status PvaClientMultiChannel::connect(double timeout,size_t maxNotConnected)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientMultiChannel was destroyed");
|
||||
if(pvaClientChannelArray) throw std::runtime_error("pvaClientMultiChannel already connected");
|
||||
PvaClientPtr pvaClient = this->pvaClient.lock();
|
||||
if(!pvaClient) return Status(Status::STATUSTYPE_ERROR,"pvaClient is gone");
|
||||
shared_vector<PvaClientChannelPtr> pvaClientChannel(numChannel,PvaClientChannelPtr());
|
||||
PVStringArray::const_svector channelNames = channelName->view();
|
||||
shared_vector<boolean> isConnected(numChannel,false);
|
||||
for(size_t i=0; i< numChannel; ++i) {
|
||||
pvaClientChannel[i] = pvaClient->createChannel(channelNames[i],providerName);
|
||||
pvaClientChannel[i]->issueConnect();
|
||||
}
|
||||
Status returnStatus = Status::Ok;
|
||||
Status status = Status::Ok;
|
||||
size_t numBad = 0;
|
||||
for(size_t i=0; i< numChannel; ++i) {
|
||||
if(numBad==0) {
|
||||
status = pvaClientChannel[i]->waitConnect(timeout);
|
||||
} else {
|
||||
status = pvaClientChannel[i]->waitConnect(.001);
|
||||
}
|
||||
if(status.isOK()) {
|
||||
++numConnected;
|
||||
isConnected[i] = true;
|
||||
continue;
|
||||
}
|
||||
if(returnStatus.isOK()) returnStatus = status;
|
||||
++numBad;
|
||||
if(numBad>maxNotConnected) break;
|
||||
}
|
||||
pvaClientChannelArray = PvaClientChannelArrayPtr(new PvaClientChannelArray(freeze(pvaClientChannel)));
|
||||
this->isConnected->replace(freeze(isConnected));
|
||||
return numBad>maxNotConnected ? returnStatus : Status::Ok;
|
||||
}
|
||||
|
||||
|
||||
bool PvaClientMultiChannel::allConnected()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientMultiChannel was destroyed");
|
||||
if(!pvaClientChannelArray) throw std::runtime_error("pvaClientMultiChannel not connected");
|
||||
if(numConnected==numChannel) return true;
|
||||
return (numConnected==numChannel) ? true : false;
|
||||
}
|
||||
|
||||
bool PvaClientMultiChannel::connectionChange()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientMultiChannel was destroyed");
|
||||
if(!pvaClientChannelArray) throw std::runtime_error("pvaClientMultiChannel not connected");
|
||||
if(numConnected==numChannel) return true;
|
||||
PVBooleanArray::const_svector isConnected = this->isConnected->view();
|
||||
shared_vector<const PvaClientChannelPtr> channels = *pvaClientChannelArray.get();
|
||||
for(size_t i=0; i<numChannel; ++i) {
|
||||
const PvaClientChannelPtr pvaClientChannel = channels[i];
|
||||
Channel::shared_pointer channel = pvaClientChannel->getChannel();
|
||||
Channel::ConnectionState stateNow = channel->getConnectionState();
|
||||
bool connectedNow = stateNow==Channel::CONNECTED ? true : false;
|
||||
if(connectedNow!=isConnected[i]) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
PVBooleanArrayPtr PvaClientMultiChannel::getIsConnected()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientMultiChannel was destroyed");
|
||||
if(!pvaClientChannelArray) throw std::runtime_error("pvaClientMultiChannel not connected");
|
||||
if(!connectionChange()) return isConnected;
|
||||
shared_vector<boolean> isConnected(numChannel,false);
|
||||
shared_vector<const PvaClientChannelPtr> channels = *pvaClientChannelArray.get();
|
||||
for(size_t i=0; i<numChannel; ++i) {
|
||||
const PvaClientChannelPtr pvaClientChannel = channels[i];
|
||||
Channel::shared_pointer channel = pvaClientChannel->getChannel();
|
||||
Channel::ConnectionState stateNow = channel->getConnectionState();
|
||||
if(stateNow==Channel::CONNECTED) isConnected[i] = true;
|
||||
}
|
||||
this->isConnected->replace(freeze(isConnected));
|
||||
return this->isConnected;
|
||||
}
|
||||
|
||||
PvaClientChannelArrayWPtr PvaClientMultiChannel::getPvaClientChannelArray()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientMultiChannel was destroyed");
|
||||
if(!pvaClientChannelArray) throw std::runtime_error("pvaClientMultiChannel not connected");
|
||||
return pvaClientChannelArray;
|
||||
}
|
||||
|
||||
PvaClient::weak_pointer PvaClientMultiChannel::getPvaClient()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientMultiChannel was destroyed");
|
||||
return pvaClient;
|
||||
}
|
||||
|
||||
PvaClientMultiChannelPtr PvaClientMultiChannel::create(
|
||||
PvaClientPtr const &pvaClient,
|
||||
PVStringArrayPtr const & channelNames,
|
||||
string const & providerName)
|
||||
{
|
||||
PvaClientMultiChannelPtr channel(new PvaClientMultiChannel(pvaClient,channelNames,providerName));
|
||||
return channel;
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,139 @@
|
||||
/* pvaClientMultiDouble.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.03
|
||||
*/
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include <pv/pvaClientMultiDouble.h>
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace pvaClient {
|
||||
|
||||
PvaClientMultiDoublePtr PvaClientMultiDouble::create(
|
||||
PvaClientPtr const & pvaClient,
|
||||
PVStringArrayPtr const & channelName,
|
||||
double timeout,
|
||||
std::string const & providerName)
|
||||
{
|
||||
PvaClientMultiChannelPtr pvaClientMultiChannel(
|
||||
PvaClientMultiChannel::create(pvaClient,channelName,providerName));
|
||||
Status status = pvaClientMultiChannel->connect(timeout,0);
|
||||
if(!status.isOK()) throw std::runtime_error(status.getMessage());
|
||||
return PvaClientMultiDoublePtr(new PvaClientMultiDouble(pvaClientMultiChannel));
|
||||
}
|
||||
|
||||
PvaClientMultiDouble::PvaClientMultiDouble(PvaClientMultiChannelPtr const &pvaClientMultiChannel)
|
||||
:
|
||||
pvaClientMultiChannel(pvaClientMultiChannel)
|
||||
{}
|
||||
|
||||
PvaClientMultiDouble::~PvaClientMultiDouble()
|
||||
{
|
||||
}
|
||||
|
||||
void PvaClientMultiDouble::createGet()
|
||||
{
|
||||
PvaClientChannelArrayPtr pvaClientChannelArray = pvaClientMultiChannel->getPvaClientChannelArray().lock();
|
||||
if(!pvaClientChannelArray) throw std::runtime_error("pvaClientChannelArray is gone");
|
||||
shared_vector<const PvaClientChannelPtr> pvaClientChannels = *pvaClientChannelArray;
|
||||
size_t numChannel = pvaClientChannels.size();
|
||||
pvaClientGet = std::vector<PvaClientGetPtr>(numChannel,PvaClientGetPtr());
|
||||
bool allOK = true;
|
||||
string message;
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
pvaClientGet[i] = pvaClientChannels[i]->createGet("value");
|
||||
pvaClientGet[i]->issueConnect();
|
||||
}
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
Status status = pvaClientGet[i]->waitConnect();
|
||||
if(!status.isOK()) {
|
||||
message = "connect status " + status.getMessage();
|
||||
allOK = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!allOK) throw std::runtime_error(message);
|
||||
}
|
||||
|
||||
void PvaClientMultiDouble::createPut()
|
||||
{
|
||||
PvaClientChannelArrayPtr pvaClientChannelArray = pvaClientMultiChannel->getPvaClientChannelArray().lock();
|
||||
if(!pvaClientChannelArray) throw std::runtime_error("pvaClientChannelArray is gone");
|
||||
shared_vector<const PvaClientChannelPtr> pvaClientChannels = *pvaClientChannelArray;
|
||||
size_t numChannel = pvaClientChannels.size();
|
||||
pvaClientPut = std::vector<PvaClientPutPtr>(numChannel,PvaClientPutPtr());
|
||||
bool allOK = true;
|
||||
string message;
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
pvaClientPut[i] = pvaClientChannels[i]->createPut("value");
|
||||
pvaClientPut[i]->issueConnect();
|
||||
}
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
Status status = pvaClientPut[i]->waitConnect();
|
||||
if(!status.isOK()) {
|
||||
message = "connect status " + status.getMessage();
|
||||
allOK = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!allOK) throw std::runtime_error(message);
|
||||
}
|
||||
|
||||
epics::pvData::shared_vector<double> PvaClientMultiDouble::get()
|
||||
{
|
||||
if(pvaClientGet.empty()) createGet();
|
||||
shared_vector<const string> channelNames = pvaClientMultiChannel->getChannelNames()->view();
|
||||
size_t numChannel = channelNames.size();
|
||||
epics::pvData::shared_vector<double> data(channelNames.size());
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
pvaClientGet[i]->issueGet();
|
||||
}
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
Status status = pvaClientGet[i]->waitGet();
|
||||
if(!status.isOK()) {
|
||||
string message = channelNames[i] + " " + status.getMessage();
|
||||
throw std::runtime_error(message);
|
||||
}
|
||||
data[i] = pvaClientGet[i]->getData()->getDouble();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
void PvaClientMultiDouble::put(shared_vector<double> const &value)
|
||||
{
|
||||
if(pvaClientPut.empty()) createPut();
|
||||
shared_vector<const string> channelNames = pvaClientMultiChannel->getChannelNames()->view();
|
||||
size_t numChannel = channelNames.size();
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
pvaClientPut[i]->getData()->putDouble(value[i]);
|
||||
pvaClientPut[i]->issuePut();
|
||||
}
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
Status status = pvaClientPut[i]->waitPut();
|
||||
if(!status.isOK()) {
|
||||
string message = channelNames[i] + " " + status.getMessage();
|
||||
throw std::runtime_error(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* easyMultiDouble.h */
|
||||
/* pvaClientMultiDouble.h */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
@@ -8,20 +8,20 @@
|
||||
* @author mrk
|
||||
* @date 2015.02
|
||||
*/
|
||||
#ifndef EASYMULTIDOUBLE_H
|
||||
#define EASYMULTIDOUBLE_H
|
||||
#ifndef PVACLIENTMULTIDOUBLE_H
|
||||
#define PVACLIENTMULTIDOUBLE_H
|
||||
|
||||
#ifdef epicsExportSharedSymbols
|
||||
# define easyPVAEpicsExportSharedSymbols
|
||||
# define pvaClientEpicsExportSharedSymbols
|
||||
# undef epicsExportSharedSymbols
|
||||
#endif
|
||||
|
||||
#include <pv/easyPVA.h>
|
||||
#include <pv/pvaClient.h>
|
||||
|
||||
namespace epics { namespace easyPVA {
|
||||
namespace epics { namespace pvaClient {
|
||||
|
||||
class EasyMultiDouble;
|
||||
typedef std::tr1::shared_ptr<EasyMultiDouble> EasyMultiDoublePtr;
|
||||
class PvaClientMultiDouble;
|
||||
typedef std::tr1::shared_ptr<PvaClientMultiDouble> PvaClientMultiDoublePtr;
|
||||
|
||||
/**
|
||||
* @brief Support for multiple channels where each channel has a value field that is a scalar double.
|
||||
@@ -29,27 +29,27 @@ typedef std::tr1::shared_ptr<EasyMultiDouble> EasyMultiDoublePtr;
|
||||
*
|
||||
* @author mrk
|
||||
*/
|
||||
class epicsShareClass EasyMultiDouble
|
||||
class epicsShareClass PvaClientMultiDouble
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(EasyMultiDouble);
|
||||
POINTER_DEFINITIONS(PvaClientMultiDouble);
|
||||
/**
|
||||
* @brief Create a EasyMultiDouble.
|
||||
* @param &easyPVA Interface to EasyPVA
|
||||
* @brief Create a PvaClientMultiDouble.
|
||||
* @param &pvaClient Interface to PvaClient
|
||||
* @param channelName PVStringArray of channelNames.
|
||||
* @param timeout The timeout in seconds for connecting.
|
||||
* @param providerName The name of the channelProvider for each channel.
|
||||
* @return The interface to EasyMultiDouble.
|
||||
* @return The interface to PvaClientMultiDouble.
|
||||
*/
|
||||
static EasyMultiDoublePtr create(
|
||||
EasyPVAPtr const & easyPVA,
|
||||
static PvaClientMultiDoublePtr create(
|
||||
PvaClientPtr const & pvaClient,
|
||||
epics::pvData::PVStringArrayPtr const & channelName,
|
||||
double timeout = 5.0,
|
||||
std::string const & providerName = "pva");
|
||||
/**
|
||||
* @brief destructor
|
||||
*/
|
||||
~EasyMultiDouble();
|
||||
~PvaClientMultiDouble();
|
||||
/**
|
||||
* @brief destroy any resources used.
|
||||
*/
|
||||
@@ -64,18 +64,18 @@ public:
|
||||
* @param value The data.
|
||||
*/
|
||||
void put(epics::pvData::shared_vector<double> const &value);
|
||||
EasyMultiChannelPtr getEasyMultiChannel();
|
||||
PvaClientMultiChannelPtr getPvaClientMultiChannel();
|
||||
private:
|
||||
EasyMultiDouble(
|
||||
EasyMultiChannelPtr const & channelName);
|
||||
PvaClientMultiDouble(
|
||||
PvaClientMultiChannelPtr const & channelName);
|
||||
void createGet();
|
||||
void createPut();
|
||||
|
||||
EasyMultiChannelPtr easyMultiChannel;
|
||||
std::vector<EasyGetPtr> easyGet;
|
||||
std::vector<EasyPutPtr> easyPut;
|
||||
PvaClientMultiChannelPtr pvaClientMultiChannel;
|
||||
std::vector<PvaClientGetPtr> pvaClientGet;
|
||||
std::vector<PvaClientPutPtr> pvaClientPut;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif // EASYMULTIDOUBLE_H
|
||||
#endif // PVACLIENTMULTIDOUBLE_H
|
||||
@@ -1,4 +1,4 @@
|
||||
/* easyNTMultiChannel.cpp */
|
||||
/* pvaClientNTMultiChannel.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
@@ -9,7 +9,8 @@
|
||||
* @date 2015.03
|
||||
*/
|
||||
|
||||
#include <pv/easyNTMultiChannel.h>
|
||||
#define epicsExportSharedSymbols
|
||||
#include <pv/pvaClientNTMultiChannel.h>
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
using namespace epics::pvData;
|
||||
@@ -17,44 +18,44 @@ using namespace epics::pvAccess;
|
||||
using namespace epics::nt;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace easyPVA {
|
||||
namespace epics { namespace pvaClient {
|
||||
|
||||
EasyNTMultiChannelPtr EasyNTMultiChannel::create(
|
||||
EasyPVAPtr const & easyPVA,
|
||||
PvaClientNTMultiChannelPtr PvaClientNTMultiChannel::create(
|
||||
PvaClientPtr const & pvaClient,
|
||||
PVStringArrayPtr const & channelName,
|
||||
StructureConstPtr const &structure,
|
||||
double timeout,
|
||||
std::string const & providerName)
|
||||
{
|
||||
EasyMultiChannelPtr easyMultiChannel(
|
||||
EasyMultiChannel::create(easyPVA,channelName,providerName));
|
||||
Status status = easyMultiChannel->connect(timeout,0);
|
||||
PvaClientMultiChannelPtr pvaClientMultiChannel(
|
||||
PvaClientMultiChannel::create(pvaClient,channelName,providerName));
|
||||
Status status = pvaClientMultiChannel->connect(timeout,0);
|
||||
if(!status.isOK()) throw std::runtime_error(status.getMessage());
|
||||
if(!NTMultiChannel::is_a(structure)) throw std::runtime_error("structure is not valid");
|
||||
PVStructurePtr pvStructure = getPVDataCreate()->createPVStructure(structure);
|
||||
pvStructure->getSubField<PVStringArray>("channelName")->
|
||||
replace(easyMultiChannel->getChannelNames()->view());
|
||||
replace(pvaClientMultiChannel->getChannelNames()->view());
|
||||
pvStructure->getSubField<PVBooleanArray>("isConnected")->
|
||||
replace(easyMultiChannel->getIsConnected()->view());
|
||||
replace(pvaClientMultiChannel->getIsConnected()->view());
|
||||
NTMultiChannelPtr ntMultiChannel(NTMultiChannel::wrap(pvStructure));
|
||||
return EasyNTMultiChannelPtr(new EasyNTMultiChannel(easyMultiChannel,ntMultiChannel));
|
||||
return PvaClientNTMultiChannelPtr(new PvaClientNTMultiChannel(pvaClientMultiChannel,ntMultiChannel));
|
||||
}
|
||||
|
||||
EasyNTMultiChannel::EasyNTMultiChannel(
|
||||
EasyMultiChannelPtr const &easyMultiChannel,
|
||||
PvaClientNTMultiChannel::PvaClientNTMultiChannel(
|
||||
PvaClientMultiChannelPtr const &pvaClientMultiChannel,
|
||||
NTMultiChannelPtr const &ntMultiChannel)
|
||||
:
|
||||
easyMultiChannel(easyMultiChannel),
|
||||
pvaClientMultiChannel(pvaClientMultiChannel),
|
||||
ntMultiChannel(ntMultiChannel),
|
||||
pvUnionArray(ntMultiChannel->getPVStructure()->getSubField<PVUnionArray>("value")),
|
||||
pvDataCreate(getPVDataCreate())
|
||||
{}
|
||||
|
||||
EasyNTMultiChannel::~EasyNTMultiChannel()
|
||||
PvaClientNTMultiChannel::~PvaClientNTMultiChannel()
|
||||
{
|
||||
}
|
||||
|
||||
void EasyNTMultiChannel::createGet()
|
||||
void PvaClientNTMultiChannel::createGet()
|
||||
{
|
||||
PVStructurePtr pvStructure = ntMultiChannel->getPVStructure();
|
||||
bool getAlarm = false;
|
||||
@@ -68,21 +69,21 @@ void EasyNTMultiChannel::createGet()
|
||||
string request = "value";
|
||||
if(getAlarm) request += ",alarm";
|
||||
if(getTimeStamp) request += ",timeStamp";
|
||||
EasyChannelArrayPtr easyChannelArray = easyMultiChannel->getEasyChannelArray().lock();
|
||||
if(!easyChannelArray) throw std::runtime_error("easyChannelArray is gone");
|
||||
shared_vector<const EasyChannelPtr> easyChannels = *easyChannelArray;
|
||||
size_t numChannel = easyChannels.size();
|
||||
easyGet = std::vector<EasyGetPtr>(numChannel,EasyGetPtr());
|
||||
PvaClientChannelArrayPtr pvaClientChannelArray = pvaClientMultiChannel->getPvaClientChannelArray().lock();
|
||||
if(!pvaClientChannelArray) throw std::runtime_error("pvaClientChannelArray is gone");
|
||||
shared_vector<const PvaClientChannelPtr> pvaClientChannels = *pvaClientChannelArray;
|
||||
size_t numChannel = pvaClientChannels.size();
|
||||
pvaClientGet = std::vector<PvaClientGetPtr>(numChannel,PvaClientGetPtr());
|
||||
bool allOK = true;
|
||||
string message;
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
easyGet[i] = easyChannels[i]->createGet(request);
|
||||
easyGet[i]->issueConnect();
|
||||
pvaClientGet[i] = pvaClientChannels[i]->createGet(request);
|
||||
pvaClientGet[i]->issueConnect();
|
||||
}
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
Status status = easyGet[i]->waitConnect();
|
||||
Status status = pvaClientGet[i]->waitConnect();
|
||||
if(!status.isOK()) {
|
||||
message = "connect status " + status.getMessage();
|
||||
allOK = false;
|
||||
@@ -93,23 +94,23 @@ void EasyNTMultiChannel::createGet()
|
||||
|
||||
}
|
||||
|
||||
void EasyNTMultiChannel::createPut()
|
||||
void PvaClientNTMultiChannel::createPut()
|
||||
{
|
||||
EasyChannelArrayPtr easyChannelArray = easyMultiChannel->getEasyChannelArray().lock();
|
||||
if(!easyChannelArray) throw std::runtime_error("easyChannelArray is gone");
|
||||
shared_vector<const EasyChannelPtr> easyChannels = *easyChannelArray;
|
||||
size_t numChannel = easyChannels.size();
|
||||
easyPut = std::vector<EasyPutPtr>(numChannel,EasyPutPtr());
|
||||
PvaClientChannelArrayPtr pvaClientChannelArray = pvaClientMultiChannel->getPvaClientChannelArray().lock();
|
||||
if(!pvaClientChannelArray) throw std::runtime_error("pvaClientChannelArray is gone");
|
||||
shared_vector<const PvaClientChannelPtr> pvaClientChannels = *pvaClientChannelArray;
|
||||
size_t numChannel = pvaClientChannels.size();
|
||||
pvaClientPut = std::vector<PvaClientPutPtr>(numChannel,PvaClientPutPtr());
|
||||
bool allOK = true;
|
||||
string message;
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
easyPut[i] = easyChannels[i]->createPut("value");
|
||||
easyPut[i]->issueConnect();
|
||||
pvaClientPut[i] = pvaClientChannels[i]->createPut("value");
|
||||
pvaClientPut[i]->issueConnect();
|
||||
}
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
Status status = easyPut[i]->waitConnect();
|
||||
Status status = pvaClientPut[i]->waitConnect();
|
||||
if(!status.isOK()) {
|
||||
message = "connect status " + status.getMessage();
|
||||
allOK = false;
|
||||
@@ -119,11 +120,11 @@ void EasyNTMultiChannel::createPut()
|
||||
if(!allOK) throw std::runtime_error(message);
|
||||
}
|
||||
|
||||
NTMultiChannelPtr EasyNTMultiChannel::get()
|
||||
NTMultiChannelPtr PvaClientNTMultiChannel::get()
|
||||
{
|
||||
if(easyGet.empty()) createGet();
|
||||
if(pvaClientGet.empty()) createGet();
|
||||
PVStructurePtr pvStructure = ntMultiChannel->getPVStructure();
|
||||
shared_vector<const string> channelNames = easyMultiChannel->getChannelNames()->view();
|
||||
shared_vector<const string> channelNames = pvaClientMultiChannel->getChannelNames()->view();
|
||||
size_t numChannel = channelNames.size();
|
||||
bool severityExists = false;
|
||||
bool statusExists = false;
|
||||
@@ -158,16 +159,16 @@ NTMultiChannelPtr EasyNTMultiChannel::get()
|
||||
shared_vector<PVUnionPtr> valueVector(numChannel);
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
easyGet[i]->issueGet();
|
||||
pvaClientGet[i]->issueGet();
|
||||
}
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
Status stat = easyGet[i]->waitGet();
|
||||
Status stat = pvaClientGet[i]->waitGet();
|
||||
if(!stat.isOK()) {
|
||||
string message = channelNames[i] + " " + stat.getMessage();
|
||||
throw std::runtime_error(message);
|
||||
}
|
||||
PVStructurePtr pvStructure = easyGet[i]->getData()->getPVStructure();
|
||||
PVStructurePtr pvStructure = pvaClientGet[i]->getData()->getPVStructure();
|
||||
PVFieldPtr pvField = pvStructure->getSubField("value");
|
||||
if(!pvField) {
|
||||
string message = channelNames[i] + " no value field";
|
||||
@@ -228,10 +229,10 @@ NTMultiChannelPtr EasyNTMultiChannel::get()
|
||||
return ntMultiChannel;
|
||||
}
|
||||
|
||||
void EasyNTMultiChannel::put(NTMultiChannelPtr const &value)
|
||||
void PvaClientNTMultiChannel::put(NTMultiChannelPtr const &value)
|
||||
{
|
||||
if(easyPut.empty()) createPut();
|
||||
shared_vector<const string> channelNames = easyMultiChannel->getChannelNames()->view();
|
||||
if(pvaClientPut.empty()) createPut();
|
||||
shared_vector<const string> channelNames = pvaClientMultiChannel->getChannelNames()->view();
|
||||
size_t numChannel = channelNames.size();
|
||||
PVUnionArrayPtr pvValue = value->getPVStructure()->
|
||||
getSubField<PVUnionArray>("value");
|
||||
@@ -240,7 +241,7 @@ void EasyNTMultiChannel::put(NTMultiChannelPtr const &value)
|
||||
{
|
||||
try {
|
||||
PVFieldPtr pvFrom = valueVector[i]->get();
|
||||
PVFieldPtr pvTo = easyPut[i]->getData()->getValue();
|
||||
PVFieldPtr pvTo = pvaClientPut[i]->getData()->getValue();
|
||||
Type typeFrom = pvFrom->getField()->getType();
|
||||
Type typeTo = pvTo->getField()->getType();
|
||||
if(typeFrom==typeTo) {
|
||||
@@ -248,7 +249,7 @@ void EasyNTMultiChannel::put(NTMultiChannelPtr const &value)
|
||||
pvTo->copy(*pvFrom);
|
||||
}
|
||||
}
|
||||
easyPut[i]->issuePut();
|
||||
pvaClientPut[i]->issuePut();
|
||||
} catch (std::exception e) {
|
||||
string message = channelNames[i] + " " + e.what();
|
||||
throw std::runtime_error(message);
|
||||
@@ -256,7 +257,7 @@ void EasyNTMultiChannel::put(NTMultiChannelPtr const &value)
|
||||
}
|
||||
for(size_t i=0; i<numChannel; ++i)
|
||||
{
|
||||
Status status = easyPut[i]->waitPut();
|
||||
Status status = pvaClientPut[i]->waitPut();
|
||||
if(!status.isOK()) {
|
||||
string message = channelNames[i] + " " + status.getMessage();
|
||||
throw std::runtime_error(message);
|
||||
@@ -1,4 +1,4 @@
|
||||
/* easyNTMultiChannel.h */
|
||||
/* pvaClientNTMultiChannel.h */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
@@ -8,20 +8,20 @@
|
||||
* @author mrk
|
||||
* @date 2015.02
|
||||
*/
|
||||
#ifndef EASYNTMULTIChannel_H
|
||||
#define EASYNTMULTIChannel_H
|
||||
#ifndef PVACLIENTNTMULTIChannel_H
|
||||
#define PVACLIENTNTMULTIChannel_H
|
||||
|
||||
#ifdef epicsExportSharedSymbols
|
||||
# define easyPVAEpicsExportSharedSymbols
|
||||
# define pvaClientEpicsExportSharedSymbols
|
||||
# undef epicsExportSharedSymbols
|
||||
#endif
|
||||
|
||||
#include <pv/easyPVA.h>
|
||||
#include <pv/pvaClient.h>
|
||||
|
||||
namespace epics { namespace easyPVA {
|
||||
namespace epics { namespace pvaClient {
|
||||
|
||||
class EasyNTMultiChannel;
|
||||
typedef std::tr1::shared_ptr<EasyNTMultiChannel> EasyNTMultiChannelPtr;
|
||||
class PvaClientNTMultiChannel;
|
||||
typedef std::tr1::shared_ptr<PvaClientNTMultiChannel> PvaClientNTMultiChannelPtr;
|
||||
|
||||
/**
|
||||
* @brief Support for multiple channels where each channel has a value field that
|
||||
@@ -31,21 +31,21 @@ typedef std::tr1::shared_ptr<EasyNTMultiChannel> EasyNTMultiChannelPtr;
|
||||
*
|
||||
* @author mrk
|
||||
*/
|
||||
class epicsShareClass EasyNTMultiChannel
|
||||
class epicsShareClass PvaClientNTMultiChannel
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(EasyNTMultiChannel);
|
||||
POINTER_DEFINITIONS(PvaClientNTMultiChannel);
|
||||
/**
|
||||
* @brief Create a EasyNTMultiChannel.
|
||||
* @param &easyPVA Interface to EasyPVA
|
||||
* @brief Create a PvaClientNTMultiChannel.
|
||||
* @param &pvaClient Interface to PvaClient
|
||||
* @param channelName PVStringArray of channelNames.
|
||||
* @param structure valid NTMultiChannel structure.
|
||||
* @param timeout Timeout for connecting.
|
||||
* @param providerName The provider for each channel.
|
||||
* @return The interface to EasyNTMultiChannel.
|
||||
* @return The interface to PvaClientNTMultiChannel.
|
||||
*/
|
||||
static EasyNTMultiChannelPtr create(
|
||||
EasyPVAPtr const & easyPVA,
|
||||
static PvaClientNTMultiChannelPtr create(
|
||||
PvaClientPtr const & pvaClient,
|
||||
epics::pvData::PVStringArrayPtr const & channelName,
|
||||
epics::pvData::StructureConstPtr const & structure,
|
||||
double timeout = 5.0,
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
/**
|
||||
* @brief destructor
|
||||
*/
|
||||
~EasyNTMultiChannel();
|
||||
~PvaClientNTMultiChannel();
|
||||
/**
|
||||
* @brief destroy any resources used.
|
||||
*/
|
||||
@@ -69,23 +69,23 @@ public:
|
||||
*/
|
||||
void put(epics::nt::NTMultiChannelPtr const &value);
|
||||
/**
|
||||
* @brief Get the EasyMultiChannel.
|
||||
* @brief Get the PvaClientMultiChannel.
|
||||
* @return The interface.
|
||||
*/
|
||||
EasyMultiChannelPtr getEasyMultiChannel();
|
||||
PvaClientMultiChannelPtr getPvaClientMultiChannel();
|
||||
private:
|
||||
EasyNTMultiChannel(
|
||||
EasyMultiChannelPtr const & channelName,
|
||||
PvaClientNTMultiChannel(
|
||||
PvaClientMultiChannelPtr const & channelName,
|
||||
epics::nt::NTMultiChannelPtr const &ntMultiChannel);
|
||||
void createGet();
|
||||
void createPut();
|
||||
|
||||
EasyMultiChannelPtr easyMultiChannel;
|
||||
PvaClientMultiChannelPtr pvaClientMultiChannel;
|
||||
epics::nt::NTMultiChannelPtr ntMultiChannel;
|
||||
epics::pvData::PVUnionArrayPtr pvUnionArray;
|
||||
epics::pvData::PVDataCreatePtr pvDataCreate;
|
||||
std::vector<EasyGetPtr> easyGet;
|
||||
std::vector<EasyPutPtr> easyPut;
|
||||
std::vector<PvaClientGetPtr> pvaClientGet;
|
||||
std::vector<PvaClientPutPtr> pvaClientPut;
|
||||
epics::pvData::shared_vector<epics::pvData::int32> severity;
|
||||
epics::pvData::shared_vector<epics::pvData::int32> status;
|
||||
epics::pvData::shared_vector<std::string> message;
|
||||
@@ -100,4 +100,4 @@ private:
|
||||
|
||||
}}
|
||||
|
||||
#endif // EASYNTMULTIChannel_H
|
||||
#endif // PVACLIENTNTMULTIChannel_H
|
||||
@@ -1,4 +1,4 @@
|
||||
/* easyProcess.cpp */
|
||||
/* pvaClientProcess.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
@@ -12,43 +12,43 @@
|
||||
|
||||
#include <sstream>
|
||||
#include <pv/event.h>
|
||||
#include <pv/easyPVA.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 easyPVA {
|
||||
namespace epics { namespace pvaClient {
|
||||
|
||||
|
||||
class ChannelProcessRequesterImpl : public ChannelProcessRequester
|
||||
{
|
||||
EasyProcess * easyProcess;
|
||||
PvaClientProcess * pvaClientProcess;
|
||||
public:
|
||||
ChannelProcessRequesterImpl(EasyProcess * easyProcess)
|
||||
: easyProcess(easyProcess) {}
|
||||
ChannelProcessRequesterImpl(PvaClientProcess * pvaClientProcess)
|
||||
: pvaClientProcess(pvaClientProcess) {}
|
||||
string getRequesterName()
|
||||
{return easyProcess->getRequesterName();}
|
||||
{return pvaClientProcess->getRequesterName();}
|
||||
void message(string const & message,MessageType messageType)
|
||||
{easyProcess->message(message,messageType);}
|
||||
{pvaClientProcess->message(message,messageType);}
|
||||
void channelProcessConnect(
|
||||
const Status& status,
|
||||
ChannelProcess::shared_pointer const & channelProcess)
|
||||
{easyProcess->channelProcessConnect(status,channelProcess);}
|
||||
{pvaClientProcess->channelProcessConnect(status,channelProcess);}
|
||||
void processDone(
|
||||
const Status& status,
|
||||
ChannelProcess::shared_pointer const & channelProcess)
|
||||
{easyProcess->processDone(status,channelProcess);}
|
||||
{pvaClientProcess->processDone(status,channelProcess);}
|
||||
};
|
||||
|
||||
EasyProcess::EasyProcess(
|
||||
EasyPVAPtr const &pva,
|
||||
EasyChannelPtr const & easyChannel,
|
||||
PvaClientProcess::PvaClientProcess(
|
||||
PvaClientPtr const &pvaClient,
|
||||
PvaClientChannelPtr const & pvaClientChannel,
|
||||
Channel::shared_pointer const & channel,
|
||||
PVStructurePtr const &pvRequest)
|
||||
: easyPVA(pva),
|
||||
easyChannel(easyChannel),
|
||||
: pvaClient(pvaClient),
|
||||
pvaClientChannel(pvaClientChannel),
|
||||
channel(channel),
|
||||
pvRequest(pvRequest),
|
||||
isDestroyed(false),
|
||||
@@ -57,57 +57,57 @@ EasyProcess::EasyProcess(
|
||||
{
|
||||
}
|
||||
|
||||
EasyProcess::~EasyProcess()
|
||||
PvaClientProcess::~PvaClientProcess()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
void EasyProcess::checkProcessState()
|
||||
void PvaClientProcess::checkProcessState()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyProcess was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientProcess was destroyed");
|
||||
if(connectState==connectIdle) connect();
|
||||
if(processState==processIdle) process();
|
||||
}
|
||||
|
||||
// from ChannelProcessRequester
|
||||
string EasyProcess::getRequesterName()
|
||||
string PvaClientProcess::getRequesterName()
|
||||
{
|
||||
EasyPVAPtr yyy = easyPVA.lock();
|
||||
if(!yyy) throw std::runtime_error("easyPVA was destroyed");
|
||||
PvaClientPtr yyy = pvaClient.lock();
|
||||
if(!yyy) throw std::runtime_error("pvaClient was destroyed");
|
||||
return yyy->getRequesterName();
|
||||
}
|
||||
|
||||
void EasyProcess::message(string const & message,MessageType messageType)
|
||||
void PvaClientProcess::message(string const & message,MessageType messageType)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyProcess was destroyed");
|
||||
EasyPVAPtr yyy = easyPVA.lock();
|
||||
if(!yyy) throw std::runtime_error("easyPVA was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientProcess was destroyed");
|
||||
PvaClientPtr yyy = pvaClient.lock();
|
||||
if(!yyy) throw std::runtime_error("pvaClient was destroyed");
|
||||
yyy->message(message, messageType);
|
||||
}
|
||||
|
||||
void EasyProcess::channelProcessConnect(
|
||||
void PvaClientProcess::channelProcessConnect(
|
||||
const Status& status,
|
||||
ChannelProcess::shared_pointer const & channelProcess)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyProcess was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientProcess was destroyed");
|
||||
channelProcessConnectStatus = status;
|
||||
this->channelProcess = channelProcess;
|
||||
waitForConnect.signal();
|
||||
|
||||
}
|
||||
|
||||
void EasyProcess::processDone(
|
||||
void PvaClientProcess::processDone(
|
||||
const Status& status,
|
||||
ChannelProcess::shared_pointer const & channelProcess)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyProcess was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientProcess was destroyed");
|
||||
channelProcessStatus = status;
|
||||
waitForProcess.signal();
|
||||
}
|
||||
|
||||
|
||||
// from EasyProcess
|
||||
void EasyProcess::destroy()
|
||||
// from PvaClientProcess
|
||||
void PvaClientProcess::destroy()
|
||||
{
|
||||
{
|
||||
Lock xx(mutex);
|
||||
@@ -118,23 +118,23 @@ void EasyProcess::destroy()
|
||||
channelProcess.reset();
|
||||
}
|
||||
|
||||
void EasyProcess::connect()
|
||||
void PvaClientProcess::connect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyProcess was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientProcess was destroyed");
|
||||
issueConnect();
|
||||
Status status = waitConnect();
|
||||
if(status.isOK()) return;
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyProcess::connect " << status.getMessage();
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientProcess::connect " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void EasyProcess::issueConnect()
|
||||
void PvaClientProcess::issueConnect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyProcess was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientProcess was destroyed");
|
||||
if(connectState!=connectIdle) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " easyProcess already connected ";
|
||||
ss << "channel " << channel->getChannelName() << " pvaClientProcess already connected ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
processRequester = ChannelProcessRequester::shared_pointer(new ChannelProcessRequesterImpl(this));
|
||||
@@ -142,12 +142,12 @@ void EasyProcess::issueConnect()
|
||||
channelProcess = channel->createChannelProcess(processRequester,pvRequest);
|
||||
}
|
||||
|
||||
Status EasyProcess::waitConnect()
|
||||
Status PvaClientProcess::waitConnect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyProcess was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientProcess was destroyed");
|
||||
if(connectState!=connectActive) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " easyProcess illegal connect state ";
|
||||
ss << "channel " << channel->getChannelName() << " pvaClientProcess illegal connect state ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
waitForConnect.wait();
|
||||
@@ -159,36 +159,36 @@ Status EasyProcess::waitConnect()
|
||||
return Status(Status::STATUSTYPE_ERROR,channelProcessConnectStatus.getMessage());
|
||||
}
|
||||
|
||||
void EasyProcess::process()
|
||||
void PvaClientProcess::process()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyProcess was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientProcess was destroyed");
|
||||
issueProcess();
|
||||
Status status = waitProcess();
|
||||
if(status.isOK()) return;
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyProcess::process " << status.getMessage();
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientProcess::process " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void EasyProcess::issueProcess()
|
||||
void PvaClientProcess::issueProcess()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyProcess was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientProcess was destroyed");
|
||||
if(connectState==connectIdle) connect();
|
||||
if(processState!=processIdle) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyProcess::issueProcess process aleady active ";
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientProcess::issueProcess process aleady active ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
processState = processActive;
|
||||
channelProcess->process();
|
||||
}
|
||||
|
||||
Status EasyProcess::waitProcess()
|
||||
Status PvaClientProcess::waitProcess()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyProcess was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientProcess was destroyed");
|
||||
if(processState!=processActive){
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyProcess::waitProcess llegal process state";
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientProcess::waitProcess llegal process state";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
waitForProcess.wait();
|
||||
@@ -199,13 +199,13 @@ Status EasyProcess::waitProcess()
|
||||
return Status(Status::STATUSTYPE_ERROR,channelProcessStatus.getMessage());
|
||||
}
|
||||
|
||||
EasyProcessPtr EasyProcess::create(
|
||||
EasyPVAPtr const &pva,
|
||||
EasyChannelPtr const & easyChannel,
|
||||
PvaClientProcessPtr PvaClientProcess::create(
|
||||
PvaClientPtr const &pvaClient,
|
||||
PvaClientChannelPtr const & pvaClientChannel,
|
||||
Channel::shared_pointer const & channel,
|
||||
PVStructurePtr const &pvRequest)
|
||||
{
|
||||
EasyProcessPtr epv(new EasyProcess(pva,easyChannel,channel,pvRequest));
|
||||
PvaClientProcessPtr epv(new PvaClientProcess(pvaClient,pvaClientChannel,channel,pvRequest));
|
||||
return epv;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* easyPut.cpp */
|
||||
/* pvaClientPut.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
@@ -12,49 +12,49 @@
|
||||
|
||||
#include <sstream>
|
||||
#include <pv/event.h>
|
||||
#include <pv/easyPVA.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 easyPVA {
|
||||
namespace epics { namespace pvaClient {
|
||||
|
||||
class ChannelPutRequesterImpl : public ChannelPutRequester
|
||||
{
|
||||
EasyPut * easyPut;
|
||||
PvaClientPut * pvaClientPut;
|
||||
public:
|
||||
ChannelPutRequesterImpl(EasyPut * easyPut)
|
||||
: easyPut(easyPut) {}
|
||||
ChannelPutRequesterImpl(PvaClientPut * pvaClientPut)
|
||||
: pvaClientPut(pvaClientPut) {}
|
||||
string getRequesterName()
|
||||
{return easyPut->getRequesterName();}
|
||||
{return pvaClientPut->getRequesterName();}
|
||||
void message(string const & message,MessageType messageType)
|
||||
{easyPut->message(message,messageType);}
|
||||
{pvaClientPut->message(message,messageType);}
|
||||
void channelPutConnect(
|
||||
const Status& status,
|
||||
ChannelPut::shared_pointer const & channelPut,
|
||||
StructureConstPtr const & structure)
|
||||
{easyPut->channelPutConnect(status,channelPut,structure);}
|
||||
{pvaClientPut->channelPutConnect(status,channelPut,structure);}
|
||||
void getDone(
|
||||
const Status& status,
|
||||
ChannelPut::shared_pointer const & channelPut,
|
||||
PVStructurePtr const & pvStructure,
|
||||
BitSetPtr const & bitSet)
|
||||
{easyPut->getDone(status,channelPut,pvStructure,bitSet);}
|
||||
{pvaClientPut->getDone(status,channelPut,pvStructure,bitSet);}
|
||||
void putDone(
|
||||
const Status& status,
|
||||
ChannelPut::shared_pointer const & channelPut)
|
||||
{easyPut->putDone(status,channelPut);}
|
||||
{pvaClientPut->putDone(status,channelPut);}
|
||||
};
|
||||
|
||||
EasyPut::EasyPut(
|
||||
EasyPVAPtr const &pva,
|
||||
EasyChannelPtr const & easyChannel,
|
||||
PvaClientPut::PvaClientPut(
|
||||
PvaClientPtr const &pvaClient,
|
||||
PvaClientChannelPtr const & pvaClientChannel,
|
||||
Channel::shared_pointer const & channel,
|
||||
PVStructurePtr const &pvRequest)
|
||||
: easyPVA(pva),
|
||||
easyChannel(easyChannel),
|
||||
: pvaClient(pvaClient),
|
||||
pvaClientChannel(pvaClientChannel),
|
||||
channel(channel),
|
||||
pvRequest(pvRequest),
|
||||
isDestroyed(false),
|
||||
@@ -63,14 +63,14 @@ EasyPut::EasyPut(
|
||||
{
|
||||
}
|
||||
|
||||
EasyPut::~EasyPut()
|
||||
PvaClientPut::~PvaClientPut()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
void EasyPut::checkPutState()
|
||||
void PvaClientPut::checkPutState()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPut was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
if(connectState==connectIdle){
|
||||
connect();
|
||||
get();
|
||||
@@ -78,67 +78,67 @@ void EasyPut::checkPutState()
|
||||
}
|
||||
|
||||
// from ChannelPutRequester
|
||||
string EasyPut::getRequesterName()
|
||||
string PvaClientPut::getRequesterName()
|
||||
{
|
||||
EasyPVAPtr yyy = easyPVA.lock();
|
||||
if(!yyy) throw std::runtime_error("easyPVA was destroyed");
|
||||
PvaClientPtr yyy = pvaClient.lock();
|
||||
if(!yyy) throw std::runtime_error("pvaClient was destroyed");
|
||||
return yyy->getRequesterName();
|
||||
}
|
||||
|
||||
void EasyPut::message(string const & message,MessageType messageType)
|
||||
void PvaClientPut::message(string const & message,MessageType messageType)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPut was destroyed");
|
||||
EasyPVAPtr yyy = easyPVA.lock();
|
||||
if(!yyy) throw std::runtime_error("easyPVA was destroyed");
|
||||
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 EasyPut::channelPutConnect(
|
||||
void PvaClientPut::channelPutConnect(
|
||||
const Status& status,
|
||||
ChannelPut::shared_pointer const & channelPut,
|
||||
StructureConstPtr const & structure)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPut was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
channelPutConnectStatus = status;
|
||||
this->channelPut = channelPut;
|
||||
if(status.isOK()) {
|
||||
easyData = EasyPutData::create(structure);
|
||||
easyData->setMessagePrefix(easyChannel.lock()->getChannelName());
|
||||
pvaClientData = PvaClientPutData::create(structure);
|
||||
pvaClientData->setMessagePrefix(pvaClientChannel.lock()->getChannelName());
|
||||
}
|
||||
waitForConnect.signal();
|
||||
|
||||
}
|
||||
|
||||
void EasyPut::getDone(
|
||||
void PvaClientPut::getDone(
|
||||
const Status& status,
|
||||
ChannelPut::shared_pointer const & channelPut,
|
||||
PVStructurePtr const & pvStructure,
|
||||
BitSetPtr const & bitSet)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPut was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
channelGetPutStatus = status;
|
||||
if(status.isOK()) {
|
||||
PVStructurePtr pvs = easyData->getPVStructure();
|
||||
PVStructurePtr pvs = pvaClientData->getPVStructure();
|
||||
pvs->copyUnchecked(*pvStructure,*bitSet);
|
||||
BitSetPtr bs = easyData->getBitSet();
|
||||
BitSetPtr bs = pvaClientData->getBitSet();
|
||||
bs->clear();
|
||||
*bs |= *bitSet;
|
||||
}
|
||||
waitForGetPut.signal();
|
||||
}
|
||||
|
||||
void EasyPut::putDone(
|
||||
void PvaClientPut::putDone(
|
||||
const Status& status,
|
||||
ChannelPut::shared_pointer const & channelPut)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPut was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
channelGetPutStatus = status;
|
||||
waitForGetPut.signal();
|
||||
}
|
||||
|
||||
|
||||
// from EasyPut
|
||||
void EasyPut::destroy()
|
||||
// from PvaClientPut
|
||||
void PvaClientPut::destroy()
|
||||
{
|
||||
{
|
||||
Lock xx(mutex);
|
||||
@@ -149,23 +149,23 @@ void EasyPut::destroy()
|
||||
channelPut.reset();
|
||||
}
|
||||
|
||||
void EasyPut::connect()
|
||||
void PvaClientPut::connect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPut was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
issueConnect();
|
||||
Status status = waitConnect();
|
||||
if(status.isOK()) return;
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyPut::connect " << status.getMessage();
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPut::connect " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void EasyPut::issueConnect()
|
||||
void PvaClientPut::issueConnect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPut was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
if(connectState!=connectIdle) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " easyPut already connected ";
|
||||
ss << "channel " << channel->getChannelName() << " pvaClientPut already connected ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
putRequester = ChannelPutRequester::shared_pointer(new ChannelPutRequesterImpl(this));
|
||||
@@ -173,12 +173,12 @@ void EasyPut::issueConnect()
|
||||
channelPut = channel->createChannelPut(putRequester,pvRequest);
|
||||
}
|
||||
|
||||
Status EasyPut::waitConnect()
|
||||
Status PvaClientPut::waitConnect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPut was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
if(connectState!=connectActive) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " easyPut illegal connect state ";
|
||||
ss << "channel " << channel->getChannelName() << " pvaClientPut illegal connect state ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
waitForConnect.wait();
|
||||
@@ -190,37 +190,37 @@ Status EasyPut::waitConnect()
|
||||
return Status(Status::STATUSTYPE_ERROR,channelPutConnectStatus.getMessage());
|
||||
}
|
||||
|
||||
void EasyPut::get()
|
||||
void PvaClientPut::get()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPut was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
issueGet();
|
||||
Status status = waitGet();
|
||||
if(status.isOK()) return;
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyPut::get " << status.getMessage();
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPut::get " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void EasyPut::issueGet()
|
||||
void PvaClientPut::issueGet()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPut was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
if(connectState==connectIdle) connect();
|
||||
if(putState!=putIdle) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyPut::issueGet get or put aleady active ";
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPut::issueGet get or put aleady active ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
putState = getActive;
|
||||
easyData->getBitSet()->clear();
|
||||
pvaClientData->getBitSet()->clear();
|
||||
channelPut->get();
|
||||
}
|
||||
|
||||
Status EasyPut::waitGet()
|
||||
Status PvaClientPut::waitGet()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPut was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
if(putState!=getActive){
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyPut::waitGet llegal put state";
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPut::waitGet llegal put state";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
waitForGetPut.wait();
|
||||
@@ -231,60 +231,60 @@ Status EasyPut::waitGet()
|
||||
return Status(Status::STATUSTYPE_ERROR,channelGetPutStatus.getMessage());
|
||||
}
|
||||
|
||||
void EasyPut::put()
|
||||
void PvaClientPut::put()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPut was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
issuePut();
|
||||
Status status = waitPut();
|
||||
if(status.isOK()) return;
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyPut::put " << status.getMessage();
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPut::put " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void EasyPut::issuePut()
|
||||
void PvaClientPut::issuePut()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPut was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
if(connectState==connectIdle) connect();
|
||||
if(putState!=putIdle) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyPut::issueGet get or put aleady active ";
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPut::issueGet get or put aleady active ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
putState = putActive;
|
||||
channelPut->put(easyData->getPVStructure(),easyData->getBitSet());
|
||||
channelPut->put(pvaClientData->getPVStructure(),pvaClientData->getBitSet());
|
||||
}
|
||||
|
||||
Status EasyPut::waitPut()
|
||||
Status PvaClientPut::waitPut()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPut was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
|
||||
if(putState!=putActive){
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyPut::waitPut llegal put state";
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPut::waitPut llegal put state";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
waitForGetPut.wait();
|
||||
putState = putIdle;
|
||||
if(channelGetPutStatus.isOK()) {
|
||||
easyData->getBitSet()->clear();
|
||||
pvaClientData->getBitSet()->clear();
|
||||
return Status::Ok;
|
||||
}
|
||||
return Status(Status::STATUSTYPE_ERROR,channelGetPutStatus.getMessage());
|
||||
}
|
||||
|
||||
EasyPutDataPtr EasyPut::getData()
|
||||
PvaClientPutDataPtr PvaClientPut::getData()
|
||||
{
|
||||
checkPutState();
|
||||
return easyData;
|
||||
return pvaClientData;
|
||||
}
|
||||
|
||||
EasyPutPtr EasyPut::create(
|
||||
EasyPVAPtr const &pva,
|
||||
EasyChannelPtr const & easyChannel,
|
||||
PvaClientPutPtr PvaClientPut::create(
|
||||
PvaClientPtr const &pvaClient,
|
||||
PvaClientChannelPtr const & pvaClientChannel,
|
||||
Channel::shared_pointer const & channel,
|
||||
PVStructurePtr const &pvRequest)
|
||||
{
|
||||
EasyPutPtr epv(new EasyPut(pva,easyChannel,channel,pvRequest));
|
||||
PvaClientPutPtr epv(new PvaClientPut(pvaClient,pvaClientChannel,channel,pvRequest));
|
||||
return epv;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* easyPutData.cpp */
|
||||
/* pvaClientPutData.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <typeinfo>
|
||||
|
||||
#include <sstream>
|
||||
#include <pv/easyPVA.h>
|
||||
#include <pv/pvaClient.h>
|
||||
#include <pv/createRequest.h>
|
||||
#include <pv/convert.h>
|
||||
|
||||
@@ -23,14 +23,14 @@ using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
namespace epics { namespace easyPVA {
|
||||
namespace epics { namespace pvaClient {
|
||||
|
||||
class EasyPostHandlerPvt: public PostHandler
|
||||
class PvaClientPostHandlerPvt: public PostHandler
|
||||
{
|
||||
EasyPutData * easyData;
|
||||
PvaClientPutData * easyData;
|
||||
size_t fieldNumber;
|
||||
public:
|
||||
EasyPostHandlerPvt(EasyPutData *easyData,size_t fieldNumber)
|
||||
PvaClientPostHandlerPvt(PvaClientPutData *easyData,size_t fieldNumber)
|
||||
: easyData(easyData),fieldNumber(fieldNumber){}
|
||||
void postPut() { easyData->postPut(fieldNumber);}
|
||||
};
|
||||
@@ -46,13 +46,13 @@ static string notScalarArray("value is not a scalarArray");
|
||||
static string notDoubleArray("value is not a doubleArray");
|
||||
static string notStringArray("value is not a stringArray");
|
||||
|
||||
EasyPutDataPtr EasyPutData::create(StructureConstPtr const & structure)
|
||||
PvaClientPutDataPtr PvaClientPutData::create(StructureConstPtr const & structure)
|
||||
{
|
||||
EasyPutDataPtr epv(new EasyPutData(structure));
|
||||
PvaClientPutDataPtr epv(new PvaClientPutData(structure));
|
||||
return epv;
|
||||
}
|
||||
|
||||
EasyPutData::EasyPutData(StructureConstPtr const & structure)
|
||||
PvaClientPutData::PvaClientPutData(StructureConstPtr const & structure)
|
||||
: structure(structure),
|
||||
pvStructure(getPVDataCreate()->createPVStructure(structure)),
|
||||
bitSet(BitSetPtr(new BitSet(pvStructure->getNumberFields())))
|
||||
@@ -62,7 +62,7 @@ EasyPutData::EasyPutData(StructureConstPtr const & structure)
|
||||
PVFieldPtr pvField;
|
||||
for(size_t i =0; i<nfields; ++i)
|
||||
{
|
||||
postHandler[i] = PostHandlerPtr(new EasyPostHandlerPvt(this, i));
|
||||
postHandler[i] = PostHandlerPtr(new PvaClientPostHandlerPvt(this, i));
|
||||
if(i==0) {
|
||||
pvField = pvStructure;
|
||||
} else {
|
||||
@@ -73,32 +73,32 @@ EasyPutData::EasyPutData(StructureConstPtr const & structure)
|
||||
pvValue = pvStructure->getSubField("value");
|
||||
}
|
||||
|
||||
void EasyPutData::checkValue()
|
||||
void PvaClientPutData::checkValue()
|
||||
{
|
||||
if(pvValue) return;
|
||||
throw std::runtime_error(messagePrefix + noValue);
|
||||
}
|
||||
|
||||
void EasyPutData::postPut(size_t fieldNumber)
|
||||
void PvaClientPutData::postPut(size_t fieldNumber)
|
||||
{
|
||||
bitSet->set(fieldNumber);
|
||||
}
|
||||
|
||||
void EasyPutData::setMessagePrefix(std::string const & value)
|
||||
void PvaClientPutData::setMessagePrefix(std::string const & value)
|
||||
{
|
||||
messagePrefix = value + " ";
|
||||
}
|
||||
|
||||
StructureConstPtr EasyPutData::getStructure()
|
||||
StructureConstPtr PvaClientPutData::getStructure()
|
||||
{return structure;}
|
||||
|
||||
PVStructurePtr EasyPutData::getPVStructure()
|
||||
PVStructurePtr PvaClientPutData::getPVStructure()
|
||||
{return pvStructure;}
|
||||
|
||||
BitSetPtr EasyPutData::getBitSet()
|
||||
BitSetPtr PvaClientPutData::getBitSet()
|
||||
{return bitSet;}
|
||||
|
||||
std::ostream & EasyPutData::showChanged(std::ostream & out)
|
||||
std::ostream & PvaClientPutData::showChanged(std::ostream & out)
|
||||
{
|
||||
size_t nextSet = bitSet->nextSetBit(0);
|
||||
PVFieldPtr pvField;
|
||||
@@ -115,33 +115,33 @@ std::ostream & EasyPutData::showChanged(std::ostream & out)
|
||||
return out;
|
||||
}
|
||||
|
||||
bool EasyPutData::hasValue()
|
||||
bool PvaClientPutData::hasValue()
|
||||
{
|
||||
if(!pvValue) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EasyPutData::isValueScalar()
|
||||
bool PvaClientPutData::isValueScalar()
|
||||
{
|
||||
if(!pvValue) return false;
|
||||
if(pvValue->getField()->getType()==scalar) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool EasyPutData::isValueScalarArray()
|
||||
bool PvaClientPutData::isValueScalarArray()
|
||||
{
|
||||
if(!pvValue) return false;
|
||||
if(pvValue->getField()->getType()==scalarArray) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
PVFieldPtr EasyPutData::getValue()
|
||||
PVFieldPtr PvaClientPutData::getValue()
|
||||
{
|
||||
checkValue();
|
||||
return pvValue;
|
||||
}
|
||||
|
||||
PVScalarPtr EasyPutData::getScalarValue()
|
||||
PVScalarPtr PvaClientPutData::getScalarValue()
|
||||
{
|
||||
checkValue();
|
||||
PVScalarPtr pv = pvStructure->getSubField<PVScalar>("value");
|
||||
@@ -151,7 +151,7 @@ PVScalarPtr EasyPutData::getScalarValue()
|
||||
return pv;
|
||||
}
|
||||
|
||||
PVArrayPtr EasyPutData::getArrayValue()
|
||||
PVArrayPtr PvaClientPutData::getArrayValue()
|
||||
{
|
||||
checkValue();
|
||||
PVArrayPtr pv = pvStructure->getSubField<PVArray>("value");
|
||||
@@ -161,7 +161,7 @@ PVArrayPtr EasyPutData::getArrayValue()
|
||||
return pv;
|
||||
}
|
||||
|
||||
PVScalarArrayPtr EasyPutData::getScalarArrayValue()
|
||||
PVScalarArrayPtr PvaClientPutData::getScalarArrayValue()
|
||||
{
|
||||
checkValue();
|
||||
PVScalarArrayPtr pv = pvStructure->getSubField<PVScalarArray>("value");
|
||||
@@ -171,7 +171,7 @@ PVScalarArrayPtr EasyPutData::getScalarArrayValue()
|
||||
return pv;
|
||||
}
|
||||
|
||||
double EasyPutData::getDouble()
|
||||
double PvaClientPutData::getDouble()
|
||||
{
|
||||
PVScalarPtr pvScalar = getScalarValue();
|
||||
ScalarType scalarType = pvScalar->getScalar()->getScalarType();
|
||||
@@ -185,13 +185,13 @@ double EasyPutData::getDouble()
|
||||
return convert->toDouble(pvScalar);
|
||||
}
|
||||
|
||||
string EasyPutData::getString()
|
||||
string PvaClientPutData::getString()
|
||||
{
|
||||
PVScalarPtr pvScalar = getScalarValue();
|
||||
return convert->toString(pvScalar);
|
||||
}
|
||||
|
||||
shared_vector<const double> EasyPutData::getDoubleArray()
|
||||
shared_vector<const double> PvaClientPutData::getDoubleArray()
|
||||
{
|
||||
checkValue();
|
||||
PVDoubleArrayPtr pv = pvStructure->getSubField<PVDoubleArray>("value");
|
||||
@@ -201,7 +201,7 @@ shared_vector<const double> EasyPutData::getDoubleArray()
|
||||
return pv->view();
|
||||
}
|
||||
|
||||
shared_vector<const string> EasyPutData::getStringArray()
|
||||
shared_vector<const string> PvaClientPutData::getStringArray()
|
||||
{
|
||||
checkValue();
|
||||
PVStringArrayPtr pv = pvStructure->getSubField<PVStringArray>("value");
|
||||
@@ -212,13 +212,14 @@ shared_vector<const string> EasyPutData::getStringArray()
|
||||
|
||||
}
|
||||
|
||||
void EasyPutData::putDouble(double value)
|
||||
void PvaClientPutData::putDouble(double value)
|
||||
{
|
||||
PVScalarPtr pvScalar = getScalarValue();
|
||||
ScalarType scalarType = pvScalar->getScalar()->getScalarType();
|
||||
if(scalarType==pvDouble) {
|
||||
PVDoublePtr pvDouble = static_pointer_cast<PVDouble>(pvScalar);
|
||||
pvDouble->put(value);
|
||||
return;
|
||||
}
|
||||
if(!ScalarTypeFunc::isNumeric(scalarType)) {
|
||||
throw std::runtime_error(messagePrefix + notCompatibleScalar);
|
||||
@@ -226,7 +227,7 @@ void EasyPutData::putDouble(double value)
|
||||
convert->fromDouble(pvScalar,value);
|
||||
}
|
||||
|
||||
void EasyPutData::putString(std::string const & value)
|
||||
void PvaClientPutData::putString(std::string const & value)
|
||||
{
|
||||
PVScalarPtr pvScalar = getScalarValue();
|
||||
convert->fromString(pvScalar,value);
|
||||
@@ -234,7 +235,7 @@ void EasyPutData::putString(std::string const & value)
|
||||
|
||||
|
||||
|
||||
void EasyPutData::putDoubleArray(shared_vector<const double> const & value)
|
||||
void PvaClientPutData::putDoubleArray(shared_vector<const double> const & value)
|
||||
{
|
||||
checkValue();
|
||||
PVDoubleArrayPtr pv = pvStructure->getSubField<PVDoubleArray>("value");
|
||||
@@ -244,7 +245,7 @@ void EasyPutData::putDoubleArray(shared_vector<const double> const & value)
|
||||
pv->replace(value);
|
||||
}
|
||||
|
||||
void EasyPutData::putStringArray(shared_vector<const std::string> const & value)
|
||||
void PvaClientPutData::putStringArray(shared_vector<const std::string> const & value)
|
||||
{
|
||||
checkValue();
|
||||
PVStringArrayPtr pv = pvStructure->getSubField<PVStringArray>("value");
|
||||
@@ -254,7 +255,7 @@ void EasyPutData::putStringArray(shared_vector<const std::string> const & value)
|
||||
pv->replace(value);
|
||||
}
|
||||
|
||||
void EasyPutData::putStringArray(std::vector<std::string> const & value)
|
||||
void PvaClientPutData::putStringArray(std::vector<std::string> const & value)
|
||||
{
|
||||
checkValue();
|
||||
PVScalarArrayPtr pv = pvStructure->getSubField<PVScalarArray>("value");
|
||||
@@ -1,4 +1,4 @@
|
||||
/* easyPutGet.cpp */
|
||||
/* pvaClientPutGet.cpp */
|
||||
/**
|
||||
* Copyright - See the COPYRIGHT that is included with this distribution.
|
||||
* EPICS pvData is distributed subject to a Software License Agreement found
|
||||
@@ -12,32 +12,32 @@
|
||||
|
||||
#include <sstream>
|
||||
#include <pv/event.h>
|
||||
#include <pv/easyPVA.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 easyPVA {
|
||||
namespace epics { namespace pvaClient {
|
||||
|
||||
class ChannelPutGetRequesterImpl : public ChannelPutGetRequester
|
||||
{
|
||||
EasyPutGet * easyPutGet;
|
||||
PvaClientPutGet * pvaClientPutGet;
|
||||
public:
|
||||
ChannelPutGetRequesterImpl(EasyPutGet * easyPutGet)
|
||||
: easyPutGet(easyPutGet) {}
|
||||
ChannelPutGetRequesterImpl(PvaClientPutGet * pvaClientPutGet)
|
||||
: pvaClientPutGet(pvaClientPutGet) {}
|
||||
string getRequesterName()
|
||||
{return easyPutGet->getRequesterName();}
|
||||
{return pvaClientPutGet->getRequesterName();}
|
||||
void message(string const & message,MessageType messageType)
|
||||
{easyPutGet->message(message,messageType);}
|
||||
{pvaClientPutGet->message(message,messageType);}
|
||||
void channelPutGetConnect(
|
||||
const epics::pvData::Status& status,
|
||||
epics::pvAccess::ChannelPutGet::shared_pointer const & channelPutGet,
|
||||
epics::pvData::StructureConstPtr const & putStructure,
|
||||
epics::pvData::StructureConstPtr const & getStructure)
|
||||
{
|
||||
easyPutGet->channelPutGetConnect(status,channelPutGet,putStructure,getStructure);
|
||||
pvaClientPutGet->channelPutGetConnect(status,channelPutGet,putStructure,getStructure);
|
||||
}
|
||||
void putGetDone(
|
||||
const epics::pvData::Status& status,
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
epics::pvData::PVStructurePtr const & getPVStructure,
|
||||
epics::pvData::BitSetPtr const & getBitSet)
|
||||
{
|
||||
easyPutGet->putGetDone(status,channelPutGet,getPVStructure,getBitSet);
|
||||
pvaClientPutGet->putGetDone(status,channelPutGet,getPVStructure,getBitSet);
|
||||
}
|
||||
void getPutDone(
|
||||
const epics::pvData::Status& status,
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
epics::pvData::PVStructurePtr const & putPVStructure,
|
||||
epics::pvData::BitSet::shared_pointer const & putBitSet)
|
||||
{
|
||||
easyPutGet->getPutDone(status,channelPutGet,putPVStructure,putBitSet);
|
||||
pvaClientPutGet->getPutDone(status,channelPutGet,putPVStructure,putBitSet);
|
||||
}
|
||||
void getGetDone(
|
||||
const epics::pvData::Status& status,
|
||||
@@ -61,17 +61,17 @@ public:
|
||||
epics::pvData::PVStructurePtr const & getPVStructure,
|
||||
epics::pvData::BitSet::shared_pointer const & getBitSet)
|
||||
{
|
||||
easyPutGet->getGetDone(status,channelPutGet,getPVStructure,getBitSet);
|
||||
pvaClientPutGet->getGetDone(status,channelPutGet,getPVStructure,getBitSet);
|
||||
}
|
||||
};
|
||||
|
||||
EasyPutGet::EasyPutGet(
|
||||
EasyPVAPtr const &pva,
|
||||
EasyChannelPtr const & easyChannel,
|
||||
PvaClientPutGet::PvaClientPutGet(
|
||||
PvaClientPtr const &pvaClient,
|
||||
PvaClientChannelPtr const & pvaClientChannel,
|
||||
Channel::shared_pointer const & channel,
|
||||
PVStructurePtr const &pvRequest)
|
||||
: easyPVA(pva),
|
||||
easyChannel(easyChannel),
|
||||
: pvaClient(pvaClient),
|
||||
pvaClientChannel(pvaClientChannel),
|
||||
channel(channel),
|
||||
pvRequest(pvRequest),
|
||||
isDestroyed(false),
|
||||
@@ -80,14 +80,14 @@ EasyPutGet::EasyPutGet(
|
||||
{
|
||||
}
|
||||
|
||||
EasyPutGet::~EasyPutGet()
|
||||
PvaClientPutGet::~PvaClientPutGet()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
void EasyPutGet::checkPutGetState()
|
||||
void PvaClientPutGet::checkPutGetState()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPutGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
|
||||
if(connectState==connectIdle){
|
||||
connect();
|
||||
getPut();
|
||||
@@ -95,90 +95,90 @@ void EasyPutGet::checkPutGetState()
|
||||
}
|
||||
|
||||
// from ChannelPutGetRequester
|
||||
string EasyPutGet::getRequesterName()
|
||||
string PvaClientPutGet::getRequesterName()
|
||||
{
|
||||
EasyPVAPtr yyy = easyPVA.lock();
|
||||
if(!yyy) throw std::runtime_error("easyPVA was destroyed");
|
||||
PvaClientPtr yyy = pvaClient.lock();
|
||||
if(!yyy) throw std::runtime_error("pvaClient was destroyed");
|
||||
return yyy->getRequesterName();
|
||||
}
|
||||
|
||||
void EasyPutGet::message(string const & message,MessageType messageType)
|
||||
void PvaClientPutGet::message(string const & message,MessageType messageType)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPutGet was destroyed");
|
||||
EasyPVAPtr yyy = easyPVA.lock();
|
||||
if(!yyy) throw std::runtime_error("easyPVA was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
|
||||
PvaClientPtr yyy = pvaClient.lock();
|
||||
if(!yyy) throw std::runtime_error("pvaClient was destroyed");
|
||||
yyy->message(message, messageType);
|
||||
}
|
||||
|
||||
void EasyPutGet::channelPutGetConnect(
|
||||
void PvaClientPutGet::channelPutGetConnect(
|
||||
const Status& status,
|
||||
ChannelPutGet::shared_pointer const & channelPutGet,
|
||||
StructureConstPtr const & putStructure,
|
||||
StructureConstPtr const & getStructure)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPutGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
|
||||
channelPutGetConnectStatus = status;
|
||||
this->channelPutGet = channelPutGet;
|
||||
if(status.isOK()) {
|
||||
easyPutData = EasyPutData::create(putStructure);
|
||||
easyPutData->setMessagePrefix(easyChannel.lock()->getChannelName());
|
||||
easyGetData = EasyGetData::create(getStructure);
|
||||
easyGetData->setMessagePrefix(easyChannel.lock()->getChannelName());
|
||||
pvaClientPutData = PvaClientPutData::create(putStructure);
|
||||
pvaClientPutData->setMessagePrefix(pvaClientChannel.lock()->getChannelName());
|
||||
pvaClientGetData = PvaClientGetData::create(getStructure);
|
||||
pvaClientGetData->setMessagePrefix(pvaClientChannel.lock()->getChannelName());
|
||||
}
|
||||
waitForConnect.signal();
|
||||
|
||||
}
|
||||
|
||||
void EasyPutGet::putGetDone(
|
||||
void PvaClientPutGet::putGetDone(
|
||||
const Status& status,
|
||||
ChannelPutGet::shared_pointer const & channelPutGet,
|
||||
PVStructurePtr const & getPVStructure,
|
||||
BitSetPtr const & getBitSet)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPutGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
|
||||
channelPutGetStatus = status;
|
||||
if(status.isOK()) {
|
||||
easyGetData->setData(getPVStructure,getBitSet);
|
||||
pvaClientGetData->setData(getPVStructure,getBitSet);
|
||||
}
|
||||
waitForPutGet.signal();
|
||||
}
|
||||
|
||||
void EasyPutGet::getPutDone(
|
||||
void PvaClientPutGet::getPutDone(
|
||||
const Status& status,
|
||||
ChannelPutGet::shared_pointer const & channelPutGet,
|
||||
PVStructurePtr const & putPVStructure,
|
||||
BitSetPtr const & putBitSet)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPutGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
|
||||
channelGetPutGetStatus = status;
|
||||
if(status.isOK()) {
|
||||
PVStructurePtr pvs = easyPutData->getPVStructure();
|
||||
PVStructurePtr pvs = pvaClientPutData->getPVStructure();
|
||||
pvs->copyUnchecked(*putPVStructure,*putBitSet);
|
||||
BitSetPtr bs = easyPutData->getBitSet();
|
||||
BitSetPtr bs = pvaClientPutData->getBitSet();
|
||||
bs->clear();
|
||||
*bs |= *putBitSet;
|
||||
}
|
||||
waitForPutGet.signal();
|
||||
}
|
||||
|
||||
void EasyPutGet::getGetDone(
|
||||
void PvaClientPutGet::getGetDone(
|
||||
const Status& status,
|
||||
ChannelPutGet::shared_pointer const & channelPutGet,
|
||||
PVStructurePtr const & getPVStructure,
|
||||
BitSetPtr const & getBitSet)
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPutGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
|
||||
channelPutGetStatus = status;
|
||||
if(status.isOK()) {
|
||||
easyGetData->setData(getPVStructure,getBitSet);
|
||||
pvaClientGetData->setData(getPVStructure,getBitSet);
|
||||
}
|
||||
waitForPutGet.signal();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// from EasyPutGet
|
||||
void EasyPutGet::destroy()
|
||||
// from PvaClientPutGet
|
||||
void PvaClientPutGet::destroy()
|
||||
{
|
||||
{
|
||||
Lock xx(mutex);
|
||||
@@ -189,23 +189,23 @@ void EasyPutGet::destroy()
|
||||
channelPutGet.reset();
|
||||
}
|
||||
|
||||
void EasyPutGet::connect()
|
||||
void PvaClientPutGet::connect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPutGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
|
||||
issueConnect();
|
||||
Status status = waitConnect();
|
||||
if(status.isOK()) return;
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyPutGet::connect " << status.getMessage();
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPutGet::connect " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void EasyPutGet::issueConnect()
|
||||
void PvaClientPutGet::issueConnect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPutGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
|
||||
if(connectState!=connectIdle) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " easyPutGet already connected ";
|
||||
ss << "channel " << channel->getChannelName() << " pvaClientPutGet already connected ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
putGetRequester = ChannelPutGetRequester::shared_pointer(new ChannelPutGetRequesterImpl(this));
|
||||
@@ -213,12 +213,12 @@ void EasyPutGet::issueConnect()
|
||||
channelPutGet = channel->createChannelPutGet(putGetRequester,pvRequest);
|
||||
}
|
||||
|
||||
Status EasyPutGet::waitConnect()
|
||||
Status PvaClientPutGet::waitConnect()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPutGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
|
||||
if(connectState!=connectActive) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " easyPutGet illegal connect state ";
|
||||
ss << "channel " << channel->getChannelName() << " pvaClientPutGet illegal connect state ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
waitForConnect.wait();
|
||||
@@ -231,37 +231,37 @@ Status EasyPutGet::waitConnect()
|
||||
}
|
||||
|
||||
|
||||
void EasyPutGet::putGet()
|
||||
void PvaClientPutGet::putGet()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPutGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
|
||||
issuePutGet();
|
||||
Status status = waitPutGet();
|
||||
if(status.isOK()) return;
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyPutGet::putGet " << status.getMessage();
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPutGet::putGet " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void EasyPutGet::issuePutGet()
|
||||
void PvaClientPutGet::issuePutGet()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPutGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
|
||||
if(connectState==connectIdle) connect();
|
||||
if(putGetState!=putGetIdle) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyPutGet::issueGet get or put aleady active ";
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPutGet::issueGet get or put aleady active ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
putGetState = putGetActive;
|
||||
channelPutGet->putGet(easyPutData->getPVStructure(),easyPutData->getBitSet());
|
||||
channelPutGet->putGet(pvaClientPutData->getPVStructure(),pvaClientPutData->getBitSet());
|
||||
}
|
||||
|
||||
|
||||
Status EasyPutGet::waitPutGet()
|
||||
Status PvaClientPutGet::waitPutGet()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPutGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
|
||||
if(putGetState!=putGetActive){
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyPutGet::waitPutGet llegal put state";
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPutGet::waitPutGet llegal put state";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
waitForPutGet.wait();
|
||||
@@ -272,36 +272,36 @@ Status EasyPutGet::waitPutGet()
|
||||
return Status(Status::STATUSTYPE_ERROR,channelGetPutGetStatus.getMessage());
|
||||
}
|
||||
|
||||
void EasyPutGet::getGet()
|
||||
void PvaClientPutGet::getGet()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPutGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
|
||||
issueGetGet();
|
||||
Status status = waitGetGet();
|
||||
if(status.isOK()) return;
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyPutGet::getGet " << status.getMessage();
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPutGet::getGet " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void EasyPutGet::issueGetGet()
|
||||
void PvaClientPutGet::issueGetGet()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPutGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
|
||||
if(connectState==connectIdle) connect();
|
||||
if(putGetState!=putGetIdle) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyPutGet::issueGetGet aleady active ";
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPutGet::issueGetGet aleady active ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
putGetState = putGetActive;
|
||||
channelPutGet->getGet();
|
||||
}
|
||||
|
||||
Status EasyPutGet::waitGetGet()
|
||||
Status PvaClientPutGet::waitGetGet()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPutGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
|
||||
if(putGetState!=putGetActive){
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyPutGet::waitGetGet illegal state";
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPutGet::waitGetGet illegal state";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
waitForPutGet.wait();
|
||||
@@ -312,36 +312,36 @@ Status EasyPutGet::waitGetGet()
|
||||
return Status(Status::STATUSTYPE_ERROR,channelGetPutGetStatus.getMessage());
|
||||
}
|
||||
|
||||
void EasyPutGet::getPut()
|
||||
void PvaClientPutGet::getPut()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPutGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
|
||||
issueGetPut();
|
||||
Status status = waitGetPut();
|
||||
if(status.isOK()) return;
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyPutGet::getPut " << status.getMessage();
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPutGet::getPut " << status.getMessage();
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void EasyPutGet::issueGetPut()
|
||||
void PvaClientPutGet::issueGetPut()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPutGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
|
||||
if(connectState==connectIdle) connect();
|
||||
if(putGetState!=putGetIdle) {
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyPutGet::issueGetPut aleady active ";
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPutGet::issueGetPut aleady active ";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
putGetState = putGetActive;
|
||||
channelPutGet->getPut();
|
||||
}
|
||||
|
||||
Status EasyPutGet::waitGetPut()
|
||||
Status PvaClientPutGet::waitGetPut()
|
||||
{
|
||||
if(isDestroyed) throw std::runtime_error("easyPutGet was destroyed");
|
||||
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
|
||||
if(putGetState!=putGetActive){
|
||||
stringstream ss;
|
||||
ss << "channel " << channel->getChannelName() << " EasyPutGet::waitGetPut illegal state";
|
||||
ss << "channel " << channel->getChannelName() << " PvaClientPutGet::waitGetPut illegal state";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
waitForPutGet.wait();
|
||||
@@ -352,25 +352,25 @@ Status EasyPutGet::waitGetPut()
|
||||
return Status(Status::STATUSTYPE_ERROR,channelGetPutGetStatus.getMessage());
|
||||
}
|
||||
|
||||
EasyGetDataPtr EasyPutGet::getGetData()
|
||||
PvaClientGetDataPtr PvaClientPutGet::getGetData()
|
||||
{
|
||||
checkPutGetState();
|
||||
return easyGetData;
|
||||
return pvaClientGetData;
|
||||
}
|
||||
|
||||
EasyPutDataPtr EasyPutGet::getPutData()
|
||||
PvaClientPutDataPtr PvaClientPutGet::getPutData()
|
||||
{
|
||||
checkPutGetState();
|
||||
return easyPutData;
|
||||
return pvaClientPutData;
|
||||
}
|
||||
|
||||
EasyPutGetPtr EasyPutGet::create(
|
||||
EasyPVAPtr const &pva,
|
||||
EasyChannelPtr const & easyChannel,
|
||||
PvaClientPutGetPtr PvaClientPutGet::create(
|
||||
PvaClientPtr const &pvaClient,
|
||||
PvaClientChannelPtr const & pvaClientChannel,
|
||||
Channel::shared_pointer const & channel,
|
||||
PVStructurePtr const &pvRequest)
|
||||
{
|
||||
EasyPutGetPtr epv(new EasyPutGet(pva,easyChannel,channel,pvRequest));
|
||||
PvaClientPutGetPtr epv(new PvaClientPutGet(pvaClient,pvaClientChannel,channel,pvRequest));
|
||||
return epv;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user