Skip to content

Commit 9981a2d

Browse files
committed
feat: make DiscoveryConfiguration class immutable
1 parent a8aca0e commit 9981a2d

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

example/coap_dns_sd_discovery.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Future<void> main(List<String> args) async {
2020
HttpClientFactory(),
2121
],
2222
discoveryConfigurations: [
23-
DnsSdDConfiguration(protocolType: ProtocolType.udp),
23+
const DnsSdDConfiguration(protocolType: ProtocolType.udp),
2424
],
2525
);
2626

lib/src/core/implementation/discovery/discovery_configuration.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//
55
// SPDX-License-Identifier: BSD-3-Clause
66

7+
import "package:meta/meta.dart";
8+
79
import "../../scripting_api/discovery/thing_filter.dart";
810

911
/// Used to indicate whether the discovery mechanism will be used to discover
@@ -89,13 +91,16 @@ enum ProtocolType {
8991

9092
/// A configuration that is used by the `WoT.discover()` method when registered
9193
/// with the underlying `Servient`.
92-
sealed class DiscoveryConfiguration {}
94+
@immutable
95+
sealed class DiscoveryConfiguration {
96+
const DiscoveryConfiguration();
97+
}
9398

9499
/// A configuration used for direct discovery, i.e. the direct retrieval of a
95100
/// Thing Description from a [uri].
96101
final class DirectConfiguration extends DiscoveryConfiguration {
97102
/// Instantiates a new [DirectConfiguration] object from a [uri].
98-
DirectConfiguration(this.uri);
103+
const DirectConfiguration(this.uri);
99104

100105
/// The [Uri] the Thing Description can be retrieved from.
101106
final Uri uri;
@@ -111,7 +116,7 @@ final class ExploreDirectoryConfiguration extends DiscoveryConfiguration {
111116
///
112117
/// A [thingFilter] can be provided for filtering and the total number of TDs
113118
/// can be [limit]ed.
114-
ExploreDirectoryConfiguration(
119+
const ExploreDirectoryConfiguration(
115120
this.uri, {
116121
this.thingFilter,
117122
this.limit,
@@ -141,7 +146,7 @@ final class ExploreDirectoryConfiguration extends DiscoveryConfiguration {
141146
/// (exploration phase).
142147
sealed class TwoStepConfiguration extends DiscoveryConfiguration {
143148
/// Creates a new [TwoStepConfiguration] object from a [discoveryType].
144-
TwoStepConfiguration({required this.discoveryType});
149+
const TwoStepConfiguration({required this.discoveryType});
145150

146151
/// Indicates whether this configuration is used for discovering Things or
147152
/// Thing Description Directories.
@@ -161,7 +166,7 @@ final class DnsSdDConfiguration extends TwoStepConfiguration {
161166
/// Other domain names are currently unsupported.
162167
///
163168
/// [RFC 6762]: https://datatracker.ietf.org/doc/html/rfc6762
164-
DnsSdDConfiguration({
169+
const DnsSdDConfiguration({
165170
this.domainName = ".local",
166171
super.discoveryType = DiscoveryType.thing,
167172
this.protocolType = ProtocolType.tcp,

0 commit comments

Comments
 (0)