Skip to content

Commit

Permalink
feat(discovery): add ExploreDirectoryConfiguration for TDDs
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed May 22, 2024
1 parent 2deed8b commit 8cdd508
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/src/core/implementation/discovery/discovery_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//
// SPDX-License-Identifier: BSD-3-Clause

import "../../scripting_api/discovery/thing_filter.dart";

/// Used to indicate whether the discovery mechanism will be used to discover
/// Thing Descriptions of Things or Thing Description Directories.
enum DiscoveryType {
Expand Down Expand Up @@ -99,6 +101,38 @@ final class DirectConfiguration extends DiscoveryConfiguration {
final Uri uri;
}

/// A configuration that is used for retrieving Thing Descriptions from a Thing
/// Description Directory (TDD).
final class ExploreDirectoryConfiguration extends DiscoveryConfiguration {
/// Instantiates a new [ExploreDirectoryConfiguration].
///
/// The [uri] needs to point to the Thing Description exposed by the TDD that
/// is supposed to be used for this [DiscoveryConfiguration].
///
/// A [thingFilter] can be provided for filtering and the total number of TDs
/// can be [limit]ed.
ExploreDirectoryConfiguration(
this.uri, {
this.thingFilter,
this.limit,
});

/// The [Uri] the TDD's Thing Description can be retrieved from.
final Uri uri;

/// Optional filter that is supposed to used as a query parameter and
/// to filter received TDs.
///
/// Currently, this configuration parameter is unused, however.
final ThingFilter? thingFilter;

/// The maximum number of TDs that should be returned by the Thing Description
/// Directory.
///
/// Note that, currently, this limit is not being enforced at the client side.
final int? limit;
}

/// Base class for configuring discovery mechanisms that involve a two-step
/// approach.
///
Expand Down
6 changes: 6 additions & 0 deletions lib/src/core/implementation/thing_discovery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ class ThingDiscovery extends Stream<ThingDescription>
yield* _discoverFromCoreResourceDirectory(uri, discoveryType);
case DirectConfiguration(:final uri):
yield* Stream.fromFuture(_servient.requestThingDescription(uri));
case ExploreDirectoryConfiguration(:final uri, :final thingFilter):
final thingDiscoveryProcess = await _servient.exploreDirectory(
uri,
thingFilter: thingFilter,
);
yield* thingDiscoveryProcess;
}
}
}
Expand Down

0 comments on commit 8cdd508

Please sign in to comment.