This MR adds a basic implementation for the BluetoothAdapter interface in Windows.Devices.Bluetooth, including winebth.sys support for getting properties associated with the radio's Low Energy capabilities.
-- v4: windows.devices.bluetooth: Implement BluetoothAdapter::get_BluetoothAddress. windows.devices.bluetooth: Implement IBluetoothAdapterStatics::GetDefaultAsync(). windows.devices.bluetooth/tests: Add tests for IBluetoothAdapter.
From: Vibhav Pant vibhavp@gmail.com
--- .../tests/bluetooth.c | 131 ++++++++++++++++-- 1 file changed, 123 insertions(+), 8 deletions(-)
diff --git a/dlls/windows.devices.bluetooth/tests/bluetooth.c b/dlls/windows.devices.bluetooth/tests/bluetooth.c index 5b78e1e176d..0db9ca0ad25 100644 --- a/dlls/windows.devices.bluetooth/tests/bluetooth.c +++ b/dlls/windows.devices.bluetooth/tests/bluetooth.c @@ -201,21 +201,94 @@ static void check_bluetoothledevice_async( int line, IAsyncOperation_BluetoothLE } }
+static void await_bluetoothadapter( int line, IAsyncOperation_BluetoothAdapter *async ) +{ + IAsyncOperationCompletedHandler_IInspectable *handler; + HANDLE event; + HRESULT hr; + DWORD ret; + + event = CreateEventW( NULL, FALSE, FALSE, NULL ); + ok_(__FILE__, line)( !!event, "CreateEventW failed, error %lu\n", GetLastError() ); + + handler = inspectable_async_handler_create( event, &IID_IAsyncOperationCompletedHandler_BluetoothAdapter ); + ok_( __FILE__, line )( !!handler, "inspectable_async_handler_create failed\n" ); + hr = IAsyncOperation_BluetoothAdapter_put_Completed( async, (IAsyncOperationCompletedHandler_BluetoothAdapter *)handler ); + ok_(__FILE__, line)( hr == S_OK, "put_Completed returned %#lx\n", hr ); + IAsyncOperationCompletedHandler_IInspectable_Release( handler ); + + ret = WaitForSingleObject( event, 5000 ); + ok_(__FILE__, line)( !ret, "WaitForSingleObject returned %#lx\n", ret ); + ret = CloseHandle( event ); + ok_(__FILE__, line)( ret, "CloseHandle failed, error %lu\n", GetLastError() ); +} + +static void check_bluetoothadapter_async( int line, IAsyncOperation_BluetoothAdapter *async, + UINT32 expect_id, AsyncStatus expect_status, + HRESULT expect_hr, IBluetoothAdapter **result ) +{ + AsyncStatus async_status; + IAsyncInfo *async_info; + HRESULT hr, async_hr; + UINT32 async_id; + + hr = IAsyncOperation_BluetoothAdapter_QueryInterface( async, &IID_IAsyncInfo, (void **)&async_info ); + ok_(__FILE__, line)( hr == S_OK, "QueryInterface returned %#lx\n", hr ); + + async_id = 0xdeadbeef; + hr = IAsyncInfo_get_Id( async_info, &async_id ); + if (expect_status < 4) ok_(__FILE__, line)( hr == S_OK, "get_Id returned %#lx\n", hr ); + else ok_(__FILE__, line)( hr == E_ILLEGAL_METHOD_CALL, "get_Id returned %#lx\n", hr ); + ok_(__FILE__, line)( async_id == expect_id, "got id %u\n", async_id ); + + async_status = 0xdeadbeef; + hr = IAsyncInfo_get_Status( async_info, &async_status ); + if (expect_status < 4) ok_(__FILE__, line)( hr == S_OK, "get_Status returned %#lx\n", hr ); + else ok_(__FILE__, line)( hr == E_ILLEGAL_METHOD_CALL, "get_Status returned %#lx\n", hr ); + ok_(__FILE__, line)( async_status == expect_status, "got status %u\n", async_status ); + + async_hr = 0xdeadbeef; + hr = IAsyncInfo_get_ErrorCode( async_info, &async_hr ); + if (expect_status < 4) ok_(__FILE__, line)( hr == S_OK, "get_ErrorCode returned %#lx\n", hr ); + else ok_(__FILE__, line)( hr == E_ILLEGAL_METHOD_CALL, "get_ErrorCode returned %#lx\n", hr ); + if (expect_status < 4) todo_wine_if( FAILED(expect_hr)) + ok_(__FILE__, line)( async_hr == expect_hr, "got error %#lx\n", async_hr ); + else ok_(__FILE__, line)( async_hr == E_ILLEGAL_METHOD_CALL, "got error %#lx\n", async_hr ); + + IAsyncInfo_Release( async_info ); + + hr = IAsyncOperation_BluetoothAdapter_GetResults( async, result ); + switch (expect_status) + { + case Completed: + case Error: + todo_wine_if( FAILED(expect_hr)) + ok_(__FILE__, line)( hr == expect_hr, "GetResults returned %#lx\n", hr ); + break; + case Canceled: + case Started: + default: + ok_(__FILE__, line)( hr == E_ILLEGAL_METHOD_CALL, "GetResults returned %#lx\n", hr ); + break; + } +} + static void test_BluetoothAdapterStatics(void) { static const WCHAR *default_res = L"System.Devices.InterfaceClassGuid:="{92383B0E-F90E-4AC9-8D44-8C2D0D0EBDA2}" " L"AND System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True"; static const WCHAR *bluetoothadapter_statics_name = L"Windows.Devices.Bluetooth.BluetoothAdapter"; + IAsyncOperation_BluetoothAdapter *adapter_async = NULL; IBluetoothAdapterStatics *bluetoothadapter_statics; + IBluetoothAdapter *adapter = NULL; IActivationFactory *factory; HSTRING str, default_str; + boolean value = FALSE; + UINT64 address = 0; HRESULT hr; INT32 res; - LONG ref; - - hr = WindowsCreateString( bluetoothadapter_statics_name, wcslen( bluetoothadapter_statics_name ), &str ); - ok( hr == S_OK, "got hr %#lx.\n", hr );
+ WindowsCreateString( bluetoothadapter_statics_name, wcslen( bluetoothadapter_statics_name ), &str ); hr = RoGetActivationFactory( str, &IID_IActivationFactory, (void **)&factory ); WindowsDeleteString( str ); ok( hr == S_OK || broken( hr == REGDB_E_CLASSNOTREG ), "got hr %#lx.\n", hr ); @@ -244,10 +317,52 @@ static void test_BluetoothAdapterStatics(void)
WindowsDeleteString( str ); WindowsDeleteString( default_str ); - ref = IBluetoothAdapterStatics_Release( bluetoothadapter_statics ); - ok( ref == 2, "got ref %ld.\n", ref ); - ref = IActivationFactory_Release( factory ); - ok( ref == 1, "got ref %ld.\n", ref ); + + hr = IBluetoothAdapterStatics_GetDefaultAsync( bluetoothadapter_statics, &adapter_async ); + todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); + if (FAILED( hr )) + { + skip( "GetDefaultAsync failed.\n" ); + goto done; + } + + await_bluetoothadapter( __LINE__, adapter_async ); + check_bluetoothadapter_async( __LINE__, adapter_async, 1, Completed, S_OK, &adapter ); + IAsyncOperation_BluetoothAdapter_Release( adapter_async ); + if (!adapter) + { + skip( "No Bluetooth adapter found.\n" ); + goto done; + } + + str = NULL; + hr = IBluetoothAdapter_get_DeviceId( adapter, &str ); + todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); + todo_wine ok( !WindowsIsStringEmpty( str ), "got str %s.\n", debugstr_hstring( str ) ); + WindowsDeleteString( str ); + + hr = IBluetoothAdapter_get_BluetoothAddress( adapter, &address ); + todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); + + hr = IBluetoothAdapter_get_IsLowEnergySupported( adapter, &value ); + todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); + + hr = IBluetoothAdapter_get_IsClassicSupported( adapter, &value ); + todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); + + hr = IBluetoothAdapter_get_IsPeripheralRoleSupported( adapter, &value ); + todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); + + hr = IBluetoothAdapter_get_IsCentralRoleSupported( adapter, &value ); + todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); + + hr = IBluetoothAdapter_get_IsAdvertisementOffloadSupported( adapter, &value ); + todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); + + IBluetoothAdapter_Release( adapter ); +done: + IBluetoothAdapterStatics_Release( bluetoothadapter_statics ); + IActivationFactory_Release( factory ); }
static void test_BluetoothDeviceStatics( void )
From: Vibhav Pant vibhavp@gmail.com
Add an initial implementation of IBluetoothAdapter, returned by GetDefaultAsync(). --- dlls/windows.devices.bluetooth/Makefile.in | 4 +- dlls/windows.devices.bluetooth/async.c | 659 ++++++++++++++++++ .../async_private.idl | 46 ++ .../bluetoothadapter.c | 226 +++++- dlls/windows.devices.bluetooth/private.h | 10 + .../tests/bluetooth.c | 6 +- 6 files changed, 936 insertions(+), 15 deletions(-) create mode 100644 dlls/windows.devices.bluetooth/async.c create mode 100644 dlls/windows.devices.bluetooth/async_private.idl
diff --git a/dlls/windows.devices.bluetooth/Makefile.in b/dlls/windows.devices.bluetooth/Makefile.in index 89f3fc78abc..e084548f7e6 100644 --- a/dlls/windows.devices.bluetooth/Makefile.in +++ b/dlls/windows.devices.bluetooth/Makefile.in @@ -1,7 +1,9 @@ MODULE = windows.devices.bluetooth.dll -IMPORTS = combase +IMPORTS = combase setupapi
SOURCES = \ + async.c \ + async_private.idl \ bluetoothadapter.c \ bluetoothdevice.c \ classes.idl \ diff --git a/dlls/windows.devices.bluetooth/async.c b/dlls/windows.devices.bluetooth/async.c new file mode 100644 index 00000000000..0c4f6d647d2 --- /dev/null +++ b/dlls/windows.devices.bluetooth/async.c @@ -0,0 +1,659 @@ +/* WinRT IAsync* implementation + * + * Copyright 2022 Bernhard Kölbl for CodeWeavers + * Copyright 2022 Rémi Bernon for CodeWeavers + * + * 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 WIDL_using_Wine_Internal +#include "private.h" +#include "initguid.h" +#include "async_private.h" + +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(combase); + +#define Closed 4 +#define HANDLER_NOT_SET ((void *)~(ULONG_PTR)0) + +struct async_info +{ + IAsyncInfoImpl IAsyncInfoImpl_iface; + IAsyncInfo IAsyncInfo_iface; + IInspectable *IInspectable_outer; + LONG ref; + + async_operation_callback callback; + TP_WORK *async_run_work; + IUnknown *invoker; + IUnknown *param; + + CRITICAL_SECTION cs; + IAsyncOperationCompletedHandlerImpl *handler; + PROPVARIANT result; + AsyncStatus status; + HRESULT hr; +}; + +static inline struct async_info *impl_from_IAsyncInfoImpl( IAsyncInfoImpl *iface ) +{ + return CONTAINING_RECORD( iface, struct async_info, IAsyncInfoImpl_iface ); +} + +static HRESULT WINAPI async_impl_QueryInterface( IAsyncInfoImpl *iface, REFIID iid, void **out ) +{ + struct async_info *impl = impl_from_IAsyncInfoImpl( 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, &IID_IAsyncInfoImpl )) + { + IInspectable_AddRef( (*out = &impl->IAsyncInfoImpl_iface) ); + return S_OK; + } + + if (IsEqualGUID( iid, &IID_IAsyncInfo )) + { + IInspectable_AddRef( (*out = &impl->IAsyncInfo_iface) ); + return S_OK; + } + + FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) ); + *out = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI async_impl_AddRef( IAsyncInfoImpl *iface ) +{ + struct async_info *impl = impl_from_IAsyncInfoImpl( iface ); + ULONG ref = InterlockedIncrement( &impl->ref ); + TRACE( "iface %p, ref %lu.\n", iface, ref ); + return ref; +} + +static ULONG WINAPI async_impl_Release( IAsyncInfoImpl *iface ) +{ + struct async_info *impl = impl_from_IAsyncInfoImpl( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + TRACE( "iface %p, ref %lu.\n", iface, ref ); + + if (!ref) + { + if (impl->handler && impl->handler != HANDLER_NOT_SET) IAsyncOperationCompletedHandlerImpl_Release( impl->handler ); + IAsyncInfo_Close( &impl->IAsyncInfo_iface ); + if (impl->param) IUnknown_Release( impl->param ); + if (impl->invoker) IUnknown_Release( impl->invoker ); + PropVariantClear( &impl->result ); + impl->cs.DebugInfo->Spare[0] = 0; + DeleteCriticalSection( &impl->cs ); + free( impl ); + } + + return ref; +} + +static HRESULT WINAPI async_impl_put_Completed( IAsyncInfoImpl *iface, IAsyncOperationCompletedHandlerImpl *handler ) +{ + struct async_info *impl = impl_from_IAsyncInfoImpl( iface ); + HRESULT hr = S_OK; + + TRACE( "iface %p, handler %p.\n", iface, handler ); + + EnterCriticalSection( &impl->cs ); + if (impl->status == Closed) hr = E_ILLEGAL_METHOD_CALL; + else if (impl->handler != HANDLER_NOT_SET) hr = E_ILLEGAL_DELEGATE_ASSIGNMENT; + else if ((impl->handler = handler)) + { + IAsyncOperationCompletedHandlerImpl_AddRef( impl->handler ); + + if (impl->status > Started) + { + IInspectable *operation = impl->IInspectable_outer; + AsyncStatus status = impl->status; + impl->handler = NULL; /* Prevent concurrent invoke. */ + LeaveCriticalSection( &impl->cs ); + + IAsyncOperationCompletedHandlerImpl_Invoke( handler, operation, status ); + IAsyncOperationCompletedHandlerImpl_Release( handler ); + + return S_OK; + } + } + LeaveCriticalSection( &impl->cs ); + + return hr; +} + +static HRESULT WINAPI async_impl_get_Completed( IAsyncInfoImpl *iface, IAsyncOperationCompletedHandlerImpl **handler ) +{ + struct async_info *impl = impl_from_IAsyncInfoImpl( iface ); + HRESULT hr = S_OK; + + TRACE( "iface %p, handler %p.\n", iface, handler ); + + EnterCriticalSection( &impl->cs ); + if (impl->status == Closed) hr = E_ILLEGAL_METHOD_CALL; + if (impl->handler == NULL || impl->handler == HANDLER_NOT_SET) *handler = NULL; + else IAsyncOperationCompletedHandlerImpl_AddRef( (*handler = impl->handler) ); + LeaveCriticalSection( &impl->cs ); + + return hr; +} + +static HRESULT WINAPI async_impl_get_Result( IAsyncInfoImpl *iface, PROPVARIANT *result ) +{ + struct async_info *impl = impl_from_IAsyncInfoImpl( iface ); + HRESULT hr = E_ILLEGAL_METHOD_CALL; + + TRACE( "iface %p, result %p.\n", iface, result ); + + EnterCriticalSection( &impl->cs ); + if (impl->status == Completed || impl->status == Error) + { + PropVariantCopy( result, &impl->result ); + hr = impl->hr; + } + LeaveCriticalSection( &impl->cs ); + + return hr; +} + +static HRESULT WINAPI async_impl_Start( IAsyncInfoImpl *iface ) +{ + struct async_info *impl = impl_from_IAsyncInfoImpl( iface ); + + TRACE( "iface %p.\n", iface ); + + /* keep the async alive in the callback */ + IInspectable_AddRef( impl->IInspectable_outer ); + SubmitThreadpoolWork( impl->async_run_work ); + + return S_OK; +} + +static const struct IAsyncInfoImplVtbl async_impl_vtbl = +{ + /* IUnknown methods */ + async_impl_QueryInterface, + async_impl_AddRef, + async_impl_Release, + /* IAsyncInfoImpl */ + async_impl_put_Completed, + async_impl_get_Completed, + async_impl_get_Result, + async_impl_Start, +}; + +DEFINE_IINSPECTABLE_OUTER( async_info, IAsyncInfo, struct async_info, IInspectable_outer ) + +static HRESULT WINAPI async_info_get_Id( IAsyncInfo *iface, UINT32 *id ) +{ + struct async_info *impl = impl_from_IAsyncInfo( iface ); + HRESULT hr = S_OK; + + TRACE( "iface %p, id %p.\n", iface, id ); + + EnterCriticalSection( &impl->cs ); + if (impl->status == Closed) hr = E_ILLEGAL_METHOD_CALL; + *id = 1; + LeaveCriticalSection( &impl->cs ); + + return hr; +} + +static HRESULT WINAPI async_info_get_Status( IAsyncInfo *iface, AsyncStatus *status ) +{ + struct async_info *impl = impl_from_IAsyncInfo( iface ); + HRESULT hr = S_OK; + + TRACE( "iface %p, status %p.\n", iface, status ); + + EnterCriticalSection( &impl->cs ); + if (impl->status == Closed) hr = E_ILLEGAL_METHOD_CALL; + *status = impl->status; + LeaveCriticalSection( &impl->cs ); + + return hr; +} + +static HRESULT WINAPI async_info_get_ErrorCode( IAsyncInfo *iface, HRESULT *error_code ) +{ + struct async_info *impl = impl_from_IAsyncInfo( iface ); + HRESULT hr = S_OK; + + TRACE( "iface %p, error_code %p.\n", iface, error_code ); + + EnterCriticalSection( &impl->cs ); + if (impl->status == Closed) *error_code = hr = E_ILLEGAL_METHOD_CALL; + else *error_code = impl->hr; + LeaveCriticalSection( &impl->cs ); + + return hr; +} + +static HRESULT WINAPI async_info_Cancel( IAsyncInfo *iface ) +{ + struct async_info *impl = impl_from_IAsyncInfo( iface ); + HRESULT hr = S_OK; + + TRACE( "iface %p.\n", iface ); + + EnterCriticalSection( &impl->cs ); + if (impl->status == Closed) hr = E_ILLEGAL_METHOD_CALL; + else if (impl->status == Started) impl->status = Canceled; + LeaveCriticalSection( &impl->cs ); + + return hr; +} + +static HRESULT WINAPI async_info_Close( IAsyncInfo *iface ) +{ + struct async_info *impl = impl_from_IAsyncInfo( iface ); + HRESULT hr = S_OK; + + TRACE( "iface %p.\n", iface ); + + EnterCriticalSection( &impl->cs ); + if (impl->status == Started) + hr = E_ILLEGAL_STATE_CHANGE; + else if (impl->status != Closed) + { + CloseThreadpoolWork( impl->async_run_work ); + impl->async_run_work = NULL; + impl->status = Closed; + } + LeaveCriticalSection( &impl->cs ); + + return hr; +} + +static const struct IAsyncInfoVtbl async_info_vtbl = +{ + /* IUnknown methods */ + async_info_QueryInterface, + async_info_AddRef, + async_info_Release, + /* IInspectable methods */ + async_info_GetIids, + async_info_GetRuntimeClassName, + async_info_GetTrustLevel, + /* IAsyncInfo */ + async_info_get_Id, + async_info_get_Status, + async_info_get_ErrorCode, + async_info_Cancel, + async_info_Close, +}; + +static void CALLBACK async_info_callback( TP_CALLBACK_INSTANCE *instance, void *iface, TP_WORK *work ) +{ + struct async_info *impl = impl_from_IAsyncInfoImpl( iface ); + IInspectable *operation = impl->IInspectable_outer; + PROPVARIANT result = {0}; + HRESULT hr; + + hr = impl->callback( impl->invoker, impl->param, &result ); + + EnterCriticalSection( &impl->cs ); + if (impl->status != Closed) impl->status = FAILED(hr) ? Error : Completed; + PropVariantCopy( &impl->result, &result ); + impl->hr = hr; + + if (impl->handler != NULL && impl->handler != HANDLER_NOT_SET) + { + IAsyncOperationCompletedHandlerImpl *handler = impl->handler; + AsyncStatus status = impl->status; + impl->handler = NULL; /* Prevent concurrent invoke. */ + LeaveCriticalSection( &impl->cs ); + + IAsyncOperationCompletedHandlerImpl_Invoke( handler, operation, status ); + IAsyncOperationCompletedHandlerImpl_Release( handler ); + } + else LeaveCriticalSection( &impl->cs ); + + /* release refcount acquired in Start */ + IInspectable_Release( operation ); + + PropVariantClear( &result ); +} + +static HRESULT async_info_create( IUnknown *invoker, IUnknown *param, async_operation_callback callback, + IInspectable *outer, IAsyncInfoImpl **out ) +{ + struct async_info *impl; + HRESULT hr; + + if (!(impl = calloc( 1, sizeof(struct async_info) ))) return E_OUTOFMEMORY; + impl->IAsyncInfoImpl_iface.lpVtbl = &async_impl_vtbl; + impl->IAsyncInfo_iface.lpVtbl = &async_info_vtbl; + impl->IInspectable_outer = outer; + impl->ref = 1; + + impl->callback = callback; + impl->handler = HANDLER_NOT_SET; + impl->status = Started; + if (!(impl->async_run_work = CreateThreadpoolWork( async_info_callback, &impl->IAsyncInfoImpl_iface, NULL ))) + { + hr = HRESULT_FROM_WIN32( GetLastError() ); + free( impl ); + return hr; + } + + if ((impl->invoker = invoker)) IUnknown_AddRef( impl->invoker ); + if ((impl->param = param)) IUnknown_AddRef( impl->param ); + + InitializeCriticalSectionEx( &impl->cs, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO ); + impl->cs.DebugInfo->Spare[0] = (DWORD_PTR)( __FILE__ ": async_info.cs" ); + + *out = &impl->IAsyncInfoImpl_iface; + return S_OK; +} + +struct async_inspectable +{ + IAsyncOperation_IInspectable IAsyncOperation_IInspectable_iface; + IAsyncInfoImpl *IAsyncInfoImpl_inner; + LONG ref; + const GUID *iid; +}; + +static inline struct async_inspectable *impl_from_IAsyncOperation_IInspectable( IAsyncOperation_IInspectable *iface ) +{ + return CONTAINING_RECORD( iface, struct async_inspectable, IAsyncOperation_IInspectable_iface ); +} + +static HRESULT WINAPI async_inspectable_QueryInterface( IAsyncOperation_IInspectable *iface, REFIID iid, void **out ) +{ + struct async_inspectable *impl = impl_from_IAsyncOperation_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->IAsyncOperation_IInspectable_iface) ); + return S_OK; + } + + return IAsyncInfoImpl_QueryInterface( impl->IAsyncInfoImpl_inner, iid, out ); +} + +static ULONG WINAPI async_inspectable_AddRef( IAsyncOperation_IInspectable *iface ) +{ + struct async_inspectable *impl = impl_from_IAsyncOperation_IInspectable( iface ); + ULONG ref = InterlockedIncrement( &impl->ref ); + TRACE( "iface %p, ref %lu.\n", iface, ref ); + return ref; +} + +static ULONG WINAPI async_inspectable_Release( IAsyncOperation_IInspectable *iface ) +{ + struct async_inspectable *impl = impl_from_IAsyncOperation_IInspectable( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + TRACE( "iface %p, ref %lu.\n", iface, ref ); + + if (!ref) + { + /* guard against re-entry if inner releases an outer iface */ + InterlockedIncrement( &impl->ref ); + IAsyncInfoImpl_Release( impl->IAsyncInfoImpl_inner ); + free( impl ); + } + + return ref; +} + +static HRESULT WINAPI async_inspectable_GetIids( IAsyncOperation_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 async_inspectable_GetRuntimeClassName( IAsyncOperation_IInspectable *iface, HSTRING *class_name ) +{ + return WindowsCreateString( L"Windows.Foundation.IAsyncOperation`1<IInspectable>", + ARRAY_SIZE(L"Windows.Foundation.IAsyncOperation`1<IInspectable>"), + class_name ); +} + +static HRESULT WINAPI async_inspectable_GetTrustLevel( IAsyncOperation_IInspectable *iface, TrustLevel *trust_level ) +{ + FIXME( "iface %p, trust_level %p stub!\n", iface, trust_level ); + return E_NOTIMPL; +} + +static HRESULT WINAPI async_inspectable_put_Completed( IAsyncOperation_IInspectable *iface, IAsyncOperationCompletedHandler_IInspectable *bool_handler ) +{ + IAsyncOperationCompletedHandlerImpl *handler = (IAsyncOperationCompletedHandlerImpl *)bool_handler; + struct async_inspectable *impl = impl_from_IAsyncOperation_IInspectable( iface ); + TRACE( "iface %p, handler %p.\n", iface, handler ); + return IAsyncInfoImpl_put_Completed( impl->IAsyncInfoImpl_inner, handler ); +} + +static HRESULT WINAPI async_inspectable_get_Completed( IAsyncOperation_IInspectable *iface, IAsyncOperationCompletedHandler_IInspectable **bool_handler ) +{ + IAsyncOperationCompletedHandlerImpl **handler = (IAsyncOperationCompletedHandlerImpl **)bool_handler; + struct async_inspectable *impl = impl_from_IAsyncOperation_IInspectable( iface ); + TRACE( "iface %p, handler %p.\n", iface, handler ); + return IAsyncInfoImpl_get_Completed( impl->IAsyncInfoImpl_inner, handler ); +} + +static HRESULT WINAPI async_inspectable_GetResults( IAsyncOperation_IInspectable *iface, IInspectable **results ) +{ + struct async_inspectable *impl = impl_from_IAsyncOperation_IInspectable( iface ); + PROPVARIANT result = {.vt = VT_UNKNOWN}; + HRESULT hr; + + TRACE( "iface %p, results %p.\n", iface, results ); + + if (SUCCEEDED(hr = IAsyncInfoImpl_get_Result( impl->IAsyncInfoImpl_inner, &result ))) + { + if ((*results = (IInspectable *)result.punkVal)) IInspectable_AddRef( *results ); + PropVariantClear( &result ); + } + + return hr; +} + +static const struct IAsyncOperation_IInspectableVtbl async_inspectable_vtbl = +{ + /* IUnknown methods */ + async_inspectable_QueryInterface, + async_inspectable_AddRef, + async_inspectable_Release, + /* IInspectable methods */ + async_inspectable_GetIids, + async_inspectable_GetRuntimeClassName, + async_inspectable_GetTrustLevel, + /* IAsyncOperation<IInspectable> */ + async_inspectable_put_Completed, + async_inspectable_get_Completed, + async_inspectable_GetResults, +}; + +HRESULT async_operation_inspectable_create( const GUID *iid, IUnknown *invoker, IUnknown *param, async_operation_callback callback, + IAsyncOperation_IInspectable **out ) +{ + struct async_inspectable *impl; + HRESULT hr; + + *out = NULL; + if (!(impl = calloc( 1, sizeof(*impl) ))) return E_OUTOFMEMORY; + impl->IAsyncOperation_IInspectable_iface.lpVtbl = &async_inspectable_vtbl; + impl->ref = 1; + impl->iid = iid; + + if (FAILED(hr = async_info_create( invoker, param, callback, (IInspectable *)&impl->IAsyncOperation_IInspectable_iface, &impl->IAsyncInfoImpl_inner )) || + FAILED(hr = IAsyncInfoImpl_Start( impl->IAsyncInfoImpl_inner ))) + { + if (impl->IAsyncInfoImpl_inner) IAsyncInfoImpl_Release( impl->IAsyncInfoImpl_inner ); + free( impl ); + return hr; + } + + *out = &impl->IAsyncOperation_IInspectable_iface; + TRACE( "created IAsyncOperation_IInspectable %p\n", *out ); + return S_OK; +} + +struct async_action +{ + IAsyncAction IAsyncAction_iface; + IAsyncInfoImpl *IAsyncInfoImpl_inner; + LONG ref; +}; + +static inline struct async_action *impl_from_IAsyncAction( IAsyncAction *iface ) +{ + return CONTAINING_RECORD( iface, struct async_action, IAsyncAction_iface ); +} + +static HRESULT WINAPI async_action_QueryInterface( IAsyncAction *iface, REFIID iid, void **out ) +{ + struct async_action *impl = impl_from_IAsyncAction( 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, &IID_IAsyncAction )) + { + IInspectable_AddRef( (*out = &impl->IAsyncAction_iface) ); + return S_OK; + } + + return IAsyncInfoImpl_QueryInterface( impl->IAsyncInfoImpl_inner, iid, out ); +} + +static ULONG WINAPI async_action_AddRef( IAsyncAction *iface ) +{ + struct async_action *impl = impl_from_IAsyncAction( iface ); + ULONG ref = InterlockedIncrement( &impl->ref ); + TRACE( "iface %p, ref %lu.\n", iface, ref ); + return ref; +} + +static ULONG WINAPI async_action_Release( IAsyncAction *iface ) +{ + struct async_action *impl = impl_from_IAsyncAction( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + TRACE( "iface %p, ref %lu.\n", iface, ref ); + + if (!ref) + { + /* guard against re-entry if inner releases an outer iface */ + InterlockedIncrement( &impl->ref ); + IAsyncInfoImpl_Release( impl->IAsyncInfoImpl_inner ); + free( impl ); + } + + return ref; +} + +static HRESULT WINAPI async_action_GetIids( IAsyncAction *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 async_action_GetRuntimeClassName( IAsyncAction *iface, HSTRING *class_name ) +{ + return WindowsCreateString( L"Windows.Foundation.IAsyncOperation`1<Boolean>", + ARRAY_SIZE(L"Windows.Foundation.IAsyncOperation`1<Boolean>"), + class_name ); +} + +static HRESULT WINAPI async_action_GetTrustLevel( IAsyncAction *iface, TrustLevel *trust_level ) +{ + FIXME( "iface %p, trust_level %p stub!\n", iface, trust_level ); + return E_NOTIMPL; +} + +static HRESULT WINAPI async_action_put_Completed( IAsyncAction *iface, IAsyncActionCompletedHandler *bool_handler ) +{ + IAsyncOperationCompletedHandlerImpl *handler = (IAsyncOperationCompletedHandlerImpl *)bool_handler; + struct async_action *impl = impl_from_IAsyncAction( iface ); + TRACE( "iface %p, handler %p.\n", iface, handler ); + return IAsyncInfoImpl_put_Completed( impl->IAsyncInfoImpl_inner, handler ); +} + +static HRESULT WINAPI async_action_get_Completed( IAsyncAction *iface, IAsyncActionCompletedHandler **bool_handler ) +{ + IAsyncOperationCompletedHandlerImpl **handler = (IAsyncOperationCompletedHandlerImpl **)bool_handler; + struct async_action *impl = impl_from_IAsyncAction( iface ); + TRACE( "iface %p, handler %p.\n", iface, handler ); + return IAsyncInfoImpl_get_Completed( impl->IAsyncInfoImpl_inner, handler ); +} + +static HRESULT WINAPI async_action_GetResults( IAsyncAction *iface ) +{ + struct async_action *impl = impl_from_IAsyncAction( iface ); + PROPVARIANT result; + HRESULT hr; + + TRACE( "iface %p.\n", iface ); + + PropVariantInit( &result ); + hr = IAsyncInfoImpl_get_Result( impl->IAsyncInfoImpl_inner, &result ); + PropVariantClear( &result ); + return hr; +} + +static const struct IAsyncActionVtbl async_action_vtbl = +{ + /* IUnknown methods */ + async_action_QueryInterface, + async_action_AddRef, + async_action_Release, + /* IInspectable methods */ + async_action_GetIids, + async_action_GetRuntimeClassName, + async_action_GetTrustLevel, + /* IAsyncOperation<boolean> */ + async_action_put_Completed, + async_action_get_Completed, + async_action_GetResults, +}; + +HRESULT async_action_create( IUnknown *invoker, async_operation_callback callback, IAsyncAction **out ) +{ + struct async_action *impl; + HRESULT hr; + + *out = NULL; + if (!(impl = calloc( 1, sizeof(*impl) ))) return E_OUTOFMEMORY; + impl->IAsyncAction_iface.lpVtbl = &async_action_vtbl; + impl->ref = 1; + + if (FAILED(hr = async_info_create( invoker, NULL, callback, (IInspectable *)&impl->IAsyncAction_iface, &impl->IAsyncInfoImpl_inner )) || + FAILED(hr = IAsyncInfoImpl_Start( impl->IAsyncInfoImpl_inner ))) + { + if (impl->IAsyncInfoImpl_inner) IAsyncInfoImpl_Release( impl->IAsyncInfoImpl_inner ); + free( impl ); + return hr; + } + + *out = &impl->IAsyncAction_iface; + TRACE( "created IAsyncAction %p\n", *out ); + return S_OK; +} diff --git a/dlls/windows.devices.bluetooth/async_private.idl b/dlls/windows.devices.bluetooth/async_private.idl new file mode 100644 index 00000000000..10741572601 --- /dev/null +++ b/dlls/windows.devices.bluetooth/async_private.idl @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Rémi Bernon for CodeWeavers + * + * 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 + */ + +#pragma makedep header + +#ifdef __WIDL__ +#pragma winrt ns_prefix +#endif + +import "propidl.idl"; +import "inspectable.idl"; +import "asyncinfo.idl"; +import "windowscontracts.idl"; + +namespace Wine.Internal { + /* type-pruning version of AsyncOperationCompletedHandlerImpl<T> */ + delegate HRESULT AsyncOperationCompletedHandlerImpl([in] IInspectable *async, [in] AsyncStatus status); + + [ + uuid(d81ab70d-82e0-481c-983d-401225d98a2c) + ] + interface IAsyncInfoImpl : IUnknown + { + [propput] HRESULT Completed([in] AsyncOperationCompletedHandlerImpl *handler); + [propget] HRESULT Completed([out, retval] AsyncOperationCompletedHandlerImpl **handler); + [propget] HRESULT Result([out, retval] PROPVARIANT *result); + HRESULT Start(); + } + + typedef HRESULT (*async_operation_callback)( IUnknown *invoker, IUnknown *param, PROPVARIANT *result ); +} diff --git a/dlls/windows.devices.bluetooth/bluetoothadapter.c b/dlls/windows.devices.bluetooth/bluetoothadapter.c index bc8e04a9d33..f2e69e67407 100644 --- a/dlls/windows.devices.bluetooth/bluetoothadapter.c +++ b/dlls/windows.devices.bluetooth/bluetoothadapter.c @@ -1,6 +1,7 @@ /* WinRT Windows.Devices.Bluetooth BluetoothAdapter Implementation * * Copyright (C) 2023 Mohamad Al-Jaf + * Copyright (C) 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 @@ -18,25 +19,26 @@ */
#include "private.h" +#include "setupapi.h" #include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(bluetooth);
-struct bluetoothadapter +struct bluetoothadapter_statics { IActivationFactory IActivationFactory_iface; IBluetoothAdapterStatics IBluetoothAdapterStatics_iface; LONG ref; };
-static inline struct bluetoothadapter *impl_from_IActivationFactory( IActivationFactory *iface ) +static inline struct bluetoothadapter_statics *impl_from_IActivationFactory( IActivationFactory *iface ) { - return CONTAINING_RECORD( iface, struct bluetoothadapter, IActivationFactory_iface ); + return CONTAINING_RECORD( iface, struct bluetoothadapter_statics, IActivationFactory_iface ); }
static HRESULT WINAPI factory_QueryInterface( IActivationFactory *iface, REFIID iid, void **out ) { - struct bluetoothadapter *impl = impl_from_IActivationFactory( iface ); + struct bluetoothadapter_statics *impl = impl_from_IActivationFactory( iface );
TRACE( "iface %p, iid %s, out %p.\n", iface, debugstr_guid( iid ), out );
@@ -64,7 +66,7 @@ static HRESULT WINAPI factory_QueryInterface( IActivationFactory *iface, REFIID
static ULONG WINAPI factory_AddRef( IActivationFactory *iface ) { - struct bluetoothadapter *impl = impl_from_IActivationFactory( iface ); + struct bluetoothadapter_statics *impl = impl_from_IActivationFactory( iface ); ULONG ref = InterlockedIncrement( &impl->ref ); TRACE( "iface %p increasing refcount to %lu.\n", iface, ref ); return ref; @@ -72,7 +74,7 @@ static ULONG WINAPI factory_AddRef( IActivationFactory *iface )
static ULONG WINAPI factory_Release( IActivationFactory *iface ) { - struct bluetoothadapter *impl = impl_from_IActivationFactory( iface ); + struct bluetoothadapter_statics *impl = impl_from_IActivationFactory( iface ); ULONG ref = InterlockedDecrement( &impl->ref ); TRACE( "iface %p decreasing refcount to %lu.\n", iface, ref ); return ref; @@ -115,7 +117,7 @@ static const struct IActivationFactoryVtbl factory_vtbl = factory_ActivateInstance, };
-DEFINE_IINSPECTABLE( bluetoothadapter_statics, IBluetoothAdapterStatics, struct bluetoothadapter, IActivationFactory_iface ) +DEFINE_IINSPECTABLE( bluetoothadapter_statics, IBluetoothAdapterStatics, struct bluetoothadapter_statics, IActivationFactory_iface )
static HRESULT WINAPI bluetoothadapter_statics_GetDeviceSelector( IBluetoothAdapterStatics *iface, HSTRING *result ) { @@ -134,10 +136,48 @@ static HRESULT WINAPI bluetoothadapter_statics_FromIdAsync( IBluetoothAdapterSta return E_NOTIMPL; }
+static HRESULT bluetoothadapter_create( const WCHAR *device_path, IBluetoothAdapter **adapter ); + +static HRESULT bluetoothadapter_get_default_async( IUnknown *invoker, IUnknown *params, PROPVARIANT *result ) +{ + char buffer[sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W) + MAX_PATH * sizeof( WCHAR )]; + SP_DEVICE_INTERFACE_DETAIL_DATA_W *iface_detail = (SP_DEVICE_INTERFACE_DETAIL_DATA_W *)buffer; + SP_DEVICE_INTERFACE_DATA iface_data; + DWORD idx = 0; + HDEVINFO devinfo; + + iface_detail->cbSize = sizeof( *iface_detail ); + iface_data.cbSize = sizeof( iface_data ); + + /* Windows.Devices.Bluetooth uses the GUID_BLUETOOTH_RADIO_INTERFACE interface class guid for radio devices, + * which is why we don't use BluetoothFindFirstRadio, which uses GUID_BTHPORT_DEVICE_INTERFACE. */ + devinfo = SetupDiGetClassDevsW( &GUID_BLUETOOTH_RADIO_INTERFACE, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE ); + if (devinfo == INVALID_HANDLE_VALUE) + return HRESULT_FROM_WIN32( GetLastError() ); + + while (SetupDiEnumDeviceInterfaces( devinfo, NULL, &GUID_BLUETOOTH_RADIO_INTERFACE, idx++, &iface_data )) + { + HRESULT hr; + IBluetoothAdapter *adapter = NULL; + + if (!SetupDiGetDeviceInterfaceDetailW( devinfo, &iface_data, iface_detail, sizeof( buffer ), NULL, NULL )) + continue; + + if (FAILED(hr = bluetoothadapter_create( iface_detail->DevicePath, &adapter ))) + return hr; + result->vt = VT_UNKNOWN; + result->punkVal = (IUnknown *)adapter; + break; + } + + return S_OK; +} + static HRESULT WINAPI bluetoothadapter_statics_GetDefaultAsync( IBluetoothAdapterStatics *iface, IAsyncOperation_BluetoothAdapter **operation ) { - FIXME( "iface %p, operation %p stub!\n", iface, operation ); - return E_NOTIMPL; + TRACE( "iface %p, operation %p\n", iface, operation ); + return async_operation_inspectable_create( &IID_IAsyncOperation_BluetoothAdapter, (IUnknown *)iface, NULL, bluetoothadapter_get_default_async, + (IAsyncOperation_IInspectable **)operation ); }
static const struct IBluetoothAdapterStaticsVtbl bluetoothadapter_statics_vtbl = @@ -155,11 +195,175 @@ static const struct IBluetoothAdapterStaticsVtbl bluetoothadapter_statics_vtbl = bluetoothadapter_statics_GetDefaultAsync, };
-static struct bluetoothadapter bluetoothadapter_statics = +static struct bluetoothadapter_statics bluetoothadapter_statics_impl = { {&factory_vtbl}, {&bluetoothadapter_statics_vtbl}, 1, };
-IActivationFactory *bluetoothadapter_factory = &bluetoothadapter_statics.IActivationFactory_iface; +IActivationFactory *bluetoothadapter_factory = &bluetoothadapter_statics_impl.IActivationFactory_iface; + +struct bluetoothadapter +{ + IBluetoothAdapter IBluetoothAdapter_iface; + HSTRING id; + LONG ref; +}; + +static inline struct bluetoothadapter *impl_from_IBluetoothAdapter( IBluetoothAdapter *iface ) +{ + return CONTAINING_RECORD( iface, struct bluetoothadapter, IBluetoothAdapter_iface ); +} + +static HRESULT WINAPI bluetoothadapter_QueryInterface( IBluetoothAdapter *iface, REFIID iid, void **out ) +{ + struct bluetoothadapter *impl = impl_from_IBluetoothAdapter( 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_IBluetoothAdapter )) + { + *out = &impl->IBluetoothAdapter_iface; + IInspectable_AddRef( *out ); + return S_OK; + } + + FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) ); + *out = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI bluetoothadapter_AddRef( IBluetoothAdapter *iface ) +{ + struct bluetoothadapter *impl = impl_from_IBluetoothAdapter( iface ); + ULONG ref = InterlockedIncrement( &impl->ref ); + TRACE( "iface %p increasing refcount to %lu.\n", iface, ref ); + return ref; +} + +static ULONG WINAPI bluetoothadapter_Release( IBluetoothAdapter *iface ) +{ + struct bluetoothadapter *impl = impl_from_IBluetoothAdapter( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + TRACE( "iface %p decreasing refcount to %lu.\n", iface, ref ); + + if (!ref) + { + WindowsDeleteString( impl->id ); + free( impl ); + } + return ref; +} + +static HRESULT WINAPI bluetoothadapter_GetIids( IBluetoothAdapter *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 bluetoothadapter_GetRuntimeClassName( IBluetoothAdapter *iface, HSTRING *class_name ) +{ + FIXME( "iface %p, class_name %p stub!\n", iface, class_name ); + return E_NOTIMPL; +} + +static HRESULT WINAPI bluetoothadapter_GetTrustLevel( IBluetoothAdapter *iface, TrustLevel *trust_level ) +{ + FIXME( "iface %p, trust_level %p stub!\n", iface, trust_level ); + return E_NOTIMPL; +} + +static HRESULT WINAPI bluetoothadapter_get_DeviceId( IBluetoothAdapter *iface, HSTRING *device_id ) +{ + struct bluetoothadapter *impl = impl_from_IBluetoothAdapter( iface ); + TRACE( "iface %p, device_id %p\n", iface, device_id ); + return WindowsDuplicateString( impl->id, device_id ); +} + +static HRESULT WINAPI bluetoothadapter_get_BluetoothAddress( IBluetoothAdapter *iface, UINT64 *addr ) +{ + FIXME( "iface %p, addr %p stub!\n", iface, addr ); + return E_NOTIMPL; +} + +static HRESULT WINAPI bluetoothadapter_get_IsClassicSupported( IBluetoothAdapter *iface, boolean *value ) +{ + FIXME( "iface %p, value %p stub!\n", iface, value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI bluetoothadapter_get_IsLowEnergySupported( IBluetoothAdapter *iface, boolean *value ) +{ + FIXME( "iface %p, value %p stub!\n", iface, value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI bluetoothadapter_get_IsPeripheralRoleSupported( IBluetoothAdapter *iface, boolean *value ) +{ + FIXME( "iface %p, value %p stub!\n", iface, value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI bluetoothadapter_get_IsCentralRoleSupported( IBluetoothAdapter *iface, boolean *value ) +{ + FIXME( "iface %p, value %p stub!\n", iface, value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI bluetoothadapter_get_IsAdvertisementOffloadSupported( IBluetoothAdapter *iface, boolean *value ) +{ + FIXME( "iface %p, value %p stub!\n", iface, value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI bluetoothadapter_GetRadioAsync( IBluetoothAdapter *iface, IAsyncOperation_Radio **op ) +{ + FIXME( "iface %p, op %p stub!\n", iface, op ); + return E_NOTIMPL; +} + +static const IBluetoothAdapterVtbl bluetooth_adapter_vtbl = +{ + /* QueryInterface methods */ + bluetoothadapter_QueryInterface, + bluetoothadapter_AddRef, + bluetoothadapter_Release, + /* IInspectable methods */ + bluetoothadapter_GetIids, + bluetoothadapter_GetRuntimeClassName, + bluetoothadapter_GetTrustLevel, + /* IBluetoothAdapter methods */ + bluetoothadapter_get_DeviceId, + bluetoothadapter_get_BluetoothAddress, + bluetoothadapter_get_IsClassicSupported, + bluetoothadapter_get_IsLowEnergySupported, + bluetoothadapter_get_IsPeripheralRoleSupported, + bluetoothadapter_get_IsCentralRoleSupported, + bluetoothadapter_get_IsAdvertisementOffloadSupported, + bluetoothadapter_GetRadioAsync +}; + +static HRESULT bluetoothadapter_create( const WCHAR *device_path, IBluetoothAdapter **adapter ) +{ + HRESULT ret; + struct bluetoothadapter *impl; + + impl = calloc( 1, sizeof( *impl ) ); + if (!impl) + return E_OUTOFMEMORY; + + ret = WindowsCreateString( device_path, wcslen( device_path ), &impl->id ); + if (FAILED( ret )) + { + free( impl ); + return ret; + } + + impl->IBluetoothAdapter_iface.lpVtbl = &bluetooth_adapter_vtbl; + impl->ref = 1; + *adapter = &impl->IBluetoothAdapter_iface; + return S_OK; +} diff --git a/dlls/windows.devices.bluetooth/private.h b/dlls/windows.devices.bluetooth/private.h index c72488c2edc..4bdda788ef1 100644 --- a/dlls/windows.devices.bluetooth/private.h +++ b/dlls/windows.devices.bluetooth/private.h @@ -28,6 +28,7 @@ #include "winstring.h"
#include "activation.h" +#include "bthdef.h"
#define WIDL_using_Windows_Foundation #define WIDL_using_Windows_Foundation_Collections @@ -35,10 +36,17 @@ #define WIDL_using_Windows_Networking #include "windows.networking.connectivity.h" #include "windows.networking.h" +#define WIDL_using_Windows_Devices_Radios +#include "windows.devices.radios.h" #define WIDL_using_Windows_Devices_Bluetooth #include "windows.devices.bluetooth.rfcomm.h" #include "windows.devices.bluetooth.h"
+#include "async_private.h" + +HRESULT async_operation_inspectable_create( const GUID *iid, IUnknown *invoker, IUnknown *param, async_operation_callback callback, + IAsyncOperation_IInspectable **out ); + extern IActivationFactory *bluetoothadapter_factory; extern IActivationFactory *bluetoothdevice_statics_factory; extern IActivationFactory *bluetoothledevice_statics_factory; @@ -80,5 +88,7 @@ extern IActivationFactory *bluetoothledevice_statics_factory; } #define DEFINE_IINSPECTABLE( pfx, iface_type, impl_type, base_iface ) \ DEFINE_IINSPECTABLE_( pfx, iface_type, impl_type, impl_from_##iface_type, iface_type##_iface, &impl->base_iface ) +#define DEFINE_IINSPECTABLE_OUTER( pfx, iface_type, impl_type, outer_iface ) \ + DEFINE_IINSPECTABLE_( pfx, iface_type, impl_type, impl_from_##iface_type, iface_type##_iface, impl->outer_iface )
#endif diff --git a/dlls/windows.devices.bluetooth/tests/bluetooth.c b/dlls/windows.devices.bluetooth/tests/bluetooth.c index 0db9ca0ad25..ec256174118 100644 --- a/dlls/windows.devices.bluetooth/tests/bluetooth.c +++ b/dlls/windows.devices.bluetooth/tests/bluetooth.c @@ -319,7 +319,7 @@ static void test_BluetoothAdapterStatics(void) WindowsDeleteString( default_str );
hr = IBluetoothAdapterStatics_GetDefaultAsync( bluetoothadapter_statics, &adapter_async ); - todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); if (FAILED( hr )) { skip( "GetDefaultAsync failed.\n" ); @@ -337,8 +337,8 @@ static void test_BluetoothAdapterStatics(void)
str = NULL; hr = IBluetoothAdapter_get_DeviceId( adapter, &str ); - todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); - todo_wine ok( !WindowsIsStringEmpty( str ), "got str %s.\n", debugstr_hstring( str ) ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + ok( !WindowsIsStringEmpty( str ), "got str %s.\n", debugstr_hstring( str ) ); WindowsDeleteString( str );
hr = IBluetoothAdapter_get_BluetoothAddress( adapter, &address );
From: Vibhav Pant vibhavp@gmail.com
--- dlls/windows.devices.bluetooth/Makefile.in | 2 +- .../bluetoothadapter.c | 28 +++++++++++++++++-- .../tests/bluetooth.c | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/dlls/windows.devices.bluetooth/Makefile.in b/dlls/windows.devices.bluetooth/Makefile.in index e084548f7e6..06141de8ad8 100644 --- a/dlls/windows.devices.bluetooth/Makefile.in +++ b/dlls/windows.devices.bluetooth/Makefile.in @@ -1,5 +1,5 @@ MODULE = windows.devices.bluetooth.dll -IMPORTS = combase setupapi +IMPORTS = bluetoothapis combase setupapi
SOURCES = \ async.c \ diff --git a/dlls/windows.devices.bluetooth/bluetoothadapter.c b/dlls/windows.devices.bluetooth/bluetoothadapter.c index f2e69e67407..c2c13f1d622 100644 --- a/dlls/windows.devices.bluetooth/bluetoothadapter.c +++ b/dlls/windows.devices.bluetooth/bluetoothadapter.c @@ -19,6 +19,8 @@ */
#include "private.h" +#include "bthsdpdef.h" +#include "bluetoothapis.h" #include "setupapi.h" #include "wine/debug.h"
@@ -208,6 +210,7 @@ struct bluetoothadapter { IBluetoothAdapter IBluetoothAdapter_iface; HSTRING id; + HANDLE radio; LONG ref; };
@@ -253,6 +256,7 @@ static ULONG WINAPI bluetoothadapter_Release( IBluetoothAdapter *iface ) if (!ref) { WindowsDeleteString( impl->id ); + CloseHandle( impl->radio ); free( impl ); } return ref; @@ -285,8 +289,19 @@ static HRESULT WINAPI bluetoothadapter_get_DeviceId( IBluetoothAdapter *iface, H
static HRESULT WINAPI bluetoothadapter_get_BluetoothAddress( IBluetoothAdapter *iface, UINT64 *addr ) { - FIXME( "iface %p, addr %p stub!\n", iface, addr ); - return E_NOTIMPL; + struct bluetoothadapter *impl = impl_from_IBluetoothAdapter( iface ); + BLUETOOTH_RADIO_INFO info = {0}; + DWORD err; + + TRACE( "iface %p, addr %p\n", iface, addr ); + + info.dwSize = sizeof( info ); + err = BluetoothGetRadioInfo( impl->radio, &info ); + if (err) + return HRESULT_FROM_WIN32( GetLastError() ); + + *addr = info.address.ullLong; + return S_OK; }
static HRESULT WINAPI bluetoothadapter_get_IsClassicSupported( IBluetoothAdapter *iface, boolean *value ) @@ -362,6 +377,15 @@ static HRESULT bluetoothadapter_create( const WCHAR *device_path, IBluetoothAdap return ret; }
+ impl->radio = CreateFileW( device_path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, 0, NULL); + if (impl->radio == INVALID_HANDLE_VALUE) + { + WindowsDeleteString( impl->id ); + free( impl ); + return HRESULT_FROM_WIN32( GetLastError() ); + } + impl->IBluetoothAdapter_iface.lpVtbl = &bluetooth_adapter_vtbl; impl->ref = 1; *adapter = &impl->IBluetoothAdapter_iface; diff --git a/dlls/windows.devices.bluetooth/tests/bluetooth.c b/dlls/windows.devices.bluetooth/tests/bluetooth.c index ec256174118..583d512ac93 100644 --- a/dlls/windows.devices.bluetooth/tests/bluetooth.c +++ b/dlls/windows.devices.bluetooth/tests/bluetooth.c @@ -342,7 +342,7 @@ static void test_BluetoothAdapterStatics(void) WindowsDeleteString( str );
hr = IBluetoothAdapter_get_BluetoothAddress( adapter, &address ); - todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr ); + ok( hr == S_OK, "got hr %#lx.\n", hr );
hr = IBluetoothAdapter_get_IsLowEnergySupported( adapter, &value ); todo_wine ok( hr == S_OK, "got hr %#lx.\n", hr );
v4:
* Remove winebth.sys code, the functionality can be implemented with device properties instead.