From: Rémi Bernon rbernon@codeweavers.com
--- dlls/windows.media.speech/Makefile.in | 1 + dlls/windows.media.speech/async.c | 948 ++++++++++---------- dlls/windows.media.speech/async_private.idl | 46 + dlls/windows.media.speech/private.h | 9 +- dlls/windows.media.speech/recognizer.c | 20 +- dlls/windows.media.speech/synthesizer.c | 28 +- dlls/windows.media.speech/tests/speech.c | 28 +- 7 files changed, 602 insertions(+), 478 deletions(-) create mode 100644 dlls/windows.media.speech/async_private.idl
diff --git a/dlls/windows.media.speech/Makefile.in b/dlls/windows.media.speech/Makefile.in index 5be66d8367e..e21fc2162c2 100644 --- a/dlls/windows.media.speech/Makefile.in +++ b/dlls/windows.media.speech/Makefile.in @@ -3,6 +3,7 @@ IMPORTS = combase uuid
SOURCES = \ async.c \ + async_private.idl \ classes.idl \ event_handlers.c \ listconstraint.c \ diff --git a/dlls/windows.media.speech/async.c b/dlls/windows.media.speech/async.c index 2b2dc394305..4e84afec2a5 100644 --- a/dlls/windows.media.speech/async.c +++ b/dlls/windows.media.speech/async.c @@ -1,6 +1,7 @@ -/* WinRT Windows.Media.Speech implementation +/* WinRT IAsync* 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 @@ -17,742 +18,787 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+#define WIDL_using_Wine_Internal #include "private.h" +#include "initguid.h" +#include "async_private.h"
#include "wine/debug.h"
-WINE_DEFAULT_DEBUG_CHANNEL(speech); +WINE_DEFAULT_DEBUG_CHANNEL(combase);
#define Closed 4 #define HANDLER_NOT_SET ((void *)~(ULONG_PTR)0)
-/* - * - * IAsyncAction - * - */ - -struct async_void +struct async_info { - IAsyncAction IAsyncAction_iface; + IAsyncInfoImpl IAsyncInfoImpl_iface; IAsyncInfo IAsyncInfo_iface; + IInspectable *IInspectable_outer; LONG ref;
- IAsyncActionCompletedHandler *handler; - - async_action_callback callback; + async_operation_callback callback; TP_WORK *async_run_work; - IInspectable *invoker; + IUnknown *invoker; + IUnknown *param;
CRITICAL_SECTION cs; + IAsyncOperationCompletedHandlerImpl *handler; + PROPVARIANT result; AsyncStatus status; HRESULT hr; };
-static inline struct async_void *impl_from_IAsyncAction( IAsyncAction *iface ) +static inline struct async_info *impl_from_IAsyncInfoImpl( IAsyncInfoImpl *iface ) { - return CONTAINING_RECORD(iface, struct async_void, IAsyncAction_iface); + return CONTAINING_RECORD( iface, struct async_info, IAsyncInfoImpl_iface ); }
-HRESULT WINAPI async_void_QueryInterface( IAsyncAction *iface, REFIID iid, void **out ) +static HRESULT WINAPI async_impl_QueryInterface( IAsyncInfoImpl *iface, REFIID iid, void **out ) { - struct async_void *impl = impl_from_IAsyncAction(iface); + struct async_info *impl = impl_from_IAsyncInfoImpl( iface );
- TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out); + 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_IAsyncAction)) + if (IsEqualGUID( iid, &IID_IUnknown ) || + IsEqualGUID( iid, &IID_IInspectable ) || + IsEqualGUID( iid, &IID_IAgileObject ) || + IsEqualGUID( iid, &IID_IAsyncInfoImpl )) { - IInspectable_AddRef((*out = &impl->IAsyncAction_iface)); + IInspectable_AddRef( (*out = &impl->IAsyncInfoImpl_iface) ); return S_OK; }
- if (IsEqualGUID(iid, &IID_IAsyncInfo)) + if (IsEqualGUID( iid, &IID_IAsyncInfo )) { - IInspectable_AddRef((*out = &impl->IAsyncInfo_iface)); + IInspectable_AddRef( (*out = &impl->IAsyncInfo_iface) ); return S_OK; }
- WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid)); + FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) ); *out = NULL; return E_NOINTERFACE; }
-ULONG WINAPI async_void_AddRef( IAsyncAction *iface ) +static ULONG WINAPI async_impl_AddRef( IAsyncInfoImpl *iface ) { - struct async_void *impl = impl_from_IAsyncAction(iface); - ULONG ref = InterlockedIncrement(&impl->ref); - TRACE("iface %p, ref %lu.\n", iface, ref); + struct async_info *impl = impl_from_IAsyncInfoImpl( iface ); + ULONG ref = InterlockedIncrement( &impl->ref ); + TRACE( "iface %p, ref %lu.\n", iface, ref ); return ref; }
-ULONG WINAPI async_void_Release( IAsyncAction *iface ) +static ULONG WINAPI async_impl_Release( IAsyncInfoImpl *iface ) { - struct async_void *impl = impl_from_IAsyncAction(iface); - ULONG ref = InterlockedDecrement(&impl->ref); - TRACE("iface %p, ref %lu.\n", iface, ref); + struct async_info *impl = impl_from_IAsyncInfoImpl( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + TRACE( "iface %p, ref %lu.\n", iface, ref );
if (!ref) { - IAsyncInfo_Close(&impl->IAsyncInfo_iface); - - if (impl->invoker) - IInspectable_Release(impl->invoker); - if (impl->handler && impl->handler != HANDLER_NOT_SET) - IAsyncActionCompletedHandler_Release(impl->handler); - + if (impl->handler && impl->handler != HANDLER_NOT_SET) IAsyncOperationCompletedHandlerImpl_Release( impl->handler ); + IAsyncInfo_Close( &impl->IAsyncInfo_iface ); + if (impl->param) IUnknown_Release( impl->param ); + if (impl->invoker) IUnknown_Release( impl->invoker ); + PropVariantClear( &impl->result ); impl->cs.DebugInfo->Spare[0] = 0; - DeleteCriticalSection(&impl->cs); - free(impl); + DeleteCriticalSection( &impl->cs ); + free( impl ); }
return ref; }
-HRESULT WINAPI async_void_GetIids( IAsyncAction *iface, ULONG *iid_count, IID **iids ) -{ - FIXME("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids); - return E_NOTIMPL; -} - -HRESULT WINAPI async_void_GetRuntimeClassName( IAsyncAction *iface, HSTRING *class_name ) -{ - FIXME("iface %p, class_name %p stub!\n", iface, class_name); - return E_NOTIMPL; -} - -HRESULT WINAPI async_void_GetTrustLevel( IAsyncAction *iface, TrustLevel *trust_level ) -{ - FIXME("iface %p, trust_level %p stub!\n", iface, trust_level); - return E_NOTIMPL; -} - -HRESULT WINAPI async_void_put_Completed( IAsyncAction *iface, IAsyncActionCompletedHandler *handler ) +static HRESULT WINAPI async_impl_put_Completed( IAsyncInfoImpl *iface, IAsyncOperationCompletedHandlerImpl *handler ) { - struct async_void *impl = impl_from_IAsyncAction(iface); + struct async_info *impl = impl_from_IAsyncInfoImpl( 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; - /* - impl->handler can only be set once with async_void_put_Completed, - so by default we set a non HANDLER_NOT_SET value, in this case handler. - */ + 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)) { - IAsyncActionCompletedHandler_AddRef(impl->handler); + IAsyncOperationCompletedHandlerImpl_AddRef( impl->handler );
if (impl->status > Started) { - IAsyncAction *action = &impl->IAsyncAction_iface; + IInspectable *operation = impl->IInspectable_outer; AsyncStatus status = impl->status; impl->handler = NULL; /* Prevent concurrent invoke. */ - LeaveCriticalSection(&impl->cs); + LeaveCriticalSection( &impl->cs );
- IAsyncActionCompletedHandler_Invoke(handler, action, status); - IAsyncActionCompletedHandler_Release(handler); + IAsyncOperationCompletedHandlerImpl_Invoke( handler, operation, status ); + IAsyncOperationCompletedHandlerImpl_Release( handler );
return S_OK; } } - LeaveCriticalSection(&impl->cs); + LeaveCriticalSection( &impl->cs );
return hr; }
-HRESULT WINAPI async_void_get_Completed( IAsyncAction *iface, IAsyncActionCompletedHandler **handler ) +static HRESULT WINAPI async_impl_get_Completed( IAsyncInfoImpl *iface, IAsyncOperationCompletedHandlerImpl **handler ) { - struct async_void *impl = impl_from_IAsyncAction(iface); + struct async_info *impl = impl_from_IAsyncInfoImpl( iface ); HRESULT hr = S_OK;
- FIXME("iface %p, handler %p semi stub!\n", iface, handler); + TRACE( "iface %p, handler %p.\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); + EnterCriticalSection( &impl->cs ); + if (impl->status == Closed) hr = E_ILLEGAL_METHOD_CALL; + if (impl->handler == NULL || impl->handler == HANDLER_NOT_SET) *handler = NULL; + else IAsyncOperationCompletedHandlerImpl_AddRef( (*handler = impl->handler) ); + LeaveCriticalSection( &impl->cs );
return hr; }
-HRESULT WINAPI async_void_GetResults( IAsyncAction *iface ) +static HRESULT WINAPI async_impl_get_Result( IAsyncInfoImpl *iface, PROPVARIANT *result ) { - /* According to the docs, this function doesn't return anything, so it's left empty. */ - TRACE("iface %p.\n", iface); + struct async_info *impl = impl_from_IAsyncInfoImpl( iface ); + HRESULT hr = E_ILLEGAL_METHOD_CALL; + + TRACE( "iface %p, result %p.\n", iface, result ); + + EnterCriticalSection( &impl->cs ); + if (impl->status == Completed || impl->status == Error) + { + PropVariantCopy( result, &impl->result ); + hr = impl->hr; + } + LeaveCriticalSection( &impl->cs ); + + return hr; +} + +static HRESULT WINAPI async_impl_Start( IAsyncInfoImpl *iface ) +{ + struct async_info *impl = impl_from_IAsyncInfoImpl( iface ); + + TRACE( "iface %p.\n", iface ); + + /* keep the async alive in the callback */ + IInspectable_AddRef( impl->IInspectable_outer ); + SubmitThreadpoolWork( impl->async_run_work ); + return S_OK; }
-static const struct IAsyncActionVtbl async_void_vtbl = +static const struct IAsyncInfoImplVtbl async_impl_vtbl = { /* IUnknown methods */ - async_void_QueryInterface, - async_void_AddRef, - async_void_Release, - /* IInspectable methods */ - async_void_GetIids, - async_void_GetRuntimeClassName, - async_void_GetTrustLevel, - /* IAsyncAction methods */ - async_void_put_Completed, - async_void_get_Completed, - async_void_GetResults + async_impl_QueryInterface, + async_impl_AddRef, + async_impl_Release, + /* IAsyncInfoImpl */ + async_impl_put_Completed, + async_impl_get_Completed, + async_impl_get_Result, + async_impl_Start, };
-/* - * - * IAsyncInfo for IAsyncAction - * - */ - -DEFINE_IINSPECTABLE_(async_void_info, IAsyncInfo, struct async_void, impl_from_async_void_IAsyncInfo, IAsyncInfo_iface, &impl->IAsyncAction_iface) +DEFINE_IINSPECTABLE_OUTER( async_info, IAsyncInfo, struct async_info, IInspectable_outer )
-static HRESULT WINAPI async_void_info_get_Id( IAsyncInfo *iface, UINT32 *id ) +static HRESULT WINAPI async_info_get_Id( IAsyncInfo *iface, UINT32 *id ) { - FIXME("iface %p, id %p stub!\n", iface, id); - return E_NOTIMPL; + struct async_info *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_void_info_get_Status( IAsyncInfo *iface, AsyncStatus *status ) +static HRESULT WINAPI async_info_get_Status( IAsyncInfo *iface, AsyncStatus *status ) { - struct async_void *impl = impl_from_async_void_IAsyncInfo(iface); + struct async_info *impl = impl_from_IAsyncInfo( iface ); HRESULT hr = S_OK;
- TRACE("iface %p, status %p.\n", iface, status); + TRACE( "iface %p, status %p.\n", iface, status );
- EnterCriticalSection(&impl->cs); - if (impl->status == Closed) - hr = E_ILLEGAL_METHOD_CALL; + EnterCriticalSection( &impl->cs ); + if (impl->status == Closed) hr = E_ILLEGAL_METHOD_CALL; *status = impl->status; - LeaveCriticalSection(&impl->cs); + LeaveCriticalSection( &impl->cs );
return hr; }
-static HRESULT WINAPI async_void_info_get_ErrorCode( IAsyncInfo *iface, HRESULT *error_code ) +static HRESULT WINAPI async_info_get_ErrorCode( IAsyncInfo *iface, HRESULT *error_code ) { - struct async_void *impl = impl_from_async_void_IAsyncInfo(iface); + struct async_info *impl = impl_from_IAsyncInfo( iface ); HRESULT hr = S_OK;
- TRACE("iface %p, error_code %p.\n", iface, error_code); + 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); + 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_void_info_Cancel( IAsyncInfo *iface ) +static HRESULT WINAPI async_info_Cancel( IAsyncInfo *iface ) { - struct async_void *impl = impl_from_async_void_IAsyncInfo(iface); + struct async_info *impl = impl_from_IAsyncInfo( iface ); HRESULT hr = S_OK;
- TRACE("iface %p.\n", iface); + 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); + 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_void_info_Close( IAsyncInfo *iface ) +static HRESULT WINAPI async_info_Close( IAsyncInfo *iface ) { - struct async_void *impl = impl_from_async_void_IAsyncInfo(iface); + struct async_info *impl = impl_from_IAsyncInfo( iface ); HRESULT hr = S_OK;
- TRACE("iface %p.\n", iface); + TRACE( "iface %p.\n", iface );
- EnterCriticalSection(&impl->cs); + EnterCriticalSection( &impl->cs ); if (impl->status == Started) hr = E_ILLEGAL_STATE_CHANGE; else if (impl->status != Closed) { - CloseThreadpoolWork(impl->async_run_work); + CloseThreadpoolWork( impl->async_run_work ); impl->async_run_work = NULL; impl->status = Closed; } - LeaveCriticalSection(&impl->cs); + LeaveCriticalSection( &impl->cs );
return hr; }
-static const struct IAsyncInfoVtbl async_void_info_vtbl = +static const struct IAsyncInfoVtbl async_info_vtbl = { /* IUnknown methods */ - async_void_info_QueryInterface, - async_void_info_AddRef, - async_void_info_Release, + async_info_QueryInterface, + async_info_AddRef, + async_info_Release, /* IInspectable methods */ - async_void_info_GetIids, - async_void_info_GetRuntimeClassName, - async_void_info_GetTrustLevel, + async_info_GetIids, + async_info_GetRuntimeClassName, + async_info_GetTrustLevel, /* IAsyncInfo */ - async_void_info_get_Id, - async_void_info_get_Status, - async_void_info_get_ErrorCode, - async_void_info_Cancel, - async_void_info_Close + async_info_get_Id, + async_info_get_Status, + async_info_get_ErrorCode, + async_info_Cancel, + async_info_Close, };
-static void CALLBACK async_void_run_cb(TP_CALLBACK_INSTANCE *instance, void *data, TP_WORK *work) +static void CALLBACK async_info_callback( TP_CALLBACK_INSTANCE *instance, void *iface, TP_WORK *work ) { - IAsyncAction *action = data; - struct async_void *impl = impl_from_IAsyncAction(action); + struct async_info *impl = impl_from_IAsyncInfoImpl( iface ); + IInspectable *operation = impl->IInspectable_outer; + PROPVARIANT result = {0}; HRESULT hr;
- hr = impl->callback(impl->invoker); - - EnterCriticalSection(&impl->cs); - if (impl->status < Closed) - impl->status = FAILED(hr) ? Error : Completed; + hr = impl->callback( impl->invoker, impl->param, &result );
+ EnterCriticalSection( &impl->cs ); + if (impl->status != Closed) impl->status = FAILED(hr) ? Error : Completed; + PropVariantCopy( &impl->result, &result ); impl->hr = hr;
if (impl->handler != NULL && impl->handler != HANDLER_NOT_SET) { - IAsyncActionCompletedHandler*handler = impl->handler; + IAsyncOperationCompletedHandlerImpl *handler = impl->handler; AsyncStatus status = impl->status; impl->handler = NULL; /* Prevent concurrent invoke. */ - LeaveCriticalSection(&impl->cs); + LeaveCriticalSection( &impl->cs );
- IAsyncActionCompletedHandler_Invoke(handler, action, status); - IAsyncActionCompletedHandler_Release(handler); + IAsyncOperationCompletedHandlerImpl_Invoke( handler, operation, status ); + IAsyncOperationCompletedHandlerImpl_Release( handler ); } - else LeaveCriticalSection(&impl->cs); + else LeaveCriticalSection( &impl->cs ); + + /* release refcount acquired in Start */ + IInspectable_Release( operation );
- IAsyncAction_Release(action); + PropVariantClear( &result ); }
-HRESULT async_action_create( IInspectable *invoker, async_action_callback callback, IAsyncAction **out ) +static HRESULT async_info_create( IUnknown *invoker, IUnknown *param, async_operation_callback callback, + IInspectable *outer, IAsyncInfoImpl **out ) { - struct async_void *impl; - - TRACE("invoker %p, callback %p, out %p.\n", invoker, callback, out); - - if (!(impl = calloc(1, sizeof(*impl)))) - { - *out = NULL; - return E_OUTOFMEMORY; - } + struct async_info *impl; + HRESULT hr;
- impl->IAsyncAction_iface.lpVtbl = &async_void_vtbl; - impl->IAsyncInfo_iface.lpVtbl = &async_void_info_vtbl; + if (!(impl = calloc( 1, sizeof(struct async_info) ))) return E_OUTOFMEMORY; + impl->IAsyncInfoImpl_iface.lpVtbl = &async_impl_vtbl; + impl->IAsyncInfo_iface.lpVtbl = &async_info_vtbl; + impl->IInspectable_outer = outer; impl->ref = 1;
- impl->handler = HANDLER_NOT_SET; impl->callback = callback; + impl->handler = HANDLER_NOT_SET; impl->status = Started; - - if (!(impl->async_run_work = CreateThreadpoolWork(async_void_run_cb, &impl->IAsyncAction_iface, NULL))) + if (!(impl->async_run_work = CreateThreadpoolWork( async_info_callback, &impl->IAsyncInfoImpl_iface, NULL ))) { - free(impl); - return HRESULT_FROM_WIN32(GetLastError()); + hr = HRESULT_FROM_WIN32( GetLastError() ); + free( impl ); + return hr; }
- if (invoker) IInspectable_AddRef((impl->invoker = invoker)); + if ((impl->invoker = invoker)) IUnknown_AddRef( impl->invoker ); + if ((impl->param = param)) IUnknown_AddRef( impl->param );
- InitializeCriticalSectionEx(&impl->cs, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO); - impl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": async_action.cs"); + InitializeCriticalSectionEx( &impl->cs, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO ); + impl->cs.DebugInfo->Spare[0] = (DWORD_PTR)( __FILE__ ": async_info.cs" );
- /* AddRef to keep the obj alive in the callback. */ - IAsyncAction_AddRef(&impl->IAsyncAction_iface); - SubmitThreadpoolWork(impl->async_run_work); - - *out = &impl->IAsyncAction_iface; - TRACE("created %p\n", *out); + *out = &impl->IAsyncInfoImpl_iface; return S_OK; }
-/* - * - * IAsyncOperation<IInspectable*> - * - */ - -struct async_inspectable +struct async_bool { - IAsyncOperation_IInspectable IAsyncOperation_IInspectable_iface; - IAsyncInfo IAsyncInfo_iface; - const GUID *iid; + IAsyncOperation_boolean IAsyncOperation_boolean_iface; + IAsyncInfoImpl *IAsyncInfoImpl_inner; LONG ref; - - IAsyncOperationCompletedHandler_IInspectable *handler; - IInspectable *result; - - async_operation_inspectable_callback callback; - TP_WORK *async_run_work; - IInspectable *invoker; - - CRITICAL_SECTION cs; - AsyncStatus status; - HRESULT hr; };
-static inline struct async_inspectable *impl_from_IAsyncOperation_IInspectable(IAsyncOperation_IInspectable *iface) +static inline struct async_bool *impl_from_IAsyncOperation_boolean( IAsyncOperation_boolean *iface ) { - return CONTAINING_RECORD(iface, struct async_inspectable, IAsyncOperation_IInspectable_iface); + return CONTAINING_RECORD( iface, struct async_bool, IAsyncOperation_boolean_iface ); }
-static HRESULT WINAPI async_inspectable_QueryInterface( IAsyncOperation_IInspectable *iface, REFIID iid, void **out ) +static HRESULT WINAPI async_bool_QueryInterface( IAsyncOperation_boolean *iface, REFIID iid, void **out ) { - struct async_inspectable *impl = impl_from_IAsyncOperation_IInspectable(iface); + struct async_bool *impl = impl_from_IAsyncOperation_boolean( iface );
- TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out); + 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, impl->iid)) + if (IsEqualGUID( iid, &IID_IUnknown ) || + IsEqualGUID( iid, &IID_IInspectable ) || + IsEqualGUID( iid, &IID_IAgileObject ) || + IsEqualGUID( iid, &IID_IAsyncOperation_boolean )) { - IInspectable_AddRef((*out = &impl->IAsyncOperation_IInspectable_iface)); + 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; + return IAsyncInfoImpl_QueryInterface( impl->IAsyncInfoImpl_inner, iid, out ); }
-static ULONG WINAPI async_inspectable_AddRef( IAsyncOperation_IInspectable *iface ) +static ULONG WINAPI async_bool_AddRef( IAsyncOperation_boolean *iface ) { - struct async_inspectable *impl = impl_from_IAsyncOperation_IInspectable(iface); - ULONG ref = InterlockedIncrement(&impl->ref); - TRACE("iface %p, ref %lu.\n", iface, ref); + 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_inspectable_Release( IAsyncOperation_IInspectable *iface ) +static ULONG WINAPI async_bool_Release( IAsyncOperation_boolean *iface ) { - struct async_inspectable *impl = impl_from_IAsyncOperation_IInspectable(iface); - - ULONG ref = InterlockedDecrement(&impl->ref); - TRACE("iface %p, ref %lu.\n", iface, ref); + 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->invoker) - IInspectable_Release(impl->invoker); - if (impl->handler && impl->handler != HANDLER_NOT_SET) - IAsyncOperationCompletedHandler_IInspectable_Release(impl->handler); - if (impl->result) - IInspectable_Release(impl->result); - - impl->cs.DebugInfo->Spare[0] = 0; - DeleteCriticalSection(&impl->cs); - free(impl); + /* guard against re-entry if inner releases an outer iface */ + InterlockedIncrement( &impl->ref ); + IAsyncInfoImpl_Release( impl->IAsyncInfoImpl_inner ); + free( impl ); }
return ref; }
-static HRESULT WINAPI async_inspectable_GetIids( IAsyncOperation_IInspectable *iface, ULONG *iid_count, IID **iids ) +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); + FIXME( "iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids ); return E_NOTIMPL; }
-static HRESULT WINAPI async_inspectable_GetRuntimeClassName( IAsyncOperation_IInspectable *iface, HSTRING *class_name ) +static HRESULT WINAPI async_bool_GetRuntimeClassName( IAsyncOperation_boolean *iface, HSTRING *class_name ) { - FIXME("iface %p, class_name %p stub!\n", iface, class_name); - return E_NOTIMPL; + return WindowsCreateString( L"Windows.Foundation.IAsyncOperation`1<Boolean>", + ARRAY_SIZE(L"Windows.Foundation.IAsyncOperation`1<Boolean>"), + class_name ); }
-static HRESULT WINAPI async_inspectable_GetTrustLevel( IAsyncOperation_IInspectable *iface, TrustLevel *trust_level ) +static HRESULT WINAPI async_bool_GetTrustLevel( IAsyncOperation_boolean *iface, TrustLevel *trust_level ) { - FIXME("iface %p, trust_level %p stub!\n", iface, trust_level); + FIXME( "iface %p, trust_level %p stub!\n", iface, trust_level ); return E_NOTIMPL; }
-static HRESULT WINAPI async_inspectable_put_Completed( IAsyncOperation_IInspectable *iface, - IAsyncOperationCompletedHandler_IInspectable *handler ) +static HRESULT WINAPI async_bool_put_Completed( IAsyncOperation_boolean *iface, IAsyncOperationCompletedHandler_boolean *bool_handler ) { - struct async_inspectable *impl = impl_from_IAsyncOperation_IInspectable(iface); - HRESULT hr = S_OK; + IAsyncOperationCompletedHandlerImpl *handler = (IAsyncOperationCompletedHandlerImpl *)bool_handler; + struct async_bool *impl = impl_from_IAsyncOperation_boolean( iface ); + TRACE( "iface %p, handler %p.\n", iface, handler ); + return IAsyncInfoImpl_put_Completed( impl->IAsyncInfoImpl_inner, handler ); +}
- 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; - /* - impl->handler can only be set once with async_inspectable_put_Completed, - so by default we set a non HANDLER_NOT_SET value, in this case handler. - */ - else if ((impl->handler = handler)) - { - IAsyncOperationCompletedHandler_IInspectable_AddRef(impl->handler); +static HRESULT WINAPI async_bool_get_Completed( IAsyncOperation_boolean *iface, IAsyncOperationCompletedHandler_boolean **bool_handler ) +{ + IAsyncOperationCompletedHandlerImpl **handler = (IAsyncOperationCompletedHandlerImpl **)bool_handler; + struct async_bool *impl = impl_from_IAsyncOperation_boolean( iface ); + TRACE( "iface %p, handler %p.\n", iface, handler ); + return IAsyncInfoImpl_get_Completed( impl->IAsyncInfoImpl_inner, handler ); +}
- if (impl->status > Started) - { - IAsyncOperation_IInspectable *operation = &impl->IAsyncOperation_IInspectable_iface; - AsyncStatus status = impl->status; - impl->handler = NULL; /* Prevent concurrent invoke. */ - LeaveCriticalSection(&impl->cs); +static HRESULT WINAPI async_bool_GetResults( IAsyncOperation_boolean *iface, BOOLEAN *results ) +{ + struct async_bool *impl = impl_from_IAsyncOperation_boolean( iface ); + PROPVARIANT result = {.vt = VT_BOOL}; + HRESULT hr;
- IAsyncOperationCompletedHandler_IInspectable_Invoke(handler, operation, status); - IAsyncOperationCompletedHandler_IInspectable_Release(handler); + TRACE( "iface %p, results %p.\n", iface, results );
- return S_OK; - } - } - LeaveCriticalSection(&impl->cs); + hr = IAsyncInfoImpl_get_Result( impl->IAsyncInfoImpl_inner, &result );
+ *results = result.boolVal; + PropVariantClear( &result ); return hr; }
-static HRESULT WINAPI async_inspectable_get_Completed( IAsyncOperation_IInspectable *iface, - IAsyncOperationCompletedHandler_IInspectable **handler ) +static const struct IAsyncOperation_booleanVtbl async_bool_vtbl = { - struct async_inspectable *impl = impl_from_IAsyncOperation_IInspectable(iface); - HRESULT hr = S_OK; + /* 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, +};
- FIXME("iface %p, handler %p semi stub!\n", iface, handler); +HRESULT async_operation_boolean_create( IUnknown *invoker, IUnknown *param, async_operation_callback callback, + IAsyncOperation_boolean **out ) +{ + struct async_bool *impl; + HRESULT hr;
- EnterCriticalSection(&impl->cs); - if (impl->status == Closed) - hr = E_ILLEGAL_METHOD_CALL; - *handler = (impl->handler != HANDLER_NOT_SET) ? impl->handler : NULL; - LeaveCriticalSection(&impl->cs); + *out = NULL; + if (!(impl = calloc( 1, sizeof(*impl) ))) return E_OUTOFMEMORY; + impl->IAsyncOperation_boolean_iface.lpVtbl = &async_bool_vtbl; + impl->ref = 1;
- return hr; + if (FAILED(hr = async_info_create( invoker, param, callback, (IInspectable *)&impl->IAsyncOperation_boolean_iface, &impl->IAsyncInfoImpl_inner )) || + FAILED(hr = IAsyncInfoImpl_Start( impl->IAsyncInfoImpl_inner ))) + { + if (impl->IAsyncInfoImpl_inner) IAsyncInfoImpl_Release( impl->IAsyncInfoImpl_inner ); + free( impl ); + return hr; + } + + *out = &impl->IAsyncOperation_boolean_iface; + TRACE( "created IAsyncOperation_boolean %p\n", *out ); + return S_OK; }
-static HRESULT WINAPI async_inspectable_GetResults( IAsyncOperation_IInspectable *iface, IInspectable **results ) +struct async_action { - /* NOTE: Despite the name, this function only returns one result! */ - struct async_inspectable *impl = impl_from_IAsyncOperation_IInspectable(iface); - HRESULT hr; + IAsyncAction IAsyncAction_iface; + IAsyncInfoImpl *IAsyncInfoImpl_inner; + LONG ref; +}; + +static inline struct async_action *impl_from_IAsyncAction( IAsyncAction *iface ) +{ + return CONTAINING_RECORD( iface, struct async_action, IAsyncAction_iface ); +} + +static HRESULT WINAPI async_action_QueryInterface( IAsyncAction *iface, REFIID iid, void **out ) +{ + struct async_action *impl = impl_from_IAsyncAction( iface );
- TRACE("iface %p, results %p.\n", iface, results); + TRACE( "iface %p, iid %s, out %p.\n", iface, debugstr_guid( iid ), out );
- EnterCriticalSection(&impl->cs); - if (impl->status != Completed && impl->status != Error) - hr = E_ILLEGAL_METHOD_CALL; - else if (!impl->result) - hr = E_UNEXPECTED; - else + if (IsEqualGUID( iid, &IID_IUnknown ) || + IsEqualGUID( iid, &IID_IInspectable ) || + IsEqualGUID( iid, &IID_IAgileObject ) || + IsEqualGUID( iid, &IID_IAsyncAction )) { - *results = impl->result; - impl->result = NULL; /* NOTE: AsyncOperation gives up it's reference to result here! */ - hr = impl->hr; + IInspectable_AddRef( (*out = &impl->IAsyncAction_iface) ); + return S_OK; } - LeaveCriticalSection(&impl->cs);
- return hr; + return IAsyncInfoImpl_QueryInterface( impl->IAsyncInfoImpl_inner, iid, out ); }
-static const struct IAsyncOperation_IInspectableVtbl async_inspectable_vtbl = +static ULONG WINAPI async_action_AddRef( IAsyncAction *iface ) { - /* IUnknown methods */ - async_inspectable_QueryInterface, - async_inspectable_AddRef, - async_inspectable_Release, - /* IInspectable methods */ - async_inspectable_GetIids, - async_inspectable_GetRuntimeClassName, - async_inspectable_GetTrustLevel, - /* IAsyncOperation<IInspectable*> */ - async_inspectable_put_Completed, - async_inspectable_get_Completed, - async_inspectable_GetResults -}; + struct async_action *impl = impl_from_IAsyncAction( iface ); + ULONG ref = InterlockedIncrement( &impl->ref ); + TRACE( "iface %p, ref %lu.\n", iface, ref ); + return ref; +}
-/* - * - * IAsyncInfo for IAsyncOperation<IInspectable*> - * - */ +static ULONG WINAPI async_action_Release( IAsyncAction *iface ) +{ + struct async_action *impl = impl_from_IAsyncAction( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + TRACE( "iface %p, ref %lu.\n", iface, ref ); + + if (!ref) + { + /* guard against re-entry if inner releases an outer iface */ + InterlockedIncrement( &impl->ref ); + IAsyncInfoImpl_Release( impl->IAsyncInfoImpl_inner ); + free( impl ); + }
-DEFINE_IINSPECTABLE_(async_inspectable_info, IAsyncInfo, struct async_inspectable, - async_inspectable_impl_from_IAsyncInfo, IAsyncInfo_iface, &impl->IAsyncOperation_IInspectable_iface) + return ref; +}
-static HRESULT WINAPI async_inspectable_info_get_Id( IAsyncInfo *iface, UINT32 *id ) +static HRESULT WINAPI async_action_GetIids( IAsyncAction *iface, ULONG *iid_count, IID **iids ) { - FIXME("iface %p, id %p stub!\n", iface, id); + FIXME( "iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids ); return E_NOTIMPL; }
-static HRESULT WINAPI async_inspectable_info_get_Status( IAsyncInfo *iface, AsyncStatus *status ) +static HRESULT WINAPI async_action_GetRuntimeClassName( IAsyncAction *iface, HSTRING *class_name ) { - struct async_inspectable *impl = async_inspectable_impl_from_IAsyncInfo(iface); - HRESULT hr = S_OK; + return WindowsCreateString( L"Windows.Foundation.IAsyncOperation`1<Boolean>", + ARRAY_SIZE(L"Windows.Foundation.IAsyncOperation`1<Boolean>"), + class_name ); +}
- TRACE("iface %p, status %p.\n", iface, status); +static HRESULT WINAPI async_action_GetTrustLevel( IAsyncAction *iface, TrustLevel *trust_level ) +{ + FIXME( "iface %p, trust_level %p stub!\n", iface, trust_level ); + return E_NOTIMPL; +}
- EnterCriticalSection(&impl->cs); - if (impl->status == Closed) - hr = E_ILLEGAL_METHOD_CALL; - *status = impl->status; - LeaveCriticalSection(&impl->cs); +static HRESULT WINAPI async_action_put_Completed( IAsyncAction *iface, IAsyncActionCompletedHandler *bool_handler ) +{ + IAsyncOperationCompletedHandlerImpl *handler = (IAsyncOperationCompletedHandlerImpl *)bool_handler; + struct async_action *impl = impl_from_IAsyncAction( iface ); + TRACE( "iface %p, handler %p.\n", iface, handler ); + return IAsyncInfoImpl_put_Completed( impl->IAsyncInfoImpl_inner, handler ); +} + +static HRESULT WINAPI async_action_get_Completed( IAsyncAction *iface, IAsyncActionCompletedHandler **bool_handler ) +{ + IAsyncOperationCompletedHandlerImpl **handler = (IAsyncOperationCompletedHandlerImpl **)bool_handler; + struct async_action *impl = impl_from_IAsyncAction( iface ); + TRACE( "iface %p, handler %p.\n", iface, handler ); + return IAsyncInfoImpl_get_Completed( impl->IAsyncInfoImpl_inner, handler ); +} + +static HRESULT WINAPI async_action_GetResults( IAsyncAction *iface ) +{ + struct async_action *impl = impl_from_IAsyncAction( iface ); + PROPVARIANT result; + HRESULT hr;
+ TRACE( "iface %p.\n", iface ); + + PropVariantInit( &result ); + hr = IAsyncInfoImpl_get_Result( impl->IAsyncInfoImpl_inner, &result ); + PropVariantClear( &result ); return hr; }
-static HRESULT WINAPI async_inspectable_info_get_ErrorCode( IAsyncInfo *iface, HRESULT *error_code ) +static const struct IAsyncActionVtbl async_action_vtbl = { - struct async_inspectable *impl = async_inspectable_impl_from_IAsyncInfo(iface); - HRESULT hr = S_OK; + /* IUnknown methods */ + async_action_QueryInterface, + async_action_AddRef, + async_action_Release, + /* IInspectable methods */ + async_action_GetIids, + async_action_GetRuntimeClassName, + async_action_GetTrustLevel, + /* IAsyncOperation<boolean> */ + async_action_put_Completed, + async_action_get_Completed, + async_action_GetResults, +};
- TRACE("iface %p, error_code %p.\n", iface, error_code); +HRESULT async_action_create( IUnknown *invoker, async_operation_callback callback, IAsyncAction **out ) +{ + struct async_action *impl; + HRESULT hr;
- EnterCriticalSection(&impl->cs); - if (impl->status == Closed) - *error_code = hr = E_ILLEGAL_METHOD_CALL; - else - *error_code = impl->hr; - LeaveCriticalSection(&impl->cs); + *out = NULL; + if (!(impl = calloc( 1, sizeof(*impl) ))) return E_OUTOFMEMORY; + impl->IAsyncAction_iface.lpVtbl = &async_action_vtbl; + impl->ref = 1;
- return hr; + if (FAILED(hr = async_info_create( invoker, NULL, callback, (IInspectable *)&impl->IAsyncAction_iface, &impl->IAsyncInfoImpl_inner )) || + FAILED(hr = IAsyncInfoImpl_Start( impl->IAsyncInfoImpl_inner ))) + { + if (impl->IAsyncInfoImpl_inner) IAsyncInfoImpl_Release( impl->IAsyncInfoImpl_inner ); + free( impl ); + return hr; + } + + *out = &impl->IAsyncAction_iface; + TRACE( "created IAsyncAction %p\n", *out ); + return S_OK; }
-static HRESULT WINAPI async_inspectable_info_Cancel( IAsyncInfo *iface ) +struct async_inspectable { - struct async_inspectable *impl = async_inspectable_impl_from_IAsyncInfo(iface); - HRESULT hr = S_OK; + IAsyncOperation_IInspectable IAsyncOperation_IInspectable_iface; + IAsyncInfoImpl *IAsyncInfoImpl_inner; + LONG ref; + const GUID *iid; +}; + +static inline struct async_inspectable *impl_from_IAsyncOperation_IInspectable( IAsyncOperation_IInspectable *iface ) +{ + return CONTAINING_RECORD( iface, struct async_inspectable, IAsyncOperation_IInspectable_iface ); +} + +static HRESULT WINAPI async_inspectable_QueryInterface( IAsyncOperation_IInspectable *iface, REFIID iid, void **out ) +{ + struct async_inspectable *impl = impl_from_IAsyncOperation_IInspectable( iface );
- TRACE("iface %p.\n", iface); + TRACE( "iface %p, iid %s, out %p.\n", iface, debugstr_guid( iid ), out );
- EnterCriticalSection(&impl->cs); - if (impl->status == Closed) - hr = E_ILLEGAL_METHOD_CALL; - else if (impl->status == Started) - impl->status = Canceled; - LeaveCriticalSection(&impl->cs); + if (IsEqualGUID( iid, &IID_IUnknown ) || + IsEqualGUID( iid, &IID_IInspectable ) || + IsEqualGUID( iid, &IID_IAgileObject ) || + IsEqualGUID( iid, impl->iid )) + { + IInspectable_AddRef( (*out = &impl->IAsyncOperation_IInspectable_iface) ); + return S_OK; + }
- return hr; + return IAsyncInfoImpl_QueryInterface( impl->IAsyncInfoImpl_inner, iid, out ); }
-static HRESULT WINAPI async_inspectable_info_Close( IAsyncInfo *iface ) +static ULONG WINAPI async_inspectable_AddRef( IAsyncOperation_IInspectable *iface ) { - struct async_inspectable *impl = async_inspectable_impl_from_IAsyncInfo(iface); - HRESULT hr = S_OK; + struct async_inspectable *impl = impl_from_IAsyncOperation_IInspectable( iface ); + ULONG ref = InterlockedIncrement( &impl->ref ); + TRACE( "iface %p, ref %lu.\n", iface, ref ); + return ref; +}
- TRACE("iface %p.\n", iface); +static ULONG WINAPI async_inspectable_Release( IAsyncOperation_IInspectable *iface ) +{ + struct async_inspectable *impl = impl_from_IAsyncOperation_IInspectable( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + TRACE( "iface %p, ref %lu.\n", iface, ref );
- EnterCriticalSection(&impl->cs); - if (impl->status == Started) - hr = E_ILLEGAL_STATE_CHANGE; - else if (impl->status != Closed) + if (!ref) { - CloseThreadpoolWork(impl->async_run_work); - impl->async_run_work = NULL; - impl->status = Closed; + /* guard against re-entry if inner releases an outer iface */ + InterlockedIncrement( &impl->ref ); + IAsyncInfoImpl_Release( impl->IAsyncInfoImpl_inner ); + free( impl ); } - LeaveCriticalSection(&impl->cs);
- return hr; + return ref; }
-static const struct IAsyncInfoVtbl async_inspectable_info_vtbl = +static HRESULT WINAPI async_inspectable_GetIids( IAsyncOperation_IInspectable *iface, ULONG *iid_count, IID **iids ) { - /* IUnknown methods */ - async_inspectable_info_QueryInterface, - async_inspectable_info_AddRef, - async_inspectable_info_Release, - /* IInspectable methods */ - async_inspectable_info_GetIids, - async_inspectable_info_GetRuntimeClassName, - async_inspectable_info_GetTrustLevel, - /* IAsyncInfo */ - async_inspectable_info_get_Id, - async_inspectable_info_get_Status, - async_inspectable_info_get_ErrorCode, - async_inspectable_info_Cancel, - async_inspectable_info_Close -}; + FIXME( "iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids ); + return E_NOTIMPL; +}
-static void CALLBACK async_inspectable_run_cb(TP_CALLBACK_INSTANCE *instance, void *data, TP_WORK *work) +static HRESULT WINAPI async_inspectable_GetRuntimeClassName( IAsyncOperation_IInspectable *iface, HSTRING *class_name ) { - IAsyncOperation_IInspectable *operation = data; - IInspectable *result = NULL; - struct async_inspectable *impl = impl_from_IAsyncOperation_IInspectable(operation); - HRESULT hr; + return WindowsCreateString( L"Windows.Foundation.IAsyncOperation`1<IInspectable>", + ARRAY_SIZE(L"Windows.Foundation.IAsyncOperation`1<IInspectable>"), + class_name ); +}
- hr = impl->callback(impl->invoker, &result); +static HRESULT WINAPI async_inspectable_GetTrustLevel( IAsyncOperation_IInspectable *iface, TrustLevel *trust_level ) +{ + FIXME( "iface %p, trust_level %p stub!\n", iface, trust_level ); + return E_NOTIMPL; +}
- EnterCriticalSection(&impl->cs); - if (impl->status < Closed) - impl->status = FAILED(hr) ? Error : Completed; +static HRESULT WINAPI async_inspectable_put_Completed( IAsyncOperation_IInspectable *iface, IAsyncOperationCompletedHandler_IInspectable *bool_handler ) +{ + IAsyncOperationCompletedHandlerImpl *handler = (IAsyncOperationCompletedHandlerImpl *)bool_handler; + struct async_inspectable *impl = impl_from_IAsyncOperation_IInspectable( iface ); + TRACE( "iface %p, handler %p.\n", iface, handler ); + return IAsyncInfoImpl_put_Completed( impl->IAsyncInfoImpl_inner, handler ); +}
- impl->result = result; - impl->hr = hr; +static HRESULT WINAPI async_inspectable_get_Completed( IAsyncOperation_IInspectable *iface, IAsyncOperationCompletedHandler_IInspectable **bool_handler ) +{ + IAsyncOperationCompletedHandlerImpl **handler = (IAsyncOperationCompletedHandlerImpl **)bool_handler; + struct async_inspectable *impl = impl_from_IAsyncOperation_IInspectable( iface ); + TRACE( "iface %p, handler %p.\n", iface, handler ); + return IAsyncInfoImpl_get_Completed( impl->IAsyncInfoImpl_inner, handler ); +}
- if (impl->handler != NULL && impl->handler != HANDLER_NOT_SET) - { - IAsyncOperationCompletedHandler_IInspectable *handler = impl->handler; - AsyncStatus status = impl->status; - impl->handler = NULL; /* Prevent concurrent invoke. */ - LeaveCriticalSection(&impl->cs); +static HRESULT WINAPI async_inspectable_GetResults( IAsyncOperation_IInspectable *iface, IInspectable **results ) +{ + struct async_inspectable *impl = impl_from_IAsyncOperation_IInspectable( iface ); + PROPVARIANT result = {.vt = VT_UNKNOWN}; + HRESULT hr;
- IAsyncOperationCompletedHandler_IInspectable_Invoke(handler, operation, status); - IAsyncOperationCompletedHandler_IInspectable_Release(handler); + TRACE( "iface %p, results %p.\n", iface, results ); + + if (SUCCEEDED(hr = IAsyncInfoImpl_get_Result( impl->IAsyncInfoImpl_inner, &result ))) + { + if ((*results = (IInspectable *)result.punkVal)) IInspectable_AddRef( *results ); + PropVariantClear( &result ); } - else LeaveCriticalSection(&impl->cs);
- IAsyncOperation_IInspectable_Release(operation); + return hr; }
-HRESULT async_operation_inspectable_create( const GUID *iid, - IInspectable *invoker, - async_operation_inspectable_callback callback, +static const struct IAsyncOperation_IInspectableVtbl async_inspectable_vtbl = +{ + /* IUnknown methods */ + async_inspectable_QueryInterface, + async_inspectable_AddRef, + async_inspectable_Release, + /* IInspectable methods */ + async_inspectable_GetIids, + async_inspectable_GetRuntimeClassName, + async_inspectable_GetTrustLevel, + /* IAsyncOperation<IInspectable> */ + async_inspectable_put_Completed, + async_inspectable_get_Completed, + async_inspectable_GetResults, +}; + +HRESULT async_operation_inspectable_create( const GUID *iid, IUnknown *invoker, IUnknown *param, async_operation_callback callback, IAsyncOperation_IInspectable **out ) { struct async_inspectable *impl; - - TRACE("iid %s, invoker %p, callback %p, out %p.\n", debugstr_guid(iid), invoker, callback, out); + HRESULT hr;
*out = NULL; - if (!(impl = calloc(1, sizeof(*impl)))) return E_OUTOFMEMORY; + if (!(impl = calloc( 1, sizeof(*impl) ))) return E_OUTOFMEMORY; impl->IAsyncOperation_IInspectable_iface.lpVtbl = &async_inspectable_vtbl; - impl->IAsyncInfo_iface.lpVtbl = &async_inspectable_info_vtbl; - impl->iid = iid; impl->ref = 1; + impl->iid = iid;
- impl->handler = HANDLER_NOT_SET; - impl->callback = callback; - impl->status = Started; - - if (!(impl->async_run_work = CreateThreadpoolWork(async_inspectable_run_cb, &impl->IAsyncOperation_IInspectable_iface, NULL))) + if (FAILED(hr = async_info_create( invoker, param, callback, (IInspectable *)&impl->IAsyncOperation_IInspectable_iface, &impl->IAsyncInfoImpl_inner )) || + FAILED(hr = IAsyncInfoImpl_Start( impl->IAsyncInfoImpl_inner ))) { - free(impl); - return HRESULT_FROM_WIN32(GetLastError()); + if (impl->IAsyncInfoImpl_inner) IAsyncInfoImpl_Release( impl->IAsyncInfoImpl_inner ); + free( impl ); + return hr; }
- if (invoker) IInspectable_AddRef((impl->invoker = invoker)); - - InitializeCriticalSectionEx(&impl->cs, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO); - impl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": async_operation.cs"); - - /* AddRef to keep the obj alive in the callback. */ - IAsyncOperation_IInspectable_AddRef(&impl->IAsyncOperation_IInspectable_iface); - SubmitThreadpoolWork(impl->async_run_work); - *out = &impl->IAsyncOperation_IInspectable_iface; - TRACE("created %p\n", *out); + TRACE( "created IAsyncOperation_IInspectable %p\n", *out ); return S_OK; } diff --git a/dlls/windows.media.speech/async_private.idl b/dlls/windows.media.speech/async_private.idl new file mode 100644 index 00000000000..10741572601 --- /dev/null +++ b/dlls/windows.media.speech/async_private.idl @@ -0,0 +1,46 @@ +/* + * 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 + */ + +#pragma makedep header + +#ifdef __WIDL__ +#pragma winrt ns_prefix +#endif + +import "propidl.idl"; +import "inspectable.idl"; +import "asyncinfo.idl"; +import "windowscontracts.idl"; + +namespace Wine.Internal { + /* type-pruning version of AsyncOperationCompletedHandlerImpl<T> */ + delegate HRESULT AsyncOperationCompletedHandlerImpl([in] IInspectable *async, [in] AsyncStatus status); + + [ + uuid(d81ab70d-82e0-481c-983d-401225d98a2c) + ] + interface IAsyncInfoImpl : IUnknown + { + [propput] HRESULT Completed([in] AsyncOperationCompletedHandlerImpl *handler); + [propget] HRESULT Completed([out, retval] AsyncOperationCompletedHandlerImpl **handler); + [propget] HRESULT Result([out, retval] PROPVARIANT *result); + HRESULT Start(); + } + + typedef HRESULT (*async_operation_callback)( IUnknown *invoker, IUnknown *param, PROPVARIANT *result ); +} diff --git a/dlls/windows.media.speech/private.h b/dlls/windows.media.speech/private.h index e80d73ec1fb..fb5b936fb01 100644 --- a/dlls/windows.media.speech/private.h +++ b/dlls/windows.media.speech/private.h @@ -43,6 +43,8 @@
#include "wine/list.h"
+#include "async_private.h" + /* * * Windows.Media.SpeechRecognition @@ -70,11 +72,8 @@ struct vector_iids const GUID *view; };
-typedef HRESULT (*async_action_callback)( IInspectable *invoker ); -typedef HRESULT (*async_operation_inspectable_callback)( IInspectable *invoker, IInspectable **result ); - -HRESULT async_action_create( IInspectable *invoker, async_action_callback callback, IAsyncAction **out ); -HRESULT async_operation_inspectable_create( const GUID *iid, IInspectable *invoker, async_operation_inspectable_callback callback, +HRESULT async_action_create( IUnknown *invoker, async_operation_callback callback, IAsyncAction **out ); +HRESULT async_operation_inspectable_create( const GUID *iid, IUnknown *invoker, IUnknown *param, async_operation_callback callback, IAsyncOperation_IInspectable **out );
HRESULT typed_event_handlers_append( struct list *list, ITypedEventHandler_IInspectable_IInspectable *handler, EventRegistrationToken *token ); diff --git a/dlls/windows.media.speech/recognizer.c b/dlls/windows.media.speech/recognizer.c index a98970d35f9..5c83beec063 100644 --- a/dlls/windows.media.speech/recognizer.c +++ b/dlls/windows.media.speech/recognizer.c @@ -382,7 +382,7 @@ static HRESULT WINAPI session_set_AutoStopSilenceTimeout( ISpeechContinuousRecog return E_NOTIMPL; }
-static HRESULT session_start_async( IInspectable *invoker ) +static HRESULT session_start_async( IUnknown *invoker, IUnknown *param, PROPVARIANT *result ) { return S_OK; } @@ -431,7 +431,7 @@ static HRESULT WINAPI session_StartWithModeAsync( ISpeechContinuousRecognitionSe return E_NOTIMPL; }
-static HRESULT session_stop_async( IInspectable *invoker ) +static HRESULT session_stop_async( IUnknown *invoker, IUnknown *param, PROPVARIANT *result ) { return S_OK; } @@ -487,7 +487,7 @@ static HRESULT WINAPI session_CancelAsync( ISpeechContinuousRecognitionSession * return E_NOTIMPL; }
-static HRESULT session_pause_async( IInspectable *invoker ) +static HRESULT session_pause_async( IUnknown *invoker, IUnknown *param, PROPVARIANT *result ) { return S_OK; } @@ -725,9 +725,17 @@ static HRESULT WINAPI recognizer_get_UIOptions( ISpeechRecognizer *iface, ISpeec return E_NOTIMPL; }
-static HRESULT recognizer_compile_constraints_async( IInspectable *invoker, IInspectable **result ) +static HRESULT recognizer_compile_constraints_async( IUnknown *invoker, IUnknown *param, PROPVARIANT *result ) { - return compilation_result_create(SpeechRecognitionResultStatus_Success, (ISpeechRecognitionCompilationResult **) result); + ISpeechRecognitionCompilationResult *compilation; + HRESULT hr; + + if (SUCCEEDED(hr = compilation_result_create(SpeechRecognitionResultStatus_Success, &compilation))) + { + result->vt = VT_UNKNOWN; + result->punkVal = (IUnknown *)compilation; + } + return hr; }
static HRESULT WINAPI recognizer_CompileConstraintsAsync( ISpeechRecognizer *iface, @@ -735,7 +743,7 @@ static HRESULT WINAPI recognizer_CompileConstraintsAsync( ISpeechRecognizer *ifa { IAsyncOperation_IInspectable **value = (IAsyncOperation_IInspectable **)operation; FIXME("iface %p, operation %p semi-stub!\n", iface, operation); - return async_operation_inspectable_create(&IID_IAsyncOperation_SpeechRecognitionCompilationResult, NULL, recognizer_compile_constraints_async, value); + return async_operation_inspectable_create(&IID_IAsyncOperation_SpeechRecognitionCompilationResult, NULL, NULL, recognizer_compile_constraints_async, value); }
static HRESULT WINAPI recognizer_RecognizeAsync( ISpeechRecognizer *iface, diff --git a/dlls/windows.media.speech/synthesizer.c b/dlls/windows.media.speech/synthesizer.c index 39d14b84ab7..80968333c8a 100644 --- a/dlls/windows.media.speech/synthesizer.c +++ b/dlls/windows.media.speech/synthesizer.c @@ -375,29 +375,45 @@ static HRESULT WINAPI synthesizer_GetTrustLevel( ISpeechSynthesizer *iface, Trus return E_NOTIMPL; }
-static HRESULT synthesizer_synthesize_text_to_stream_async( IInspectable *invoker, IInspectable **result ) +static HRESULT synthesizer_synthesize_text_to_stream_async( IUnknown *invoker, IUnknown *param, PROPVARIANT *result ) { - return synthesis_stream_create((ISpeechSynthesisStream **)result); + ISpeechSynthesisStream *stream; + HRESULT hr; + + if (SUCCEEDED(hr = synthesis_stream_create(&stream))) + { + result->vt = VT_UNKNOWN; + result->punkVal = (IUnknown *)stream; + } + return hr; }
static HRESULT WINAPI synthesizer_SynthesizeTextToStreamAsync( ISpeechSynthesizer *iface, HSTRING text, IAsyncOperation_SpeechSynthesisStream **operation ) { TRACE("iface %p, text %p, operation %p.\n", iface, text, operation); - return async_operation_inspectable_create(&IID_IAsyncOperation_SpeechSynthesisStream, NULL, + return async_operation_inspectable_create(&IID_IAsyncOperation_SpeechSynthesisStream, NULL, NULL, synthesizer_synthesize_text_to_stream_async, (IAsyncOperation_IInspectable **)operation); }
-static HRESULT synthesizer_synthesize_ssml_to_stream_async( IInspectable *invoker, IInspectable **result ) +static HRESULT synthesizer_synthesize_ssml_to_stream_async( IUnknown *invoker, IUnknown *param, PROPVARIANT *result ) { - return synthesis_stream_create((ISpeechSynthesisStream **)result); + ISpeechSynthesisStream *stream; + HRESULT hr; + + if (SUCCEEDED(hr = synthesis_stream_create(&stream))) + { + result->vt = VT_UNKNOWN; + result->punkVal = (IUnknown *)stream; + } + return hr; }
static HRESULT WINAPI synthesizer_SynthesizeSsmlToStreamAsync( ISpeechSynthesizer *iface, HSTRING ssml, IAsyncOperation_SpeechSynthesisStream **operation ) { TRACE("iface %p, ssml %p, operation %p.\n", iface, ssml, operation); - return async_operation_inspectable_create(&IID_IAsyncOperation_SpeechSynthesisStream, NULL, + return async_operation_inspectable_create(&IID_IAsyncOperation_SpeechSynthesisStream, NULL, NULL, synthesizer_synthesize_ssml_to_stream_async, (IAsyncOperation_IInspectable **)operation); }
diff --git a/dlls/windows.media.speech/tests/speech.c b/dlls/windows.media.speech/tests/speech.c index ea1487d379c..7da2457bf38 100644 --- a/dlls/windows.media.speech/tests/speech.c +++ b/dlls/windows.media.speech/tests/speech.c @@ -431,9 +431,9 @@ static void check_async_info_( unsigned int line, IInspectable *async_obj, UINT3
async_id = 0xdeadbeef; hr = IAsyncInfo_get_Id(async_info, &async_id); - if (expect_status < 4) todo_wine ok_(__FILE__, line)(hr == S_OK, "IAsyncInfo_get_Id returned %#lx\n", hr); - else todo_wine ok_(__FILE__, line)(hr == E_ILLEGAL_METHOD_CALL, "IAsyncInfo_get_Id returned %#lx\n", hr); - todo_wine ok_(__FILE__, line)(async_id == expect_id, "got async_id %#x\n", async_id); + if (expect_status < 4) ok_(__FILE__, line)(hr == S_OK, "IAsyncInfo_get_Id returned %#lx\n", hr); + else ok_(__FILE__, line)(hr == E_ILLEGAL_METHOD_CALL, "IAsyncInfo_get_Id returned %#lx\n", hr); + todo_wine_if(expect_id != 1) ok_(__FILE__, line)(async_id == expect_id, "got async_id %#x\n", async_id);
async_status = 0xdeadbeef; hr = IAsyncInfo_get_Status(async_info, &async_status); @@ -787,7 +787,7 @@ static void test_SpeechSynthesizer(void) IVectorView_IMediaMarker *media_markers = NULL; IVectorView_VoiceInformation *voices = NULL; IInstalledVoicesStatic *voices_static = NULL; - ISpeechSynthesisStream *ss_stream = NULL; + ISpeechSynthesisStream *ss_stream = NULL, *tmp; IVoiceInformation *voice; IInspectable *inspectable = NULL, *tmp_inspectable = NULL; IAgileObject *agile_object = NULL, *tmp_agile_object = NULL; @@ -943,6 +943,14 @@ static void test_SpeechSynthesizer(void) hr = IAsyncOperation_SpeechSynthesisStream_GetResults(operation_ss_stream, &ss_stream); ok(hr == S_OK, "IAsyncOperation_SpeechSynthesisStream_GetResults failed, hr %#lx\n", hr);
+ tmp = (void *)0xdeadbeef; + hr = IAsyncOperation_SpeechSynthesisStream_GetResults(operation_ss_stream, &tmp); + ok(hr == S_OK, "IAsyncOperation_SpeechSynthesisStream_GetResults failed, hr %#lx\n", hr); + todo_wine ok(tmp == NULL, "Got %p.\n", tmp); + if (tmp && tmp != (void *)0xdeadbeef) ISpeechSynthesisStream_Release(tmp); + + IAsyncOperation_SpeechSynthesisStream_Release(operation_ss_stream); + hr = ISpeechSynthesisStream_get_Markers(ss_stream, &media_markers); ok(hr == S_OK, "ISpeechSynthesisStream_get_Markers failed, hr %#lx\n", hr); check_interface(media_markers, &IID_IVectorView_IMediaMarker, TRUE); @@ -955,8 +963,6 @@ static void test_SpeechSynthesizer(void) ref = ISpeechSynthesisStream_Release(ss_stream); ok(ref == 0, "Got unexpected ref %lu.\n", ref);
- IAsyncOperation_SpeechSynthesisStream_Release(operation_ss_stream); - /* Test SynthesizeSsmlToStreamAsync */ hr = WindowsCreateString(simple_ssml, wcslen(simple_ssml), &str2); ok(hr == S_OK, "WindowsCreateString failed, hr %#lx\n", hr); @@ -975,12 +981,11 @@ static void test_SpeechSynthesizer(void) ok(hr == S_OK, "IAsyncOperation_SpeechSynthesisStream_GetResults failed, hr %#lx\n", hr); check_interface(ss_stream, &IID_ISpeechSynthesisStream, TRUE); check_interface(ss_stream, &IID_IAgileObject, TRUE); + IAsyncOperation_SpeechSynthesisStream_Release(operation_ss_stream);
ref = ISpeechSynthesisStream_Release(ss_stream); ok(ref == 0, "Got unexpected ref %lu.\n", ref);
- IAsyncOperation_SpeechSynthesisStream_Release(operation_ss_stream); - operation_ss_stream = (void *)0xdeadbeef; hr = ISpeechSynthesizer_SynthesizeSsmlToStreamAsync(synthesizer, NULL, &operation_ss_stream); /* Broken on Win 8 + 8.1 */ @@ -1283,10 +1288,13 @@ static void test_SpeechRecognizer(void) ok(result_status == SpeechRecognitionResultStatus_Success, "Got unexpected status %#x.\n", result_status);
ref = ISpeechRecognitionCompilationResult_Release(compilation_result); - ok(!ref , "Got unexpected ref %lu.\n", ref); + todo_wine ok(!ref , "Got unexpected ref %lu.\n", ref);
+ compilation_result = (void *)0xdeadbeef; hr = IAsyncOperation_SpeechRecognitionCompilationResult_GetResults(operation, &compilation_result); - ok(hr == E_UNEXPECTED, "Got unexpected hr %#lx.\n", hr); + todo_wine ok(hr == E_UNEXPECTED, "Got unexpected hr %#lx.\n", hr); + todo_wine ok(compilation_result == NULL, "Got %p.\n", compilation_result); + if (compilation_result && compilation_result != (void *)0xdeadbeef) ISpeechRecognitionCompilationResult_Release(compilation_result);
hr = IAsyncOperation_SpeechRecognitionCompilationResult_QueryInterface(operation, &IID_IAsyncInfo, (void **)&info); ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);