WIP: partially restore PlayerVideo transfer over network.
[dcpomatic.git] / src / lib / font.cc
index 333539aa4b7cbc6441dbc2e5c75dae4d0f7752a3..c817d361018ce9c9bfc51068a4846e4ce06c284e 100644 (file)
 
 #include "font.h"
 #include "dcpomatic_assert.h"
+#include "dcpomatic_socket.h"
+#include <dcp/data.h>
+#include <dcp/raw_convert.h>
 #include <libxml++/libxml++.h>
 #include <boost/foreach.hpp>
 
 using std::string;
+using boost::shared_ptr;
+using dcp::raw_convert;
+using namespace dcpomatic;
 
 Font::Font (cxml::NodePtr node)
        : _id (node->string_child ("Id"))
@@ -37,7 +43,7 @@ Font::Font (cxml::NodePtr node)
 }
 
 void
-Font::as_xml (xmlpp::Node* node)
+Font::as_xml (xmlpp::Node* node) const
 {
        node->add_child("Id")->add_child_text (_id);
        if (_file) {
@@ -45,9 +51,30 @@ Font::as_xml (xmlpp::Node* node)
        }
 }
 
+/** Add things to an XML node to describe this font for transfer across
+ *  a network to another machine.  The companion method send_binary() will be called
+ *  to send binary parts.
+ */
+void
+Font::transfer_xml (xmlpp::Node* node) const
+{
+       node->add_child("Id")->add_child_text (_id);
+       if (_file) {
+               node->add_child("FileLength")->add_child_text(raw_convert<string>(boost::filesystem::file_size(*_file)));
+       }
+}
+
+void
+Font::transfer_binary (shared_ptr<Socket> socket) const
+{
+       if (_file) {
+               dcp::Data data (*_file);
+               socket->write (data.data().get(), data.size());
+       }
+}
 
 bool
-operator== (Font const & a, Font const & b)
+dcpomatic::operator== (Font const & a, Font const & b)
 {
        if (a.id() != b.id()) {
                return false;
@@ -57,7 +84,7 @@ operator== (Font const & a, Font const & b)
 }
 
 bool
-operator!= (Font const & a, Font const & b)
+dcpomatic::operator!= (Font const & a, Font const & b)
 {
        return !(a == b);
 }