Class GorgonGamingDeviceDriver
The required functionality for a gaming device driver.
Inherited Members
Namespace: Gorgon.Input
Assembly: Gorgon.Input.dll
Syntax
public abstract class GorgonGamingDeviceDriver : GorgonPlugIn, IGorgonGamingDeviceDriver, IGorgonNamedObject, IDisposable
Remarks
A gaming device driver provides access to various gaming input devices like a joystick, game pad, etc... This allows for various input providers to be used when accessing these devices. For example, Gorgon comes with 2 drivers: One for XBOX controllers (via XInput), and one for generic joysticks/game pads (via Direct Input).
important
The XInput driver does not enumerate or use any other type of controllers other than XBox controllers, and the Direct Input driver purposely ignores XBox controllers so that only generic devices get enumerated. This is done because the XInput controller provides more features for the XBox controllers, and the mapping of the device interface (i.e. axes, POV, etc...) is not as straight forward.
These drivers are typically loaded as plug ins from a IGorgonGamingDeviceDriverFactory. The driver is responsible for enumerating the available devices that it supports, and will create instances of a IGorgonGamingDevice that represents the functionality of the gaming device as provided by the underlying native provider.
Because drivers may need to set up native resources for internal use, this interface implements IDisposable, and in order to avoid leakage of resource data, the Dispose() method must be called when done with the driver.
Examples
LoadPlugInAssemblies(string, string) The following shows how to load a IGorgonGamingDeviceDriver and enumerate the devices:
IReadOnlyList<GorgonGamingDeviceInfo> joysticks = null;
using (var assemblies = new GorgonMefPlugInCache())
{
IGorgonPlugInService plugInService = new GorgonMefPlugInService(assemblies);
var factory = new GorgonGamingDeviceDriverFactory(plugInService);
// Load the assembly for the XInput driver.
assemblies.LoadAssemblies(".\", "Gorgon.Input.XInput.dll");
// Get the correct driver from the plug ins via the factory.
IGorgonGamingDeviceDriver driver = factory.Load("Gorgon.Input.GorgonXInputDriver");
// Get connected devices only. You may change the parameter to false to retrieve all devices.
joysticks = driver.EnumerateGamingDevices(true);
foreach(IGorgonGamingDeviceInfo info in joysticks)
{
Console.WriteLine($"Controller: {info.Description}");
}
}
Constructors
| Edit this page View SourceGorgonGamingDeviceDriver(string)
Initializes a new instance of the GorgonGamingDeviceDriver class.
Declaration
protected GorgonGamingDeviceDriver(string description)
Parameters
Type | Name | Description |
---|---|---|
string | description | The human readable description of the driver. |
Properties
| Edit this page View SourceLog
Property to return the logger used for debugging.
Declaration
protected IGorgonLog Log { get; }
Property Value
Type | Description |
---|---|
IGorgonLog |
Methods
| Edit this page View SourceCreateGamingDevice(IGorgonGamingDeviceInfo)
Function to create a GorgonGamingDevice object.
Declaration
public abstract IGorgonGamingDevice CreateGamingDevice(IGorgonGamingDeviceInfo gamingDeviceInfo)
Parameters
Type | Name | Description |
---|---|---|
IGorgonGamingDeviceInfo | gamingDeviceInfo | The IGorgonGamingDeviceInfo used to determine which device to associate with the resulting object. |
Returns
Type | Description |
---|---|
IGorgonGamingDevice | A GorgonGamingDevice representing the data from the physical device. |
Remarks
This will create a new instance of a IGorgonGamingDevice which will relay data from the physical device using the native provider.
Some devices may allocate native resources in order to communicate with the underlying native providers, and because of this, it is important to call the Dispose() method on the object when you are done with the object so that those resources may be freed.
CreateGamingDevices(bool)
Function to create all GorgonGamingDevice objects for this driver.
Declaration
public IReadOnlyList<IGorgonGamingDevice> CreateGamingDevices(bool connectedOnly = false)
Parameters
Type | Name | Description |
---|---|---|
bool | connectedOnly | [Optional] true to only include connected gaming devices, false to include all devices. |
Returns
Type | Description |
---|---|
IReadOnlyList<IGorgonGamingDevice> | A list of of GorgonGamingDevice objects for this driver. |
Remarks
This will create an instance of IGorgonGamingDevice for all devices supported by the driver at one time and return a list containing those instances.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
Remarks
For implementors of a GorgonGamingDeviceDriver this dispose method is used to clean up any native resources that may be allocated by the driver. In such a case, put the clean up code for the native resources in an override of this method. If the driver does not use native resources, then this method should be left alone.
Dispose(bool)
Releases unmanaged and - optionally - managed resources.
Declaration
protected abstract void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing |
|
EnumerateGamingDevices(bool)
Function to enumerate the gaming devices supported by this driver.
Declaration
public abstract IReadOnlyList<IGorgonGamingDeviceInfo> EnumerateGamingDevices(bool connectedOnly = false)
Parameters
Type | Name | Description |
---|---|---|
bool | connectedOnly | [Optional] true to only enumerate devices that are connected, or false to enumerate all devices. |
Returns
Type | Description |
---|---|
IReadOnlyList<IGorgonGamingDeviceInfo> | A read only list of gaming device info values. |
Remarks
This will return only the devices supported by the driver. In some cases, the driver may not return a complete listing of all gaming devices attached to the system because the underlying provider may not support those device types.