libvirtualhid latest
Cross-platform C++ library for virtual HID devices.
lvh::Gamepad Class Referencefinal

Virtual gamepad device handle. More...

#include <src/include/libvirtualhid/runtime.hpp>

Inheritance diagram for lvh::Gamepad:
[legend]
Collaboration diagram for lvh::Gamepad:
[legend]

Public Member Functions

OperationStatus close () override
 Close the virtual device.
 
DeviceId device_id () const override
 Get the device identifier assigned by the runtime.
 
std::vector< DeviceNodedevice_nodes () const override
 Get platform-visible nodes associated with the device.
 
OperationStatus dispatch_output (const GamepadOutput &output)
 Dispatch an output event to the registered callback.
 
 Gamepad (const Gamepad &)=delete
 Copy construction is disabled because the handle owns device lifetime.
 
 Gamepad (detail::RuntimeConstructionToken token, std::shared_ptr< detail::GamepadDevice > device)
 Construct a gamepad handle for Runtime-owned state.
 
 Gamepad (Gamepad &&other) noexcept
 Move construct a gamepad handle.
 
bool is_open () const override
 Check whether the device is open.
 
std::vector< std::uint8_t > last_input_report () const
 Get the most recently packed input report.
 
GamepadState last_submitted_state () const
 Get the most recently submitted gamepad state.
 
const GamepadMetadatametadata () const
 Get the metadata supplied when the gamepad was created.
 
Gamepadoperator= (const Gamepad &)=delete
 Copy assignment is disabled because the handle owns device lifetime.
 
Gamepadoperator= (Gamepad &&other) noexcept
 Move assign a gamepad handle.
 
const DeviceProfileprofile () const override
 Get the profile used to create this device.
 
void set_output_callback (const OutputCallback &callback)
 Register a callback for backend output events.
 
OperationStatus submit (const GamepadState &state)
 Submit the latest gamepad input state.
 
std::size_t submit_count () const
 Get the number of successful submit operations.
 
 ~Gamepad () override
 Destroy the gamepad handle and close the virtual device if it is still open.
 
- Public Member Functions inherited from lvh::VirtualDevice
virtual ~VirtualDevice ()=default
 Destroy the virtual device handle.
 

Detailed Description

Virtual gamepad device handle.

Constructor & Destructor Documentation

◆ Gamepad() [1/2]

lvh::Gamepad::Gamepad ( Gamepad && other)
noexcept

Move construct a gamepad handle.

Parameters
otherHandle to move from.

◆ Gamepad() [2/2]

lvh::Gamepad::Gamepad ( detail::RuntimeConstructionToken token,
std::shared_ptr< detail::GamepadDevice > device )

Construct a gamepad handle for Runtime-owned state.

Parameters
tokenRuntime construction token.
deviceShared gamepad state.

Member Function Documentation

◆ close()

OperationStatus lvh::Gamepad::close ( )
overridevirtual

Close the virtual device.

Returns
Close operation status.

Implements lvh::VirtualDevice.

◆ device_id()

DeviceId lvh::Gamepad::device_id ( ) const
overridevirtual

Get the device identifier assigned by the runtime.

Returns
Device identifier.

Implements lvh::VirtualDevice.

◆ device_nodes()

std::vector< DeviceNode > lvh::Gamepad::device_nodes ( ) const
overridevirtual

Get platform-visible nodes associated with the device.

Returns
Device nodes and diagnostic paths currently known to the backend.

Implements lvh::VirtualDevice.

◆ dispatch_output()

OperationStatus lvh::Gamepad::dispatch_output ( const GamepadOutput & output)

Dispatch an output event to the registered callback.

Parameters
outputOutput event.
Returns
Dispatch operation status.

◆ is_open()

bool lvh::Gamepad::is_open ( ) const
overridevirtual

Check whether the device is open.

Returns
true when the device can accept operations.

Implements lvh::VirtualDevice.

◆ last_input_report()

std::vector< std::uint8_t > lvh::Gamepad::last_input_report ( ) const

Get the most recently packed input report.

Returns
Last input report bytes.

◆ last_submitted_state()

GamepadState lvh::Gamepad::last_submitted_state ( ) const

Get the most recently submitted gamepad state.

Returns
Last submitted state.

◆ metadata()

const GamepadMetadata & lvh::Gamepad::metadata ( ) const

Get the metadata supplied when the gamepad was created.

Returns
Gamepad metadata.

◆ operator=() [1/2]

Gamepad & lvh::Gamepad::operator= ( const Gamepad & )
delete

Copy assignment is disabled because the handle owns device lifetime.

Returns
This gamepad handle.

◆ operator=() [2/2]

Gamepad & lvh::Gamepad::operator= ( Gamepad && other)
noexcept

Move assign a gamepad handle.

Parameters
otherHandle to move from.
Returns
This gamepad handle.

◆ profile()

const DeviceProfile & lvh::Gamepad::profile ( ) const
overridevirtual

Get the profile used to create this device.

Returns
Device profile.

Implements lvh::VirtualDevice.

◆ set_output_callback()

void lvh::Gamepad::set_output_callback ( const OutputCallback & callback)

Register a callback for backend output events.

Parameters
callbackOutput callback copied into the handle. Passing an empty callback clears it.

◆ submit()

OperationStatus lvh::Gamepad::submit ( const GamepadState & state)

Submit the latest gamepad input state.

Parameters
stateGamepad input state.
Returns
Submit operation status.

◆ submit_count()

std::size_t lvh::Gamepad::submit_count ( ) const

Get the number of successful submit operations.

Returns
Submit count.

The documentation for this class was generated from the following file: