public async Task AdvertiseAsync(RosClient client, CancellationToken token) { token.ThrowIfCancellationRequested(); string fullService = service[0] == '/' ? service : $"{client?.CallerId}/{service}"; if (client != null) { for (int t = 0; t < NumRetries; t++) { try { await client.AdvertiseServiceAsync <T>(fullService, CallbackImpl, token); break; } catch (RoslibException e) { Core.Logger.Error($"Failed to advertise service (try {t}): ", e); await Task.Delay(WaitBetweenRetriesInMs, token); } } } }
static async Task MainImpl(string[] args) { Console.WriteLine("** Starting Iviz.ModelService..."); Uri?masterUri = RosClient.EnvironmentMasterUri; if (masterUri is null) { Console.Error.WriteLine("EE Fatal error: Failed to determine master uri. " + "Try setting ROS_MASTER_URI to the address of the master."); return; } Uri myUri = RosClient.TryGetCallerUriFor(masterUri) ?? RosClient.TryGetCallerUri(); await using RosClient client = await RosClient.CreateAsync(masterUri, "iviz_model_service", myUri); bool enableFileSchema; if (args.Length != 0 && args[0] == "--enable-file-schema") { enableFileSchema = true; Console.Error.WriteLine("WW Uris starting with 'file://' are now accepted. " + "This makes all your files available to the outside."); } else { enableFileSchema = false; } string?rosPackagePathExtras = null; string?extrasPath = await GetPathExtras(); if (extrasPath != null && File.Exists(extrasPath)) { try { rosPackagePathExtras = await File.ReadAllTextAsync(extrasPath); } catch (IOException e) { Console.WriteLine($"EE Extras file '{extrasPath}' could not be read: {e.Message}"); } } using var modelServer = new ModelServer(rosPackagePathExtras, enableFileSchema); if (modelServer.NumPackages == 0) { return; } Console.WriteLine("** Starting service {0} [{1}]...", ModelServer.ModelServiceName, GetModelResource.RosServiceType); await client.AdvertiseServiceAsync <GetModelResource>(ModelServer.ModelServiceName, modelServer.ModelCallback); Console.WriteLine("** Starting service {0} [{1}]...", ModelServer.TextureServiceName, GetModelTexture.RosServiceType); await client.AdvertiseServiceAsync <GetModelTexture>(ModelServer.TextureServiceName, modelServer.TextureCallback); Console.WriteLine("** Starting service {0} [{1}]...", ModelServer.FileServiceName, GetFile.RosServiceType); await client.AdvertiseServiceAsync <GetFile>(ModelServer.FileServiceName, modelServer.FileCallback); Console.WriteLine("** Starting service {0} [{1}]...", ModelServer.SdfServiceName, GetSdf.RosServiceType); await client.AdvertiseServiceAsync <GetSdf>(ModelServer.SdfServiceName, modelServer.SdfCallback); Console.WriteLine("** Done."); Console.WriteLine("** Iviz.ModelService started with " + modelServer.NumPackages + " ROS package path(s)."); Console.WriteLine("** Standing by for requests."); await WaitForCancel(); Console.WriteLine(); }