From: Bernhard Kölbl besentv@gmail.com
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- dlls/windows.media.speech/tests/speech.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/dlls/windows.media.speech/tests/speech.c b/dlls/windows.media.speech/tests/speech.c index 6fd683109b4..935afb3c773 100644 --- a/dlls/windows.media.speech/tests/speech.c +++ b/dlls/windows.media.speech/tests/speech.c @@ -390,7 +390,7 @@ HRESULT WINAPI async_inspectable_handler_Invoke( IAsyncOperationCompletedHandler return S_OK; }
-static const struct IAsyncOperationCompletedHandler_IInspectableVtbl asnyc_inspectable_handler_vtbl = +static const struct IAsyncOperationCompletedHandler_IInspectableVtbl async_inspectable_handler_vtbl = { /* IUnknown methods */ async_inspectable_handler_QueryInterface, @@ -402,7 +402,7 @@ static const struct IAsyncOperationCompletedHandler_IInspectableVtbl asnyc_inspe
static HRESULT WINAPI async_inspectable_handler_create_static( struct async_inspectable_handler *impl, const GUID *iid ) { - impl->IAsyncOperationCompletedHandler_IInspectable_iface.lpVtbl = &asnyc_inspectable_handler_vtbl; + impl->IAsyncOperationCompletedHandler_IInspectable_iface.lpVtbl = &async_inspectable_handler_vtbl; impl->iid = iid; impl->ref = 1;
@@ -425,8 +425,8 @@ static void await_async_inspectable_( unsigned int line, IAsyncOperation_IInspec CloseHandle(handler->event_finished); }
-#define check_async_info(obj, exp_id, exp_status, exp_hr) check_asnyc_info_(__LINE__, obj, exp_id, exp_status, exp_hr) -static void check_asnyc_info_( unsigned int line, IInspectable *async_obj, UINT32 expect_id, AsyncStatus expect_status, HRESULT expect_hr) +#define check_async_info(obj, exp_id, exp_status, exp_hr) check_async_info_(__LINE__, obj, exp_id, exp_status, exp_hr) +static void check_async_info_( unsigned int line, IInspectable *async_obj, UINT32 expect_id, AsyncStatus expect_status, HRESULT expect_hr) { IAsyncInfo *async_info; AsyncStatus async_status;
From: Bernhard Kölbl besentv@gmail.com
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- dlls/windows.media.speech/tests/speech.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/windows.media.speech/tests/speech.c b/dlls/windows.media.speech/tests/speech.c index 935afb3c773..91d8704f2c8 100644 --- a/dlls/windows.media.speech/tests/speech.c +++ b/dlls/windows.media.speech/tests/speech.c @@ -452,7 +452,7 @@ static void check_async_info_( unsigned int line, IInspectable *async_obj, UINT3 hr = IAsyncInfo_get_ErrorCode(async_info, &async_hr); if (expect_status < 4) ok_(__FILE__, line)(hr == S_OK, "IAsyncInfo_get_ErrorCode returned %#lx\n", hr); else ok_(__FILE__, line)(hr == E_ILLEGAL_METHOD_CALL, "IAsyncInfo_get_ErrorCode returned %#lx\n", hr); - if (expect_status < 4) todo_wine_if(FAILED(expect_hr)) ok_(__FILE__, line)(async_hr == expect_hr, "got async_hr %#lx\n", async_hr); + if (expect_status < 4) ok_(__FILE__, line)(async_hr == expect_hr, "got async_hr %#lx\n", async_hr); else ok_(__FILE__, line)(async_hr == E_ILLEGAL_METHOD_CALL, "got async_hr %#lx\n", async_hr);
IAsyncInfo_Release(async_info);
From: Bernhard Kölbl besentv@gmail.com
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- dlls/windows.media.speech/async.c | 126 +++++++++++++++++++++++ dlls/windows.media.speech/private.h | 1 + dlls/windows.media.speech/recognizer.c | 2 +- dlls/windows.media.speech/tests/speech.c | 14 +-- 4 files changed, 135 insertions(+), 8 deletions(-)
diff --git a/dlls/windows.media.speech/async.c b/dlls/windows.media.speech/async.c index eceda4338b3..1abb88528ef 100644 --- a/dlls/windows.media.speech/async.c +++ b/dlls/windows.media.speech/async.c @@ -26,6 +26,132 @@ WINE_DEFAULT_DEBUG_CHANNEL(speech); #define Closed 4 #define HANDLER_NOT_SET ((void *)~(ULONG_PTR)0)
+/* + * + * IAsyncAction + * + */ + +struct async_void +{ + IAsyncAction IAsyncAction_iface; + LONG ref; +}; + +static inline struct async_void *impl_from_IAsyncAction( IAsyncAction *iface ) +{ + return CONTAINING_RECORD(iface, struct async_void, IAsyncAction_iface); +} + +HRESULT WINAPI async_void_QueryInterface( IAsyncAction *iface, REFIID iid, void **out ) +{ + struct async_void *impl = impl_from_IAsyncAction(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_IAsyncAction)) + { + IInspectable_AddRef((*out = &impl->IAsyncAction_iface)); + return S_OK; + } + + WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid)); + *out = NULL; + return E_NOINTERFACE; +} + +ULONG WINAPI async_void_AddRef( IAsyncAction *iface ) +{ + struct async_void *impl = impl_from_IAsyncAction(iface); + ULONG ref = InterlockedIncrement(&impl->ref); + TRACE("iface %p, ref %lu.\n", iface, ref); + return ref; +} + +ULONG WINAPI async_void_Release( IAsyncAction *iface ) +{ + struct async_void *impl = impl_from_IAsyncAction(iface); + ULONG ref = InterlockedDecrement(&impl->ref); + TRACE("iface %p, ref %lu.\n", iface, ref); + 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 ) +{ + FIXME("iface %p, handler %p stub!\n", iface, handler); + return E_NOTIMPL; +} + +HRESULT WINAPI async_void_get_Completed( IAsyncAction *iface, IAsyncActionCompletedHandler **handler ) +{ + FIXME("iface %p, handler %p stub!\n", iface, handler); + return E_NOTIMPL; +} + +HRESULT WINAPI async_void_GetResults( IAsyncAction *iface ) +{ + FIXME("iface %p stub!\n", iface); + return E_NOTIMPL; +} + +static const struct IAsyncActionVtbl async_void_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 +}; + + +HRESULT async_action_create( IAsyncAction **out ) +{ + struct async_void *impl; + + TRACE("out %p.\n", out); + + if (!(impl = calloc(1, sizeof(*impl)))) + { + *out = NULL; + return E_OUTOFMEMORY; + } + + impl->IAsyncAction_iface.lpVtbl = &async_void_vtbl; + impl->ref = 1; + + *out = &impl->IAsyncAction_iface; + TRACE("created %p\n", *out); + return S_OK; +} + /* * * IAsyncOperation<IInspectable*> diff --git a/dlls/windows.media.speech/private.h b/dlls/windows.media.speech/private.h index 97afa4d3499..ba8e942fe5f 100644 --- a/dlls/windows.media.speech/private.h +++ b/dlls/windows.media.speech/private.h @@ -71,6 +71,7 @@ struct vector_iids
typedef HRESULT (WINAPI *async_operation_inspectable_callback)( IInspectable *invoker, IInspectable **result );
+HRESULT async_action_create( IAsyncAction **out ); HRESULT async_operation_inspectable_create( const GUID *iid, IInspectable *invoker, async_operation_inspectable_callback callback, IAsyncOperation_IInspectable **out );
diff --git a/dlls/windows.media.speech/recognizer.c b/dlls/windows.media.speech/recognizer.c index c78f69b0a67..853e9eb9830 100644 --- a/dlls/windows.media.speech/recognizer.c +++ b/dlls/windows.media.speech/recognizer.c @@ -247,7 +247,7 @@ static HRESULT WINAPI session_set_AutoStopSilenceTimeout( ISpeechContinuousRecog static HRESULT WINAPI session_StartAsync( ISpeechContinuousRecognitionSession *iface, IAsyncAction **action ) { FIXME("iface %p, action %p stub!\n", iface, action); - return E_NOTIMPL; + return async_action_create(action); }
static HRESULT WINAPI session_StartWithModeAsync( ISpeechContinuousRecognitionSession *iface, diff --git a/dlls/windows.media.speech/tests/speech.c b/dlls/windows.media.speech/tests/speech.c index 91d8704f2c8..f3b28c40f51 100644 --- a/dlls/windows.media.speech/tests/speech.c +++ b/dlls/windows.media.speech/tests/speech.c @@ -1577,20 +1577,20 @@ static void test_Recognition(void) IAsyncOperation_IInspectable_Release((IAsyncOperation_IInspectable *)operation);
hr = ISpeechContinuousRecognitionSession_StartAsync(session, &action); - todo_wine ok(hr == S_OK, "ISpeechContinuousRecognitionSession_StartAsync failed, hr %#lx.\n", hr); - - if (FAILED(hr)) goto skip_action; - - await_async_void(action, &action_handler); - check_async_info((IInspectable *)action, 1, Completed, S_OK); + ok(hr == S_OK, "ISpeechContinuousRecognitionSession_StartAsync failed, hr %#lx.\n", hr);
handler = (void *)0xdeadbeef; hr = IAsyncAction_get_Completed(action, &handler); todo_wine ok(hr == S_OK, "IAsyncAction_put_Completed failed, hr %#lx.\n", hr); todo_wine ok(handler == NULL, "Handler was %p.\n", handler);
+ if (FAILED(hr)) goto skip_action; + + await_async_void(action, &action_handler); + hr = IAsyncAction_QueryInterface(action, &IID_IAsyncInfo, (void **)&info); todo_wine ok(hr == S_OK, "IAsyncAction_QueryInterface failed, hr %#lx.\n", hr); + check_async_info((IInspectable *)action, 1, Completed, S_OK);
hr = IAsyncInfo_Cancel(info); todo_wine ok(hr == S_OK, "IAsyncInfo_Cancel failed, hr %#lx.\n", hr); @@ -1660,9 +1660,9 @@ static void test_Recognition(void) todo_wine ok(action != action2, "actions were the same!\n");
IAsyncAction_Release(action2); +skip_action: IAsyncAction_Release(action);
-skip_action: hr = ISpeechContinuousRecognitionSession_remove_ResultGenerated(session, token); ok(hr == S_OK, "ISpeechContinuousRecognitionSession_remove_ResultGenerated failed, hr %#lx.\n", hr);
From: Bernhard Kölbl besentv@gmail.com
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- dlls/windows.media.speech/async.c | 63 +++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)
diff --git a/dlls/windows.media.speech/async.c b/dlls/windows.media.speech/async.c index 1abb88528ef..d7ac090be78 100644 --- a/dlls/windows.media.speech/async.c +++ b/dlls/windows.media.speech/async.c @@ -35,6 +35,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(speech); struct async_void { IAsyncAction IAsyncAction_iface; + IAsyncInfo IAsyncInfo_iface; LONG ref; };
@@ -58,6 +59,12 @@ HRESULT WINAPI async_void_QueryInterface( IAsyncAction *iface, REFIID iid, void 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; @@ -131,6 +138,61 @@ static const struct IAsyncActionVtbl async_void_vtbl = async_void_GetResults };
+/* + * + * IAsyncInfo for IAsyncAction + * + */ + +DEFINE_IINSPECTABLE_(async_void_info, IAsyncInfo, struct async_void, impl_from_async_void_IAsyncInfo, IAsyncInfo_iface, &impl->IAsyncAction_iface) + +static HRESULT WINAPI async_void_info_get_Id( IAsyncInfo *iface, UINT32 *id ) +{ + FIXME("iface %p, id %p stub!\n", iface, id); + return E_NOTIMPL; +} + +static HRESULT WINAPI async_void_info_get_Status( IAsyncInfo *iface, AsyncStatus *status ) +{ + FIXME("iface %p, status %p.\n", iface, status); + return E_NOTIMPL; +} + +static HRESULT WINAPI async_void_info_get_ErrorCode( IAsyncInfo *iface, HRESULT *error_code ) +{ + FIXME("iface %p, error_code %p.\n", iface, error_code); + return E_NOTIMPL; +} + +static HRESULT WINAPI async_void_info_Cancel( IAsyncInfo *iface ) +{ + TRACE("iface %p.\n", iface); + return E_NOTIMPL; +} + +static HRESULT WINAPI async_void_info_Close( IAsyncInfo *iface ) +{ + TRACE("iface %p.\n", iface); + return E_NOTIMPL; +} + +static const struct IAsyncInfoVtbl async_void_info_vtbl = +{ + /* IUnknown methods */ + async_void_info_QueryInterface, + async_void_info_AddRef, + async_void_info_Release, + /* IInspectable methods */ + async_void_info_GetIids, + async_void_info_GetRuntimeClassName, + async_void_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 +};
HRESULT async_action_create( IAsyncAction **out ) { @@ -145,6 +207,7 @@ HRESULT async_action_create( IAsyncAction **out ) }
impl->IAsyncAction_iface.lpVtbl = &async_void_vtbl; + impl->IAsyncInfo_iface.lpVtbl = &async_void_info_vtbl; impl->ref = 1;
*out = &impl->IAsyncAction_iface;
From: Bernhard Kölbl besentv@gmail.com
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- dlls/windows.media.speech/async.c | 103 ++++++++++++++++++++--- dlls/windows.media.speech/tests/speech.c | 16 ++-- 2 files changed, 99 insertions(+), 20 deletions(-)
diff --git a/dlls/windows.media.speech/async.c b/dlls/windows.media.speech/async.c index d7ac090be78..3d67b90060e 100644 --- a/dlls/windows.media.speech/async.c +++ b/dlls/windows.media.speech/async.c @@ -37,6 +37,11 @@ struct async_void IAsyncAction IAsyncAction_iface; IAsyncInfo IAsyncInfo_iface; LONG ref; + + IAsyncActionCompletedHandler *handler; + + AsyncStatus status; + HRESULT hr; };
static inline struct async_void *impl_from_IAsyncAction( IAsyncAction *iface ) @@ -106,20 +111,56 @@ HRESULT WINAPI async_void_GetTrustLevel( IAsyncAction *iface, TrustLevel *trust_
HRESULT WINAPI async_void_put_Completed( IAsyncAction *iface, IAsyncActionCompletedHandler *handler ) { - FIXME("iface %p, handler %p stub!\n", iface, handler); - return E_NOTIMPL; + struct async_void *impl = impl_from_IAsyncAction(iface); + HRESULT hr = S_OK; + + TRACE("iface %p, handler %p.\n", iface, handler); + + 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_operation_put_Completed, + so by default we set a non HANDLER_NOT_SET value, in this case handler. + */ + else if ((impl->handler = handler)) + { + IAsyncActionCompletedHandler_AddRef(impl->handler); + + if (impl->status > Started) + { + IAsyncAction *action = &impl->IAsyncAction_iface; + AsyncStatus status = impl->status; + impl->handler = NULL; /* Prevent concurrent invoke. */ + + IAsyncActionCompletedHandler_Invoke(handler, action, status); + IAsyncActionCompletedHandler_Release(handler); + } + } + + return hr; }
HRESULT WINAPI async_void_get_Completed( IAsyncAction *iface, IAsyncActionCompletedHandler **handler ) { - FIXME("iface %p, handler %p stub!\n", iface, handler); - return E_NOTIMPL; + struct async_void *impl = impl_from_IAsyncAction(iface); + HRESULT hr = S_OK; + + FIXME("iface %p, handler %p semi stub!\n", iface, handler); + + if (impl->status == Closed) + hr = E_ILLEGAL_METHOD_CALL; + *handler = (impl->handler != HANDLER_NOT_SET) ? impl->handler : NULL; + + return hr; }
HRESULT WINAPI async_void_GetResults( IAsyncAction *iface ) { - FIXME("iface %p stub!\n", iface); - return E_NOTIMPL; + /* According to the docs, this function doesn't return anything, so it's left empty. */ + TRACE("iface %p.\n", iface); + return S_OK; }
static const struct IAsyncActionVtbl async_void_vtbl = @@ -154,26 +195,61 @@ static HRESULT WINAPI async_void_info_get_Id( IAsyncInfo *iface, UINT32 *id )
static HRESULT WINAPI async_void_info_get_Status( IAsyncInfo *iface, AsyncStatus *status ) { - FIXME("iface %p, status %p.\n", iface, status); - return E_NOTIMPL; + struct async_void *impl = impl_from_async_void_IAsyncInfo(iface); + HRESULT hr = S_OK; + + TRACE("iface %p, status %p.\n", iface, status); + + if (impl->status == Closed) + hr = E_ILLEGAL_METHOD_CALL; + *status = impl->status; + + return hr; }
static HRESULT WINAPI async_void_info_get_ErrorCode( IAsyncInfo *iface, HRESULT *error_code ) { - FIXME("iface %p, error_code %p.\n", iface, error_code); - return E_NOTIMPL; + struct async_void *impl = impl_from_async_void_IAsyncInfo(iface); + HRESULT hr = S_OK; + + TRACE("iface %p, error_code %p.\n", iface, error_code); + + if (impl->status == Closed) + *error_code = hr = E_ILLEGAL_METHOD_CALL; + else + *error_code = impl->hr; + + return hr; }
static HRESULT WINAPI async_void_info_Cancel( IAsyncInfo *iface ) { + struct async_void *impl = impl_from_async_void_IAsyncInfo(iface); + HRESULT hr = S_OK; + TRACE("iface %p.\n", iface); - return E_NOTIMPL; + + if (impl->status == Closed) + hr = E_ILLEGAL_METHOD_CALL; + else if (impl->status == Started) + impl->status = Canceled; + + return hr; }
static HRESULT WINAPI async_void_info_Close( IAsyncInfo *iface ) { + struct async_void *impl = impl_from_async_void_IAsyncInfo(iface); + HRESULT hr = S_OK; + TRACE("iface %p.\n", iface); - return E_NOTIMPL; + + if (impl->status == Started) + hr = E_ILLEGAL_STATE_CHANGE; + else if (impl->status != Closed) + impl->status = Closed; + + return hr; }
static const struct IAsyncInfoVtbl async_void_info_vtbl = @@ -210,6 +286,9 @@ HRESULT async_action_create( IAsyncAction **out ) impl->IAsyncInfo_iface.lpVtbl = &async_void_info_vtbl; impl->ref = 1;
+ impl->handler = HANDLER_NOT_SET; + impl->status = Completed; + *out = &impl->IAsyncAction_iface; TRACE("created %p\n", *out); return S_OK; diff --git a/dlls/windows.media.speech/tests/speech.c b/dlls/windows.media.speech/tests/speech.c index f3b28c40f51..5e74b90bf9a 100644 --- a/dlls/windows.media.speech/tests/speech.c +++ b/dlls/windows.media.speech/tests/speech.c @@ -1581,27 +1581,25 @@ static void test_Recognition(void)
handler = (void *)0xdeadbeef; hr = IAsyncAction_get_Completed(action, &handler); - todo_wine ok(hr == S_OK, "IAsyncAction_put_Completed failed, hr %#lx.\n", hr); - todo_wine ok(handler == NULL, "Handler was %p.\n", handler); - - if (FAILED(hr)) goto skip_action; + ok(hr == S_OK, "IAsyncAction_put_Completed failed, hr %#lx.\n", hr); + ok(handler == NULL, "Handler was %p.\n", handler);
await_async_void(action, &action_handler);
hr = IAsyncAction_QueryInterface(action, &IID_IAsyncInfo, (void **)&info); - todo_wine ok(hr == S_OK, "IAsyncAction_QueryInterface failed, hr %#lx.\n", hr); + ok(hr == S_OK, "IAsyncAction_QueryInterface failed, hr %#lx.\n", hr); check_async_info((IInspectable *)action, 1, Completed, S_OK);
hr = IAsyncInfo_Cancel(info); - todo_wine ok(hr == S_OK, "IAsyncInfo_Cancel failed, hr %#lx.\n", hr); + ok(hr == S_OK, "IAsyncInfo_Cancel failed, hr %#lx.\n", hr); check_async_info((IInspectable *)action, 1, Completed, S_OK);
hr = IAsyncInfo_Close(info); - todo_wine ok(hr == S_OK, "IAsyncInfo_Close failed, hr %#lx.\n", hr); + ok(hr == S_OK, "IAsyncInfo_Close failed, hr %#lx.\n", hr); check_async_info((IInspectable *)action, 1, AsyncStatus_Closed, S_OK);
hr = IAsyncInfo_Close(info); - todo_wine ok(hr == S_OK, "IAsyncInfo_Close failed, hr %#lx.\n", hr); + ok(hr == S_OK, "IAsyncInfo_Close failed, hr %#lx.\n", hr); check_async_info((IInspectable *)action, 1, AsyncStatus_Closed, S_OK);
hr = IAsyncInfo_Cancel(info); @@ -1617,6 +1615,8 @@ static void test_Recognition(void) hr = ISpeechContinuousRecognitionSession_StopAsync(session, &action2); todo_wine ok(hr == S_OK, "ISpeechContinuousRecognitionSession_StopAsync failed, hr %#lx.\n", hr);
+ if (FAILED(hr)) goto skip_action; + async_void_handler_create_static(&action_handler); action_handler.event_block = CreateEventW(NULL, FALSE, FALSE, NULL); action_handler.event_finished = CreateEventW(NULL, FALSE, FALSE, NULL);
From: Bernhard Kölbl besentv@gmail.com
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- dlls/windows.media.speech/async.c | 75 ++++++++++++++++++++++++-- dlls/windows.media.speech/private.h | 3 +- dlls/windows.media.speech/recognizer.c | 7 ++- 3 files changed, 80 insertions(+), 5 deletions(-)
diff --git a/dlls/windows.media.speech/async.c b/dlls/windows.media.speech/async.c index 3d67b90060e..5d20fe482f1 100644 --- a/dlls/windows.media.speech/async.c +++ b/dlls/windows.media.speech/async.c @@ -40,6 +40,11 @@ struct async_void
IAsyncActionCompletedHandler *handler;
+ async_action_callback callback; + TP_WORK *async_run_work; + IInspectable *invoker; + + CRITICAL_SECTION cs; AsyncStatus status; HRESULT hr; }; @@ -116,6 +121,7 @@ HRESULT WINAPI async_void_put_Completed( IAsyncAction *iface, IAsyncActionComple
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) @@ -133,11 +139,15 @@ HRESULT WINAPI async_void_put_Completed( IAsyncAction *iface, IAsyncActionComple IAsyncAction *action = &impl->IAsyncAction_iface; AsyncStatus status = impl->status; impl->handler = NULL; /* Prevent concurrent invoke. */ + LeaveCriticalSection(&impl->cs);
IAsyncActionCompletedHandler_Invoke(handler, action, status); IAsyncActionCompletedHandler_Release(handler); + + return S_OK; } } + LeaveCriticalSection(&impl->cs);
return hr; } @@ -149,9 +159,11 @@ HRESULT WINAPI async_void_get_Completed( IAsyncAction *iface, IAsyncActionComple
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; } @@ -200,9 +212,11 @@ static HRESULT WINAPI async_void_info_get_Status( IAsyncInfo *iface, AsyncStatus
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; } @@ -214,10 +228,12 @@ static HRESULT WINAPI async_void_info_get_ErrorCode( IAsyncInfo *iface, HRESULT
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; } @@ -229,10 +245,12 @@ static HRESULT WINAPI async_void_info_Cancel( IAsyncInfo *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);
return hr; } @@ -244,10 +262,16 @@ static HRESULT WINAPI async_void_info_Close( IAsyncInfo *iface )
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; } @@ -270,11 +294,40 @@ static const struct IAsyncInfoVtbl async_void_info_vtbl = async_void_info_Close };
-HRESULT async_action_create( IAsyncAction **out ) +static void CALLBACK async_void_run_cb(TP_CALLBACK_INSTANCE *instance, void *data, TP_WORK *work) +{ + IAsyncAction *action = data; + struct async_void *impl = impl_from_IAsyncAction(action); + HRESULT hr; + + hr = impl->callback(impl->invoker); + + EnterCriticalSection(&impl->cs); + if (impl->status < Closed) + impl->status = FAILED(hr) ? Error : Completed; + + impl->hr = hr; + + if (impl->handler != NULL && impl->handler != HANDLER_NOT_SET) + { + IAsyncActionCompletedHandler*handler = impl->handler; + AsyncStatus status = impl->status; + impl->handler = NULL; /* Prevent concurrent invoke. */ + LeaveCriticalSection(&impl->cs); + + IAsyncActionCompletedHandler_Invoke(handler, action, status); + IAsyncActionCompletedHandler_Release(handler); + } + else LeaveCriticalSection(&impl->cs); + + IAsyncAction_Release(action); +} + +HRESULT async_action_create( IInspectable *invoker, async_action_callback callback, IAsyncAction **out ) { struct async_void *impl;
- TRACE("out %p.\n", out); + TRACE("invoker %p, callback %p, out %p.\n", invoker, callback, out);
if (!(impl = calloc(1, sizeof(*impl)))) { @@ -287,7 +340,23 @@ HRESULT async_action_create( IAsyncAction **out ) impl->ref = 1;
impl->handler = HANDLER_NOT_SET; - impl->status = Completed; + impl->callback = callback; + impl->status = Started; + + if (!(impl->async_run_work = CreateThreadpoolWork(async_void_run_cb, &impl->IAsyncAction_iface, NULL))) + { + free(impl); + return HRESULT_FROM_WIN32(GetLastError()); + } + + if (invoker) IInspectable_AddRef((impl->invoker = invoker)); + + InitializeCriticalSection(&impl->cs); + impl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": async_action.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); diff --git a/dlls/windows.media.speech/private.h b/dlls/windows.media.speech/private.h index ba8e942fe5f..13964329697 100644 --- a/dlls/windows.media.speech/private.h +++ b/dlls/windows.media.speech/private.h @@ -69,9 +69,10 @@ struct vector_iids const GUID *view; };
+typedef HRESULT (WINAPI *async_action_callback)( IInspectable *invoker ); typedef HRESULT (WINAPI *async_operation_inspectable_callback)( IInspectable *invoker, IInspectable **result );
-HRESULT async_action_create( IAsyncAction **out ); +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, IAsyncOperation_IInspectable **out );
diff --git a/dlls/windows.media.speech/recognizer.c b/dlls/windows.media.speech/recognizer.c index 853e9eb9830..6a058df86e5 100644 --- a/dlls/windows.media.speech/recognizer.c +++ b/dlls/windows.media.speech/recognizer.c @@ -244,10 +244,15 @@ static HRESULT WINAPI session_set_AutoStopSilenceTimeout( ISpeechContinuousRecog return E_NOTIMPL; }
+static HRESULT WINAPI start_callback( IInspectable *invoker ) +{ + return S_OK; +} + static HRESULT WINAPI session_StartAsync( ISpeechContinuousRecognitionSession *iface, IAsyncAction **action ) { FIXME("iface %p, action %p stub!\n", iface, action); - return async_action_create(action); + return async_action_create(NULL, start_callback, action); }
static HRESULT WINAPI session_StartWithModeAsync( ISpeechContinuousRecognitionSession *iface,
Rémi Bernon (@rbernon) commented about dlls/windows.media.speech/async.c:
- return hr;
}
HRESULT WINAPI async_void_get_Completed( IAsyncAction *iface, IAsyncActionCompletedHandler **handler ) {
- FIXME("iface %p, handler %p stub!\n", iface, handler);
- return E_NOTIMPL;
- struct async_void *impl = impl_from_IAsyncAction(iface);
- HRESULT hr = S_OK;
- FIXME("iface %p, handler %p semi stub!\n", iface, handler);
- if (impl->status == Closed)
hr = E_ILLEGAL_METHOD_CALL;
- *handler = (impl->handler != HANDLER_NOT_SET) ? impl->handler : NULL;
This will need to be fixed in the `async_inspectable` too but you need to `AddRef` on the returned handler if it's not `NULL`.
This merge request was approved by Rémi Bernon.
On Tue May 24 14:25:42 2022 +0000, Rémi Bernon wrote:
This will need to be fixed in the `async_inspectable` too but you need to `AddRef` on the returned handler if it's not `NULL`.
(Approving nonetheless I don't think it's critical as the other flavor has the same issue)