Skip to content

Commit

Permalink
fixup! feat!: move discovery configurations to scripting_api package
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Jun 7, 2024
1 parent 1814e5d commit 9c11c6e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 20 deletions.
4 changes: 2 additions & 2 deletions example/coap_discovery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Future<void> main(List<String> 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.');
Expand All @@ -63,7 +63,7 @@ Future<void> main(List<String> 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);
},
Expand Down
7 changes: 3 additions & 4 deletions example/coap_dns_sd_discovery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ Future<void> main(List<String> 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.');
Expand All @@ -43,7 +42,7 @@ Future<void> main(List<String> 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.'),
Expand Down
3 changes: 1 addition & 2 deletions example/core_link_format_discovery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ Future<void> main(List<String> 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") {
Expand Down
10 changes: 4 additions & 6 deletions lib/src/core/implementation/servient.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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<scripting_api.DiscoveryConfiguration> discoveryConfigurations, {
scripting_api.ThingFilter? thingFilter,
required List<scripting_api.DiscoveryConfiguration> discoveryConfigurations,
}) {
return ThingDiscovery(thingFilter, this, discoveryConfigurations);
}
Expand Down
11 changes: 8 additions & 3 deletions lib/src/core/implementation/wot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -39,12 +41,15 @@ class WoT implements scripting_api.WoT {
_servient.produce(init);

@override
ThingDiscovery discover({
ThingDiscovery discover(
@experimental
List<scripting_api.DiscoveryConfiguration> discoveryConfigurations, {
scripting_api.ThingFilter? thingFilter,
required List<scripting_api.DiscoveryConfiguration> configurations,
}) =>
_servient.discover(
thingFilter: thingFilter, discoveryConfigurations: configurations);
discoveryConfigurations,
thingFilter: thingFilter,
);

@override
Future<ThingDescription> requestThingDescription(Uri url) =>
Expand Down
12 changes: 9 additions & 3 deletions lib/src/core/scripting_api/wot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//
// SPDX-License-Identifier: BSD-3-Clause

import "package:meta/meta.dart";

import "../definitions.dart";

import "consumed_thing.dart";
Expand Down Expand Up @@ -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.
Expand All @@ -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<DiscoveryConfiguration> discoveryConfigurations, {
ThingFilter? thingFilter,
required List<DiscoveryConfiguration> configurations,
});
}

0 comments on commit 9c11c6e

Please sign in to comment.