Needed by Lenovo Ready For Assistant.
-- v2: windows.devices.enumeration/tests: Add IDeviceInformationStatics::CreateWatcherAqsFilter() tests. windows.devices.enumeration: Implement IDeviceInformationStatics::CreateWatcherAqsFilter(). windows.devices.enumeration: Add IDeviceInformationStatics stub interface.
From: Mohamad Al-Jaf mohamadaljaf@gmail.com
--- include/windows.devices.enumeration.idl | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
diff --git a/include/windows.devices.enumeration.idl b/include/windows.devices.enumeration.idl index a88cb69edac..0186d043e42 100644 --- a/include/windows.devices.enumeration.idl +++ b/include/windows.devices.enumeration.idl @@ -192,6 +192,44 @@ namespace Windows.Devices.Enumeration { [propget] HRESULT Panel([out, retval] Windows.Devices.Enumeration.Panel *value); }
+ [ + contract(Windows.Foundation.UniversalApiContract, 1.0), + exclusiveto(Windows.Devices.Enumeration.DeviceInformation), + uuid(c17f100e-3a46-4a78-8013-769dc9b97390) + ] + interface IDeviceInformationStatics : IInspectable + { + [overload("CreateFromIdAsync")] + HRESULT CreateFromIdAsync([in] HSTRING id, + [out, retval] Windows.Foundation.IAsyncOperation<Windows.Devices.Enumeration.DeviceInformation *> **op); + [overload("CreateFromIdAsync")] + HRESULT CreateFromIdAsyncAdditionalProperties([in] HSTRING id, + [in] Windows.Foundation.Collections.IIterable<HSTRING> *additional_properties, + [out, retval] Windows.Foundation.IAsyncOperation<Windows.Devices.Enumeration.DeviceInformation *> **op); + [overload("FindAllAsync")] + HRESULT FindAllAsync([out, retval] Windows.Foundation.IAsyncOperation<Windows.Devices.Enumeration.DeviceInformationCollection *> **op); + [default_overload] [overload("FindAllAsync")] + HRESULT FindAllAsyncDeviceClass([in] Windows.Devices.Enumeration.DeviceClass device_class, + [out, retval] Windows.Foundation.IAsyncOperation<Windows.Devices.Enumeration.DeviceInformationCollection *> **op); + [overload("FindAllAsync")] + HRESULT FindAllAsyncAqsFilter([in] HSTRING filter, + [out, retval] Windows.Foundation.IAsyncOperation<Windows.Devices.Enumeration.DeviceInformationCollection *> **op); + [overload("FindAllAsync")] + HRESULT FindAllAsyncAqsFilterAndAdditionalProperties([in] HSTRING filter, + [in] Windows.Foundation.Collections.IIterable<HSTRING> *additional_properties, + [out, retval] Windows.Foundation.IAsyncOperation<Windows.Devices.Enumeration.DeviceInformationCollection *> **op); + [overload("CreateWatcher")] + HRESULT CreateWatcher([out, retval] Windows.Devices.Enumeration.DeviceWatcher **watcher); + [default_overload] [overload("CreateWatcher")] + HRESULT CreateWatcherDeviceClass([in] Windows.Devices.Enumeration.DeviceClass device_class, + [out, retval] Windows.Devices.Enumeration.DeviceWatcher **watcher); + [overload("CreateWatcher")] + HRESULT CreateWatcherAqsFilter([in] HSTRING filter, [out, retval] Windows.Devices.Enumeration.DeviceWatcher **watcher); + [overload("CreateWatcher")] + HRESULT CreateWatcherAqsFilterAndAdditionalProperties([in] HSTRING filter, + [in] Windows.Foundation.Collections.IIterable<HSTRING> *additional_properties, [out, retval] Windows.Devices.Enumeration.DeviceWatcher **watcher); + } + [ contract(Windows.Foundation.UniversalApiContract, 1.0), exclusiveto(Windows.Devices.Enumeration.DeviceInformation),
From: Mohamad Al-Jaf mohamadaljaf@gmail.com
--- dlls/windows.devices.enumeration/main.c | 101 ++++++++++++++++++ .../tests/devices.c | 14 ++- 2 files changed, 113 insertions(+), 2 deletions(-)
diff --git a/dlls/windows.devices.enumeration/main.c b/dlls/windows.devices.enumeration/main.c index c87240df2db..0d392e1cf14 100644 --- a/dlls/windows.devices.enumeration/main.c +++ b/dlls/windows.devices.enumeration/main.c @@ -220,6 +220,7 @@ static const struct IDeviceWatcherVtbl device_watcher_vtbl = struct device_information_statics { IActivationFactory IActivationFactory_iface; + IDeviceInformationStatics IDeviceInformationStatics_iface; IDeviceInformationStatics2 IDeviceInformationStatics2_iface; LONG ref; }; @@ -243,6 +244,12 @@ static HRESULT WINAPI activation_factory_QueryInterface( IActivationFactory *ifa return S_OK; }
+ if (IsEqualGUID( iid, &IID_IDeviceInformationStatics )) + { + IInspectable_AddRef( (*out = &impl->IDeviceInformationStatics_iface) ); + return S_OK; + } + if (IsEqualGUID( iid, &IID_IDeviceInformationStatics2 )) { IInspectable_AddRef( (*out = &impl->IDeviceInformationStatics2_iface) ); @@ -307,6 +314,99 @@ static const struct IActivationFactoryVtbl activation_factory_vtbl = activation_factory_ActivateInstance, };
+DEFINE_IINSPECTABLE( device_statics, IDeviceInformationStatics, struct device_information_statics, IActivationFactory_iface ); + +static HRESULT WINAPI device_statics_CreateFromIdAsync( IDeviceInformationStatics *iface, HSTRING id, + IAsyncOperation_DeviceInformation **op ) +{ + FIXME( "iface %p, id %s, op %p stub!\n", iface, debugstr_hstring(id), op ); + return E_NOTIMPL; +} + +static HRESULT WINAPI device_statics_CreateFromIdAsyncAdditionalProperties( IDeviceInformationStatics *iface, HSTRING id, + IIterable_HSTRING *additional_properties, + IAsyncOperation_DeviceInformation **op ) +{ + FIXME( "iface %p, id %s, additional_properties %p, op %p stub!\n", iface, debugstr_hstring(id), additional_properties, op ); + return E_NOTIMPL; +} + +static HRESULT WINAPI device_statics_FindAllAsync( IDeviceInformationStatics *iface, + IAsyncOperation_DeviceInformationCollection **op ) +{ + FIXME( "iface %p, op %p stub!\n", iface, op ); + return E_NOTIMPL; +} + +static HRESULT WINAPI device_statics_FindAllAsyncDeviceClass( IDeviceInformationStatics *iface, DeviceClass class, + IAsyncOperation_DeviceInformationCollection **op ) +{ + FIXME( "iface %p, class %d, op %p stub!\n", iface, class, op ); + return E_NOTIMPL; +} + +static HRESULT WINAPI device_statics_FindAllAsyncAqsFilter( IDeviceInformationStatics *iface, HSTRING filter, + IAsyncOperation_DeviceInformationCollection **op ) +{ + FIXME( "iface %p, aqs %p, op %p stub!\n", iface, debugstr_hstring(filter), op ); + return E_NOTIMPL; +} + +static HRESULT WINAPI device_statics_FindAllAsyncAqsFilterAndAdditionalProperties( IDeviceInformationStatics *iface, HSTRING filter, + IIterable_HSTRING *additional_properties, + IAsyncOperation_DeviceInformationCollection **op ) +{ + FIXME( "iface %p, aqs %p, additional_properties %p, op %p stub!\n", iface, debugstr_hstring(filter), additional_properties, op ); + return E_NOTIMPL; +} + +static HRESULT WINAPI device_statics_CreateWatcher( IDeviceInformationStatics *iface, IDeviceWatcher **watcher ) +{ + FIXME( "iface %p, watcher %p stub!\n", iface, watcher ); + return E_NOTIMPL; +} + +static HRESULT WINAPI device_statics_CreateWatcherDeviceClass( IDeviceInformationStatics *iface, DeviceClass class, IDeviceWatcher **watcher ) +{ + FIXME( "iface %p, class %d, watcher %p stub!\n", iface, class, watcher ); + return E_NOTIMPL; +} + +static HRESULT WINAPI device_statics_CreateWatcherAqsFilter( IDeviceInformationStatics *iface, HSTRING filter, IDeviceWatcher **watcher ) +{ + FIXME( "iface %p, filter %s, watcher %p stub!\n", iface, debugstr_hstring(filter), watcher ); + return E_NOTIMPL; +} + +static HRESULT WINAPI device_statics_CreateWatcherAqsFilterAndAdditionalProperties( IDeviceInformationStatics *iface, HSTRING filter, + IIterable_HSTRING *additional_properties, IDeviceWatcher **watcher ) +{ + FIXME( "iface %p, aqs %p, additional_properties %p, watcher %p stub!\n", iface, debugstr_hstring(filter), additional_properties, watcher ); + return E_NOTIMPL; +} + +static const struct IDeviceInformationStaticsVtbl device_statics_vtbl = +{ + device_statics_QueryInterface, + device_statics_AddRef, + device_statics_Release, + /* IInspectable methods */ + device_statics_GetIids, + device_statics_GetRuntimeClassName, + device_statics_GetTrustLevel, + /* IDeviceInformationStatics methods */ + device_statics_CreateFromIdAsync, + device_statics_CreateFromIdAsyncAdditionalProperties, + device_statics_FindAllAsync, + device_statics_FindAllAsyncDeviceClass, + device_statics_FindAllAsyncAqsFilter, + device_statics_FindAllAsyncAqsFilterAndAdditionalProperties, + device_statics_CreateWatcher, + device_statics_CreateWatcherDeviceClass, + device_statics_CreateWatcherAqsFilter, + device_statics_CreateWatcherAqsFilterAndAdditionalProperties, +}; + DEFINE_IINSPECTABLE( device_statics2, IDeviceInformationStatics2, struct device_information_statics, IActivationFactory_iface );
static HRESULT WINAPI device_statics2_GetAqsFilterFromDeviceClass( IDeviceInformationStatics2 *iface, DeviceClass device_class, @@ -374,6 +474,7 @@ static const struct IDeviceInformationStatics2Vtbl device_statics2_vtbl = static struct device_information_statics device_information_statics = { {&activation_factory_vtbl}, + {&device_statics_vtbl}, {&device_statics2_vtbl}, 1 }; diff --git a/dlls/windows.devices.enumeration/tests/devices.c b/dlls/windows.devices.enumeration/tests/devices.c index c65312ea800..833b8835842 100644 --- a/dlls/windows.devices.enumeration/tests/devices.c +++ b/dlls/windows.devices.enumeration/tests/devices.c @@ -144,6 +144,7 @@ static void test_DeviceInformation( void ) IInspectable *inspectable, *inspectable2; IActivationFactory *factory; IDeviceInformationStatics2 *device_info_statics2; + IDeviceInformationStatics *device_info_statics; IDeviceWatcher *device_watcher; DeviceWatcherStatus status = 0xdeadbeef; ULONG ref; @@ -174,7 +175,7 @@ static void test_DeviceInformation( void ) if (FAILED( hr )) { win_skip( "IDeviceInformationStatics2 not supported.\n" ); - goto skip_device_statics2; + goto skip_device_statics; }
hr = IDeviceInformationStatics2_QueryInterface( device_info_statics2, &IID_IInspectable, (void **)&inspectable2 ); @@ -223,7 +224,16 @@ static void test_DeviceInformation( void ) IInspectable_Release( inspectable2 ); IDeviceInformationStatics2_Release( device_info_statics2 );
-skip_device_statics2: + hr = IActivationFactory_QueryInterface( factory, &IID_IDeviceInformationStatics, (void **)&device_info_statics ); + ok( hr == S_OK || broken( hr == E_NOINTERFACE ), "got hr %#lx\n", hr ); + if (FAILED( hr )) + { + win_skip( "IDeviceInformationStatics not supported.\n" ); + goto skip_device_statics; + } + + IDeviceInformationStatics_Release( device_info_statics ); +skip_device_statics: IInspectable_Release( inspectable ); ref = IActivationFactory_Release( factory ); ok( ref == 1, "got ref %lu\n", ref );
From: Mohamad Al-Jaf mohamadaljaf@gmail.com
Needed by Lenovo Ready For Assistant. --- dlls/windows.devices.enumeration/main.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/dlls/windows.devices.enumeration/main.c b/dlls/windows.devices.enumeration/main.c index 0d392e1cf14..c5bd40d8448 100644 --- a/dlls/windows.devices.enumeration/main.c +++ b/dlls/windows.devices.enumeration/main.c @@ -31,6 +31,7 @@ struct device_watcher LONG ref;
struct list stopped_handlers; + HSTRING filter; };
static inline struct device_watcher *impl_from_IDeviceWatcher( IDeviceWatcher *iface ) @@ -374,8 +375,20 @@ static HRESULT WINAPI device_statics_CreateWatcherDeviceClass( IDeviceInformatio
static HRESULT WINAPI device_statics_CreateWatcherAqsFilter( IDeviceInformationStatics *iface, HSTRING filter, IDeviceWatcher **watcher ) { - FIXME( "iface %p, filter %s, watcher %p stub!\n", iface, debugstr_hstring(filter), watcher ); - return E_NOTIMPL; + struct device_watcher *this; + + TRACE( "iface %p, filter %s, watcher %p\n", iface, debugstr_hstring(filter), watcher ); + + if (!(this = calloc( 1, sizeof(*this) ))) return E_OUTOFMEMORY; + + this->IDeviceWatcher_iface.lpVtbl = &device_watcher_vtbl; + this->ref = 1; + WindowsDuplicateString( filter, &this->filter ); + + list_init( &this->stopped_handlers ); + + *watcher = &this->IDeviceWatcher_iface; + return S_OK; }
static HRESULT WINAPI device_statics_CreateWatcherAqsFilterAndAdditionalProperties( IDeviceInformationStatics *iface, HSTRING filter,
From: Mohamad Al-Jaf mohamadaljaf@gmail.com
--- .../tests/devices.c | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+)
diff --git a/dlls/windows.devices.enumeration/tests/devices.c b/dlls/windows.devices.enumeration/tests/devices.c index 833b8835842..ae76e5d754a 100644 --- a/dlls/windows.devices.enumeration/tests/devices.c +++ b/dlls/windows.devices.enumeration/tests/devices.c @@ -232,6 +232,47 @@ static void test_DeviceInformation( void ) goto skip_device_statics; }
+ IDeviceInformationStatics_CreateWatcherAqsFilter( device_info_statics, NULL, &device_watcher ); + ok( hr == S_OK, "got hr %#lx\n", hr ); + + check_interface( device_watcher, &IID_IUnknown, TRUE ); + check_interface( device_watcher, &IID_IInspectable, TRUE ); + check_interface( device_watcher, &IID_IAgileObject, TRUE ); + check_interface( device_watcher, &IID_IDeviceWatcher, TRUE ); + + hr = IDeviceWatcher_add_Added( + device_watcher, + (ITypedEventHandler_DeviceWatcher_DeviceInformation *)&added_handler.ITypedEventHandler_DeviceWatcher_IInspectable_iface, + &added_token ); + ok( hr == S_OK, "got hr %#lx\n", hr ); + hr = IDeviceWatcher_add_Stopped( + device_watcher, &stopped_handler.ITypedEventHandler_DeviceWatcher_IInspectable_iface, + &stopped_token ); + ok( hr == S_OK, "got hr %#lx\n", hr ); + + hr = IDeviceWatcher_get_Status( device_watcher, &status ); + todo_wine ok( hr == S_OK, "got hr %#lx\n", hr ); + todo_wine ok( status == DeviceWatcherStatus_Created, "got status %u\n", status ); + + hr = IDeviceWatcher_Start( device_watcher ); + ok( hr == S_OK, "got hr %#lx\n", hr ); + hr = IDeviceWatcher_get_Status( device_watcher, &status ); + todo_wine ok( hr == S_OK, "got hr %#lx\n", hr ); + todo_wine ok( status == DeviceWatcherStatus_Started, "got status %u\n", status ); + + ref = IDeviceWatcher_AddRef( device_watcher ); + ok( ref == 2, "got ref %lu\n", ref ); + hr = IDeviceWatcher_Stop( device_watcher ); + ok( hr == S_OK, "got hr %#lx\n", hr ); + ok( !WaitForSingleObject( stopped_handler.event, 1000 ), "wait for stopped_handler.event failed\n" ); + + hr = IDeviceWatcher_get_Status( device_watcher, &status ); + todo_wine ok( hr == S_OK, "got hr %#lx\n", hr ); + todo_wine ok( status == DeviceWatcherStatus_Stopped, "got status %u\n", status ); + ok( stopped_handler.invoked, "stopped_handler not invoked\n" ); + ok( stopped_handler.args == NULL, "stopped_handler not invoked\n" ); + + IDeviceWatcher_Release( device_watcher ); IDeviceInformationStatics_Release( device_info_statics ); skip_device_statics: IInspectable_Release( inspectable );
Rémi Bernon (@rbernon) commented about include/windows.devices.enumeration.idl:
contract(Windows.Foundation.UniversalApiContract, 1.0),
exclusiveto(Windows.Devices.Enumeration.DeviceInformation),
uuid(c17f100e-3a46-4a78-8013-769dc9b97390)
- ]
- interface IDeviceInformationStatics : IInspectable
- {
[overload("CreateFromIdAsync")]
HRESULT CreateFromIdAsync([in] HSTRING id,
[out, retval] Windows.Foundation.IAsyncOperation<Windows.Devices.Enumeration.DeviceInformation *> **op);
[overload("CreateFromIdAsync")]
HRESULT CreateFromIdAsyncAdditionalProperties([in] HSTRING id,
[in] Windows.Foundation.Collections.IIterable<HSTRING> *additional_properties,
[out, retval] Windows.Foundation.IAsyncOperation<Windows.Devices.Enumeration.DeviceInformation *> **op);
[overload("FindAllAsync")]
HRESULT FindAllAsync([out, retval] Windows.Foundation.IAsyncOperation<Windows.Devices.Enumeration.DeviceInformationCollection *> **op);
[default_overload] [overload("FindAllAsync")]
I'd use the same attribute style as everywhere else (and put overload first as it's more common):
```suggestion:-0+0 [overload("FindAllAsync"), default_overload] ```
Rémi Bernon (@rbernon) commented about dlls/windows.devices.enumeration/main.c:
static HRESULT WINAPI device_statics_CreateWatcherAqsFilter( IDeviceInformationStatics *iface, HSTRING filter, IDeviceWatcher **watcher ) {
- FIXME( "iface %p, filter %s, watcher %p stub!\n", iface, debugstr_hstring(filter), watcher );
- return E_NOTIMPL;
- struct device_watcher *this;
- TRACE( "iface %p, filter %s, watcher %p\n", iface, debugstr_hstring(filter), watcher );
- if (!(this = calloc( 1, sizeof(*this) ))) return E_OUTOFMEMORY;
- this->IDeviceWatcher_iface.lpVtbl = &device_watcher_vtbl;
- this->ref = 1;
- WindowsDuplicateString( filter, &this->filter );
Now that the filter string is kept on the object, you should probably also call `WindowsDuplicateString` in `device_statics2_CreateWatcher`. And you need to call `WindowsDeleteString` in `device_watcher_Release`.