From 667f53b522d6181ca3794e0d45d52bc1b069a513 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sun, 19 Jan 2020 04:29:33 +0200 Subject: libcamera: signal: Make slots list private MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The slots list is touched from most of the Signal template functions. In order to prepare for thread-safety, move handling of the list to a small number of non-template functions in the SignalBase class. This incidently fixes a bug in signal disconnection handling where the signal wasn't removed from the object's signals list, as pointed out by the signals unit test. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/signal.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/libcamera/signal.cpp') diff --git a/src/libcamera/signal.cpp b/src/libcamera/signal.cpp index 19003331..9bb7eca8 100644 --- a/src/libcamera/signal.cpp +++ b/src/libcamera/signal.cpp @@ -14,6 +14,42 @@ namespace libcamera { +void SignalBase::connect(BoundMethodBase *slot) +{ + Object *object = slot->object(); + if (object) + object->connect(this); + slots_.push_back(slot); +} + +void SignalBase::disconnect(Object *object) +{ + disconnect([object](SlotList::iterator &iter) { + return (*iter)->match(object); + }); +} + +void SignalBase::disconnect(std::function match) +{ + for (auto iter = slots_.begin(); iter != slots_.end(); ) { + if (match(iter)) { + Object *object = (*iter)->object(); + if (object) + object->disconnect(this); + + delete *iter; + iter = slots_.erase(iter); + } else { + ++iter; + } + } +} + +SignalBase::SlotList SignalBase::slots() +{ + return slots_; +} + /** * \class Signal * \brief Generic signal and slot communication mechanism -- cgit v1.2.1