VirtualBox

Changeset 13495 in vbox


Ignore:
Timestamp:
Oct 22, 2008 2:51:14 PM (16 years ago)
Author:
vboxsync
Message:

Register power state change callback handler.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/win/SUPDrv-win.cpp

    r12161 r13495  
    7878static int                 VBoxDrvNtDeviceControlSlow(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PIRP pIrp, PIO_STACK_LOCATION pStack);
    7979static NTSTATUS _stdcall   VBoxDrvNtInternalDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp);
     80static VOID     _stdcall   VBoxPowerDispatchCallback(PVOID pCallbackContext, PVOID pArgument1, PVOID pArgument2);
    8081static NTSTATUS _stdcall   VBoxDrvNtNotSupportedStub(PDEVICE_OBJECT pDevObj, PIRP pIrp);
    8182static NTSTATUS            VBoxDrvNtErr2NtStatus(int rc);
     
    142143                    pDrvObj->MajorFunction[IRP_MJ_READ]                     = VBoxDrvNtNotSupportedStub;
    143144                    pDrvObj->MajorFunction[IRP_MJ_WRITE]                    = VBoxDrvNtNotSupportedStub;
     145
    144146                    /* more? */
     147
     148                    /* Register ourselves for power state changes. */
     149                    UNICODE_STRING      CallbackName;
     150                    OBJECT_ATTRIBUTES   Attr;
     151
     152                    RtlInitUnicodeString(&CallbackName, L"\\Callback\\PowerState");
     153                        InitializeObjectAttributes(&Attr, &CallbackName, OBJ_CASE_INSENSITIVE, NULL, NULL);
     154
     155                        rc = ExCreateCallback(&pDevExt->pObjPowerCallback, &Attr, TRUE, TRUE);
     156                    if (rc == STATUS_SUCCESS)
     157                                pDevExt->hPowerCallback = ExRegisterCallback(pDevExt->pObjPowerCallback, VBoxPowerDispatchCallback, pDevObj);
     158
    145159                    dprintf(("VBoxDrv::DriverEntry   returning STATUS_SUCCESS\n"));
    146160                    return STATUS_SUCCESS;
     
    184198
    185199    dprintf(("VBoxDrvNtUnload at irql %d\n", KeGetCurrentIrql()));
     200
     201    /* Clean up the power callback registration. */
     202    if (pDevExt->hPowerCallback)
     203        ExUnregisterCallback(pDevExt->hPowerCallback);
     204    if (pDevExt->pObjPowerCallback)
     205        ObDereferenceObject(pDevExt->pObjPowerCallback);
    186206
    187207    /*
     
    500520
    501521/**
     522 * ExRegisterCallback handler for power events
     523 *
     524 * @param   pCallbackContext    User supplied parameter (pDevObj)
     525 * @param   pArgument1          First argument
     526 * @param   pArgument2          Second argument
     527 */
     528VOID _stdcall VBoxPowerDispatchCallback(PVOID pCallbackContext, PVOID pArgument1, PVOID pArgument2)
     529{
     530    PDEVICE_OBJECT pDevObj = (PDEVICE_OBJECT)pCallbackContext;
     531
     532    dprintf(("VBoxPowerDispatchCallback: %x %x\n", pArgument1, pArgument2));
     533
     534    /* Power change imminent? */
     535    if ((unsigned)pArgument1 == PO_CB_SYSTEM_STATE_LOCK)
     536    {
     537        if ((unsigned)pArgument2 == 0)
     538            dprintf(("VBoxPowerDispatchCallback: about to go into suspend mode!\n"));
     539        else
     540            dprintf(("VBoxPowerDispatchCallback: resumed!\n"));
     541    }
     542}
     543
     544
     545/**
    502546 * Initializes any OS specific object creator fields.
    503547 */
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