}
void
-Config::changed ()
+Config::changed (Property what)
{
- Changed ();
+ Changed (what);
}
void
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;
void set_use_any_servers (bool u) {
_use_any_servers = u;
- changed ();
+ changed (USE_ANY_SERVERS);
}
bool use_any_servers () const {
/** @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 */
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;
#include "data.h"
#include <libcxml/cxml.h>
#include <boost/lambda/lambda.hpp>
+#include <boost/foreach.hpp>
#include <iostream>
#include "i18n.h"
, _terminate (false)
, _writer (writer)
{
-
+ servers_list_changed ();
}
Encoder::~Encoder ()
_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));
}
}
}
_threads.clear ();
+ _terminate = false;
}
void
}
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);
+ }
}
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;
{
_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 ()
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 ();
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 ()
{
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 ();
+ }
+}
#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 ();
return _disabled;
}
+ std::list<ServerDescription> servers () const;
+
+ /** Emitted whenever the list of servers changes */
+ boost::signals2::signal<void ()> ServersListChanged;
+
private:
ServerFinder ();
~ServerFinder ();
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;
*/
-#include <boost/lexical_cast.hpp>
-#include "lib/server_finder.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;
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
-ServersListDialog::server_found (ServerDescription s)
+ServersListDialog::servers_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;
+ }
}
ServersListDialog (wxWindow *);
private:
- void server_found (ServerDescription);
+ void servers_list_changed ();
- std::list<ServerDescription> _servers;
wxListCtrl* _list;
boost::signals2::scoped_connection _server_finder_connection;