remove destroy except PVRecord, which has new semantics
This commit is contained in:
+12
-178
@@ -103,7 +103,7 @@ public:
|
||||
PVStructurePtr const & pvRequest,
|
||||
PVRecordPtr const &pvRecord);
|
||||
virtual void process();
|
||||
virtual void destroy();
|
||||
virtual void destroy() EPICS_DEPRECATED {};
|
||||
virtual std::tr1::shared_ptr<Channel> getChannel()
|
||||
{return channelLocal;}
|
||||
virtual void cancel(){}
|
||||
@@ -121,14 +121,12 @@ private:
|
||||
PVRecordPtr const &pvRecord,
|
||||
int nProcess)
|
||||
:
|
||||
isDestroyed(false),
|
||||
channelLocal(channelLocal),
|
||||
channelProcessRequester(channelProcessRequester),
|
||||
pvRecord(pvRecord),
|
||||
nProcess(nProcess)
|
||||
{
|
||||
}
|
||||
bool isDestroyed;
|
||||
ChannelLocalPtr channelLocal;
|
||||
ChannelProcessRequester::weak_pointer channelProcessRequester;
|
||||
PVRecordPtr pvRecord;
|
||||
@@ -174,30 +172,10 @@ ChannelProcessLocalPtr ChannelProcessLocal::create(
|
||||
return process;
|
||||
}
|
||||
|
||||
|
||||
void ChannelProcessLocal::destroy()
|
||||
{
|
||||
if(pvRecord->getTraceLevel()>0)
|
||||
{
|
||||
cout << "ChannelProcessLocal::destroy";
|
||||
cout << " destroyed " << isDestroyed << endl;
|
||||
}
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) return;
|
||||
isDestroyed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ChannelProcessLocal::process()
|
||||
{
|
||||
ChannelProcessRequester::shared_pointer requester = channelProcessRequester.lock();
|
||||
if(!requester) return;
|
||||
if(isDestroyed) {
|
||||
requester->processDone(channelDestroyedStatus,getPtrSelf());
|
||||
return;
|
||||
}
|
||||
if(pvRecord->getTraceLevel()>1)
|
||||
{
|
||||
cout << "ChannelProcessLocal::process";
|
||||
@@ -236,7 +214,7 @@ public:
|
||||
PVStructurePtr const & pvRequest,
|
||||
PVRecordPtr const &pvRecord);
|
||||
virtual void get();
|
||||
virtual void destroy();
|
||||
virtual void destroy() EPICS_DEPRECATED {};
|
||||
virtual std::tr1::shared_ptr<Channel> getChannel()
|
||||
{return channelLocal;}
|
||||
virtual void cancel(){}
|
||||
@@ -258,7 +236,6 @@ private:
|
||||
PVRecordPtr const &pvRecord)
|
||||
:
|
||||
firstTime(true),
|
||||
isDestroyed(false),
|
||||
callProcess(callProcess),
|
||||
channelLocal(channelLocal),
|
||||
channelGetRequester(channelGetRequester),
|
||||
@@ -269,7 +246,6 @@ private:
|
||||
{
|
||||
}
|
||||
bool firstTime;
|
||||
bool isDestroyed;
|
||||
bool callProcess;
|
||||
ChannelLocalPtr channelLocal;
|
||||
ChannelGetRequester::weak_pointer channelGetRequester;
|
||||
@@ -323,29 +299,10 @@ ChannelGetLocalPtr ChannelGetLocal::create(
|
||||
}
|
||||
|
||||
|
||||
void ChannelGetLocal::destroy()
|
||||
{
|
||||
if(pvRecord->getTraceLevel()>0)
|
||||
{
|
||||
cout << "ChannelGetLocal::destroy";
|
||||
cout << " destroyed " << isDestroyed << endl;
|
||||
}
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) return;
|
||||
isDestroyed = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelGetLocal::get()
|
||||
{
|
||||
ChannelGetRequester::shared_pointer requester = channelGetRequester.lock();
|
||||
if(!requester) return;
|
||||
if(isDestroyed) {
|
||||
requester->getDone(
|
||||
channelDestroyedStatus,getPtrSelf(),nullPVStructure,nullBitSet);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
bitSet->clear();
|
||||
{
|
||||
@@ -398,7 +355,7 @@ public:
|
||||
PVRecordPtr const &pvRecord);
|
||||
virtual void put(PVStructurePtr const &pvStructure,BitSetPtr const &bitSet);
|
||||
virtual void get();
|
||||
virtual void destroy();
|
||||
virtual void destroy() EPICS_DEPRECATED {};
|
||||
virtual std::tr1::shared_ptr<Channel> getChannel()
|
||||
{return channelLocal;}
|
||||
virtual void cancel(){}
|
||||
@@ -417,7 +374,6 @@ private:
|
||||
PVCopyPtr const &pvCopy,
|
||||
PVRecordPtr const &pvRecord)
|
||||
:
|
||||
isDestroyed(false),
|
||||
callProcess(callProcess),
|
||||
channelLocal(channelLocal),
|
||||
channelPutRequester(channelPutRequester),
|
||||
@@ -425,7 +381,6 @@ private:
|
||||
pvRecord(pvRecord)
|
||||
{
|
||||
}
|
||||
bool isDestroyed;
|
||||
bool callProcess;
|
||||
ChannelLocalPtr channelLocal;
|
||||
ChannelPutRequester::weak_pointer channelPutRequester;
|
||||
@@ -474,29 +429,10 @@ ChannelPutLocalPtr ChannelPutLocal::create(
|
||||
return put;
|
||||
}
|
||||
|
||||
void ChannelPutLocal::destroy()
|
||||
{
|
||||
if(pvRecord->getTraceLevel()>0)
|
||||
{
|
||||
cout << "ChannelPutLocal::destroy";
|
||||
cout << " destroyed " << isDestroyed << endl;
|
||||
}
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) return;
|
||||
isDestroyed = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelPutLocal::get()
|
||||
{
|
||||
ChannelPutRequester::shared_pointer requester = channelPutRequester.lock();
|
||||
if(!requester) return;
|
||||
if(isDestroyed) {
|
||||
requester->getDone(
|
||||
channelDestroyedStatus,getPtrSelf(),nullPVStructure,nullBitSet);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
PVStructurePtr pvStructure = pvCopy->createPVStructure();
|
||||
BitSetPtr bitSet(new BitSet(pvStructure->getNumberFields()));
|
||||
@@ -525,10 +461,6 @@ void ChannelPutLocal::put(
|
||||
{
|
||||
ChannelPutRequester::shared_pointer requester = channelPutRequester.lock();
|
||||
if(!requester) return;
|
||||
if(isDestroyed) {
|
||||
requester->putDone(channelDestroyedStatus,getPtrSelf());
|
||||
return;
|
||||
}
|
||||
try {
|
||||
{
|
||||
epicsGuard <PVRecord> guard(*pvRecord);
|
||||
@@ -574,7 +506,7 @@ public:
|
||||
BitSetPtr const &putBitSet);
|
||||
virtual void getPut();
|
||||
virtual void getGet();
|
||||
virtual void destroy();
|
||||
virtual void destroy() EPICS_DEPRECATED {};
|
||||
virtual std::tr1::shared_ptr<Channel> getChannel()
|
||||
{return channelLocal;}
|
||||
virtual void cancel(){}
|
||||
@@ -596,7 +528,6 @@ private:
|
||||
BitSetPtr const & getBitSet,
|
||||
PVRecordPtr const &pvRecord)
|
||||
:
|
||||
isDestroyed(false),
|
||||
callProcess(callProcess),
|
||||
channelLocal(channelLocal),
|
||||
channelPutGetRequester(channelPutGetRequester),
|
||||
@@ -607,7 +538,6 @@ private:
|
||||
pvRecord(pvRecord)
|
||||
{
|
||||
}
|
||||
bool isDestroyed;
|
||||
bool callProcess;
|
||||
ChannelLocalPtr channelLocal;
|
||||
ChannelPutGetRequester::weak_pointer channelPutGetRequester;
|
||||
@@ -668,30 +598,11 @@ ChannelPutGetLocalPtr ChannelPutGetLocal::create(
|
||||
}
|
||||
|
||||
|
||||
void ChannelPutGetLocal::destroy()
|
||||
{
|
||||
if(pvRecord->getTraceLevel()>0)
|
||||
{
|
||||
cout << "ChannelPutGetLocal::destroy";
|
||||
cout << " destroyed " << isDestroyed << endl;
|
||||
}
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) return;
|
||||
isDestroyed = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelPutGetLocal::putGet(
|
||||
PVStructurePtr const &pvPutStructure,BitSetPtr const &putBitSet)
|
||||
{
|
||||
ChannelPutGetRequester::shared_pointer requester = channelPutGetRequester.lock();
|
||||
if(!requester) return;
|
||||
if(isDestroyed) {
|
||||
requester->putGetDone(
|
||||
channelDestroyedStatus,getPtrSelf(),nullPVStructure,nullBitSet);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
{
|
||||
epicsGuard <PVRecord> guard(*pvRecord);
|
||||
@@ -718,11 +629,6 @@ void ChannelPutGetLocal::getPut()
|
||||
{
|
||||
ChannelPutGetRequester::shared_pointer requester = channelPutGetRequester.lock();
|
||||
if(!requester) return;
|
||||
if(isDestroyed) {
|
||||
requester->getPutDone(
|
||||
channelDestroyedStatus,getPtrSelf(),nullPVStructure,nullBitSet);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
PVStructurePtr pvPutStructure = pvPutCopy->createPVStructure();
|
||||
BitSetPtr putBitSet(new BitSet(pvPutStructure->getNumberFields()));
|
||||
@@ -748,11 +654,6 @@ void ChannelPutGetLocal::getGet()
|
||||
{
|
||||
ChannelPutGetRequester::shared_pointer requester = channelPutGetRequester.lock();
|
||||
if(!requester) return;
|
||||
if(isDestroyed) {
|
||||
requester->getGetDone(
|
||||
channelDestroyedStatus,getPtrSelf(),nullPVStructure,nullBitSet);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
getBitSet->clear();
|
||||
{
|
||||
@@ -792,7 +693,6 @@ public:
|
||||
ChannelRPCRequester::shared_pointer const & channelRPCRequester,
|
||||
Service::shared_pointer const & service,
|
||||
PVRecordPtr const & pvRecord) :
|
||||
isDestroyed(),
|
||||
channelLocal(channelLocal),
|
||||
channelRPCRequester(channelRPCRequester),
|
||||
service(service),
|
||||
@@ -807,7 +707,6 @@ public:
|
||||
{
|
||||
cout << "~ChannelRPCLocal()" << endl;
|
||||
}
|
||||
destroy();
|
||||
}
|
||||
|
||||
void processRequest(RPCService::shared_pointer const & service,
|
||||
@@ -819,9 +718,6 @@ public:
|
||||
ChannelRPCRequester::shared_pointer requester = channelRPCRequester.lock();
|
||||
if(!requester) return;
|
||||
requester->requestDone(status, getPtrSelf(), result);
|
||||
|
||||
if (isLastRequest.get())
|
||||
destroy();
|
||||
}
|
||||
|
||||
void processRequest(RPCServiceAsync::shared_pointer const & service,
|
||||
@@ -841,7 +737,7 @@ public:
|
||||
|
||||
virtual void cancel() {}
|
||||
|
||||
virtual void destroy();
|
||||
virtual void destroy() EPICS_DEPRECATED {};
|
||||
|
||||
virtual void lock() {}
|
||||
|
||||
@@ -854,7 +750,6 @@ private:
|
||||
return shared_from_this();
|
||||
}
|
||||
|
||||
AtomicBoolean isDestroyed;
|
||||
ChannelLocalPtr channelLocal;
|
||||
ChannelRPCRequester::weak_pointer channelRPCRequester;
|
||||
Service::shared_pointer service;
|
||||
@@ -990,17 +885,6 @@ void ChannelRPCLocal::request(PVStructurePtr const & pvArgument)
|
||||
}
|
||||
|
||||
|
||||
void ChannelRPCLocal::destroy()
|
||||
{
|
||||
if(pvRecord->getTraceLevel()>0)
|
||||
{
|
||||
cout << "ChannelRPCLocal::destroy";
|
||||
cout << " destroyed " << isDestroyed.get() << endl;
|
||||
}
|
||||
isDestroyed.set();
|
||||
}
|
||||
|
||||
|
||||
typedef std::tr1::shared_ptr<PVArray> PVArrayPtr;
|
||||
|
||||
class ChannelArrayLocal :
|
||||
@@ -1027,7 +911,7 @@ public:
|
||||
size_t offset, size_t count, size_t stride);
|
||||
virtual void getLength();
|
||||
virtual void setLength(size_t length);
|
||||
virtual void destroy();
|
||||
virtual void destroy() EPICS_DEPRECATED {};
|
||||
virtual std::tr1::shared_ptr<Channel> getChannel()
|
||||
{return channelLocal;}
|
||||
virtual void cancel(){}
|
||||
@@ -1046,7 +930,6 @@ private:
|
||||
PVArrayPtr const &pvCopy,
|
||||
PVRecordPtr const &pvRecord)
|
||||
:
|
||||
isDestroyed(false),
|
||||
channelLocal(channelLocal),
|
||||
channelArrayRequester(channelArrayRequester),
|
||||
pvArray(pvArray),
|
||||
@@ -1054,7 +937,7 @@ private:
|
||||
pvRecord(pvRecord)
|
||||
{
|
||||
}
|
||||
bool isDestroyed;
|
||||
|
||||
ChannelLocalPtr channelLocal;
|
||||
ChannelArrayRequester::weak_pointer channelArrayRequester;
|
||||
PVArrayPtr pvArray;
|
||||
@@ -1147,29 +1030,11 @@ ChannelArrayLocalPtr ChannelArrayLocal::create(
|
||||
return array;
|
||||
}
|
||||
|
||||
|
||||
void ChannelArrayLocal::destroy()
|
||||
{
|
||||
if(pvRecord->getTraceLevel()>0)
|
||||
{
|
||||
cout << "ChannelArrayLocal::destroy";
|
||||
cout << " destroyed " << isDestroyed << endl;
|
||||
}
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) return;
|
||||
isDestroyed = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelArrayLocal::getArray(size_t offset, size_t count, size_t stride)
|
||||
{
|
||||
ChannelArrayRequester::shared_pointer requester = channelArrayRequester.lock();
|
||||
if(!requester) return;
|
||||
if(isDestroyed) {
|
||||
requester->getArrayDone(channelDestroyedStatus,getPtrSelf(),pvCopy);
|
||||
return;
|
||||
}
|
||||
|
||||
if(pvRecord->getTraceLevel()>1)
|
||||
{
|
||||
cout << "ChannelArrayLocal::getArray" << endl;
|
||||
@@ -1218,10 +1083,7 @@ void ChannelArrayLocal::putArray(
|
||||
{
|
||||
ChannelArrayRequester::shared_pointer requester = channelArrayRequester.lock();
|
||||
if(!requester) return;
|
||||
if(isDestroyed) {
|
||||
requester->putArrayDone(channelDestroyedStatus,getPtrSelf());
|
||||
return;
|
||||
}
|
||||
|
||||
if(pvRecord->getTraceLevel()>1)
|
||||
{
|
||||
cout << "ChannelArrayLocal::putArray" << endl;
|
||||
@@ -1277,10 +1139,7 @@ void ChannelArrayLocal::setLength(size_t length)
|
||||
{
|
||||
ChannelArrayRequester::shared_pointer requester = channelArrayRequester.lock();
|
||||
if(!requester) return;
|
||||
if(isDestroyed) {
|
||||
requester->setLengthDone(channelDestroyedStatus,getPtrSelf());
|
||||
return;
|
||||
}
|
||||
|
||||
if(pvRecord->getTraceLevel()>1)
|
||||
{
|
||||
cout << "ChannelArrayLocal::setLength" << endl;
|
||||
@@ -1308,8 +1167,7 @@ ChannelLocal::ChannelLocal(
|
||||
:
|
||||
requester(requester),
|
||||
provider(provider),
|
||||
pvRecord(pvRecord),
|
||||
isDestroyed(false)
|
||||
pvRecord(pvRecord)
|
||||
{
|
||||
if(pvRecord->getTraceLevel()>0) {
|
||||
cout << "ChannelLocal::ChannelLocal()"
|
||||
@@ -1325,26 +1183,10 @@ ChannelLocal::~ChannelLocal()
|
||||
{
|
||||
cout << "~ChannelLocal()" << endl;
|
||||
}
|
||||
destroy();
|
||||
}
|
||||
|
||||
void ChannelLocal::destroy()
|
||||
{
|
||||
if(pvRecord->getTraceLevel()>0) {
|
||||
cout << "ChannelLocal::destroy()"
|
||||
<< " recordName " << pvRecord->getRecordName()
|
||||
<< " isDestroyed " << isDestroyed
|
||||
<< " requester exists " << (requester ? "true" : "false")
|
||||
<< endl;
|
||||
}
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) return;
|
||||
isDestroyed = true;
|
||||
}
|
||||
pvRecord->removePVRecordClient(getPtrSelf());
|
||||
}
|
||||
|
||||
|
||||
void ChannelLocal::detach(PVRecordPtr const & pvRecord)
|
||||
{
|
||||
if(pvRecord->getTraceLevel()>0) {
|
||||
@@ -1381,10 +1223,6 @@ void ChannelLocal::message(
|
||||
<< " requester exists " << (requester ? "true" : "false")
|
||||
<< endl;
|
||||
}
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) return;
|
||||
}
|
||||
if(requester) {
|
||||
requester->message(message,messageType);
|
||||
return;
|
||||
@@ -1402,8 +1240,6 @@ string ChannelLocal::getRemoteAddress()
|
||||
|
||||
Channel::ConnectionState ChannelLocal::getConnectionState()
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) return Channel::DESTROYED;
|
||||
return Channel::CONNECTED;
|
||||
}
|
||||
|
||||
@@ -1419,8 +1255,6 @@ ChannelRequester::shared_pointer ChannelLocal::getChannelRequester()
|
||||
|
||||
bool ChannelLocal::isConnected()
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
* @date 2013.04
|
||||
*/
|
||||
|
||||
#include <epicsThread.h>
|
||||
|
||||
|
||||
#include <pv/serverContext.h>
|
||||
#include <pv/syncChannelFind.h>
|
||||
|
||||
@@ -28,79 +31,66 @@ using std::string;
|
||||
namespace epics { namespace pvDatabase {
|
||||
|
||||
static string providerName("local");
|
||||
|
||||
static ChannelProvider::shared_pointer channelProvider;
|
||||
|
||||
class LocalChannelProviderFactory;
|
||||
typedef std::tr1::shared_ptr<LocalChannelProviderFactory> LocalChannelProviderFactoryPtr;
|
||||
|
||||
class LocalChannelProviderFactory : public ChannelProviderFactory
|
||||
{
|
||||
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(LocalChannelProviderFactory);
|
||||
virtual string getFactoryName() { return providerName;}
|
||||
static LocalChannelProviderFactoryPtr create(
|
||||
ChannelProviderLocalPtr const &channelProvider)
|
||||
{
|
||||
LocalChannelProviderFactoryPtr xxx(
|
||||
new LocalChannelProviderFactory(channelProvider));
|
||||
ChannelProviderRegistry::servers()->add(xxx);
|
||||
return xxx;
|
||||
}
|
||||
virtual ChannelProvider::shared_pointer sharedInstance()
|
||||
{
|
||||
if(!channelProvider) channelProvider = ChannelProvider::shared_pointer(new ChannelProviderLocal());
|
||||
return channelProvider;
|
||||
}
|
||||
virtual ChannelProvider::shared_pointer newInstance()
|
||||
{
|
||||
cout << "LocalChannelProviderFactory::newInstance()\n";
|
||||
throw std::logic_error("newInstance not Implemented");
|
||||
}
|
||||
private:
|
||||
LocalChannelProviderFactory(
|
||||
ChannelProviderLocalPtr const &channelProvider)
|
||||
: channelProvider(channelProvider)
|
||||
{}
|
||||
ChannelProviderLocalPtr channelProvider;
|
||||
};
|
||||
|
||||
|
||||
ChannelProviderLocalPtr getChannelProviderLocal()
|
||||
{
|
||||
static ChannelProviderLocalPtr channelProviderLocal;
|
||||
static Mutex mutex;
|
||||
Lock xx(mutex);
|
||||
if(!channelProviderLocal) {
|
||||
channelProviderLocal = ChannelProviderLocalPtr(
|
||||
new ChannelProviderLocal());
|
||||
ChannelProvider::shared_pointer xxx =
|
||||
dynamic_pointer_cast<ChannelProvider>(channelProviderLocal);
|
||||
channelProviderLocal->channelFinder =
|
||||
SyncChannelFind::shared_pointer(new SyncChannelFind(xxx));
|
||||
LocalChannelProviderFactoryPtr factory(LocalChannelProviderFactory::create(channelProviderLocal));
|
||||
|
||||
static int firstTime = 1;
|
||||
if (firstTime) {
|
||||
firstTime = 0;
|
||||
ChannelProviderFactory::shared_pointer factory(
|
||||
new LocalChannelProviderFactory());
|
||||
ChannelProviderRegistry::servers()->add(factory);
|
||||
}
|
||||
return channelProviderLocal;
|
||||
ChannelProvider::shared_pointer channelProvider =
|
||||
ChannelProviderRegistry::servers()->getProvider(providerName);
|
||||
return std::tr1::dynamic_pointer_cast<ChannelProviderLocal>(channelProvider);
|
||||
}
|
||||
|
||||
ChannelProviderLocal::ChannelProviderLocal()
|
||||
: pvDatabase(PVDatabase::getMaster()),
|
||||
beingDestroyed(false)
|
||||
traceLevel(0)
|
||||
{
|
||||
}
|
||||
|
||||
ChannelProviderLocal::~ChannelProviderLocal()
|
||||
{
|
||||
destroy();
|
||||
if(traceLevel>0) {
|
||||
cout << "ChannelProviderLocal::~ChannelProviderLocal() \n";
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelProviderLocal::destroy()
|
||||
std::tr1::shared_ptr<ChannelProvider> ChannelProviderLocal::getChannelProvider()
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(beingDestroyed) return;
|
||||
beingDestroyed = true;
|
||||
pvDatabase->destroy();
|
||||
pvDatabase.reset();
|
||||
return shared_from_this();
|
||||
}
|
||||
|
||||
void ChannelProviderLocal::cancel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
string ChannelProviderLocal::getProviderName()
|
||||
{
|
||||
return providerName;
|
||||
@@ -110,35 +100,41 @@ ChannelFind::shared_pointer ChannelProviderLocal::channelFind(
|
||||
string const & channelName,
|
||||
ChannelFindRequester::shared_pointer const &channelFindRequester)
|
||||
{
|
||||
if(traceLevel>1) {
|
||||
cout << "ChannelProviderLocal::channelFind " << "channelName" << endl;
|
||||
}
|
||||
Lock xx(mutex);
|
||||
PVRecordPtr pvRecord = pvDatabase->findRecord(channelName);
|
||||
if(pvRecord) {
|
||||
channelFindRequester->channelFindResult(
|
||||
Status::Ok,
|
||||
channelFinder,
|
||||
shared_from_this(),
|
||||
true);
|
||||
|
||||
} else {
|
||||
Status notFoundStatus(Status::STATUSTYPE_ERROR,"pv not found");
|
||||
channelFindRequester->channelFindResult(
|
||||
notFoundStatus,
|
||||
channelFinder,
|
||||
shared_from_this(),
|
||||
false);
|
||||
}
|
||||
return channelFinder;
|
||||
return shared_from_this();
|
||||
}
|
||||
|
||||
ChannelFind::shared_pointer ChannelProviderLocal::channelList(
|
||||
ChannelListRequester::shared_pointer const & channelListRequester)
|
||||
{
|
||||
if(traceLevel>1) {
|
||||
cout << "ChannelProviderLocal::channelList\n";
|
||||
}
|
||||
PVStringArrayPtr records;
|
||||
{
|
||||
Lock guard(mutex);
|
||||
records = pvDatabase->getRecordNames();
|
||||
}
|
||||
|
||||
channelListRequester->channelListResult(Status::Ok, channelFinder, records->view(), false);
|
||||
return channelFinder;
|
||||
channelListRequester->channelListResult(Status::Ok, shared_from_this(), records->view(), false);
|
||||
return shared_from_this();
|
||||
}
|
||||
|
||||
Channel::shared_pointer ChannelProviderLocal::createChannel(
|
||||
@@ -146,11 +142,14 @@ Channel::shared_pointer ChannelProviderLocal::createChannel(
|
||||
ChannelRequester::shared_pointer const &channelRequester,
|
||||
short priority)
|
||||
{
|
||||
if(traceLevel>1) {
|
||||
cout << "ChannelProviderLocal::createChannel " << "channelName" << endl;
|
||||
}
|
||||
Lock xx(mutex);
|
||||
PVRecordPtr pvRecord = pvDatabase->findRecord(channelName);
|
||||
if(pvRecord) {
|
||||
ChannelLocalPtr channel(new ChannelLocal(
|
||||
getPtrSelf(),channelRequester,pvRecord));
|
||||
shared_from_this(),channelRequester,pvRecord));
|
||||
channelRequester->channelCreated(
|
||||
Status::Ok,
|
||||
channel);
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <epicsGuard.h>
|
||||
#include <pv/thread.h>
|
||||
#include <pv/bitSetUtil.h>
|
||||
#include <pv/queue.h>
|
||||
#include <pv/timeStamp.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
@@ -34,16 +33,93 @@ namespace epics { namespace pvDatabase {
|
||||
static MonitorPtr nullMonitor;
|
||||
static MonitorElementPtr NULLMonitorElement;
|
||||
static Status failedToCreateMonitorStatus(Status::STATUSTYPE_ERROR,"failed to create monitor");
|
||||
static Status wasDestroyedStatus(Status::STATUSTYPE_ERROR,"was destroyed");
|
||||
static Status alreadyStartedStatus(Status::STATUSTYPE_ERROR,"already started");
|
||||
static Status notStartedStatus(Status::STATUSTYPE_ERROR,"not started");
|
||||
static Status destroyedStatus(Status::STATUSTYPE_ERROR,"record is destroyed");
|
||||
|
||||
|
||||
|
||||
typedef Queue<MonitorElement> MonitorElementQueue;
|
||||
class MonitorElementQueue;
|
||||
typedef std::tr1::shared_ptr<MonitorElementQueue> MonitorElementQueuePtr;
|
||||
typedef std::tr1::shared_ptr<MonitorRequester> MonitorRequesterPtr;
|
||||
|
||||
class MonitorElementQueue
|
||||
{
|
||||
private:
|
||||
MonitorElementPtrArray elements;
|
||||
// TODO use size_t instead
|
||||
int size;
|
||||
int numberFree;
|
||||
int numberUsed;
|
||||
int nextGetFree;
|
||||
int nextSetUsed;
|
||||
int nextGetUsed;
|
||||
int nextReleaseUsed;
|
||||
public:
|
||||
POINTER_DEFINITIONS(MonitorElementQueue);
|
||||
|
||||
MonitorElementQueue(std::vector<MonitorElementPtr> monitorElementArray)
|
||||
: elements(monitorElementArray),
|
||||
size(monitorElementArray.size()),
|
||||
numberFree(size),
|
||||
numberUsed(0),
|
||||
nextGetFree(0),
|
||||
nextSetUsed(0),
|
||||
nextGetUsed(0),
|
||||
nextReleaseUsed(0)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~MonitorElementQueue() {}
|
||||
|
||||
void clear()
|
||||
{
|
||||
numberFree = size;
|
||||
numberUsed = 0;
|
||||
nextGetFree = 0;
|
||||
nextSetUsed = 0;
|
||||
nextGetUsed = 0;
|
||||
nextReleaseUsed = 0;
|
||||
}
|
||||
|
||||
MonitorElementPtr getFree()
|
||||
{
|
||||
if(numberFree==0) return MonitorElementPtr();
|
||||
numberFree--;
|
||||
int ind = nextGetFree;
|
||||
MonitorElementPtr queueElement = elements[nextGetFree++];
|
||||
if(nextGetFree>=size) nextGetFree = 0;
|
||||
return elements[ind];
|
||||
}
|
||||
|
||||
void setUsed(MonitorElementPtr const &element)
|
||||
{
|
||||
if(element!=elements[nextSetUsed++]) {
|
||||
throw std::logic_error("not correct queueElement");
|
||||
}
|
||||
numberUsed++;
|
||||
if(nextSetUsed>=size) nextSetUsed = 0;
|
||||
}
|
||||
|
||||
MonitorElementPtr getUsed()
|
||||
{
|
||||
if(numberUsed==0) return MonitorElementPtr();
|
||||
int ind = nextGetUsed;
|
||||
MonitorElementPtr queueElement = elements[nextGetUsed++];
|
||||
if(nextGetUsed>=size) nextGetUsed = 0;
|
||||
return elements[ind];
|
||||
}
|
||||
void releaseUsed(MonitorElementPtr const &element)
|
||||
{
|
||||
if(element!=elements[nextReleaseUsed++]) {
|
||||
throw std::logic_error(
|
||||
"not queueElement returned by last call to getUsed");
|
||||
}
|
||||
if(nextReleaseUsed>=size) nextReleaseUsed = 0;
|
||||
numberUsed--;
|
||||
numberFree++;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
typedef std::tr1::shared_ptr<MonitorRequester> MonitorRequesterPtr;
|
||||
|
||||
|
||||
class MonitorLocal :
|
||||
@@ -51,15 +127,15 @@ class MonitorLocal :
|
||||
public PVListener,
|
||||
public std::tr1::enable_shared_from_this<MonitorLocal>
|
||||
{
|
||||
enum MonitorState {idle,active, destroyed};
|
||||
enum MonitorState {idle,active,destroyed};
|
||||
public:
|
||||
POINTER_DEFINITIONS(MonitorLocal);
|
||||
virtual ~MonitorLocal();
|
||||
virtual Status start();
|
||||
virtual Status stop();
|
||||
virtual MonitorElementPtr poll();
|
||||
virtual void destroy();
|
||||
virtual void detach(PVRecordPtr const & pvRecord){destroy();}
|
||||
virtual void destroy() EPICS_DEPRECATED {};
|
||||
virtual void detach(PVRecordPtr const & pvRecord){}
|
||||
virtual void release(MonitorElementPtr const & monitorElement);
|
||||
virtual void dataPut(PVRecordFieldPtr const & pvRecordField);
|
||||
virtual void dataPut(
|
||||
@@ -109,25 +185,8 @@ MonitorLocal::~MonitorLocal()
|
||||
{
|
||||
cout << "MonitorLocal::~MonitorLocal()" << endl;
|
||||
}
|
||||
destroy();
|
||||
}
|
||||
|
||||
void MonitorLocal::destroy()
|
||||
{
|
||||
if(pvRecord->getTraceLevel()>0)
|
||||
{
|
||||
cout << "MonitorLocal::destroy state " << state << endl;
|
||||
}
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(state==destroyed) return;
|
||||
}
|
||||
if(state==active) stop();
|
||||
{
|
||||
Lock xx(mutex);
|
||||
state = destroyed;
|
||||
}
|
||||
}
|
||||
|
||||
Status MonitorLocal::start()
|
||||
{
|
||||
@@ -137,8 +196,8 @@ Status MonitorLocal::start()
|
||||
}
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(state==destroyed) return wasDestroyedStatus;
|
||||
if(state==active) return alreadyStartedStatus;
|
||||
if(state==destroyed) return destroyedStatus;
|
||||
}
|
||||
pvRecord->addListener(getPtrSelf(),pvCopy);
|
||||
epicsGuard <PVRecord> guard(*pvRecord);
|
||||
@@ -161,10 +220,10 @@ Status MonitorLocal::stop()
|
||||
}
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(state==destroyed) return wasDestroyedStatus;
|
||||
if(state==idle) return notStartedStatus;
|
||||
if(state==destroyed) return destroyedStatus;
|
||||
state = idle;
|
||||
}
|
||||
}
|
||||
pvRecord->removeListener(getPtrSelf(),pvCopy);
|
||||
return Status::Ok;
|
||||
}
|
||||
@@ -310,6 +369,10 @@ void MonitorLocal::unlisten(PVRecordPtr const & pvRecord)
|
||||
{
|
||||
cout << "PVCopyMonitor::unlisten\n";
|
||||
}
|
||||
{
|
||||
Lock xx(mutex);
|
||||
state = destroyed;
|
||||
}
|
||||
MonitorRequesterPtr requester = monitorRequester.lock();
|
||||
if(requester) {
|
||||
if(pvRecord->getTraceLevel()>1)
|
||||
@@ -318,7 +381,6 @@ void MonitorLocal::unlisten(PVRecordPtr const & pvRecord)
|
||||
}
|
||||
requester->unlisten(getPtrSelf());
|
||||
}
|
||||
pvRecord->removeListener(getPtrSelf(),pvCopy);
|
||||
}
|
||||
|
||||
|
||||
@@ -385,18 +447,12 @@ bool MonitorLocal::init(PVStructurePtr const & pvRequest)
|
||||
|
||||
|
||||
MonitorFactory::MonitorFactory()
|
||||
: isDestroyed(false)
|
||||
{
|
||||
}
|
||||
|
||||
MonitorFactory::~MonitorFactory()
|
||||
{
|
||||
}
|
||||
|
||||
void MonitorFactory::destroy()
|
||||
{
|
||||
Lock lock(mutex);
|
||||
isDestroyed = true;
|
||||
}
|
||||
|
||||
MonitorPtr MonitorFactory::createMonitor(
|
||||
@@ -405,10 +461,6 @@ MonitorPtr MonitorFactory::createMonitor(
|
||||
PVStructurePtr const & pvRequest)
|
||||
{
|
||||
Lock xx(mutex);
|
||||
if(isDestroyed) {
|
||||
monitorRequester->message("MonitorFactory is destroyed",errorMessage);
|
||||
return nullMonitor;
|
||||
}
|
||||
MonitorLocalPtr monitor(new MonitorLocal(
|
||||
monitorRequester,pvRecord));
|
||||
bool result = monitor->init(pvRequest);
|
||||
@@ -420,8 +472,8 @@ MonitorPtr MonitorFactory::createMonitor(
|
||||
}
|
||||
if(pvRecord->getTraceLevel()>0)
|
||||
{
|
||||
cout << "MonitorFactory::createMonitor";
|
||||
cout << " recordName " << pvRecord->getRecordName() << endl;
|
||||
cout << "MonitorFactory::createMonitor"
|
||||
<< " recordName " << pvRecord->getRecordName() << endl;
|
||||
}
|
||||
return monitor;
|
||||
}
|
||||
|
||||
@@ -53,18 +53,15 @@ extern "C" void pvdbl(const iocshArgBuf *args)
|
||||
for(size_t i=0; i<xxx.size(); ++i) cout<< xxx[i] << endl;
|
||||
}
|
||||
|
||||
static void channelProviderLocalExitHandler(void* /*pPrivate*/) {
|
||||
getChannelProviderLocal()->destroy();
|
||||
}
|
||||
|
||||
static void registerChannelProviderLocal(void)
|
||||
{
|
||||
static int firstTime = 1;
|
||||
cout << "registerChannelProviderLocal firstTime " << (firstTime ? "true" : "false") << endl;
|
||||
if (firstTime) {
|
||||
firstTime = 0;
|
||||
iocshRegister(&pvdblFuncDef, pvdbl);
|
||||
getChannelProviderLocal();
|
||||
epicsAtExit(channelProviderLocalExitHandler, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user