Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Palacios GUI Added
[palacios.git] / linux_usr / gui / palacios / newpalacios.h
1 #ifndef NEWPALACIOS_H
2 #define NEWPALACIOS_H
3
4 #include <QtGui>
5 #include <QApplication>
6 #include <QMainWindow>
7 #include <QWidget>
8 #include <QListWidget>
9 #include <QTableWidget>
10 #include <QVBoxLayout>
11 #include <QTextEdit>
12 #include <QFile>
13 #include <QTextStream>
14 #include <QList>
15 #include <QAction>
16 #include <QMenu>
17 #include <QMenuBar>
18 #include <QToolBar>
19 #include <QStatusBar>
20 #include <QProcess>
21 #include <QObject>
22 #include <QDomDocument>
23 #include <QDomNode>
24 #include <QDomNodeList>
25 #include <QDomElement>
26 #include <QDomText>
27 #include <QDomAttr>
28 #include <QDomNamedNodeMap>
29
30 #include "vm_creation_wizard.h"
31 #include "vm_console_widget.h"
32
33 class VmInfo;
34 class VmInfoWidget;
35 class VmXConsoleParent;
36 class VmVncWidget;
37 class LoadVmsThread;
38 class AddVmThread;
39 class DeleteVmThread;
40 class VmModeDialog;
41
42 class NewPalacios: public QMainWindow {
43 Q_OBJECT
44
45 public:
46         NewPalacios(QWidget *parent = 0);
47         ~NewPalacios();
48
49 protected:
50         void closeEvent(QCloseEvent*);
51
52 private slots:
53         void createVmInstance();
54         void aboutPalacios();
55         void exitApplication();
56         void startVm();
57         void stopVm();
58         void pauseVm();
59         void restartVm();
60         void activateVm();
61         void reloadVms();
62         // Item click listener for tree items
63         void vmItemClickListener(QTreeWidgetItem*, int);
64         void finishLoadingVmsFromFile();
65         void addNewVm();
66         void updateVmList();
67         void deleteVm(QString);
68         void handleVmDeletion();
69         // Context menu for VMs
70         void vmContextMenu(const QPoint &p);
71         void consoleWindowClosed(QString);
72         void vmTabClosed(int);
73         // This slot will be triggered when play/menu start
74         // button is pressed. This will launch a dialog which
75         // will allow the user to select operating mode
76         void selectVmMode();
77         // This slot will be triggered from the mode selection
78         // dialog when the user has finished selection. 
79         void getVmMode(int, QString);
80         void updateTelemetry(bool);
81         void updateTelemetryView();
82         
83 private slots:
84         // These are used for debugging QProcess commands
85         //void processStarted();
86         //void processExit(int, QProcess::ExitStatus);
87         //void processError(QProcess::ProcessError);
88
89 signals:
90         void vmLoadingComplete();
91
92 public:
93         void readExistingVmsFile();
94         // Check for Palacios setup
95         void checkPalacios();
96
97 private:
98         // Functions to setup different components of the window
99         void createCentralWidget();
100         void createActions();
101         void createMenus();
102         void createToolBars();
103         void createStatusBar();
104         void createDockWindows();
105         void createWizard();
106         void createEventHandler();
107         // Show error message boxes
108         void showMessage(QString err, bool error, bool warning=false);
109         // Update state of VM
110         void updateVmState(int);
111         // Create inactive VM
112         int createInactiveVm();
113         // Update DB
114         int updateDb(int);
115         
116 private:
117         // Main view of the application.
118         QTabWidget* mVmControlPanel;
119         VmInfoWidget* mVmInfoWidget;
120         // This is used to represent the classes of VM
121         QTreeWidget* mVmTreeView;
122         QTextEdit* mVmTelemetryView;
123
124         // Progress dialog to inform user about background thread processing
125         //QProgressDialog* mProgress;
126
127         // Runs Palacios in terminal mode
128         QList<VmXConsoleParent*> mRunningVms;
129         
130         bool mExitAppFromMenu;
131         // Used to identify VMs inside list
132         int mVmPos;
133         QString mVmName;
134         
135         // Action variables used to handle events such as menu clicks, button clicks etc.
136         QAction* mExitApp;
137         QAction* mVmNew;
138         QAction* mVmStop;
139         QAction* mVmPause;
140         QAction* mVmStart;
141         QAction* mVmActivate;
142         QAction* mReloadVms;
143         QAction* mAboutApp;
144
145         // Menu variables
146         QMenu* mFileMenu;
147         QMenu* mViewMenu;
148         QMenu* mVmMenu;
149         QMenu* mHelpMenu;
150
151         // Toolbar variables
152         QToolBar* mVmToolBar;
153         QToolBar* mVmCtrlToolBar;
154         
155         // This dialog will be used to give option
156         // to user to select from three modes of
157         // operation
158         VmModeDialog* mVmModeDialog;
159         int mVmMode;
160         QString mStreamName;
161         bool isHeaderClicked;
162
163         // Process to read kernel logs
164         QProcess* mLogProc;
165
166         // Wizard to help in vm creation
167         NewVmWizard* mVmWizard;
168
169         // List of created VMs. Each VM object contains information parsed from
170         // the config files provided as part of VM creation
171         QList<VmInfo*> mVmList;
172         //QList<VM*> mVmList;
173
174         /* We save the information about VMs in a text file. We store the name of the VM instance
175          * and the path of the configuration file used to create the VM. Every time we create/add/delete
176          * a VM instance, this file is edited. This is simplest way as of now to store this information.
177          * If in future we need more information to be stored we could use a database and Qt's
178          * model-view system */
179         
180         QThread* mThread;
181
182         // Thread to load existing VM intances
183         LoadVmsThread* mLoadVmsThread;
184         // Thread to add a new VM instance
185         AddVmThread* mAddVmThread;
186         // Thread to delete a VM instance
187         DeleteVmThread* mDeleteVmThread;
188         
189         // Telemetry process
190         QProcess* mTelemProc;
191 };
192
193 class VmModeDialog : public QWidget {
194 Q_OBJECT
195 public:
196     VmModeDialog(QWidget* parent = 0);
197
198 private slots:
199     void selectMode(bool);
200     void okButton();
201     void cancelButton();
202
203 signals:
204     // This signal will be caught in the main window
205     // and the mode will be set accordingly
206     void setMode(int, QString);
207
208 private:
209     void setupDialog();
210
211 private:
212     bool isV3Cons;
213     bool isV3Stream;
214     bool isV3Vnc;
215     int mode;
216     QGroupBox* v3_modes;
217     QRadioButton* v3_stream;
218     QRadioButton* v3_cons;
219     QRadioButton* v3_vnc;
220     QWidget* v3_stream_info;
221     QLineEdit* v3_stream_name;
222 };
223
224 // Class to hold information about a VM instance
225 class VmInfo {
226 public:
227         VmInfo() {
228         }
229         
230         ~VmInfo() {
231         }
232         
233         // Tells us about the state of the VM
234         enum {
235                 STOPPED, PAUSED, RUNNING
236         };
237
238         // Tells about the category of VM
239         enum {
240                 ACTIVE_INVENTORY, INACTIVE_INVENTORY, ACTIVE_NOT_INVENTORY
241         };
242         
243         // Return state of VM
244         int getState() {
245                 return mVmState;     
246         }
247         
248         // Ser state of VM
249         void setState(int state) {
250                 this->mVmState = state;
251         }
252
253         void setCategory(int cat) {
254                 this->mVmCategory = cat;
255         }
256
257         int getCategory() {
258                 return mVmCategory;
259         }
260
261         void setImageFile(QString img) {
262                 this->mVmImageFile = img;
263         }
264
265         QString getImageFile() {
266                 return mVmImageFile;
267         }
268         
269         QString getVmName() {
270                 return mVmName;
271         }
272
273         void setVmName(QString name) {
274                 this->mVmName = name;
275         }
276
277         QString getVmDevFile() {
278                 return mVmDevFile;
279         }
280
281         void setVmDevFile(QString name) {
282                 this->mVmDevFile = name;
283         }
284         
285         QString getVmConfigFile() {
286                 return this->mVmConfigFile;
287         }
288         
289         void setVmConfigFile(QString file) {
290                 this->mVmConfigFile = file;
291         }
292         
293 private:
294         int mVmState;
295         int mVmCategory;
296         QString mVmName;
297         QString mVmDevFile;
298         QString mVmImageFile;
299         QString mVmConfigFile;
300 };
301
302 class VmInfoWidget: public QWidget {
303 Q_OBJECT
304 public:
305         VmInfoWidget(QWidget* parent = 0);
306         ~VmInfoWidget();
307         
308 private:
309         void setInfoView();
310         void setupUi();
311
312 public:
313         void parseElement(const QDomElement&, QTreeWidgetItem*);
314         void parseAttribute(const QDomElement&, QTreeWidgetItem*);
315         void parseText(const QDomElement&, QTreeWidgetItem*);
316         void updateInfoView(VmInfo* vm);
317         void deleteVm();
318
319 private:
320         QTreeWidget* mVmInfoView;
321 };
322
323 class VmXConsoleParent: public QWidget {
324 Q_OBJECT
325 public:
326         VmXConsoleParent(QString name, QWidget* parent = 0);
327         void showWidget(int mode, QString devfile, QString streamName);
328         void showTelemetryInfo();
329         bool isRunning();
330         QString getVmName();
331         
332 signals:
333         void windowClosingWithId(QString name);
334         void windowClosing();
335
336 protected:
337         void closeEvent(QCloseEvent* event);
338
339 private:
340         bool mIsConsoleRunning;
341         QString mVmName;
342         VmConsoleWidget* mConsole;
343 };
344
345 class LoadVmsThread: public QObject {
346 Q_OBJECT
347 public:
348         static const int STATUS_OK = 0;
349         static const int ERROR_FILE_CANNOT_BE_OPENED = -1;
350
351         int getStatus();
352         QList<VmInfo*> getVmList();
353
354 signals:
355         void finished();
356
357 public slots:
358         void loadVms();
359 private:
360         int status;
361         QList<VmInfo*> list;
362 };
363
364 class AddVmThread: public QObject {
365 Q_OBJECT
366 public:
367         static const int STATUS_OK = 0;
368         static const int ERROR_V3CREATE_PATH = -1;
369         static const int ERROR_V3CREATE_IOCTL = -2;
370         static const int ERROR_V3CREATE_PROC = -3;
371         static const int ERROR_V3CREATE_DEV = -4;
372         static const int ERROR_V3CREATE_DB = -5;
373         
374         AddVmThread(QString name, QString conf, QString img);
375         int getStatus();
376         QString getName();
377         VmInfo* getNewVm();
378
379 signals:
380         void finished();
381
382 public slots:
383         void addVm();
384
385 private:
386         int status;
387         QString vmName;
388         QString vmDevFile;
389         QString vmConfigFile;
390         QString vmImageFile;
391         VmInfo* vm;
392 };
393
394 class DeleteVmThread: public QObject {
395 Q_OBJECT
396 public:
397         static const int STATUS_OK = 0;
398         static const int ERROR_V3FREE_PATH = -1;
399         static const int ERROR_V3FREE_IOCTL = -2;
400         static const int ERROR_V3FREE_DB = -3;
401         static const int ERROR_V3FREE_INVALID_ARGUMENT = -4;
402
403         DeleteVmThread(int, QString, QString);
404         int getStatus();
405
406 signals:
407         void finished();
408
409 public slots:
410         void deleteVm();
411         
412 private slots:
413         // These are used for debugging QProcess commands
414         //void processStarted();
415         //void processExit(int, QProcess::ExitStatus);
416         //void processError(QProcess::ProcessError);
417
418 private:
419         int status;
420         int vmCategory;
421         QString vmToDelete;
422         QString vmDevfile;
423 };
424
425 #endif // NEWPALACIOS_H