I?m improving an HID filter driver that supports up to 15 Force Feedback (FFB) HID devices.
Each HID device is represented by a raw PDO (There is a single parent FDO device).
Its current architecture allows multiple DirectInput feeding applications, each sending its FFB data to one or more of the (raw PDO) HID devices.
There is also a ?Client? application that is receiving the FFB data and activates corresponding actuators.
The client gets a file handle to one of the raw devices like this:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
h = CreateFile ( deviceInterfaceDetailData->DevicePath,
GENERIC_READ | GENERIC_WRITE,
0,
NULL, // no SECURITY_ATTRIBUTES structure
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL);
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Then, the client constantly reads the FFB data from the device using overlapped I/O operation:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
do
{
// This is an async (overlapped) transaction
memset(&FfbOverlapped,0, sizeof(OVERLAPPED));
FfbOverlapped.hEvent = hIoctlEvent;
DeviceIoControl(h, GET_FFB_DATA, NULL, 0, &FfbData, IoSize, &bytes, &FfbOverlapped);
gotdata = GetOverlappedResult(h, &FfbOverlapped, &nBytesTranss, TRUE);
if (gotdata && nBytesTranss && nBytesTranss<=BUFFERSIZE && nBytesTranss>0)
FfbSendData(FfbData, nBytesTranss);
} while (nBytesTranss);
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Data Flow inside the driver:
Every Request received at the filter device as IOCTL_HID_WRITE_REPORT IOCTL is requeued into a manual queue ?FfbWriteQueue?.
Whenever the overlapped operation has posted a Request on the manual queue ?FfbReadQueue?, the FFB data waiting on the ?FfbWriteQueue? is copied to the ?FfbReadQueue? and both requests are completed.
This works fine but the FFB data destined to different devices are mixed on the same queue.
As long as there is only one client application, this is not a problem since the destination of the FFB reports is marked on the reports. However, if there are several clients, I get a race.
Here?s my question:
Do you recommend creating 15 FfbReadQueue/FfbWriteQueus pairs - each one associated with the corresponding PDO - so that with every arriving request, it will be directed to the corresponding pair of queues.
OR
Use WdfIoQueueFindRequest on a single FfbReadQueue - exstracting the FFB request corresponding to the open file (=raw PDO).