]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/wxbutils.h
This commit was manufactured by cvs2svn to create tag
[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    private:
68       static bool inited;
69 };
70
71 /*
72  *  abstract class that can receive director information.
73  */
74 class wxbDataParser
75 {
76    public:
77       /* Creates a new wxbDataParser, and register it in wxbMainFrame
78        * lineanalysis : indicate if date is to be analysed line by line (true)
79        * or packet by packet (false).
80        */
81       wxbDataParser(bool lineanalysis);
82
83       /* Destroy a wxbDataParser, and unregister it in wxbMainFrame */
84       virtual ~wxbDataParser();
85
86       /*
87        * Receives director information, forwarded by wxbMainFrame, and sends it
88        * line by line to the virtual function Analyse.
89        *
90        * Returns true if status == CS_PROMPT and the message has been parsed
91        * correctly.
92        */
93       bool Print(wxString str, int status);
94
95       /*
96        *   Receives data to analyse.
97        */
98       virtual bool Analyse(wxString str, int status) = 0;
99    private:
100       bool lineanalysis;
101       wxString buffer;
102 };
103
104 /*
105  *  abstract panel that can receive director information.
106  */
107 class wxbPanel : public wxPanel
108 {
109    public:
110       wxbPanel(wxWindow* parent) : wxPanel(parent) {}
111
112       /*
113        *   Tab title in the notebook.
114        */
115       virtual wxString GetTitle() = 0;
116
117       /*
118        *   Enable or disable this panel
119        */
120       virtual void EnablePanel(bool enable = true) = 0;
121 };
122
123 /*
124  *  Receives director information, and splits it by line.
125  *
126  * datatokenizer[0] retrieves first line
127  */
128 class wxbDataTokenizer: public wxbDataParser, public wxArrayString
129 {
130    public:
131       /* Creates a new wxbDataTokenizer */
132       wxbDataTokenizer(bool linebyline);
133
134       /* Destroy a wxbDataTokenizer */
135       virtual ~wxbDataTokenizer();
136
137       /*
138        *   Receives data to analyse.
139        */
140       virtual bool Analyse(wxString str, int status);
141
142       /* Returns true if the last signal received was an end signal,
143        * indicating that no more data is available */
144       bool hasFinished();
145
146    private:
147       bool finished;
148 };
149
150 /*
151  *  Receives director information, and check if the last messages are questions.
152  */
153 class wxbPromptParser: public wxbDataParser
154 {
155    public:
156       /* Creates a new wxbDataTokenizer */
157       wxbPromptParser();
158
159       /* Destroy a wxbDataTokenizer */
160       virtual ~wxbPromptParser();
161
162       /*
163        *   Receives data to analyse.
164        */
165       virtual bool Analyse(wxString str, int status);
166
167       /* Returns true if the last signal received was an prompt signal,
168        * or an end signal */
169       bool hasFinished();
170
171       /* Returns true if the last message received is a prompt message */
172       bool isPrompt();
173
174       /* Returns multiple choice question's introduction */
175       wxString getIntroString();
176
177       /* Returns question string */
178       wxString getQuestionString();
179
180       /* Returns a wxArrayString containing the indexed choices we have
181        * to answer the question, or NULL if this question is not a multiple
182        * choice one. */
183       wxArrayString* getChoices();
184
185       /* Returns true if the expected answer to the choice list is a number,
186        * false if it is a string (for example yes/mod/no). */
187       bool isNumericalChoice();
188
189    private:
190       bool finished;
191       bool prompt;
192       bool numerical;
193       wxString introStr;
194       wxArrayString* choices;
195       wxString questionStr;
196 };
197
198 #endif // WXBUTILS_H