Add copy variant of SharedPV::fetch()

This commit is contained in:
Michael Davidsaver
2020-07-26 20:46:12 -07:00
parent 24f3478c98
commit e31e6cda36
2 changed files with 19 additions and 3 deletions
+4 -2
View File
@@ -72,8 +72,10 @@ struct PVXS_API SharedPV
//! Update the internal data value, and dispatch subscription updates to any clients.
void post(const Value& val);
//! query the internal data value.
void fetch(Value& val);
//! query the internal data value and update the provided Value.
void fetch(Value& val) const;
//! Return a (shallow) copy of the internal data value
Value fetch() const;
struct Impl;
private:
+15 -1
View File
@@ -407,7 +407,7 @@ void SharedPV::post(const Value& val)
}
}
void SharedPV::fetch(Value& val)
void SharedPV::fetch(Value& val) const
{
if(!impl)
throw std::logic_error("Empty SharedPV");
@@ -421,6 +421,20 @@ void SharedPV::fetch(Value& val)
}
}
Value SharedPV::fetch() const
{
if(!impl)
throw std::logic_error("Empty SharedPV");
Guard G(impl->lock);
if(impl->current) {
return impl->current.clone();
} else {
throw std::logic_error("open() first");
}
}
struct StaticSource::Impl : public Source
{
RWLock lock;