ISensorDriver::OnClientUnsubscribeFromEvents method

The ISensorDriver::OnClientUnsubscribeFromEvents method notifies the sensor driver that a client application no longer requests event notifications.

Syntax


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

Parameters

pClientFile [in]

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

pwszSensorID

LPWSTR that contains the ID for the sensor from which the client application is requesting cancellation of 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

The sensor class extension calls this method in the following instances:

  • An application unsubscribes from events.

  • An application closes normally.

  • The user revokes permission for an application to access the device that contains the specified sensor.

  • The sensor class extension is shutting down.

  • The cleanup work from a call to ISensorClassExtension::CleanupFile has completed.

You can use this call as a signal to update the reference count of applications requesting events for the specified sensor.

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

The ClientData structure is defined as follows.

Examples

The following example code demonstrates an implementation of ISensorDriver::OnClientUnsubscribeFromEvents. 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.


// Struct to keep track of connected client status.
struct ClientData
{
    BOOL bListening;  // Client is listening to events.
    ULONG ulInterval;  // Interval requested by client.
};

The function definition follows.


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

    HRESULT hr = S_OK;
    ClientData* pCD = NULL;
    BOOL bCurrent = FALSE;

    if(m_cEventClients > 0)
    {
        // Decrement the count of event listeners.
        m_cEventClients--;
    }

    // Find the client that is unsubscribing.
    pCD = Clients.Lookup(pClientFile);
    if(NULL == pCD)
    {
        hr = E_UNEXPECTED;
    }

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

    if(SUCCEEDED(hr))
    {
        // Test whether the current report interval equals
        // the one set by this client.
        // There may be multiple clients that requested the
        // same interval, but we have no way of knowing that.
        if(pCD->ulInterval == m_ulReportInterval)
        {
            bCurrent = TRUE;
        }

        // Update the actual report interval.
        m_ulReportInterval = GetNewReportInterval();
    }

    if(m_cEventClients == 0 &&
    m_pSampleEvents != NULL)
    {
        // No clients listening to events.
        // This case will also occur when the class extension
        // shuts down.
        hr = m_pSampleEvents->Uninitialize();

        // Destroy the event class.
        delete m_pSampleEvents;
        m_pSampleEvents = NULL;

        // Return to the default interval.
        m_ulReportInterval = (ULONG) g_dwDefaultInterval;
    }
    else if(SUCCEEDED(hr) && bCurrent == TRUE)
    {
        // Notify the event class about the new interval.
        if(NULL != m_pSampleEvents)
        {
            Lock();

            m_pSampleEvents->SetInterval((DWORD)m_ulReportInterval);

            Unlock();
        }
    }

    return hr;
}

Requirements

Minimum supported client

Windows 7

Minimum supported server

None supported

Target platform

Desktop

Version

Available in Windows 7.

Header

Sensorsclassextension.h

Library

SensorsClassExtension.lib

See also

ISensorClassExtension::PostEvent
ISensorClassExtension::PostStateChange
ISensorDriver::OnClientSubscribeToEvents

 

 

Send comments about this topic to Microsoft

Show:
© 2015 Microsoft