Skip to content

Commit

Permalink
Typo fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Jun 11, 2024
1 parent c6abb6b commit 98a0e79
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/Shiny.BluetoothLE/Intrastructure/OperationQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;

namespace Shiny.BluetoothLE.Intrastructure;
namespace Shiny.BluetoothLE.Infrastructure;

// The operation queue cannot crash if it holds state, but it needs to bubble it's error out

Expand Down
60 changes: 23 additions & 37 deletions src/Shiny.BluetoothLE/Platforms/Apple/BleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,19 @@
using Microsoft.Extensions.Logging;
using CoreBluetooth;
using Foundation;
using Shiny.BluetoothLE.Intrastructure;
using Shiny.BluetoothLE.Infrastructure;

namespace Shiny.BluetoothLE;


public class BleManager : CBCentralManagerDelegate, IBleManager
public class BleManager(
AppleBleConfiguration config,
IServiceProvider services,
IOperationQueue operations,
ILogger<BleManager> logger,
ILogger<Peripheral> peripheralLogger
) : CBCentralManagerDelegate, IBleManager
{
readonly IServiceProvider services;
readonly IOperationQueue operations;
readonly ILogger logger;
readonly ILogger<Peripheral> peripheralLogger;
readonly AppleBleConfiguration config;

public BleManager(
AppleBleConfiguration config,
IServiceProvider services,
IOperationQueue operations,
ILogger<BleManager> logger,
ILogger<Peripheral> peripheralLogger
)
{
this.config = config;
this.operations = operations;
this.services = services;
this.logger = logger;
this.peripheralLogger = peripheralLogger;
}

public bool IsScanning { get; private set; }

Expand All @@ -46,26 +32,26 @@ public CBCentralManager Manager
if (this.manager == null)
{
if (!AppleExtensions.HasPlistValue("NSBluetoothPeripheralUsageDescription"))
this.logger.MissingIosPermission("NSBluetoothPeripheralUsageDescription");
logger.MissingIosPermission("NSBluetoothPeripheralUsageDescription");

if (!AppleExtensions.HasPlistValue("NSBluetoothAlwaysUsageDescription", 13))
this.logger.MissingIosPermission("NSBluetoothAlwaysUsageDescription");
logger.MissingIosPermission("NSBluetoothAlwaysUsageDescription");

var background = this.services.GetService(typeof(IBleDelegate)) != null;
var background = services.GetService(typeof(IBleDelegate)) != null;
if (!background)
{
this.manager = new CBCentralManager(this, this.config.DispatchQueue);
this.manager = new CBCentralManager(this, config.DispatchQueue);
this.manager.Delegate = this;
}
else
{
var opts = new CBCentralInitOptions
{
ShowPowerAlert = this.config.ShowPowerAlert,
RestoreIdentifier = this.config.RestoreIdentifier ?? "shinyble"
ShowPowerAlert = config.ShowPowerAlert,
RestoreIdentifier = config.RestoreIdentifier ?? "shinyble"
};

this.manager = new CBCentralManager(this, this.config.DispatchQueue, opts);
this.manager = new CBCentralManager(this, config.DispatchQueue, opts);
this.manager.Delegate = this;
}
}
Expand Down Expand Up @@ -184,10 +170,10 @@ public override async void WillRestoreState(CBCentralManager central, NSDictiona
{
var item = peripheralArray.GetItem<CBPeripheral>(i);
var peripheral = this.GetPeripheral(item);
await this.services
await services
.RunDelegates<IBleDelegate>(
x => x.OnPeripheralStateChanged(peripheral),
this.logger
logger
)
.ConfigureAwait(false);
}
Expand Down Expand Up @@ -222,16 +208,16 @@ public override void FailedToConnectPeripheral(CBCentralManager central, CBPerip
readonly Subject<AccessState> stateUpdatedSubj = new();
public override async void UpdatedState(CBCentralManager central)
{
this.logger.ManagerStateChange(central.State);
logger.ManagerStateChange(central.State);

var state = central.State.FromNative();
if (state == AccessState.Unknown)
return;

this.stateUpdatedSubj.OnNext(state);
await this.services.RunDelegates<IBleDelegate>(
await services.RunDelegates<IBleDelegate>(
x => x.OnAdapterStateChanged(state),
this.logger
logger
);
}

Expand All @@ -244,19 +230,19 @@ void Clear() => this.peripherals

void RunStateChange(CBPeripheral peripheral, bool connected, NSError? error)
{
this.logger.PeripheralStateChange(peripheral.Identifier, connected, error?.LocalizedDescription ?? "None");
logger.PeripheralStateChange(peripheral.Identifier, connected, error?.LocalizedDescription ?? "None");

var p = this.GetPeripheral(peripheral);
var status = connected ? ConnectionState.Connected : ConnectionState.Disconnected;
p.ReceiveStateChange(status);

this.services.RunDelegates<IBleDelegate>(x => x.OnPeripheralStateChanged(p), this.logger);
services.RunDelegates<IBleDelegate>(x => x.OnPeripheralStateChanged(p), logger);
}


readonly ConcurrentDictionary<string, Peripheral> peripherals = new();
Peripheral GetPeripheral(CBPeripheral peripheral) => this.peripherals.GetOrAdd(
peripheral.Identifier.ToString(),
x => new Peripheral(this, peripheral, this.operations, this.peripheralLogger)
x => new Peripheral(this, peripheral, operations, peripheralLogger)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using CoreBluetooth;
using Foundation;
using Microsoft.Extensions.Logging;
using Shiny.BluetoothLE.Intrastructure;
using Shiny.BluetoothLE.Infrastructure;

namespace Shiny.BluetoothLE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Reactive.Threading.Tasks;
using CoreBluetooth;
using Foundation;
using Shiny.BluetoothLE.Intrastructure;
using Shiny.BluetoothLE.Infrastructure;

namespace Shiny.BluetoothLE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using CoreBluetooth;
using Foundation;
using Microsoft.Extensions.Logging;
using Shiny.BluetoothLE.Intrastructure;
using Shiny.BluetoothLE.Infrastructure;

namespace Shiny.BluetoothLE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Shiny.BluetoothLE;
using Shiny.BluetoothLE.Intrastructure;
using Shiny.BluetoothLE.Infrastructure;

namespace Shiny;

Expand Down

0 comments on commit 98a0e79

Please sign in to comment.