-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RSDK-9622: Add Discover Service and GetModelsFromModules to Flutter (#…
…321) * add discovery service * register and add tests * add module models * change to discoveries * update with latest api changes * fix mocks * fix import' * import common to discovery.dart * remove content of test * readd test * export discovery client --------- Co-authored-by: Naveed Jooma <[email protected]>
- Loading branch information
1 parent
4c4b202
commit 5d442c7
Showing
7 changed files
with
4,257 additions
and
4,544 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import 'package:grpc/grpc_connection_interface.dart'; | ||
|
||
import '../../protos/common/common.dart'; | ||
import '../gen/common/v1/common.pb.dart'; | ||
import '../../protos/service/discovery.dart'; | ||
import '../gen/service/discovery/v1/discovery.pbgrpc.dart'; | ||
import '../gen/app/v1/robot.pb.dart'; | ||
import '../resource/base.dart'; | ||
import '../robot/client.dart'; | ||
import '../utils.dart'; | ||
|
||
/// {@category Services} | ||
class DiscoveryClient extends Resource implements ResourceRPCClient { | ||
static const Subtype subtype = Subtype(resourceNamespaceRDK, resourceTypeService, 'discovery'); | ||
|
||
@override | ||
final String name; | ||
|
||
@override | ||
ClientChannelBase channel; | ||
|
||
@override | ||
DiscoveryServiceClient get client => DiscoveryServiceClient(channel); | ||
|
||
DiscoveryClient(this.name, this.channel); | ||
|
||
/// Returns a list of [ComponentConfig]s for all discovered viam resources connected to the viam-server machine. | ||
/// | ||
/// ``` | ||
/// // Example: | ||
/// var resources = await myDiscoveryService.discoverResources('myWebcam'); | ||
/// ``` | ||
Future<List<ComponentConfig>> discoverResources(String discoveryName, {Map<String, dynamic>? extra}) async { | ||
final request = DiscoverResourcesRequest(name: name, extra: extra?.toStruct()); | ||
final response = await client.discoverResources(request); | ||
return response.discoveries; | ||
} | ||
|
||
@override | ||
Future<Map<String, dynamic>> doCommand(Map<String, dynamic> command) async { | ||
final request = DoCommandRequest() | ||
..name = name | ||
..command = command.toStruct(); | ||
final response = await client.doCommand(request); | ||
return response.result.toMap(); | ||
} | ||
|
||
/// Get the [ResourceName] for this [DiscoveryClient] with the given [name] | ||
static ResourceName getResourceName(String name) { | ||
return DiscoveryClient.subtype.getResourceName(name); | ||
} | ||
|
||
/// Get the [DiscoveryClient] named [name] from the provided robot. | ||
static DiscoveryClient fromRobot(RobotClient robot, String name) { | ||
return robot.getResource(DiscoveryClient.getResourceName(name)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.