[PATCH 2/2] sapi: Add stub SpResourceManager object.
Gijs Vermeulen
gijsvrm at gmail.com
Thu Nov 12 04:28:07 CST 2020
Signed-off-by: Gijs Vermeulen <gijsvrm at gmail.com>
---
dlls/sapi/Makefile.in | 1 +
dlls/sapi/main.c | 3 +
dlls/sapi/resource.c | 140 ++++++++++++++++++++++++++++++++++++
dlls/sapi/sapi_private.h | 1 +
dlls/sapi/tests/Makefile.in | 1 +
dlls/sapi/tests/resource.c | 80 +++++++++++++++++++++
include/sapi.idl | 32 +++++++++
7 files changed, 258 insertions(+)
create mode 100644 dlls/sapi/resource.c
create mode 100644 dlls/sapi/tests/resource.c
diff --git a/dlls/sapi/Makefile.in b/dlls/sapi/Makefile.in
index f695bd47b12..466941ddd87 100644
--- a/dlls/sapi/Makefile.in
+++ b/dlls/sapi/Makefile.in
@@ -6,6 +6,7 @@ EXTRADLLFLAGS = -mno-cygwin
C_SRCS = \
automation.c \
main.c \
+ resource.c \
stream.c \
token.c \
tts.c
diff --git a/dlls/sapi/main.c b/dlls/sapi/main.c
index cbe097f22ad..4408e1e693f 100644
--- a/dlls/sapi/main.c
+++ b/dlls/sapi/main.c
@@ -107,6 +107,7 @@ static const struct IClassFactoryVtbl class_factory_vtbl =
static struct class_factory data_key_cf = { { &class_factory_vtbl }, data_key_create };
static struct class_factory file_stream_cf = { { &class_factory_vtbl }, file_stream_create };
+static struct class_factory resource_mgr_cf = { { &class_factory_vtbl }, resource_manager_create };
static struct class_factory speech_stream_cf = { { &class_factory_vtbl }, speech_stream_create };
static struct class_factory speech_voice_cf = { { &class_factory_vtbl }, speech_voice_create };
static struct class_factory token_category_cf = { { &class_factory_vtbl }, token_category_create };
@@ -132,6 +133,8 @@ HRESULT WINAPI DllGetClassObject( REFCLSID clsid, REFIID iid, void **obj )
cf = &token_enum_cf.IClassFactory_iface;
else if (IsEqualCLSID( clsid, &CLSID_SpObjectToken ))
cf = &token_cf.IClassFactory_iface;
+ else if (IsEqualCLSID( clsid, &CLSID_SpResourceManager ))
+ cf = &resource_mgr_cf.IClassFactory_iface;
else if (IsEqualCLSID( clsid, &CLSID_SpStream ))
cf = &speech_stream_cf.IClassFactory_iface;
else if (IsEqualCLSID( clsid, &CLSID_SpVoice ))
diff --git a/dlls/sapi/resource.c b/dlls/sapi/resource.c
new file mode 100644
index 00000000000..85d4430f8ad
--- /dev/null
+++ b/dlls/sapi/resource.c
@@ -0,0 +1,140 @@
+/*
+ * Speech API (SAPI) resource manager implementation.
+ *
+ * Copyright 2020 Gijs Vermeulen
+ *
+ * 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
+ */
+
+#include <stdarg.h>
+
+#define COBJMACROS
+
+#include "windef.h"
+#include "winbase.h"
+#include "objbase.h"
+
+#include "sapiddk.h"
+
+#include "wine/debug.h"
+
+#include "sapi_private.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(sapi);
+
+struct resource_manager
+{
+ ISpResourceManager ISpResourceManager_iface;
+ LONG ref;
+};
+
+static inline struct resource_manager *impl_from_ISpResourceManager(ISpResourceManager *iface)
+{
+ return CONTAINING_RECORD(iface, struct resource_manager, ISpResourceManager_iface);
+}
+
+static HRESULT WINAPI resource_manager_QueryInterface(ISpResourceManager *iface, REFIID iid, void **obj)
+{
+ struct resource_manager *This = impl_from_ISpResourceManager(iface);
+
+ TRACE("(%p, %s, %p).\n", iface, debugstr_guid(iid), obj);
+
+ if (IsEqualIID(iid, &IID_IUnknown) ||
+ IsEqualIID(iid, &IID_ISpResourceManager))
+ *obj = &This->ISpResourceManager_iface;
+ else
+ {
+ *obj = NULL;
+ FIXME("interface %s not implemented.\n", debugstr_guid(iid));
+ return E_NOINTERFACE;
+ }
+
+ IUnknown_AddRef((IUnknown *)*obj);
+ return S_OK;
+}
+
+static ULONG WINAPI resource_manager_AddRef(ISpResourceManager *iface)
+{
+ struct resource_manager *This = impl_from_ISpResourceManager(iface);
+ ULONG ref = InterlockedIncrement(&This->ref);
+
+ TRACE("(%p): ref=%u.\n", iface, ref);
+
+ return ref;
+}
+
+static ULONG WINAPI resource_manager_Release(ISpResourceManager *iface)
+{
+ struct resource_manager *This = impl_from_ISpResourceManager(iface);
+ ULONG ref = InterlockedDecrement(&This->ref);
+
+ TRACE("(%p): ref=%u.\n", iface, ref);
+
+ if (!ref)
+ {
+ heap_free(This);
+ }
+
+ return ref;
+}
+
+static HRESULT WINAPI resource_manager_QueryService(ISpResourceManager *iface, REFGUID guid, REFIID iid,
+ void **obj)
+{
+ FIXME("(%p, %s, %s, %p): stub.\n", iface, debugstr_guid(guid), debugstr_guid(iid), obj);
+
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI resource_manager_SetObject(ISpResourceManager *iface, REFGUID guid, IUnknown *obj)
+{
+ FIXME("(%p, %s, %p): stub.\n", iface, debugstr_guid(guid), obj);
+
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI resource_manager_GetObject(ISpResourceManager *iface, REFGUID guid, REFCLSID clsid, REFIID iid,
+ BOOL release, void **obj)
+{
+ FIXME("(%p, %s, %s, %s, %d, %p): stub.\n", iface, debugstr_guid(guid), debugstr_guid(clsid), debugstr_guid(iid),
+ release, obj);
+
+ return E_NOTIMPL;
+}
+
+const static ISpResourceManagerVtbl resource_manager_vtbl =
+{
+ resource_manager_QueryInterface,
+ resource_manager_AddRef,
+ resource_manager_Release,
+ resource_manager_QueryService,
+ resource_manager_SetObject,
+ resource_manager_GetObject
+};
+
+HRESULT resource_manager_create(IUnknown *outer, REFIID iid, void **obj)
+{
+ struct resource_manager *This = heap_alloc(sizeof(*This));
+ HRESULT hr;
+
+ if (!This) return E_OUTOFMEMORY;
+ This->ISpResourceManager_iface.lpVtbl = &resource_manager_vtbl;
+ This->ref = 1;
+
+ hr = ISpResourceManager_QueryInterface(&This->ISpResourceManager_iface, iid, obj);
+
+ ISpResourceManager_Release(&This->ISpResourceManager_iface);
+ return hr;
+}
diff --git a/dlls/sapi/sapi_private.h b/dlls/sapi/sapi_private.h
index 509bcb0715b..8a375cdb6c2 100644
--- a/dlls/sapi/sapi_private.h
+++ b/dlls/sapi/sapi_private.h
@@ -22,6 +22,7 @@
HRESULT data_key_create( IUnknown *outer, REFIID iid, void **obj ) DECLSPEC_HIDDEN;
HRESULT file_stream_create( IUnknown *outer, REFIID iid, void **obj ) DECLSPEC_HIDDEN;
+HRESULT resource_manager_create( IUnknown *outer, REFIID iid, void **obj ) DECLSPEC_HIDDEN;
HRESULT speech_stream_create( IUnknown *outer, REFIID iid, void **obj ) DECLSPEC_HIDDEN;
HRESULT speech_voice_create( IUnknown *outer, REFIID iid, void **obj ) DECLSPEC_HIDDEN;
HRESULT token_category_create( IUnknown *outer, REFIID iid, void **obj ) DECLSPEC_HIDDEN;
diff --git a/dlls/sapi/tests/Makefile.in b/dlls/sapi/tests/Makefile.in
index f1de67418dc..75c70d072d8 100644
--- a/dlls/sapi/tests/Makefile.in
+++ b/dlls/sapi/tests/Makefile.in
@@ -3,6 +3,7 @@ IMPORTS = ole32 user32 advapi32
C_SRCS = \
automation.c \
+ resource.c \
stream.c \
token.c \
tts.c
diff --git a/dlls/sapi/tests/resource.c b/dlls/sapi/tests/resource.c
new file mode 100644
index 00000000000..cbddaf6323a
--- /dev/null
+++ b/dlls/sapi/tests/resource.c
@@ -0,0 +1,80 @@
+/*
+ * Speech API (SAPI) resource manager tests.
+ *
+ * Copyright 2020 Gijs Vermeulen
+ *
+ * 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
+ */
+
+#define COBJMACROS
+
+#include "sapiddk.h"
+#include "sperror.h"
+
+#include "wine/test.h"
+
+#define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
+static void _expect_ref(IUnknown *obj, ULONG ref, int line)
+{
+ ULONG rc;
+ IUnknown_AddRef(obj);
+ rc = IUnknown_Release(obj);
+ ok_(__FILE__,line)(rc == ref, "Unexpected refcount %d, expected %d.\n", rc, ref);
+}
+
+static void test_interfaces(void)
+{
+ ISpResourceManager *resource_manager, *resource_manager2;
+ IDispatch *dispatch;
+ IUnknown *unk;
+ HRESULT hr;
+
+ hr = CoCreateInstance(&CLSID_SpResourceManager, NULL, CLSCTX_INPROC_SERVER,
+ &IID_ISpResourceManager, (void **)&resource_manager);
+ ok(hr == S_OK, "Failed to create ISpeechVoice interface: %#x.\n", hr);
+ EXPECT_REF(resource_manager, 1);
+
+ hr = CoCreateInstance(&CLSID_SpResourceManager, NULL, CLSCTX_INPROC_SERVER,
+ &IID_ISpResourceManager, (void **)&resource_manager2);
+ ok(hr == S_OK, "Failed to create ISpeechVoice interface: %#x.\n", hr);
+ todo_wine ok(resource_manager2 == resource_manager, "Expected managers to match.\n");
+ todo_wine EXPECT_REF(resource_manager2, 2);
+ todo_wine EXPECT_REF(resource_manager, 2);
+ if (resource_manager2 == resource_manager) ISpResourceManager_Release(resource_manager2);
+ EXPECT_REF(resource_manager, 1);
+
+ hr = CoCreateInstance(&CLSID_SpResourceManager, NULL, CLSCTX_INPROC_SERVER,
+ &IID_IUnknown, (void **)&unk);
+ ok(hr == S_OK, "Failed to create IUnknown interface: %#x.\n", hr);
+ todo_wine ok(unk == (IUnknown *)resource_manager, "Expected unk to match existing manager.\n");
+ todo_wine EXPECT_REF(unk, 2);
+ todo_wine EXPECT_REF(resource_manager, 2);
+ if (unk == (IUnknown *)resource_manager) IUnknown_Release(unk);
+ EXPECT_REF(resource_manager, 1);
+
+ hr = CoCreateInstance(&CLSID_SpResourceManager, NULL, CLSCTX_INPROC_SERVER,
+ &IID_IDispatch, (void **)&dispatch);
+ ok(hr == E_NOINTERFACE, "Succeeded to create IDispatch interface: %#x.\n", hr);
+ ok(!dispatch, "Expected NULL dispatch, got %p.", dispatch);
+
+ ISpResourceManager_Release(resource_manager);
+}
+
+START_TEST(resource)
+{
+ CoInitialize(NULL);
+ test_interfaces();
+ CoUninitialize();
+}
diff --git a/include/sapi.idl b/include/sapi.idl
index e71d009428c..5120e379450 100644
--- a/include/sapi.idl
+++ b/include/sapi.idl
@@ -651,6 +651,24 @@ interface IEnumSpObjectTokens : IUnknown
HRESULT GetCount([out] ULONG *pCount);
}
+[
+ object,
+ uuid(93384e18-5014-43d5-adbb-a78e055926bd),
+ helpstring("ISpResourceManager"),
+ pointer_default(unique),
+ restricted
+]
+interface ISpResourceManager : IServiceProvider
+{
+ HRESULT SetObject([in] REFGUID guidServiceId,
+ [in] IUnknown *pUnkObject);
+ HRESULT GetObject([in] REFGUID guidServiceId,
+ [in] REFCLSID ObjectCLSID,
+ [in] REFIID ObjectIID,
+ [in] BOOL fReleaseWhenLastExternalRefReleased,
+ [out, iid_is(ObjectIID)] void** ppObject);
+}
+
[
object,
uuid(1a5c0354-b621-4b5a-8791-d306ed379e53),
@@ -1077,6 +1095,20 @@ library SpeechLib
[default] interface ISpDataKey;
}
+ [
+ uuid(96749373-3391-11d2-9ee3-00c04f797396),
+ helpstring("Resource Manager"),
+ progid("SAPI.SpResourceManager.1"),
+ vi_progid("SAPI.SpResourceManager"),
+ threading(both),
+ restricted,
+ hidden
+ ]
+ coclass SpResourceManager
+ {
+ [default] interface ISpResourceManager;
+ };
+
[
uuid(3bee4890-4fe9-4a37-8c1e-5e7e12791c1f)
]
--
2.29.2
More information about the wine-devel
mailing list