summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-03-16 22:25:57 +0000
committerCarl Hetherington <cth@carlh.net>2015-03-16 22:25:57 +0000
commit1b0b9e4b951e305d47bb011fc4e198472bb3fecf (patch)
tree715db098b0a716a0ee3d46aa060fecadcffc1766 /src/lib
parentc416bee48d5a5829077c844c5f2b802bf13ab4cd (diff)
Hand-apply 33b76b675d747fd828aba91d9d857227cb8a8244 from master; make sure signals are disconnected in the right places.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/encoder.cc4
-rw-r--r--src/lib/encoder.h2
-rw-r--r--src/lib/film.cc17
-rw-r--r--src/lib/film.h5
-rw-r--r--src/lib/server_finder.cc8
-rw-r--r--src/lib/server_finder.h8
6 files changed, 32 insertions, 12 deletions
diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc
index 6b520571a..2a6026879 100644
--- a/src/lib/encoder.cc
+++ b/src/lib/encoder.cc
@@ -93,7 +93,9 @@ Encoder::begin ()
_threads.push_back (new boost::thread (boost::bind (&Encoder::encoder_thread, this, optional<ServerDescription> ())));
}
- ServerFinder::instance()->connect (boost::bind (&Encoder::server_found, this, _1));
+ if (!ServerFinder::instance()->disabled ()) {
+ _server_found_connection = ServerFinder::instance()->connect (boost::bind (&Encoder::server_found, this, _1));
+ }
}
void
diff --git a/src/lib/encoder.h b/src/lib/encoder.h
index 694c9bf1f..a4fe55874 100644
--- a/src/lib/encoder.h
+++ b/src/lib/encoder.h
@@ -114,6 +114,8 @@ private:
boost::shared_ptr<Writer> _writer;
Waker _waker;
+
+ boost::signals2::scoped_connection _server_found_connection;
};
#endif
diff --git a/src/lib/film.cc b/src/lib/film.cc
index c695a7d4b..0b48bf7b1 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -136,8 +136,8 @@ Film::Film (boost::filesystem::path dir, bool log)
{
set_isdcf_date_today ();
- _playlist->Changed.connect (bind (&Film::playlist_changed, this));
- _playlist->ContentChanged.connect (bind (&Film::playlist_content_changed, this, _1, _2));
+ _playlist_changed_connection = _playlist->Changed.connect (bind (&Film::playlist_changed, this));
+ _playlist_content_changed_connection = _playlist->ContentChanged.connect (bind (&Film::playlist_content_changed, this, _1, _2));
/* Make state.directory a complete path without ..s (where possible)
(Code swiped from Adam Bowen on stackoverflow)
@@ -167,6 +167,13 @@ Film::Film (boost::filesystem::path dir, bool log)
_playlist->set_sequence_video (_sequence_video);
}
+Film::~Film ()
+{
+ for (list<boost::signals2::connection>::const_iterator i = _job_connections.begin(); i != _job_connections.end(); ++i) {
+ i->disconnect ();
+ }
+}
+
string
Film::video_identifier () const
{
@@ -937,7 +944,11 @@ Film::examine_and_add_content (shared_ptr<Content> c)
}
shared_ptr<Job> j (new ExamineContentJob (shared_from_this(), c));
- j->Finished.connect (bind (&Film::maybe_add_content, this, boost::weak_ptr<Job> (j), boost::weak_ptr<Content> (c)));
+
+ _job_connections.push_back (
+ j->Finished.connect (bind (&Film::maybe_add_content, this, boost::weak_ptr<Job> (j), boost::weak_ptr<Content> (c)))
+ );
+
JobManager::instance()->add (j);
}
diff --git a/src/lib/film.h b/src/lib/film.h
index 2de065159..c3ab9f2ff 100644
--- a/src/lib/film.h
+++ b/src/lib/film.h
@@ -60,6 +60,7 @@ class Film : public boost::enable_shared_from_this<Film>, public boost::noncopya
{
public:
Film (boost::filesystem::path, bool log = true);
+ ~Film ();
boost::filesystem::path info_dir () const;
boost::filesystem::path j2c_path (int, Eyes, bool) const;
@@ -341,6 +342,10 @@ private:
/** true if our state has changed since we last saved it */
mutable bool _dirty;
+ boost::signals2::scoped_connection _playlist_changed_connection;
+ boost::signals2::scoped_connection _playlist_content_changed_connection;
+ std::list<boost::signals2::connection> _job_connections;
+
friend struct paths_test;
friend struct film_metadata_test;
};
diff --git a/src/lib/server_finder.cc b/src/lib/server_finder.cc
index bef00702f..d62531d9f 100644
--- a/src/lib/server_finder.cc
+++ b/src/lib/server_finder.cc
@@ -192,13 +192,9 @@ ServerFinder::server_found (string ip) const
return i != _servers.end ();
}
-void
+boost::signals2::connection
ServerFinder::connect (boost::function<void (ServerDescription)> fn)
{
- if (_disabled) {
- return;
- }
-
boost::mutex::scoped_lock lm (_mutex);
/* Emit the current list of servers */
@@ -206,7 +202,7 @@ ServerFinder::connect (boost::function<void (ServerDescription)> fn)
fn (*i);
}
- ServerFound.connect (fn);
+ return ServerFound.connect (fn);
}
ServerFinder*
diff --git a/src/lib/server_finder.h b/src/lib/server_finder.h
index c0f1feb66..3fab6864a 100644
--- a/src/lib/server_finder.h
+++ b/src/lib/server_finder.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -23,7 +23,7 @@
class ServerFinder : public ExceptionStore
{
public:
- void connect (boost::function<void (ServerDescription)>);
+ boost::signals2::connection connect (boost::function<void (ServerDescription)>);
static ServerFinder* instance ();
static void drop ();
@@ -32,6 +32,10 @@ public:
_disabled = true;
}
+ bool disabled () const {
+ return _disabled;
+ }
+
private:
ServerFinder ();
~ServerFinder ();