]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/wxbutils.h
Correct a minor build problem with wx-console.
[bacula/bacula] / bacula / src / wx-console / wxbutils.h
1 /*
2  *
3  *   wxbDataParser, class that receives and analyses data
4  *   wxbPanel, main frame's notebook panels
5  *
6  *    Nicolas Boichat, April-July 2004
7  *
8  *   Version $Id$
9  */
10 /*
11    Copyright (C) 2004 Kern Sibbald and John Walker
12
13    This program is free software; you can redistribute it and/or
14    modify it under the terms of the GNU General Public License
15    as published by the Free Software Foundation; either version 2
16    of the License, or (at your option) any later version.
17
18    This program is distributed in the hope that it will be useful,
19    but WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21    GNU General Public License for more details.
22
23    You should have received a copy of the GNU General Public License
24    along with this program; if not, write to the Free Software
25    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifndef WXBUTILS_H
29 #define WXBUTILS_H
30
31 #include "wx/wxprec.h"
32
33 #ifndef WX_PRECOMP
34    #include "wx/wx.h"
35 #endif
36
37 class wxbTableParser;
38 class wxbDataParser;
39 class wxbDataTokenizer;
40 class wxbPromptParser;
41
42 /*
43  *  General functions
44  */
45 class wxbUtils
46 {
47    public:
48       /* Initialization */
49       static void Init();
50
51       /* Reset state */
52       static void Reset();
53
54       /* Parse a table in tableParser */
55       static wxbTableParser* CreateAndWaitForParser(wxString cmd);
56
57       /* Run a command, and waits until result is fully received,
58        * if keepresults is true, returns a valid pointer to a wxbDataTokenizer
59        * containing the data. */
60       static wxbDataTokenizer* WaitForEnd(wxString cmd, bool keepresults = false, bool linebyline = true);
61
62       /* Run a command, and waits until prompt result is fully received,
63        * if keepresults is true, returns a valid pointer to a wxbPromptParser
64        * containing the data. */
65       static wxbPromptParser* WaitForPrompt(wxString cmd, bool keepresults = false);
66       
67       /* Sleeps during milliseconds (wrapper for wxUsleep (2.4) or wxMilliSleep (2.6)) */
68       static void MilliSleep(unsigned long milliseconds);
69       
70       static wxString ConvertToPrintable(wxString& str);
71       
72    private:
73       static bool inited;
74 };
75
76 /*
77  *  abstract class that can receive director information.
78  */
79 class wxbDataParser
80 {
81    public:
82       /* Creates a new wxbDataParser, and register it in wxbMainFrame
83        * lineanalysis : indicate if date is to be analysed line by line (true)
84        * or packet by packet (false).
85        */
86       wxbDataParser(bool lineanalysis);
87
88       /* Destroy a wxbDataParser, and unregister it in wxbMainFrame */
89       virtual ~wxbDataParser();
90
91       /*
92        * Receives director information, forwarded by wxbMainFrame, and sends it
93        * line by line to the virtual function Analyse.
94        *
95        * Returns true if status == CS_PROMPT and the message has been parsed
96        * correctly.
97        */
98       bool Print(wxString str, int status);
99
100       /*
101        *   Receives data to analyse.
102        */
103       virtual bool Analyse(wxString str, int status) = 0;
104    private:
105       bool lineanalysis;
106       wxString buffer;
107 };
108
109 /*
110  *  abstract panel that can receive director information.
111  */
112 class wxbPanel : public wxPanel
113 {
114    public:
115       wxbPanel(wxWindow* parent) : wxPanel(parent) {}
116
117       /*
118        *   Tab title in the notebook.
119        */
120       virtual wxString GetTitle() = 0;
121
122       /*
123        *   Enable or disable this panel
124        */
125       virtual void EnablePanel(bool enable = true) = 0;
126 };
127
128 /*
129  *  Receives director information, and splits it by line.
130  *
131  * datatokenizer[0] retrieves first line
132  */
133 class wxbDataTokenizer: public wxbDataParser, public wxArrayString
134 {
135    public:
136       /* Creates a new wxbDataTokenizer */
137       wxbDataTokenizer(bool linebyline);
138
139       /* Destroy a wxbDataTokenizer */
140       virtual ~wxbDataTokenizer();
141
142       /*
143        *   Receives data to analyse.
144        */
145       virtual bool Analyse(wxString str, int status);
146
147       /* Returns true if the last signal received was an end signal,
148        * indicating that no more data is available */
149       bool hasFinished();
150
151    private:
152       bool finished;
153 };
154
155 /*
156  *  Receives director information, and check if the last messages are questions.
157  */
158 class wxbPromptParser: public wxbDataParser
159 {
160    public:
161       /* Creates a new wxbDataTokenizer */
162       wxbPromptParser();
163
164       /* Destroy a wxbDataTokenizer */
165       virtual ~wxbPromptParser();
166
167       /*
168        *   Receives data to analyse.
169        */
170       virtual bool Analyse(wxString str, int status);
171
172       /* Returns true if the last signal received was an prompt signal,
173        * or an end signal */
174       bool hasFinished();
175
176       /* Returns true if the last message received is a prompt message */
177       bool isPrompt();
178
179       /* Returns multiple choice question's introduction */
180       wxString getIntroString();
181
182       /* Returns question string */
183       wxString getQuestionString();
184
185       /* Returns a wxArrayString containing the indexed choices we have
186        * to answer the question, or NULL if this question is not a multiple
187        * choice one. */
188       wxArrayString* getChoices();
189
190       /* Returns true if the expected answer to the choice list is a number,
191        * false if it is a string (for example yes/mod/no). */
192       bool isNumericalChoice();
193
194    private:
195       bool finished;
196       bool prompt;
197       bool numerical;
198       wxString introStr;
199       wxArrayString* choices;
200       wxString questionStr;
201 };
202
203 #endif // WXBUTILS_H