diff --git a/src/database/pvRecord.cpp b/src/database/pvRecord.cpp index 1047e7c..fd0be95 100644 --- a/src/database/pvRecord.cpp +++ b/src/database/pvRecord.cpp @@ -99,6 +99,51 @@ PVRecord::~PVRecord() notifyClients(); } +void PVRecord::remove() +{ +#ifdef XXX + { + epicsGuard guard(mutex); + if(traceLevel>0) { + cout << "PVRecord::remove() " << recordName + << " isDestroyed " << (isDestroyed ? "true" : "false") + << endl; + } + if(isDestroyed) { + return; + } + isDestroyed = true; + } +#endif + PVDatabasePtr pvDatabase(PVDatabase::getMaster()); + if(pvDatabase) pvDatabase->removeRecord(shared_from_this()); + pvTimeStamp.detach(); + for(std::list::iterator iter = pvListenerList.begin(); + iter!=pvListenerList.end(); + iter++ ) + { + PVListenerPtr listener = iter->lock(); + if(!listener) continue; + if(traceLevel>0) { + cout << "PVRecord::remove() calling listener->unlisten " << recordName << endl; + } + listener->unlisten(shared_from_this()); + } + pvListenerList.clear(); + for (std::list::iterator iter = clientList.begin(); + iter!=clientList.end(); + iter++ ) + { + PVRecordClientPtr client = iter->lock(); + if(!client) continue; + if(traceLevel>0) { + cout << "PVRecord::remove() calling client->detach " << recordName << endl; + } + client->detach(shared_from_this()); + } + clientList.clear(); +} + void PVRecord::initPVRecord() { PVRecordStructurePtr parent; diff --git a/src/pv/pvDatabase.h b/src/pv/pvDatabase.h index 27f0849..2094a73 100644 --- a/src/pv/pvDatabase.h +++ b/src/pv/pvDatabase.h @@ -101,6 +101,15 @@ public: * @brief DEPRECATED */ virtual void destroy() {} + /** + * @brief remove record from database. + * + * Remove the PVRecord. Release any resources used and + * get rid of listeners and requesters. + * If derived class overrides this then it must call PVRecord::remove() + * after it has destroyed any resorces it uses. + */ + virtual void remove(); /** * @brief Optional method for derived class. * diff --git a/src/special/removeRecord.cpp b/src/special/removeRecord.cpp index e6aab7e..1e157de 100644 --- a/src/special/removeRecord.cpp +++ b/src/special/removeRecord.cpp @@ -65,7 +65,7 @@ void RemoveRecord::process() pvResult->put(name + " not found"); return; } - pvRecord->destroy(); + pvRecord->remove(); pvResult->put("success"); }