Message ID | 20210418090459.38506-4-naush@raspberrypi.com |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Hi Naush As per our discussion, it may be worthwhile including a merge (or Merge) method. Something like "void Metadata::Merge(Metadata &other)". This method would add any key/value pairs in the passed metadata object "other" to "this" one. It could do so either by "moving" the data values or by copying them. Presumably there are circumstances where "moving" may be more efficient. Such a method would help us to update the metadata correctly when we elect not to run the control algorithms (one of the other patches in this set). It would update all the sensor's metadata items, not just the "device.status", preparing us for the day when we have sensors that will generate such information. Thanks! David On Sun, 18 Apr 2021 at 10:05, Naushir Patuck <naush@raspberrypi.com> wrote: > > Add a default, move and copy constructor as well as a move operator > implementation RPiController::Metadata class. > > Signed-off-by: Naushir Patuck <naush@raspberrypi.com> > Reviewed-by: David Plowman <david.plowman@raspberrypi.com> > --- > src/ipa/raspberrypi/controller/metadata.hpp | 24 +++++++++++++++++++++ > 1 file changed, 24 insertions(+) > > diff --git a/src/ipa/raspberrypi/controller/metadata.hpp b/src/ipa/raspberrypi/controller/metadata.hpp > index 07dd28ed9e0a..319f2320fc70 100644 > --- a/src/ipa/raspberrypi/controller/metadata.hpp > +++ b/src/ipa/raspberrypi/controller/metadata.hpp > @@ -19,6 +19,21 @@ namespace RPiController { > class Metadata > { > public: > + Metadata() = default; > + > + Metadata(Metadata const &other) > + { > + std::lock_guard<std::mutex> other_lock(other.mutex_); > + data_ = other.data_; > + } > + > + Metadata(Metadata &&other) > + { > + std::lock_guard<std::mutex> other_lock(other.mutex_); > + data_ = std::move(other.data_); > + other.data_.clear(); > + } > + > template<typename T> > void Set(std::string const &tag, T const &value) > { > @@ -51,6 +66,15 @@ public: > return *this; > } > > + Metadata &operator=(Metadata &&other) > + { > + std::lock_guard<std::mutex> lock(mutex_); > + std::lock_guard<std::mutex> other_lock(other.mutex_); > + data_ = std::move(other.data_); > + other.data_.clear(); > + return *this; > + } > + > template<typename T> > T *GetLocked(std::string const &tag) > { > -- > 2.25.1 >
diff --git a/src/ipa/raspberrypi/controller/metadata.hpp b/src/ipa/raspberrypi/controller/metadata.hpp index 07dd28ed9e0a..319f2320fc70 100644 --- a/src/ipa/raspberrypi/controller/metadata.hpp +++ b/src/ipa/raspberrypi/controller/metadata.hpp @@ -19,6 +19,21 @@ namespace RPiController { class Metadata { public: + Metadata() = default; + + Metadata(Metadata const &other) + { + std::lock_guard<std::mutex> other_lock(other.mutex_); + data_ = other.data_; + } + + Metadata(Metadata &&other) + { + std::lock_guard<std::mutex> other_lock(other.mutex_); + data_ = std::move(other.data_); + other.data_.clear(); + } + template<typename T> void Set(std::string const &tag, T const &value) { @@ -51,6 +66,15 @@ public: return *this; } + Metadata &operator=(Metadata &&other) + { + std::lock_guard<std::mutex> lock(mutex_); + std::lock_guard<std::mutex> other_lock(other.mutex_); + data_ = std::move(other.data_); + other.data_.clear(); + return *this; + } + template<typename T> T *GetLocked(std::string const &tag) {