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.


Extensions to HVM ROS userspace library corresponding to HVM enhancements
[palacios.git] / linux_usr / gui / palacios / vm_info_widget.cpp
1 #include "newpalacios.h"
2
3 VmInfoWidget::VmInfoWidget(QWidget* parent) :
4                 QWidget(parent) {
5         setInfoView();
6         setupUi();
7 }
8
9 VmInfoWidget::~VmInfoWidget() {
10         delete mVmInfoView;
11 }
12
13 void VmInfoWidget::setInfoView() {
14         // Create the main tree widget
15         mVmInfoView = new QTreeWidget();
16         mVmInfoView->setColumnCount(2);
17         QStringList headerLabels;
18         headerLabels << "Property" << "Value";
19         mVmInfoView->setHeaderLabels(headerLabels);
20 }
21
22 void VmInfoWidget::setupUi() {
23         QVBoxLayout* vmDetailsLayout = new QVBoxLayout(this);
24         vmDetailsLayout->addWidget(mVmInfoView);
25         setLayout(vmDetailsLayout);
26 }
27
28 void VmInfoWidget::parseAttribute(const QDomElement &element,
29                               QTreeWidgetItem* parent) {
30     QDomNamedNodeMap atts = element.attributes();
31
32     for (unsigned int i=0; i<atts.length(); i++) {
33         QTreeWidgetItem* item = new QTreeWidgetItem(parent);
34
35         item->setText(0, "[" + atts.item(i).nodeName() +"]");
36         item->setText(1, "[" + atts.item(i).nodeValue() +"]");
37     }
38 }
39
40 void VmInfoWidget::parseText(const QDomElement &element,
41                               QTreeWidgetItem* parent) {
42     QString value = element.text();
43     parent->setText(1, value);
44 }
45
46 void VmInfoWidget::parseElement(const QDomElement &element,
47                               QTreeWidgetItem* parent) {
48
49     QTreeWidgetItem* item = new QTreeWidgetItem(parent);
50
51     if (element.tagName().compare("memory") == 0) {
52         // Memory tag
53         item->setText(0, "memory");
54         parseAttribute(element, item);
55         parseText(element, item);
56
57     } else if (element.tagName().compare("telemetry") == 0) {
58         // Telemetry tag
59         item->setText(0, "telemetry");
60         parseText(element, item);
61
62     } else if (element.tagName().compare("extensions") == 0) {
63         // Extensions tag
64         item->setText(0, "extensions");
65         QDomNode child = element.firstChild();
66         while (!child.isNull()) {
67             if (!child.isElement()) {
68                 child = child.nextSibling();
69                 continue;
70             }
71
72             parseElement(child.toElement(), item);
73             child = child.nextSibling();
74         }
75
76     } else if (element.tagName().compare("extension") == 0) {
77       // Specific Extension
78         item->setText(0, "extension");
79         parseAttribute(element, item);
80         parseText(element, item);
81
82     } else if (element.tagName().compare("paging") == 0) {
83         // Paging tag
84         item->setText(0, "paging");
85         parseAttribute(element, item);
86         QDomNode child = element.firstChild();
87         while (!child.isNull()) {
88             if (!child.isElement()) {
89                 child = child.nextSibling();
90                 continue;
91             }
92
93             parseElement(child.toElement(), item);
94             child = child.nextSibling();
95         }
96
97     } else if (element.tagName().compare("strategy") == 0) {
98         item->setText(0, "strategy");
99         parseText(element, item);
100
101     } else if (element.tagName().compare("large_pages") == 0) {
102         item->setText(0, "large_pages");
103         parseText(element, item);
104
105     } else if (element.tagName().compare("schedule_hz") == 0) {
106         // Schedule Hz
107         item->setText(0, "schedule_hz");
108         parseText(element, item);
109
110     } else if (element.tagName().compare("cores") == 0) {
111         // Cores
112         item->setText(0, "cores");
113         parseAttribute(element, item);
114
115     } else if (element.tagName().compare("core") == 0) {
116         item->setText(0, "core");
117
118     } else if (element.tagName().compare("memmap") == 0) {
119         item->setText(0, "memmap");
120         QDomNode child = element.firstChild();
121         while (!child.isNull()) {
122
123             if (!child.isElement()) {
124                 child = child.nextSibling();
125                 continue;
126             }
127
128             parseElement(child.toElement(), item);
129             child = child.nextSibling();
130         }
131
132     } else if (element.tagName().compare("region") == 0) {
133         item->setText(0, "region");
134         QDomNode child = element.firstChild();
135         while (!child.isNull()) {
136             if (!child.isElement()) {
137                 child = child.nextSibling();
138                 continue;
139             }
140
141             parseElement(child.toElement(), item);
142             child = child.nextSibling();
143         }
144
145     } else if (element.tagName().compare("start") == 0) {
146         item->setText(0, "start");
147         parseText(element, item);
148
149     } else if (element.tagName().compare("end") == 0) {
150         item->setText(0, "end");
151         parseText(element, item);
152
153     } else if (element.tagName().compare("host_addr") == 0) {
154         item->setText(0, "host_addr");
155         parseText(element, item);
156
157     } else if (element.tagName().compare("files") == 0) {
158         item->setText(0, "files");
159         QDomNode child = element.firstChild();
160         while (!child.isNull()) {
161             if (!child.isElement()) {
162                 child = child.nextSibling();
163                 continue;
164             }
165
166             parseElement(child.toElement(), item);
167             child = child.nextSibling();
168         }
169
170     } else if (element.tagName().compare("file") == 0) {
171         item->setText(0, "file");
172         parseAttribute(element, item);
173
174     } else if (element.tagName().compare("devices") == 0) {
175         // Devices
176         item->setText(0, "devices");
177         QDomNode child = element.firstChild();
178         while (!child.isNull()) {
179             if (!child.isElement()) {
180                 child = child.nextSibling();
181                 continue;
182             }
183
184             parseElement(child.toElement(), item);
185             child = child.nextSibling();
186         }
187
188     } else if (element.tagName().compare("device") == 0) {
189         // Device
190         item->setText(0, "device");
191         parseAttribute(element, item);
192         QDomNode child = element.firstChild();
193         while (!child.isNull()) {
194             if (!child.isElement()) {
195                 child = child.nextSibling();
196                 continue;
197             }
198
199             parseElement(child.toElement(), item);
200             child = child.nextSibling();
201         }
202
203     } else if (element.tagName().compare("storage") == 0) {
204         item->setText(0, "storage");
205         parseText(element, item);
206
207     } else if (element.tagName().compare("apic") == 0) {
208         item->setText(0, "apic");
209         parseText(element, item);
210
211     } else if (element.tagName().compare("bus") == 0) {
212         // Bus tag, is seen in many device tags
213
214     } else if (element.tagName().compare("vendor_id") == 0) {
215         item->setText(0, "vendor_id");
216         parseText(element, item);
217
218     } else if (element.tagName().compare("device_id") == 0) {
219         item->setText(0, "device_id");
220         parseText(element, item);
221
222     } else if (element.tagName().compare("irq") == 0) {
223         item->setText(0, "irq");
224         parseText(element, item);
225
226     } else if (element.tagName().compare("controller") == 0) {
227         // Controller tag, is also seen in some device files
228         item->setText(0, "controller");
229         parseText(element, item);
230
231     } else if (element.tagName().compare("file") == 0) {
232         item->setText(0, "file");
233         parseText(element, item);
234
235     } else if (element.tagName().compare("frontend") == 0) {
236         item->setText(0, "frontend");
237         parseAttribute(element, item);
238         QDomNode child = element.firstChild();
239         while (!child.isNull()) {
240             if (!child.isElement()) {
241                 child = child.nextSibling();
242                 continue;
243             }
244
245             parseElement(child.toElement(), item);
246             child = child.nextSibling();
247         }
248
249     } else if (element.tagName().compare("model") == 0) {
250         item->setText(0, "model");
251         parseText(element, item);
252
253     } else if (element.tagName().compare("type") == 0) {
254         item->setText(0, "type");
255         parseText(element, item);
256
257     } else if (element.tagName().compare("bus_num") == 0) {
258         item->setText(0, "bus_num");
259         parseText(element, item);
260
261     } else if (element.tagName().compare("drive_num") == 0) {
262         item->setText(0, "drive_num");
263         parseText(element, item);
264
265     } else if (element.tagName().compare("path") == 0) {
266         item->setText(0, "path");
267         parseText(element, item);
268
269     } else if (element.tagName().compare("ip") == 0) {
270         item->setText(0, "ip");
271         parseText(element, item);
272
273     } else if (element.tagName().compare("port") == 0) {
274         item->setText(0, "port");
275         parseText(element, item);
276
277     } else if (element.tagName().compare("tag") == 0) {
278         item->setText(0, "tag");
279         parseText(element, item);
280
281     } else if (element.tagName().compare("size") == 0) {
282         item->setText(0, "size");
283         parseText(element, item);
284
285     } else if (element.tagName().compare("mac") == 0) {
286         item->setText(0, "mac");
287         parseText(element, item);
288
289     } else if (element.tagName().compare("name") == 0) {
290         item->setText(0, "name");
291         parseText(element, item);
292
293     } else if (element.tagName().compare("ports") == 0) {
294         item->setText(0, "ports");
295         QDomNode child = element.firstChild();
296         while (!child.isNull()) {
297             if (!child.isElement()) {
298                 child = child.nextSibling();
299                 continue;
300             }
301
302             parseElement(child.toElement(), item);
303             child = child.nextSibling();
304         }
305
306     } else if (element.tagName().compare("mode") == 0) {
307         item->setText(0, "mode");
308         parseText(element, item);
309
310     }
311 }
312
313 void VmInfoWidget::updateInfoView(VmInfo* vm) {
314         // Open config file
315         QFile file(vm->getVmConfigFile());
316         if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
317                 qDebug() << "File cannot be opened!";
318                 return;
319         }
320
321         // Setup DOM parser
322         QDomDocument doc("vm_config");
323         if (!doc.setContent(&file)) {
324                 qDebug() << "Error setting content";
325                 return;
326         }
327         
328         file.close();
329         
330         // Root element
331         QTreeWidgetItem* rootItem = new QTreeWidgetItem();
332         QDomElement root = doc.documentElement();
333         
334         rootItem->setText(0, root.tagName());
335         parseAttribute(root, rootItem);
336         mVmInfoView->takeTopLevelItem(0);
337         mVmInfoView->addTopLevelItem(rootItem);
338
339         // Elements
340         QDomNode n = root.firstChild();
341         while (!n.isNull()) {
342
343                 if (n.isElement()) {
344                         parseElement(n.toElement(), rootItem);
345                 }
346
347                 n = n.nextSibling();
348         }
349
350         mVmInfoView->expandAll();
351 }
352
353 void VmInfoWidget::deleteVm() {
354         QTreeWidgetItem* item = mVmInfoView->takeTopLevelItem(0);
355         delete item;
356 }