more work on EasyGet and conneection management; still work in progress

This commit is contained in:
Marty Kraimer
2015-03-02 15:09:24 -05:00
parent f677e1a091
commit be69a74094
6 changed files with 175 additions and 134 deletions

View File

@@ -143,19 +143,23 @@ EasyChannelImpl::~EasyChannelImpl()
void EasyChannelImpl::channelCreated(const Status& status, Channel::shared_pointer const & channel)
{
if(isDestroyed) throw std::runtime_error("easyChannel was destroyed");
channelConnectStatus = status;
this->channel = channel;
if(status.isOK()) {
this->channel = channel;
return;
}
cout << "EasyChannelImpl::channelCreated status " << status.getMessage() << " why??\n";
}
void EasyChannelImpl::channelStateChange(
Channel::shared_pointer const & channel,
Channel::ConnectionState connectionState)
{
if(isDestroyed) throw std::runtime_error("easyChannel was destroyed");
if(isDestroyed) return;
bool waitingForConnect = false;
if(connectState==connectActive) waitingForConnect = true;
if(connectionState!=Channel::CONNECTED) {
string mess(channelName + " connection state " + Channel::ConnectionStateNames[connectionState]);
string mess(channelName +
" connection state " + Channel::ConnectionStateNames[connectionState]);
message(mess,errorMessage);
channelConnectStatus = Status(Status::STATUSTYPE_ERROR,mess);
connectState = notConnected;
@@ -220,10 +224,14 @@ void EasyChannelImpl::issueConnect()
}
channelRequester = ChannelRequester::shared_pointer(new ChannelRequesterImpl(this));
channelConnectStatus = Status(Status::STATUSTYPE_ERROR,"createChannel failed");
connectState = connectActive;
ChannelProviderRegistry::shared_pointer reg = getChannelProviderRegistry();
ChannelProvider::shared_pointer provider = reg->getProvider(providerName);
channel = provider->createChannel(channelName,channelRequester,ChannelProvider::PRIORITY_DEFAULT);
if(!channel) {
throw std::runtime_error(channelConnectStatus.getMessage());
}
}
Status EasyChannelImpl::waitConnect(double timeout)
@@ -268,7 +276,7 @@ EasyProcessPtr EasyChannelImpl::createProcess(PVStructurePtr const & pvRequest)
EasyGetPtr EasyChannelImpl::createGet()
{
return EasyChannelImpl::createGet("value,alarm.timeStamp");
return EasyChannelImpl::createGet("value,alarm,timeStamp");
}
EasyGetPtr EasyChannelImpl::createGet(string const & request)

View File

