]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/tray-monitor/task.h
Big backport from Enterprise
[bacula/bacula] / bacula / src / qt-console / tray-monitor / task.h
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2017 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 TASK_H
21 #define TASK_H
22
23 #include "common.h"
24 #include <QtCore/QObject>
25 #include "tray_conf.h"
26
27 enum {
28    TASK_NONE,
29    TASK_STATUS,
30    TASK_RESOURCES,
31    TASK_QUERY,
32    TASK_RUN,
33    TASK_RESTORE,
34    TASK_DEFAULTS,
35    TASK_CLOSE,
36    TASK_INFO,
37    TASK_BWLIMIT,
38    TASK_DISCONNECT
39 };
40
41 /* The task should emit a signal when done */
42 class task: public QObject
43 {
44    Q_OBJECT
45
46 public:
47    RESMON   *res;
48    POOLMEM  *errmsg;
49    int       type;
50    bool      status;
51    char     *curline;
52    char     *curend;
53    char     *arg;               /* Argument that can be used by some tasks */
54    char     *arg2;
55
56    union {
57       bool  b;
58       int   i;
59       char  c[256];
60    } result;                    /* The task might return something */
61    
62    task(): QObject(), res(NULL), type(TASK_NONE), status(false), curline(NULL),
63       curend(NULL), arg(NULL), arg2(NULL)
64    {
65       errmsg = get_pool_memory(PM_FNAME);
66       *errmsg = 0;
67       memset(result.c, 0, sizeof(result.c));
68    };
69    ~task() {
70       Enter();
71       disconnect();             /* disconnect all signals */
72       free_pool_memory(errmsg);
73    };
74    void init(int t) {
75       res = NULL;
76       type = t;
77       status = false;
78    };
79    void init(RESMON *s, int t) {
80       init(t);
81       res = s;
82    };
83
84    RESMON *get_res();
85    void lock_res();
86    void unlock_res();
87    bool connect_bacula();
88    bool do_status();
89    bool read_status_terminated(RESMON *res);
90    bool read_status_header(RESMON *res);
91    bool read_status_running(RESMON *res);
92    bool set_bandwidth();
93    bool disconnect_bacula();
94    void mark_as_done() {
95       status = true;
96       emit done(this);
97    };
98    void mark_as_failed() {
99       status = false;
100       emit done(this);
101    };
102    bool get_resources();
103    bool get_next_line(RESMON *res);
104    bool get_job_defaults(); /* Look r->defaults.job */
105    bool run_job();
106    bool get_job_info(const char *level);     /* look r->info */
107
108 signals:
109    void done(task *t);
110 };
111
112 worker *worker_start();
113 void worker_stop(worker *);
114
115 #endif