SharedPV ensure callback pairing
Ensure that onLastDisconnect() isn't called unless onFirstConnect() is/has been called.
This commit is contained in:
@@ -202,6 +202,8 @@ private:
|
||||
//! Used for initial Monitor update and Get operations.
|
||||
epics::pvData::BitSet valid;
|
||||
|
||||
bool notifiedConn; // whether onFirstConnect() has been, or is being, called
|
||||
|
||||
int debugLvl;
|
||||
|
||||
EPICS_NOT_COPYABLE(SharedPV)
|
||||
|
||||
@@ -51,6 +51,7 @@ SharedChannel::SharedChannel(const std::tr1::shared_ptr<SharedPV> &owner,
|
||||
if(owner->channels.empty())
|
||||
handler = owner->handler;
|
||||
owner->channels.push_back(this);
|
||||
owner->notifiedConn = !!handler;
|
||||
}
|
||||
if(handler) {
|
||||
handler->onFirstConnect(owner);
|
||||
@@ -64,8 +65,9 @@ SharedChannel::~SharedChannel()
|
||||
Guard G(owner->mutex);
|
||||
bool wasempty = owner->channels.empty();
|
||||
owner->channels.remove(this);
|
||||
if(!wasempty && owner->channels.empty()) {
|
||||
if(!wasempty && owner->channels.empty() && owner->notifiedConn) {
|
||||
handler = owner->handler;
|
||||
owner->notifiedConn = false;
|
||||
}
|
||||
}
|
||||
if(handler) {
|
||||
|
||||
@@ -74,6 +74,7 @@ SharedPV::shared_pointer SharedPV::buildMailbox(pvas::SharedPV::Config *conf)
|
||||
SharedPV::SharedPV(const std::tr1::shared_ptr<Handler> &handler, pvas::SharedPV::Config *conf)
|
||||
:config(conf ? *conf : Config())
|
||||
,handler(handler)
|
||||
,notifiedConn(false)
|
||||
,debugLvl(0)
|
||||
{
|
||||
REFTRACE_INCREMENT(num_instances);
|
||||
@@ -264,8 +265,10 @@ void SharedPV::close(bool destroy)
|
||||
puts.clear();
|
||||
rpcs.clear();
|
||||
monitors.clear();
|
||||
if(!channels.empty())
|
||||
if(!channels.empty() && notifiedConn) {
|
||||
p_handler = handler;
|
||||
notifiedConn = false;
|
||||
}
|
||||
channels.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user