Skip to content
Permalink
Browse files

BluetoothListener scaffolding. Win32 Picker now attached to active wi…

…ndow.
  • Loading branch information
peterfoot committed Mar 10, 2020
1 parent e67e4c4 commit 65e01032ea27b29550e2ccc551bdde099bd201b6
@@ -0,0 +1,62 @@
// 32feet.NET - Personal Area Networking for .NET
//
// InTheHand.Net.Sockets.BluetoothListener
//
// Copyright (c) 2003-2020 In The Hand Ltd, All rights reserved.
// This source code is licensed under the MIT License

using InTheHand.Net.Bluetooth;
using System;

namespace InTheHand.Net.Sockets
{
public sealed partial class BluetoothListener
{
Guid serviceUuid;

public BluetoothListener(Guid service)
{
serviceUuid = service;
}

public bool Active
{
get;
private set;
}

public ServiceClass ServiceClass
{
get;
set;
}

public string ServiceName
{
get;
set;
}

public bool Pending()
{
return DoPending();
}

public void Start()
{
DoStart();
Active = true;
}

public void Stop()
{
DoStop();
Active = false;
}

public BluetoothClient AcceptBluetoothClient()
{
return DoAcceptBluetoothClient();
}
}
}
@@ -0,0 +1,36 @@
// 32feet.NET - Personal Area Networking for .NET
//
// InTheHand.Net.Sockets.BluetoothListener (Android)
//
// Copyright (c) 2018-2020 In The Hand Ltd, All rights reserved.
// This source code is licensed under the MIT License

using Android.Bluetooth;
using InTheHand.Net.Bluetooth;
using System;

namespace InTheHand.Net.Sockets
{
partial class BluetoothListener
{
void DoStart()
{

}

void DoStop()
{

}

bool DoPending()
{
return false;
}

BluetoothClient DoAcceptBluetoothClient()
{
return null;
}
}
}
@@ -1,6 +1,6 @@
// 32feet.NET - Personal Area Networking for .NET
//
// InTheHand.Net.Bluetooth.BluetoothClient (.NET Standard)
// InTheHand.Net.Sockets.BluetoothClient (.NET Standard)
//
// Copyright (c) 2018-2020 In The Hand Ltd, All rights reserved.
// This source code is licensed under the MIT License
@@ -44,12 +44,11 @@ void SetAuthenticate(bool value)

bool GetConnected()
{
return false;
return false;
}

bool GetEncrypt()
{

return false;
}

@@ -62,7 +61,6 @@ public string GetRemoteMachineName()
return string.Empty;
}


NetworkStream DoGetStream()
{
return null;
@@ -0,0 +1,35 @@
// 32feet.NET - Personal Area Networking for .NET
//
// InTheHand.Net.Sockets.BluetoothListener (.NET Standard)
//
// Copyright (c) 2018-2020 In The Hand Ltd, All rights reserved.
// This source code is licensed under the MIT License

using InTheHand.Net.Bluetooth;
using System;

namespace InTheHand.Net.Sockets
{
partial class BluetoothListener
{
void DoStart()
{

}

void DoStop()
{

}

bool DoPending()
{
return false;
}

BluetoothClient DoAcceptBluetoothClient()
{
return null;
}
}
}
@@ -0,0 +1,24 @@
// 32feet.NET - Personal Area Networking for .NET
//
// InTheHand.Net.Bluetooth.Win32.BTH_SET_SERVICE
//
// Copyright (c) 2003-2020 In The Hand Ltd, All rights reserved.
// This source code is licensed under the MIT License

using System;
using System.Runtime.InteropServices;

namespace InTheHand.Net.Bluetooth.Win32
{
[StructLayout(LayoutKind.Sequential)]
internal struct BTH_SET_SERVICE
{
public uint pSdpVersion;
public IntPtr pRecordHandle;
public ServiceClass fCodService;
[MarshalAs(UnmanagedType.ByValArray, SizeConst =5)]
uint[] Reserved;
public uint ulRecordLength;
public IntPtr pRecord;
}
}
@@ -13,21 +13,24 @@ namespace InTheHand.Net.Bluetooth
{
partial class BluetoothDevicePicker
{
private async Task<BluetoothDeviceInfo> DoPickSingleDeviceAsync()
private Task<BluetoothDeviceInfo> DoPickSingleDeviceAsync()
{
BluetoothDeviceInfo info = null;

BLUETOOTH_SELECT_DEVICE_PARAMS p = new BLUETOOTH_SELECT_DEVICE_PARAMS();
p.Reset();
p.SetClassOfDevices(ClassOfDevices.ToArray());
p.fForceAuthentication = RequireAuthentication;
p.hwndParent = NativeMethods.GetActiveWindow();

bool success = NativeMethods.BluetoothSelectDevices(ref p);

if(success)
if (success)
{
return new BluetoothDeviceInfo(p.Device);
info = new BluetoothDeviceInfo(p.Device);
}

return null;
return Task.FromResult(info);
}
}
}
}
@@ -0,0 +1,35 @@
// 32feet.NET - Personal Area Networking for .NET
//
// InTheHand.Net.Sockets.BluetoothListener (Win32)
//
// Copyright (c) 2018-2020 In The Hand Ltd, All rights reserved.
// This source code is licensed under the MIT License

