VirtualBox

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

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

export webservices to OSE

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

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