@@ -101,6 +101,7 @@ public:
return shared_from_this();
}
private:
void checkGetState();
enum GetConnectState {connectIdle,connectActive,connected};
EasyPVAPtr easyPVA;
@@ -176,6 +177,12 @@ EasyGetImpl::~EasyGetImpl()
destroy();
}
void EasyGetImpl::checkGetState()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
if(connectState==connectIdle) connect();
if(getState==getIdle) get();
}
// from ChannelGetRequester
string EasyGetImpl::getRequesterName()
@@ -257,7 +264,6 @@ void EasyGetImpl::issueConnect()
throw std::runtime_error(ss.str());
}
getRequester = ChannelGetRequester::shared_pointer(new ChannelGetRequesterImpl(this));
connectState = connectActive;
channelGet = channel->createChannelGet(getRequester,pvRequest);
}
@@ -335,206 +341,206 @@ void EasyGetImpl::setPVStructure(epics::pvData::PVStructurePtr const & pvStructu
Alarm EasyGetImpl::getAlarm()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getAlarm();
}
TimeStamp EasyGetImpl::getTimeStamp()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getTimeStamp();
}
bool EasyGetImpl::hasValue()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->hasValue();
}
bool EasyGetImpl::isValueScalar()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->isValueScalar();
}
bool EasyGetImpl::isValueScalarArray()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->isValueScalarArray();
}
PVFieldPtr EasyGetImpl::getValue()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getValue();
}
PVScalarPtr EasyGetImpl::getScalarValue()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getScalarValue();
}
std::tr1::shared_ptr<PVArray> EasyGetImpl::getArrayValue()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getArrayValue();
}
std::tr1::shared_ptr<PVScalarArray> EasyGetImpl::getScalarArrayValue()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getScalarArrayValue();
}
bool EasyGetImpl::getBoolean()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getBoolean();
}
int8 EasyGetImpl::getByte()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getByte();
}
int16 EasyGetImpl::getShort()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getShort();
}
int32 EasyGetImpl::getInt()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getInt();
}
int64 EasyGetImpl::getLong()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getLong();
}
uint8 EasyGetImpl::getUByte()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getUByte();
}
uint16 EasyGetImpl::getUShort()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getUShort();
}
uint32 EasyGetImpl::getUInt()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getUInt();
}
uint64 EasyGetImpl::getULong()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getULong();
}
float EasyGetImpl::getFloat()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getFloat();
}
double EasyGetImpl::getDouble()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
return easyPVStructure->isValueScalar();
checkGetState();
return easyPVStructure->getDouble();
}
std::string EasyGetImpl::getString()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getString();
}
shared_vector<boolean> EasyGetImpl::getBooleanArray()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getBooleanArray();
}
shared_vector<int8> EasyGetImpl::getByteArray()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getByteArray();
}
shared_vector<int16> EasyGetImpl::getShortArray()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getShortArray();
}
shared_vector<int32> EasyGetImpl::getIntArray()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getIntArray();
}
shared_vector<int64> EasyGetImpl::getLongArray()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getLongArray();
}
shared_vector<uint8> EasyGetImpl::getUByteArray()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getUByteArray();
}
shared_vector<uint16> EasyGetImpl::getUShortArray()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getUShortArray();
}
shared_vector<uint32> EasyGetImpl::getUIntArray()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getUIntArray();
}
shared_vector<uint64> EasyGetImpl::getULongArray()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getULongArray();
}
shared_vector<float> EasyGetImpl::getFloatArray()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getFloatArray();
}
shared_vector<double> EasyGetImpl::getDoubleArray()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getDoubleArray();
}
shared_vector<std::string> EasyGetImpl::getStringArray()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getStringArray();
}
PVStructurePtr EasyGetImpl::getPVStructure()
{
if(isDestroyed) throw std::runtime_error("easyGet was destroyed");
checkGetState();
return easyPVStructure->getPVStructure();
}

View File

@@ -11,6 +11,7 @@
#define epicsExportSharedSymbols
#include <pv/easyPVA.h>
#include <pv/createRequest.h>
#include <pv/clientFactory.h>
using std::tr1::static_pointer_cast;
using namespace epics::pvData;
@@ -24,9 +25,46 @@ 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();
}
static void EasyPVABeingDestroyed() {
size_t numLeft = 0;
{
Lock xx(mutex);
--numberEasyPVA;
numLeft = numberEasyPVA;
}
if(numLeft<=0) ClientFactory::stop();
}
};
}
using namespace epics::easyPVA::easyPVAPvt;
EasyPVAPtr EasyPVA::create()
{
EasyPVAPtr xx(new EasyPVA());
StartStopClientFactory::EasyPVABeingConstructed();
return xx;
}
@@ -45,7 +83,9 @@ EasyPVA::EasyPVA()
{
}
EasyPVA::~EasyPVA() {destroy();}
EasyPVA::~EasyPVA() {
destroy();
}
void EasyPVA::destroy()
{
@@ -61,8 +101,8 @@ void EasyPVA::destroy()
channelList.erase(channelIter);
(*channelIter)->destroy();
}
std::list<EasyMultiChannelPtr>::iterator multiChannelIter;
#ifdef NOTDONE
std::list<EasyMultiChannelPtr>::iterator multiChannelIter;
while(true) {
multiChannelIter = multiChannelList.begin();
if(multiChannelIter==multiChannelList.end()) break;
@@ -70,7 +110,7 @@ void EasyPVA::destroy()
(*multiChannelIter)->destroy();
}
#endif
StartStopClientFactory::EasyPVABeingDestroyed();
}
string EasyPVA:: getRequesterName()