SharedPV ensure callback pairing

Ensure that onLastDisconnect() isn't called
unless onFirstConnect() is/has been called.
This commit is contained in:
Michael Davidsaver
2018-09-21 10:42:31 -07:00
parent a6eca51fa0
commit 6b463d77e1
3 changed files with 9 additions and 2 deletions
+2
View File
@@ -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)
+3 -1
View File
@@ -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) {
+4 -1
View File
@@ -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();
}
}