Commit caf138f5 authored by Bernhard Kölbl's avatar Bernhard Kölbl Committed by Alexandre Julliard

windows.media.speech: Partially implement IAsyncOperation.

parent 9d67ca49
......@@ -23,6 +23,9 @@
WINE_DEFAULT_DEBUG_CHANNEL(speech);
#define Closed 4
#define HANDLER_NOT_SET ((void *)~(ULONG_PTR)0)
/*
*
* IAsyncOperation<IInspectable*>
......@@ -35,6 +38,11 @@ struct async_operation
IAsyncInfo IAsyncInfo_iface;
const GUID *iid;
LONG ref;
IAsyncOperationCompletedHandler_IInspectable *handler;
AsyncStatus status;
HRESULT hr;
};
static inline struct async_operation *impl_from_IAsyncOperation_IInspectable(IAsyncOperation_IInspectable *iface)
......@@ -84,7 +92,14 @@ static ULONG WINAPI async_operation_Release( IAsyncOperation_IInspectable *iface
TRACE("iface %p, ref %lu.\n", iface, ref);
if (!ref)
{
IAsyncInfo_Close(&impl->IAsyncInfo_iface);
if (impl->handler && impl->handler != HANDLER_NOT_SET)
IAsyncOperationCompletedHandler_IInspectable_Release(impl->handler);
free(impl);
}
return ref;
}
......@@ -110,21 +125,72 @@ static HRESULT WINAPI async_operation_GetTrustLevel( IAsyncOperation_IInspectabl
static HRESULT WINAPI async_operation_put_Completed( IAsyncOperation_IInspectable *iface,
IAsyncOperationCompletedHandler_IInspectable *handler )
{
FIXME("iface %p, handler %p stub!\n", iface, handler);
return E_NOTIMPL;
struct async_operation *impl = impl_from_IAsyncOperation_IInspectable(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))
{
IAsyncOperationCompletedHandler_IInspectable_AddRef(impl->handler);
if (impl->status > Started)
{
IAsyncOperation_IInspectable *operation = &impl->IAsyncOperation_IInspectable_iface;
AsyncStatus status = impl->status;
impl->handler = NULL; /* Prevent concurrent invoke. */
IAsyncOperationCompletedHandler_IInspectable_Invoke(handler, operation, status);
IAsyncOperationCompletedHandler_IInspectable_Release(handler);
return S_OK;
}
}
return hr;
}
static HRESULT WINAPI async_operation_get_Completed( IAsyncOperation_IInspectable *iface,
IAsyncOperationCompletedHandler_IInspectable **handler )
{
FIXME("iface %p, handler %p stub!\n", iface, handler);
return E_NOTIMPL;
struct async_operation *impl = impl_from_IAsyncOperation_IInspectable(iface);
HRESULT hr;
FIXME("iface %p, handler %p semi stub!\n", iface, handler);
if (impl->status == Closed)
hr = E_ILLEGAL_METHOD_CALL;
else
hr = S_OK;
*handler = (impl->handler != HANDLER_NOT_SET) ? impl->handler : NULL;
return hr;
}
static HRESULT WINAPI async_operation_GetResults( IAsyncOperation_IInspectable *iface, IInspectable **results )
{
FIXME("iface %p, results %p stub!\n", iface, results);
return E_NOTIMPL;
/* NOTE: Despite the name, this function only returns one result! */
struct async_operation *impl = impl_from_IAsyncOperation_IInspectable(iface);
HRESULT hr;
TRACE("iface %p, results %p.\n", iface, results);
if (impl->status == Closed)
hr = E_ILLEGAL_METHOD_CALL;
else if (impl->status > Started)
hr = S_OK;
else
hr = E_UNEXPECTED;
return hr;
}
static const struct IAsyncOperation_IInspectableVtbl async_operation_vtbl =
......@@ -159,26 +225,56 @@ static HRESULT WINAPI async_operation_info_get_Id( IAsyncInfo *iface, UINT32 *id
static HRESULT WINAPI async_operation_info_get_Status( IAsyncInfo *iface, AsyncStatus *status )
{
FIXME("iface %p, status %p stub!\n", iface, status);
return E_NOTIMPL;
struct async_operation *impl = impl_from_IAsyncInfo(iface);
HRESULT hr;
TRACE("iface %p, status %p.\n", iface, status);
if (impl->status == Closed)
hr = E_ILLEGAL_METHOD_CALL;
else
hr = S_OK;
*status = impl->status;
return hr;
}
static HRESULT WINAPI async_operation_info_get_ErrorCode( IAsyncInfo *iface, HRESULT *error_code )
{
FIXME("iface %p, error_code %p stub!\n", iface, error_code);
return E_NOTIMPL;
struct async_operation *impl = impl_from_IAsyncInfo(iface);
TRACE("iface %p, error_code %p.\n", iface, error_code);
*error_code = impl->hr;
return S_OK;
}
static HRESULT WINAPI async_operation_info_Cancel( IAsyncInfo *iface )
{
FIXME("iface %p stub!\n", iface);
return E_NOTIMPL;
struct async_operation *impl = impl_from_IAsyncInfo(iface);
HRESULT hr;
TRACE("iface %p.\n", iface);
hr = S_OK;
if (impl->status == Closed)
hr = E_ILLEGAL_METHOD_CALL;
else if (impl->status == Started)
impl->status = Canceled;
return hr;
}
static HRESULT WINAPI async_operation_info_Close( IAsyncInfo *iface )
{
FIXME("iface %p stub!\n", iface);
return E_NOTIMPL;
struct async_operation *impl = impl_from_IAsyncInfo(iface);
TRACE("iface %p.\n", iface);
if (impl->status == Started)
return E_ILLEGAL_STATE_CHANGE;
impl->status = Closed;
return S_OK;
}
static const struct IAsyncInfoVtbl async_operation_info_vtbl =
......@@ -202,11 +298,14 @@ static const struct IAsyncInfoVtbl async_operation_info_vtbl =
HRESULT async_operation_create( const GUID *iid, IAsyncOperation_IInspectable **out )
{
struct async_operation *impl;
HRESULT hr;
*out = NULL;
if (!(impl = calloc(1, sizeof(*impl))))
{
*out = NULL;
return E_OUTOFMEMORY;
hr = E_OUTOFMEMORY;
goto error;
}
impl->IAsyncOperation_IInspectable_iface.lpVtbl = &async_operation_vtbl;
......@@ -214,7 +313,14 @@ HRESULT async_operation_create( const GUID *iid, IAsyncOperation_IInspectable **
impl->iid = iid;
impl->ref = 1;
impl->handler = HANDLER_NOT_SET;
impl->status = Completed;
*out = &impl->IAsyncOperation_IInspectable_iface;
TRACE("created %p\n", *out);
return S_OK;
error:
free(impl);
return hr;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment