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