summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/config.cc28
-rw-r--r--src/lib/config.h26
-rw-r--r--src/lib/server_finder.cc26
3 files changed, 75 insertions, 5 deletions
diff --git a/src/lib/config.cc b/src/lib/config.cc
index 1a7c64405..777d4114d 100644
--- a/src/lib/config.cc
+++ b/src/lib/config.cc
@@ -22,6 +22,7 @@
#include <fstream>
#include <glib.h>
#include <boost/filesystem.hpp>
+#include <boost/algorithm/string.hpp>
#include <libdcp/colour_matrix.h>
#include <libcxml/cxml.h>
#include "config.h"
@@ -48,6 +49,8 @@ using std::cerr;
using boost::shared_ptr;
using boost::lexical_cast;
using boost::optional;
+using boost::algorithm::is_any_of;
+using boost::algorithm::split;
Config* Config::_instance = 0;
@@ -55,6 +58,7 @@ Config* Config::_instance = 0;
Config::Config ()
: _num_local_encoding_threads (max (2U, boost::thread::hardware_concurrency()))
, _server_port_base (6192)
+ , _use_any_servers (true)
, _tms_path (".")
, _sound_processor (SoundProcessor::from_id (N_("dolby_cp750")))
, _default_still_length (10)
@@ -101,6 +105,18 @@ Config::read ()
b = f.optional_number_child<int> ("ServerPortBase");
}
_server_port_base = b.get ();
+
+ boost::optional<bool> u = f.optional_bool_child ("UseAnyServers");
+ _use_any_servers = u.get_value_or (true);
+
+ list<shared_ptr<cxml::Node> > servers = f.node_children ("Server");
+ for (list<shared_ptr<cxml::Node> >::iterator i = servers.begin(); i != servers.end(); ++i) {
+ if ((*i)->node_children("HostName").size() == 1) {
+ _servers.push_back ((*i)->string_child ("HostName"));
+ } else {
+ _servers.push_back ((*i)->content ());
+ }
+ }
_tms_ip = f.string_child ("TMSIP");
_tms_path = f.string_child ("TMSPath");
@@ -192,6 +208,12 @@ Config::read_old_metadata ()
_default_directory = v;
} else if (k == N_("server_port")) {
_server_port_base = atoi (v.c_str ());
+ } else if (k == N_("server")) {
+ vector<string> b;
+ split (b, v, is_any_of (" "));
+ if (b.size() == 2) {
+ _servers.push_back (b[0]);
+ }
} else if (k == N_("tms_ip")) {
_tms_ip = v;
} else if (k == N_("tms_path")) {
@@ -283,6 +305,12 @@ Config::write () const
root->add_child("NumLocalEncodingThreads")->add_child_text (lexical_cast<string> (_num_local_encoding_threads));
root->add_child("DefaultDirectory")->add_child_text (_default_directory.string ());
root->add_child("ServerPortBase")->add_child_text (lexical_cast<string> (_server_port_base));
+ root->add_child("UseAnyServers")->add_child_text (_use_any_servers ? "1" : "0");
+
+ for (vector<string>::const_iterator i = _servers.begin(); i != _servers.end(); ++i) {
+ root->add_child("Server")->add_child_text (*i);
+ }
+
root->add_child("TMSIP")->add_child_text (_tms_ip);
root->add_child("TMSPath")->add_child_text (_tms_path);
root->add_child("TMSUser")->add_child_text (_tms_user);
diff --git a/src/lib/config.h b/src/lib/config.h
index 0dcfd3f58..1fa54f669 100644
--- a/src/lib/config.h
+++ b/src/lib/config.h
@@ -31,7 +31,9 @@
#include <libdcp/metadata.h>
#include "dci_metadata.h"
#include "colour_conversion.h"
+#include "server.h"
+class ServerDescription;
class Scaler;
class Filter;
class SoundProcessor;
@@ -62,11 +64,29 @@ public:
return _server_port_base;
}
+ void set_use_any_servers (bool u) {
+ _use_any_servers = u;
+ }
+
+ bool use_any_servers () const {
+ return _use_any_servers;
+ }
+
+ /** @param s New list of servers */
+ void set_servers (std::vector<std::string> s) {
+ _servers = s;
+ }
+
+ /** @return Host names / IP addresses of J2K encoding servers that should definitely be used */
+ std::vector<std::string> servers () const {
+ return _servers;
+ }
+
/** @return The IP address of a TMS that we can copy DCPs to */
std::string tms_ip () const {
return _tms_ip;
}
-
+
/** @return The path on a TMS that we should write DCPs to */
std::string tms_path () const {
return _tms_path;
@@ -262,6 +282,10 @@ private:
* this port and the one above it will be used.
*/
int _server_port_base;
+ /** true to broadcast on the `any' address to look for servers */
+ bool _use_any_servers;
+ /** J2K encoding servers that should definitely be used */
+ std::vector<std::string> _servers;
/** Scaler to use for the "A" part of A/B comparisons */
Scaler const * _reference_scaler;
/** Filters to use for the "A" part of A/B comparisons */
diff --git a/src/lib/server_finder.cc b/src/lib/server_finder.cc
index 941caf4d9..a51aecd97 100644
--- a/src/lib/server_finder.cc
+++ b/src/lib/server_finder.cc
@@ -28,6 +28,7 @@
using std::string;
using std::stringstream;
using std::list;
+using std::vector;
using boost::shared_ptr;
using boost::scoped_array;
@@ -55,12 +56,29 @@ ServerFinder::broadcast_thread ()
socket.set_option (boost::asio::ip::udp::socket::reuse_address (true));
socket.set_option (boost::asio::socket_base::broadcast (true));
-
- boost::asio::ip::udp::endpoint end_point (boost::asio::ip::address_v4::broadcast(), Config::instance()->server_port_base() + 1);
+ string const data = DCPOMATIC_HELLO;
+
while (1) {
- string const data = DCPOMATIC_HELLO;
- socket.send_to (boost::asio::buffer (data.c_str(), data.size() + 1), end_point);
+ if (Config::instance()->use_any_servers ()) {
+ /* Broadcast to look for servers */
+ boost::asio::ip::udp::endpoint end_point (boost::asio::ip::address_v4::broadcast(), Config::instance()->server_port_base() + 1);
+ socket.send_to (boost::asio::buffer (data.c_str(), data.size() + 1), end_point);
+ }
+
+ /* Query our `definite' servers (if there are any) */
+ vector<string> servers = Config::instance()->servers ();
+ for (vector<string>::const_iterator i = servers.begin(); i != servers.end(); ++i) {
+ try {
+ boost::asio::ip::udp::resolver resolver (io_service);
+ boost::asio::ip::udp::resolver::query query (*i);
+ boost::asio::ip::udp::endpoint end_point (*resolver.resolve (query));
+ socket.send_to (boost::asio::buffer (data.c_str(), data.size() + 1), end_point);
+ } catch (...) {
+
+ }
+ }
+
dcpomatic_sleep (10);
}
}