X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fwx-console%2Fwxbutils.h;h=f7cb4ed60919b66542f5dd5201de64e687565b00;hb=b34b84f6913ee6d03d6c838e647c4aedf4bda3f2;hp=b7726a3fa413727df637dd18d16bec053d5063f4;hpb=63fca4b5573bd264d2aaed81d9847aa3445f4f25;p=bacula%2Fbacula diff --git a/bacula/src/wx-console/wxbutils.h b/bacula/src/wx-console/wxbutils.h index b7726a3fa4..f7cb4ed609 100644 --- a/bacula/src/wx-console/wxbutils.h +++ b/bacula/src/wx-console/wxbutils.h @@ -3,8 +3,9 @@ * wxbDataParser, class that receives and analyses data * wxbPanel, main frame's notebook panels * - * Nicolas Boichat, April 2004 + * Nicolas Boichat, April-July 2004 * + * Version $Id$ */ /* Copyright (C) 2004 Kern Sibbald and John Walker @@ -24,8 +25,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef WXBPANEL_H -#define WXBPANEL_H +#ifndef WXBUTILS_H +#define WXBUTILS_H #include "wx/wxprec.h" @@ -33,22 +34,76 @@ #include "wx/wx.h" #endif +class wxbTableParser; +class wxbDataParser; +class wxbDataTokenizer; +class wxbPromptParser; + +/* + * General functions + */ +class wxbUtils +{ + public: + /* Initialization */ + static void Init(); + + /* Reset state */ + static void Reset(); + + /* Parse a table in tableParser */ + static wxbTableParser* CreateAndWaitForParser(wxString cmd); + + /* Run a command, and waits until result is fully received, + * if keepresults is true, returns a valid pointer to a wxbDataTokenizer + * containing the data. */ + static wxbDataTokenizer* WaitForEnd(wxString cmd, bool keepresults = false, bool linebyline = true); + + /* Run a command, and waits until prompt result is fully received, + * if keepresults is true, returns a valid pointer to a wxbPromptParser + * containing the data. */ + static wxbPromptParser* WaitForPrompt(wxString cmd, bool keepresults = false); + + /* Sleeps during milliseconds (wrapper for wxUsleep (2.4) or wxMilliSleep (2.6)) */ + static void MilliSleep(unsigned long milliseconds); + + static wxString ConvertToPrintable(wxString& str); + + private: + static bool inited; +}; + /* * abstract class that can receive director information. */ class wxbDataParser { public: - /* Creates a new wxbDataParser, and register it in wxbMainFrame */ - wxbDataParser(); + /* Creates a new wxbDataParser, and register it in wxbMainFrame + * lineanalysis : indicate if date is to be analysed line by line (true) + * or packet by packet (false). + */ + wxbDataParser(bool lineanalysis); /* Destroy a wxbDataParser, and unregister it in wxbMainFrame */ virtual ~wxbDataParser(); /* - * Receives director information, forwarded by wxbMainFrame. + * Receives director information, forwarded by wxbMainFrame, and sends it + * line by line to the virtual function Analyse. + * + * Returns true if status == CS_PROMPT and the message has been parsed + * correctly. + */ + bool Print(wxString str, int status); + + /* + * Receives data to analyse. */ - virtual void Print(wxString str, int status) = 0; + virtual bool Analyse(wxString str, int status) = 0; + private: + bool lineanalysis; + wxString buffer; }; /* @@ -63,7 +118,7 @@ class wxbPanel : public wxPanel * Tab title in the notebook. */ virtual wxString GetTitle() = 0; - + /* * Enable or disable this panel */ @@ -72,31 +127,77 @@ class wxbPanel : public wxPanel /* * Receives director information, and splits it by line. - * + * * datatokenizer[0] retrieves first line */ class wxbDataTokenizer: public wxbDataParser, public wxArrayString { public: /* Creates a new wxbDataTokenizer */ - wxbDataTokenizer(); + wxbDataTokenizer(bool linebyline); /* Destroy a wxbDataTokenizer */ virtual ~wxbDataTokenizer(); /* - * Receives director information, forwarded by wxbMainFrame. + * Receives data to analyse. */ - virtual void Print(wxString str, int status); - - /* Returns true if the last signal received was an end signal, + virtual bool Analyse(wxString str, int status); + + /* Returns true if the last signal received was an end signal, * indicating that no more data is available */ bool hasFinished(); - + private: bool finished; - wxString buffer; }; -#endif // WXBPANEL_H +/* + * Receives director information, and check if the last messages are questions. + */ +class wxbPromptParser: public wxbDataParser +{ + public: + /* Creates a new wxbDataTokenizer */ + wxbPromptParser(); + + /* Destroy a wxbDataTokenizer */ + virtual ~wxbPromptParser(); + + /* + * Receives data to analyse. + */ + virtual bool Analyse(wxString str, int status); + + /* Returns true if the last signal received was an prompt signal, + * or an end signal */ + bool hasFinished(); + + /* Returns true if the last message received is a prompt message */ + bool isPrompt(); + + /* Returns multiple choice question's introduction */ + wxString getIntroString(); + + /* Returns question string */ + wxString getQuestionString(); + + /* Returns a wxArrayString containing the indexed choices we have + * to answer the question, or NULL if this question is not a multiple + * choice one. */ + wxArrayString* getChoices(); + + /* Returns true if the expected answer to the choice list is a number, + * false if it is a string (for example yes/mod/no). */ + bool isNumericalChoice(); + + private: + bool finished; + bool prompt; + bool numerical; + wxString introStr; + wxArrayString* choices; + wxString questionStr; +}; +#endif // WXBUTILS_H