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

Caches a full gamepad state and resubmits it after partial updates. More...

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

Public Member Functions

OperationStatus clear_battery ()
 Clear battery metadata and submit the full cached state.
 
OperationStatus clear_motion ()
 Clear motion data and submit the full cached state.
 
OperationStatus clear_touchpad_contact (std::size_t index)
 Clear one touchpad contact and submit the full cached state.
 
OperationStatus close ()
 Close the owned gamepad.
 
OperationStatus dispatch_output (const GamepadOutput &output)
 Dispatch an output event to the owned gamepad callback.
 
Gamepadgamepad ()
 Get the owned gamepad handle.
 
const Gamepadgamepad () const
 Get the owned gamepad handle.
 
 GamepadStateAdapter (const GamepadStateAdapter &)=delete
 Copy construction is disabled because the adapter owns the gamepad handle.
 
 GamepadStateAdapter (GamepadStateAdapter &&other) noexcept
 Move construct an adapter.
 
 GamepadStateAdapter (std::unique_ptr< Gamepad > gamepad)
 Construct an adapter around a created gamepad handle.
 
bool is_open () const
 Check whether the owned gamepad is open.
 
GamepadStateAdapteroperator= (const GamepadStateAdapter &)=delete
 Copy assignment is disabled because the adapter owns the gamepad handle.
 
GamepadStateAdapteroperator= (GamepadStateAdapter &&other) noexcept
 Move assign an adapter.
 
OperationStatus set_acceleration (std::optional< Vector3 > acceleration)
 Update accelerometer data and submit the full cached state.
 
OperationStatus set_battery (GamepadBattery battery)
 Update battery metadata and submit the full cached state.
 
OperationStatus set_button (GamepadButton button, bool pressed)
 Update one logical button and submit the full cached state.
 
OperationStatus set_gyroscope (std::optional< Vector3 > gyroscope)
 Update gyroscope data and submit the full cached state.
 
OperationStatus set_left_stick (Stick stick)
 Update the left stick and submit the full cached state.
 
OperationStatus set_left_trigger (float value)
 Update the left trigger and submit the full cached state.
 
OperationStatus set_motion (Vector3 acceleration, Vector3 gyroscope)
 Update accelerometer and gyroscope data and submit the full cached state.
 
void set_output_callback (const OutputCallback &callback)
 Register a callback for backend output events.
 
OperationStatus set_right_stick (Stick stick)
 Update the right stick and submit the full cached state.
 
OperationStatus set_right_trigger (float value)
 Update the right trigger and submit the full cached state.
 
OperationStatus set_state (const GamepadState &state)
 Replace and submit the cached full gamepad state.
 
OperationStatus set_touchpad_contact (std::size_t index, GamepadTouchContact contact)
 Update one touchpad contact and submit the full cached state.
 
const GamepadStatestate () const
 Get the cached full gamepad state.
 
OperationStatus submit ()
 Submit the cached full gamepad state.
 
const GamepadProfileSupportsupport () const
 Get profile support flags captured at creation time.
 
 ~GamepadStateAdapter ()
 Destroy the adapter and close the owned gamepad if still open.
 

Static Public Member Functions

static GamepadAdapterCreationResult create (Runtime &runtime, const CreateGamepadOptions &options)
 Create a gamepad and wrap it in a state adapter.
 

Detailed Description

Caches a full gamepad state and resubmits it after partial updates.

Constructor & Destructor Documentation

◆ GamepadStateAdapter() [1/2]

lvh::GamepadStateAdapter::GamepadStateAdapter ( GamepadStateAdapter && other)
noexcept

Move construct an adapter.

Parameters
otherAdapter to move from.

◆ GamepadStateAdapter() [2/2]

lvh::GamepadStateAdapter::GamepadStateAdapter ( std::unique_ptr< Gamepad > gamepad)
explicit

Construct an adapter around a created gamepad handle.

Parameters
gamepadGamepad handle owned by the adapter.

Member Function Documentation

◆ clear_battery()

OperationStatus lvh::GamepadStateAdapter::clear_battery ( )

Clear battery metadata and submit the full cached state.

Returns
Submit operation status.

◆ clear_motion()

OperationStatus lvh::GamepadStateAdapter::clear_motion ( )

Clear motion data and submit the full cached state.

Returns
Submit operation status.

◆ clear_touchpad_contact()

OperationStatus lvh::GamepadStateAdapter::clear_touchpad_contact ( std::size_t index)

Clear one touchpad contact and submit the full cached state.

Parameters
indexTouchpad contact slot.
Returns
Submit operation status.

◆ close()

OperationStatus lvh::GamepadStateAdapter::close ( )

Close the owned gamepad.

Returns
Close operation status.

◆ create()