using InTheHand.Net.Bluetooth;
using System;

namespace InTheHand.Net.Sockets
{
partial class BluetoothListener
{
void DoStart()
{

}

void DoStop()
{

}

bool DoPending()
{
return false;
}

BluetoothClient DoAcceptBluetoothClient()
{
return null;
}
}
}
@@ -1,6 +1,6 @@
// 32feet.NET - Personal Area Networking for .NET
//
// InTheHand.Net.Bluetooth.BluetoothIoCapability
// InTheHand.Net.Bluetooth.Win32.NativeMethods
//
// Copyright (c) 2003-2020 In The Hand Ltd, All rights reserved.
// This source code is licensed under the MIT License
@@ -13,7 +13,11 @@ namespace InTheHand.Net.Bluetooth.Win32
internal static class NativeMethods
{
private const string bthpropsDll = "bthprops.cpl";
private const string irpropsDll = "Irprops.cpl";
private const string irpropsDll = "Irprops.cpl";
private const string wsDll = "ws2_32.dll";

[DllImport("User32")]
internal static extern IntPtr GetActiveWindow();

// Requires Vista SP2 or later
[DllImport(bthpropsDll, SetLastError = true, CharSet = CharSet.Unicode)]
@@ -98,6 +102,10 @@ internal static class NativeMethods
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool CloseHandle(IntPtr handle);

//SetService
[DllImport(wsDll, EntryPoint = "WSASetService", SetLastError = true)]
internal static extern int WSASetService(ref WSAQUERYSET lpqsRegInfo, WSAESETSERVICEOP essoperation, int dwControlFlags);

// Picker
[DllImport(irpropsDll, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
@@ -0,0 +1,33 @@
// 32feet.NET - Personal Area Networking for .NET
//
// InTheHand.Net.Bluetooth.Win32.WSAESETSERVICEOP
//
// Copyright (c) 2003-2020 In The Hand Ltd, All rights reserved.
// This source code is licensed under the MIT License

namespace InTheHand.Net.Bluetooth.Win32
{
internal enum WSAESETSERVICEOP : int
{
/// <summary>
/// Register the service. For SAP, this means sending out a periodic broadcast.
/// This is an NOP for the DNS namespace.
/// For persistent data stores, this means updating the address information.
/// </summary>
RNRSERVICE_REGISTER = 0,

/// <summary>
/// Remove the service from the registry.
/// For SAP, this means stop sending out the periodic broadcast.
/// This is an NOP for the DNS namespace.
/// For persistent data stores this means deleting address information.
/// </summary>
RNRSERVICE_DEREGISTER,

/// <summary>
/// Delete the service from dynamic name and persistent spaces.
/// For services represented by multiple CSADDR_INFO structures (using the SERVICE_MULTIPLE flag), only the specified address will be deleted, and this must match exactly the corresponding CSADDR_INFO structure that was specified when the service was registered
/// </summary>
RNRSERVICE_DELETE,
}
}
@@ -0,0 +1,40 @@
// 32feet.NET - Personal Area Networking for .NET
//
// InTheHand.Net.Bluetooth.Win32.WSAQuerySet
//
// Copyright (c) 2003-2020 In The Hand Ltd, All rights reserved.
// This source code is licensed under the MIT License

using System;
using System.Runtime.InteropServices;

namespace InTheHand.Net.Bluetooth.Win32
{
[StructLayout(LayoutKind.Sequential)]
internal struct WSAQUERYSET
{
public uint dwSize;
string lpszServiceInstanceName;
public Guid lpServiceClassId;
IntPtr lpVersion;
IntPtr lpszComment;
public uint dwNameSpace; //NS_BTH
IntPtr lpNSProviderId;
IntPtr lpszContext;
uint dwNumberOfProtocols;
IntPtr lpafpProtocols;
string lpszQueryString;
uint dwNumberOfCsAddrs;
IntPtr lpcsaBuffer;
uint dwOutputFlags;
[MarshalAs(UnmanagedType.LPStruct)]
public BLOB lpBlob;
}

[StructLayout(LayoutKind.Sequential)]
internal struct BLOB
{
public uint size;
public BTH_SET_SERVICE blobData;
}
}

0 comments on commit 65e0103

Please sign in to comment.
You can’t perform that action at this time.