]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/wxbmainframe.h
- wxbMainFrame : Fixed 100% CPU usage in GTK : added buffering when receiving data...
[bacula/bacula] / bacula / src / wx-console / wxbmainframe.h
1 /*
2  *
3  *   Main frame header file
4  *
5  *    Nicolas Boichat, April 2004
6  *
7  */
8 /*
9    Copyright (C) 2004 Kern Sibbald and John Walker
10
11    This program is free software; you can redistribute it and/or
12    modify it under the terms of the GNU General Public License
13    as published by the Free Software Foundation; either version 2
14    of the License, or (at your option) any later version.
15
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19    GNU General Public License for more details.
20
21    You should have received a copy of the GNU General Public License
22    along with this program; if not, write to the Free Software
23    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifndef WXBMAINFRAME_H
27 #define WXBMAINFRAME_H
28
29 #include "wx/wxprec.h"
30
31 #ifdef __BORLANDC__
32    #pragma hdrstop
33 #endif
34
35 // for all others, include the necessary headers (this file is usually all you
36 // need because it includes almost all "standard" wxWindows headers)
37 #ifndef WX_PRECOMP
38    #include "wx/wx.h"
39 #endif
40
41 #include <wx/textctrl.h>
42 #include <wx/tokenzr.h>
43 #include <wx/notebook.h>
44
45 #include <wx/dynarray.h>
46
47 #include "console_thread.h"
48
49 #include "wxbutils.h"
50
51 WX_DEFINE_ARRAY(wxbDataParser*, wxbDataParsers);
52
53 // ----------------------------------------------------------------------------
54 // wxbPrintObject - Used by wxbThreadEvent to contain data sent by director
55 // ----------------------------------------------------------------------------
56
57 class wxbPrintObject: public wxObject {
58    public:
59       wxString str;
60       int status;
61       wxbPrintObject(wxString str, int status): wxObject() {
62          this->str = str;
63          this->status = status;
64       }
65
66       wxbPrintObject(const wxbPrintObject& pe) {
67          this->str = pe.str;
68          this->status = pe.status;
69       }
70 };
71
72 // ----------------------------------------------------------------------------
73 // wxbThreadEvent - Event used by wxbTHREAD_EVENT
74 // ----------------------------------------------------------------------------
75
76 class wxbThreadEvent: public wxEvent {
77    public:
78       wxbThreadEvent(int id);
79       ~wxbThreadEvent();
80       wxbThreadEvent(const wxbThreadEvent& te);
81       virtual wxEvent *Clone() const;
82       wxbPrintObject* GetEventPrintObject();
83       void SetEventPrintObject(wxbPrintObject* object);
84 };
85
86 // Define a new frame type: this is going to be our main frame
87 class wxbMainFrame : public wxFrame
88 {
89 public:
90    /* this class is a singleton */
91    static wxbMainFrame* CreateInstance(const wxString& title, const wxPoint& pos, const wxSize& size, long style = wxDEFAULT_FRAME_STYLE);
92    static wxbMainFrame* GetInstance();
93
94    /* event handlers (these functions should _not_ be virtual) */
95    void OnQuit(wxCommandEvent& event);
96    void OnAbout(wxCommandEvent& event);
97    void OnEnter(wxCommandEvent& event);
98    void OnPrint(wxbThreadEvent& event);
99
100    /* Enable and disable panels */
101    void EnablePanels();
102    void DisablePanels(void* except = NULL);
103    
104    void EnableConsole(bool enable = true);
105
106    /*
107     *  Prints data received from director to the console,
108     *  and forwards it to the panels
109     */
110    void Print(wxString str, int status);
111
112    /* Sends data to the director */
113    void Send(wxString str);
114
115    /*
116     *  Starts the thread interacting with the director
117     */
118    void StartConsoleThread();
119    
120    /* Register a new wxbDataParser */
121    void Register(wxbDataParser* dp);
122    
123    /* Unregister a wxbDataParser */
124    void Unregister(wxbDataParser* dp);
125
126    console_thread* ct; /* thread interacting with the director */
127
128 private:
129    /* private constructor, singleton */
130    wxbMainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style);
131    ~wxbMainFrame();
132
133    wxNotebook *notebook; /* main notebook */
134    wxTextCtrl *typeCtrl; /* wxTextCtrl for console user input */
135    wxTextCtrl *consoleCtrl; /* wxTextCtrl containing graphical console */
136
137    wxbPanel **panels; /* panels array, contained in the notebook */
138    wxbDataParsers parsers; /* Data parsers, which need to receive director informations */
139
140    wxbPromptParser* promptparser; /* prompt parser catching uncatched questions */
141
142    static wxbMainFrame *frame; /* this */
143    
144    bool lockedbyconsole; /* true if the panels have been locked by something typed in the console */
145    
146    wxString consoleBuffer;
147    
148    // any class wishing to process wxWindows events must use this macro
149    DECLARE_EVENT_TABLE()
150 };
151
152 #endif // WXBMAINFRAME_H
153