Skip to content

Commit be25734

Browse files
committed
introduce BP35A1Options for renaming and mark BP35A1Configurations obsolete
1 parent c0d5151 commit be25734

File tree

5 files changed

+60
-37
lines changed

5 files changed

+60
-37
lines changed

src/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35A1.cs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,57 +35,69 @@ public static ValueTask<BP35A1> CreateAsync(
3535
CancellationToken cancellationToken = default
3636
)
3737
=> CreateAsync(
38-
configurations: new BP35A1Configurations() {
38+
options: new BP35A1Options() {
3939
SerialPortName = serialPortName,
4040
},
4141
serviceProvider: serviceProvider,
4242
cancellationToken: cancellationToken
4343
);
4444

45+
[Obsolete($"Use {nameof(BP35A1Options)} instead.")]
4546
public static ValueTask<BP35A1> CreateAsync(
4647
BP35A1Configurations configurations,
4748
IServiceProvider? serviceProvider = null,
4849
CancellationToken cancellationToken = default
50+
)
51+
=> CreateAsync(
52+
options: configurations ?? throw new ArgumentNullException(nameof(configurations)),
53+
serviceProvider: serviceProvider,
54+
cancellationToken: cancellationToken
55+
);
56+
57+
public static ValueTask<BP35A1> CreateAsync(
58+
BP35A1Options options,
59+
IServiceProvider? serviceProvider = null,
60+
CancellationToken cancellationToken = default
4961
)
5062
=> InitializeAsync(
5163
#pragma warning disable CA2000
5264
device: new BP35A1(
53-
configurations: configurations ?? throw new ArgumentNullException(nameof(configurations)),
65+
options: options ?? throw new ArgumentNullException(nameof(options)),
5466
serviceProvider: serviceProvider
5567
),
5668
#pragma warning restore CA2000
57-
tryLoadFlashMemory: configurations.TryLoadFlashMemory,
69+
tryLoadFlashMemory: options.TryLoadFlashMemory,
5870
serviceProvider: serviceProvider,
5971
cancellationToken: cancellationToken
6072
);
6173

6274
/// <summary>
63-
/// Initializes a new instance of the <see cref="BP35A1"/> class with specifying configurations.
75+
/// Initializes a new instance of the <see cref="BP35A1"/> class with specifying options.
6476
/// </summary>
65-
/// <param name="configurations">
66-
/// A <see cref="BP35A1Configurations"/> that holds the configurations to the <see cref="BP35A1"/> instance.
77+
/// <param name="options">
78+
/// A <see cref="BP35A1Options"/> that holds the options to configure the new instance.
6779
/// </param>
6880
/// <param name="serviceProvider">
6981
/// The <see cref="IServiceProvider"/>.
7082
/// This constructor overload attempts to get a service of <see cref="IBP35SerialPortStreamFactory"/>, to create an <see cref="System.IO.Ports.SerialPort"/>.
7183
/// </param>
7284
private BP35A1(
73-
BP35A1Configurations configurations,
85+
BP35A1Options options,
7486
IServiceProvider? serviceProvider = null
7587
)
7688
: base(
77-
serialPortName: configurations.SerialPortName,
89+
serialPortName: options.SerialPortName,
7890
#pragma warning disable CA2000
79-
serialPortStreamFactory: serviceProvider?.GetService<IBP35SerialPortStreamFactory>() ?? new BP35A1SerialPortStreamFactory(configurations),
91+
serialPortStreamFactory: serviceProvider?.GetService<IBP35SerialPortStreamFactory>() ?? new BP35A1SerialPortStreamFactory(options),
8092
#pragma warning restore CA2000
8193
erxudpDataFormat: SkStackERXUDPDataFormat.Binary,
8294
logger: serviceProvider?.GetService<ILoggerFactory>()?.CreateLogger<BP35A1>()
8395
)
8496
{
8597
}
8698

87-
private sealed class BP35A1SerialPortStreamFactory(BP35A1Configurations configurations) : SerialPortStreamFactory {
88-
public override BP35UartBaudRate BaudRate { get; } = configurations.BaudRate;
89-
public override bool UseFlowControl { get; } = configurations.UseFlowControl;
99+
private sealed class BP35A1SerialPortStreamFactory(BP35A1Options options) : SerialPortStreamFactory {
100+
public override BP35UartBaudRate BaudRate { get; } = options.BaudRate;
101+
public override bool UseFlowControl { get; } = options.UseFlowControl;
90102
}
91103
}
Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,9 @@
11
// SPDX-FileCopyrightText: 2023 smdn <smdn@smdn.jp>
22
// SPDX-License-Identifier: MIT
3-
namespace Smdn.Devices.BP35XX;
4-
5-
public sealed class BP35A1Configurations {
6-
/// <summary>
7-
/// Gets or sets the <see cref="string"/> value that holds the serial port name for communicating with the device that implements the SKSTACK-IP protocol.
8-
/// </summary>
9-
public string? SerialPortName { get; set; }
3+
using System;
104

11-
/// <summary>
12-
/// Gets or sets the <see cref="BP35UartBaudRate"/> value that specifies the baud rate of the serial port for communicating with the device.
13-
/// </summary>
14-
public BP35UartBaudRate BaudRate { get; set; } = BP35A1.DefaultValueForBP35UartBaudRate;
15-
16-
/// <summary>
17-
/// Gets or sets a value indicating whether or not to use the Request-to-Send (RTS) hardware flow control for communicating with the device.
18-
/// </summary>
19-
public bool UseFlowControl { get; set; } = BP35A1.DefaultValueForUseFlowControl;
5+
namespace Smdn.Devices.BP35XX;
206

21-
/// <summary>
22-
/// Gets or sets a value indicating whether or not to attempt to load the configuration from flash memory during initialization.
23-
/// </summary>
24-
public bool TryLoadFlashMemory { get; set; } = BP35Base.DefaultValueForTryLoadFlashMemory;
7+
[Obsolete($"Use {nameof(BP35A1Options)} instead.")]
8+
public sealed class BP35A1Configurations : BP35A1Options {
259
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// SPDX-FileCopyrightText: 2025 smdn <smdn@smdn.jp>
2+
// SPDX-License-Identifier: MIT
3+
namespace Smdn.Devices.BP35XX;
4+
5+
public
6+
/* sealed */ // TODO: remove BP35A1Configurations and seal BP35A1Options
7+
class BP35A1Options {
8+
/// <summary>
9+
/// Gets or sets the <see cref="string"/> value that holds the serial port name for communicating with the device that implements the SKSTACK-IP protocol.
10+
/// </summary>
11+
public string? SerialPortName { get; set; }
12+
13+
/// <summary>
14+
/// Gets or sets the <see cref="BP35UartBaudRate"/> value that specifies the baud rate of the serial port for communicating with the device.
15+
/// </summary>
16+
public BP35UartBaudRate BaudRate { get; set; } = BP35A1.DefaultValueForBP35UartBaudRate;
17+
18+
/// <summary>
19+
/// Gets or sets a value indicating whether or not to use the Request-to-Send (RTS) hardware flow control for communicating with the device.
20+
/// </summary>
21+
public bool UseFlowControl { get; set; } = BP35A1.DefaultValueForUseFlowControl;
22+
23+
/// <summary>
24+
/// Gets or sets a value indicating whether or not to attempt to load the configuration from flash memory during initialization.
25+
/// </summary>
26+
public bool TryLoadFlashMemory { get; set; } = BP35Base.DefaultValueForTryLoadFlashMemory;
27+
}

tests/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35A1.Commands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class BP35A1CommandsTests {
5151
factory.Stream.ResponseWriter.Write("OK 00\r");
5252

5353
var bp35a1 = await BP35A1.CreateAsync(
54-
new BP35A1Configurations() {
54+
options: new BP35A1Options() {
5555
SerialPortName = "/dev/pseudo-serial-port",
5656
TryLoadFlashMemory = true,
5757
},

tests/Smdn.Devices.BP35XX/Smdn.Devices.BP35XX/BP35A1.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void CreateAsync(bool tryLoadFlashMemory)
6161
Assert.DoesNotThrowAsync(
6262
async () => {
6363
using var bp35a1 = await BP35A1.CreateAsync(
64-
new BP35A1Configurations() {
64+
options: new BP35A1Options() {
6565
SerialPortName = "/dev/pseudo-serial-port",
6666
TryLoadFlashMemory = tryLoadFlashMemory,
6767
},
@@ -103,7 +103,7 @@ public void CreateAsync_ExceptionThrownBySerialPortStreamFactory(string? serialP
103103
Assert.That(
104104
async () => {
105105
using var bp35a1 = await BP35A1.CreateAsync(
106-
new BP35A1Configurations() {
106+
options: new BP35A1Options() {
107107
SerialPortName = serialPortName,
108108
},
109109
services.BuildServiceProvider()
@@ -161,7 +161,7 @@ public async Task Properties()
161161
factory.Stream.ResponseWriter.Write("OK 00\r");
162162

163163
using var bp35a1 = await BP35A1.CreateAsync(
164-
new BP35A1Configurations() {
164+
options: new BP35A1Options() {
165165
SerialPortName = "/dev/pseudo-serial-port",
166166
},
167167
services.BuildServiceProvider()
@@ -213,7 +213,7 @@ public async Task Dispose()
213213
factory.Stream.ResponseWriter.Write("OK 00\r");
214214

215215
using var bp35a1 = await BP35A1.CreateAsync(
216-
new BP35A1Configurations() {
216+
options: new BP35A1Options() {
217217
SerialPortName = "/dev/pseudo-serial-port",
218218
TryLoadFlashMemory = true,
219219
},

0 commit comments

Comments
 (0)