#ifndef DCPOMATIC_ENCODE_SERVER_DESCRIPTION_H
#define DCPOMATIC_ENCODE_SERVER_DESCRIPTION_H
+#include "types.h"
#include <boost/date_time/posix_time/posix_time.hpp>
/** @class EncodeServerDescription
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) {
_listen_thread = 0;
boost::mutex::scoped_lock lm (_servers_mutex);
- _good_servers.clear ();
- _bad_servers.clear ();
-}
-
-static bool
-remove_missing (list<EncodeServerDescription>& servers, int since)
-{
- bool removed = false;
- list<EncodeServerDescription>::iterator i = servers.begin();
- while (i != servers.end()) {
- if (i->last_seen_seconds() > since) {
- list<EncodeServerDescription>::iterator j = i;
- ++j;
- servers.erase (i);
- i = j;
- removed = true;
- } else {
- ++i;
- }
- }
- return removed;
+ _servers.clear ();
}
void
/* 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<EncodeServerDescription>::iterator i = _servers.begin();
+ while (i != _servers.end()) {
+ if (i->last_seen_seconds() > 2 * interval) {
+ list<EncodeServerDescription>::iterator j = i;
+ ++j;
+ _servers.erase (i);
+ i = j;
+ removed = true;
+ } else {
+ ++i;
+ }
+ }
+
+ if (removed) {
emit (boost::bind (boost::ref (ServersListChanged)));
}
}
(*found)->set_seen ();
} else {
EncodeServerDescription sd (ip, xml->number_child<int>("Threads"), xml->optional_number_child<int>("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)));
}
EncodeServerFinder::server_found (string ip)
{
boost::mutex::scoped_lock lm (_servers_mutex);
- list<EncodeServerDescription>::iterator i = _good_servers.begin();
- while (i != _good_servers.end() && i->host_name() != ip) {
+ list<EncodeServerDescription>::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;
}
}
list<EncodeServerDescription>
-EncodeServerFinder::good_servers () const
-{
- boost::mutex::scoped_lock lm (_servers_mutex);
- return _good_servers;
-}
-
-list<EncodeServerDescription>
-EncodeServerFinder::bad_servers () const
+EncodeServerFinder::servers () const
{
boost::mutex::scoped_lock lm (_servers_mutex);
- return _bad_servers;
+ return _servers;
}
void
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 ();
void stop ();
- std::list<EncodeServerDescription> good_servers () const;
- std::list<EncodeServerDescription> bad_servers () const;
+ std::list<EncodeServerDescription> servers () const;
/** Emitted whenever the list of servers changes */
boost::signals2::signal<void ()> ServersListChanged;
/** Thread to listen to the responses from servers */
boost::thread* _listen_thread;
- /** Available servers with the correct link version */
- std::list<EncodeServerDescription> _good_servers;
- /** Available servers with an incorrect link version */
- std::list<EncodeServerDescription> _bad_servers;
- /** Mutex for _good_servers and _bad_servers */
+ /** Available servers */
+ std::list<EncodeServerDescription> _servers;
+ /** Mutex for _servers */
mutable boost::mutex _servers_mutex;
boost::asio::io_service _listen_io_service;
}
}
- 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)));
{
while (true) {
int N = 0;
- list<EncodeServerDescription> servers = EncodeServerFinder::instance()->good_servers ();
+ list<EncodeServerDescription> 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.
optional<int> threads;
list<EncodeServerDescription>::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<EncodeServerDescription>::iterator tmp = j;
++tmp;
/* 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);
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<string> (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<string> (i.threads ())));
+ } else {
+ _list->SetItem (n, 1, _("Incorrect version"));
+ }
++n;
}
}