1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
5    Copyright (C) 2011-2012 Planets Communications B.V.
6    Copyright (C) 2013-2019 Bareos GmbH & Co. KG
7 
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12 
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    Affero General Public License for more details.
17 
18    You should have received a copy of the GNU Affero General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22 */
23 
24 #ifndef BAREOS_SRC_DIRD_SCHEDULER_PRIVATE_H_
25 #define BAREOS_SRC_DIRD_SCHEDULER_PRIVATE_H_
26 
27 #include "dird/scheduler_job_item_queue.h"
28 
29 #include <atomic>
30 #include <functional>
31 #include <memory>
32 
33 namespace directordaemon {
34 
35 class SchedulerTimeAdapter;
36 
37 class SchedulerPrivate {
38  public:
39   ~SchedulerPrivate();
40   SchedulerPrivate();
41 
42   SchedulerPrivate(const SchedulerPrivate& other) = delete;
43   SchedulerPrivate(SchedulerPrivate&& other) = delete;
44   SchedulerPrivate& operator=(SchedulerPrivate&& other) = delete;
45   SchedulerPrivate& operator=(const SchedulerPrivate& other) = delete;
46 
47   void WaitForJobsToRun();
48   void FillSchedulerJobQueueOrSleep();
49   void AddJobWithNoRunResourceToQueue(JobResource* job);
50 
51   std::unique_ptr<SchedulerTimeAdapter> time_adapter;
52   SchedulerJobItemQueue prioritised_job_item_queue;
53   std::atomic<bool> active{true};
54 
55   // testing:
56   SchedulerPrivate(std::unique_ptr<SchedulerTimeAdapter> time_adapter,
57                    std::function<void(JobControlRecord*)> ExecuteJobCallback);
58 
59  private:
60   std::function<void(JobControlRecord*)> ExecuteJobCallback_;
61   JobControlRecord* TryCreateJobControlRecord(const SchedulerJobItem& next_job);
62   void AddJobsForThisAndNextHourToQueue();
63   void AddJobToQueue(JobResource* job,
64                      RunResource* run,
65                      time_t now,
66                      time_t runtime);
67 };
68 
69 }  // namespace directordaemon
70 
71 #endif  // BAREOS_SRC_DIRD_SCHEDULER_PRIVATE_H_
72