Use dcp::file_to_string().
[dcpomatic.git] / src / lib / upload_job.cc
1 /*
2     Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 /** @file src/upload_job.cc
23  *  @brief A job to copy DCPs to a server using libcurl.
24  */
25
26
27 #include "compose.hpp"
28 #include "config.h"
29 #include "curl_uploader.h"
30 #include "dcpomatic_log.h"
31 #include "film.h"
32 #include "log.h"
33 #include "scp_uploader.h"
34 #include "upload_job.h"
35 #include <iostream>
36
37 #include "i18n.h"
38
39
40 using std::string;
41 using std::min;
42 using std::shared_ptr;
43 using boost::scoped_ptr;
44 #if BOOST_VERSION >= 106100
45 using namespace boost::placeholders;
46 #endif
47
48
49 UploadJob::UploadJob (shared_ptr<const Film> film)
50         : Job (film)
51         , _status (_("Waiting"))
52 {
53
54 }
55
56
57 UploadJob::~UploadJob ()
58 {
59         stop_thread ();
60 }
61
62
63 string
64 UploadJob::name () const
65 {
66         return _("Copy DCP to TMS");
67 }
68
69
70 string
71 UploadJob::json_name () const
72 {
73         return N_("upload");
74 }
75
76
77 void
78 UploadJob::run ()
79 {
80         LOG_GENERAL_NC (N_("Upload job starting"));
81
82         scoped_ptr<Uploader> uploader;
83         switch (Config::instance()->tms_protocol()) {
84         case FileTransferProtocol::SCP:
85                 uploader.reset (new SCPUploader(bind (&UploadJob::set_status, this, _1), bind(&UploadJob::set_progress, this, _1, false)));
86                 break;
87         case FileTransferProtocol::FTP:
88                 uploader.reset (new CurlUploader(bind (&UploadJob::set_status, this, _1), bind(&UploadJob::set_progress, this, _1, false)));
89                 break;
90         }
91
92         uploader->upload (_film->dir(_film->dcp_name()));
93
94         set_progress (1);
95         set_status (N_(""));
96         set_state (FINISHED_OK);
97 }
98
99
100 string
101 UploadJob::status () const
102 {
103         boost::mutex::scoped_lock lm (_status_mutex);
104         auto s = Job::status ();
105         if (!_status.empty() && !finished_in_error()) {
106                 s += N_("; ") + _status;
107         }
108         return s;
109 }
110
111
112 void
113 UploadJob::set_status (string s)
114 {
115         boost::mutex::scoped_lock lm (_status_mutex);
116         _status = s;
117 }