From baea758a3aafbf78d07c2d4776f7c61f615254b5 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 27 Jul 2017 11:06:39 +0100 Subject: [PATCH 1/1] Tidy up server reporting in dcpomatic_cli. --- src/tools/dcpomatic_cli.cc | 71 +++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/src/tools/dcpomatic_cli.cc b/src/tools/dcpomatic_cli.cc index 9572c7973..2a70a3003 100644 --- a/src/tools/dcpomatic_cli.cc +++ b/src/tools/dcpomatic_cli.cc @@ -122,44 +122,51 @@ show_servers () int N = 0; list servers = EncodeServerFinder::instance()->servers (); - if (Config::instance()->use_any_servers ()) { - if (servers.empty ()) { - cout << "No encoding servers found.\n"; - ++N; - } else { - cout << std::left << setw(24) << "Host" << " Threads\n"; - ++N; - BOOST_FOREACH (EncodeServerDescription const & i, servers) { - cout << std::left << setw(24) << i.host_name() << " " << i.threads() << "\n"; - ++N; - } - } + /* 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. + */ + + if (servers.empty() && Config::instance()->servers().empty()) { + cout << "No encoding servers found or configured.\n"; + ++N; } else { - vector configured_servers = Config::instance()->servers(); - if (configured_servers.empty()) { - cout << "No configured servers, and DCP-o-matic is not set to search for any server.\n"; - ++N; - } else { - cout << std::left << setw(24) << "Host" << " Status Threads\n"; - ++N; - BOOST_FOREACH (string const & i, Config::instance()->servers()) { - cout << std::left << setw(24) << i << " "; - optional threads; - BOOST_FOREACH (EncodeServerDescription const & j, servers) { - if (i == j.host_name()) { - threads = j.threads(); - } - } - if (static_cast(threads)) { - cout << "UP " << threads.get() << "\n"; + cout << std::left << setw(24) << "Host" << " Status Threads\n"; + ++N; + + /* Report the state of configured servers */ + BOOST_FOREACH (string i, Config::instance()->servers()) { + cout << std::left << setw(24) << i << " "; + + /* See if this server is on the active list; if so, remove it and note + the number of threads it is offering. + */ + optional threads; + list::iterator j = servers.begin (); + while (j != servers.end ()) { + if (i == j->host_name()) { + threads = j->threads(); + list::iterator tmp = j; + ++tmp; + servers.erase (j); + j = tmp; } else { - cout << "DOWN\n"; + ++j; } - ++N; } + if (static_cast(threads)) { + cout << "UP " << threads.get() << "\n"; + } else { + cout << "DOWN\n"; + } + ++N; } - } + /* 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"; + ++N; + } + } dcpomatic_sleep (1); -- 2.30.2