VirtualBox

Changeset 6852 in vbox


Ignore:
Timestamp:
Feb 7, 2008 5:45:47 PM (17 years ago)
Author:
vboxsync
Message:

FE/SDL: use feedback from the guest to decide if we need to switch off the VM hardly or not

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/pdmifs.h

    r6312 r6852  
    16771677     */
    16781678    DECLR3CALLBACKMEMBER(int, pfnSleepButtonPress,(PPDMIACPIPORT pInterface));
     1679
     1680    /**
     1681     * Check if the last power button event was handled by the guest.
     1682     *
     1683     * @returns VBox status code
     1684     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1685     * @param   pfHandled       Is set to true if the last power button event was handled, false otherwise.
     1686     */
     1687    DECLR3CALLBACKMEMBER(int, pfnGetPowerButtonHandled,(PPDMIACPIPORT pInterface, bool *pfHandled));
    16791688} PDMIACPIPORT;
    16801689
  • trunk/src/VBox/Devices/PC/DevACPI.cpp

    r6305 r6852  
    181181    uint8_t             u8IndexShift;
    182182    uint8_t             u8UseIOApic;
     183    bool                fPowerButtonHandled;
    183184
    184185    /** ACPI port base interface. */
     
    741742{
    742743    ACPIState *s = IACPIPORT_2_ACPISTATE(pInterface);
     744    s->fPowerButtonHandled = false;
    743745    update_pm1a (s, s->pm1a_sts | PWRBTN_STS, s->pm1a_en);
     746    return VINF_SUCCESS;
     747}
     748
     749static DECLCALLBACK(int) acpiGetPowerButtonHandled(PPDMIACPIPORT pInterface, bool *pfHandled)
     750{
     751    ACPIState *s = IACPIPORT_2_ACPISTATE(pInterface);
     752    *pfHandled = s->fPowerButtonHandled;
    744753    return VINF_SUCCESS;
    745754}
     
    784793{
    785794    Log (("acpi: acpiPM1aStsWritew <- %#x (%#x)\n", val, val & ~(RSR_STS | IGN_STS)));
     795    if (val & PWRBTN_STS)
     796        s->fPowerButtonHandled = true; /* Remember that the guest handled the last power button event */
    786797    val = s->pm1a_sts & ~(val & ~(RSR_STS | IGN_STS));
    787798    update_pm1a (s, val, s->pm1a_en);
     
    10631074            return VERR_IOM_IOPORT_UNUSED;
    10641075    }
    1065 //    LogRel(("Query %04x => %08x\n", s->uBatteryIndex, *pu32));
    10661076    return VINF_SUCCESS;
    10671077}
     
    16761686     */
    16771687    /* IBase */
    1678     s->IBase.pfnQueryInterface         = acpiQueryInterface;
     1688    s->IBase.pfnQueryInterface            = acpiQueryInterface;
    16791689    /* IACPIPort */
    1680     s->IACPIPort.pfnSleepButtonPress   = acpiSleepButtonPress;
    1681     s->IACPIPort.pfnPowerButtonPress   = acpiPowerButtonPress;
     1690    s->IACPIPort.pfnSleepButtonPress      = acpiSleepButtonPress;
     1691    s->IACPIPort.pfnPowerButtonPress      = acpiPowerButtonPress;
     1692    s->IACPIPort.pfnGetPowerButtonHandled = acpiGetPowerButtonHandled;
    16821693
    16831694   /*
  • trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp

    r6616 r6852  
    140140static Uint32  StartupTimer(Uint32 interval, void *param);
    141141static Uint32  ResizeTimer(Uint32 interval, void *param);
     142static Uint32  QuitTimer(Uint32 interval, void *param);
    142143static int     WaitSDLEvent(SDL_Event *event);
    143144
     
    191192static SDL_Cursor *gpOffCursor = NULL;
    192193static SDL_TimerID gSdlResizeTimer = NULL;
     194static SDL_TimerID gSdlQuitTimer = NULL;
    193195
    194196#ifdef VBOXSDL_WITH_X11
     
    22102212            case SDL_QUIT:
    22112213            {
    2212                 if (!gfACPITerm)
     2214                if (!gfACPITerm || gSdlQuitTimer)
    22132215                    goto leave;
    22142216                if (gConsole)
    22152217                    gConsole->PowerButton();
    2216                 gfACPITerm = false; /* don't try a second time */
     2218                gSdlQuitTimer = SDL_AddTimer(1000, QuitTimer, NULL);
    22172219                break;
    22182220            }
     
    43714373
    43724374/**
     4375 * Timer callback function to check if an ACPI power button event was handled by the guest.
     4376 */
     4377static Uint32 QuitTimer(Uint32 interval, void *param)
     4378{
     4379    PRBool fHandled = FALSE;
     4380
     4381    gSdlQuitTimer = NULL;
     4382    if (gConsole)
     4383    {
     4384        int rc = gConsole->GetPowerButtonHandled(&fHandled);
     4385        LogRel(("QuitTimer: rc=%d handled=%d\n", rc, fHandled));
     4386        if (VBOX_FAILURE(rc) || !fHandled)
     4387        {
     4388            /* event was not handled, power down the guest */
     4389            gfACPITerm = FALSE;
     4390            SDL_Event event = {0};
     4391            event.type = SDL_QUIT;
     4392            PushSDLEventForSure(&event);
     4393        }
     4394    }
     4395    /* one-shot */
     4396    return 0;
     4397}
     4398
     4399/**
    43734400 * Wait for the next SDL event. Don't use SDL_WaitEvent since this function
    43744401 * calls SDL_Delay(10) if the event queue is empty.
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r6658 r6852  
    15541554        setError (E_FAIL,
    15551555            tr ("Controlled power off failed (%Vrc)"), vrc);
     1556
     1557    LogFlowThisFunc (("rc=%08X\n", rc));
     1558    LogFlowThisFuncLeave();
     1559    return rc;
     1560}
     1561
     1562STDMETHODIMP Console::GetPowerButtonHandled(PRBool *aHandled)
     1563{
     1564    LogFlowThisFuncEnter();
     1565
     1566    AutoCaller autoCaller (this);
     1567
     1568    AutoLock lock (this);
     1569
     1570    if (mMachineState != MachineState_Running)
     1571        return E_FAIL;
     1572
     1573    /* protect mpVM */
     1574    AutoVMCaller autoVMCaller (this);
     1575    CheckComRCReturnRC (autoVMCaller.rc());
     1576
     1577    PPDMIBASE pBase;
     1578    int vrc = PDMR3QueryDeviceLun (mpVM, "acpi", 0, 0, &pBase);
     1579    bool handled = false;
     1580    if (VBOX_SUCCESS (vrc))
     1581    {
     1582        Assert (pBase);
     1583        PPDMIACPIPORT pPort =
     1584            (PPDMIACPIPORT) pBase->pfnQueryInterface(pBase, PDMINTERFACE_ACPI_PORT);
     1585        vrc = pPort ? pPort->pfnGetPowerButtonHandled(pPort, &handled) : VERR_INVALID_POINTER;
     1586    }
     1587
     1588    HRESULT rc = VBOX_SUCCESS (vrc) ? S_OK :
     1589        setError (E_FAIL,
     1590            tr ("Checking if poweroff was handled failed (%Vrc)"), vrc);
     1591
     1592    *aHandled = handled;
    15561593
    15571594    LogFlowThisFunc (("rc=%08X\n", rc));
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r6616 r6852  
    37683768    </method>
    37693769
     3770    <method name="getPowerButtonHandled">
     3771      <desc>Check if the last power button event was handled by guest.</desc>
     3772      <param name="handled" type="boolean" dir="return"/>
     3773    </method>
     3774
    37703775    <method name="saveState">
    37713776      <desc>
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r6464 r6852  
    127127    STDMETHOD(PowerButton)();
    128128    STDMETHOD(SleepButton)();
     129    STDMETHOD(GetPowerButtonHandled)(PRBool *aHandled);
    129130    STDMETHOD(SaveState) (IProgress **aProgress);
    130131    STDMETHOD(AdoptSavedState) (INPTR BSTR aSavedStateFile);
Note: See TracChangeset for help on using the changeset viewer.

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