diff --git a/src/pvxs/sharedpv.h b/src/pvxs/sharedpv.h index 6527028..a953e4f 100644 --- a/src/pvxs/sharedpv.h +++ b/src/pvxs/sharedpv.h @@ -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: diff --git a/src/sharedpv.cpp b/src/sharedpv.cpp index 219b6a8..69b1e90 100644 --- a/src/sharedpv.cpp +++ b/src/sharedpv.cpp @@ -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;