Add server configuration back in.
authorCarl Hetherington <cth@carlh.net>
Thu, 14 Nov 2013 11:39:10 +0000 (11:39 +0000)
committerCarl Hetherington <cth@carlh.net>
Thu, 14 Nov 2013 11:39:10 +0000 (11:39 +0000)
ChangeLog
src/lib/config.cc
src/lib/config.h
src/lib/server_finder.cc
src/wx/config_dialog.cc
src/wx/config_dialog.h
src/wx/server_dialog.cc [new file with mode: 0644]
src/wx/server_dialog.h [new file with mode: 0644]
src/wx/wscript

index 6725d35b07fb0b6c6edd5638a7427e60139c8a65..03c8bb029b206e6d960334389a164308c5fd8c2b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2013-11-14  Carl Hetherington  <cth@carlh.net>
+
+       * Add server configuration back in.
+
 2013-11-12  Carl Hetherington  <cth@carlh.net>
 
        * Version 1.29 released.
index 1a7c64405d88e5ae25a3346373b3884e4a5eb0fc..777d4114d9c3b9fcfaf14bb46bbe20ecd64a8347 100644 (file)
@@ -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);
index 0dcfd3f58b9593e420661652928e7885de3cd765..1fa54f669bd83130fa8502faf3c9789e9a5a8285 100644 (file)
@@ -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 */
index 941caf4d97b3f50e94c8f849b4a0187937b93d3e..a51aecd978dce72c47a1adf9eccdeaea17ac0f99 100644 (file)
@@ -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);
        }
 }
index 114f20aee908b93c3491c6d6770f102daf3bad80..71a0f505fc794947ce5a7791e5564245de078428 100644 (file)
@@ -39,6 +39,7 @@
 #include "dir_picker_ctrl.h"
 #include "dci_metadata_dialog.h"
 #include "preset_colour_conversion_dialog.h"
+#include "server_dialog.h"
 
 using std::vector;
 using std::string;
@@ -56,6 +57,8 @@ ConfigDialog::ConfigDialog (wxWindow* parent)
 
        make_misc_panel ();
        _notebook->AddPage (_misc_panel, _("Miscellaneous"), true);
+       make_servers_panel ();
+       _notebook->AddPage (_servers_panel, _("Encoding servers"), false);
        make_colour_conversions_panel ();
        _notebook->AddPage (_colour_conversions_panel, _("Colour conversions"), false);
        make_metadata_panel ();
@@ -290,6 +293,44 @@ ConfigDialog::make_metadata_panel ()
        _creator->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&ConfigDialog::creator_changed, this));
 }
 
+static string 
+server_column (string s)
+{
+       return s;
+}
+
+void
+ConfigDialog::make_servers_panel ()
+{
+       _servers_panel = new wxPanel (_notebook);
+       wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
+       _servers_panel->SetSizer (s);
+
+       _use_any_servers = new wxCheckBox (_servers_panel, wxID_ANY, _("Use all servers"));
+       s->Add (_use_any_servers, 0, wxALL, DCPOMATIC_SIZER_X_GAP);
+       
+       vector<string> columns;
+       columns.push_back (wx_to_std (_("IP address / host name")));
+       _servers_list = new EditableList<std::string, ServerDialog> (
+               _servers_panel,
+               columns,
+               boost::bind (&Config::servers, Config::instance()),
+               boost::bind (&Config::set_servers, Config::instance(), _1),
+               boost::bind (&server_column, _1)
+               );
+
+       s->Add (_servers_list, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_X_GAP);
+
+       _use_any_servers->SetValue (Config::instance()->use_any_servers ());
+       _use_any_servers->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&ConfigDialog::use_any_servers_changed, this));
+}
+
+void
+ConfigDialog::use_any_servers_changed ()
+{
+       Config::instance()->set_use_any_servers (_use_any_servers->GetValue ());
+}
+
 void
 ConfigDialog::language_changed ()
 {
index 2492f4899bdb7d90251bd50cf8d8eb6fd52ce7af..3a196cce309d031b742a1da39fcbfd692fe91089 100644 (file)
@@ -32,6 +32,7 @@ class DirPickerCtrl;
 class wxNotebook;
 class PresetColourConversion;
 class PresetColourConversionDialog;
+class ServerDialog;
 
 /** @class ConfigDialog
  *  @brief A dialogue to edit DCP-o-matic configuration.
@@ -60,10 +61,12 @@ private:
        void mail_server_changed ();
        void kdm_from_changed ();
        void kdm_email_changed ();
+       void use_any_servers_changed ();
 
        void setup_language_sensitivity ();
 
        void make_misc_panel ();
+       void make_servers_panel ();
        void make_tms_panel ();
        void make_metadata_panel ();
        void make_colour_conversions_panel ();
@@ -71,6 +74,7 @@ private:
 
        wxNotebook* _notebook;
        wxPanel* _misc_panel;
+       wxPanel* _servers_panel;
        wxPanel* _tms_panel;
        EditableList<PresetColourConversion, PresetColourConversionDialog>* _colour_conversions_panel;
        wxPanel* _metadata_panel;
@@ -97,5 +101,7 @@ private:
        wxSpinCtrl* _default_j2k_bandwidth;
        wxPanel* _kdm_email_panel;
        wxTextCtrl* _kdm_email;
+       wxCheckBox* _use_any_servers;
+       EditableList<std::string, ServerDialog>* _servers_list;
 };
 
diff --git a/src/wx/server_dialog.cc b/src/wx/server_dialog.cc
new file mode 100644 (file)
index 0000000..04da9ad
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "lib/server.h"
+#include "server_dialog.h"
+#include "wx_util.h"
+
+using std::string;
+using boost::shared_ptr;
+
+ServerDialog::ServerDialog (wxWindow* parent)
+       : wxDialog (parent, wxID_ANY, _("Server"))
+{
+       wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
+       table->AddGrowableCol (1, 1);
+
+        wxClientDC dc (parent);
+       /* XXX: bit of a mystery why we need such a long string here */
+        wxSize size = dc.GetTextExtent (wxT ("255.255.255.255.255.255.255.255"));
+        size.SetHeight (-1);
+
+        wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST);
+        wxArrayString list;
+
+       add_label_to_sizer (table, this, _("Host name or IP address"), true);
+       _host = new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, size);
+       table->Add (_host, 1, wxEXPAND | wxALL);
+
+       wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
+       overall_sizer->Add (table, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
+
+       wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
+       if (buttons) {
+               overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
+       }
+
+       SetSizer (overall_sizer);
+       overall_sizer->Layout ();
+       overall_sizer->SetSizeHints (this);
+}
+
+void
+ServerDialog::set (string server)
+{
+       _host->SetValue (std_to_wx (server));
+}
+
+string
+ServerDialog::get () const
+{
+       return wx_to_std (_host->GetValue ());
+}
+
diff --git a/src/wx/server_dialog.h b/src/wx/server_dialog.h
new file mode 100644 (file)
index 0000000..9d758d7
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <wx/wx.h>
+
+class ServerDialog : public wxDialog
+{
+public:
+       ServerDialog (wxWindow *);
+
+       void set (std::string);
+       std::string get () const;
+
+private:
+       wxTextCtrl* _host;
+};
index 85bb697ab915a3e67a9894477a6ade5a98235421..c86188c6aded9c93ffe2c1ac68ce44a5227401a0 100644 (file)
@@ -30,6 +30,7 @@ sources = """
           properties_dialog.cc
           repeat_dialog.cc
           screen_dialog.cc
+          server_dialog.cc
           servers_list_dialog.cc
           subtitle_panel.cc
           timecode.cc