Changeset 47631 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Aug 9, 2013 10:08:12 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp
r47629 r47631 24 24 #ifndef VBOX_ONLY_DOCS 25 25 26 #include <VBox/com/array.h> 26 27 #include <VBox/com/com.h> 27 #include <VBox/com/string.h>28 #include <VBox/com/array.h>29 28 #include <VBox/com/ErrorInfo.h> 30 29 #include <VBox/com/errorprint.h> 30 #include <VBox/com/listeners.h> 31 #include <VBox/com/NativeEventQueue.h> 32 #include <VBox/com/string.h> 31 33 #include <VBox/com/VirtualBox.h> 32 #include <VBox/com/NativeEventQueue.h>33 34 34 35 #include <VBox/err.h> … … 62 63 63 64 /** 64 * IVirtualBoxCallback implementation for handling the GuestControlCallback in 65 * relation to the "guestcontrol * wait" command. 65 * Handler for guest events. 66 66 */ 67 /** @todo */ 67 class GuestEventListener 68 { 69 public: 70 GuestEventListener(void) 71 { 72 } 73 74 virtual ~GuestEventListener(void) 75 { 76 } 77 78 HRESULT init(void) 79 { 80 return S_OK; 81 } 82 83 void uninit(void) 84 { 85 } 86 87 STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent *aEvent) 88 { 89 switch (aType) 90 { 91 case VBoxEventType_OnGuestSessionRegistered: 92 { 93 ComPtr<IGuestSessionRegisteredEvent> pEvent = aEvent; 94 Assert(!pEvent.isNull()); 95 96 ComPtr<IGuestSession> pSession; 97 HRESULT rc = pEvent->COMGETTER(Session)(pSession.asOutParam()); 98 AssertComRCBreakRC(rc); 99 AssertBreak(!pSession.isNull()); 100 101 BOOL fRegistered; 102 rc = pEvent->COMGETTER(Registered)(&fRegistered); 103 AssertComRCBreakRC(rc); 104 105 Bstr strName; 106 rc = pSession->COMGETTER(Name)(strName.asOutParam()); 107 AssertComRCBreakRC(rc); 108 ULONG uID; 109 rc = pSession->COMGETTER(Id)(&uID); 110 AssertComRCBreakRC(rc); 111 112 RTPrintf("Session ID=%RU32 \"%s\" %s\n", 113 uID, Utf8Str(strName).c_str(), 114 fRegistered ? "registered" : "unregistered"); 115 116 pSession.setNull(); 117 break; 118 } 119 120 default: 121 AssertFailed(); 122 } 123 124 return S_OK; 125 } 126 }; 127 typedef ListenerImpl<GuestEventListener> GuestEventListenerImpl; 128 VBOX_LISTENER_DECLARE(GuestEventListenerImpl) 68 129 69 130 /** Set by the signal handler. */ … … 294 355 " [--wait-start]\n" 295 356 " [-- [<argument1>] ... [<argumentN>]]\n" 357 "\n" 358 " watch [--verbose]\n" 296 359 "\n", pcszSep1, pcszSep2); 297 360 } … … 3369 3432 } 3370 3433 3434 static RTEXITCODE handleCtrlWatch(ComPtr<IGuest> guest, HandlerArg *pArg) 3435 { 3436 AssertPtrReturn(pArg, RTEXITCODE_SYNTAX); 3437 3438 /* 3439 * Parse arguments. 3440 */ 3441 static const RTGETOPTDEF s_aOptions[] = 3442 { 3443 { "--verbose", 'v', RTGETOPT_REQ_NOTHING } 3444 }; 3445 3446 int ch; 3447 RTGETOPTUNION ValueUnion; 3448 RTGETOPTSTATE GetState; 3449 RTGetOptInit(&GetState, pArg->argc, pArg->argv, 3450 s_aOptions, RT_ELEMENTS(s_aOptions), 0, RTGETOPTINIT_FLAGS_OPTS_FIRST); 3451 3452 bool fVerbose = false; 3453 3454 while ((ch = RTGetOpt(&GetState, &ValueUnion))) 3455 { 3456 /* For options that require an argument, ValueUnion has received the value. */ 3457 switch (ch) 3458 { 3459 case 'v': /* Verbose */ 3460 fVerbose = true; 3461 break; 3462 3463 case VINF_GETOPT_NOT_OPTION: 3464 break; 3465 3466 default: 3467 return RTGetOptPrintError(ch, &ValueUnion); 3468 } 3469 } 3470 3471 /** @todo Specify categories to watch for. */ 3472 /** @todo Specify a --timeout for waiting only for a certain amount of time? */ 3473 3474 HRESULT rc; 3475 3476 try 3477 { 3478 ComObjPtr<GuestEventListenerImpl> pGuestListener; 3479 3480 3481 3482 do 3483 { 3484 /* Listener creation. */ 3485 pGuestListener.createObject(); 3486 pGuestListener->init(new GuestEventListener()); 3487 3488 /* Register for IGuest events. */ 3489 ComPtr<IEventSource> es; 3490 CHECK_ERROR_BREAK(guest, COMGETTER(EventSource)(es.asOutParam())); 3491 com::SafeArray<VBoxEventType_T> eventTypes; 3492 eventTypes.push_back(VBoxEventType_OnGuestSessionRegistered); 3493 /** @todo Also register for VBoxEventType_OnGuestUserStateChanged on demand? */ 3494 CHECK_ERROR_BREAK(es, RegisterListener(pGuestListener, ComSafeArrayAsInParam(eventTypes), 3495 true /* Active listener */)); 3496 /* Note: All other guest control events have to be registered 3497 * as their corresponding objects appear. */ 3498 3499 } while (0); 3500 3501 ctrlSignalHandlerInstall(); 3502 3503 if (fVerbose) 3504 RTPrintf("Waiting for events ...\n"); 3505 3506 while (!g_fGuestCtrlCanceled) 3507 { 3508 /** @todo Timeout handling (see above)? */ 3509 RTThreadYield(); 3510 } 3511 3512 if (fVerbose) 3513 RTPrintf("Signal caught, exiting ...\n"); 3514 3515 ctrlSignalHandlerUninstall(); 3516 3517 if (!pGuestListener.isNull()) 3518 { 3519 /* Guest callback unregistration. */ 3520 ComPtr<IEventSource> pES; 3521 CHECK_ERROR(guest, COMGETTER(EventSource)(pES.asOutParam())); 3522 if (!pES.isNull()) 3523 CHECK_ERROR(pES, UnregisterListener(pGuestListener)); 3524 pGuestListener.setNull(); 3525 } 3526 } 3527 catch (std::bad_alloc &) 3528 { 3529 rc = E_OUTOFMEMORY; 3530 } 3531 3532 return SUCCEEDED(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 3533 } 3534 3371 3535 /** 3372 3536 * Access the guest control store. … … 3431 3595 else if ( !RTStrICmp(pArg->argv[1], "process")) 3432 3596 rcExit = handleCtrlProcess(guest, &arg); 3597 else if ( !RTStrICmp(pArg->argv[1], "watch")) 3598 rcExit = handleCtrlWatch(guest, &arg); 3433 3599 else 3434 3600 rcExit = errorSyntax(USAGE_GUESTCONTROL, "Unknown sub command '%s' specified!", pArg->argv[1]);
Note:
See TracChangeset
for help on using the changeset viewer.