windows.gaming.input: Import IAsyncOperation from windows.media.speech.
Adapting it for the IAsyncOperation_boolean interface and use it to implement IForceFeedbackMotor_Try(Enable|Disable|Reset)Async. Signed-off-by: Rémi Bernon <rbernon@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
a7d67c1c90
commit
730b35ba46
|
@ -4482,7 +4482,7 @@ static void check_bool_async_( int line, IAsyncOperation_boolean *async, UINT32
|
|||
hr = IAsyncInfo_get_ErrorCode( async_info, &async_hr );
|
||||
if (expect_status < 4) ok_(__FILE__, line)( hr == S_OK, "get_ErrorCode returned %#lx\n", hr );
|
||||
else ok_(__FILE__, line)( hr == E_ILLEGAL_METHOD_CALL, "get_ErrorCode returned %#lx\n", hr );
|
||||
if (expect_status < 4) ok_(__FILE__, line)( async_hr == expect_hr, "got error %#lx\n", async_hr );
|
||||
if (expect_status < 4) todo_wine_if(FAILED(expect_hr)) ok_(__FILE__, line)( async_hr == expect_hr, "got error %#lx\n", async_hr );
|
||||
else ok_(__FILE__, line)( async_hr == E_ILLEGAL_METHOD_CALL, "got error %#lx\n", async_hr );
|
||||
|
||||
IAsyncInfo_Release( async_info );
|
||||
|
@ -4493,6 +4493,7 @@ static void check_bool_async_( int line, IAsyncOperation_boolean *async, UINT32
|
|||
{
|
||||
case Completed:
|
||||
case Error:
|
||||
todo_wine_if(FAILED(expect_hr))
|
||||
ok_(__FILE__, line)( hr == expect_hr, "GetResults returned %#lx\n", hr );
|
||||
ok_(__FILE__, line)( result == expect_result, "got result %u\n", result );
|
||||
break;
|
||||
|
@ -5091,7 +5092,6 @@ static void test_windows_gaming_input(void)
|
|||
.report_id = 1,
|
||||
.report_len = 2,
|
||||
.report_buf = {1, 0x05},
|
||||
.todo = TRUE,
|
||||
};
|
||||
static struct hid_expect expect_enable =
|
||||
{
|
||||
|
@ -5099,7 +5099,6 @@ static void test_windows_gaming_input(void)
|
|||
.report_id = 1,
|
||||
.report_len = 2,
|
||||
.report_buf = {1, 0x04},
|
||||
.todo = TRUE,
|
||||
};
|
||||
static struct hid_expect expect_enable_fail =
|
||||
{
|
||||
|
@ -5108,7 +5107,6 @@ static void test_windows_gaming_input(void)
|
|||
.report_id = 1,
|
||||
.report_len = 2,
|
||||
.report_buf = {1, 0x04},
|
||||
.todo = TRUE,
|
||||
};
|
||||
static struct hid_expect expect_reset_delay[] =
|
||||
{
|
||||
|
@ -5119,7 +5117,6 @@ static void test_windows_gaming_input(void)
|
|||
.report_id = 1,
|
||||
.report_len = 2,
|
||||
.report_buf = {1, 0x01},
|
||||
.todo = TRUE,
|
||||
},
|
||||
/* device gain */
|
||||
{
|
||||
|
@ -5127,7 +5124,6 @@ static void test_windows_gaming_input(void)
|
|||
.report_id = 6,
|
||||
.report_len = 2,
|
||||
.report_buf = {6, 0x7f},
|
||||
.todo = TRUE,
|
||||
},
|
||||
};
|
||||
struct hid_expect expect_reset[] =
|
||||
|
@ -5138,7 +5134,6 @@ static void test_windows_gaming_input(void)
|
|||
.report_id = 1,
|
||||
.report_len = 2,
|
||||
.report_buf = {1, 0x01},
|
||||
.todo = TRUE,
|
||||
},
|
||||
/* device gain */
|
||||
{
|
||||
|
@ -5146,7 +5141,6 @@ static void test_windows_gaming_input(void)
|
|||
.report_id = 6,
|
||||
.report_len = 2,
|
||||
.report_buf = {6, 0x7f},
|
||||
.todo = TRUE,
|
||||
},
|
||||
};
|
||||
static const WCHAR *force_feedback_motor = RuntimeClass_Windows_Gaming_Input_ForceFeedback_ForceFeedbackMotor;
|
||||
|
@ -5309,9 +5303,7 @@ static void test_windows_gaming_input(void)
|
|||
|
||||
enabled = FALSE;
|
||||
hr = IForceFeedbackMotor_get_IsEnabled( motor, &enabled );
|
||||
todo_wine
|
||||
ok( hr == S_OK, "get_IsEnabled returned %#lx\n", hr );
|
||||
todo_wine
|
||||
ok( enabled == TRUE, "got enabled %u\n", enabled );
|
||||
|
||||
supported_axes = 0xdeadbeef;
|
||||
|
@ -5335,10 +5327,8 @@ static void test_windows_gaming_input(void)
|
|||
|
||||
set_hid_expect( file, &expect_disable, sizeof(expect_disable) );
|
||||
hr = IForceFeedbackMotor_TryDisableAsync( motor, &bool_async );
|
||||
todo_wine
|
||||
ok( hr == S_OK, "TryDisableAsync returned %#lx\n", hr );
|
||||
wait_hid_expect_( __FILE__, __LINE__, file, 100, TRUE );
|
||||
if (hr != S_OK) goto skip_tests;
|
||||
wait_hid_expect( file, 100 );
|
||||
check_bool_async( bool_async, 1, Completed, S_OK, TRUE );
|
||||
|
||||
check_interface( bool_async, &IID_IUnknown, TRUE );
|
||||
|
@ -5382,9 +5372,8 @@ static void test_windows_gaming_input(void)
|
|||
|
||||
set_hid_expect( file, &expect_enable_fail, sizeof(expect_enable_fail) );
|
||||
hr = IForceFeedbackMotor_TryEnableAsync( motor, &bool_async );
|
||||
todo_wine
|
||||
ok( hr == S_OK, "TryEnableAsync returned %#lx\n", hr );
|
||||
wait_hid_expect_( __FILE__, __LINE__, file, 100, TRUE );
|
||||
wait_hid_expect( file, 100 );
|
||||
check_bool_async( bool_async, 1, Error, 0x8685400d, FALSE );
|
||||
|
||||
bool_async_handler = default_bool_async_handler;
|
||||
|
@ -5411,7 +5400,6 @@ static void test_windows_gaming_input(void)
|
|||
|
||||
set_hid_expect( file, expect_reset_delay, sizeof(expect_reset_delay) );
|
||||
hr = IForceFeedbackMotor_TryResetAsync( motor, &bool_async );
|
||||
todo_wine
|
||||
ok( hr == S_OK, "TryResetAsync returned %#lx\n", hr );
|
||||
check_bool_async( bool_async, 1, Started, S_OK, FALSE );
|
||||
|
||||
|
@ -5435,7 +5423,7 @@ static void test_windows_gaming_input(void)
|
|||
ok( !bool_async_handler.invoked, "handler invoked\n" );
|
||||
IAsyncInfo_Release( async_info );
|
||||
|
||||
wait_hid_expect_( __FILE__, __LINE__, file, 100, TRUE );
|
||||
wait_hid_expect( file, 100 );
|
||||
ret = WaitForSingleObject( bool_async_handler.event, 100 );
|
||||
ok( ret == 0, "WaitForSingleObject returned %#lx\n", ret );
|
||||
CloseHandle( bool_async_handler.event );
|
||||
|
@ -5455,7 +5443,6 @@ static void test_windows_gaming_input(void)
|
|||
|
||||
set_hid_expect( file, expect_reset_delay, sizeof(expect_reset_delay) );
|
||||
hr = IForceFeedbackMotor_TryResetAsync( motor, &bool_async );
|
||||
todo_wine
|
||||
ok( hr == S_OK, "TryResetAsync returned %#lx\n", hr );
|
||||
check_bool_async( bool_async, 1, Started, S_OK, FALSE );
|
||||
|
||||
|
@ -5481,7 +5468,7 @@ static void test_windows_gaming_input(void)
|
|||
ok( !bool_async_handler.invoked, "handler invoked\n" );
|
||||
IAsyncInfo_Release( async_info );
|
||||
|
||||
wait_hid_expect_( __FILE__, __LINE__, file, 100, TRUE );
|
||||
wait_hid_expect( file, 100 );
|
||||
ret = WaitForSingleObject( bool_async_handler.event, 100 );
|
||||
ok( ret == 0, "WaitForSingleObject returned %#lx\n", ret );
|
||||
CloseHandle( bool_async_handler.event );
|
||||
|
@ -5498,21 +5485,18 @@ static void test_windows_gaming_input(void)
|
|||
|
||||
set_hid_expect( file, &expect_enable, sizeof(expect_enable) );
|
||||
hr = IForceFeedbackMotor_TryEnableAsync( motor, &bool_async );
|
||||
todo_wine
|
||||
ok( hr == S_OK, "TryEnableAsync returned %#lx\n", hr );
|
||||
wait_hid_expect_( __FILE__, __LINE__, file, 100, TRUE );
|
||||
wait_hid_expect( file, 100 );
|
||||
IAsyncOperation_boolean_Release( bool_async );
|
||||
|
||||
|
||||
set_hid_expect( file, expect_reset, sizeof(expect_reset) );
|
||||
hr = IForceFeedbackMotor_TryResetAsync( motor, &bool_async );
|
||||
todo_wine
|
||||
ok( hr == S_OK, "TryResetAsync returned %#lx\n", hr );
|
||||
wait_hid_expect_( __FILE__, __LINE__, file, 100, TRUE );
|
||||
wait_hid_expect( file, 100 );
|
||||
IAsyncOperation_boolean_Release( bool_async );
|
||||
|
||||
|
||||
skip_tests:
|
||||
IForceFeedbackMotor_Release( motor );
|
||||
|
||||
IRawGameController_Release( raw_controller );
|
||||
|
|
|
@ -2,6 +2,7 @@ MODULE = windows.gaming.input.dll
|
|||
IMPORTS = combase uuid user32 dinput8 setupapi hid
|
||||
|
||||
C_SRCS = \
|
||||
async.c \
|
||||
controller.c \
|
||||
event_handlers.c \
|
||||
force_feedback.c \
|
||||
|
|
|
@ -0,0 +1,369 @@
|
|||
/* WinRT Windows.Gaming.Input implementation
|
||||
*
|
||||
* Copyright 2022 Bernhard Kölbl for CodeWeavers
|
||||
* Copyright 2022 Rémi Bernon for CodeWeavers
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include "private.h"
|
||||
|
||||
#include "wine/debug.h"
|
||||
|
||||
WINE_DEFAULT_DEBUG_CHANNEL(input);
|
||||
|
||||
#define Closed 4
|
||||
#define HANDLER_NOT_SET ((void *)~(ULONG_PTR)0)
|
||||
|
||||
struct async_bool
|
||||
{
|
||||
IAsyncOperation_boolean IAsyncOperation_boolean_iface;
|
||||
IAsyncInfo IAsyncInfo_iface;
|
||||
LONG ref;
|
||||
|
||||
IAsyncOperationCompletedHandler_boolean *handler;
|
||||
BOOLEAN result;
|
||||
|
||||
async_operation_boolean_callback callback;
|
||||
TP_WORK *async_run_work;
|
||||
IInspectable *invoker;
|
||||
|
||||
CRITICAL_SECTION cs;
|
||||
AsyncStatus status;
|
||||
HRESULT hr;
|
||||
};
|
||||
|
||||
DEFINE_IINSPECTABLE( async_info, IAsyncInfo, struct async_bool, IAsyncOperation_boolean_iface )
|
||||
|
||||
static HRESULT WINAPI async_info_get_Id( IAsyncInfo *iface, UINT32 *id )
|
||||
{
|
||||
struct async_bool *impl = impl_from_IAsyncInfo( iface );
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
TRACE( "iface %p, id %p.\n", iface, id );
|
||||
|
||||
EnterCriticalSection( &impl->cs );
|
||||
if (impl->status == Closed) hr = E_ILLEGAL_METHOD_CALL;
|
||||
*id = 1;
|
||||
LeaveCriticalSection( &impl->cs );
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI async_info_get_Status( IAsyncInfo *iface, AsyncStatus *status )
|
||||
{
|
||||
struct async_bool *impl = impl_from_IAsyncInfo( iface );
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
TRACE( "iface %p, status %p.\n", iface, status );
|
||||
|
||||
EnterCriticalSection( &impl->cs );
|
||||
if (impl->status == Closed) hr = E_ILLEGAL_METHOD_CALL;
|
||||
*status = impl->status;
|
||||
LeaveCriticalSection( &impl->cs );
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI async_info_get_ErrorCode( IAsyncInfo *iface, HRESULT *error_code )
|
||||
{
|
||||
struct async_bool *impl = impl_from_IAsyncInfo( iface );
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
TRACE( "iface %p, error_code %p.\n", iface, error_code );
|
||||
|
||||
EnterCriticalSection( &impl->cs );
|
||||
if (impl->status == Closed) *error_code = hr = E_ILLEGAL_METHOD_CALL;
|
||||
else *error_code = impl->hr;
|
||||
LeaveCriticalSection( &impl->cs );
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI async_info_Cancel( IAsyncInfo *iface )
|
||||
{
|
||||
struct async_bool *impl = impl_from_IAsyncInfo( iface );
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
TRACE( "iface %p.\n", iface );
|
||||
|
||||
EnterCriticalSection( &impl->cs );
|
||||
if (impl->status == Closed) hr = E_ILLEGAL_METHOD_CALL;
|
||||
else if (impl->status == Started) impl->status = Canceled;
|
||||
LeaveCriticalSection( &impl->cs );
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI async_info_Close( IAsyncInfo *iface )
|
||||
{
|
||||
struct async_bool *impl = impl_from_IAsyncInfo( iface );
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
TRACE( "iface %p.\n", iface );
|
||||
|
||||
EnterCriticalSection( &impl->cs );
|
||||
if (impl->status == Started)
|
||||
hr = E_ILLEGAL_STATE_CHANGE;
|
||||
else if (impl->status != Closed)
|
||||
{
|
||||
CloseThreadpoolWork( impl->async_run_work );
|
||||
impl->async_run_work = NULL;
|
||||
impl->status = Closed;
|
||||
}
|
||||
LeaveCriticalSection( &impl->cs );
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
static const struct IAsyncInfoVtbl async_info_vtbl =
|
||||
{
|
||||
/* IUnknown methods */
|
||||
async_info_QueryInterface,
|
||||
async_info_AddRef,
|
||||
async_info_Release,
|
||||
/* IInspectable methods */
|
||||
async_info_GetIids,
|
||||
async_info_GetRuntimeClassName,
|
||||
async_info_GetTrustLevel,
|
||||
/* IAsyncInfo */
|
||||
async_info_get_Id,
|
||||
async_info_get_Status,
|
||||
async_info_get_ErrorCode,
|
||||
async_info_Cancel,
|
||||
async_info_Close,
|
||||
};
|
||||
|
||||
static inline struct async_bool *impl_from_IAsyncOperation_boolean( IAsyncOperation_boolean *iface )
|
||||
{
|
||||
return CONTAINING_RECORD( iface, struct async_bool, IAsyncOperation_boolean_iface );
|
||||
}
|
||||
|
||||
static HRESULT WINAPI async_bool_QueryInterface( IAsyncOperation_boolean *iface, REFIID iid, void **out )
|
||||
{
|
||||
struct async_bool *impl = impl_from_IAsyncOperation_boolean( iface );
|
||||
|
||||
TRACE( "iface %p, iid %s, out %p.\n", iface, debugstr_guid( iid ), out );
|
||||
|
||||
if (IsEqualGUID( iid, &IID_IUnknown ) ||
|
||||
IsEqualGUID( iid, &IID_IInspectable ) ||
|
||||
IsEqualGUID( iid, &IID_IAgileObject ) ||
|
||||
IsEqualGUID( iid, &IID_IAsyncOperation_boolean ))
|
||||
{
|
||||
IInspectable_AddRef( (*out = &impl->IAsyncOperation_boolean_iface) );
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
if (IsEqualGUID( iid, &IID_IAsyncInfo ))
|
||||
{
|
||||
IInspectable_AddRef( (*out = &impl->IAsyncInfo_iface) );
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
WARN( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) );
|
||||
*out = NULL;
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
static ULONG WINAPI async_bool_AddRef( IAsyncOperation_boolean *iface )
|
||||
{
|
||||
struct async_bool *impl = impl_from_IAsyncOperation_boolean( iface );
|
||||
ULONG ref = InterlockedIncrement( &impl->ref );
|
||||
TRACE( "iface %p, ref %lu.\n", iface, ref );
|
||||
return ref;
|
||||
}
|
||||
|
||||
static ULONG WINAPI async_bool_Release( IAsyncOperation_boolean *iface )
|
||||
{
|
||||
struct async_bool *impl = impl_from_IAsyncOperation_boolean( iface );
|
||||
|
||||
ULONG ref = InterlockedDecrement( &impl->ref );
|
||||
TRACE( "iface %p, ref %lu.\n", iface, ref );
|
||||
|
||||
if (!ref)
|
||||
{
|
||||
IAsyncInfo_Close( &impl->IAsyncInfo_iface );
|
||||
if (impl->handler && impl->handler != HANDLER_NOT_SET) IAsyncOperationCompletedHandler_boolean_Release( impl->handler );
|
||||
IInspectable_Release( impl->invoker );
|
||||
DeleteCriticalSection( &impl->cs );
|
||||
free( impl );
|
||||
}
|
||||
|
||||
return ref;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI async_bool_GetIids( IAsyncOperation_boolean *iface, ULONG *iid_count, IID **iids )
|
||||
{
|
||||
FIXME( "iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids );
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI async_bool_GetRuntimeClassName( IAsyncOperation_boolean *iface, HSTRING *class_name )
|
||||
{
|
||||
return WindowsCreateString( L"Windows.Foundation.IAsyncOperation`1<Boolean>",
|
||||
ARRAY_SIZE(L"Windows.Foundation.IAsyncOperation`1<Boolean>"),
|
||||
class_name );
|
||||
}
|
||||
|
||||
static HRESULT WINAPI async_bool_GetTrustLevel( IAsyncOperation_boolean *iface, TrustLevel *trust_level )
|
||||
{
|
||||
FIXME( "iface %p, trust_level %p stub!\n", iface, trust_level );
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI async_bool_put_Completed( IAsyncOperation_boolean *iface, IAsyncOperationCompletedHandler_boolean *handler )
|
||||
{
|
||||
struct async_bool *impl = impl_from_IAsyncOperation_boolean( iface );
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
TRACE( "iface %p, handler %p.\n", iface, handler );
|
||||
|
||||
EnterCriticalSection( &impl->cs );
|
||||
if (impl->status == Closed) hr = E_ILLEGAL_METHOD_CALL;
|
||||
else if (impl->handler != HANDLER_NOT_SET) hr = E_ILLEGAL_DELEGATE_ASSIGNMENT;
|
||||
else if ((impl->handler = handler))
|
||||
{
|
||||
IAsyncOperationCompletedHandler_boolean_AddRef( impl->handler );
|
||||
|
||||
if (impl->status > Started)
|
||||
{
|
||||
IAsyncOperation_boolean *operation = &impl->IAsyncOperation_boolean_iface;
|
||||
AsyncStatus status = impl->status;
|
||||
impl->handler = NULL; /* Prevent concurrent invoke. */
|
||||
LeaveCriticalSection( &impl->cs );
|
||||
|
||||
IAsyncOperationCompletedHandler_boolean_Invoke( handler, operation, status );
|
||||
IAsyncOperationCompletedHandler_boolean_Release( handler );
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
}
|
||||
LeaveCriticalSection( &impl->cs );
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI async_bool_get_Completed( IAsyncOperation_boolean *iface, IAsyncOperationCompletedHandler_boolean **handler )
|
||||
{
|
||||
struct async_bool *impl = impl_from_IAsyncOperation_boolean( iface );
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
FIXME( "iface %p, handler %p semi stub!\n", iface, handler );
|
||||
|
||||
EnterCriticalSection( &impl->cs );
|
||||
if (impl->status == Closed) hr = E_ILLEGAL_METHOD_CALL;
|
||||
*handler = (impl->handler != HANDLER_NOT_SET) ? impl->handler : NULL;
|
||||
LeaveCriticalSection( &impl->cs );
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI async_bool_GetResults( IAsyncOperation_boolean *iface, BOOLEAN *results )
|
||||
{
|
||||
struct async_bool *impl = impl_from_IAsyncOperation_boolean( iface );
|
||||
HRESULT hr;
|
||||
|
||||
TRACE( "iface %p, results %p.\n", iface, results );
|
||||
|
||||
EnterCriticalSection( &impl->cs );
|
||||
if (impl->status != Completed && impl->status != Error) hr = E_ILLEGAL_METHOD_CALL;
|
||||
else
|
||||
{
|
||||
*results = impl->result;
|
||||
hr = impl->hr;
|
||||
}
|
||||
LeaveCriticalSection( &impl->cs );
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
static const struct IAsyncOperation_booleanVtbl async_bool_vtbl =
|
||||
{
|
||||
/* IUnknown methods */
|
||||
async_bool_QueryInterface,
|
||||
async_bool_AddRef,
|
||||
async_bool_Release,
|
||||
/* IInspectable methods */
|
||||
async_bool_GetIids,
|
||||
async_bool_GetRuntimeClassName,
|
||||
async_bool_GetTrustLevel,
|
||||
/* IAsyncOperation<boolean> */
|
||||
async_bool_put_Completed,
|
||||
async_bool_get_Completed,
|
||||
async_bool_GetResults,
|
||||
};
|
||||
|
||||
static void CALLBACK async_run_cb( TP_CALLBACK_INSTANCE *instance, void *data, TP_WORK *work )
|
||||
{
|
||||
IAsyncOperation_boolean *operation = data;
|
||||
struct async_bool *impl = impl_from_IAsyncOperation_boolean( operation );
|
||||
BOOLEAN result = FALSE;
|
||||
HRESULT hr;
|
||||
|
||||
hr = impl->callback( impl->invoker, &result );
|
||||
|
||||
EnterCriticalSection( &impl->cs );
|
||||
if (impl->status != Closed) impl->status = FAILED(hr) ? Error : Completed;
|
||||
impl->result = result;
|
||||
impl->hr = hr;
|
||||
|
||||
if (impl->handler != NULL && impl->handler != HANDLER_NOT_SET)
|
||||
{
|
||||
IAsyncOperationCompletedHandler_boolean *handler = impl->handler;
|
||||
AsyncStatus status = impl->status;
|
||||
impl->handler = NULL; /* Prevent concurrent invoke. */
|
||||
LeaveCriticalSection( &impl->cs );
|
||||
|
||||
IAsyncOperationCompletedHandler_boolean_Invoke( handler, operation, status );
|
||||
IAsyncOperationCompletedHandler_boolean_Release( handler );
|
||||
}
|
||||
else LeaveCriticalSection( &impl->cs );
|
||||
|
||||
IAsyncOperation_boolean_Release( operation );
|
||||
}
|
||||
|
||||
HRESULT async_operation_boolean_create( IInspectable *invoker, async_operation_boolean_callback callback,
|
||||
IAsyncOperation_boolean **out )
|
||||
{
|
||||
struct async_bool *impl;
|
||||
|
||||
*out = NULL;
|
||||
if (!(impl = calloc( 1, sizeof(*impl) ))) return E_OUTOFMEMORY;
|
||||
impl->IAsyncOperation_boolean_iface.lpVtbl = &async_bool_vtbl;
|
||||
impl->IAsyncInfo_iface.lpVtbl = &async_info_vtbl;
|
||||
impl->ref = 1;
|
||||
|
||||
impl->handler = HANDLER_NOT_SET;
|
||||
impl->callback = callback;
|
||||
impl->status = Started;
|
||||
|
||||
if (!(impl->async_run_work = CreateThreadpoolWork( async_run_cb, &impl->IAsyncOperation_boolean_iface, NULL )))
|
||||
{
|
||||
free( impl );
|
||||
return HRESULT_FROM_WIN32( GetLastError() );
|
||||
}
|
||||
|
||||
IInspectable_AddRef( (impl->invoker = invoker) );
|
||||
InitializeCriticalSection( &impl->cs );
|
||||
impl->cs.DebugInfo->Spare[0] = (DWORD_PTR)( __FILE__ ": async_operation.cs" );
|
||||
|
||||
/* keep the async alive in the callback */
|
||||
IAsyncOperation_boolean_AddRef( &impl->IAsyncOperation_boolean_iface );
|
||||
SubmitThreadpoolWork( impl->async_run_work );
|
||||
|
||||
*out = &impl->IAsyncOperation_boolean_iface;
|
||||
TRACE( "created IAsyncOperation_boolean %p\n", *out );
|
||||
return S_OK;
|
||||
}
|
|
@ -161,8 +161,16 @@ static HRESULT WINAPI motor_put_MasterGain( IForceFeedbackMotor *iface, double v
|
|||
|
||||
static HRESULT WINAPI motor_get_IsEnabled( IForceFeedbackMotor *iface, BOOLEAN *value )
|
||||
{
|
||||
FIXME( "iface %p, value %p stub!\n", iface, value );
|
||||
return E_NOTIMPL;
|
||||
struct motor *impl = impl_from_IForceFeedbackMotor( iface );
|
||||
DWORD state;
|
||||
HRESULT hr;
|
||||
|
||||
TRACE( "iface %p, value %p.\n", iface, value );
|
||||
|
||||
if (FAILED(hr = IDirectInputDevice8_GetForceFeedbackState( impl->device, &state ))) *value = FALSE;
|
||||
else *value = !(state & DIGFFS_ACTUATORSOFF);
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI motor_get_SupportedAxes( IForceFeedbackMotor *iface, enum ForceFeedbackEffectAxes *value )
|
||||
|
@ -205,22 +213,55 @@ static HRESULT WINAPI motor_StopAllEffects( IForceFeedbackMotor *iface )
|
|||
return IDirectInputDevice8_SendForceFeedbackCommand( impl->device, DISFFC_STOPALL );
|
||||
}
|
||||
|
||||
static HRESULT WINAPI motor_try_disable_async( IInspectable *iface, BOOLEAN *result )
|
||||
{
|
||||
struct motor *impl = impl_from_IForceFeedbackMotor( (IForceFeedbackMotor *)iface );
|
||||
HRESULT hr;
|
||||
|
||||
hr = IDirectInputDevice8_SendForceFeedbackCommand( impl->device, DISFFC_SETACTUATORSOFF );
|
||||
*result = SUCCEEDED(hr);
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI motor_TryDisableAsync( IForceFeedbackMotor *iface, IAsyncOperation_boolean **async_op )
|
||||
{
|
||||
FIXME( "iface %p, async_op %p stub!\n", iface, async_op );
|
||||
return E_NOTIMPL;
|
||||
TRACE( "iface %p, async_op %p.\n", iface, async_op );
|
||||
return async_operation_boolean_create( (IInspectable *)iface, motor_try_disable_async, async_op );
|
||||
}
|
||||
|
||||
static HRESULT WINAPI motor_try_enable_async( IInspectable *iface, BOOLEAN *result )
|
||||
{
|
||||
struct motor *impl = impl_from_IForceFeedbackMotor( (IForceFeedbackMotor *)iface );
|
||||
HRESULT hr;
|
||||
|
||||
hr = IDirectInputDevice8_SendForceFeedbackCommand( impl->device, DISFFC_SETACTUATORSON );
|
||||
*result = SUCCEEDED(hr);
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI motor_TryEnableAsync( IForceFeedbackMotor *iface, IAsyncOperation_boolean **async_op )
|
||||
{
|
||||
FIXME( "iface %p, async_op %p stub!\n", iface, async_op );
|
||||
return E_NOTIMPL;
|
||||
TRACE( "iface %p, async_op %p.\n", iface, async_op );
|
||||
return async_operation_boolean_create( (IInspectable *)iface, motor_try_enable_async, async_op );
|
||||
}
|
||||
|
||||
static HRESULT WINAPI motor_try_reset_async( IInspectable *iface, BOOLEAN *result )
|
||||
{
|
||||
struct motor *impl = impl_from_IForceFeedbackMotor( (IForceFeedbackMotor *)iface );
|
||||
HRESULT hr;
|
||||
|
||||
hr = IDirectInputDevice8_SendForceFeedbackCommand( impl->device, DISFFC_RESET );
|
||||
*result = SUCCEEDED(hr);
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI motor_TryResetAsync( IForceFeedbackMotor *iface, IAsyncOperation_boolean **async_op )
|
||||
{
|
||||
FIXME( "iface %p, async_op %p stub!\n", iface, async_op );
|
||||
return E_NOTIMPL;
|
||||
TRACE( "iface %p, async_op %p.\n", iface, async_op );
|
||||
return async_operation_boolean_create( (IInspectable *)iface, motor_try_reset_async, async_op );
|
||||
}
|
||||
|
||||
static HRESULT WINAPI motor_TryUnloadEffectAsync( IForceFeedbackMotor *iface, IForceFeedbackEffect *effect,
|
||||
|
|
|
@ -67,6 +67,10 @@ extern void event_handlers_notify( struct list *list, IInspectable *element );
|
|||
|
||||
extern HRESULT force_feedback_motor_create( IDirectInputDevice8W *device, IForceFeedbackMotor **out );
|
||||
|
||||
typedef HRESULT (WINAPI *async_operation_boolean_callback)( IInspectable *invoker, BOOLEAN *result );
|
||||
extern HRESULT async_operation_boolean_create( IInspectable *invoker, async_operation_boolean_callback callback,
|
||||
IAsyncOperation_boolean **out );
|
||||
|
||||
#define DEFINE_IINSPECTABLE_( pfx, iface_type, impl_type, impl_from, iface_mem, expr ) \
|
||||
static inline impl_type *impl_from( iface_type *iface ) \
|
||||
{ \
|
||||
|
|
Loading…
Reference in New Issue