2 Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
21 /** @file src/job_manager.h
22 * @brief A simple scheduler for jobs.
25 #include "signaller.h"
26 #include <boost/thread/mutex.hpp>
27 #include <boost/thread.hpp>
28 #include <boost/signals2.hpp>
35 extern bool wait_for_jobs ();
38 * @brief A simple scheduler for jobs.
40 class JobManager : public Signaller, public boost::noncopyable
43 boost::shared_ptr<Job> add (boost::shared_ptr<Job>);
44 boost::shared_ptr<Job> add_after (boost::shared_ptr<Job> after, boost::shared_ptr<Job> j);
45 std::list<boost::shared_ptr<Job> > get () const;
46 bool work_to_do () const;
48 void increase_priority (boost::shared_ptr<Job>);
49 void decrease_priority (boost::shared_ptr<Job>);
52 bool paused () const {
53 boost::mutex::scoped_lock lm (_mutex);
58 boost::shared_ptr<const Film> film,
59 boost::shared_ptr<const Playlist> playlist,
61 boost::signals2::connection& connection,
62 boost::function<void()> ready
65 boost::signals2::signal<void (boost::weak_ptr<Job>)> JobAdded;
66 boost::signals2::signal<void ()> JobsReordered;
67 boost::signals2::signal<void (boost::optional<std::string>, boost::optional<std::string>)> ActiveJobsChanged;
69 static JobManager* instance ();
73 /* This function is part of the test suite */
74 friend bool ::wait_for_jobs ();
80 void priority_changed ();
82 mutable boost::mutex _mutex;
83 /** List of jobs in the order that they will be executed */
84 std::list<boost::shared_ptr<Job> > _jobs;
87 boost::shared_ptr<Job> _paused_job;
89 boost::optional<std::string> _last_active_job;
90 boost::thread* _scheduler;
92 static JobManager* _instance;