refresh method
Refresh the resources of this robot
await machine.refresh();
Implementation
Future<void> refresh() async {
final rpb.ResourceNamesResponse response = await _client.resourceNames(rpb.ResourceNamesRequest());
final responseNames = response.resources.map((rn) {
if (rn.remotePath.isEmpty) {
rn.remotePath.addAll(rn.name.split(':')..removeLast());
}
if (rn.localName.isEmpty) {
rn.localName = rn.name.split(':').last;
}
return rn;
});
if (setEquals(responseNames.toSet(), resourceNames.toSet())) {
resourceNames.forEach((element) {
_resetResourceChannel(element);
});
return;
}
final manager = ResourceManager();
for (ResourceName name in responseNames) {
if (![resourceTypeComponent, resourceTypeService].contains(name.type)) {
continue;
}
if (name.subtype == 'remote') {
continue;
}
_resetResourceChannel(name);
try {
manager.register(name, Registry.instance.lookupSubtype(Subtype.fromResourceName(name)).rpcClientCreator(name.name, _channel));
} catch (error) {
continue;
}
}
resourceNames = responseNames.toList();
if (_manager.resources != manager.resources) {
_manager = manager;
}
}