]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/wxbutils.h
kes wx-console crashes because of differences between Bacula and wxWidgets
[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-2006 Kern Sibbald
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    version 2 as amended with additional clauses defined in the
16    file LICENSE in the main source directory.
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    the file LICENSE for additional details.
22
23  */
24
25 #ifndef WXBUTILS_H
26 #define WXBUTILS_H
27
28 #include "wx/wxprec.h"
29
30 #ifndef WX_PRECOMP
31    #include "wx/wx.h"
32 #endif
33
34 class wxbTableParser;
35 class wxbDataParser;
36 class wxbDataTokenizer;
37 class wxbPromptParser;
38
39 /*
40  *  General functions
41  */
42 class wxbUtils
43 {
44    public:
45       /* Initialization */
46       static void Init();
47
48       /* Reset state */
49       static void Reset();
50
51       /* Parse a table in tableParser */
52       static wxbTableParser* CreateAndWaitForParser(wxString cmd);
53
54       /* Run a command, and waits until result is fully received,
55        * if keepresults is true, returns a valid pointer to a wxbDataTokenizer
56        * containing the data. */
57       static wxbDataTokenizer* WaitForEnd(wxString cmd, bool keepresults = false, bool linebyline = true);
58
59       /* Run a command, and waits until prompt result is fully received,
60        * if keepresults is true, returns a valid pointer to a wxbPromptParser
61        * containing the data. */
62       static wxbPromptParser* WaitForPrompt(wxString cmd, bool keepresults = false);
63       
64       /* Sleeps during milliseconds (wrapper for wxUsleep (2.4) or wxMilliSleep (2.6)) */
65       static void MilliSleep(unsigned long milliseconds);
66       
67       static wxString ConvertToPrintable(wxString& str);
68       
69    private:
70       static bool inited;
71 };
72
73 /*
74  *  abstract class that can receive director information.
75  */
76 class wxbDataParser
77 {
78    public:
79       /* Creates a new wxbDataParser, and register it in wxbMainFrame
80        * lineanalysis : indicate if date is to be analysed line by line (true)
81        * or packet by packet (false).
82        */
83       wxbDataParser(bool lineanalysis);
84
85       /* Destroy a wxbDataParser, and unregister it in wxbMainFrame */
86       virtual ~wxbDataParser();
87
88       /*
89        * Receives director information, forwarded by wxbMainFrame, and sends it
90        * line by line to the virtual function Analyse.
91        *
92        * Returns true if status == CS_PROMPT and the message has been parsed
93        * correctly.
94        */
95       bool Print(wxString str, int status);
96
97       /*
98        *   Receives data to analyse.
99        */
100       virtual bool Analyse(wxString str, int status) = 0;
101    private:
102       bool lineanalysis;
103       wxString buffer;
104 };
105
106 /*
107  *  abstract panel that can receive director information.
108  */
109 class wxbPanel : public wxPanel
110 {
111    public:
112       wxbPanel(wxWindow* parent) : wxPanel(parent) {}
113
114       /*
115        *   Tab title in the notebook.
116        */
117       virtual wxString GetTitle() = 0;
118
119       /*
120        *   Enable or disable this panel
121        */
122       virtual void EnablePanel(bool enable = true) = 0;
123 };
124
125 /*
126  *  Receives director information, and splits it by line.
127  *
128  * datatokenizer[0] retrieves first line
129  */
130 class wxbDataTokenizer: public wxbDataParser, public wxArrayString
131 {
132    public:
133       /* Creates a new wxbDataTokenizer */
134       wxbDataTokenizer(bool linebyline);
135
136       /* Destroy a wxbDataTokenizer */
137       virtual ~wxbDataTokenizer();
138
139       /*
140        *   Receives data to analyse.
141        */
142       virtual bool Analyse(wxString str, int status);
143
144       /* Returns true if the last signal received was an end signal,
145        * indicating that no more data is available */
146       bool hasFinished();
147
148    private:
149       bool finished;
150 };
151
152 /*
153  *  Receives director information, and check if the last messages are questions.
154  */
155 class wxbPromptParser: public wxbDataParser
156 {
157    public:
158       /* Creates a new wxbDataTokenizer */
159       wxbPromptParser();
160
161       /* Destroy a wxbDataTokenizer */
162       virtual ~wxbPromptParser();
163
164       /*
165        *   Receives data to analyse.
166        */
167       virtual bool Analyse(wxString str, int status);
168
169       /* Returns true if the last signal received was an prompt signal,
170        * or an end signal */
171       bool hasFinished();
172
173       /* Returns true if the last message received is a prompt message */
174       bool isPrompt();
175
176       /* Returns multiple choice question's introduction */
177       wxString getIntroString();
178
179       /* Returns question string */
180       wxString getQuestionString();
181
182       /* Returns a wxArrayString containing the indexed choices we have
183        * to answer the question, or NULL if this question is not a multiple
184        * choice one. */
185       wxArrayString* getChoices();
186
187       /* Returns true if the expected answer to the choice list is a number,
188        * false if it is a string (for example yes/mod/no). */
189       bool isNumericalChoice();
190
191    private:
192       bool finished;
193       bool prompt;
194       bool numerical;
195       wxString introStr;
196       wxArrayString* choices;
197       wxString questionStr;
198 };
199
200 #endif // WXBUTILS_H