From: Vibhav Pant vibhavp@gmail.com
--- dlls/windows.devices.bluetooth/Makefile.in | 1 + .../windows.devices.bluetooth/advertisement.c | 329 ++++++++++++++++++ dlls/windows.devices.bluetooth/classes.idl | 1 + dlls/windows.devices.bluetooth/main.c | 2 + dlls/windows.devices.bluetooth/private.h | 3 + .../tests/bluetooth.c | 4 +- 6 files changed, 338 insertions(+), 2 deletions(-) create mode 100644 dlls/windows.devices.bluetooth/advertisement.c
diff --git a/dlls/windows.devices.bluetooth/Makefile.in b/dlls/windows.devices.bluetooth/Makefile.in index 89f3fc78abc..237a54b04fc 100644 --- a/dlls/windows.devices.bluetooth/Makefile.in +++ b/dlls/windows.devices.bluetooth/Makefile.in @@ -2,6 +2,7 @@ MODULE = windows.devices.bluetooth.dll IMPORTS = combase
SOURCES = \ + advertisement.c \ bluetoothadapter.c \ bluetoothdevice.c \ classes.idl \ diff --git a/dlls/windows.devices.bluetooth/advertisement.c b/dlls/windows.devices.bluetooth/advertisement.c new file mode 100644 index 00000000000..9e08c8873f0 --- /dev/null +++ b/dlls/windows.devices.bluetooth/advertisement.c @@ -0,0 +1,329 @@ +/* windows.Devices.Bluetooth.Advertisement Implementation + * + * Copyright 2025 Vibhav Pant + * + * 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 "private.h" + +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL( bluetooth ); + +struct adv_watcher_factory +{ + IActivationFactory IActivationFactory_iface; + LONG ref; +}; + +static inline struct adv_watcher_factory *impl_from_IActivationFactory( IActivationFactory *iface ) +{ + return CONTAINING_RECORD( iface, struct adv_watcher_factory, IActivationFactory_iface ); +} + +static HRESULT WINAPI adv_watcher_factory_QueryInterface( IActivationFactory *iface, REFIID iid, void **out ) +{ + struct adv_watcher_factory *impl = impl_from_IActivationFactory( iface ); + + TRACE( "(%p, %s, %p)\n", iface, debugstr_guid( iid ), out ); + + if (IsEqualGUID( iid, &IID_IUnknown ) || + IsEqualGUID( iid, &IID_IInspectable ) || + IsEqualGUID( iid, &IID_IAgileObject ) || + IsEqualGUID( iid, &IID_IActivationFactory )) + { + IActivationFactory_AddRef(( *out = &impl->IActivationFactory_iface )); + return S_OK; + } + + *out = NULL; + FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) ); + return E_NOINTERFACE; +} + +static ULONG WINAPI adv_watcher_factory_AddRef( IActivationFactory *iface ) +{ + struct adv_watcher_factory *impl = impl_from_IActivationFactory( iface ); + TRACE( "(%p)\n", iface ); + return InterlockedIncrement( &impl->ref ); +} + +static ULONG WINAPI adv_watcher_factory_Release( IActivationFactory *iface ) +{ + struct adv_watcher_factory *impl = impl_from_IActivationFactory( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + TRACE( "(%p)\n", iface ); + return ref; +} + +static HRESULT WINAPI adv_watcher_factory_GetIids( IActivationFactory *iface, ULONG *iid_count, IID **iids ) +{ + FIXME( "(%p, %p, %p): stub!\n", iface, iid_count, iids ); + return E_NOTIMPL; +} + +static HRESULT WINAPI adv_watcher_factory_GetRuntimeClassName( IActivationFactory *iface, HSTRING *class_name ) +{ + FIXME( "(%p, %p): stub!\n", iface, class_name ); + return E_NOTIMPL; +} + +static HRESULT WINAPI adv_watcher_factory_GetTrustLevel( IActivationFactory *iface, TrustLevel *level ) +{ + FIXME( "(%p, %p): stub!\n", iface, level ); + return E_NOTIMPL; +} + +static HRESULT adv_watcher_create( IBluetoothLEAdvertisementWatcher **watcher ); + +static HRESULT WINAPI adv_watcher_factory_ActivateInstance( IActivationFactory *iface, IInspectable **instance ) +{ + TRACE( "(%p, %p)\n", iface, instance ); + return adv_watcher_create( (IBluetoothLEAdvertisementWatcher **)instance ); +} + +static const struct IActivationFactoryVtbl adv_watcher_factory_vtbl = +{ + adv_watcher_factory_QueryInterface, + adv_watcher_factory_AddRef, + adv_watcher_factory_Release, + /* IInspectable */ + adv_watcher_factory_GetIids, + adv_watcher_factory_GetRuntimeClassName, + adv_watcher_factory_GetTrustLevel, + /* IActivationFactory */ + adv_watcher_factory_ActivateInstance +}; + +static struct adv_watcher_factory adv_watcher_factory = +{ + {&adv_watcher_factory_vtbl}, + 1 +}; + +IActivationFactory *advertisement_watcher_factory = &adv_watcher_factory.IActivationFactory_iface; + +struct adv_watcher +{ + IBluetoothLEAdvertisementWatcher IBluetoothLEAdvertisementWatcher_iface; + LONG ref; +}; + +static inline struct adv_watcher *impl_from_IBluetoothLEAdvertisementWatcher( IBluetoothLEAdvertisementWatcher *iface ) +{ + return CONTAINING_RECORD( iface, struct adv_watcher, IBluetoothLEAdvertisementWatcher_iface ); +} + +static HRESULT WINAPI adv_watcher_QueryInterface( IBluetoothLEAdvertisementWatcher *iface, REFIID iid, void **out ) +{ + struct adv_watcher *impl = impl_from_IBluetoothLEAdvertisementWatcher( iface ); + + TRACE( "(%p, %s, %p)\n", iface, debugstr_guid( iid ), out ); + + if (IsEqualGUID( iid, &IID_IUnknown ) || + IsEqualGUID( iid, &IID_IInspectable ) || + IsEqualGUID( iid, &IID_IAgileObject ) || + IsEqualGUID( iid, &IID_IBluetoothLEAdvertisementWatcher )) + { + IBluetoothLEAdvertisementWatcher_AddRef(( *out = &impl->IBluetoothLEAdvertisementWatcher_iface )); + return S_OK; + } + + *out = NULL; + FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) ); + return E_NOINTERFACE; +} + +static ULONG WINAPI adv_watcher_AddRef( IBluetoothLEAdvertisementWatcher *iface ) +{ + struct adv_watcher *impl = impl_from_IBluetoothLEAdvertisementWatcher( iface ); + TRACE( "(%p)\n", iface ); + return InterlockedIncrement( &impl->ref ); +} + +static ULONG WINAPI adv_watcher_Release( IBluetoothLEAdvertisementWatcher *iface ) +{ + struct adv_watcher *impl = impl_from_IBluetoothLEAdvertisementWatcher( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + TRACE( "(%p)\n", iface ); + return ref; +} + +static HRESULT WINAPI adv_watcher_GetIids( IBluetoothLEAdvertisementWatcher *iface, ULONG *iid_count, IID **iids ) +{ + FIXME( "(%p, %p, %p): stub!\n", iface, iid_count, iids ); + return E_NOTIMPL; +} + +static HRESULT WINAPI adv_watcher_GetRuntimeClassName( IBluetoothLEAdvertisementWatcher *iface, HSTRING *class_name ) +{ + FIXME( "(%p, %p): stub!\n", iface, class_name ); + return E_NOTIMPL; +} + +static HRESULT WINAPI adv_watcher_GetTrustLevel( IBluetoothLEAdvertisementWatcher *iface, TrustLevel *level ) +{ + FIXME( "(%p, %p): stub!\n", iface, level ); + return E_NOTIMPL; +} + +static HRESULT WINAPI adv_watcher_get_MinSamplingInternal( IBluetoothLEAdvertisementWatcher *iface, TimeSpan *value ) +{ + FIXME( "(%p, %p): stub!\n", iface, value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI adv_watcher_get_MaxSamplingInternal( IBluetoothLEAdvertisementWatcher *iface, TimeSpan *value ) +{ + FIXME( "(%p, %p): stub!\n", iface, value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI adv_watcher_get_MinOutOfRangeTimeout( IBluetoothLEAdvertisementWatcher *iface, TimeSpan *value ) +{ + FIXME( "(%p, %p): stub!\n", iface, value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI adv_watcher_get_MaxOutOfRangeTimeout( IBluetoothLEAdvertisementWatcher *iface, TimeSpan *value ) +{ + FIXME( "(%p, %p): stub!\n", iface, value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI adv_watcher_get_Status( IBluetoothLEAdvertisementWatcher *iface, BluetoothLEAdvertisementWatcherStatus *status ) +{ + FIXME( "(%p, %p): stub!\n", iface, status ); + return E_NOTIMPL; +} + +static HRESULT WINAPI adv_watcher_get_ScanningMode( IBluetoothLEAdvertisementWatcher *iface, BluetoothLEScanningMode *value ) +{ + FIXME( "(%p, %p): stub!\n", iface, value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI adv_watcher_put_ScanningMode( IBluetoothLEAdvertisementWatcher *iface, BluetoothLEScanningMode value ) +{ + FIXME( "(%p, %d): stub!\n", iface, value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI adv_watcher_get_SignalStrengthFilter( IBluetoothLEAdvertisementWatcher *iface, IBluetoothSignalStrengthFilter **filter ) +{ + FIXME( "(%p, %p): stub!\n", iface, filter ); + return E_NOTIMPL; +} + +static HRESULT WINAPI adv_watcher_put_SignalStrengthFilter( IBluetoothLEAdvertisementWatcher *iface, IBluetoothSignalStrengthFilter *filter ) +{ + FIXME( "(%p, %p): stub!\n", iface, filter ); + return E_NOTIMPL; +} + +static HRESULT WINAPI adv_watcher_get_AdvertisementFilter( IBluetoothLEAdvertisementWatcher *iface, IBluetoothLEAdvertisementFilter **filter ) +{ + FIXME( "(%p, %p): stub!\n", iface, filter ); + return E_NOTIMPL; +} + +static HRESULT WINAPI adv_watcher_put_AdvertisementFilter( IBluetoothLEAdvertisementWatcher *iface, IBluetoothLEAdvertisementFilter *filter ) +{ + FIXME( "(%p, %p): stub!\n", iface, filter ); + return E_NOTIMPL; +} + +static HRESULT WINAPI adv_watcher_Start( IBluetoothLEAdvertisementWatcher *iface ) +{ + FIXME( "(%p): stub!\n", iface ); + return E_NOTIMPL; +} + +static HRESULT WINAPI adv_watcher_Stop( IBluetoothLEAdvertisementWatcher *iface ) +{ + FIXME( "(%p): stub!\n", iface ); + return E_NOTIMPL; +} + +static HRESULT WINAPI adv_watcher_add_Received( IBluetoothLEAdvertisementWatcher *iface, + ITypedEventHandler_BluetoothLEAdvertisementWatcher_BluetoothLEAdvertisementReceivedEventArgs *handler, + EventRegistrationToken *token ) +{ + FIXME( "(%p, %p, %p): stub!\n", iface, handler, token ); + return E_NOTIMPL; +} + +static HRESULT WINAPI adv_watcher_remove_Received( IBluetoothLEAdvertisementWatcher *iface, EventRegistrationToken token ) +{ + FIXME( "(%p, %I64x): stub!\n", iface, token.value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI adv_watcher_add_Stopped( IBluetoothLEAdvertisementWatcher *iface, + ITypedEventHandler_BluetoothLEAdvertisementWatcher_BluetoothLEAdvertisementWatcherStoppedEventArgs *handler, + EventRegistrationToken *token ) +{ + FIXME( "(%p, %p, %p): stub!\n", iface, handler, token ); + return E_NOTIMPL; +} + + +static HRESULT WINAPI adv_watcher_remove_Stopped( IBluetoothLEAdvertisementWatcher *iface, EventRegistrationToken token ) +{ + FIXME( "(%p, %I64x): stub!\n", iface, token.value ); + return E_NOTIMPL; +} + +static const IBluetoothLEAdvertisementWatcherVtbl adv_watcher_vtbl = +{ + /* IUnknown */ + adv_watcher_QueryInterface, + adv_watcher_AddRef, + adv_watcher_Release, + /* IInspectable */ + adv_watcher_GetIids, + adv_watcher_GetRuntimeClassName, + adv_watcher_GetTrustLevel, + /* IBluetoothLEAdvertisementWatcher */ + adv_watcher_get_MinSamplingInternal, + adv_watcher_get_MaxSamplingInternal, + adv_watcher_get_MinOutOfRangeTimeout, + adv_watcher_get_MaxOutOfRangeTimeout, + adv_watcher_get_Status, + adv_watcher_get_ScanningMode, + adv_watcher_put_ScanningMode, + adv_watcher_get_SignalStrengthFilter, + adv_watcher_put_SignalStrengthFilter, + adv_watcher_get_AdvertisementFilter, + adv_watcher_put_AdvertisementFilter, + adv_watcher_Start, + adv_watcher_Stop, + adv_watcher_add_Received, + adv_watcher_remove_Received, + adv_watcher_add_Stopped, + adv_watcher_remove_Stopped +}; + +static HRESULT adv_watcher_create( IBluetoothLEAdvertisementWatcher **watcher ) +{ + struct adv_watcher *impl; + + if (!(impl = calloc( 1, sizeof( *impl ) ))) return E_OUTOFMEMORY; + impl->IBluetoothLEAdvertisementWatcher_iface.lpVtbl = &adv_watcher_vtbl; + impl->ref = 1; + *watcher = &impl->IBluetoothLEAdvertisementWatcher_iface; + return S_OK; +} diff --git a/dlls/windows.devices.bluetooth/classes.idl b/dlls/windows.devices.bluetooth/classes.idl index ae2b58ffa2d..a2874370e52 100644 --- a/dlls/windows.devices.bluetooth/classes.idl +++ b/dlls/windows.devices.bluetooth/classes.idl @@ -36,6 +36,7 @@ import "windows.networking.sockets.idl"; import "windows.storage.streams.idl";
#define DO_NO_IMPORTS +#include "windows.devices.bluetooth.advertisement.idl" #include "windows.devices.bluetooth.genericattributeprofile.idl" #include "windows.devices.bluetooth.rfcomm.idl" #include "windows.devices.bluetooth.idl" diff --git a/dlls/windows.devices.bluetooth/main.c b/dlls/windows.devices.bluetooth/main.c index 83fd2100f06..4bfbcd17c8e 100644 --- a/dlls/windows.devices.bluetooth/main.c +++ b/dlls/windows.devices.bluetooth/main.c @@ -44,6 +44,8 @@ HRESULT WINAPI DllGetActivationFactory( HSTRING classid, IActivationFactory **fa IActivationFactory_QueryInterface( bluetoothdevice_statics_factory, &IID_IActivationFactory, (void **)factory ); if (!wcscmp( buffer, RuntimeClass_Windows_Devices_Bluetooth_BluetoothLEDevice )) IActivationFactory_QueryInterface( bluetoothledevice_statics_factory, &IID_IActivationFactory, (void **)factory ); + if (!wcscmp( buffer, RuntimeClass_Windows_Devices_Bluetooth_Advertisement_BluetoothLEAdvertisementWatcher)) + IActivationFactory_QueryInterface( advertisement_watcher_factory, &IID_IActivationFactory, (void **)factory );
if (*factory) return S_OK; return CLASS_E_CLASSNOTAVAILABLE; diff --git a/dlls/windows.devices.bluetooth/private.h b/dlls/windows.devices.bluetooth/private.h index c72488c2edc..66dd1d34131 100644 --- a/dlls/windows.devices.bluetooth/private.h +++ b/dlls/windows.devices.bluetooth/private.h @@ -38,10 +38,13 @@ #define WIDL_using_Windows_Devices_Bluetooth #include "windows.devices.bluetooth.rfcomm.h" #include "windows.devices.bluetooth.h" +#define WIDL_using_Windows_Devices_Bluetooth_Advertisement +#include "windows.devices.bluetooth.advertisement.h"
extern IActivationFactory *bluetoothadapter_factory; extern IActivationFactory *bluetoothdevice_statics_factory; extern IActivationFactory *bluetoothledevice_statics_factory; +extern IActivationFactory *advertisement_watcher_factory;
#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.devices.bluetooth/tests/bluetooth.c b/dlls/windows.devices.bluetooth/tests/bluetooth.c index 37f76596659..cebf7596a58 100644 --- a/dlls/windows.devices.bluetooth/tests/bluetooth.c +++ b/dlls/windows.devices.bluetooth/tests/bluetooth.c @@ -650,10 +650,10 @@ static void test_BluetoothLEAdvertisementWatcher( void ) WindowsCreateString( class_name, wcslen( class_name ), &str ); hr = RoActivateInstance( str, &inspectable ); WindowsDeleteString( str ); - todo_wine ok( hr == S_OK || broken( hr == REGDB_E_CLASSNOTREG ), "got hr %#lx.\n", hr ); + ok( hr == S_OK || broken( hr == REGDB_E_CLASSNOTREG ), "got hr %#lx.\n", hr ); if (hr == REGDB_E_CLASSNOTREG || hr == CLASS_E_CLASSNOTAVAILABLE) { - todo_wine win_skip( "%s runtimeclass not registered, skipping tests.\n", wine_dbgstr_w( class_name ) ); + win_skip( "%s runtimeclass not registered, skipping tests.\n", wine_dbgstr_w( class_name ) ); return; }