summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/object.cpp7
-rw-r--r--src/libcamera/signal.cpp36
2 files changed, 42 insertions, 1 deletions
diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp
index 21aad565..f2a8be17 100644
--- a/src/libcamera/object.cpp
+++ b/src/libcamera/object.cpp
@@ -76,7 +76,12 @@ Object::Object(Object *parent)
*/
Object::~Object()
{
- for (SignalBase *signal : signals_)
+ /*
+ * Move signals to a private list to avoid concurrent iteration and
+ * deletion of items from Signal::disconnect().
+ */
+ std::list<SignalBase *> signals(std::move(signals_));
+ for (SignalBase *signal : signals)
signal->disconnect(this);
if (pendingMessages_)
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<bool(SlotList::iterator &)> 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