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

@@ -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;
}
}}