No-op; fix GPL address and use the explicit-program-name version.
[dcpomatic.git] / src / lib / job_manager.h
1 /*
2     Copyright (C) 2012-2015 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 /** @file  src/job_manager.h
22  *  @brief A simple scheduler for jobs.
23  */
24
25 #include "signaller.h"
26 #include <boost/thread/mutex.hpp>
27 #include <boost/thread.hpp>
28 #include <boost/signals2.hpp>
29 #include <list>
30
31 class Job;
32 class Film;
33 class Playlist;
34
35 extern void wait_for_jobs ();
36
37 /** @class JobManager
38  *  @brief A simple scheduler for jobs.
39  */
40 class JobManager : public Signaller, public boost::noncopyable
41 {
42 public:
43
44         boost::shared_ptr<Job> add (boost::shared_ptr<Job>);
45         std::list<boost::shared_ptr<Job> > get () const;
46         bool work_to_do () const;
47         bool errors () const;
48
49         void analyse_audio (
50                 boost::shared_ptr<const Film> film,
51                 boost::shared_ptr<const Playlist> playlist,
52                 boost::signals2::connection& connection,
53                 boost::function<void()> ready
54                 );
55
56         boost::signals2::signal<void (boost::weak_ptr<Job>)> JobAdded;
57         boost::signals2::signal<void (boost::optional<std::string>, boost::optional<std::string>)> ActiveJobsChanged;
58
59         static JobManager* instance ();
60         static void drop ();
61
62 private:
63         /* This function is part of the test suite */
64         friend void ::wait_for_jobs ();
65
66         JobManager ();
67         ~JobManager ();
68         void scheduler ();
69         void start ();
70
71         mutable boost::mutex _mutex;
72         std::list<boost::shared_ptr<Job> > _jobs;
73         bool _terminate;
74
75         boost::optional<std::string> _last_active_job;
76         boost::thread* _scheduler;
77
78         static JobManager* _instance;
79 };