From: Carl Hetherington Date: Fri, 13 Apr 2018 00:09:10 +0000 (+0100) Subject: Tidy up to use one list of servers. X-Git-Tag: v2.13.14~1 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=9106e6ed551b13e1b7c7ee2088d54ce0ae430bcf;ds=sidebyside Tidy up to use one list of servers. --- diff --git a/src/lib/encode_server_description.h b/src/lib/encode_server_description.h index 0b9d72f44..f60051b85 100644 --- a/src/lib/encode_server_description.h +++ b/src/lib/encode_server_description.h @@ -21,6 +21,7 @@ #ifndef DCPOMATIC_ENCODE_SERVER_DESCRIPTION_H #define DCPOMATIC_ENCODE_SERVER_DESCRIPTION_H +#include "types.h" #include /** @class EncodeServerDescription @@ -59,8 +60,8 @@ public: return _threads; } - int link_version () const { - return _link_version; + bool current_link_version () const { + return _link_version == SERVER_LINK_VERSION; } void set_host_name (std::string n) { diff --git a/src/lib/encode_server_finder.cc b/src/lib/encode_server_finder.cc index 06a6a396b..1837101b5 100644 --- a/src/lib/encode_server_finder.cc +++ b/src/lib/encode_server_finder.cc @@ -99,27 +99,7 @@ EncodeServerFinder::stop () _listen_thread = 0; boost::mutex::scoped_lock lm (_servers_mutex); - _good_servers.clear (); - _bad_servers.clear (); -} - -static bool -remove_missing (list& servers, int since) -{ - bool removed = false; - list::iterator i = servers.begin(); - while (i != servers.end()) { - if (i->last_seen_seconds() > since) { - list::iterator j = i; - ++j; - servers.erase (i); - i = j; - removed = true; - } else { - ++i; - } - } - return removed; + _servers.clear (); } void @@ -171,9 +151,22 @@ try /* Discard servers that we haven't seen for a while */ { boost::mutex::scoped_lock lm (_servers_mutex); - bool g = remove_missing(_good_servers, 2 * interval); - bool b = remove_missing(_bad_servers, 2 * interval); - if (g || b) { + + bool removed = false; + list::iterator i = _servers.begin(); + while (i != _servers.end()) { + if (i->last_seen_seconds() > 2 * interval) { + list::iterator j = i; + ++j; + _servers.erase (i); + i = j; + removed = true; + } else { + ++i; + } + } + + if (removed) { emit (boost::bind (boost::ref (ServersListChanged))); } } @@ -243,13 +236,8 @@ EncodeServerFinder::handle_accept (boost::system::error_code ec, shared_ptrset_seen (); } else { EncodeServerDescription sd (ip, xml->number_child("Threads"), xml->optional_number_child("Version").get_value_or(0)); - if (sd.link_version() == SERVER_LINK_VERSION) { - boost::mutex::scoped_lock lm (_servers_mutex); - _good_servers.push_back (sd); - } else { - boost::mutex::scoped_lock lm (_servers_mutex); - _bad_servers.push_back (sd); - } + boost::mutex::scoped_lock lm (_servers_mutex); + _servers.push_back (sd); emit (boost::bind (boost::ref (ServersListChanged))); } @@ -260,21 +248,12 @@ optional::iterator> EncodeServerFinder::server_found (string ip) { boost::mutex::scoped_lock lm (_servers_mutex); - list::iterator i = _good_servers.begin(); - while (i != _good_servers.end() && i->host_name() != ip) { + list::iterator i = _servers.begin(); + while (i != _servers.end() && i->host_name() != ip) { ++i; } - if (i != _good_servers.end()) { - return i; - } - - i = _bad_servers.begin(); - while (i != _bad_servers.end() && i->host_name() != ip) { - ++i; - } - - if (i != _bad_servers.end()) { + if (i != _servers.end()) { return i; } @@ -300,17 +279,10 @@ EncodeServerFinder::drop () } list -EncodeServerFinder::good_servers () const -{ - boost::mutex::scoped_lock lm (_servers_mutex); - return _good_servers; -} - -list -EncodeServerFinder::bad_servers () const +EncodeServerFinder::servers () const { boost::mutex::scoped_lock lm (_servers_mutex); - return _bad_servers; + return _servers; } void @@ -319,8 +291,7 @@ EncodeServerFinder::config_changed (Config::Property what) if (what == Config::USE_ANY_SERVERS || what == Config::SERVERS) { { boost::mutex::scoped_lock lm (_servers_mutex); - _good_servers.clear (); - _bad_servers.clear (); + _servers.clear (); } ServersListChanged (); _search_condition.notify_all (); diff --git a/src/lib/encode_server_finder.h b/src/lib/encode_server_finder.h index 58dee7e64..abfcc6d35 100644 --- a/src/lib/encode_server_finder.h +++ b/src/lib/encode_server_finder.h @@ -48,8 +48,7 @@ public: void stop (); - std::list good_servers () const; - std::list bad_servers () const; + std::list servers () const; /** Emitted whenever the list of servers changes */ boost::signals2::signal ServersListChanged; @@ -74,11 +73,9 @@ private: /** Thread to listen to the responses from servers */ boost::thread* _listen_thread; - /** Available servers with the correct link version */ - std::list _good_servers; - /** Available servers with an incorrect link version */ - std::list _bad_servers; - /** Mutex for _good_servers and _bad_servers */ + /** Available servers */ + std::list _servers; + /** Mutex for _servers */ mutable boost::mutex _servers_mutex; boost::asio::io_service _listen_io_service; diff --git a/src/lib/j2k_encoder.cc b/src/lib/j2k_encoder.cc index bbd602dd0..e62e708cc 100644 --- a/src/lib/j2k_encoder.cc +++ b/src/lib/j2k_encoder.cc @@ -412,7 +412,11 @@ J2KEncoder::servers_list_changed () } } - BOOST_FOREACH (EncodeServerDescription i, EncodeServerFinder::instance()->good_servers ()) { + BOOST_FOREACH (EncodeServerDescription i, EncodeServerFinder::instance()->servers()) { + if (!i.current_link_version()) { + continue; + } + LOG_GENERAL (N_("Adding %1 worker threads for remote %2"), i.threads(), i.host_name ()); for (int j = 0; j < i.threads(); ++j) { _threads.push_back (new boost::thread (boost::bind (&J2KEncoder::encoder_thread, this, i))); diff --git a/src/tools/dcpomatic_cli.cc b/src/tools/dcpomatic_cli.cc index 52a113cbb..788594f0c 100644 --- a/src/tools/dcpomatic_cli.cc +++ b/src/tools/dcpomatic_cli.cc @@ -121,7 +121,7 @@ list_servers () { while (true) { int N = 0; - list servers = EncodeServerFinder::instance()->good_servers (); + list servers = EncodeServerFinder::instance()->servers(); /* This is a bit fiddly because we want to list configured servers that are down as well as all those (configured and found by broadcast) that are up. @@ -144,7 +144,7 @@ list_servers () optional threads; list::iterator j = servers.begin (); while (j != servers.end ()) { - if (i == j->host_name()) { + if (i == j->host_name() && j->current_link_version()) { threads = j->threads(); list::iterator tmp = j; ++tmp; @@ -164,14 +164,13 @@ list_servers () /* Now report any left that have been found by broadcast */ BOOST_FOREACH (EncodeServerDescription const & i, servers) { - cout << std::left << setw(24) << i.host_name() << " UP " << i.threads() << "\n"; + if (i.current_link_version()) { + cout << std::left << setw(24) << i.host_name() << " UP " << i.threads() << "\n"; + } else { + cout << std::left << setw(24) << i.host_name() << " bad version\n"; + } ++N; } - - /* And those that have a bad version */ - BOOST_FOREACH (EncodeServerDescription i, EncodeServerFinder::instance()->good_servers()) { - cout << std::left << setw(24) << i.host_name() << " bad version\n"; - } } dcpomatic_sleep (1); diff --git a/src/wx/servers_list_dialog.cc b/src/wx/servers_list_dialog.cc index e4839916e..37a143384 100644 --- a/src/wx/servers_list_dialog.cc +++ b/src/wx/servers_list_dialog.cc @@ -77,25 +77,17 @@ ServersListDialog::servers_list_changed () int n = 0; - BOOST_FOREACH (EncodeServerDescription i, EncodeServerFinder::instance()->good_servers()) { + BOOST_FOREACH (EncodeServerDescription i, EncodeServerFinder::instance()->servers()) { wxListItem list_item; list_item.SetId (n); _list->InsertItem (list_item); _list->SetItem (n, 0, std_to_wx (i.host_name ())); - _list->SetItem (n, 1, std_to_wx (lexical_cast (i.threads ()))); - - ++n; - } - - BOOST_FOREACH (EncodeServerDescription i, EncodeServerFinder::instance()->bad_servers()) { - wxListItem list_item; - list_item.SetId (n); - _list->InsertItem (list_item); - - _list->SetItem (n, 0, std_to_wx (i.host_name ())); - _list->SetItem (n, 1, _("Incorrect version")); - + if (i.current_link_version()) { + _list->SetItem (n, 1, std_to_wx (lexical_cast (i.threads ()))); + } else { + _list->SetItem (n, 1, _("Incorrect version")); + } ++n; } }