projects
/
dcpomatic.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8fb1e87
)
Better updating of servers list when things change.
author
Carl Hetherington
<cth@carlh.net>
Mon, 6 Jul 2015 12:37:35 +0000
(13:37 +0100)
committer
Carl Hetherington
<cth@carlh.net>
Mon, 6 Jul 2015 12:37:35 +0000
(13:37 +0100)
src/lib/config.cc
patch
|
blob
|
history
src/lib/config.h
patch
|
blob
|
history
src/lib/encoder.cc
patch
|
blob
|
history
src/lib/encoder.h
patch
|
blob
|
history
src/lib/server_finder.cc
patch
|
blob
|
history
src/lib/server_finder.h
patch
|
blob
|
history
src/wx/servers_list_dialog.cc
patch
|
blob
|
history
src/wx/servers_list_dialog.h
patch
|
blob
|
history
diff --git
a/src/lib/config.cc
b/src/lib/config.cc
index ee38e98665994ce4c87380e400032b4dd35adf45..16a3849b51cc93da95af614b923d44bcfec5a8b7 100644
(file)
--- a/
src/lib/config.cc
+++ b/
src/lib/config.cc
@@
-407,9
+407,9
@@
Config::drop ()
}
void
}
void
-Config::changed ()
+Config::changed (
Property what
)
{
{
- Changed ();
+ Changed (
what
);
}
void
}
void
diff --git
a/src/lib/config.h
b/src/lib/config.h
index 0040591f165543c4b895c9171397aa91b7e95eaa..ad95bc3441fccc3344e82c4bb62c172589c1aae0 100644
(file)
--- 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;
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;
/** @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;
void set_use_any_servers (bool u) {
_use_any_servers = u;
- changed ();
+ changed (
USE_ANY_SERVERS
);
}
bool use_any_servers () const {
}
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;
/** @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 */
}
/** @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 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;
void write () const;
diff --git
a/src/lib/encoder.cc
b/src/lib/encoder.cc
index c3ad084419a071958be2873ac0a8c1c6a373d1d2..07c97c6747fa6a341e5a759ac370139398ae252c 100644
(file)
--- 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 "data.h"
#include <libcxml/cxml.h>
#include <boost/lambda/lambda.hpp>
+#include <boost/foreach.hpp>
#include <iostream>
#include "i18n.h"
#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)
{
, _terminate (false)
, _writer (writer)
{
-
+ servers_list_changed ();
}
Encoder::~Encoder ()
}
Encoder::~Encoder ()
@@
-99,7
+100,7
@@
Encoder::begin ()
_writer->set_encoder_threads (_threads.size ());
if (!ServerFinder::instance()->disabled ()) {
_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 ();
}
_threads.clear ();
+ _terminate = false;
}
void
}
void
@@
-362,7
+364,10
@@
catch (...)
}
void
}
void
-Encoder::server
_found (ServerDescription s
)
+Encoder::server
s_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 6bbdda4c5e23ea8722395623efd950293d749d13..85bc6ae99d57b823058d6cc95251cc955c416d82 100644
(file)
--- 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 encoder_thread (boost::optional<ServerDescription>);
void terminate_threads ();
void add_worker_threads (ServerDescription);
- void server
_found (ServerDescription
);
+ void server
s_list_changed (
);
/** Film that we are encoding */
boost::shared_ptr<const Film> _film;
/** 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 ac4651657872418b7aa56f9aaedfa91e595599f9..a189ae8027dbcb44762b822d281ecc089335ca8e 100644
(file)
--- 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));
{
_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 ()
}
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);
}
boost::mutex::scoped_lock lm (_mutex);
_servers.push_back (sd);
}
- emit (boost::bind (boost::ref (Server
Found), sd
));
+ emit (boost::bind (boost::ref (Server
sListChanged)
));
}
start_accept ();
}
start_accept ();
@@
-190,19
+191,6
@@
ServerFinder::server_found (string ip) const
return i != _servers.end ();
}
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 ()
{
ServerFinder*
ServerFinder::instance ()
{
@@
-219,3
+207,22
@@
ServerFinder::drop ()
delete _instance;
_instance = 0;
}
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 ec855938be4ddfd92e1f324194cbf6d8128b4e41..c43c2a422ee9c5e1dceeaa4d7962d0ad29cb1bf1 100644
(file)
--- a/
src/lib/server_finder.h
+++ b/
src/lib/server_finder.h
@@
-19,13
+19,12
@@
#include "server.h"
#include "signaller.h"
#include "server.h"
#include "signaller.h"
+#include "config.h"
#include <boost/signals2.hpp>
class ServerFinder : public Signaller, public ExceptionStore
{
public:
#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 ();
static ServerFinder* instance ();
static void drop ();
@@
-37,6
+36,11
@@
public:
return _disabled;
}
return _disabled;
}
+ std::list<ServerDescription> servers () const;
+
+ /** Emitted whenever the list of servers changes */
+ boost::signals2::signal<void ()> ServersListChanged;
+
private:
ServerFinder ();
~ServerFinder ();
private:
ServerFinder ();
~ServerFinder ();
@@
-48,7
+52,7
@@
private:
void start_accept ();
void handle_accept (boost::system::error_code ec, boost::shared_ptr<Socket> socket);
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;
bool _disabled;
diff --git
a/src/wx/servers_list_dialog.cc
b/src/wx/servers_list_dialog.cc
index 13c6df70729746ba40d7556e14fa2e5d8fdd3c5f..b678da073d498f0e55ebc006fa89dfda85116b28 100644
(file)
--- a/
src/wx/servers_list_dialog.cc
+++ b/
src/wx/servers_list_dialog.cc
@@
-17,10
+17,11
@@
*/
*/
-#include <boost/lexical_cast.hpp>
-#include "lib/server_finder.h"
#include "servers_list_dialog.h"
#include "wx_util.h"
#include "servers_list_dialog.h"
#include "wx_util.h"
+#include "lib/server_finder.h"
+#include <boost/lexical_cast.hpp>
+#include <boost/foreach.hpp>
using std::list;
using std::string;
using std::list;
using std::string;
@@
-61,19
+62,24
@@
ServersListDialog::ServersListDialog (wxWindow* parent)
s->Layout ();
s->SetSizeHints (this);
s->Layout ();
s->SetSizeHints (this);
- _server_finder_connection = ServerFinder::instance()->connect (boost::bind (&ServersListDialog::server_found, this, _1));
+ _server_finder_connection = ServerFinder::instance()->ServersListChanged.connect (boost::bind (&ServersListDialog::servers_list_changed, this));
+ servers_list_changed ();
}
void
}
void
-ServersListDialog::server
_found (ServerDescription s
)
+ServersListDialog::server
s_list_changed (
)
{
{
- wxListItem list_item;
- int const n = _list->GetItemCount ();
- list_item.SetId (n);
- _list->InsertItem (list_item);
+ _list->DeleteAllItems ();
+
+ int n = 0;
+ BOOST_FOREACH (ServerDescription i, ServerFinder::instance()->servers ()) {
+ wxListItem list_item;
+ list_item.SetId (n);
+ _list->InsertItem (list_item);
-
_list->SetItem (n, 0, std_to_wx (s
.host_name ()));
-
_list->SetItem (n, 1, std_to_wx (lexical_cast<string> (s
.threads ())));
+
_list->SetItem (n, 0, std_to_wx (i
.host_name ()));
+
_list->SetItem (n, 1, std_to_wx (lexical_cast<string> (i
.threads ())));
- _servers.push_back (s);
+ ++n;
+ }
}
}
diff --git
a/src/wx/servers_list_dialog.h
b/src/wx/servers_list_dialog.h
index 3804d2a7e17f9f3ddecad977759333c3597e655d..60fcdb236bece157ebd11dcf47e29c23db6ec25f 100644
(file)
--- a/
src/wx/servers_list_dialog.h
+++ b/
src/wx/servers_list_dialog.h
@@
-27,9
+27,8
@@
public:
ServersListDialog (wxWindow *);
private:
ServersListDialog (wxWindow *);
private:
- void server
_found (ServerDescription
);
+ void server
s_list_changed (
);
- std::list<ServerDescription> _servers;
wxListCtrl* _list;
boost::signals2::scoped_connection _server_finder_connection;
wxListCtrl* _list;
boost::signals2::scoped_connection _server_finder_connection;