Don't use --target-macos-arm64 any more, since it's not supported.
[dcpomatic.git] / src / lib / job_manager.h
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/job_manager.h
23  *  @brief A simple scheduler for jobs.
24  */
25
26
27 #include "signaller.h"
28 #include <boost/thread/mutex.hpp>
29 #include <boost/thread.hpp>
30 #include <boost/signals2.hpp>
31 #include <boost/thread/condition.hpp>
32 #include <list>
33
34
35 class Job;
36 class Film;
37 class Playlist;
38 class Content;
39 struct threed_test7;
40
41
42 extern bool wait_for_jobs ();
43
44
45 /** @class JobManager
46  *  @brief A simple scheduler for jobs.
47  */
48 class JobManager : public Signaller
49 {
50 public:
51         JobManager (JobManager const&) = delete;
52         JobManager& operator= (JobManager const&) = delete;
53
54         std::shared_ptr<Job> add (std::shared_ptr<Job>);
55         std::shared_ptr<Job> add_after (std::shared_ptr<Job> after, std::shared_ptr<Job> j);
56         std::list<std::shared_ptr<Job>> get () const;
57         bool work_to_do () const;
58         bool errors () const;
59         void increase_priority (std::shared_ptr<Job>);
60         void decrease_priority (std::shared_ptr<Job>);
61         void pause ();
62         void resume ();
63         bool paused () const {
64                 boost::mutex::scoped_lock lm (_mutex);
65                 return _paused;
66         }
67
68         void analyse_audio (
69                 std::shared_ptr<const Film> film,
70                 std::shared_ptr<const Playlist> playlist,
71                 bool from_zero,
72                 boost::signals2::connection& connection,
73                 std::function<void()> ready
74                 );
75
76         void analyse_subtitles (
77                 std::shared_ptr<const Film> film,
78                 std::shared_ptr<Content> content,
79                 boost::signals2::connection& connection,
80                 std::function<void()> ready
81                 );
82
83         boost::signals2::signal<void (std::weak_ptr<Job>)> JobAdded;
84         boost::signals2::signal<void ()> JobsReordered;
85         boost::signals2::signal<void (boost::optional<std::string>, boost::optional<std::string>)> ActiveJobsChanged;
86
87         static JobManager* instance ();
88         static void drop ();
89
90 private:
91         /* This function is part of the test suite */
92         friend bool ::wait_for_jobs ();
93         friend struct threed_test7;
94
95         JobManager ();
96         ~JobManager ();
97         void scheduler ();
98         void start ();
99         void job_finished ();
100
101         mutable boost::mutex _mutex;
102         boost::condition _empty_condition;
103         /** List of jobs in the order that they will be executed */
104         std::list<std::shared_ptr<Job>> _jobs;
105         std::list<boost::signals2::connection> _connections;
106         bool _terminate = false;
107         bool _paused = false;
108         std::shared_ptr<Job> _paused_job;
109
110         boost::optional<std::string> _last_active_job;
111         boost::thread _scheduler;
112
113         static JobManager* _instance;
114 };