Changeset 26322 in vbox
- Timestamp:
- Feb 8, 2010 11:08:02 AM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 57403
- Location:
- trunk/src/VBox/Frontends
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp
r26089 r26322 71 71 #define LogError(m,rc) \ 72 72 do { \ 73 Log 74 RTPrintf 73 Log(("VBoxHeadless: ERROR: " m " [rc=0x%08X]\n", rc)); \ 74 RTPrintf("%s\n", m); \ 75 75 } while (0) 76 76 … … 90 90 { 91 91 public: 92 StateChangeEvent (MachineState_T state) : mState(state) {}92 StateChangeEvent(MachineState_T state) : mState(state) {} 93 93 protected: 94 94 void *handler() 95 95 { 96 LogFlow 96 LogFlow(("VBoxHeadless: StateChangeEvent: %d\n", mState)); 97 97 /* post the termination event if the machine has been PoweredDown/Saved/Aborted */ 98 98 if (mState < MachineState_Running) 99 gEventQ->postEvent 99 gEventQ->postEvent(NULL); 100 100 return 0; 101 101 } … … 275 275 public: 276 276 277 ConsoleCallback 277 ConsoleCallback() 278 278 { 279 279 #ifndef VBOX_WITH_XPCOM … … 302 302 VBOX_SCRIPTABLE_DISPATCH_IMPL(IConsoleCallback) 303 303 304 STDMETHOD(OnMousePointerShapeChange) 305 306 { 307 return S_OK; 308 } 309 310 STDMETHOD(OnMouseCapabilityChange) 304 STDMETHOD(OnMousePointerShapeChange)(BOOL visible, BOOL alpha, ULONG xHot, ULONG yHot, 305 ULONG width, ULONG height, BYTE *shape) 306 { 307 return S_OK; 308 } 309 310 STDMETHOD(OnMouseCapabilityChange)(BOOL supportsAbsolute, BOOL needsHostCursor) 311 311 { 312 312 /* Emit absolute mouse event to actually enable the host mouse cursor. */ … … 328 328 } 329 329 330 STDMETHOD(OnStateChange) 331 { 332 gEventQ->postEvent (new StateChangeEvent(machineState));333 return S_OK; 334 } 335 336 STDMETHOD(OnExtraDataChange) 330 STDMETHOD(OnStateChange)(MachineState_T machineState) 331 { 332 gEventQ->postEvent(new StateChangeEvent(machineState)); 333 return S_OK; 334 } 335 336 STDMETHOD(OnExtraDataChange)(BSTR key) 337 337 { 338 338 return S_OK; … … 344 344 } 345 345 346 STDMETHOD(OnNetworkAdapterChange) 347 { 348 return S_OK; 349 } 350 351 STDMETHOD(OnSerialPortChange) 352 { 353 return S_OK; 354 } 355 356 STDMETHOD(OnParallelPortChange) 346 STDMETHOD(OnNetworkAdapterChange)(INetworkAdapter *aNetworkAdapter) 347 { 348 return S_OK; 349 } 350 351 STDMETHOD(OnSerialPortChange)(ISerialPort *aSerialPort) 352 { 353 return S_OK; 354 } 355 356 STDMETHOD(OnParallelPortChange)(IParallelPort *aParallelPort) 357 357 { 358 358 return S_OK; … … 412 412 } 413 413 414 STDMETHOD(OnUSBDeviceStateChange) 414 STDMETHOD(OnUSBDeviceStateChange)(IUSBDevice *aDevice, BOOL aAttached, 415 415 IVirtualBoxErrorInfo *aError) 416 416 { … … 418 418 } 419 419 420 STDMETHOD(OnSharedFolderChange) 420 STDMETHOD(OnSharedFolderChange)(Scope_T aScope) 421 421 { 422 422 return S_OK; … … 437 437 } 438 438 439 STDMETHOD(OnShowWindow) 439 STDMETHOD(OnShowWindow)(ULONG64 *winId) 440 440 { 441 441 /* OnCanShowWindow() always returns FALSE, so this call should never … … 457 457 458 458 #ifdef VBOX_WITH_XPCOM 459 NS_DECL_CLASSINFO 460 NS_IMPL_THREADSAFE_ISUPPORTS1_CI 461 NS_DECL_CLASSINFO 462 NS_IMPL_THREADSAFE_ISUPPORTS1_CI 459 NS_DECL_CLASSINFO(VirtualBoxCallback) 460 NS_IMPL_THREADSAFE_ISUPPORTS1_CI(VirtualBoxCallback, IVirtualBoxCallback) 461 NS_DECL_CLASSINFO(ConsoleCallback) 462 NS_IMPL_THREADSAFE_ISUPPORTS1_CI(ConsoleCallback, IConsoleCallback) 463 463 #endif 464 464 … … 597 597 * Entry point. 598 598 */ 599 extern "C" DECLEXPORT (int) TrustedMain(int argc, char **argv, char **envp)599 extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv, char **envp) 600 600 { 601 601 #ifdef VBOX_WITH_VRDP … … 862 862 { 863 863 ComPtr <IMachine> m; 864 rc = virtualBox->FindMachine (Bstr(name), m.asOutParam());865 if (FAILED 866 { 867 LogError 868 break; 869 } 870 m->COMGETTER(Id) 871 AssertComRC 872 if (FAILED 873 break; 874 } 875 876 Log 864 rc = virtualBox->FindMachine(Bstr(name), m.asOutParam()); 865 if (FAILED(rc)) 866 { 867 LogError("Invalid machine name!\n", rc); 868 break; 869 } 870 m->COMGETTER(Id)(id.asOutParam()); 871 AssertComRC(rc); 872 if (FAILED(rc)) 873 break; 874 } 875 876 Log(("VBoxHeadless: Opening a session with machine (id={%s})...\n", 877 877 Utf8Str(id).raw())); 878 878 879 879 // open a session 880 CHECK_ERROR_BREAK(virtualBox, OpenSession 880 CHECK_ERROR_BREAK(virtualBox, OpenSession(session, id)); 881 881 fSessionOpened = true; 882 882 883 883 /* get the console */ 884 884 ComPtr <IConsole> console; 885 CHECK_ERROR_BREAK(session, COMGETTER (Console)(console.asOutParam()));885 CHECK_ERROR_BREAK(session, COMGETTER(Console)(console.asOutParam())); 886 886 887 887 /* get the machine */ 888 888 ComPtr <IMachine> machine; 889 CHECK_ERROR_BREAK(console, COMGETTER(Machine) 889 CHECK_ERROR_BREAK(console, COMGETTER(Machine)(machine.asOutParam())); 890 890 891 891 ComPtr <IDisplay> display; 892 CHECK_ERROR_BREAK(console, COMGETTER(Display) 892 CHECK_ERROR_BREAK(console, COMGETTER(Display)(display.asOutParam())); 893 893 894 894 #ifdef VBOX_FFMPEG … … 923 923 "you wish to use is supported on your system\n", rcc); 924 924 } 925 if (RT_SUCCESS(rrc) && ( S_OK == rcc))925 if (RT_SUCCESS(rrc) && (rcc == S_OK)) 926 926 { 927 927 Log2(("VBoxHeadless: Registering framebuffer\n")); … … 952 952 } 953 953 #endif /* defined(VBOX_FFMPEG) */ 954 VRDPFramebuffer *pVRDPFramebuffer = new VRDPFramebuffer 954 VRDPFramebuffer *pVRDPFramebuffer = new VRDPFramebuffer(); 955 955 if (!pVRDPFramebuffer) 956 956 { … … 1027 1027 /* register a callback for machine events */ 1028 1028 { 1029 ConsoleCallback *callback = new ConsoleCallback 1029 ConsoleCallback *callback = new ConsoleCallback(); 1030 1030 callback->AddRef(); 1031 CHECK_ERROR(console, RegisterCallback 1031 CHECK_ERROR(console, RegisterCallback(callback)); 1032 1032 callback->Release(); 1033 if (FAILED 1033 if (FAILED(rc)) 1034 1034 break; 1035 1035 } … … 1040 1040 BOOL fVRDPEnabled; 1041 1041 ComPtr <IVRDPServer> vrdpServer; 1042 CHECK_ERROR_BREAK(machine, COMGETTER (VRDPServer)(vrdpServer.asOutParam()));1043 CHECK_ERROR_BREAK(vrdpServer, COMGETTER(Enabled) 1042 CHECK_ERROR_BREAK(machine, COMGETTER(VRDPServer)(vrdpServer.asOutParam())); 1043 CHECK_ERROR_BREAK(vrdpServer, COMGETTER(Enabled)(&fVRDPEnabled)); 1044 1044 1045 1045 if (vrdpEnabled != NULL) … … 1062 1062 if (fVRDPEnable) 1063 1063 { 1064 Log 1064 Log(("VBoxHeadless: Enabling VRDP server...\n")); 1065 1065 1066 1066 /* set VRDP port if requested by the user */ … … 1078 1078 if (!fVRDPEnabled) 1079 1079 { 1080 CHECK_ERROR_BREAK(vrdpServer, COMSETTER(Enabled) 1080 CHECK_ERROR_BREAK(vrdpServer, COMSETTER(Enabled)(TRUE)); 1081 1081 } 1082 1082 } … … 1086 1086 if (fVRDPEnabled) 1087 1087 { 1088 CHECK_ERROR_BREAK(vrdpServer, COMSETTER(Enabled) 1089 } 1090 } 1091 #endif 1092 Log 1088 CHECK_ERROR_BREAK(vrdpServer, COMSETTER(Enabled)(FALSE)); 1089 } 1090 } 1091 #endif 1092 Log(("VBoxHeadless: Powering up the machine...\n")); 1093 1093 1094 1094 ComPtr <IProgress> progress; 1095 CHECK_ERROR_BREAK(console, PowerUp 1095 CHECK_ERROR_BREAK(console, PowerUp(progress.asOutParam())); 1096 1096 1097 1097 /* wait for result because there can be errors */ 1098 if (SUCCEEDED(progress->WaitForCompletion 1098 if (SUCCEEDED(progress->WaitForCompletion(-1))) 1099 1099 { 1100 1100 LONG progressRc; … … 1120 1120 #endif 1121 1121 1122 Log 1122 Log(("VBoxHeadless: Waiting for PowerDown...\n")); 1123 1123 1124 1124 Event *e; 1125 1125 1126 while (gEventQ->waitForEvent 1127 gEventQ->handleEvent 1128 1129 Log 1126 while (gEventQ->waitForEvent(&e) && e) 1127 gEventQ->handleEvent(e); 1128 1129 Log(("VBoxHeadless: event loop has terminated...\n")); 1130 1130 1131 1131 #ifdef VBOX_FFMPEG 1132 1132 if (pFramebuffer) 1133 1133 { 1134 pFramebuffer->Release 1134 pFramebuffer->Release(); 1135 1135 Log(("Released framebuffer\n")); 1136 1136 pFramebuffer = NULL; … … 1151 1151 * unregister the callback we've registered before. 1152 1152 */ 1153 Log 1153 Log(("VBoxHeadless: Closing the session...\n")); 1154 1154 session->Close(); 1155 1155 } … … 1161 1161 com::Shutdown(); 1162 1162 1163 LogFlow 1163 LogFlow(("VBoxHeadless FINISHED.\n")); 1164 1164 1165 1165 return rc; … … 1171 1171 * Main entry point. 1172 1172 */ 1173 int main 1173 int main(int argc, char **argv, char **envp) 1174 1174 { 1175 1175 // initialize VBox Runtime … … 1191 1191 } 1192 1192 1193 return TrustedMain 1193 return TrustedMain(argc, argv, envp); 1194 1194 } 1195 1195 #endif /* !VBOX_WITH_HARDENING */ -
trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp
r26089 r26322 991 991 } 992 992 993 rc = com::Initialize();994 if (FAILED(rc))995 {996 RTPrintf("Error: COM initialization failed, rc = 0x%x!\n", rc);997 return 1;998 }999 1000 do1001 {1002 // scopes all the stuff till shutdown1003 ////////////////////////////////////////////////////////////////////////////1004 1005 ComPtr <IVirtualBox> virtualBox;1006 ComPtr <ISession> session;1007 bool sessionOpened = false;1008 1009 rc = virtualBox.createLocalObject (CLSID_VirtualBox);1010 if (FAILED(rc))1011 {1012 com::ErrorInfo info;1013 if (info.isFullAvailable())1014 PrintError("Failed to create VirtualBox object",1015 info.getText().raw(), info.getComponent().raw());1016 else1017 RTPrintf("Failed to create VirtualBox object! No error information available (rc = 0x%x).\n", rc);1018 break;1019 }1020 rc = session.createInprocObject (CLSID_Session);1021 if (FAILED(rc))1022 {1023 RTPrintf("Failed to create session object, rc = 0x%x!\n", rc);1024 break;1025 }1026 1027 EventQueue* eventQ = com::EventQueue::getMainEventQueue();1028 1029 /* Get the number of network adapters */1030 ULONG NetworkAdapterCount = 0;1031 ComPtr <ISystemProperties> sysInfo;1032 virtualBox->COMGETTER(SystemProperties) (sysInfo.asOutParam());1033 sysInfo->COMGETTER (NetworkAdapterCount) (&NetworkAdapterCount);1034 1035 993 // command line argument parsing stuff 1036 994 for (int curArg = 1; curArg < argc; curArg++) … … 1046 1004 { 1047 1005 RTPrintf("Error: VM not specified (UUID or name)!\n"); 1048 rc = E_FAIL; 1049 break; 1006 return 1; 1050 1007 } 1051 1008 // first check if a UUID was supplied … … 1062 1019 { 1063 1020 RTPrintf("Error: missing argument for comment!\n"); 1064 rc = E_FAIL; 1065 break; 1021 return 1; 1066 1022 } 1067 1023 } … … 1072 1028 { 1073 1029 RTPrintf("Error: missing argument for boot drive!\n"); 1074 rc = E_FAIL; 1075 break; 1030 return 1; 1076 1031 } 1077 1032 switch (argv[curArg][0]) … … 1104 1059 { 1105 1060 RTPrintf("Error: wrong argument for boot drive!\n"); 1106 rc = E_FAIL; 1107 break; 1061 return 1; 1108 1062 } 1109 1063 } 1110 if (FAILED (rc))1111 break;1112 1064 } 1113 1065 else if ( !strcmp(argv[curArg], "--memory") … … 1118 1070 { 1119 1071 RTPrintf("Error: missing argument for memory size!\n"); 1120 rc = E_FAIL; 1121 break; 1072 return 1; 1122 1073 } 1123 1074 memorySize = atoi(argv[curArg]); … … 1129 1080 { 1130 1081 RTPrintf("Error: missing argument for vram size!\n"); 1131 rc = E_FAIL; 1132 break; 1082 return 1; 1133 1083 } 1134 1084 vramSize = atoi(argv[curArg]); … … 1154 1104 { 1155 1105 RTPrintf("Error: missing arguments for fixed video mode!\n"); 1156 rc = E_FAIL; 1157 break; 1106 return 1; 1158 1107 } 1159 1108 fixedWidth = atoi(argv[++curArg]); … … 1183 1132 { 1184 1133 RTPrintf("Error: missing a string of disabled hostkey combinations\n"); 1185 rc = E_FAIL; 1186 break; 1134 return 1; 1187 1135 } 1188 1136 gHostKeyDisabledCombinations = argv[curArg]; … … 1194 1142 RTPrintf("Error: <hostkey> + '%c' is not a valid combination\n", 1195 1143 gHostKeyDisabledCombinations[i]); 1196 rc = E_FAIL; 1197 break; 1144 return 1; 1198 1145 } 1199 1146 } 1200 if (rc == E_FAIL)1201 break;1202 1147 } 1203 1148 else if ( !strcmp(argv[curArg], "--nograbonclick") … … 1217 1162 { 1218 1163 RTPrintf("Error: missing file name for --pidfile!\n"); 1219 rc = E_FAIL; 1220 break; 1164 return 1; 1221 1165 } 1222 1166 gpszPidFile = argv[curArg]; … … 1228 1172 { 1229 1173 RTPrintf("Error: missing file name for first hard disk!\n"); 1230 rc = E_FAIL; 1231 break; 1174 return 1; 1232 1175 } 1233 1176 /* resolve it. */ … … 1237 1180 { 1238 1181 RTPrintf("Error: The path to the specified harddisk, '%s', could not be resolved.\n", argv[curArg]); 1239 rc = E_FAIL; 1240 break; 1182 return 1; 1241 1183 } 1242 1184 } … … 1247 1189 { 1248 1190 RTPrintf("Error: missing file/device name for first floppy disk!\n"); 1249 rc = E_FAIL; 1250 break; 1191 return 1; 1251 1192 } 1252 1193 /* resolve it. */ … … 1256 1197 { 1257 1198 RTPrintf("Error: The path to the specified floppy disk, '%s', could not be resolved.\n", argv[curArg]); 1258 rc = E_FAIL; 1259 break; 1199 return 1; 1260 1200 } 1261 1201 } … … 1266 1206 { 1267 1207 RTPrintf("Error: missing file/device name for cdrom!\n"); 1268 rc = E_FAIL; 1269 break; 1208 return 1; 1270 1209 } 1271 1210 /* resolve it. */ … … 1275 1214 { 1276 1215 RTPrintf("Error: The path to the specified cdrom, '%s', could not be resolved.\n", argv[curArg]); 1277 rc = E_FAIL; 1278 break; 1216 return 1; 1279 1217 } 1280 1218 } … … 1320 1258 { 1321 1259 RTPrintf("Error: missing font file name for secure label!\n"); 1322 rc = E_FAIL; 1323 break; 1260 return 1; 1324 1261 } 1325 1262 secureLabelFontFile = argv[curArg]; … … 1331 1268 { 1332 1269 RTPrintf("Error: missing font point size for secure label!\n"); 1333 rc = E_FAIL; 1334 break; 1270 return 1; 1335 1271 } 1336 1272 secureLabelPointSize = atoi(argv[curArg]); … … 1342 1278 { 1343 1279 RTPrintf("Error: missing font pixel offset for secure label!\n"); 1344 rc = E_FAIL; 1345 break; 1280 return 1; 1346 1281 } 1347 1282 secureLabelFontOffs = atoi(argv[curArg]); … … 1353 1288 { 1354 1289 RTPrintf("Error: missing text color value for secure label!\n"); 1355 rc = E_FAIL; 1356 break; 1290 return 1; 1357 1291 } 1358 1292 sscanf(argv[curArg], "%X", &secureLabelColorFG); … … 1364 1298 { 1365 1299 RTPrintf("Error: missing background color value for secure label!\n"); 1366 rc = E_FAIL; 1367 break; 1300 return 1; 1368 1301 } 1369 1302 sscanf(argv[curArg], "%X", &secureLabelColorBG); … … 1407 1340 { 1408 1341 RTPrintf("Error: missing the rate value for the --warpdrive option!\n"); 1409 rc = E_FAIL; 1410 break; 1342 return 1; 1411 1343 } 1412 1344 u32WarpDrive = RTStrToUInt32(argv[curArg]); … … 1414 1346 { 1415 1347 RTPrintf("Error: the warp drive rate is restricted to [2..20000]. (%d)\n", u32WarpDrive); 1416 rc = E_FAIL; 1417 break; 1348 return 1; 1418 1349 } 1419 1350 } … … 1433 1364 { 1434 1365 RTPrintf("Error: not enough arguments for host keys!\n"); 1435 rc = E_FAIL; 1436 break; 1366 return 1; 1437 1367 } 1438 1368 gHostKeySym1 = atoi(argv[curArg++]); … … 1455 1385 } 1456 1386 } 1387 1388 rc = com::Initialize(); 1457 1389 if (FAILED(rc)) 1390 { 1391 RTPrintf("Error: COM initialization failed, rc = 0x%x!\n", rc); 1392 return 1; 1393 } 1394 1395 do 1396 { 1397 // scopes all the stuff till shutdown 1398 //////////////////////////////////////////////////////////////////////////// 1399 1400 ComPtr <IVirtualBox> virtualBox; 1401 ComPtr <ISession> session; 1402 bool sessionOpened = false; 1403 1404 rc = virtualBox.createLocalObject (CLSID_VirtualBox); 1405 if (FAILED(rc)) 1406 { 1407 com::ErrorInfo info; 1408 if (info.isFullAvailable()) 1409 PrintError("Failed to create VirtualBox object", 1410 info.getText().raw(), info.getComponent().raw()); 1411 else 1412 RTPrintf("Failed to create VirtualBox object! No error information available (rc = 0x%x).\n", rc); 1458 1413 break; 1414 } 1415 rc = session.createInprocObject (CLSID_Session); 1416 if (FAILED(rc)) 1417 { 1418 RTPrintf("Failed to create session object, rc = 0x%x!\n", rc); 1419 break; 1420 } 1421 1422 EventQueue* eventQ = com::EventQueue::getMainEventQueue(); 1459 1423 1460 1424 /* … … 2922 2886 LogFlow(("Returning from main()!\n")); 2923 2887 RTLogFlush(NULL); 2924 return FAILED 2888 return FAILED(rc) ? 1 : 0; 2925 2889 } 2926 2890
Note:
See TracChangeset
for help on using the changeset viewer.