Use make_shared<>.
[dcpomatic.git] / src / lib / encode_server.cc
index 6560bcfec9ebf52b7dbeb5d0dc4d66ec25dcde05..635913cc29ec8d304390389241f18a81fc06cd0c 100644 (file)
@@ -1,19 +1,20 @@
 /*
     Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
 
-    This program is free software; you can redistribute it and/or modify
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic 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,
+    DCP-o-matic 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.
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 
@@ -40,6 +41,7 @@
 #include <boost/algorithm/string.hpp>
 #include <boost/scoped_array.hpp>
 #include <boost/foreach.hpp>
+#include <boost/make_shared.hpp>
 #include <string>
 #include <vector>
 #include <iostream>
@@ -62,6 +64,7 @@ using boost::thread;
 using boost::bind;
 using boost::scoped_array;
 using boost::optional;
+using boost::make_shared;
 using dcp::Size;
 using dcp::Data;
 
@@ -78,6 +81,7 @@ EncodeServer::~EncodeServer ()
 {
        {
                boost::mutex::scoped_lock lm (_mutex);
+               _terminate = true;
                _empty_condition.notify_all ();
                _full_condition.notify_all ();
        }
@@ -106,7 +110,7 @@ EncodeServer::process (shared_ptr<Socket> socket, struct timeval& after_read, st
        socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
 
        string s (buffer.get());
-       shared_ptr<cxml::Document> xml (new cxml::Document ("EncodingRequest"));
+       shared_ptr<cxml::Document> xml = make_shared<cxml::Document> ("EncodingRequest");
        xml->read_string (s);
        /* This is a double-check; the server shouldn't even be on the candidate list
           if it is the wrong version, but it doesn't hurt to make sure here.
@@ -117,7 +121,7 @@ EncodeServer::process (shared_ptr<Socket> socket, struct timeval& after_read, st
                return -1;
        }
 
-       shared_ptr<PlayerVideo> pvf (new PlayerVideo (xml, socket));
+       shared_ptr<PlayerVideo> pvf = make_shared<PlayerVideo> (xml, socket);
 
        DCPVideo dcp_video_frame (pvf, xml, _log);
 
@@ -262,7 +266,7 @@ EncodeServer::broadcast_received ()
                if (_verbose) {
                        cout << "Offering services to master " << _broadcast.send_endpoint.address().to_string () << "\n";
                }
-               shared_ptr<Socket> socket (new Socket);
+               shared_ptr<Socket> socket = make_shared<Socket> ();
                try {
                        socket->connect (boost::asio::ip::tcp::endpoint (_broadcast.send_endpoint.address(), Config::instance()->server_port_base() + 1));
                        socket->write (xml.length() + 1);