still working on RAII

This commit is contained in:
mrkraimer
2016-05-24 10:35:10 -04:00
parent 643fa9b40b
commit 3008825587
16 changed files with 446 additions and 347 deletions

View File

@@ -125,27 +125,6 @@ public:
void message(
std::string const & message,
epics::pvData::MessageType messageType);
/** Get a cached channel or create and connect to a new channel.
*
* The provider is pva. The timeout is 5 seconds.
* @param channelName The channelName.
* @return The interface.
* @throw runtime_error if connection fails.
*/
PvaClientChannelPtr channel(std::string const & channelName)
{ return channel(channelName,"pva", 5.0); }
/** Get a cached channel or create and connect to a new channel.
*
* The timeout is 5 seconds.
* @param channelName The channelName.
* @param providerName The providerName.
* @return The interface.
* @throw runtime_error if connection fails.
*/
PvaClientChannelPtr channel(
std::string const & channelName,
std::string const &providerName)
{ return channel(channelName,providerName, 5.0); }
/** Get a cached channel or create and connect to a new channel.
* @param channelName The channelName.
* @param providerName The providerName.
@@ -155,8 +134,8 @@ public:
*/
PvaClientChannelPtr channel(
std::string const & channelName,
std::string const &providerName,
double timeOut);
std::string const &providerName = "pva",
double timeOut = 5.0);
/** Create an PvaClientChannel. The provider is pva.
* @param channelName The channelName.
* @return The interface.
@@ -223,6 +202,9 @@ class PvaClientGetCache;
typedef std::tr1::shared_ptr<PvaClientGetCache> PvaClientGetCachePtr;
class PvaClientPutCache;
typedef std::tr1::shared_ptr<PvaClientPutCache> PvaClientPutCachePtr;
// NOTE: must use seprate class that implements ChannelRequester,
// because pvAccess holds a shared_ptr to ChannelRequester instead of weak_pointer
class ChannelRequesterImpl;
typedef std::tr1::shared_ptr<ChannelRequesterImpl> ChannelRequesterImplPtr;
@@ -231,9 +213,8 @@ typedef std::tr1::shared_ptr<ChannelRequesterImpl> ChannelRequesterImplPtr;
*
* @author mrk
*/
class epicsShareClass PvaClientChannel //:
// public epics::pvAccess::ChannelRequester,
// public std::tr1::enable_shared_from_this<PvaClientChannel>
class epicsShareClass PvaClientChannel
{
public:
POINTER_DEFINITIONS(PvaClientChannel);
@@ -883,9 +864,11 @@ private:
*
* @author mrk
*/
class epicsShareClass PvaClientProcess :
public epics::pvAccess::ChannelProcessRequester,
public std::tr1::enable_shared_from_this<PvaClientProcess>
// NOTE: must use seprate class that implements ChannelProcessRequester,
// because pvAccess holds a shared_ptr to ChannelProcessRequester instead of weak_pointer
class ChannelProcessRequesterImpl;
typedef std::tr1::shared_ptr<ChannelProcessRequesterImpl> ChannelProcessRequesterImplPtr;
class epicsShareClass PvaClientProcess
{
public:
POINTER_DEFINITIONS(PvaClientProcess);
@@ -903,14 +886,7 @@ public:
/** Destructor
*/
~PvaClientProcess();
std::string getRequesterName();
void message(std::string const & message,epics::pvData::MessageType messageType);
void channelProcessConnect(
const epics::pvData::Status& status,
epics::pvAccess::ChannelProcess::shared_pointer const & channelProcess);
void processDone(
const epics::pvData::Status& status,
epics::pvAccess::ChannelProcess::shared_pointer const & channelProcess);
/** Call issueConnect and then waitConnect.
* An exception is thrown if connect fails.
* @throw runtime_error if failure.
@@ -940,6 +916,15 @@ public:
*/
void destroy() EPICS_DEPRECATED {}
private:
std::string getRequesterName();
void message(std::string const & message,epics::pvData::MessageType messageType);
void channelProcessConnect(
const epics::pvData::Status& status,
epics::pvAccess::ChannelProcess::shared_pointer const & channelProcess);
void processDone(
const epics::pvData::Status& status,
epics::pvAccess::ChannelProcess::shared_pointer const & channelProcess);
PvaClientProcess(
PvaClientPtr const &pvaClient,
epics::pvAccess::Channel::shared_pointer const & channel,
@@ -963,6 +948,8 @@ private:
enum ProcessState {processIdle,processActive,processComplete};
ProcessState processState;
ChannelProcessRequesterImplPtr channelProcessRequester;
friend class ChannelProcessRequesterImpl;
};
/**
@@ -970,11 +957,11 @@ private:
*
* @author mrk
*/
// NOTE: must use seprate class that implements ChannelGetRequester,
// because pvAccess holds a shared_ptr to ChannelGetRequester instead of weak_pointer
class ChannelGetRequesterImpl;
typedef std::tr1::shared_ptr<ChannelGetRequesterImpl> ChannelGetRequesterImplPtr;
class epicsShareClass PvaClientGet //:
// public epics::pvAccess::ChannelGetRequester,
// public std::tr1::enable_shared_from_this<PvaClientGet>
class epicsShareClass PvaClientGet
{
public:
POINTER_DEFINITIONS(PvaClientGet);
@@ -992,17 +979,6 @@ public:
/** Destructor
*/
~PvaClientGet();
std::string getRequesterName();
void message(std::string const & message,epics::pvData::MessageType messageType);
void channelGetConnect(
const epics::pvData::Status& status,
epics::pvAccess::ChannelGet::shared_pointer const & channelGet,
epics::pvData::StructureConstPtr const & structure);
void getDone(
const epics::pvData::Status& status,
epics::pvAccess::ChannelGet::shared_pointer const & channelGet,
epics::pvData::PVStructurePtr const & pvStructure,
epics::pvData::BitSetPtr const & bitSet);
/** Call issueConnect and then waitConnect.
* An exception is thrown if connect fails.
* @throw runtime_error if failure.
@@ -1038,6 +1014,18 @@ public:
*/
void destroy() EPICS_DEPRECATED {}
private:
std::string getRequesterName();
void message(std::string const & message,epics::pvData::MessageType messageType);
void channelGetConnect(
const epics::pvData::Status& status,
epics::pvAccess::ChannelGet::shared_pointer const & channelGet,
epics::pvData::StructureConstPtr const & structure);
void getDone(
const epics::pvData::Status& status,
epics::pvAccess::ChannelGet::shared_pointer const & channelGet,
epics::pvData::PVStructurePtr const & pvStructure,
epics::pvData::BitSetPtr const & bitSet);
PvaClientGet(
PvaClientPtr const &pvaClient,
epics::pvAccess::Channel::shared_pointer const & channel,
@@ -1065,6 +1053,7 @@ private:
enum GetState {getIdle,getActive,getComplete};
GetState getState;
ChannelGetRequesterImplPtr channelGetRequester;
friend class ChannelGetRequesterImpl;
};
/**
@@ -1072,9 +1061,11 @@ private:
*
* @author mrk
*/
class epicsShareClass PvaClientPut :
public epics::pvAccess::ChannelPutRequester,
public std::tr1::enable_shared_from_this<PvaClientPut>
// NOTE: must use seprate class that implements ChannelPutRequester,
// because pvAccess holds a shared_ptr to ChannelPutRequester instead of weak_pointer
class ChannelPutRequesterImpl;
typedef std::tr1::shared_ptr<ChannelPutRequesterImpl> ChannelPutRequesterImplPtr;
class epicsShareClass PvaClientPut
{
public:
POINTER_DEFINITIONS(PvaClientPut);
@@ -1092,20 +1083,7 @@ public:
/** Destructor
*/
~PvaClientPut();
std::string getRequesterName();
void message(std::string const & message,epics::pvData::MessageType messageType);
void channelPutConnect(
const epics::pvData::Status& status,
epics::pvAccess::ChannelPut::shared_pointer const & channelPut,
epics::pvData::StructureConstPtr const & structure);
void getDone(
const epics::pvData::Status& status,
epics::pvAccess::ChannelPut::shared_pointer const & channelPut,
epics::pvData::PVStructurePtr const & pvStructure,
epics::pvData::BitSetPtr const & bitSet);
void putDone(
const epics::pvData::Status& status,
epics::pvAccess::ChannelPut::shared_pointer const & channelPut);
/** Call issueConnect and then waitConnect.
* An exception is thrown if connect fails.
* @throw runtime_error if failure.
@@ -1152,6 +1130,20 @@ public:
*/
void destroy() EPICS_DEPRECATED {}
private :
std::string getRequesterName();
void message(std::string const & message,epics::pvData::MessageType messageType);
void channelPutConnect(
const epics::pvData::Status& status,
epics::pvAccess::ChannelPut::shared_pointer const & channelPut,
epics::pvData::StructureConstPtr const & structure);
void getDone(
const epics::pvData::Status& status,
epics::pvAccess::ChannelPut::shared_pointer const & channelPut,
epics::pvData::PVStructurePtr const & pvStructure,
epics::pvData::BitSetPtr const & bitSet);
void putDone(
const epics::pvData::Status& status,
epics::pvAccess::ChannelPut::shared_pointer const & channelPut);
PvaClientPut(
PvaClientPtr const &pvaClient,
epics::pvAccess::Channel::shared_pointer const & channel,
@@ -1176,6 +1168,8 @@ private :
enum PutState {putIdle,getActive,putActive};
PutState putState;
ChannelPutRequesterImplPtr channelPutRequester;
friend class ChannelPutRequesterImpl;
};
/**
@@ -1183,9 +1177,11 @@ private :
*
* @author mrk
*/
class epicsShareClass PvaClientPutGet :
public epics::pvAccess::ChannelPutGetRequester,
public std::tr1::enable_shared_from_this<PvaClientPutGet>
// NOTE: must use seprate class that implements ChannelPutGetRequester,
// because pvAccess holds a shared_ptr to ChannelPutGetRequester instead of weak_pointer
class ChannelPutGetRequesterImpl;
typedef std::tr1::shared_ptr<ChannelPutGetRequesterImpl> ChannelPutGetRequesterImplPtr;
class epicsShareClass PvaClientPutGet
{
public:
POINTER_DEFINITIONS(PvaClientPutGet);
@@ -1203,28 +1199,7 @@ public:
/** Destructor
*/
~PvaClientPutGet();
std::string getRequesterName();
void message(std::string const & message,epics::pvData::MessageType 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);
void putGetDone(
const epics::pvData::Status& status,
epics::pvAccess::ChannelPutGet::shared_pointer const & channelPutGet,
epics::pvData::PVStructurePtr const & getPVStructure,
epics::pvData::BitSetPtr const & getBitSet);
void getPutDone(
const epics::pvData::Status& status,
epics::pvAccess::ChannelPutGet::shared_pointer const & channelPutGet,
epics::pvData::PVStructurePtr const & putPVStructure,
epics::pvData::BitSet::shared_pointer const & putBitSet);
void getGetDone(
const epics::pvData::Status& status,
epics::pvAccess::ChannelPutGet::shared_pointer const & channelPutGet,
epics::pvData::PVStructurePtr const & getPVStructure,
epics::pvData::BitSet::shared_pointer const & getBitSet);
/** Call issueConnect and then waitConnect.
* An exception is thrown if connect fails.
* @throw runtime_error if failure.
@@ -1287,6 +1262,29 @@ public:
*/
void destroy() EPICS_DEPRECATED {}
private :
std::string getRequesterName();
void message(std::string const & message,epics::pvData::MessageType 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);
void putGetDone(
const epics::pvData::Status& status,
epics::pvAccess::ChannelPutGet::shared_pointer const & channelPutGet,
epics::pvData::PVStructurePtr const & getPVStructure,
epics::pvData::BitSetPtr const & getBitSet);
void getPutDone(
const epics::pvData::Status& status,
epics::pvAccess::ChannelPutGet::shared_pointer const & channelPutGet,
epics::pvData::PVStructurePtr const & putPVStructure,
epics::pvData::BitSet::shared_pointer const & putBitSet);
void getGetDone(
const epics::pvData::Status& status,
epics::pvAccess::ChannelPutGet::shared_pointer const & channelPutGet,
epics::pvData::PVStructurePtr const & getPVStructure,
epics::pvData::BitSet::shared_pointer const & getBitSet);
PvaClientPutGet(
PvaClientPtr const &pvaClient,
epics::pvAccess::Channel::shared_pointer const & channel,
@@ -1311,6 +1309,8 @@ private :
enum PutGetState {putGetIdle,putGetActive,putGetComplete};
PutGetState putGetState;
ChannelPutGetRequesterImplPtr channelPutGetRequester;
friend class ChannelPutGetRequesterImpl;
};
//class ChannelMonitorRequester; // private to PvaClientMonitor
@@ -1333,8 +1333,11 @@ public:
* @brief An easy to use alternative to Monitor.
*
*/
// NOTE: must use seprate class that implements MonitorRequester,
// because pvAccess holds a shared_ptr to MonitorRequester instead of weak_pointer
class MonitorRequesterImpl;
typedef std::tr1::shared_ptr<MonitorRequesterImpl> MonitorRequesterImplPtr;
class epicsShareClass PvaClientMonitor :
public epics::pvData::MonitorRequester,
public std::tr1::enable_shared_from_this<PvaClientMonitor>
{
public:
@@ -1353,38 +1356,8 @@ public:
/** Destructor
*/
~PvaClientMonitor();
/** epics::pvData::MonitorRequester method
* The requester must have a name.
* @return The requester's name.
*/
virtual std::string getRequesterName();
/** epics::pvData::MonitorRequester method
* A message for the requester.
* @param message The message.
* @param messageType The type of message:
*/
virtual void message(std::string const & message,epics::pvData::MessageType messageType);
/** epics::pvData::MonitorRequester method
* @param status Completion status.
* @param monitor The monitor
* @param structure The structure defining the data.
*/
virtual void monitorConnect(
const epics::pvData::Status& status,
epics::pvData::MonitorPtr const & monitor,
epics::pvData::StructureConstPtr const & structure);
/** epics::pvData::MonitorRequester method
* The client and server have both completed the createMonitor request.
* The data source is no longer available.
* @param monitor The monitor.
*/
virtual void unlisten(epics::pvData::MonitorPtr const & monitor);
/** epics::pvData::MonitorRequester method
* A monitor event has occurred.
* The requester must call Monitor.poll to get data.
* @param monitor The monitor.
*/
virtual void monitorEvent(epics::pvData::MonitorPtr const & monitor);
/** Call issueConnect and then waitConnect.
* An exception is thrown if connect fails.
*/
@@ -1427,17 +1400,20 @@ public:
* @return The interface.
*/
PvaClientMonitorDataPtr getData();
/** Get shared pointer to this
*/
PvaClientMonitorPtr getPtrSelf()
{
return shared_from_this();
}
/** Deprecated method
* \deprecated This method will go away in future versions.
*/
void destroy() EPICS_DEPRECATED {}
private:
virtual std::string getRequesterName();
virtual void message(std::string const & message,epics::pvData::MessageType messageType);
virtual void monitorConnect(
const epics::pvData::Status& status,
epics::pvData::MonitorPtr const & monitor,
epics::pvData::StructureConstPtr const & structure);
virtual void unlisten(epics::pvData::MonitorPtr const & monitor);
virtual void monitorEvent(epics::pvData::MonitorPtr const & monitor);
PvaClientMonitor(
PvaClientPtr const &pvaClient,
epics::pvAccess::Channel::shared_pointer const & channel,
@@ -1463,6 +1439,8 @@ private:
MonitorConnectState connectState;
bool userPoll;
bool userWait;
MonitorRequesterImplPtr monitorRequester;
friend class MonitorRequesterImpl;
};
}}

View File

@@ -26,11 +26,6 @@ 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();
class PvaClientChannelCache
{
@@ -43,7 +38,6 @@ public:
string const & channelName,
string const & providerName);
void addChannel(PvaClientChannelPtr const & pvaClientChannel);
void removeChannel(string const & channelName,string const & providerName);
void showCache();
size_t cacheSize();
private:
@@ -83,7 +77,6 @@ void PvaClientChannelCache::showCache()
string channelName = channel->getChannelName();
string providerName = channel->getProvider()->getProviderName();
cout << "channel " << channelName << " provider " << providerName << endl;
cout << " get and put cacheSize " << pvaChannel->cacheSize() << endl;
pvaChannel->showCache();
}
@@ -138,14 +131,13 @@ PvaClient::~PvaClient() {
if(PvaClient::debug) cout<< "PvaClient::~PvaClient()\n";
{
Lock xx(mutex);
if(isDestroyed) {
cerr<< "Why was PvaClient::~PvaClient() called more then once????\n";
return;
}
if(isDestroyed) throw std::runtime_error("pvaClient was destroyed");
isDestroyed = true;
}
if(PvaClient::debug) showCache();
pvaClientChannelCache.reset();
if(PvaClient::debug) {
cout << "pvaChannel cache:\n";
showCache();
}
if(pvaStarted){
if(PvaClient::debug) cout<< "calling ClientFactory::stop()\n";
ClientFactory::stop();
@@ -206,12 +198,16 @@ void PvaClient::setRequester(RequesterPtr const & requester)
void PvaClient::clearRequester()
{
requester = Requester::weak_pointer();
requester.reset();
}
void PvaClient::showCache()
{
pvaClientChannelCache->showCache();
if(pvaClientChannelCache->cacheSize()>=1) {
pvaClientChannelCache->showCache();
} else {
cout << "pvaClientChannelCache is empty\n";
}
}

View File

@@ -32,7 +32,7 @@ public:
PvaClientGetCache(){}
~PvaClientGetCache()
{
pvaClientGetMap.clear();
if(PvaClient::getDebug()) cout << "PvaClientGetCache::~PvaClientGetCache\n";
}
PvaClientGetPtr getGet(string const & request);
void addGet(string const & request,PvaClientGetPtr const & pvaClientGet);
@@ -79,7 +79,7 @@ public:
PvaClientPutCache(){}
~PvaClientPutCache()
{
pvaClientPutMap.clear();
if(PvaClient::getDebug()) cout << "PvaClientPutCache::~PvaClientPutCache\n";
}
PvaClientPutPtr getPut(string const & request);
void addPut(string const & request,PvaClientPutPtr const & pvaClientPut);
@@ -208,7 +208,7 @@ PvaClientChannel::~PvaClientChannel()
}
{
Lock xx(mutex);
if(isDestroyed) return;
if(isDestroyed) throw std::runtime_error("pvaClientChannel was destroyed");
isDestroyed = true;
}
if(PvaClient::getDebug()) showCache();
@@ -227,7 +227,6 @@ void PvaClientChannel::channelCreated(const Status& status, Channel::shared_poin
<< endl;
}
Lock xx(mutex);
if(isDestroyed) throw std::runtime_error("pvaClientChannel was destroyed");
if(connectState!=connectActive) {
string message("PvaClientChannel::channelCreated");
message += " channel " + channelName
@@ -256,7 +255,6 @@ void PvaClientChannel::channelStateChange(
<< endl;
}
Lock xx(mutex);
if(isDestroyed) return;
bool waitingForConnect = false;
if(connectState==connectActive) waitingForConnect = true;
if(connectionState!=Channel::CONNECTED) {
@@ -289,22 +287,16 @@ void PvaClientChannel::message(
string PvaClientChannel::getChannelName()
{
if(isDestroyed) throw std::runtime_error(
"PvaClientChannel::getChannelName() pvaClientChannel was destroyed");
return channelName;
}
Channel::shared_pointer PvaClientChannel::getChannel()
{
if(isDestroyed) throw std::runtime_error(
"PvaClientChannel::getChannel() pvaClientChannel was destroyed");
return channel;
}
void PvaClientChannel::connect(double timeout)
{
if(isDestroyed) throw std::runtime_error(
"PvaClientChannel::connect() pvaClientChannel was destroyed");
if(PvaClient::getDebug()) {
cout << "PvaClientChannel::connect"
<< " channelName " << channelName << endl;
@@ -320,15 +312,12 @@ void PvaClientChannel::connect(double timeout)
void PvaClientChannel::issueConnect()
{
if(isDestroyed) throw std::runtime_error(
"PvaClientChannel::issueConnect() pvaClientChannel was destroyed");
if(PvaClient::getDebug()) {
cout << "PvaClientChannel::issueConnect"
<< " channelName " << channelName << endl;
}
{
Lock xx(mutex);
if(isDestroyed) throw std::runtime_error("pvaClientChannel was destroyed");
if(connectState!=connectIdle) {
throw std::runtime_error("pvaClientChannel already connected");
}
@@ -339,7 +328,6 @@ void PvaClientChannel::issueConnect()
if(!provider) {
throw std::runtime_error(channelName + " provider " + providerName + " not registered");
}
// ChannelRequester::shared_pointer channelRequester(shared_from_this());
if(PvaClient::getDebug()) cout << "PvaClientChannel::issueConnect calling provider->createChannel\n";
channel = provider->createChannel(channelName,channelRequester,ChannelProvider::PRIORITY_DEFAULT);
if(!channel) {
@@ -349,15 +337,12 @@ void PvaClientChannel::issueConnect()
Status PvaClientChannel::waitConnect(double timeout)
{
if(isDestroyed) throw std::runtime_error(
"PvaClientChannel::waitConnect() pvaClientChannel was destroyed");
if(PvaClient::getDebug()) {
cout << "PvaClientChannel::waitConnect"
<< " channelName " << channelName << endl;
}
{
Lock xx(mutex);
if(isDestroyed) throw std::runtime_error("pvaClientChannel was destroyed");
if(channel->isConnected()) return Status::Ok;
}
if(timeout>0.0) {
@@ -585,10 +570,18 @@ PvaClientMonitorPtr PvaClientChannel::createMonitor(PVStructurePtr const & pvR
void PvaClientChannel::showCache()
{
cout << " pvaClientGet" << endl;
pvaClientGetCache->showCache();
cout << " pvaClientPut" << endl;
pvaClientPutCache->showCache();
if(pvaClientGetCache->cacheSize()>=1) {
cout << " pvaClientGet cache" << endl;
pvaClientGetCache->showCache();
} else {
cout << " pvaClientGet cache is empty\n";
}
if(pvaClientPutCache->cacheSize()>=1) {
cout << " pvaClientPut cache" << endl;
pvaClientPutCache->showCache();
} else {
cout << " pvaClientPut cache is empty\n";
}
}
size_t PvaClientChannel::cacheSize()

View File

@@ -102,14 +102,13 @@ PvaClientGet::~PvaClientGet()
if(PvaClient::getDebug()) cout<< "PvaClientGet::~PvaClientGet()\n";
{
Lock xx(mutex);
if(isDestroyed) return;
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
isDestroyed = true;
}
}
void PvaClientGet::checkGetState()
{
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
if(connectState==connectIdle) connect();
if(getState==getIdle) get();
}
@@ -139,7 +138,6 @@ void PvaClientGet::channelGetConnect(
<< " status.isOK " << (status.isOK() ? "true" : "false")
<< endl;
}
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
{
Lock xx(mutex);
channelGetConnectStatus = status;
@@ -166,7 +164,6 @@ void PvaClientGet::getDone(
<< " status.isOK " << (status.isOK() ? "true" : "false")
<< endl;
}
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
{
Lock xx(mutex);
channelGetStatus = status;
@@ -180,7 +177,6 @@ void PvaClientGet::getDone(
void PvaClientGet::connect()
{
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
issueConnect();
Status status = waitConnect();
if(status.isOK()) return;
@@ -194,7 +190,6 @@ void PvaClientGet::connect()
void PvaClientGet::issueConnect()
{
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
if(connectState!=connectIdle) {
Channel::shared_pointer chan(channel.lock());
string channelName("disconnected");
@@ -203,7 +198,6 @@ void PvaClientGet::issueConnect()
+ " pvaClientGet already connected ";
throw std::runtime_error(message);
}
// ChannelGetRequester::shared_pointer channelGetRequester(shared_from_this());
connectState = connectActive;
Channel::shared_pointer chan(channel.lock());
if(chan) {
@@ -215,7 +209,6 @@ void PvaClientGet::issueConnect()
Status PvaClientGet::waitConnect()
{
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
{
Lock xx(mutex);
if(connectState==connected) {
@@ -238,7 +231,6 @@ Status PvaClientGet::waitConnect()
void PvaClientGet::get()
{
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
issueGet();
Status status = waitGet();
if(status.isOK()) return;
@@ -252,7 +244,6 @@ void PvaClientGet::get()
void PvaClientGet::issueGet()
{
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
if(connectState==connectIdle) connect();
if(getState!=getIdle) {
Channel::shared_pointer chan(channel.lock());
@@ -268,7 +259,6 @@ void PvaClientGet::issueGet()
Status PvaClientGet::waitGet()
{
if(isDestroyed) throw std::runtime_error("pvaClientGet was destroyed");
{
Lock xx(mutex);
if(getState==getComplete) {

View File

@@ -25,6 +25,70 @@ using namespace std;
namespace epics { namespace pvaClient {
class MonitorRequesterImpl : public MonitorRequester
{
PvaClientMonitor::weak_pointer pvaClientMonitor;
PvaClient::weak_pointer pvaClient;
public:
MonitorRequesterImpl(
PvaClientMonitorPtr const & pvaClientMonitor,
PvaClientPtr const &pvaClient)
: pvaClientMonitor(pvaClientMonitor),
pvaClient(pvaClient)
{}
virtual ~MonitorRequesterImpl() {
if(PvaClient::getDebug()) std::cout << "~MonitorRequesterImpl" << std::endl;
}
virtual std::string getRequesterName() {
PvaClientMonitorPtr clientMonitor(pvaClientMonitor.lock());
if(!clientMonitor) return string("pvaClientMonitor is null");
return clientMonitor->getRequesterName();
}
virtual void message(std::string const & message, epics::pvData::MessageType messageType) {
PvaClientMonitorPtr clientMonitor(pvaClientMonitor.lock());
if(!clientMonitor) return;
clientMonitor->message(message,messageType);
}
virtual void monitorConnect(
const Status& status,
Monitor::shared_pointer const & monitor,
Structure::const_shared_pointer const & structure)
{
PvaClientMonitorPtr clientMonitor(pvaClientMonitor.lock());
if(!clientMonitor) return;
clientMonitor->monitorConnect(status,monitor,structure);
}
virtual void unlisten(epics::pvData::MonitorPtr const & monitor)
{
PvaClientMonitorPtr clientMonitor(pvaClientMonitor.lock());
if(!clientMonitor) return;
clientMonitor->unlisten(monitor);
}
virtual void monitorEvent(epics::pvData::MonitorPtr const & monitor)
{
PvaClientMonitorPtr clientMonitor(pvaClientMonitor.lock());
if(!clientMonitor) return;
clientMonitor->monitorEvent(monitor);
}
};
PvaClientMonitorPtr PvaClientMonitor::create(
PvaClientPtr const &pvaClient,
Channel::shared_pointer const & channel,
PVStructurePtr const &pvRequest)
{
PvaClientMonitorPtr epv(new PvaClientMonitor(pvaClient,channel,pvRequest));
epv->monitorRequester = MonitorRequesterImplPtr(
new MonitorRequesterImpl(epv,pvaClient));
return epv;
}
PvaClientMonitor::PvaClientMonitor(
PvaClientPtr const &pvaClient,
Channel::shared_pointer const & channel,
@@ -45,27 +109,22 @@ PvaClientMonitor::~PvaClientMonitor()
if(PvaClient::getDebug()) cout<< "PvaClientMonitor::~PvaClientMonitor()\n";
{
Lock xx(mutex);
if(isDestroyed) {
cerr<< "Why was PvaClientMonitor::~PvaClientMonitor() called more then once????\n";
return;
}
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
isDestroyed = true;
}
if(monitor) monitor->destroy();
monitor.reset();
monitorElement.reset();
}
void PvaClientMonitor::checkMonitorState()
{
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
if(PvaClient::getDebug()) cout<< "PvaClientMonitor::checkMonitorState()\n";
if(connectState==connectIdle) connect();
if(connectState==connected) start();
}
// from MonitorRequester
string PvaClientMonitor::getRequesterName()
{
if(PvaClient::getDebug()) cout<< "PvaClientMonitor::getRequesterName()\n";
PvaClientPtr yyy = pvaClient.lock();
if(!yyy) throw std::runtime_error("pvaClient was destroyed");
return yyy->getRequesterName();
@@ -73,7 +132,7 @@ string PvaClientMonitor::getRequesterName()
void PvaClientMonitor::message(string const & message,MessageType messageType)
{
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
if(PvaClient::getDebug()) cout<< "PvaClientMonitor::message()\n";
PvaClientPtr yyy = pvaClient.lock();
if(!yyy) throw std::runtime_error("pvaClient was destroyed");
yyy->message(message, messageType);
@@ -84,7 +143,7 @@ void PvaClientMonitor::monitorConnect(
Monitor::shared_pointer const & monitor,
StructureConstPtr const & structure)
{
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
if(PvaClient::getDebug()) cout<< "PvaClientMonitor::monitorConnect()\n";
connectStatus = status;
connectState = connected;
this->monitor = monitor;
@@ -98,29 +157,21 @@ void PvaClientMonitor::monitorConnect(
void PvaClientMonitor::monitorEvent(MonitorPtr const & monitor)
{
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
if(PvaClient::getDebug()) cout<< "PvaClientMonitor::monitorEvent()\n";
PvaClientMonitorRequesterPtr req = pvaClientMonitorRequester.lock();
if(req) req->event(getPtrSelf());
if(req) req->event(shared_from_this());
if(userWait) waitForEvent.signal();
}
void PvaClientMonitor::unlisten(MonitorPtr const & monitor)
{
if(PvaClient::getDebug()) cout << "PvaClientMonitor::unlisten\n";
{
Lock xx(mutex);
if(isDestroyed) {
cerr<< "Why was PvaClientMonitor::unlisten called when PvaClientMonitor was destroyed?\n";
return;
}
}
this->monitor.reset();
this->monitorElement.reset();
throw std::runtime_error("pvaClientMonitor::unlisten called but do not know what to do");
}
void PvaClientMonitor::connect()
{
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
if(PvaClient::getDebug()) cout << "PvaClientMonitor::connect\n";
issueConnect();
Status status = waitConnect();
if(status.isOK()) return;
@@ -131,22 +182,19 @@ void PvaClientMonitor::connect()
void PvaClientMonitor::issueConnect()
{
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
if(PvaClient::getDebug()) cout << "PvaClientMonitor::issueConnect\n";
if(connectState!=connectIdle) {
string message = string("channel ") + channel->getChannelName()
+ " pvaClientMonitor already connected ";
throw std::runtime_error(message);
}
MonitorRequester::shared_pointer monitorRequester =
dynamic_pointer_cast<MonitorRequester>(getPtrSelf());
//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(PvaClient::getDebug()) cout << "PvaClientMonitor::waitConnect\n";
if(connectState==connected) {
if(connectStatus.isOK()) connectState = connectIdle;
return connectStatus;
@@ -163,12 +211,13 @@ Status PvaClientMonitor::waitConnect()
void PvaClientMonitor::setRequester(PvaClientMonitorRequesterPtr const & pvaClientMonitorrRequester)
{
if(PvaClient::getDebug()) cout << "PvaClientMonitor::setRequester\n";
this->pvaClientMonitorRequester = pvaClientMonitorrRequester;
}
void PvaClientMonitor::start()
{
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
if(PvaClient::getDebug()) cout << "PvaClientMonitor::start\n";
if(connectState==monitorStarted) return;
if(connectState==connectIdle) connect();
if(connectState!=connected) throw std::runtime_error("PvaClientMonitor::start illegal state");
@@ -179,7 +228,7 @@ void PvaClientMonitor::start()
void PvaClientMonitor::stop()
{
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
if(PvaClient::getDebug()) cout << "PvaClientMonitor::stop\n";
if(connectState!=monitorStarted) return;
connectState = connected;
monitor->stop();
@@ -187,6 +236,7 @@ void PvaClientMonitor::stop()
bool PvaClientMonitor::poll()
{
if(PvaClient::getDebug()) cout << "PvaClientMonitor::poll\n";
checkMonitorState();
if(connectState!=monitorStarted) throw std::runtime_error("PvaClientMonitor::poll illegal state");
if(userPoll) throw std::runtime_error("PvaClientMonitor::poll did not release last");
@@ -199,7 +249,7 @@ bool PvaClientMonitor::poll()
bool PvaClientMonitor::waitEvent(double secondsToWait)
{
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
if(PvaClient::getDebug()) cout << "PvaClientMonitor::waitEvent\n";
if(connectState!=monitorStarted) throw std::runtime_error("PvaClientMonitor::waitEvent illegal state");
if(poll()) return true;
userWait = true;
@@ -214,7 +264,7 @@ bool PvaClientMonitor::waitEvent(double secondsToWait)
void PvaClientMonitor::releaseEvent()
{
if(isDestroyed) throw std::runtime_error("pvaClientMonitor was destroyed");
if(PvaClient::getDebug()) cout << "PvaClientMonitor::releaseEvent\n";
if(connectState!=monitorStarted) throw std::runtime_error(
"PvaClientMonitor::poll illegal state");
if(!userPoll) throw std::runtime_error("PvaClientMonitor::releaseEvent did not call poll");
@@ -224,17 +274,10 @@ void PvaClientMonitor::releaseEvent()
PvaClientMonitorDataPtr PvaClientMonitor::getData()
{
if(PvaClient::getDebug()) cout << "PvaClientMonitor::getData\n";
checkMonitorState();
return pvaClientData;
}
PvaClientMonitorPtr PvaClientMonitor::create(
PvaClientPtr const &pvaClient,
Channel::shared_pointer const & channel,
PVStructurePtr const &pvRequest)
{
PvaClientMonitorPtr epv(new PvaClientMonitor(pvaClient,channel,pvRequest));
return epv;
}
}}

View File

@@ -64,10 +64,7 @@ PvaClientMultiChannel::~PvaClientMultiChannel()
if(PvaClient::getDebug()) cout<< "PvaClientMultiChannel::~PvaClientMultiChannel()\n";
{
Lock xx(mutex);
if(isDestroyed) {
cerr<< "Why was PvaClientMultiChannel::~PvaClientMultiChannel() called more then once????\n";
return;
}
if(isDestroyed) throw std::runtime_error("pvaClientMultiChannel was destroyed");
isDestroyed = true;
}
pvaClientChannelArray.clear();
@@ -80,13 +77,11 @@ void PvaClientMultiChannel::checkConnected()
epics::pvData::shared_vector<const string> PvaClientMultiChannel::getChannelNames()
{
if(isDestroyed) throw std::runtime_error("pvaClientMultiChannel was destroyed");
return channelName;
}
Status PvaClientMultiChannel::connect(double timeout)
{
if(isDestroyed) throw std::runtime_error("pvaClientMultiChannel was destroyed");
for(size_t i=0; i< numChannel; ++i) {
pvaClientChannelArray[i] = pvaClient->createChannel(channelName[i],providerName);
pvaClientChannelArray[i]->issueConnect();
@@ -115,13 +110,11 @@ Status PvaClientMultiChannel::connect(double timeout)
bool PvaClientMultiChannel::allConnected()
{
if(isDestroyed) throw std::runtime_error("pvaClientMultiChannel was destroyed");
return (numConnected==numChannel) ? true : false;
}
bool PvaClientMultiChannel::connectionChange()
{
if(isDestroyed) throw std::runtime_error("pvaClientMultiChannel was destroyed");
for(size_t i=0; i<numChannel; ++i) {
PvaClientChannelPtr pvaClientChannel = pvaClientChannelArray[i];
Channel::shared_pointer channel = pvaClientChannel->getChannel();
@@ -134,7 +127,6 @@ bool PvaClientMultiChannel::connectionChange()
epics::pvData::shared_vector<epics::pvData::boolean> PvaClientMultiChannel::getIsConnected()
{
if(isDestroyed) throw std::runtime_error("pvaClientMultiChannel was destroyed");
for(size_t i=0; i<numChannel; ++i) {
PvaClientChannelPtr pvaClientChannel = pvaClientChannelArray[i];
if(!pvaClientChannel) {
@@ -150,13 +142,11 @@ epics::pvData::shared_vector<epics::pvData::boolean> PvaClientMultiChannel::get
PvaClientChannelArray PvaClientMultiChannel::getPvaClientChannelArray()
{
if(isDestroyed) throw std::runtime_error("pvaClientMultiChannel was destroyed");
return pvaClientChannelArray;
}
PvaClientPtr PvaClientMultiChannel::getPvaClient()
{
if(isDestroyed) throw std::runtime_error("pvaClientMultiChannel was destroyed");
return pvaClient;
}

View File

@@ -59,10 +59,7 @@ PvaClientMultiGetDouble::~PvaClientMultiGetDouble()
if(PvaClient::getDebug()) cout<< "PvaClientMultiGetDouble::~PvaClientMultiGetDouble()\n";
{
Lock xx(mutex);
if(isDestroyed) {
cerr<< "Why was PvaClientMultiGetDouble::~PvaClientMultiGetDouble() called more then once????\n";
return;
}
if(isDestroyed) throw std::runtime_error("pvaClientMultiGetDouble was destroyed");
isDestroyed = true;
}
pvaClientChannelArray.clear();

View File

@@ -60,10 +60,7 @@ PvaClientMultiMonitorDouble::~PvaClientMultiMonitorDouble()
if(PvaClient::getDebug()) cout<< "PvaClientMultiMonitorDouble::~PvaClientMultiMonitorDouble()\n";
{
Lock xx(mutex);
if(isDestroyed) {
cerr<< "Why was PvaClientMultiMonitorDouble::~PvaClientMultiMonitorDouble() called more then once????\n";
return;
}
if(isDestroyed) throw std::runtime_error("pvaClientMultiMonitorDouble was destroyed");
isDestroyed = true;
}
pvaClientChannelArray.clear();

View File

@@ -61,10 +61,7 @@ PvaClientMultiPutDouble::~PvaClientMultiPutDouble()
if(PvaClient::getDebug()) cout<< "PvaClientMultiPutDouble::~PvaClientMultiPutDouble()\n";
{
Lock xx(mutex);
if(isDestroyed) {
cerr<< "Why was PvaClientMultiPutDouble::~PvaClientMultiPutDouble() called more then once????\n";
return;
}
if(isDestroyed) throw std::runtime_error("pvaClientMultiPutDouble was destroyed");
isDestroyed = true;
}
pvaClientChannelArray.clear();

View File

@@ -92,10 +92,7 @@ PvaClientNTMultiData::~PvaClientNTMultiData()
if(PvaClient::getDebug()) cout<< "PvaClientNTMultiData::~PvaClientNTMultiData()\n";
{
Lock xx(mutex);
if(isDestroyed) {
cerr<< "Why was PvaClientNTMultiData::~PvaClientNTMultiData() called more then once????\n";
return;
}
if(isDestroyed) throw std::runtime_error("pvaClientNTMultiData was destroyed");
isDestroyed = true;
}
pvaClientChannelArray.clear();

View File

@@ -68,10 +68,7 @@ PvaClientNTMultiGet::~PvaClientNTMultiGet()
if(PvaClient::getDebug()) cout<< "PvaClientNTMultiGet::~PvaClientNTMultiGet()\n";
{
Lock xx(mutex);
if(isDestroyed) {
cerr<< "Why was PvaClientNTMultiGet::~PvaClientNTMultiGet() called more then once????\n";
return;
}
if(isDestroyed) throw std::runtime_error("pvaClientNTMultiGet was destroyed");
isDestroyed = true;
}
pvaClientChannelArray.clear();

View File

@@ -66,10 +66,7 @@ PvaClientNTMultiMonitor::~PvaClientNTMultiMonitor()
if(PvaClient::getDebug()) cout<< "PvaClientNTMultiMonitor::~PvaClientNTMultiMonitor()\n";
{
Lock xx(mutex);
if(isDestroyed) {
cerr<< "Why was PvaClientNTMultiMonitor::~PvaClientNTMultiMonitor() called more then once????\n";
return;
}
if(isDestroyed) throw std::runtime_error("pvaClientNTMultiMonitor was destroyed");
isDestroyed = true;
}
pvaClientChannelArray.clear();

View File

@@ -57,10 +57,7 @@ PvaClientNTMultiPut::~PvaClientNTMultiPut()
if(PvaClient::getDebug()) cout<< "PvaClientNTMultiPut::~PvaClientNTMultiPut()\n";
{
Lock xx(mutex);
if(isDestroyed) {
cerr<< "Why was PvaClientNTMultiPut::~PvaClientNTMultiPut() called more then once????\n";
return;
}
if(isDestroyed) throw std::runtime_error("pvaClientNTMultiPut was destroyed");
isDestroyed = true;
}
pvaClientChannelArray.clear();

View File

@@ -22,6 +22,64 @@ using namespace std;
namespace epics { namespace pvaClient {
class ChannelProcessRequesterImpl : public ChannelProcessRequester
{
PvaClientProcess::weak_pointer pvaClientProcess;
PvaClient::weak_pointer pvaClient;
public:
ChannelProcessRequesterImpl(
PvaClientProcessPtr const & pvaClientProcess,
PvaClientPtr const &pvaClient)
: pvaClientProcess(pvaClientProcess),
pvaClient(pvaClient)
{}
virtual ~ChannelProcessRequesterImpl() {
if(PvaClient::getDebug()) std::cout << "~ChannelProcessRequesterImpl" << std::endl;
}
virtual std::string getRequesterName() {
PvaClientProcessPtr clientProcess(pvaClientProcess.lock());
if(!clientProcess) return string("clientProcess is null");
return clientProcess->getRequesterName();
}
virtual void message(std::string const & message, epics::pvData::MessageType messageType) {
PvaClientProcessPtr clientProcess(pvaClientProcess.lock());
if(!clientProcess) return;
clientProcess->message(message,messageType);
}
virtual void channelProcessConnect(
const Status& status,
ChannelProcess::shared_pointer const & channelProcess)
{
PvaClientProcessPtr clientProcess(pvaClientProcess.lock());
if(!clientProcess) return;
clientProcess->channelProcessConnect(status,channelProcess);
}
virtual void processDone(
const Status& status,
ChannelProcess::shared_pointer const & ChannelProcess)
{
PvaClientProcessPtr clientProcess(pvaClientProcess.lock());
if(!clientProcess) return;
clientProcess->processDone(status,ChannelProcess);
}
};
PvaClientProcessPtr PvaClientProcess::create(
PvaClientPtr const &pvaClient,
Channel::shared_pointer const & channel,
PVStructurePtr const &pvRequest)
{
PvaClientProcessPtr epv(new PvaClientProcess(pvaClient,channel,pvRequest));
epv->channelProcessRequester = ChannelProcessRequesterImplPtr(
new ChannelProcessRequesterImpl(epv,pvaClient));
return epv;
}
PvaClientProcess::PvaClientProcess(
PvaClientPtr const &pvaClient,
Channel::shared_pointer const & channel,
@@ -41,10 +99,7 @@ PvaClientProcess::~PvaClientProcess()
if(PvaClient::getDebug()) cout<< "PvaClientProcess::~PvaClientProcess()\n";
{
Lock xx(mutex);
if(isDestroyed) {
cerr<< "Why was PvaClientProcess::~PvaClientProcess() called more then once????\n";
return;
}
if(isDestroyed) throw std::runtime_error("pvaClientProcess was destroyed");
isDestroyed = true;
}
channelProcess->destroy();
@@ -60,7 +115,6 @@ string PvaClientProcess::getRequesterName()
void PvaClientProcess::message(string const & message,MessageType messageType)
{
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);
@@ -70,7 +124,6 @@ void PvaClientProcess::channelProcessConnect(
const Status& status,
ChannelProcess::shared_pointer const & channelProcess)
{
if(isDestroyed) return;
channelProcessConnectStatus = status;
this->channelProcess = channelProcess;
waitForConnect.signal();
@@ -81,14 +134,12 @@ void PvaClientProcess::processDone(
const Status& status,
ChannelProcess::shared_pointer const & channelProcess)
{
if(isDestroyed) return;
channelProcessStatus = status;
waitForProcess.signal();
}
void PvaClientProcess::connect()
{
if(isDestroyed) throw std::runtime_error("pvaClientProcess was destroyed");
issueConnect();
Status status = waitConnect();
if(status.isOK()) return;
@@ -99,20 +150,17 @@ void PvaClientProcess::connect()
void PvaClientProcess::issueConnect()
{
if(isDestroyed) throw std::runtime_error("pvaClientProcess was destroyed");
if(connectState!=connectIdle) {
string message = string("channel ") + channel->getChannelName()
+ " pvaClientProcess already connected ";
throw std::runtime_error(message);
}
ChannelProcessRequester::shared_pointer processRequester(shared_from_this());
connectState = connectActive;
channelProcess = channel->createChannelProcess(processRequester,pvRequest);
channelProcess = channel->createChannelProcess(channelProcessRequester,pvRequest);
}
Status PvaClientProcess::waitConnect()
{
if(isDestroyed) throw std::runtime_error("pvaClientProcess was destroyed");
if(connectState!=connectActive) {
string message = string("channel ") + channel->getChannelName()
+ " pvaClientProcess illegal connect state ";
@@ -125,7 +173,6 @@ Status PvaClientProcess::waitConnect()
void PvaClientProcess::process()
{
if(isDestroyed) throw std::runtime_error("pvaClientProcess was destroyed");
issueProcess();
Status status = waitProcess();
if(status.isOK()) return;
@@ -136,7 +183,6 @@ void PvaClientProcess::process()
void PvaClientProcess::issueProcess()
{
if(isDestroyed) throw std::runtime_error("pvaClientProcess was destroyed");
if(connectState==connectIdle) connect();
if(processState!=processIdle) {
string message = string("channel ") + channel->getChannelName()
@@ -149,7 +195,6 @@ void PvaClientProcess::issueProcess()
Status PvaClientProcess::waitProcess()
{
if(isDestroyed) throw std::runtime_error("pvaClientProcess was destroyed");
if(processState!=processActive){
string message = string("channel ") + channel->getChannelName()
+ " PvaClientProcess::waitProcess llegal process state";
@@ -160,13 +205,4 @@ Status PvaClientProcess::waitProcess()
return channelProcessStatus;
}
PvaClientProcessPtr PvaClientProcess::create(
PvaClientPtr const &pvaClient,
Channel::shared_pointer const & channel,
PVStructurePtr const &pvRequest)
{
PvaClientProcessPtr epv(new PvaClientProcess(pvaClient,channel,pvRequest));
return epv;
}
}}

View File

@@ -22,6 +22,77 @@ using namespace std;
namespace epics { namespace pvaClient {
class ChannelPutRequesterImpl : public ChannelPutRequester
{
PvaClientPut::weak_pointer pvaClientPut;
PvaClient::weak_pointer pvaClient;
public:
ChannelPutRequesterImpl(
PvaClientPutPtr const & pvaClientPut,
PvaClientPtr const &pvaClient)
: pvaClientPut(pvaClientPut),
pvaClient(pvaClient)
{}
virtual ~ChannelPutRequesterImpl() {
if(PvaClient::getDebug()) std::cout << "~ChannelPutRequesterImpl" << std::endl;
}
virtual std::string getRequesterName() {
PvaClientPutPtr clientPut(pvaClientPut.lock());
if(!clientPut) return string("clientPut is null");
return clientPut->getRequesterName();
}
virtual void message(std::string const & message, epics::pvData::MessageType messageType) {
PvaClientPutPtr clientPut(pvaClientPut.lock());
if(!clientPut) return;
clientPut->message(message,messageType);
}
virtual void channelPutConnect(
const Status& status,
ChannelPut::shared_pointer const & channelPut,
Structure::const_shared_pointer const & structure)
{
PvaClientPutPtr clientPut(pvaClientPut.lock());
if(!clientPut) return;
clientPut->channelPutConnect(status,channelPut,structure);
}
virtual void getDone(
const Status& status,
ChannelPut::shared_pointer const & channelPut,
PVStructurePtr const & pvStructure,
BitSet::shared_pointer const & bitSet)
{
PvaClientPutPtr clientPut(pvaClientPut.lock());
if(!clientPut) return;
clientPut->getDone(status,channelPut,pvStructure,bitSet);
}
virtual void putDone(
const Status& status,
ChannelPut::shared_pointer const & channelPut)
{
PvaClientPutPtr clientPut(pvaClientPut.lock());
if(!clientPut) return;
clientPut->putDone(status,channelPut);
}
};
PvaClientPutPtr PvaClientPut::create(
PvaClientPtr const &pvaClient,
Channel::shared_pointer const & channel,
PVStructurePtr const &pvRequest)
{
PvaClientPutPtr epv(new PvaClientPut(pvaClient,channel,pvRequest));
epv->channelPutRequester = ChannelPutRequesterImplPtr(
new ChannelPutRequesterImpl(epv,pvaClient));
return epv;
}
PvaClientPut::PvaClientPut(
PvaClientPtr const &pvaClient,
Channel::shared_pointer const & channel,
@@ -41,10 +112,7 @@ PvaClientPut::~PvaClientPut()
if(PvaClient::getDebug()) cout<< "PvaClientPut::~PvaClientPut()\n";
{
Lock xx(mutex);
if(isDestroyed) {
cerr<< "Why was PvaClientPut::~PvaClientPut() called more then once????\n";
return;
}
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
isDestroyed = true;
}
if(channelPut) channelPut->destroy();
@@ -52,14 +120,12 @@ PvaClientPut::~PvaClientPut()
void PvaClientPut::checkPutState()
{
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
if(connectState==connectIdle){
connect();
get();
}
}
// from ChannelPutRequester
string PvaClientPut::getRequesterName()
{
PvaClientPtr yyy = pvaClient.lock();
@@ -69,7 +135,6 @@ string PvaClientPut::getRequesterName()
void PvaClientPut::message(string const & message,MessageType messageType)
{
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
PvaClientPtr yyy = pvaClient.lock();
if(!yyy) throw std::runtime_error("pvaClient was destroyed");
yyy->message(message, messageType);
@@ -80,7 +145,6 @@ void PvaClientPut::channelPutConnect(
ChannelPut::shared_pointer const & channelPut,
StructureConstPtr const & structure)
{
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
channelPutConnectStatus = status;
this->channelPut = channelPut;
if(status.isOK()) {
@@ -97,7 +161,6 @@ void PvaClientPut::getDone(
PVStructurePtr const & pvStructure,
BitSetPtr const & bitSet)
{
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
channelGetPutStatus = status;
connectState = connected;
if(status.isOK()) {
@@ -114,14 +177,12 @@ void PvaClientPut::putDone(
const Status& status,
ChannelPut::shared_pointer const & channelPut)
{
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
channelGetPutStatus = status;
waitForGetPut.signal();
}
void PvaClientPut::connect()
{
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
issueConnect();
Status status = waitConnect();
if(status.isOK()) return;
@@ -134,20 +195,17 @@ void PvaClientPut::connect()
void PvaClientPut::issueConnect()
{
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
if(connectState!=connectIdle) {
string message = string("channel ") + channel->getChannelName()
+ " pvaClientPut already connected ";
throw std::runtime_error(message);
}
ChannelPutRequester::shared_pointer putRequester(shared_from_this());
connectState = connectActive;
channelPut = channel->createChannelPut(putRequester,pvRequest);
channelPut = channel->createChannelPut(channelPutRequester,pvRequest);
}
Status PvaClientPut::waitConnect()
{
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
if(connectState==connected) {
if(!channelPutConnectStatus.isOK()) connectState = connectIdle;
return channelPutConnectStatus;
@@ -164,7 +222,6 @@ Status PvaClientPut::waitConnect()
void PvaClientPut::get()
{
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
issueGet();
Status status = waitGet();
if(status.isOK()) return;
@@ -177,7 +234,6 @@ void PvaClientPut::get()
void PvaClientPut::issueGet()
{
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
if(connectState==connectIdle) connect();
if(putState!=putIdle) {
string message = string("channel ")
@@ -191,7 +247,6 @@ void PvaClientPut::issueGet()
Status PvaClientPut::waitGet()
{
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
if(putState!=getActive){
string message = string("channel ") + channel->getChannelName()
+ " PvaClientPut::waitGet illegal put state";
@@ -204,7 +259,6 @@ Status PvaClientPut::waitGet()
void PvaClientPut::put()
{
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
issuePut();
Status status = waitPut();
if(status.isOK()) return;
@@ -217,7 +271,6 @@ void PvaClientPut::put()
void PvaClientPut::issuePut()
{
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
if(connectState==connectIdle) connect();
if(putState!=putIdle) {
string message = string("channel ") + channel->getChannelName()
@@ -230,7 +283,6 @@ void PvaClientPut::issuePut()
Status PvaClientPut::waitPut()
{
if(isDestroyed) throw std::runtime_error("pvaClientPut was destroyed");
if(putState!=putActive){
string message = string("channel ") + channel->getChannelName()
+ " PvaClientPut::waitPut illegal put state";
@@ -248,14 +300,5 @@ PvaClientPutDataPtr PvaClientPut::getData()
return pvaClientData;
}
PvaClientPutPtr PvaClientPut::create(
PvaClientPtr const &pvaClient,
Channel::shared_pointer const & channel,
PVStructurePtr const &pvRequest)
{
PvaClientPutPtr epv(new PvaClientPut(pvaClient,channel,pvRequest));
return epv;
}
}}

View File

@@ -21,6 +21,90 @@ using namespace std;
namespace epics { namespace pvaClient {
class ChannelPutGetRequesterImpl : public ChannelPutGetRequester
{
PvaClientPutGet::weak_pointer pvaClientPutGet;
PvaClient::weak_pointer pvaClient;
public:
ChannelPutGetRequesterImpl(
PvaClientPutGetPtr const & pvaClientPutGet,
PvaClientPtr const &pvaClient)
: pvaClientPutGet(pvaClientPutGet),
pvaClient(pvaClient)
{}
virtual ~ChannelPutGetRequesterImpl() {
if(PvaClient::getDebug()) std::cout << "~ChannelPutGetRequesterImpl" << std::endl;
}
virtual std::string getRequesterName() {
PvaClientPutGetPtr clientPutGet(pvaClientPutGet.lock());
if(!clientPutGet) return string("clientPutGet is null");
return clientPutGet->getRequesterName();
}
virtual void message(std::string const & message, epics::pvData::MessageType messageType) {
PvaClientPutGetPtr clientPutGet(pvaClientPutGet.lock());
if(!clientPutGet) return;
clientPutGet->message(message,messageType);
}
virtual void channelPutGetConnect(
const Status& status,
ChannelPutGet::shared_pointer const & channelPutGet,
Structure::const_shared_pointer const & putStructure,
Structure::const_shared_pointer const & getStructure)
{
PvaClientPutGetPtr clientPutGet(pvaClientPutGet.lock());
if(!clientPutGet) return;
clientPutGet->channelPutGetConnect(status,channelPutGet,putStructure,getStructure);
}
virtual void putGetDone(
const Status& status,
ChannelPutGet::shared_pointer const & channelPutGet,
PVStructurePtr const & getPVStructure,
BitSet::shared_pointer const & getBitSet)
{
PvaClientPutGetPtr clientPutGet(pvaClientPutGet.lock());
if(!clientPutGet) return;
clientPutGet->putGetDone(status,channelPutGet,getPVStructure,getBitSet);
}
virtual void getPutDone(
const Status& status,
ChannelPutGet::shared_pointer const & channelPutGet,
PVStructurePtr const & putPVStructure,
BitSet::shared_pointer const & putBitSet)
{
PvaClientPutGetPtr clientPutGet(pvaClientPutGet.lock());
if(!clientPutGet) return;
clientPutGet->getPutDone(status,channelPutGet,putPVStructure,putBitSet);
}
virtual void getGetDone(
const Status& status,
ChannelPutGet::shared_pointer const & channelPutGet,
PVStructurePtr const & getPVStructure,
BitSet::shared_pointer const & getBitSet)
{
PvaClientPutGetPtr clientPutGet(pvaClientPutGet.lock());
if(!clientPutGet) return;
clientPutGet->getGetDone(status,channelPutGet,getPVStructure,getBitSet);
}
};
PvaClientPutGetPtr PvaClientPutGet::create(
PvaClientPtr const &pvaClient,
Channel::shared_pointer const & channel,
PVStructurePtr const &pvRequest)
{
PvaClientPutGetPtr epv(new PvaClientPutGet(pvaClient,channel,pvRequest));
epv->channelPutGetRequester = ChannelPutGetRequesterImplPtr(
new ChannelPutGetRequesterImpl(epv,pvaClient));
return epv;
}
PvaClientPutGet::PvaClientPutGet(
PvaClientPtr const &pvaClient,
Channel::shared_pointer const & channel,
@@ -40,10 +124,7 @@ PvaClientPutGet::~PvaClientPutGet()
if(PvaClient::getDebug()) cout<< "PvaClientPutGet::~PvaClientPutGet()\n";
{
Lock xx(mutex);
if(isDestroyed) {
cerr<< "Why was PvaClientPutGet::~PvaClientPutGet() called more then once????\n";
return;
}
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
isDestroyed = true;
}
channelPutGet->destroy();
@@ -51,14 +132,12 @@ PvaClientPutGet::~PvaClientPutGet()
void PvaClientPutGet::checkPutGetState()
{
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
if(connectState==connectIdle){
connect();
getPut();
}
}
// from ChannelPutGetRequester
string PvaClientPutGet::getRequesterName()
{
PvaClientPtr yyy = pvaClient.lock();
@@ -68,7 +147,6 @@ string PvaClientPutGet::getRequesterName()
void PvaClientPutGet::message(string const & message,MessageType messageType)
{
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);
@@ -80,7 +158,6 @@ void PvaClientPutGet::channelPutGetConnect(
StructureConstPtr const & putStructure,
StructureConstPtr const & getStructure)
{
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
channelPutGetConnectStatus = status;
this->channelPutGet = channelPutGet;
if(status.isOK()) {
@@ -99,7 +176,6 @@ void PvaClientPutGet::putGetDone(
PVStructurePtr const & getPVStructure,
BitSetPtr const & getChangedBitSet)
{
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
channelPutGetStatus = status;
if(status.isOK()) {
pvaClientGetData->setData(getPVStructure,getChangedBitSet);
@@ -113,7 +189,6 @@ void PvaClientPutGet::getPutDone(
PVStructurePtr const & putPVStructure,
BitSetPtr const & putBitSet)
{
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
channelPutGetStatus = status;
if(status.isOK()) {
PVStructurePtr pvs = pvaClientPutData->getPVStructure();
@@ -131,7 +206,6 @@ void PvaClientPutGet::getGetDone(
PVStructurePtr const & getPVStructure,
BitSetPtr const & getChangedBitSet)
{
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
channelPutGetStatus = status;
if(status.isOK()) {
pvaClientGetData->setData(getPVStructure,getChangedBitSet);
@@ -141,7 +215,6 @@ void PvaClientPutGet::getGetDone(
void PvaClientPutGet::connect()
{
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
issueConnect();
Status status = waitConnect();
if(status.isOK()) return;
@@ -152,20 +225,17 @@ void PvaClientPutGet::connect()
void PvaClientPutGet::issueConnect()
{
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
if(connectState!=connectIdle) {
string message = string("channel ") + channel->getChannelName()
+ " pvaClientPutGet already connected ";
throw std::runtime_error(message);
}
ChannelPutGetRequester::shared_pointer putGetRequester(shared_from_this());
connectState = connectActive;
channelPutGet = channel->createChannelPutGet(putGetRequester,pvRequest);
channelPutGet = channel->createChannelPutGet(channelPutGetRequester,pvRequest);
}
Status PvaClientPutGet::waitConnect()
{
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
if(connectState!=connectActive) {
string message = string("channel ") + channel->getChannelName()
+ " pvaClientPutGet illegal connect state ";
@@ -179,7 +249,6 @@ Status PvaClientPutGet::waitConnect()
void PvaClientPutGet::putGet()
{
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
issuePutGet();
Status status = waitPutGet();
if(status.isOK()) return;
@@ -190,7 +259,6 @@ void PvaClientPutGet::putGet()
void PvaClientPutGet::issuePutGet()
{
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
if(connectState==connectIdle) connect();
if(putGetState!=putGetIdle) {
string message = string("channel ") + channel->getChannelName()
@@ -204,7 +272,6 @@ void PvaClientPutGet::issuePutGet()
Status PvaClientPutGet::waitPutGet()
{
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
if(putGetState!=putGetActive){
string message = string("channel ") + channel->getChannelName()
+ " PvaClientPutGet::waitPutGet llegal put state";
@@ -217,7 +284,6 @@ Status PvaClientPutGet::waitPutGet()
void PvaClientPutGet::getGet()
{
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
issueGetGet();
Status status = waitGetGet();
if(status.isOK()) return;
@@ -228,7 +294,6 @@ void PvaClientPutGet::getGet()
void PvaClientPutGet::issueGetGet()
{
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
if(connectState==connectIdle) connect();
if(putGetState!=putGetIdle) {
string message = string("channel ") + channel->getChannelName()
@@ -241,7 +306,6 @@ void PvaClientPutGet::issueGetGet()
Status PvaClientPutGet::waitGetGet()
{
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
if(putGetState!=putGetActive){
string message = string("channel ") + channel->getChannelName()
+ " PvaClientPutGet::waitGetGet illegal state";
@@ -254,7 +318,6 @@ Status PvaClientPutGet::waitGetGet()
void PvaClientPutGet::getPut()
{
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
issueGetPut();
Status status = waitGetPut();
if(status.isOK()) return;
@@ -265,7 +328,6 @@ void PvaClientPutGet::getPut()
void PvaClientPutGet::issueGetPut()
{
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
if(connectState==connectIdle) connect();
if(putGetState!=putGetIdle) {
string message = string("channel ") + channel->getChannelName()
@@ -278,7 +340,6 @@ void PvaClientPutGet::issueGetPut()
Status PvaClientPutGet::waitGetPut()
{
if(isDestroyed) throw std::runtime_error("pvaClientPutGet was destroyed");
if(putGetState!=putGetActive){
string message = string("channel ") + channel->getChannelName()
+ " PvaClientPutGet::waitGetPut illegal state";
@@ -301,14 +362,4 @@ PvaClientPutDataPtr PvaClientPutGet::getPutData()
return pvaClientPutData;
}
PvaClientPutGetPtr PvaClientPutGet::create(
PvaClientPtr const &pvaClient,
Channel::shared_pointer const & channel,
PVStructurePtr const &pvRequest)
{
PvaClientPutGetPtr epv(new PvaClientPutGet(pvaClient,channel,pvRequest));
return epv;
}
}}