[69382] | 1 | /* $Id: webtest.cpp 98297 2023-01-25 01:59:25Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[16120] | 3 | * webtest.cpp:
|
---|
| 4 | * demo webservice client in C++. This mimics some of the
|
---|
| 5 | * functionality of VBoxManage for testing purposes.
|
---|
[69382] | 6 | */
|
---|
| 7 | /*
|
---|
[98103] | 8 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[16120] | 9 | *
|
---|
[96407] | 10 | * This file is part of VirtualBox base platform packages, as
|
---|
| 11 | * available from https://www.virtualbox.org.
|
---|
| 12 | *
|
---|
| 13 | * This program is free software; you can redistribute it and/or
|
---|
| 14 | * modify it under the terms of the GNU General Public License
|
---|
| 15 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 16 | * License.
|
---|
| 17 | *
|
---|
| 18 | * This program is distributed in the hope that it will be useful, but
|
---|
| 19 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 21 | * General Public License for more details.
|
---|
| 22 | *
|
---|
| 23 | * You should have received a copy of the GNU General Public License
|
---|
| 24 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 25 | *
|
---|
| 26 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[16120] | 27 | */
|
---|
| 28 |
|
---|
| 29 | // gSOAP headers (must come after vbox includes because it checks for conflicting defs)
|
---|
| 30 | #include "soapStub.h"
|
---|
| 31 |
|
---|
| 32 | // include generated namespaces table
|
---|
| 33 | #include "vboxwebsrv.nsmap"
|
---|
| 34 |
|
---|
| 35 | #include <iostream>
|
---|
[83794] | 36 | #include <iprt/sanitized/sstream>
|
---|
| 37 | #include <iprt/sanitized/string>
|
---|
[16120] | 38 |
|
---|
[75793] | 39 | #include <iprt/initterm.h>
|
---|
| 40 | #include <iprt/message.h>
|
---|
[76474] | 41 | #include <iprt/errcore.h>
|
---|
[16120] | 42 |
|
---|
[75793] | 43 |
|
---|
[40130] | 44 | static void usage(int exitcode)
|
---|
| 45 | {
|
---|
| 46 | std::cout <<
|
---|
| 47 | "webtest: VirtualBox webservice testcase.\n"
|
---|
| 48 | "\nUsage: webtest [options] [command]...\n"
|
---|
| 49 | "\nSupported options:\n"
|
---|
| 50 | " -h: print this help message and exit.\n"
|
---|
| 51 | " -c URL: specify the webservice server URL (default http://localhost:18083/).\n"
|
---|
| 52 | "\nSupported commands:\n"
|
---|
| 53 | " - IWebsessionManager:\n"
|
---|
| 54 | " - webtest logon <user> <pass>: IWebsessionManager::logon().\n"
|
---|
| 55 | " - webtest getsession <vboxref>: IWebsessionManager::getSessionObject().\n"
|
---|
| 56 | " - webtest logoff <vboxref>: IWebsessionManager::logoff().\n"
|
---|
| 57 | " - IVirtualBox:\n"
|
---|
| 58 | " - webtest version <vboxref>: IVirtualBox::getVersion().\n"
|
---|
| 59 | " - webtest gethost <vboxref>: IVirtualBox::getHost().\n"
|
---|
| 60 | " - webtest getpc <vboxref>: IVirtualBox::getPerformanceCollector().\n"
|
---|
| 61 | " - webtest getmachines <vboxref>: IVirtualBox::getMachines().\n"
|
---|
| 62 | " - webtest createmachine <vboxref> <settingsPath> <name>: IVirtualBox::createMachine().\n"
|
---|
| 63 | " - webtest registermachine <vboxref> <machineref>: IVirtualBox::registerMachine().\n"
|
---|
| 64 | " - IHost:\n"
|
---|
| 65 | " - webtest getdvddrives <hostref>: IHost::getDVDDrives.\n"
|
---|
| 66 | " - IHostDVDDrive:\n"
|
---|
| 67 | " - webtest getdvdname <dvdref>: IHostDVDDrive::getname.\n"
|
---|
| 68 | " - IMachine:\n"
|
---|
| 69 | " - webtest getname <machineref>: IMachine::getName().\n"
|
---|
| 70 | " - webtest getid <machineref>: IMachine::getId().\n"
|
---|
| 71 | " - webtest getostype <machineref>: IMachine::getGuestOSType().\n"
|
---|
| 72 | " - webtest savesettings <machineref>: IMachine::saveSettings().\n"
|
---|
| 73 | " - IPerformanceCollector:\n"
|
---|
| 74 | " - webtest setupmetrics <pcref>: IPerformanceCollector::setupMetrics()\n"
|
---|
| 75 | " - webtest querymetricsdata <pcref>: IPerformanceCollector::QueryMetricsData()\n"
|
---|
[46478] | 76 | " - IVirtualBoxErrorInfo:\n"
|
---|
| 77 | " - webtest errorinfo <eiref>: various IVirtualBoxErrorInfo getters\n"
|
---|
[40130] | 78 | " - All managed object references:\n"
|
---|
| 79 | " - webtest getif <ref>: report interface of object.\n"
|
---|
| 80 | " - webtest release <ref>: IUnknown::Release().\n";
|
---|
| 81 | exit(exitcode);
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[16120] | 84 | /**
|
---|
| 85 | *
|
---|
| 86 | * @param argc
|
---|
| 87 | * @param argv[]
|
---|
| 88 | * @return
|
---|
| 89 | */
|
---|
| 90 | int main(int argc, char* argv[])
|
---|
| 91 | {
|
---|
[40130] | 92 | bool fSSL = false;
|
---|
| 93 | const char *pcszArgEndpoint = "http://localhost:18083/";
|
---|
| 94 |
|
---|
[75793] | 95 | /* SSL callbacks drag in IPRT sem/thread use, so make sure it is ready. */
|
---|
[98297] | 96 | int vrc = RTR3InitExe(argc, &argv, 0);
|
---|
| 97 | if (RT_FAILURE(vrc))
|
---|
| 98 | return RTMsgInitFailure(vrc);
|
---|
[75793] | 99 |
|
---|
[40130] | 100 | int ap;
|
---|
[46478] | 101 | for (ap = 1; ap < argc; ap++)
|
---|
[40130] | 102 | {
|
---|
| 103 | if (argv[ap][0] == '-')
|
---|
| 104 | {
|
---|
| 105 | if (!strcmp(argv[ap], "-h"))
|
---|
| 106 | usage(0);
|
---|
| 107 | else if (!strcmp(argv[ap], "-c"))
|
---|
| 108 | {
|
---|
| 109 | ap++;
|
---|
[46478] | 110 | if (ap >= argc)
|
---|
[40130] | 111 | usage(1);
|
---|
| 112 | pcszArgEndpoint = argv[ap];
|
---|
| 113 | fSSL = !strncmp(pcszArgEndpoint, "https://", 8);
|
---|
| 114 | }
|
---|
| 115 | else
|
---|
| 116 | usage(1);
|
---|
| 117 | }
|
---|
| 118 | else
|
---|
| 119 | break;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | if (argc < 1 + ap)
|
---|
| 123 | usage(1);
|
---|
| 124 |
|
---|
| 125 | #ifdef WITH_OPENSSL
|
---|
| 126 | if (fSSL)
|
---|
| 127 | soap_ssl_init();
|
---|
| 128 | #endif /* WITH_OPENSSL */
|
---|
| 129 |
|
---|
[16120] | 130 | struct soap soap; // gSOAP runtime environment
|
---|
| 131 | soap_init(&soap); // initialize runtime environment (only once)
|
---|
[40130] | 132 | #ifdef WITH_OPENSSL
|
---|
| 133 | // Use SOAP_SSL_NO_AUTHENTICATION here to accept broken server configs.
|
---|
| 134 | // In a real world setup please use at least SOAP_SSL_DEFAULT and provide
|
---|
| 135 | // the necessary CA certificate for validating the server's certificate.
|
---|
[53186] | 136 | if (fSSL && soap_ssl_client_context(&soap, SOAP_SSL_NO_AUTHENTICATION | SOAP_TLSv1,
|
---|
[40130] | 137 | NULL /*clientkey*/, NULL /*password*/,
|
---|
| 138 | NULL /*cacert*/, NULL /*capath*/,
|
---|
| 139 | NULL /*randfile*/))
|
---|
[16120] | 140 | {
|
---|
[40130] | 141 | soap_print_fault(&soap, stderr);
|
---|
[16120] | 142 | exit(1);
|
---|
| 143 | }
|
---|
[40130] | 144 | #endif /* WITH_OPENSSL */
|
---|
[16120] | 145 |
|
---|
[40130] | 146 | const char *pcszMode = argv[ap];
|
---|
| 147 | int soaprc = SOAP_SVR_FAULT;
|
---|
[16120] | 148 |
|
---|
| 149 | if (!strcmp(pcszMode, "logon"))
|
---|
| 150 | {
|
---|
[40130] | 151 | if (argc < 3 + ap)
|
---|
[16120] | 152 | std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
|
---|
| 153 | else
|
---|
| 154 | {
|
---|
| 155 | _vbox__IWebsessionManager_USCORElogon req;
|
---|
[40130] | 156 | req.username = argv[ap + 1];
|
---|
| 157 | req.password = argv[ap + 2];
|
---|
[16120] | 158 | _vbox__IWebsessionManager_USCORElogonResponse resp;
|
---|
| 159 |
|
---|
| 160 | if (!(soaprc = soap_call___vbox__IWebsessionManager_USCORElogon(&soap,
|
---|
| 161 | pcszArgEndpoint,
|
---|
| 162 | NULL,
|
---|
| 163 | &req,
|
---|
| 164 | &resp)))
|
---|
| 165 | std::cout << "VirtualBox objref: \"" << resp.returnval << "\"\n";
|
---|
| 166 | }
|
---|
| 167 | }
|
---|
| 168 | else if (!strcmp(pcszMode, "getsession"))
|
---|
| 169 | {
|
---|
[40130] | 170 | if (argc < 2 + ap)
|
---|
[16120] | 171 | std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
|
---|
| 172 | else
|
---|
| 173 | {
|
---|
| 174 | _vbox__IWebsessionManager_USCOREgetSessionObject req;
|
---|
[40130] | 175 | req.refIVirtualBox = argv[ap + 1];
|
---|
[16120] | 176 | _vbox__IWebsessionManager_USCOREgetSessionObjectResponse resp;
|
---|
| 177 |
|
---|
| 178 | if (!(soaprc = soap_call___vbox__IWebsessionManager_USCOREgetSessionObject(&soap,
|
---|
| 179 | pcszArgEndpoint,
|
---|
| 180 | NULL,
|
---|
| 181 | &req,
|
---|
| 182 | &resp)))
|
---|
| 183 | std::cout << "session: \"" << resp.returnval << "\"\n";
|
---|
| 184 | }
|
---|
| 185 | }
|
---|
[22666] | 186 | else if (!strcmp(pcszMode, "logoff"))
|
---|
| 187 | {
|
---|
[40130] | 188 | if (argc < 2 + ap)
|
---|
[22666] | 189 | std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
|
---|
| 190 | else
|
---|
| 191 | {
|
---|
| 192 | _vbox__IWebsessionManager_USCORElogoff req;
|
---|
[40130] | 193 | req.refIVirtualBox = argv[ap + 1];
|
---|
[22666] | 194 | _vbox__IWebsessionManager_USCORElogoffResponse resp;
|
---|
| 195 |
|
---|
| 196 | if (!(soaprc = soap_call___vbox__IWebsessionManager_USCORElogoff(&soap,
|
---|
| 197 | pcszArgEndpoint,
|
---|
| 198 | NULL,
|
---|
| 199 | &req,
|
---|
| 200 | &resp)))
|
---|
[26023] | 201 | {
|
---|
[22666] | 202 | ;
|
---|
[26023] | 203 | }
|
---|
[22666] | 204 | }
|
---|
| 205 | }
|
---|
[16120] | 206 | else if (!strcmp(pcszMode, "version"))
|
---|
| 207 | {
|
---|
[40130] | 208 | if (argc < 2 + ap)
|
---|
[16120] | 209 | std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
|
---|
| 210 | else
|
---|
| 211 | {
|
---|
| 212 | _vbox__IVirtualBox_USCOREgetVersion req;
|
---|
[40130] | 213 | req._USCOREthis = argv[ap + 1];
|
---|
[16120] | 214 | _vbox__IVirtualBox_USCOREgetVersionResponse resp;
|
---|
| 215 |
|
---|
| 216 | if (!(soaprc = soap_call___vbox__IVirtualBox_USCOREgetVersion(&soap,
|
---|
| 217 | pcszArgEndpoint,
|
---|
| 218 | NULL,
|
---|
| 219 | &req,
|
---|
| 220 | &resp)))
|
---|
| 221 | std::cout << "version: \"" << resp.returnval << "\"\n";
|
---|
| 222 | }
|
---|
| 223 | }
|
---|
| 224 | else if (!strcmp(pcszMode, "gethost"))
|
---|
| 225 | {
|
---|
[40130] | 226 | if (argc < 2 + ap)
|
---|
[16120] | 227 | std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
|
---|
| 228 | else
|
---|
| 229 | {
|
---|
| 230 | _vbox__IVirtualBox_USCOREgetHost req;
|
---|
[40130] | 231 | req._USCOREthis = argv[ap + 1];
|
---|
[16120] | 232 | _vbox__IVirtualBox_USCOREgetHostResponse resp;
|
---|
| 233 |
|
---|
| 234 | if (!(soaprc = soap_call___vbox__IVirtualBox_USCOREgetHost(&soap,
|
---|
| 235 | pcszArgEndpoint,
|
---|
| 236 | NULL,
|
---|
| 237 | &req,
|
---|
| 238 | &resp)))
|
---|
| 239 | {
|
---|
| 240 | std::cout << "Host objref " << resp.returnval << "\n";
|
---|
| 241 | }
|
---|
| 242 | }
|
---|
| 243 | }
|
---|
[29960] | 244 | else if (!strcmp(pcszMode, "getpc"))
|
---|
| 245 | {
|
---|
[40130] | 246 | if (argc < 2 + ap)
|
---|
[29960] | 247 | std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
|
---|
| 248 | else
|
---|
| 249 | {
|
---|
| 250 | _vbox__IVirtualBox_USCOREgetPerformanceCollector req;
|
---|
[40130] | 251 | req._USCOREthis = argv[ap + 1];
|
---|
[29960] | 252 | _vbox__IVirtualBox_USCOREgetPerformanceCollectorResponse resp;
|
---|
| 253 |
|
---|
| 254 | if (!(soaprc = soap_call___vbox__IVirtualBox_USCOREgetPerformanceCollector(&soap,
|
---|
| 255 | pcszArgEndpoint,
|
---|
| 256 | NULL,
|
---|
| 257 | &req,
|
---|
| 258 | &resp)))
|
---|
| 259 | {
|
---|
| 260 | std::cout << "Performance collector objref " << resp.returnval << "\n";
|
---|
| 261 | }
|
---|
| 262 | }
|
---|
| 263 | }
|
---|
[16120] | 264 | else if (!strcmp(pcszMode, "getmachines"))
|
---|
| 265 | {
|
---|
[40130] | 266 | if (argc < 2 + ap)
|
---|
[16120] | 267 | std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
|
---|
| 268 | else
|
---|
| 269 | {
|
---|
[17737] | 270 | _vbox__IVirtualBox_USCOREgetMachines req;
|
---|
[40130] | 271 | req._USCOREthis = argv[ap + 1];
|
---|
[17737] | 272 | _vbox__IVirtualBox_USCOREgetMachinesResponse resp;
|
---|
[16120] | 273 |
|
---|
[17737] | 274 | if (!(soaprc = soap_call___vbox__IVirtualBox_USCOREgetMachines(&soap,
|
---|
[16120] | 275 | pcszArgEndpoint,
|
---|
| 276 | NULL,
|
---|
| 277 | &req,
|
---|
| 278 | &resp)))
|
---|
| 279 | {
|
---|
[18423] | 280 | size_t c = resp.returnval.size();
|
---|
| 281 | for (size_t i = 0;
|
---|
[16120] | 282 | i < c;
|
---|
| 283 | ++i)
|
---|
| 284 | {
|
---|
| 285 | std::cout << "Machine " << i << ": objref " << resp.returnval[i] << "\n";
|
---|
| 286 | }
|
---|
| 287 | }
|
---|
| 288 | }
|
---|
| 289 | }
|
---|
| 290 | else if (!strcmp(pcszMode, "createmachine"))
|
---|
| 291 | {
|
---|
[40130] | 292 | if (argc < 4 + ap)
|
---|
[16120] | 293 | std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
|
---|
| 294 | else
|
---|
| 295 | {
|
---|
| 296 | _vbox__IVirtualBox_USCOREcreateMachine req;
|
---|
[40130] | 297 | req._USCOREthis = argv[ap + 1];
|
---|
| 298 | req.settingsFile = argv[ap + 2];
|
---|
| 299 | req.name = argv[ap + 3];
|
---|
[33451] | 300 | std::cout << "createmachine: settingsFile = \"" << req.settingsFile << "\", name = \"" << req.name << "\"\n";
|
---|
[16120] | 301 | _vbox__IVirtualBox_USCOREcreateMachineResponse resp;
|
---|
| 302 |
|
---|
| 303 | if (!(soaprc = soap_call___vbox__IVirtualBox_USCOREcreateMachine(&soap,
|
---|
| 304 | pcszArgEndpoint,
|
---|
| 305 | NULL,
|
---|
| 306 | &req,
|
---|
| 307 | &resp)))
|
---|
| 308 | std::cout << "Machine created: managed object reference ID is " << resp.returnval << "\n";
|
---|
| 309 | }
|
---|
| 310 | }
|
---|
| 311 | else if (!strcmp(pcszMode, "registermachine"))
|
---|
| 312 | {
|
---|
[40130] | 313 | if (argc < 3 + ap)
|
---|
[16120] | 314 | std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
|
---|
| 315 | else
|
---|
| 316 | {
|
---|
| 317 | _vbox__IVirtualBox_USCOREregisterMachine req;
|
---|
[40130] | 318 | req._USCOREthis = argv[ap + 1];
|
---|
| 319 | req.machine = argv[ap + 2];
|
---|
[16120] | 320 | _vbox__IVirtualBox_USCOREregisterMachineResponse resp;
|
---|
| 321 | if (!(soaprc = soap_call___vbox__IVirtualBox_USCOREregisterMachine(&soap,
|
---|
| 322 | pcszArgEndpoint,
|
---|
| 323 | NULL,
|
---|
| 324 | &req,
|
---|
| 325 | &resp)))
|
---|
| 326 | std::cout << "Machine registered.\n";
|
---|
| 327 | }
|
---|
| 328 | }
|
---|
| 329 | else if (!strcmp(pcszMode, "getdvddrives"))
|
---|
| 330 | {
|
---|
[40130] | 331 | if (argc < 2 + ap)
|
---|
[16120] | 332 | std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
|
---|
| 333 | else
|
---|
| 334 | {
|
---|
| 335 | _vbox__IHost_USCOREgetDVDDrives req;
|
---|
[40130] | 336 | req._USCOREthis = argv[ap + 1];
|
---|
[16120] | 337 | _vbox__IHost_USCOREgetDVDDrivesResponse resp;
|
---|
| 338 | if (!(soaprc = soap_call___vbox__IHost_USCOREgetDVDDrives(&soap,
|
---|
| 339 | pcszArgEndpoint,
|
---|
| 340 | NULL,
|
---|
| 341 | &req,
|
---|
| 342 | &resp)))
|
---|
| 343 | {
|
---|
[23223] | 344 | size_t c = resp.returnval.size();
|
---|
| 345 | for (size_t i = 0;
|
---|
| 346 | i < c;
|
---|
| 347 | ++i)
|
---|
| 348 | {
|
---|
| 349 | std::cout << "DVD drive " << i << ": objref " << resp.returnval[i] << "\n";
|
---|
| 350 | }
|
---|
[16120] | 351 | }
|
---|
| 352 | }
|
---|
| 353 | }
|
---|
| 354 | else if (!strcmp(pcszMode, "getname"))
|
---|
| 355 | {
|
---|
[40130] | 356 | if (argc < 2 + ap)
|
---|
[16120] | 357 | std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
|
---|
| 358 | else
|
---|
| 359 | {
|
---|
| 360 | _vbox__IMachine_USCOREgetName req;
|
---|
[40130] | 361 | req._USCOREthis = argv[ap + 1];
|
---|
[16120] | 362 | _vbox__IMachine_USCOREgetNameResponse resp;
|
---|
| 363 | if (!(soaprc = soap_call___vbox__IMachine_USCOREgetName(&soap,
|
---|
| 364 | pcszArgEndpoint,
|
---|
| 365 | NULL,
|
---|
| 366 | &req,
|
---|
| 367 | &resp)))
|
---|
| 368 | printf("Name is: %s\n", resp.returnval.c_str());
|
---|
| 369 | }
|
---|
| 370 | }
|
---|
| 371 | else if (!strcmp(pcszMode, "getid"))
|
---|
| 372 | {
|
---|
[40130] | 373 | if (argc < 2 + ap)
|
---|
[16120] | 374 | std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
|
---|
| 375 | else
|
---|
| 376 | {
|
---|
| 377 | _vbox__IMachine_USCOREgetId req;
|
---|
[40130] | 378 | req._USCOREthis = argv[ap + 1];
|
---|
[16120] | 379 | _vbox__IMachine_USCOREgetIdResponse resp;
|
---|
| 380 | if (!(soaprc = soap_call___vbox__IMachine_USCOREgetId(&soap,
|
---|
| 381 | pcszArgEndpoint,
|
---|
| 382 | NULL,
|
---|
| 383 | &req,
|
---|
| 384 | &resp)))
|
---|
| 385 | std::cout << "UUID is: " << resp.returnval << "\n";;
|
---|
| 386 | }
|
---|
| 387 | }
|
---|
| 388 | else if (!strcmp(pcszMode, "getostypeid"))
|
---|
| 389 | {
|
---|
[40130] | 390 | if (argc < 2 + ap)
|
---|
[16120] | 391 | std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
|
---|
| 392 | else
|
---|
| 393 | {
|
---|
| 394 | _vbox__IMachine_USCOREgetOSTypeId req;
|
---|
[40130] | 395 | req._USCOREthis = argv[ap + 1];
|
---|
[16120] | 396 | _vbox__IMachine_USCOREgetOSTypeIdResponse resp;
|
---|
| 397 | if (!(soaprc = soap_call___vbox__IMachine_USCOREgetOSTypeId(&soap,
|
---|
| 398 | pcszArgEndpoint,
|
---|
| 399 | NULL,
|
---|
| 400 | &req,
|
---|
| 401 | &resp)))
|
---|
| 402 | std::cout << "Guest OS type is: " << resp.returnval << "\n";
|
---|
| 403 | }
|
---|
| 404 | }
|
---|
| 405 | else if (!strcmp(pcszMode, "savesettings"))
|
---|
| 406 | {
|
---|
[40130] | 407 | if (argc < 2 + ap)
|
---|
[16120] | 408 | std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
|
---|
| 409 | else
|
---|
| 410 | {
|
---|
| 411 | _vbox__IMachine_USCOREsaveSettings req;
|
---|
[40130] | 412 | req._USCOREthis = argv[ap + 1];
|
---|
[16120] | 413 | _vbox__IMachine_USCOREsaveSettingsResponse resp;
|
---|
| 414 | if (!(soaprc = soap_call___vbox__IMachine_USCOREsaveSettings(&soap,
|
---|
| 415 | pcszArgEndpoint,
|
---|
| 416 | NULL,
|
---|
| 417 | &req,
|
---|
| 418 | &resp)))
|
---|
| 419 | std::cout << "Settings saved\n";
|
---|
| 420 | }
|
---|
| 421 | }
|
---|
[29960] | 422 | else if (!strcmp(pcszMode, "setupmetrics"))
|
---|
| 423 | {
|
---|
[40130] | 424 | if (argc < 2 + ap)
|
---|
[29960] | 425 | std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
|
---|
| 426 | else
|
---|
| 427 | {
|
---|
| 428 | _vbox__IPerformanceCollector_USCOREsetupMetrics req;
|
---|
[40130] | 429 | req._USCOREthis = argv[ap + 1];
|
---|
[29960] | 430 | // req.metricNames[0] = "*";
|
---|
| 431 | // req.objects
|
---|
| 432 | req.period = 1; // seconds
|
---|
| 433 | req.count = 100;
|
---|
| 434 | _vbox__IPerformanceCollector_USCOREsetupMetricsResponse resp;
|
---|
| 435 | if (!(soaprc = soap_call___vbox__IPerformanceCollector_USCOREsetupMetrics(&soap,
|
---|
| 436 | pcszArgEndpoint,
|
---|
| 437 | NULL,
|
---|
| 438 | &req,
|
---|
| 439 | &resp)))
|
---|
| 440 | {
|
---|
| 441 | size_t c = resp.returnval.size();
|
---|
| 442 | for (size_t i = 0;
|
---|
| 443 | i < c;
|
---|
| 444 | ++i)
|
---|
| 445 | {
|
---|
| 446 | std::cout << "Metric " << i << ": objref " << resp.returnval[i] << "\n";
|
---|
| 447 | }
|
---|
| 448 | }
|
---|
| 449 | }
|
---|
| 450 | }
|
---|
| 451 | else if (!strcmp(pcszMode, "querymetricsdata"))
|
---|
| 452 | {
|
---|
[40130] | 453 | if (argc < 2 + ap)
|
---|
[29960] | 454 | std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
|
---|
| 455 | else
|
---|
| 456 | {
|
---|
| 457 | _vbox__IPerformanceCollector_USCOREqueryMetricsData req;
|
---|
[40130] | 458 | req._USCOREthis = argv[ap + 1];
|
---|
[29960] | 459 | // req.metricNames[0] = "*";
|
---|
| 460 | // req.objects
|
---|
| 461 | _vbox__IPerformanceCollector_USCOREqueryMetricsDataResponse resp;
|
---|
| 462 | if (!(soaprc = soap_call___vbox__IPerformanceCollector_USCOREqueryMetricsData(&soap,
|
---|
| 463 | pcszArgEndpoint,
|
---|
| 464 | NULL,
|
---|
| 465 | &req,
|
---|
| 466 | &resp)))
|
---|
| 467 | {
|
---|
| 468 | size_t c = resp.returnval.size();
|
---|
| 469 | for (size_t i = 0;
|
---|
| 470 | i < c;
|
---|
| 471 | ++i)
|
---|
| 472 | {
|
---|
| 473 | std::cout << "long " << i << ": " << resp.returnval[i] << "\n";
|
---|
| 474 | }
|
---|
| 475 | }
|
---|
| 476 | }
|
---|
| 477 | }
|
---|
[46478] | 478 | else if (!strcmp(pcszMode, "errorinfo"))
|
---|
| 479 | {
|
---|
| 480 | if (argc < 2 + ap)
|
---|
| 481 | std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
|
---|
| 482 | else
|
---|
| 483 | {
|
---|
| 484 | _vbox__IVirtualBoxErrorInfo_USCOREgetResultCode req;
|
---|
| 485 | req._USCOREthis = argv[ap + 1];
|
---|
| 486 | _vbox__IVirtualBoxErrorInfo_USCOREgetResultCodeResponse resp;
|
---|
| 487 | if (!(soaprc = soap_call___vbox__IVirtualBoxErrorInfo_USCOREgetResultCode(&soap,
|
---|
| 488 | pcszArgEndpoint,
|
---|
| 489 | NULL,
|
---|
| 490 | &req,
|
---|
| 491 | &resp)))
|
---|
| 492 | {
|
---|
| 493 | std::cout << "ErrorInfo ResultCode: " << std::hex << resp.returnval << "\n";
|
---|
| 494 |
|
---|
| 495 | _vbox__IVirtualBoxErrorInfo_USCOREgetText req2;
|
---|
| 496 | req2._USCOREthis = argv[ap + 1];
|
---|
| 497 | _vbox__IVirtualBoxErrorInfo_USCOREgetTextResponse resp2;
|
---|
| 498 | if (!(soaprc = soap_call___vbox__IVirtualBoxErrorInfo_USCOREgetText(&soap,
|
---|
| 499 | pcszArgEndpoint,
|
---|
| 500 | NULL,
|
---|
| 501 | &req2,
|
---|
| 502 | &resp2)))
|
---|
| 503 | {
|
---|
| 504 | std::cout << "ErrorInfo Text: " << resp2.returnval << "\n";
|
---|
| 505 |
|
---|
| 506 | _vbox__IVirtualBoxErrorInfo_USCOREgetNext req3;
|
---|
| 507 | req3._USCOREthis = argv[ap + 1];
|
---|
| 508 | _vbox__IVirtualBoxErrorInfo_USCOREgetNextResponse resp3;
|
---|
| 509 | if (!(soaprc = soap_call___vbox__IVirtualBoxErrorInfo_USCOREgetNext(&soap,
|
---|
| 510 | pcszArgEndpoint,
|
---|
| 511 | NULL,
|
---|
| 512 | &req3,
|
---|
| 513 | &resp3)))
|
---|
| 514 | std::cout << "Next ErrorInfo: " << resp3.returnval << "\n";
|
---|
| 515 | }
|
---|
| 516 | }
|
---|
| 517 | }
|
---|
| 518 | }
|
---|
[16120] | 519 | else if (!strcmp(pcszMode, "release"))
|
---|
| 520 | {
|
---|
[40130] | 521 | if (argc < 2 + ap)
|
---|
[16120] | 522 | std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n";
|
---|
| 523 | else
|
---|
| 524 | {
|
---|
| 525 | _vbox__IManagedObjectRef_USCORErelease req;
|
---|
[40130] | 526 | req._USCOREthis = argv[ap + 1];
|
---|
[16120] | 527 | _vbox__IManagedObjectRef_USCOREreleaseResponse resp;
|
---|
| 528 | if (!(soaprc = soap_call___vbox__IManagedObjectRef_USCORErelease(&soap,
|
---|
| 529 | pcszArgEndpoint,
|
---|
| 530 | NULL,
|
---|
| 531 | &req,
|
---|
| 532 | &resp)))
|
---|
| 533 | std::cout << "Managed object reference " << req._USCOREthis << " released.\n";
|
---|
| 534 | }
|
---|
| 535 | }
|
---|
| 536 | else
|
---|
| 537 | std::cout << "Unknown mode parameter \"" << pcszMode << "\".\n";
|
---|
| 538 |
|
---|
| 539 | if (soaprc)
|
---|
| 540 | {
|
---|
| 541 | if ( (soap.fault)
|
---|
| 542 | && (soap.fault->detail)
|
---|
| 543 | )
|
---|
| 544 | {
|
---|
[46478] | 545 | // generic fault message whether the fault is known or not
|
---|
| 546 | std::cerr << "Generic fault message:\n";
|
---|
| 547 | soap_print_fault(&soap, stderr); // display the SOAP fault message on the stderr stream
|
---|
| 548 |
|
---|
[16120] | 549 | if (soap.fault->detail->vbox__InvalidObjectFault)
|
---|
| 550 | {
|
---|
[46478] | 551 | std::cerr << "Bad object ID: " << soap.fault->detail->vbox__InvalidObjectFault->badObjectID << "\n";
|
---|
[16120] | 552 | }
|
---|
[40130] | 553 | else if (soap.fault->detail->vbox__RuntimeFault)
|
---|
[16120] | 554 | {
|
---|
[46478] | 555 | std::cerr << "Result code: 0x" << std::hex << soap.fault->detail->vbox__RuntimeFault->resultCode << "\n";
|
---|
| 556 | std::cerr << "ErrorInfo: " << soap.fault->detail->vbox__RuntimeFault->returnval << "\n";
|
---|
[16120] | 557 | }
|
---|
| 558 | }
|
---|
| 559 | else
|
---|
| 560 | {
|
---|
| 561 | std::cerr << "Invalid fault data, fault message:\n";
|
---|
| 562 | soap_print_fault(&soap, stderr); // display the SOAP fault message on the stderr stream
|
---|
| 563 | }
|
---|
| 564 | }
|
---|
| 565 |
|
---|
| 566 | soap_destroy(&soap); // delete deserialized class instances (for C++ only)
|
---|
| 567 | soap_end(&soap); // remove deserialized data and clean up
|
---|
| 568 | soap_done(&soap); // detach the gSOAP environment
|
---|
| 569 |
|
---|
| 570 | return soaprc;
|
---|
| 571 | }
|
---|
| 572 |
|
---|