4.4  EventRegister

PURPOSE
• Registers your application to receive Plug-and-Play and power management event notifications, according to a predefined set of criteria.
The function receives an event handler callback, which will be invoked upon the occurrence of a registered event.
PROTOTYPE
DWORD EventRegister(
    HANDLE *phEvent,
    HANDLE hWD,
    WD_EVENT *pEvent,
    EVENT_HANDLER pFunc,
    void *pData);
PARAMETERS
NameTypeInput/Output
phEventHANDLE*Output
hWDHANDLEInput
pEventWD_EVENT*Input
• handleDWORDOutput
• dwActionDWORDInput
• dwStatusDWORDN/A
• dwEventIdDWORDN/A
• dwCardTypeWD_BUS_TYPEInput
• hKernelPlugInDWORDInput
dwOptionsDWORDInput
• uunion 
 * Pcistruct 
   • cardIdWD_PCI_ID 
    * dwVendorIdDWORDInput
    * dwDeviceIdDWORDInput
   • pciSlotWD_PCI_SLOT
    * dwBusDWORDInput
    * dwSlotDWORDInput
    * dwFunctionDWORDInput
 * UsbstructInput
 * Pcmciastruct 
   • deviceIdWD_PCMCIA_ID 
    * wManufacturerIdWORDInput
    * wCardIdWORDInput
   • slotWD_PCMCIA_SLOT 
    * uBusBYTEInput
    * uSocketBYTEInput
    * uFunctionBYTEInput
    * uPaddingBYTEN/A
• dwEventVerDWORDN/A
• dwNumMatchTablesDWORDInput
• matchTablesWDU_MATCH_TABLE[1]Input
pFunctypedef void (*EVENT_HANDLER)(
WD_EVENT *pEvent,
void *pData);
Input
pDatavoidInput
DESCRIPTION
NameDescription
phEvent Pointer to the handle to be used in calls to EventUnregister [4.5], or NULL if the event registration fails.
hWDHandle to WinDriver's kernel-mode driver as received from WD_Open [5.2]
pEventThe criteria set for registering to receive event notifications.
• handle Optional handle to be used by the low-level WD_EventUnregister function; Zero when event registration fails.
• dwAction A bit-mask indicating which events to register to:
Plug-and-Play events:
WD_INSERT – Device was attached and configured by the operating system's Plug-and-Play manager
WD_REMOVE – Device was un-configured and detached by the operating system's Plug-and-Play manager
Device power state:
WD_POWER_CHANGED_D0 – Full power
WD_POWER_CHANGED_D1 – Low sleep
WD_POWER_CHANGED_D2 – Medium sleep
WD_POWER_CHANGED_D3 – Full sleep
WD_POWER_SYSTEM_WORKING – Fully on
Systems power state:
WD_POWER_SYSTEM_SLEEPING1 – Fully on but sleeping
WD_POWER_SYSTEM_SLEEPING2 – CPU off, memory on, PCI/PCMCIA on
WD_POWER_SYSTEM_SLEEPING3 – CPU off, memory is in refresh, PCI/PCMCIA on aux power
WD_POWER_SYSTEM_HIBERNATE – OS saves context before shutdown
WD_POWER_SYSTEM_SHUTDOWN – No context saved
• dwCardType Card type. Can be either WD_BUS_PCI – for a PCI card, WD_BUS_PCMCIA – for a PCMCIA card, or WD_BUS_USB – for a USB device (see the WD_BUS_TYPE enumeration values)
• hKernelPlugIn Handle to Kernel PlugIn returned from WD_KernelPlugInOpen [6.1] (when using the Kernel PlugIn to handle the events)
dwOptions Can be either zero or:
WD_ACKNOWLEDGE – If set, the user can perform actions on the requested event before acknowledging it. The OS waits on the event until the user calls WD_EventSend If EventRegister [4.4] is called, WD_EventSend will be called automatically after the callback function exits.
• uDevice information union:
 * PciPCI card information:
   • cardIdCard information structure:
    * dwVendorIdPCI vendor ID to register to. If zero, register to all PCI vendor IDs.
    * dwDeviceIdPCI card ID to register to. If zero, register to all PCI device IDs.
   • pciSlotPCI slot information:
    * dwBusPCI bus number to register to. If zero, register to all PCI buses.
    * dwSlotPCI slot to register to. If zero, register to all slots.
    * dwFunctionPCI function to register to. If zero, register to all functions.
 * UsbUSB device information – relevant only for USB devices
 * PcmciaPCMCIA card information:
   • deviceIdPCMCIA card ID information structure:
    * wManufacturerIdPCMCIA Manufacturer ID to register to. If zero, register to all PCMCIA manufacturer IDs.
    * wCardId PCMCIA card ID to register to. If zero, register to all PCMCIA card IDs.
   • slotPCMCIA slot information structure:
    * uBusPCMCIA bus number to register to. If zero, register to all PCMCIA buses.
    * uSocketPCMCIA socket to register to. If zero, register to all sockets.
    * uFunctionPCMCIA function to register to. If zero, register to all functions.
• dwNumMatchTablesRelevant only for USB devices
• matchTablesRelevant only for USB devices
pFuncThe callback function to call upon receipt of event notification.
pDataPointer to the data to pass to the pFunc callback (NULL if there is no data to pass).
RETURN VALUE
Returns WD_STATUS_SUCCESS(0) on success, or an appropriate error code otherwise [A].
REMARKS
EXAMPLE
HANDLE *event_handle;
WD_EVENT event;
DWORD dwStatus;
BZERO(event);
event.dwAction = WD_INSERT | WD_REMOVE;
event.dwCardType = WD_BUS_PCI;
dwStatus = EventRegister(&event_handle, hWD, &event,
    event_handler_func, NULL);
if (dwStatus!=WD_STATUS_SUCCESS)
{
    printf("Failed register\n");
    return;
}