Yes, that is a good design with one exception on how you store the list
of WDFMEMORYs.
Adds to a WDFCOLLECTION can fail since they require an allocation.
Instead, you can put a LIST_ENTRY in the WDFMEMORY context and avoid an
extra point of failure. The context will be there automatically if you
specify WDF_USB_CONTINUOUS_READER_CONFIG:: BufferAttributes when
configuring the continuous reader. Put the WDFMEMORYs into a LIST_ENTRY
list head in the device context. To get back to the WDFMEMORY from its
context, you can do something like this by calling
WdfObjectContextGetObject()
struct READER_CONTEXT {
LIST_ENTRY Link;
};
Struct DEVICE_CONTEXT {
LIST_ENTRY ListHead;
}
PLIST_ENTRY ple = RemoveListHead(&DeviceContext->ListHead);
READER_CONTEXT* pReaderContext = CONTAINING_RECORD(ple, READER_CONTEXT,
Link);
WDFMEMORY memory = (WDFMEMORY)
WdfObjectContextGetObject(pReaderContext);
d
– I can spell, I just can’t type.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Paolo Cazzola
Sent: Saturday, May 06, 2006 7:39 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] usb pipe continuous reader and user requests
Hi all,
I am currently converting a WDM USB function driver to KMDF 1.0.
The device always needs pending read so I presume to use a continuous
reader for input pipes.
Now I have the problem to connect user application read events to
continous reader completion callbacks.
I think to use the following design pattern:
Actors:
- EvtIoRead for a sequential dispatch queue
- PipeReadComplete callback
- EvtRequestCancel to cancel current pending WDFREQUEST
- WDFCOLLECTION of WDFMEMORY objects to cache data
- WDFSPINLOCK to synchronize operations
Logic (simplified):
EvtIoRead()
IF WDFCOLLECTION is empty
Save WDFREQUEST in device context
Enable cancellation on such a request (WdfRequestMarkCancelable)
ELSE
Get first WDFMEMORY from WDFCOLLECTION
Use WDFMEMORY data to fill WDFREQUEST
Dereference WDFMEMORY object
Complete WDFREQUEST
ENDIF
PipeReadComplete()
IF there is a pending WDFREQUEST in device context
Use incoming WDFMEMORY to fill WDFREQUEST
Disable cancellation on such a request
(WdfRequestUnmarkCancelable)
Complete WDFREQUEST
ELSE
Add reference to incoming WDFMEMORY
Push incoming WDFMEMORY to WDFCOLLECTION
ENDIF
EvtRequestCancel ()
Remove WDFREQUEST from device context
Question:
Is this a valid pattern or there is some better way to decouple user
requests with receive callbacks.
Best regards,
PaoloC
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer