Changeset 26322 in vbox for trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp
- Timestamp:
- Feb 8, 2010 11:08:02 AM (15 years ago)
- File:
-
- 1 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 */
Note:
See TracChangeset
for help on using the changeset viewer.