diff options
| author | J M Rossy <[email protected]> | 2015-07-29 15:40:09 -0700 |
|---|---|---|
| committer | J M Rossy <[email protected]> | 2015-07-29 16:34:40 -0700 |
| commit | 5d61a4a79a1e96dc5d9af1e5e712c84507307544 (patch) | |
| tree | 49ed270893578cd18758b74ffcca16dc7ab948d6 /pos/drivers/barcodescanner/Device.cpp | |
| parent | 5d41613e26e147d2300c786bb2b34cb4b4067a25 (diff) | |
Samples update for public Windows 10 release
Fix #2 Enabling WPP Recorder in Sensors Samples causes errors
Fix #4 Add back fixed KMDOD sample
Add new BarcodeScanner sample in pos folder
Add new MagneticStripeReader sample in pos folder
Add new SynpaticsTouch sample in input folder
Add new Power Engine Plugin sample in pofx folder
Add new DeviceMft sample in avstream folder
Add new AvsCamera sample in root
Add new SimBatt sample in root
Add other pre-existing samples not yet released for Win10
Diffstat (limited to 'pos/drivers/barcodescanner/Device.cpp')
| -rw-r--r-- | pos/drivers/barcodescanner/Device.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/pos/drivers/barcodescanner/Device.cpp b/pos/drivers/barcodescanner/Device.cpp new file mode 100644 index 00000000..d122e60a --- /dev/null +++ b/pos/drivers/barcodescanner/Device.cpp @@ -0,0 +1,101 @@ +#include <pch.h> + +#include "File.h" +#include "PosEvents.h" +#include "Ioctl.h" +#include "IoRead.h" + +/* +** Driver TODO: Complete the implementation of EvtDriverDeviceAdd for your specific device. +** +** WDF calls this callback when a device instance is added to the driver. Good drivers will do a lot of +** work here to set up everything necessary, such as adding callbacks for PNP power state changes. +** This function defines an IO queue for handling DeviceIoControl and file read requests, both of which are +** important to the POS barcode scanner model. +** +** Note that this is not a complete device add implementation, as the PNP power callbacks are not handled. +** Additionally, driver writers may wish to set up additional queues to serialize device property requests +** (see Ioctl.cpp for more info). +*/ +NTSTATUS EvtDriverDeviceAdd(_In_ WDFDRIVER /* UnusedDriver */, _Inout_ PWDFDEVICE_INIT DeviceInit) +{ + NTSTATUS status = STATUS_SUCCESS; + WDF_FILEOBJECT_CONFIG fileConfig; + WDF_OBJECT_ATTRIBUTES deviceAttributes; + WDF_OBJECT_ATTRIBUTES fileAttributes; + WDFDEVICE device; + + // Handle file events + WDF_FILEOBJECT_CONFIG_INIT( + &fileConfig, + EvtDeviceFileCreate, + EvtFileClose, + WDF_NO_EVENT_CALLBACK + ); + + WDF_OBJECT_ATTRIBUTES_INIT(&fileAttributes); + WdfDeviceInitSetFileObjectConfig( + DeviceInit, + &fileConfig, + &fileAttributes + ); + + // Create Device + WDF_OBJECT_ATTRIBUTES_INIT(&deviceAttributes); + status = WdfDeviceCreate( + &DeviceInit, + &deviceAttributes, + &device + ); + + if (!NT_SUCCESS(status)) + { + return status; + } + + // Create a device interface for POS Barcode Scanner so that the device can be enumerated + status = WdfDeviceCreateDeviceInterface( + device, + &GUID_DEVINTERFACE_POS_SCANNER, + NULL + ); + + if (!NT_SUCCESS(status)) + { + return status; + } + + // Initialize the POS library + POS_CX_ATTRIBUTES posCxAttributes; + POS_CX_ATTRIBUTES_INIT(&posCxAttributes); + posCxAttributes.EvtDeviceOwnershipChange = EvtDeviceOwnershipChange; + + status = PosCxInit(device, &posCxAttributes); + + if (!NT_SUCCESS(status)) + { + return status; + } + + // Set up an IO queue to handle DeviceIoControl and ReadFile + WDF_IO_QUEUE_CONFIG queueConfig; + WDF_OBJECT_ATTRIBUTES attributes; + WDFQUEUE queue; + + WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&queueConfig, WdfIoQueueDispatchSequential); + queueConfig.EvtIoDeviceControl = EvtIoDeviceControl; + queueConfig.EvtIoRead = EvtIoRead; + + // Call us in PASSIVE_LEVEL + WDF_OBJECT_ATTRIBUTES_INIT(&attributes); + attributes.ExecutionLevel = WdfExecutionLevelPassive; + + status = WdfIoQueueCreate( + device, + &queueConfig, + &attributes, + &queue + ); + + return status; +} |
