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; +}
And make it obtainable from IVector<Inspectable*>_GetView.
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- dlls/windows.media.speech/private.h | 1 + dlls/windows.media.speech/recognizer.c | 1 + dlls/windows.media.speech/vector.c | 176 ++++++++++++++++++++++++- 3 files changed, 176 insertions(+), 2 deletions(-)
diff --git a/dlls/windows.media.speech/private.h b/dlls/windows.media.speech/private.h index 348c060c1c6..f7ca87ab393 100644 --- a/dlls/windows.media.speech/private.h +++ b/dlls/windows.media.speech/private.h @@ -64,6 +64,7 @@ extern IActivationFactory *synthesizer_factory; struct vector_iids { const GUID *vector; + const GUID *view; };
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 5f88331c703..cbfe4b71c13 100644 --- a/dlls/windows.media.speech/recognizer.c +++ b/dlls/windows.media.speech/recognizer.c @@ -642,6 +642,7 @@ static HRESULT WINAPI recognizer_factory_Create( ISpeechRecognizerFactory *iface struct vector_iids constraints_iids = { .vector = &IID_IVector_ISpeechRecognitionConstraint, + .view = &IID_IVectorView_ISpeechRecognitionConstraint, }; HRESULT hr;
diff --git a/dlls/windows.media.speech/vector.c b/dlls/windows.media.speech/vector.c index e3a802fc020..90627fa1c37 100644 --- a/dlls/windows.media.speech/vector.c +++ b/dlls/windows.media.speech/vector.c @@ -772,6 +772,165 @@ error: return hr; }
+/* + * + * IVectorView<Inspectable*> + * + */ + +struct vector_view_inspectable +{ + IVectorView_IInspectable IVectorView_IInspectable_iface; + struct vector_iids iids; + LONG ref; + + UINT32 size; + IInspectable *elements[]; +}; + +static inline struct vector_view_inspectable *impl_from_IVectorView_IInspectable( IVectorView_IInspectable *iface ) +{ + return CONTAINING_RECORD(iface, struct vector_view_inspectable, IVectorView_IInspectable_iface); +} + +static HRESULT WINAPI vector_view_inspectable_QueryInterface( IVectorView_IInspectable *iface, REFIID iid, void **out ) +{ + struct vector_view_inspectable *impl = impl_from_IVectorView_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.view)) + { + IInspectable_AddRef((*out = &impl->IVectorView_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_view_inspectable_AddRef( IVectorView_IInspectable *iface ) +{ + struct vector_view_inspectable *impl = impl_from_IVectorView_IInspectable(iface); + ULONG ref = InterlockedIncrement(&impl->ref); + TRACE("iface %p increasing refcount to %lu.\n", iface, ref); + return ref; +} + +static ULONG WINAPI vector_view_inspectable_Release( IVectorView_IInspectable *iface ) +{ + struct vector_view_inspectable *impl = impl_from_IVectorView_IInspectable(iface); + ULONG i, ref = InterlockedDecrement(&impl->ref); + + TRACE("iface %p decreasing refcount to %lu.\n", iface, ref); + + if (!ref) + { + for (i = 0; i < impl->size; ++i) IInspectable_Release(impl->elements[i]); + free(impl); + } + + return ref; +} + +static HRESULT WINAPI vector_view_inspectable_GetIids( IVectorView_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_view_inspectable_GetRuntimeClassName( IVectorView_IInspectable *iface, HSTRING *class_name ) +{ + FIXME("iface %p, class_name %p stub!\n", iface, class_name); + return E_NOTIMPL; +} + +static HRESULT WINAPI vector_view_inspectable_GetTrustLevel( IVectorView_IInspectable *iface, TrustLevel *trust_level ) +{ + FIXME("iface %p, trust_level %p stub!\n", iface, trust_level); + return E_NOTIMPL; +} + +static HRESULT WINAPI vector_view_inspectable_GetAt( IVectorView_IInspectable *iface, UINT32 index, IInspectable **value ) +{ + struct vector_view_inspectable *impl = impl_from_IVectorView_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_view_inspectable_get_Size( IVectorView_IInspectable *iface, UINT32 *value ) +{ + struct vector_view_inspectable *impl = impl_from_IVectorView_IInspectable(iface); + + TRACE("iface %p, value %p.\n", iface, value); + + *value = impl->size; + return S_OK; +} + +static HRESULT WINAPI vector_view_inspectable_IndexOf( IVectorView_IInspectable *iface, IInspectable *element, + UINT32 *index, BOOLEAN *found ) +{ + struct vector_view_inspectable *impl = impl_from_IVectorView_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_view_inspectable_GetMany( IVectorView_IInspectable *iface, UINT32 start_index, + UINT32 items_size, IInspectable **items, UINT *count ) +{ + struct vector_view_inspectable *impl = impl_from_IVectorView_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 const struct IVectorView_IInspectableVtbl vector_view_inspectable_vtbl = +{ + /* IUnknown methods */ + vector_view_inspectable_QueryInterface, + vector_view_inspectable_AddRef, + vector_view_inspectable_Release, + /* IInspectable methods */ + vector_view_inspectable_GetIids, + vector_view_inspectable_GetRuntimeClassName, + vector_view_inspectable_GetTrustLevel, + /* IVectorView<IInspectable*> methods */ + vector_view_inspectable_GetAt, + vector_view_inspectable_get_Size, + vector_view_inspectable_IndexOf, + vector_view_inspectable_GetMany +}; + /* * * IVector<Inspectable*> @@ -879,8 +1038,21 @@ static HRESULT WINAPI vector_inspectable_get_Size( IVector_IInspectable *iface,
static HRESULT WINAPI vector_inspectable_GetView( IVector_IInspectable *iface, IVectorView_IInspectable **value ) { - FIXME("iface %p, value %p stub!\n", iface, value); - return E_NOTIMPL; + struct vector_inspectable *impl = impl_from_IVector_IInspectable(iface); + struct vector_view_inspectable *view; + ULONG i; + + TRACE("iface %p, value %p.\n", iface, value); + + if (!(view = calloc(1, offsetof(struct vector_view_inspectable, elements[impl->size])))) return E_OUTOFMEMORY; + view->IVectorView_IInspectable_iface.lpVtbl = &vector_view_inspectable_vtbl; + view->iids = impl->iids; + view->ref = 1; + + for (i = 0; i < impl->size; ++i) IInspectable_AddRef((view->elements[view->size++] = impl->elements[i])); + + *value = &view->IVectorView_IInspectable_iface; + return S_OK; }
static HRESULT WINAPI vector_inspectable_IndexOf( IVector_IInspectable *iface,
On 3/30/22 15:15, Bernhard Kölbl wrote:
+/*
- IVectorView<Inspectable*>
- */
+struct vector_view_inspectable +{
- IVectorView_IInspectable IVectorView_IInspectable_iface;
- struct vector_iids iids;
- LONG ref;
- UINT32 size;
- IInspectable *elements[];
+};
There too, I missed it for the HSTRING view but I think if we're using flexible arrays now, to add a:
C_ASSERT(sizeof(struct vector_view_inspectable) == offsetof(struct vector_view_inspectable, elements[0]));
To make sure the array is not misaligned.
To both IVector<IInspectable*> and IVectorView<IInspectable*>.
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- dlls/windows.media.speech/private.h | 1 + dlls/windows.media.speech/recognizer.c | 1 + dlls/windows.media.speech/vector.c | 73 ++++++++++++++++++++++++++ 3 files changed, 75 insertions(+)
diff --git a/dlls/windows.media.speech/private.h b/dlls/windows.media.speech/private.h index f7ca87ab393..ba790c361aa 100644 --- a/dlls/windows.media.speech/private.h +++ b/dlls/windows.media.speech/private.h @@ -63,6 +63,7 @@ extern IActivationFactory *synthesizer_factory;
struct vector_iids { + const GUID *iterable; const GUID *vector; const GUID *view; }; diff --git a/dlls/windows.media.speech/recognizer.c b/dlls/windows.media.speech/recognizer.c index cbfe4b71c13..cca3e25d0d6 100644 --- a/dlls/windows.media.speech/recognizer.c +++ b/dlls/windows.media.speech/recognizer.c @@ -641,6 +641,7 @@ static HRESULT WINAPI recognizer_factory_Create( ISpeechRecognizerFactory *iface struct session *session; struct vector_iids constraints_iids = { + .iterable = &IID_IIterable_ISpeechRecognitionConstraint, .vector = &IID_IVector_ISpeechRecognitionConstraint, .view = &IID_IVectorView_ISpeechRecognitionConstraint, }; diff --git a/dlls/windows.media.speech/vector.c b/dlls/windows.media.speech/vector.c index 90627fa1c37..bad977fe429 100644 --- a/dlls/windows.media.speech/vector.c +++ b/dlls/windows.media.speech/vector.c @@ -781,6 +781,7 @@ error: struct vector_view_inspectable { IVectorView_IInspectable IVectorView_IInspectable_iface; + IIterable_IInspectable IIterable_IInspectable_iface; struct vector_iids iids; LONG ref;
@@ -808,6 +809,12 @@ static HRESULT WINAPI vector_view_inspectable_QueryInterface( IVectorView_IInspe return S_OK; }
+ if (IsEqualGUID(iid, impl->iids.iterable)) + { + IInspectable_AddRef((*out = &impl->IIterable_IInspectable_iface)); + return S_OK; + } + WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid)); *out = NULL; return E_NOINTERFACE; @@ -931,6 +938,35 @@ static const struct IVectorView_IInspectableVtbl vector_view_inspectable_vtbl = vector_view_inspectable_GetMany };
+/* + * + * IIterable<Inspectable*> + * + */ + +DEFINE_IINSPECTABLE_(iterable_view_inspectable, IIterable_IInspectable, struct vector_view_inspectable, + view_impl_from_IIterable_IInspectable, IIterable_IInspectable_iface, &impl->IVectorView_IInspectable_iface) + +static HRESULT WINAPI iterable_view_inspectable_First( IIterable_IInspectable *iface, IIterator_IInspectable **value ) +{ + FIXME("iface %p, value %p stub!\n", iface, value); + return E_NOTIMPL; +} + +static const struct IIterable_IInspectableVtbl iterable_view_inspectable_vtbl = +{ + /* IUnknown methods */ + iterable_view_inspectable_QueryInterface, + iterable_view_inspectable_AddRef, + iterable_view_inspectable_Release, + /* IInspectable methods */ + iterable_view_inspectable_GetIids, + iterable_view_inspectable_GetRuntimeClassName, + iterable_view_inspectable_GetTrustLevel, + /* IIterable<IInspectable*> methods */ + iterable_view_inspectable_First +}; + /* * * IVector<Inspectable*> @@ -940,6 +976,7 @@ static const struct IVectorView_IInspectableVtbl vector_view_inspectable_vtbl = struct vector_inspectable { IVector_IInspectable IVector_IInspectable_iface; + IIterable_IInspectable IIterable_IInspectable_iface; struct vector_iids iids; LONG ref;
@@ -968,6 +1005,12 @@ static HRESULT WINAPI vector_inspectable_QueryInterface( IVector_IInspectable *i return S_OK; }
+ if (IsEqualGUID(iid, impl->iids.iterable)) + { + IInspectable_AddRef((*out = &impl->IIterable_IInspectable_iface)); + return S_OK; + } + WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid)); *out = NULL; return E_NOINTERFACE; @@ -1046,6 +1089,7 @@ static HRESULT WINAPI vector_inspectable_GetView( IVector_IInspectable *iface, I
if (!(view = calloc(1, offsetof(struct vector_view_inspectable, elements[impl->size])))) return E_OUTOFMEMORY; view->IVectorView_IInspectable_iface.lpVtbl = &vector_view_inspectable_vtbl; + view->IIterable_IInspectable_iface.lpVtbl = &iterable_view_inspectable_vtbl; view->iids = impl->iids; view->ref = 1;
@@ -1207,6 +1251,34 @@ static const struct IVector_IInspectableVtbl vector_inspectable_vtbl = vector_inspectable_ReplaceAll };
+/* + * + * IIterable<Inspectable*> + * + */ + +DEFINE_IINSPECTABLE(iterable_inspectable, IIterable_IInspectable, struct vector_inspectable, IVector_IInspectable_iface) + +static HRESULT WINAPI iterable_inspectable_First( IIterable_IInspectable *iface, IIterator_IInspectable **value ) +{ + FIXME("iface %p, value %p stub!\n", iface, value); + return E_NOTIMPL; +} + +static const struct IIterable_IInspectableVtbl iterable_inspectable_vtbl = +{ + /* IUnknown methods */ + iterable_inspectable_QueryInterface, + iterable_inspectable_AddRef, + iterable_inspectable_Release, + /* IInspectable methods */ + iterable_inspectable_GetIids, + iterable_inspectable_GetRuntimeClassName, + iterable_inspectable_GetTrustLevel, + /* IIterable<IInspectable*> methods */ + iterable_inspectable_First +}; + HRESULT vector_inspectable_create( const struct vector_iids *iids, IVector_IInspectable **out ) { struct vector_inspectable *impl; @@ -1215,6 +1287,7 @@ HRESULT vector_inspectable_create( const struct vector_iids *iids, IVector_IInsp
if (!(impl = calloc(1, sizeof(*impl)))) return E_OUTOFMEMORY; impl->IVector_IInspectable_iface.lpVtbl = &vector_inspectable_vtbl; + impl->IIterable_IInspectable_iface.lpVtbl = &iterable_inspectable_vtbl; impl->iids = *iids; impl->ref = 1;
And implement the IIterable<Inspectable*>_First methods.
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- dlls/windows.media.speech/private.h | 1 + dlls/windows.media.speech/recognizer.c | 1 + dlls/windows.media.speech/vector.c | 171 ++++++++++++++++++++++++- 3 files changed, 169 insertions(+), 4 deletions(-)
diff --git a/dlls/windows.media.speech/private.h b/dlls/windows.media.speech/private.h index ba790c361aa..a5177ddd538 100644 --- a/dlls/windows.media.speech/private.h +++ b/dlls/windows.media.speech/private.h @@ -64,6 +64,7 @@ extern IActivationFactory *synthesizer_factory; struct vector_iids { const GUID *iterable; + const GUID *iterator; const GUID *vector; const GUID *view; }; diff --git a/dlls/windows.media.speech/recognizer.c b/dlls/windows.media.speech/recognizer.c index cca3e25d0d6..2d6605f4b7e 100644 --- a/dlls/windows.media.speech/recognizer.c +++ b/dlls/windows.media.speech/recognizer.c @@ -642,6 +642,7 @@ static HRESULT WINAPI recognizer_factory_Create( ISpeechRecognizerFactory *iface struct vector_iids constraints_iids = { .iterable = &IID_IIterable_ISpeechRecognitionConstraint, + .iterator = &IID_IIterator_ISpeechRecognitionConstraint, .vector = &IID_IVector_ISpeechRecognitionConstraint, .view = &IID_IVectorView_ISpeechRecognitionConstraint, }; diff --git a/dlls/windows.media.speech/vector.c b/dlls/windows.media.speech/vector.c index bad977fe429..83442d88d0b 100644 --- a/dlls/windows.media.speech/vector.c +++ b/dlls/windows.media.speech/vector.c @@ -772,6 +772,142 @@ error: return hr; }
+/* + * + * IIterator<Inspectable*> + * + */ + +struct iterator_inspectable +{ + IIterator_IInspectable IIterator_IInspectable_iface; + const GUID *iid; + LONG ref; + + IVectorView_IInspectable *view; + UINT32 index; + UINT32 size; +}; + +static inline struct iterator_inspectable *impl_from_IIterator_IInspectable( IIterator_IInspectable *iface ) +{ + return CONTAINING_RECORD(iface, struct iterator_inspectable, IIterator_IInspectable_iface); +} + +static HRESULT WINAPI iterator_inspectable_QueryInterface( IIterator_IInspectable *iface, REFIID iid, void **out ) +{ + struct iterator_inspectable *impl = impl_from_IIterator_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->iid)) + { + IInspectable_AddRef((*out = &impl->IIterator_IInspectable_iface)); + return S_OK; + } + + WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid)); + *out = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI iterator_inspectable_AddRef( IIterator_IInspectable *iface ) +{ + struct iterator_inspectable *impl = impl_from_IIterator_IInspectable(iface); + ULONG ref = InterlockedIncrement(&impl->ref); + TRACE("iface %p increasing refcount to %lu.\n", iface, ref); + return ref; +} + +static ULONG WINAPI iterator_inspectable_Release( IIterator_IInspectable *iface ) +{ + struct iterator_inspectable *impl = impl_from_IIterator_IInspectable(iface); + ULONG ref = InterlockedDecrement(&impl->ref); + + TRACE("iface %p decreasing refcount to %lu.\n", iface, ref); + + if (!ref) + { + IVectorView_IInspectable_Release(impl->view); + free(impl); + } + + return ref; +} + +static HRESULT WINAPI iterator_inspectable_GetIids( IIterator_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 iterator_inspectable_GetRuntimeClassName( IIterator_IInspectable *iface, HSTRING *class_name ) +{ + FIXME("iface %p, class_name %p stub!\n", iface, class_name); + return E_NOTIMPL; +} + +static HRESULT WINAPI iterator_inspectable_GetTrustLevel( IIterator_IInspectable *iface, TrustLevel *trust_level ) +{ + FIXME("iface %p, trust_level %p stub!\n", iface, trust_level); + return E_NOTIMPL; +} + +static HRESULT WINAPI iterator_inspectable_get_Current( IIterator_IInspectable *iface, IInspectable **value ) +{ + struct iterator_inspectable *impl = impl_from_IIterator_IInspectable(iface); + TRACE("iface %p, value %p.\n", iface, value); + return IVectorView_IInspectable_GetAt(impl->view, impl->index, value); +} + +static HRESULT WINAPI iterator_inspectable_get_HasCurrent( IIterator_IInspectable *iface, BOOL *value ) +{ + struct iterator_inspectable *impl = impl_from_IIterator_IInspectable(iface); + + TRACE("iface %p, value %p.\n", iface, value); + + *value = impl->index < impl->size; + return S_OK; +} + +static HRESULT WINAPI iterator_inspectable_MoveNext( IIterator_IInspectable *iface, BOOL *value ) +{ + struct iterator_inspectable *impl = impl_from_IIterator_IInspectable(iface); + + TRACE("iface %p, value %p.\n", iface, value); + + if (impl->index < impl->size) impl->index++; + return IIterator_IInspectable_get_HasCurrent(iface, value); +} + +static HRESULT WINAPI iterator_inspectable_GetMany( IIterator_IInspectable *iface, UINT32 items_size, + IInspectable **items, UINT *count ) +{ + struct iterator_inspectable *impl = impl_from_IIterator_IInspectable(iface); + TRACE("iface %p, items_size %u, items %p, count %p.\n", iface, items_size, items, count); + return IVectorView_IInspectable_GetMany(impl->view, impl->index, items_size, items, count); +} + +static const IIterator_IInspectableVtbl iterator_inspectable_vtbl = +{ + /* IUnknown methods */ + iterator_inspectable_QueryInterface, + iterator_inspectable_AddRef, + iterator_inspectable_Release, + /* IInspectable methods */ + iterator_inspectable_GetIids, + iterator_inspectable_GetRuntimeClassName, + iterator_inspectable_GetTrustLevel, + /* IIterator<IInspectable*> methods */ + iterator_inspectable_get_Current, + iterator_inspectable_get_HasCurrent, + iterator_inspectable_MoveNext, + iterator_inspectable_GetMany +}; + /* * * IVectorView<Inspectable*> @@ -949,8 +1085,21 @@ DEFINE_IINSPECTABLE_(iterable_view_inspectable, IIterable_IInspectable, struct v
static HRESULT WINAPI iterable_view_inspectable_First( IIterable_IInspectable *iface, IIterator_IInspectable **value ) { - FIXME("iface %p, value %p stub!\n", iface, value); - return E_NOTIMPL; + struct vector_view_inspectable *impl = view_impl_from_IIterable_IInspectable(iface); + struct iterator_inspectable *iter; + + TRACE("iface %p, value %p.\n", iface, value); + + if (!(iter = calloc(1, sizeof(struct iterator_inspectable)))) return E_OUTOFMEMORY; + iter->IIterator_IInspectable_iface.lpVtbl = &iterator_inspectable_vtbl; + iter->iid = impl->iids.iterator; + iter->ref = 1; + + IVectorView_IInspectable_AddRef((iter->view = &impl->IVectorView_IInspectable_iface)); + iter->size = impl->size; + + *value = &iter->IIterator_IInspectable_iface; + return S_OK; }
static const struct IIterable_IInspectableVtbl iterable_view_inspectable_vtbl = @@ -1261,8 +1410,22 @@ DEFINE_IINSPECTABLE(iterable_inspectable, IIterable_IInspectable, struct vector_
static HRESULT WINAPI iterable_inspectable_First( IIterable_IInspectable *iface, IIterator_IInspectable **value ) { - FIXME("iface %p, value %p stub!\n", iface, value); - return E_NOTIMPL; + struct vector_inspectable *impl = impl_from_IIterable_IInspectable(iface); + IIterable_IInspectable *iterable; + IVectorView_IInspectable *view; + HRESULT hr; + + TRACE("iface %p, value %p.\n", iface, value); + + if (FAILED(hr = IVector_IInspectable_GetView(&impl->IVector_IInspectable_iface, &view))) return hr; + + hr = IVectorView_IInspectable_QueryInterface(view, impl->iids.iterable, (void **)&iterable); + IVectorView_IInspectable_Release(view); + if (FAILED(hr)) return hr; + + hr = IIterable_IInspectable_First(iterable, value); + IIterable_IInspectable_Release(iterable); + return hr; }
static const struct IIterable_IInspectableVtbl iterable_inspectable_vtbl =
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- dlls/windows.media.speech/recognizer.c | 6 ++++-- dlls/windows.media.speech/tests/speech.c | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/dlls/windows.media.speech/recognizer.c b/dlls/windows.media.speech/recognizer.c index 2d6605f4b7e..350451a69af 100644 --- a/dlls/windows.media.speech/recognizer.c +++ b/dlls/windows.media.speech/recognizer.c @@ -324,8 +324,10 @@ static HRESULT WINAPI recognizer_GetTrustLevel( ISpeechRecognizer *iface, TrustL
static HRESULT WINAPI recognizer_get_Constraints( ISpeechRecognizer *iface, IVector_ISpeechRecognitionConstraint **vector ) { - FIXME("iface %p, operation %p stub!\n", iface, vector); - return E_NOTIMPL; + struct recognizer *impl = impl_from_ISpeechRecognizer(iface); + TRACE("iface %p, operation %p.\n", iface, vector); + IVector_ISpeechRecognitionConstraint_AddRef((*vector = impl->constraints)); + return S_OK; }
static HRESULT WINAPI recognizer_get_CurrentLanguage( ISpeechRecognizer *iface, ILanguage **language ) diff --git a/dlls/windows.media.speech/tests/speech.c b/dlls/windows.media.speech/tests/speech.c index ea160eec9da..8093c4b95b8 100644 --- a/dlls/windows.media.speech/tests/speech.c +++ b/dlls/windows.media.speech/tests/speech.c @@ -729,6 +729,7 @@ static void test_VoiceInformation(void) static void test_SpeechRecognizer(void) { static const WCHAR *speech_recognition_name = L"Windows.Media.SpeechRecognition.SpeechRecognizer"; + IVector_ISpeechRecognitionConstraint *constraints = NULL; ISpeechContinuousRecognitionSession *session = NULL; ISpeechRecognizerFactory *sr_factory = NULL; ISpeechRecognizerStatics *sr_statics = NULL; @@ -841,6 +842,12 @@ static void test_SpeechRecognizer(void) hr = ISpeechContinuousRecognitionSession_remove_ResultGenerated(session, token); ok(hr == S_OK, "ISpeechContinuousRecognitionSession_remove_ResultGenerated failed, hr %#lx.\n", hr);
+ hr = ISpeechRecognizer_get_Constraints(recognizer, &constraints); + ok(hr == S_OK, "ISpeechContinuousRecognitionSession_get_Constraints failed, hr %#lx.\n", hr); + + ref = IVector_ISpeechRecognitionConstraint_Release(constraints); + ok(ref == 1, "Got unexpected ref %lu.\n", ref); + ref = ISpeechContinuousRecognitionSession_Release(session); ok(ref == 1, "Got unexpected ref %lu.\n", ref);
On 3/30/22 15:15, Bernhard Kölbl wrote:
+error:
- if (session) free(session);
- if (impl) free(impl);
You don't need the if before free. FWIW I've missed it before but I think there's another one else where that you could remove at some point later.
I think I added these for style reasons, but I can also just let free check for null pointers.
Bernhard
Am Mi., 30. März 2022 um 17:43 Uhr schrieb Rémi Bernon rbernon@codeweavers.com:
On 3/30/22 15:15, Bernhard Kölbl wrote:
+error:
- if (session) free(session);
- if (impl) free(impl);
You don't need the if before free. FWIW I've missed it before but I think there's another one else where that you could remove at some point later.
-- Rémi Bernon rbernon@codeweavers.com
On 3/30/22 18:08, Bernhard Kölbl wrote:
I think I added these for style reasons, but I can also just let free check for null pointers.
Bernhard
Am Mi., 30. März 2022 um 17:43 Uhr schrieb Rémi Bernon rbernon@codeweavers.com:
On 3/30/22 15:15, Bernhard Kölbl wrote:
+error:
- if (session) free(session);
- if (impl) free(impl);
You don't need the if before free. FWIW I've missed it before but I think there's another one else where that you could remove at some point later.
-- Rémi Bernon rbernon@codeweavers.com
Yeah I think we usually do that, it removes a conditional and simplifies the code.