1 /*
2    Bacula(R) - The Network Backup Solution
3 
4    Copyright (C) 2000-2020 Kern Sibbald
5 
6    The original author of Bacula is Kern Sibbald, with contributions
7    from many others, a complete list can be found in the file AUTHORS.
8 
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13 
14    This notice must be preserved when any source code is
15    conveyed and/or propagated.
16 
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 
20 #ifndef RUN_H
21 #define RUN_H
22 
23 #include "common.h"
24 #include "ui_run.h"
25 #include "tray_conf.h"
26 #include "task.h"
27 #include <QDialog>
28 
29 class RunJob: public QDialog
30 {
31    Q_OBJECT
32 
33 public:
34    RESMON *res;
35    QWidget *tabAdvanced;
36    POOL_MEM command;
37    POOL_MEM info;
38    POOL_MEM level;
39    POOL_MEM curjob;
40    Ui::runForm ui;
41    RunJob(RESMON *r);
42    ~RunJob();
43 
44 public slots:
45    void jobChanged(int);
46    void levelChanged(int);
47    void jobStarted(task *);
48    void jobInfo(task *);
49    void fill_defaults(task *);
50    void tabChange(int idx);
51    void runjob();
52    /* close the window properly */
53    void close_cb(task *t);
54    void close_cb();
55 };
56 
57 /* Object that can scan a directory to find jobs */
58 class TSched: public QObject
59 {
60    Q_OBJECT
61 private:
62    char *command_dir;
63    bool read_command_file(const char *file, alist *lst, btime_t mtime);
64    int   timer;
65 
66 public:
67    TSched();
68    ~TSched();
69    void init(const char *cmd_dir);
70    bool scan_for_commands(alist *lst);
start()71    void start() {
72       timer = startTimer(60000);  // 1-minute timer
73    };
stop()74    void stop() {
75       if (timer >= 0) {
76          killTimer(timer);
77          timer = -1;
78       }
79    };
80 public slots:
81    void jobStarted(task *t);
82 protected:
83    void timerEvent(QTimerEvent *event);
84 
85 };
86 
87 
88 /* Job found in the command directory */
89 class TSchedJob: public QObject
90 {
91    Q_OBJECT
92 
93 public:
94    char *component;             // Name of the daemon
95    char *command;               // job command
96    btime_t create_date;         // When the command file was created
TSchedJob()97    TSchedJob() : component(NULL), command(NULL) {};
98 
TSchedJob(const char * comp,const char * cmd,btime_t cd)99    TSchedJob(const char *comp, const char *cmd, btime_t cd) {
100          component = bstrdup(comp);
101          command = bstrdup(cmd);
102          create_date = cd;
103    };
104 
~TSchedJob()105    ~TSchedJob() {
106       clear();
107    };
clear()108    void clear() {
109       if (component) {
110          bfree_and_null(component);
111       }
112       if (command) {
113          bfree_and_null(command);
114       }
115       create_date = 0;
116    };
117 };
118 
119 #endif
120