Export (0) Print
Expand All

ISensorDriver::OnClientSubscribeToEvents method

The ISensorDriver::OnClientSubscribeToEvents method notifies the sensor driver that an authorized client application is requesting event notifications.

Syntax


HRESULT OnClientSubscribeToEvents(
  [in]  IWDFFile *pClientFile,
  [in]  LPWSTR pwszSensorID
);

Parameters

pClientFile [in]

Pointer to an IWDFFile interface that represents the file object for the application requesting event notifications.

pwszSensorID [in]

LPWSTR that contains the ID for the sensor from which the client application is requesting event notifications.

Return value

If the operation succeeds, this method returns S_OK. Otherwise, this method returns one of the error codes that are defined in Winerror.h.

Remarks

When a client application requests event notifications, the driver raises all events to the sensor class extension for the specified object ID. The class extension then forwards these events to the Sensor API as event notifications for applications.

You can maintain a reference count of connected applications for each sensor to avoid making event callbacks when not required.

Platform-defined events are defined in sensors.h.

For more information about how to use this method, see Filtering data.

Examples

The following example code demonstrates an implementation of ISensorDriver::OnClientSubscribeToEvents. This function uses an ATL simple map, named Clients, to keep track of connected clients. See ISensorDriver::OnClientConnect for an example of how connected clients are added to the map.


HRESULT CSensorDdi::OnClientSubscribeToEvents(
        __in IWDFFile* pClientFile,
        __in LPWSTR pwszSensorID
        )
{
    if(NULL == pClientFile ||
       NULL == pwszSensorID)
    {
        return E_POINTER;
    }

    HRESULT hr = S_OK;
    ClientData* pCD = NULL;

    if(m_cEventClients == 0)
    {
        // Create the event class.
        m_pSampleEvents = new(CSampleEvents);

        if(NULL == m_pSampleEvents)
        {
            hr = E_OUTOFMEMORY;
        }

        if(SUCCEEDED(hr))
        {
            // Initialize the event class.
            hr = m_pSampleEvents->Initialize(m_spSensorCXT, this, m_ulReportInterval);
        }
    }

    m_cEventClients++;

    pCD = Clients.Lookup(pClientFile);
    if(NULL == pCD)
    {
        hr = E_UNEXPECTED;
    }

    if(SUCCEEDED(hr))
    {
        // Mark this client as an event listener.
        pCD->bListening = TRUE;

        // Update the actual report interval by calling
        // a custom helper function. See Managing Report
        // Intervals for an example.
        m_ulReportInterval = GetNewReportInterval();

        // Notify the event class about the new interval.
        if(NULL != m_pSampleEvents)
        {
            m_pSampleEvents->SetInterval((DWORD)m_ulReportInterval);
        }
    }

    return hr;
}

Requirements

Minimum supported client

Windows 7

Minimum supported server

None supported

Version

Available in Windows 7.

Header

Sensorsclassextension.h

Library

SensorsClassExtension.lib

See also

ISensorClassExtension::PostEvent
ISensorClassExtension::PostStateChange
ISensorDriver::OnClientUnsubscribeFromEvents

 

 

Send comments about this topic to Microsoft

Show:
© 2014 Microsoft