static GamepadAdapterCreationResult lvh::GamepadStateAdapter::create ( Runtime & runtime,
const CreateGamepadOptions & options )
static

Create a gamepad and wrap it in a state adapter.

Parameters
runtimeRuntime used to create the gamepad.
optionsGamepad creation options.
Returns
Adapter creation result.

◆ dispatch_output()

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

Dispatch an output event to the owned gamepad callback.

Parameters
outputOutput event.
Returns
Dispatch operation status.

◆ gamepad() [1/2]

Gamepad * lvh::GamepadStateAdapter::gamepad ( )

Get the owned gamepad handle.

Returns
Owned gamepad handle, or nullptr after move.

◆ gamepad() [2/2]

const Gamepad * lvh::GamepadStateAdapter::gamepad ( ) const

Get the owned gamepad handle.

Returns
Owned gamepad handle, or nullptr after move.

◆ is_open()

bool lvh::GamepadStateAdapter::is_open ( ) const

Check whether the owned gamepad is open.

Returns
true when the owned gamepad can accept operations.

◆ operator=() [1/2]

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

Copy assignment is disabled because the adapter owns the gamepad handle.

Returns
This adapter.

◆ operator=() [2/2]

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

Move assign an adapter.

Parameters
otherAdapter to move from.
Returns
This adapter.

◆ set_acceleration()

OperationStatus lvh::GamepadStateAdapter::set_acceleration ( std::optional< Vector3 > acceleration)

Update accelerometer data and submit the full cached state.

Parameters
accelerationAccelerometer data, or std::nullopt to clear it.
Returns
Submit operation status.

◆ set_battery()

OperationStatus lvh::GamepadStateAdapter::set_battery ( GamepadBattery battery)

Update battery metadata and submit the full cached state.

Parameters
batteryBattery metadata.
Returns
Submit operation status.

◆ set_button()

OperationStatus lvh::GamepadStateAdapter::set_button ( GamepadButton button,
bool pressed )

Update one logical button and submit the full cached state.

Parameters
buttonLogical button to update.
pressedWhether the button is pressed.
Returns
Submit operation status.

◆ set_gyroscope()

OperationStatus lvh::GamepadStateAdapter::set_gyroscope ( std::optional< Vector3 > gyroscope)

Update gyroscope data and submit the full cached state.

Parameters
gyroscopeGyroscope data, or std::nullopt to clear it.
Returns
Submit operation status.

◆ set_left_stick()

OperationStatus lvh::GamepadStateAdapter::set_left_stick ( Stick stick)

Update the left stick and submit the full cached state.

Parameters
stickLeft stick state.
Returns
Submit operation status.

◆ set_left_trigger()

OperationStatus lvh::GamepadStateAdapter::set_left_trigger ( float value)

Update the left trigger and submit the full cached state.

Parameters
valueNormalized left trigger value.
Returns
Submit operation status.

◆ set_motion()

OperationStatus lvh::GamepadStateAdapter::set_motion ( Vector3 acceleration,
Vector3 gyroscope )

Update accelerometer and gyroscope data and submit the full cached state.

Parameters
accelerationAccelerometer data.
gyroscopeGyroscope data.
Returns
Submit operation status.

◆ set_output_callback()

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

Register a callback for backend output events.

Parameters
callbackOutput callback copied into the owned gamepad.

◆ set_right_stick()

OperationStatus lvh::GamepadStateAdapter::set_right_stick ( Stick stick)

Update the right stick and submit the full cached state.

Parameters
stickRight stick state.
Returns
Submit operation status.

◆ set_right_trigger()

OperationStatus lvh::GamepadStateAdapter::set_right_trigger ( float value)

Update the right trigger and submit the full cached state.

Parameters
valueNormalized right trigger value.
Returns
Submit operation status.

◆ set_state()

OperationStatus lvh::GamepadStateAdapter::set_state ( const GamepadState & state)

Replace and submit the cached full gamepad state.

Parameters
stateNew full gamepad state.
Returns
Submit operation status.

◆ set_touchpad_contact()

OperationStatus lvh::GamepadStateAdapter::set_touchpad_contact ( std::size_t index,
GamepadTouchContact contact )

Update one touchpad contact and submit the full cached state.

Parameters
indexTouchpad contact slot.
contactTouchpad contact state.
Returns
Submit operation status.

◆ state()

const GamepadState & lvh::GamepadStateAdapter::state ( ) const

Get the cached full gamepad state.

Returns
Cached gamepad state.

◆ submit()

OperationStatus lvh::GamepadStateAdapter::submit ( )

Submit the cached full gamepad state.

Returns
Submit operation status.

◆ support()

const GamepadProfileSupport & lvh::GamepadStateAdapter::support ( ) const

Get profile support flags captured at creation time.

Returns
Profile support summary.

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