]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/tray-monitor/tray-monitor.h
update configure
[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 #ifdef HAVE_WIN32
39 # ifndef _STAT_DEFINED
40 #  define _STAT_DEFINED 1 /* don't pull in MinGW struct stat from wchar.h */
41 # endif
42 #endif
43
44 #include <QString>
45 #include <QStringList>
46
47 #include "bacula.h"
48 #include "tray_conf.h"
49 #include "jcr.h"
50
51
52 struct job_defaults {
53    QString job_name;
54    QString pool_name;
55    QString messages_name;
56    QString client_name;
57    QString store_name;
58    QString where;
59    QString level;
60    QString type;
61    QString fileset_name;
62    QString catalog_name;
63    bool enabled;
64 };
65
66 struct resources {
67    QStringList job_list;
68    QStringList pool_list;
69    QStringList client_list;
70    QStringList storage_list;
71    QStringList levels;
72    QStringList fileset_list;
73    QStringList messages_list;
74 };
75
76 enum stateenum {
77    idle = 0,
78    running = 1,
79    warn = 2,
80    error = 3
81 };
82
83 class monitoritem;
84 int doconnect(monitoritem* item);
85 void get_list(monitoritem* item, const char *cmd, QStringList &lst);
86
87 class  monitoritem {
88 public:
89    rescode type; /* R_DIRECTOR, R_CLIENT or R_STORAGE */
90    void* resource; /* DIRRES*, CLIENT* or STORE* */
91    BSOCK *D_sock;
92    stateenum state;
93    stateenum oldstate;
94
95    char *get_name() {
96       return ((URES*)resource)->hdr.name;
97    }
98
99    void writecmd(const char* command) {
100       if (this->D_sock) {
101          this->D_sock->msglen = pm_strcpy(&this->D_sock->msg, command);
102          bnet_send(this->D_sock);
103       }
104    }
105
106    bool get_job_defaults(struct job_defaults &job_defs)
107    {
108       int stat;
109       char *def;
110       BSOCK *dircomm;
111       bool rtn = false;
112       QString scmd = QString(".defaults job=\"%1\"").arg(job_defs.job_name);
113
114       if (job_defs.job_name == "") {
115          return rtn;
116       }
117
118       if (!doconnect(this)) {
119          return rtn;
120       }
121       dircomm = this->D_sock;
122       dircomm->fsend("%s", scmd.toUtf8().data());
123
124       while ((stat = dircomm->recv()) > 0) {
125          def = strchr(dircomm->msg, '=');
126          if (!def) {
127             continue;
128          }
129          /* Pointer to default value */
130          *def++ = 0;
131          strip_trailing_junk(def);
132          
133          if (strcmp(dircomm->msg, "job") == 0) {
134             if (strcmp(def, job_defs.job_name.toUtf8().data()) != 0) {
135                goto bail_out;
136             }
137             continue;
138          }
139          if (strcmp(dircomm->msg, "pool") == 0) {
140             job_defs.pool_name = def;
141             continue;
142          }
143          if (strcmp(dircomm->msg, "messages") == 0) {
144             job_defs.messages_name = def;
145             continue;
146          }
147          if (strcmp(dircomm->msg, "client") == 0) {
148             job_defs.client_name = def;
149             continue;
150          }
151          if (strcmp(dircomm->msg, "storage") == 0) {
152             job_defs.store_name = def;
153             continue;
154          }
155          if (strcmp(dircomm->msg, "where") == 0) {
156             job_defs.where = def;
157             continue;
158          }
159          if (strcmp(dircomm->msg, "level") == 0) {
160             job_defs.level = def;
161             continue;
162          }
163          if (strcmp(dircomm->msg, "type") == 0) {
164             job_defs.type = def;
165             continue;
166          }
167          if (strcmp(dircomm->msg, "fileset") == 0) {
168             job_defs.fileset_name = def;
169             continue;
170          }
171          if (strcmp(dircomm->msg, "catalog") == 0) {
172             job_defs.catalog_name = def;
173             continue;
174          }
175          if (strcmp(dircomm->msg, "enabled") == 0) {
176             job_defs.enabled = *def == '1' ? true : false;
177             continue;
178          }
179       }
180       rtn = true;
181       /* Fall through wanted */
182    bail_out:
183       return rtn;
184    }
185 };
186
187 #endif  /* TRAY_MONITOR_H */