From 9c11c6e2b48683124d31947fccb45ac6806e3290 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Fri, 7 Jun 2024 10:26:34 +0200 Subject: [PATCH] fixup! feat!: move discovery configurations to scripting_api package --- example/coap_discovery.dart | 4 ++-- example/coap_dns_sd_discovery.dart | 7 +++---- example/core_link_format_discovery.dart | 3 +-- lib/src/core/implementation/servient.dart | 10 ++++------ lib/src/core/implementation/wot.dart | 11 ++++++++--- lib/src/core/scripting_api/wot.dart | 12 +++++++++--- 6 files changed, 27 insertions(+), 20 deletions(-) diff --git a/example/coap_discovery.dart b/example/coap_discovery.dart index 2536cd4c..aa86efe5 100644 --- a/example/coap_discovery.dart +++ b/example/coap_discovery.dart @@ -51,7 +51,7 @@ Future main(List args) async { // Example using for-await-loop try { await for (final thingDescription - in wot.discover(configurations: discoveryConfigurations)) { + in wot.discover(discoveryConfigurations)) { await handleThingDescription(wot, thingDescription); } print('Discovery with "await for" has finished.'); @@ -63,7 +63,7 @@ Future main(List args) async { // // Notice how the "onDone" callback is called before the result is passed // to the handleThingDescription function. - wot.discover(configurations: discoveryConfigurations).listen( + wot.discover(discoveryConfigurations).listen( (thingDescription) async { await handleThingDescription(wot, thingDescription); }, diff --git a/example/coap_dns_sd_discovery.dart b/example/coap_dns_sd_discovery.dart index 029402c2..432305f2 100644 --- a/example/coap_dns_sd_discovery.dart +++ b/example/coap_dns_sd_discovery.dart @@ -29,9 +29,8 @@ Future main(List args) async { // Example using for-await-loop try { - await for (final thingDescription in wot.discover( - configurations: discoveryConfigurations, - )) { + await for (final thingDescription + in wot.discover(discoveryConfigurations)) { handleThingDescription(thingDescription); } print('Discovery with "await for" has finished.'); @@ -43,7 +42,7 @@ Future main(List args) async { // // Notice how the "onDone" callback is called before the result is passed // to the handleThingDescription function. - wot.discover(configurations: discoveryConfigurations).listen( + wot.discover(discoveryConfigurations).listen( handleThingDescription, onError: (error) => print("Encountered an error: $error"), onDone: () => print('Discovery with "listen" has finished.'), diff --git a/example/core_link_format_discovery.dart b/example/core_link_format_discovery.dart index b0902c5e..4be758d3 100644 --- a/example/core_link_format_discovery.dart +++ b/example/core_link_format_discovery.dart @@ -21,8 +21,7 @@ Future main(List args) async { ), ]; - await for (final thingDescription - in wot.discover(configurations: discoveryConfigurations)) { + await for (final thingDescription in wot.discover(discoveryConfigurations)) { print(thingDescription.title); if (thingDescription.title != "Smart-Coffee-Machine") { diff --git a/lib/src/core/implementation/servient.dart b/lib/src/core/implementation/servient.dart index 52d3889b..b63d4028 100644 --- a/lib/src/core/implementation/servient.dart +++ b/lib/src/core/implementation/servient.dart @@ -27,8 +27,7 @@ import "wot.dart"; abstract class Servient { /// Creates a new [Servient]. /// - /// The [Servient] can be pre-configured with [List]s of - /// [clientFactories] and [discoveryConfigurations]. + /// The [Servient] can be pre-configured with a [List] of [clientFactories]. /// However, it is also possible to dynamically [addClientFactory]s and /// [removeClientFactory]s at runtime. /// @@ -327,14 +326,13 @@ class InternalServient implements Servient { return thingDescription; } - /// Perform automatic discovery using this [InternalServient]'s - /// [discoveryConfigurations]. + /// Perform discovery using the passed-in [discoveryConfigurations]. /// /// A [thingFilter] can be provided to filter the discovered Thing /// Descriptions; however, doing so currently does not have any effect yet. - ThingDiscovery discover({ + ThingDiscovery discover( + List discoveryConfigurations, { scripting_api.ThingFilter? thingFilter, - required List discoveryConfigurations, }) { return ThingDiscovery(thingFilter, this, discoveryConfigurations); } diff --git a/lib/src/core/implementation/wot.dart b/lib/src/core/implementation/wot.dart index d26187c5..0b395a8e 100644 --- a/lib/src/core/implementation/wot.dart +++ b/lib/src/core/implementation/wot.dart @@ -6,6 +6,8 @@ import "dart:async"; +import "package:meta/meta.dart"; + import "../definitions.dart"; import "../scripting_api.dart" as scripting_api; import "consumed_thing.dart"; @@ -39,12 +41,15 @@ class WoT implements scripting_api.WoT { _servient.produce(init); @override - ThingDiscovery discover({ + ThingDiscovery discover( + @experimental + List discoveryConfigurations, { scripting_api.ThingFilter? thingFilter, - required List configurations, }) => _servient.discover( - thingFilter: thingFilter, discoveryConfigurations: configurations); + discoveryConfigurations, + thingFilter: thingFilter, + ); @override Future requestThingDescription(Uri url) => diff --git a/lib/src/core/scripting_api/wot.dart b/lib/src/core/scripting_api/wot.dart index 47a62b61..5db66697 100644 --- a/lib/src/core/scripting_api/wot.dart +++ b/lib/src/core/scripting_api/wot.dart @@ -4,6 +4,8 @@ // // SPDX-License-Identifier: BSD-3-Clause +import "package:meta/meta.dart"; + import "../definitions.dart"; import "consumed_thing.dart"; @@ -47,7 +49,8 @@ abstract interface class WoT { DirectoryPayloadFormat? format, }); - /// Discovers [ThingDescription]s using the underlying platform configuration. + /// Discovers [ThingDescription]s based on the provided + /// [discoveryConfigurations]. /// /// A [thingFilter] may be passed for filtering out TDs before they /// are processed. @@ -61,8 +64,11 @@ abstract interface class WoT { /// It also allows for stopping the Discovery process prematurely and /// for retrieving information about its current state (i.e., whether it is /// still [ThingDiscovery.active]). - ThingDiscovery discover({ + /// + /// The shape of the `discover` API is still experimental and will most likely + /// change in the future. + ThingDiscovery discover( + @experimental List discoveryConfigurations, { ThingFilter? thingFilter, - required List configurations, }); }