]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/tray-monitor/tray-monitor.h
Add new QT traymonitor
[bacula/bacula] / bacula / src / qt-console / tray-monitor / tray-monitor.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2004-2011 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
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    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    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  * Includes specific to the tray monitor
30  *
31  *     Nicolas Boichat, August MMIV
32  *
33  */
34
35 #ifndef TRAY_MONITOR_H
36 #define TRAY_MONITOR_H
37
38 #include <QString>
39 #include <QStringList>
40 #include "bacula.h"
41 #include "tray_conf.h"
42 #include "jcr.h"
43
44 struct job_defaults {
45    QString job_name;
46    QString pool_name;
47    QString messages_name;
48    QString client_name;
49    QString store_name;
50    QString where;
51    QString level;
52    QString type;
53    QString fileset_name;
54    QString catalog_name;
55    bool enabled;
56 };
57
58 struct resources {
59    QStringList job_list;
60    QStringList pool_list;
61    QStringList client_list;
62    QStringList storage_list;
63    QStringList levels;
64    QStringList fileset_list;
65    QStringList messages_list;
66 };
67
68 enum stateenum {
69    idle = 0,
70    running = 1,
71    warn = 2,
72    error = 3
73 };
74
75 class monitoritem;
76 int doconnect(monitoritem* item);
77 void get_list(monitoritem* item, const char *cmd, QStringList &lst);
78
79 class  monitoritem {
80 public:
81    rescode type; /* R_DIRECTOR, R_CLIENT or R_STORAGE */
82    void* resource; /* DIRRES*, CLIENT* or STORE* */
83    BSOCK *D_sock;
84    stateenum state;
85    stateenum oldstate;
86
87    char *get_name() {
88       return ((URES*)resource)->hdr.name;
89    }
90
91    void writecmd(const char* command) {
92       if (this->D_sock) {
93          this->D_sock->msglen = pm_strcpy(&this->D_sock->msg, command);
94          bnet_send(this->D_sock);
95       }
96    }
97
98    bool get_job_defaults(struct job_defaults &job_defs)
99    {
100       int stat;
101       char *def;
102       BSOCK *dircomm;
103       bool rtn = false;
104       QString scmd = QString(".defaults job=\"%1\"").arg(job_defs.job_name);
105
106       if (job_defs.job_name == "") {
107          return rtn;
108       }
109
110       if (!doconnect(this)) {
111          return rtn;
112       }
113       dircomm = this->D_sock;
114       dircomm->fsend("%s", scmd.toUtf8().data());
115
116       while ((stat = dircomm->recv()) > 0) {
117          def = strchr(dircomm->msg, '=');
118          if (!def) {
119             continue;
120          }
121          /* Pointer to default value */
122          *def++ = 0;
123          strip_trailing_junk(def);
124          
125          if (strcmp(dircomm->msg, "job") == 0) {
126             if (strcmp(def, job_defs.job_name.toUtf8().data()) != 0) {
127                goto bail_out;
128             }
129             continue;
130          }
131          if (strcmp(dircomm->msg, "pool") == 0) {
132             job_defs.pool_name = def;
133             continue;
134          }
135          if (strcmp(dircomm->msg, "messages") == 0) {
136             job_defs.messages_name = def;
137             continue;
138          }
139          if (strcmp(dircomm->msg, "client") == 0) {
140             job_defs.client_name = def;
141             continue;
142          }
143          if (strcmp(dircomm->msg, "storage") == 0) {
144             job_defs.store_name = def;
145             continue;
146          }
147          if (strcmp(dircomm->msg, "where") == 0) {
148             job_defs.where = def;
149             continue;
150          }
151          if (strcmp(dircomm->msg, "level") == 0) {
152             job_defs.level = def;
153             continue;
154          }
155          if (strcmp(dircomm->msg, "type") == 0) {
156             job_defs.type = def;
157             continue;
158          }
159          if (strcmp(dircomm->msg, "fileset") == 0) {
160             job_defs.fileset_name = def;
161             continue;
162          }
163          if (strcmp(dircomm->msg, "catalog") == 0) {
164             job_defs.catalog_name = def;
165             continue;
166          }
167          if (strcmp(dircomm->msg, "enabled") == 0) {
168             job_defs.enabled = *def == '1' ? true : false;
169             continue;
170          }
171       }
172       rtn = true;
173       /* Fall through wanted */
174    bail_out:
175       return rtn;
176    }
177 };
178
179 #endif  /* TRAY_MONITOR_H */