summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-07-06 13:37:35 +0100
committerCarl Hetherington <cth@carlh.net>2015-07-06 13:37:35 +0100
commit7ae514af0aea1b953a93f88d5507e6c1dd675908 (patch)
treed14505318a517a3f86944fc194d9b4f5ce05a3e3 /src/lib
parent8fb1e87dc19210dc29a1eabc4e410af4a3fb740b (diff)
Better updating of servers list when things change.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/config.cc4
-rw-r--r--src/lib/config.h14
-rw-r--r--src/lib/encoder.cc13
-rw-r--r--src/lib/encoder.h2
-rw-r--r--src/lib/server_finder.cc35
-rw-r--r--src/lib/server_finder.h10
6 files changed, 50 insertions, 28 deletions
diff --git a/src/lib/config.cc b/src/lib/config.cc
index ee38e9866..16a3849b5 100644
--- a/src/lib/config.cc
+++ b/src/lib/config.cc
@@ -407,9 +407,9 @@ Config::drop ()
}
void
-Config::changed ()
+Config::changed (Property what)
{
- Changed ();
+ Changed (what);
}
void
diff --git a/src/lib/config.h b/src/lib/config.h
index 0040591f1..ad95bc344 100644
--- a/src/lib/config.h
+++ b/src/lib/config.h
@@ -59,6 +59,12 @@ public:
boost::filesystem::path default_directory_or (boost::filesystem::path a) const;
+ enum Property {
+ USE_ANY_SERVERS,
+ SERVERS,
+ OTHER
+ };
+
/** @return base port number to use for J2K encoding servers */
int server_port_base () const {
return _server_port_base;
@@ -66,7 +72,7 @@ public:
void set_use_any_servers (bool u) {
_use_any_servers = u;
- changed ();
+ changed (USE_ANY_SERVERS);
}
bool use_any_servers () const {
@@ -76,7 +82,7 @@ public:
/** @param s New list of servers */
void set_servers (std::vector<std::string> s) {
_servers = s;
- changed ();
+ changed (SERVERS);
}
/** @return Host names / IP addresses of J2K encoding servers that should definitely be used */
@@ -395,8 +401,8 @@ public:
void add_to_history (boost::filesystem::path p);
- void changed ();
- boost::signals2::signal<void ()> Changed;
+ void changed (Property p = OTHER);
+ boost::signals2::signal<void (Property)> Changed;
void write () const;
diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc
index c3ad08441..07c97c674 100644
--- a/src/lib/encoder.cc
+++ b/src/lib/encoder.cc
@@ -36,6 +36,7 @@
#include "data.h"
#include <libcxml/cxml.h>
#include <boost/lambda/lambda.hpp>
+#include <boost/foreach.hpp>
#include <iostream>
#include "i18n.h"
@@ -66,7 +67,7 @@ Encoder::Encoder (shared_ptr<const Film> film, weak_ptr<Job> j, shared_ptr<Write
, _terminate (false)
, _writer (writer)
{
-
+ servers_list_changed ();
}
Encoder::~Encoder ()
@@ -99,7 +100,7 @@ Encoder::begin ()
_writer->set_encoder_threads (_threads.size ());
if (!ServerFinder::instance()->disabled ()) {
- _server_found_connection = ServerFinder::instance()->connect (boost::bind (&Encoder::server_found, this, _1));
+ _server_found_connection = ServerFinder::instance()->ServersListChanged.connect (boost::bind (&Encoder::servers_list_changed, this));
}
}
@@ -271,6 +272,7 @@ Encoder::terminate_threads ()
}
_threads.clear ();
+ _terminate = false;
}
void
@@ -362,7 +364,10 @@ catch (...)
}
void
-Encoder::server_found (ServerDescription s)
+Encoder::servers_list_changed ()
{
- add_worker_threads (s);
+ terminate_threads ();
+ BOOST_FOREACH (ServerDescription i, ServerFinder::instance()->servers ()) {
+ add_worker_threads (i);
+ }
}
diff --git a/src/lib/encoder.h b/src/lib/encoder.h
index 6bbdda4c5..85bc6ae99 100644
--- a/src/lib/encoder.h
+++ b/src/lib/encoder.h
@@ -83,7 +83,7 @@ private:
void encoder_thread (boost::optional<ServerDescription>);
void terminate_threads ();
void add_worker_threads (ServerDescription);
- void server_found (ServerDescription);
+ void servers_list_changed ();
/** Film that we are encoding */
boost::shared_ptr<const Film> _film;
diff --git a/src/lib/server_finder.cc b/src/lib/server_finder.cc
index ac4651657..a189ae802 100644
--- a/src/lib/server_finder.cc
+++ b/src/lib/server_finder.cc
@@ -47,6 +47,7 @@ ServerFinder::ServerFinder ()
{
_broadcast_thread = new boost::thread (boost::bind (&ServerFinder::broadcast_thread, this));
_listen_thread = new boost::thread (boost::bind (&ServerFinder::listen_thread, this));
+ Config::instance()->Changed.connect (boost::bind (&ServerFinder::config_changed, this, _1));
}
ServerFinder::~ServerFinder ()
@@ -172,7 +173,7 @@ ServerFinder::handle_accept (boost::system::error_code ec, shared_ptr<Socket> so
boost::mutex::scoped_lock lm (_mutex);
_servers.push_back (sd);
}
- emit (boost::bind (boost::ref (ServerFound), sd));
+ emit (boost::bind (boost::ref (ServersListChanged)));
}
start_accept ();
@@ -190,19 +191,6 @@ ServerFinder::server_found (string ip) const
return i != _servers.end ();
}
-boost::signals2::connection
-ServerFinder::connect (boost::function<void (ServerDescription)> fn)
-{
- boost::mutex::scoped_lock lm (_mutex);
-
- /* Emit the current list of servers */
- for (list<ServerDescription>::iterator i = _servers.begin(); i != _servers.end(); ++i) {
- fn (*i);
- }
-
- return ServerFound.connect (fn);
-}
-
ServerFinder*
ServerFinder::instance ()
{
@@ -219,3 +207,22 @@ ServerFinder::drop ()
delete _instance;
_instance = 0;
}
+
+list<ServerDescription>
+ServerFinder::servers () const
+{
+ boost::mutex::scoped_lock lm (_mutex);
+ return _servers;
+}
+
+void
+ServerFinder::config_changed (Config::Property what)
+{
+ if (what == Config::USE_ANY_SERVERS || what == Config::SERVERS) {
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _servers.clear ();
+ }
+ ServersListChanged ();
+ }
+}
diff --git a/src/lib/server_finder.h b/src/lib/server_finder.h
index ec855938b..c43c2a422 100644
--- a/src/lib/server_finder.h
+++ b/src/lib/server_finder.h
@@ -19,13 +19,12 @@
#include "server.h"
#include "signaller.h"
+#include "config.h"
#include <boost/signals2.hpp>
class ServerFinder : public Signaller, public ExceptionStore
{
public:
- boost::signals2::connection connect (boost::function<void (ServerDescription)>);
-
static ServerFinder* instance ();
static void drop ();
@@ -37,6 +36,11 @@ public:
return _disabled;
}
+ std::list<ServerDescription> servers () const;
+
+ /** Emitted whenever the list of servers changes */
+ boost::signals2::signal<void ()> ServersListChanged;
+
private:
ServerFinder ();
~ServerFinder ();
@@ -48,7 +52,7 @@ private:
void start_accept ();
void handle_accept (boost::system::error_code ec, boost::shared_ptr<Socket> socket);
- boost::signals2::signal<void (ServerDescription)> ServerFound;
+ void config_changed (Config::Property what);
bool _disabled;