And use it in recognizer.
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- dlls/windows.media.speech/private.h | 6 + dlls/windows.media.speech/recognizer.c | 21 +- dlls/windows.media.speech/vector.c | 279 +++++++++++++++++++++++++ 3 files changed, 305 insertions(+), 1 deletion(-)
diff --git a/dlls/windows.media.speech/private.h b/dlls/windows.media.speech/private.h index 3c8371ccdbe..348c060c1c6 100644 --- a/dlls/windows.media.speech/private.h +++ b/dlls/windows.media.speech/private.h @@ -61,6 +61,11 @@ extern IActivationFactory *synthesizer_factory;
+struct vector_iids +{ + const GUID *vector; +}; + HRESULT typed_event_handlers_append( struct list *list, ITypedEventHandler_IInspectable_IInspectable *handler, EventRegistrationToken *token ); HRESULT typed_event_handlers_remove( struct list *list, EventRegistrationToken *token ); HRESULT typed_event_handlers_notify( struct list *list, IInspectable *sender, IInspectable *args ); @@ -68,6 +73,7 @@ HRESULT typed_event_handlers_clear( struct list* list );
HRESULT vector_hstring_create( IVector_HSTRING **out ); HRESULT vector_hstring_create_copy( IIterable_HSTRING *iterable, IVector_HSTRING **out ); +HRESULT vector_inspectable_create( const struct vector_iids *iids, IVector_IInspectable **out );
#define DEFINE_IINSPECTABLE_( pfx, iface_type, impl_type, impl_from, iface_mem, expr ) \ static inline impl_type *impl_from( iface_type *iface ) \ diff --git a/dlls/windows.media.speech/recognizer.c b/dlls/windows.media.speech/recognizer.c index da219d6bd0a..5f88331c703 100644 --- a/dlls/windows.media.speech/recognizer.c +++ b/dlls/windows.media.speech/recognizer.c @@ -233,6 +233,7 @@ struct recognizer LONG ref;
ISpeechContinuousRecognitionSession *session; + IVector_ISpeechRecognitionConstraint *constraints; };
/* @@ -296,6 +297,7 @@ static ULONG WINAPI recognizer_Release( ISpeechRecognizer *iface ) if (!ref) { ISpeechContinuousRecognitionSession_Release(impl->session); + IVector_ISpeechRecognitionConstraint_Release(impl->constraints); free(impl); }
@@ -637,13 +639,22 @@ static HRESULT WINAPI recognizer_factory_Create( ISpeechRecognizerFactory *iface { struct recognizer *impl; struct session *session; + struct vector_iids constraints_iids = + { + .vector = &IID_IVector_ISpeechRecognitionConstraint, + }; + HRESULT hr;
TRACE("iface %p, language %p, speechrecognizer %p.\n", iface, language, speechrecognizer);
*speechrecognizer = NULL;
if (!(impl = calloc(1, sizeof(*impl)))) return E_OUTOFMEMORY; - if (!(session = calloc(1, sizeof(*session)))) return E_OUTOFMEMORY; + if (!(session = calloc(1, sizeof(*session)))) + { + hr = E_OUTOFMEMORY; + goto error; + }
if (language) FIXME("language parameter unused. Stub!\n"); @@ -658,11 +669,19 @@ static HRESULT WINAPI recognizer_factory_Create( ISpeechRecognizerFactory *iface impl->ISpeechRecognizer2_iface.lpVtbl = &speech_recognizer2_vtbl; impl->session = &session->ISpeechContinuousRecognitionSession_iface; impl->ref = 1; + if (FAILED(hr = vector_inspectable_create(&constraints_iids, (IVector_IInspectable**)&impl->constraints))) + goto error;
TRACE("created SpeechRecognizer %p.\n", impl);
*speechrecognizer = &impl->ISpeechRecognizer_iface; return S_OK; + +error: + if (session) free(session); + if (impl) free(impl); + + return hr; }
static const struct ISpeechRecognizerFactoryVtbl speech_recognizer_factory_vtbl = diff --git a/dlls/windows.media.speech/vector.c b/dlls/windows.media.speech/vector.c index fcb7f483e03..e3a802fc020 100644 --- a/dlls/windows.media.speech/vector.c +++ b/dlls/windows.media.speech/vector.c @@ -771,3 +771,282 @@ error: IVector_HSTRING_Release(*out); return hr; } + +/* + * + * IVector<Inspectable*> + * + */ + +struct vector_inspectable +{ + IVector_IInspectable IVector_IInspectable_iface; + struct vector_iids iids; + LONG ref; + + UINT32 size; + UINT32 capacity; + IInspectable **elements; +}; + +static inline struct vector_inspectable *impl_from_IVector_IInspectable( IVector_IInspectable *iface ) +{ + return CONTAINING_RECORD(iface, struct vector_inspectable, IVector_IInspectable_iface); +} + +static HRESULT WINAPI vector_inspectable_QueryInterface( IVector_IInspectable *iface, REFIID iid, void **out ) +{ + struct vector_inspectable *impl = impl_from_IVector_IInspectable(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, impl->iids.vector)) + { + IInspectable_AddRef((*out = &impl->IVector_IInspectable_iface)); + return S_OK; + } + + WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid)); + *out = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI vector_inspectable_AddRef( IVector_IInspectable *iface ) +{ + struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface); + ULONG ref = InterlockedIncrement(&impl->ref); + TRACE("iface %p increasing refcount to %lu.\n", iface, ref); + return ref; +} + +static ULONG WINAPI vector_inspectable_Release( IVector_IInspectable *iface ) +{ + struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface); + ULONG ref = InterlockedDecrement(&impl->ref); + + TRACE("iface %p decreasing refcount to %lu.\n", iface, ref); + + if (!ref) + { + IVector_IInspectable_Clear(iface); + free(impl); + } + + return ref; +} + +static HRESULT WINAPI vector_inspectable_GetIids( IVector_IInspectable *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 vector_inspectable_GetRuntimeClassName( IVector_IInspectable *iface, HSTRING *class_name ) +{ + FIXME("iface %p, class_name %p stub!\n", iface, class_name); + return E_NOTIMPL; +} + +static HRESULT WINAPI vector_inspectable_GetTrustLevel( IVector_IInspectable *iface, TrustLevel *trust_level ) +{ + FIXME("iface %p, trust_level %p stub!\n", iface, trust_level); + return E_NOTIMPL; +} + +static HRESULT WINAPI vector_inspectable_GetAt( IVector_IInspectable *iface, UINT32 index, IInspectable **value ) +{ + struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface); + + TRACE("iface %p, index %u, value %p.\n", iface, index, value); + + *value = NULL; + if (index >= impl->size) return E_BOUNDS; + + IInspectable_AddRef((*value = impl->elements[index])); + return S_OK; +} + +static HRESULT WINAPI vector_inspectable_get_Size( IVector_IInspectable *iface, UINT32 *value ) +{ + struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface); + TRACE("iface %p, value %p.\n", iface, value); + *value = impl->size; + return S_OK; +} + +static HRESULT WINAPI vector_inspectable_GetView( IVector_IInspectable *iface, IVectorView_IInspectable **value ) +{ + FIXME("iface %p, value %p stub!\n", iface, value); + return E_NOTIMPL; +} + +static HRESULT WINAPI vector_inspectable_IndexOf( IVector_IInspectable *iface, + IInspectable *element, UINT32 *index, BOOLEAN *found ) +{ + struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface); + ULONG i; + + TRACE("iface %p, element %p, index %p, found %p.\n", iface, element, index, found); + + for (i = 0; i < impl->size; ++i) if (impl->elements[i] == element) break; + if ((*found = (i < impl->size))) *index = i; + else *index = 0; + + return S_OK; +} + +static HRESULT WINAPI vector_inspectable_SetAt( IVector_IInspectable *iface, UINT32 index, IInspectable *value ) +{ + struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface); + + TRACE("iface %p, index %u, value %p.\n", iface, index, value); + + if (index >= impl->size) return E_BOUNDS; + IInspectable_Release(impl->elements[index]); + IInspectable_AddRef((impl->elements[index] = value)); + return S_OK; +} + +static HRESULT WINAPI vector_inspectable_InsertAt( IVector_IInspectable *iface, UINT32 index, IInspectable *value ) +{ + struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface); + IInspectable **tmp = impl->elements; + + TRACE("iface %p, index %u, value %p.\n", iface, index, value); + + if (impl->size == impl->capacity) + { + impl->capacity = max(32, impl->capacity * 3 / 2); + if (!(impl->elements = realloc(impl->elements, impl->capacity * sizeof(*impl->elements)))) + { + impl->elements = tmp; + return E_OUTOFMEMORY; + } + } + + memmove(impl->elements + index + 1, impl->elements + index, (impl->size++ - index) * sizeof(*impl->elements)); + IInspectable_AddRef((impl->elements[index] = value)); + return S_OK; +} + +static HRESULT WINAPI vector_inspectable_RemoveAt( IVector_IInspectable *iface, UINT32 index ) +{ + struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface); + + TRACE("iface %p, index %u.\n", iface, index); + + if (index >= impl->size) return E_BOUNDS; + IInspectable_Release(impl->elements[index]); + memmove(impl->elements + index, impl->elements + index + 1, (--impl->size - index) * sizeof(*impl->elements)); + return S_OK; +} + +static HRESULT WINAPI vector_inspectable_Append( IVector_IInspectable *iface, IInspectable *value ) +{ + struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface); + + TRACE("iface %p, value %p.\n", iface, value); + + return IVector_IInspectable_InsertAt(iface, impl->size, value); +} + +static HRESULT WINAPI vector_inspectable_RemoveAtEnd( IVector_IInspectable *iface ) +{ + struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface); + + TRACE("iface %p.\n", iface); + + if (impl->size) IInspectable_Release(impl->elements[--impl->size]); + return S_OK; +} + +static HRESULT WINAPI vector_inspectable_Clear( IVector_IInspectable *iface ) +{ + struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface); + + TRACE("iface %p.\n", iface); + + while (impl->size) IVector_IInspectable_RemoveAtEnd(iface); + free(impl->elements); + impl->capacity = 0; + impl->elements = NULL; + + return S_OK; +} + +static HRESULT WINAPI vector_inspectable_GetMany( IVector_IInspectable *iface, UINT32 start_index, + UINT32 items_size, IInspectable **items, UINT *count ) +{ + struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface); + UINT32 i; + + TRACE("iface %p, start_index %u, items_size %u, items %p, count %p.\n", + iface, start_index, items_size, items, count); + + if (start_index >= impl->size) return E_BOUNDS; + + for (i = start_index; i < impl->size; ++i) + { + if (i - start_index >= items_size) break; + IInspectable_AddRef((items[i - start_index] = impl->elements[i])); + } + *count = i - start_index; + + return S_OK; +} + +static HRESULT WINAPI vector_inspectable_ReplaceAll( IVector_IInspectable *iface, UINT32 count, IInspectable **items ) +{ + HRESULT hr; + ULONG i; + + TRACE("iface %p, count %u, items %p.\n", iface, count, items); + + hr = IVector_IInspectable_Clear(iface); + for (i = 0; i < count && SUCCEEDED(hr); ++i) hr = IVector_IInspectable_Append(iface, items[i]); + return hr; +} + +static const struct IVector_IInspectableVtbl vector_inspectable_vtbl = +{ + /* IUnknown methods */ + vector_inspectable_QueryInterface, + vector_inspectable_AddRef, + vector_inspectable_Release, + /* IInspectable methods */ + vector_inspectable_GetIids, + vector_inspectable_GetRuntimeClassName, + vector_inspectable_GetTrustLevel, + /* IVector<IInspectable*> methods */ + vector_inspectable_GetAt, + vector_inspectable_get_Size, + vector_inspectable_GetView, + vector_inspectable_IndexOf, + vector_inspectable_SetAt, + vector_inspectable_InsertAt, + vector_inspectable_RemoveAt, + vector_inspectable_Append, + vector_inspectable_RemoveAtEnd, + vector_inspectable_Clear, + vector_inspectable_GetMany, + vector_inspectable_ReplaceAll +}; + +HRESULT vector_inspectable_create( const struct vector_iids *iids, IVector_IInspectable **out ) +{ + struct vector_inspectable *impl; + + TRACE("iid %s, out %p.\n", debugstr_guid(iids->vector), out); + + if (!(impl = calloc(1, sizeof(*impl)))) return E_OUTOFMEMORY; + impl->IVector_IInspectable_iface.lpVtbl = &vector_inspectable_vtbl; + impl->iids = *iids; + impl->ref = 1; + + *out = &impl->IVector_IInspectable_iface; + TRACE("created %p\n", *out); + return S_OK; +}