VirtualBox

source: vbox/trunk/src/VBox/Main/webservice/webtest.cpp@ 17097

Last change on this file since 17097 was 16122, checked in by vboxsync, 16 years ago

fixed webservice copyright

  • Property filesplitter.c set to Makefile.kmk
  • Property svn:eol-style set to native
File size: 16.0 KB
Line 
1/*
2 * webtest.cpp:
3 * demo webservice client in C++. This mimics some of the
4 * functionality of VBoxManage for testing purposes.
5 *
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
17 * Clara, CA 95054 USA or visit http://www.sun.com if you need
18 * additional information or have any questions.
19 */
20
21// gSOAP headers (must come after vbox includes because it checks for conflicting defs)
22#include "soapStub.h"
23
24// include generated namespaces table
25#include "vboxwebsrv.nsmap"
26
27#include <iostream>
28#include <sstream>
29#include <string>
30
31
32/**
33 *
34 * @param argc
35 * @param argv[]
36 * @return
37 */
38int main(int argc, char* argv[])
39{
40 struct soap soap; // gSOAP runtime environment
41 soap_init(&soap); // initialize runtime environment (only once)
42
43 if (argc < 2)
44 {
45 std::cout <<
46 "webtest: VirtualBox webservice testcase.\n"
47 "Usage:\n"
48 " - IWebsessionManager:\n"
49 " - webtest logon <user> <pass>: IWebsessionManage::logon().\n"
50 " - webtest getsession <vboxref>: IWebsessionManage::getSessionObject().\n"
51 " - IVirtualBox:\n"
52 " - webtest version <vboxref>: IVirtualBox::getVersion().\n"
53 " - webtest gethost <vboxref>: IVirtualBox::getHost().\n"
54 " - webtest getmachines <vboxref>: IVirtualBox::getMachines().\n"
55 " - webtest createmachine <vboxref> <baseFolder> <name>: IVirtualBox::createMachine().\n"
56 " - webtest registermachine <vboxref> <machineref>: IVirtualBox::registerMachine().\n"
57 " - IHost:\n"
58 " - webtest getdvddrives <hostref>: IHost::getDVDDrives.\n"
59 " - IHostDVDDrive:\n"
60 " - webtest getdvdname <dvdref>: IHostDVDDrive::getname.\n"
61 " - IMachine:\n"
62 " - webtest getname <machineref>: IMachine::getName().\n"
63 " - webtest getid <machineref>: IMachine::getId().\n"
64 " - webtest getostype <machineref>: IMachine::getGuestOSType().\n"
65 " - webtest savesettings <machineref>: IMachine::saveSettings().\n"
66 " - All managed object references:\n"
67 " - webtest getif <ref>: report interface of object.\n"
68 " - webtest release <ref>: IUnknown::Release().\n";
69 exit(1);
70 }
71
72 const char *pcszArgEndpoint = "localhost:18083";
73
74 const char *pcszMode = argv[1];
75 int soaprc = 2;
76
77 if (!strcmp(pcszMode, "logon"))
78 {
79 if (argc < 4)
80 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
81 else
82 {
83 _vbox__IWebsessionManager_USCORElogon req;
84 req.username = argv[2];
85 req.password = argv[3];
86 std::cout << "logon: user = \"" << req.username << "\", pass = \"" << req.password << "\"\n";
87 _vbox__IWebsessionManager_USCORElogonResponse resp;
88
89 if (!(soaprc = soap_call___vbox__IWebsessionManager_USCORElogon(&soap,
90 pcszArgEndpoint,
91 NULL,
92 &req,
93 &resp)))
94 std::cout << "VirtualBox objref: \"" << resp.returnval << "\"\n";
95 }
96 }
97 else if (!strcmp(pcszMode, "getsession"))
98 {
99 if (argc < 3)
100 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
101 else
102 {
103 _vbox__IWebsessionManager_USCOREgetSessionObject req;
104 req.refIVirtualBox = argv[2];
105 _vbox__IWebsessionManager_USCOREgetSessionObjectResponse resp;
106
107 if (!(soaprc = soap_call___vbox__IWebsessionManager_USCOREgetSessionObject(&soap,
108 pcszArgEndpoint,
109 NULL,
110 &req,
111 &resp)))
112 std::cout << "session: \"" << resp.returnval << "\"\n";
113 }
114 }
115 else if (!strcmp(pcszMode, "version"))
116 {
117 if (argc < 3)
118 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
119 else
120 {
121 _vbox__IVirtualBox_USCOREgetVersion req;
122 req._USCOREthis = argv[2];
123 _vbox__IVirtualBox_USCOREgetVersionResponse resp;
124
125 if (!(soaprc = soap_call___vbox__IVirtualBox_USCOREgetVersion(&soap,
126 pcszArgEndpoint,
127 NULL,
128 &req,
129 &resp)))
130 std::cout << "version: \"" << resp.returnval << "\"\n";
131 }
132 }
133 else if (!strcmp(pcszMode, "gethost"))
134 {
135 if (argc < 3)
136 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
137 else
138 {
139 _vbox__IVirtualBox_USCOREgetHost req;
140 req._USCOREthis = argv[2];
141 _vbox__IVirtualBox_USCOREgetHostResponse resp;
142
143 if (!(soaprc = soap_call___vbox__IVirtualBox_USCOREgetHost(&soap,
144 pcszArgEndpoint,
145 NULL,
146 &req,
147 &resp)))
148 {
149 std::cout << "Host objref " << resp.returnval << "\n";
150 }
151 }
152 }
153 else if (!strcmp(pcszMode, "getmachines"))
154 {
155 if (argc < 3)
156 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
157 else
158 {
159 _vbox__IVirtualBox_USCOREgetMachines2 req;
160 req._USCOREthis = argv[2];
161 _vbox__IVirtualBox_USCOREgetMachines2Response resp;
162
163 if (!(soaprc = soap_call___vbox__IVirtualBox_USCOREgetMachines2(&soap,
164 pcszArgEndpoint,
165 NULL,
166 &req,
167 &resp)))
168 {
169 unsigned int i,
170 c = resp.returnval.size();
171 for (i = 0;
172 i < c;
173 ++i)
174 {
175 std::cout << "Machine " << i << ": objref " << resp.returnval[i] << "\n";
176 }
177 }
178 }
179 }
180 else if (!strcmp(pcszMode, "createmachine"))
181 {
182 if (argc < 5)
183 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
184 else
185 {
186 _vbox__IVirtualBox_USCOREcreateMachine req;
187 req._USCOREthis = argv[2];
188 req.baseFolder = argv[3];
189 req.name = argv[4];
190 std::cout << "createmachine: baseFolder = \"" << req.baseFolder << "\", name = \"" << req.name << "\"\n";
191 _vbox__IVirtualBox_USCOREcreateMachineResponse resp;
192
193 if (!(soaprc = soap_call___vbox__IVirtualBox_USCOREcreateMachine(&soap,
194 pcszArgEndpoint,
195 NULL,
196 &req,
197 &resp)))
198 std::cout << "Machine created: managed object reference ID is " << resp.returnval << "\n";
199 }
200 }
201 else if (!strcmp(pcszMode, "registermachine"))
202 {
203 if (argc < 4)
204 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
205 else
206 {
207 _vbox__IVirtualBox_USCOREregisterMachine req;
208 req._USCOREthis = argv[2];
209 req.machine = argv[3];
210 _vbox__IVirtualBox_USCOREregisterMachineResponse resp;
211 if (!(soaprc = soap_call___vbox__IVirtualBox_USCOREregisterMachine(&soap,
212 pcszArgEndpoint,
213 NULL,
214 &req,
215 &resp)))
216 std::cout << "Machine registered.\n";
217 }
218 }
219 else if (!strcmp(pcszMode, "getdvddrives"))
220 {
221 if (argc < 3)
222 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
223 else
224 {
225 _vbox__IHost_USCOREgetDVDDrives req;
226 req._USCOREthis = argv[2];
227 _vbox__IHost_USCOREgetDVDDrivesResponse resp;
228 if (!(soaprc = soap_call___vbox__IHost_USCOREgetDVDDrives(&soap,
229 pcszArgEndpoint,
230 NULL,
231 &req,
232 &resp)))
233 {
234 unsigned int i,
235 c = resp.returnval->array.size();
236 for(i = 0;
237 i < c;
238 ++i)
239 {
240 std::cout << "DVD drive " << i << ": objref " << resp.returnval->array[i] << "\n";
241 }
242 }
243 }
244 }
245 else if (!strcmp(pcszMode, "getdvdname"))
246 {
247 if (argc < 3)
248 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
249 else
250 {
251 _vbox__IHostDVDDrive_USCOREgetName req;
252 req._USCOREthis = argv[2];
253 _vbox__IHostDVDDrive_USCOREgetNameResponse resp;
254 if (!(soaprc = soap_call___vbox__IHostDVDDrive_USCOREgetName(&soap,
255 pcszArgEndpoint,
256 NULL,
257 &req,
258 &resp)))
259 std::cout << "Name is: \"" << resp.returnval << "\"\n";
260 }
261 }
262 else if (!strcmp(pcszMode, "getname"))
263 {
264 if (argc < 3)
265 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
266 else
267 {
268 _vbox__IMachine_USCOREgetName req;
269 req._USCOREthis = argv[2];
270 _vbox__IMachine_USCOREgetNameResponse resp;
271 if (!(soaprc = soap_call___vbox__IMachine_USCOREgetName(&soap,
272 pcszArgEndpoint,
273 NULL,
274 &req,
275 &resp)))
276 printf("Name is: %s\n", resp.returnval.c_str());
277 }
278 }
279 else if (!strcmp(pcszMode, "getid"))
280 {
281 if (argc < 3)
282 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
283 else
284 {
285 _vbox__IMachine_USCOREgetId req;
286 req._USCOREthis = argv[2];
287 _vbox__IMachine_USCOREgetIdResponse resp;
288 if (!(soaprc = soap_call___vbox__IMachine_USCOREgetId(&soap,
289 pcszArgEndpoint,
290 NULL,
291 &req,
292 &resp)))
293 std::cout << "UUID is: " << resp.returnval << "\n";;
294 }
295 }
296 else if (!strcmp(pcszMode, "getostypeid"))
297 {
298 if (argc < 3)
299 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
300 else
301 {
302 _vbox__IMachine_USCOREgetOSTypeId req;
303 req._USCOREthis = argv[2];
304 _vbox__IMachine_USCOREgetOSTypeIdResponse resp;
305 if (!(soaprc = soap_call___vbox__IMachine_USCOREgetOSTypeId(&soap,
306 pcszArgEndpoint,
307 NULL,
308 &req,
309 &resp)))
310 std::cout << "Guest OS type is: " << resp.returnval << "\n";
311 }
312 }
313 else if (!strcmp(pcszMode, "savesettings"))
314 {
315 if (argc < 3)
316 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
317 else
318 {
319 _vbox__IMachine_USCOREsaveSettings req;
320 req._USCOREthis = argv[2];
321 _vbox__IMachine_USCOREsaveSettingsResponse resp;
322 if (!(soaprc = soap_call___vbox__IMachine_USCOREsaveSettings(&soap,
323 pcszArgEndpoint,
324 NULL,
325 &req,
326 &resp)))
327 std::cout << "Settings saved\n";
328 }
329 }
330 else if (!strcmp(pcszMode, "release"))
331 {
332 if (argc < 3)
333 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
334 else
335 {
336 _vbox__IManagedObjectRef_USCORErelease req;
337 req._USCOREthis = argv[2];
338 _vbox__IManagedObjectRef_USCOREreleaseResponse resp;
339 if (!(soaprc = soap_call___vbox__IManagedObjectRef_USCORErelease(&soap,
340 pcszArgEndpoint,
341 NULL,
342 &req,
343 &resp)))
344 std::cout << "Managed object reference " << req._USCOREthis << " released.\n";
345 }
346 }
347 else
348 std::cout << "Unknown mode parameter \"" << pcszMode << "\".\n";
349
350 if (soaprc)
351 {
352 if ( (soap.fault)
353 && (soap.fault->detail)
354 )
355 {
356 if (soap.fault->detail->vbox__InvalidObjectFault)
357 {
358 std::cout << "Bad object ID: " << soap.fault->detail->vbox__InvalidObjectFault->badObjectID << "\n";
359 }
360 if (soap.fault->detail->vbox__RuntimeFault)
361 {
362 std::cout << "Result code: 0x" << std::hex << soap.fault->detail->vbox__RuntimeFault->resultCode << "\n";
363 std::cout << "Text: " << std::hex << soap.fault->detail->vbox__RuntimeFault->text << "\n";
364 std::cout << "Component: " << std::hex << soap.fault->detail->vbox__RuntimeFault->component << "\n";
365 std::cout << "Interface ID: " << std::hex << soap.fault->detail->vbox__RuntimeFault->interfaceID << "\n";
366 }
367 }
368 else
369 {
370 std::cerr << "Invalid fault data, fault message:\n";
371 soap_print_fault(&soap, stderr); // display the SOAP fault message on the stderr stream
372 }
373 }
374
375 soap_destroy(&soap); // delete deserialized class instances (for C++ only)
376 soap_end(&soap); // remove deserialized data and clean up
377 soap_done(&soap); // detach the gSOAP environment
378
379 return soaprc;
380}
381
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette