Gazebo Gazebo

API Reference

6.16.0
gz/sim/ServerConfig.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef GZ_GAZEBO_SERVERCONFIG_HH_
18 #define GZ_GAZEBO_SERVERCONFIG_HH_
19 
20 #include <chrono>
21 #include <list>
22 #include <memory>
23 #include <optional> // NOLINT(*)
24 #include <string>
25 #include <vector>
26 #include <sdf/Element.hh>
27 #include <sdf/Plugin.hh>
28 #include <sdf/Root.hh>
29 #include <gz/sim/config.hh>
30 #include <gz/sim/Export.hh>
31 
32 namespace ignition
33 {
34  namespace gazebo
35  {
36  // Inline bracket to help doxygen filtering.
37  inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
38  // Forward declarations.
39  class ServerConfigPrivate;
40 
45  class IGNITION_GAZEBO_VISIBLE ServerConfig
46  {
48  public: enum class SourceType
49  {
50  // No source specified.
51  kNone,
52 
53  // The source is an SDF Root object.
54  kSdfRoot,
55 
56  // The source is an SDF file.
57  kSdfFile,
58 
59  // The source is an SDF string.
60  kSdfString,
61  };
62 
63 
64  class PluginInfoPrivate;
71  public: class IGNITION_GAZEBO_VISIBLE PluginInfo
72  {
74  public: PluginInfo();
75 
77  public: ~PluginInfo();
78 
92  public: PluginInfo(const std::string &_entityName,
93  const std::string &_entityType,
94  const std::string &_filename,
95  const std::string &_name,
96  const sdf::ElementPtr &_sdf);
97 
106  public: PluginInfo(const std::string &_entityName,
107  const std::string &_entityType,
108  const sdf::Plugin &_plugin);
109 
112  public: PluginInfo(const PluginInfo &_info);
113 
117  public: PluginInfo &operator=(const PluginInfo &_info);
118 
123  public: const std::string &EntityName() const;
124 
129  public: void SetEntityName(const std::string &_entityName);
130 
135  public: const std::string &EntityType() const;
136 
141  public: void SetEntityType(const std::string &_entityType);
142 
147  public: const std::string &Filename() const;
148 
155  public: void SetFilename(const std::string &_filename);
156 
162  public: const std::string &Name() const;
163 
169  public: void SetName(const std::string &_name);
170 
175  public: const sdf::ElementPtr &Sdf() const;
176 
181  public: void SetSdf(const sdf::ElementPtr &_sdf);
182 
185  public: const sdf::Plugin &Plugin() const;
186 
189  public: sdf::Plugin &Plugin();
190 
193  public: void SetPlugin(const sdf::Plugin &_plugin) const;
194 
197  };
198 
200  public: ServerConfig();
201 
204  public: ServerConfig(const ServerConfig &_config);
205 
207  public: ~ServerConfig();
208 
216  public: bool SetSdfFile(const std::string &_file);
217 
221  public: std::string SdfFile() const;
222 
229  public: bool SetSdfString(const std::string &_sdfString);
230 
234  public: std::string SdfString() const;
235 
240  public: void SetSdfRoot(const sdf::Root &_root) const;
241 
245  public: std::optional<sdf::Root> &SdfRoot() const;
246 
249  public: void SetUpdateRate(const double &_hz);
250 
254  public: std::optional<double> UpdateRate() const;
255 
258  public: bool UseLevels() const;
259 
262  public: void SetUseLevels(const bool _levels);
263 
268  public: bool UseDistributedSimulation() const;
269 
276  public: void SetNetworkSecondaries(unsigned int _secondaries);
277 
282  public: unsigned int NetworkSecondaries() const;
283 
291  public: void SetNetworkRole(const std::string &_role);
292 
298  public: std::string NetworkRole() const;
299 
302  public: bool UseLogRecord() const;
303 
306  public: void SetUseLogRecord(const bool _record);
307 
310  public: const std::string LogRecordPath() const;
311 
314  public: void SetLogRecordPath(const std::string &_recordPath);
315 
318  public: std::chrono::steady_clock::duration LogRecordPeriod() const;
319 
322  public: void SetLogRecordPeriod(
323  const std::chrono::steady_clock::duration &_period);
324 
327  public: void AddLogRecordTopic(const std::string &_topic);
328 
331  public: void ClearLogRecordTopics();
332 
336  public: const std::vector<std::string> &LogRecordTopics() const;
337 
340  public: const std::string LogPlaybackPath() const;
341 
344  public: void SetLogPlaybackPath(const std::string &_playbackPath);
345 
348  public: bool LogRecordResources() const;
349 
352  public: void SetLogRecordResources(bool _recordResources);
353 
356  public: std::string LogRecordCompressPath() const;
357 
360  public: void SetLogRecordCompressPath(const std::string &_path);
361 
364  public: unsigned int Seed() const;
365 
368  public: void SetSeed(unsigned int _seed);
369 
373  public: std::optional<std::chrono::steady_clock::duration>
374  UpdatePeriod() const;
375 
381  public: const std::string &ResourceCache() const;
382 
388  public: void SetResourceCache(const std::string &_path);
389 
392  public: const std::string &PhysicsEngine() const;
393 
396  public: void SetPhysicsEngine(const std::string &_physicsEngine);
397 
400  public: const std::string &RenderEngineServer() const;
401 
404  public: const std::string &RenderEngineGui() const;
405 
408  public: void SetHeadlessRendering(const bool _headless);
409 
412  public: bool HeadlessRendering() const;
413 
416  public: void SetRenderEngineServer(
417  const std::string &_renderEngineServer);
418 
421  public: void SetRenderEngineGui(const std::string &_renderEngineGui);
422 
426  public: void AddPlugin(const PluginInfo &_info);
427 
430  public: void AddPlugins(const std::list<PluginInfo> &_plugins);
431 
439  public: PluginInfo LogRecordPlugin() const;
440 
444  public: PluginInfo LogPlaybackPlugin() const;
445 
449  public: const std::list<PluginInfo> &Plugins() const;
450 
454  public: ServerConfig &operator=(const ServerConfig &_cfg);
455 
462  Timestamp() const;
463 
466  public: SourceType Source() const;
467 
469  private: std::unique_ptr<ServerConfigPrivate> dataPtr;
470  };
471 
476  IGNITION_GAZEBO_VISIBLE
477  parsePluginsFromFile(const std::string &_fname);
478 
483  IGNITION_GAZEBO_VISIBLE
484  parsePluginsFromString(const std::string &_str);
485 
502  //
505  //
508  IGNITION_GAZEBO_VISIBLE
509  loadPluginInfo(bool _isPlayback = false);
510  }
511  }
512 }
513 
514 #endif
std::string NetworkRole() const
Get the network role. See SetNetworkRole(const std::string &_role) for more information about distrib...
std::string LogRecordCompressPath() const
Get file path to compress log files to.
bool SetSdfString(const std::string &_sdfString)
Set an SDF string to be used by the server.
Configuration parameters for a Server. An instance of this object can be used to construct a Server w...
Definition: gz/sim/ServerConfig.hh:45
void SetLogRecordCompressPath(const std::string &_path)
Set file path to compress log files to.
void AddLogRecordTopic(const std::string &_topic)
Add a topic to record.
void ClearLogRecordTopics()
Clear topics to record. This will remove all topics set using AddLogRecordTopic.
void AddPlugins(const std::list< PluginInfo > &_plugins)
Add multiple plugins to the simulation.
void SetEntityType(const std::string &_entityType)
Set the type of the entity which should receive this plugin. The type is used in conjuction with Enti...
std::optional< std::chrono::steady_clock::duration > UpdatePeriod() const
Get the update period duration.
This library is part of the Gazebo project.
STL class.
std::chrono::steady_clock::duration LogRecordPeriod() const
Get time period to record states.
void SetSdf(const sdf::ElementPtr &_sdf)
Set the plugin XML elements associated with this plugin.
STL class.
const std::string & Filename() const
Get the plugin library filename.
void SetUseLogRecord(const bool _record)
Set whether the server is recording states.
const sdf::Plugin & Plugin() const
Get the SDF plugin information.
const std::string & PhysicsEngine() const
Physics engine plugin library to load.
std::list< ServerConfig::PluginInfo > loadPluginInfo(bool _isPlayback=false)
Load plugin information, following ordering.
STL class.
void SetUpdateRate(const double &_hz)
Set the update rate in Hertz. Value <=0 are ignored.
const std::vector< std::string > & LogRecordTopics() const
Get the topics to record that were added using AddLogRecordTopic.
SourceType Source() const
Get the type of source.
void SetUseLevels(const bool _levels)
Get whether the server is using the level system.
const std::string LogRecordPath() const
Get path to place recorded states.
unsigned int Seed() const
The given random seed.
const std::chrono::time_point< std::chrono::system_clock > & Timestamp() const
Get the timestamp of this ServerConfig. This is the system time when this ServerConfig was created....
void SetNetworkSecondaries(unsigned int _secondaries)
Set the number of network secondary servers that the primary server should expect....
void SetSdfRoot(const sdf::Root &_root) const
Set the SDF Root DOM object. The sdf::Root object will take precendence over ServerConfig::SdfString(...
ServerConfig & operator=(const ServerConfig &_cfg)
Equal operator.
std::list< ServerConfig::PluginInfo > parsePluginsFromFile(const std::string &_fname)
Parse plugins from XML configuration file.
void SetLogRecordPath(const std::string &_recordPath)
Set path to place recorded states.
void SetRenderEngineServer(const std::string &_renderEngineServer)
Set the render engine server plugin library.
std::chrono::steady_clock::time_point Timestamp
void SetPhysicsEngine(const std::string &_physicsEngine)
Set the physics engine plugin library.
void SetFilename(const std::string &_filename)
Set the type of the entity which should receive this plugin. The type is used in conjuction with Enti...
PluginInfo LogPlaybackPlugin() const
Generate PluginInfo for Log playback based on the internal state of this ServerConfig object:
const std::string & ResourceCache() const
Path to where simulation resources, such as models downloaded from fuel.gazebosim....
void SetHeadlessRendering(const bool _headless)
Set the headless mode.
unsigned int NetworkSecondaries() const
Get the number of secondary servers that a primary server should expect.
bool UseLevels() const
Get whether the server is using the level system.
std::string SdfFile() const
Get the SDF file that has been set. An empty string will be returned if an SDF file has not been set.
const std::string LogPlaybackPath() const
Get path to recorded states to play back.
void SetLogPlaybackPath(const std::string &_playbackPath)
Set path to recorded states to play back.
std::list< ServerConfig::PluginInfo > parsePluginsFromString(const std::string &_str)
Parse plugins from XML configuration string.
void SetLogRecordResources(bool _recordResources)
Set whether meshes and material files are recorded.
PluginInfo LogRecordPlugin() const
Generate PluginInfo for Log recording based on the internal state of this ServerConfig object:
bool HeadlessRendering() const
Get the headless mode.
void SetRenderEngineGui(const std::string &_renderEngineGui)
Set the render engine gui plugin library.
const std::string & RenderEngineGui() const
Render engine plugin library to load.
void SetLogRecordPeriod(const std::chrono::steady_clock::duration &_period)
Set time period to record states.
bool SetSdfFile(const std::string &_file)
Set an SDF file to be used with the server.
void SetName(const std::string &_name)
Set the name of the interface within the plugin library to load.
void AddPlugin(const PluginInfo &_info)
Instruct simulation to attach a plugin to a specific entity when simulation starts.
PluginInfo & operator=(const PluginInfo &_info)
Equal operator.
void SetResourceCache(const std::string &_path)
Set the path to where simulation resources, such as models downloaded from fuel.gazebosim....
const std::string & EntityType() const
Get the entity type which should receive this plugin. The type is used in conjuction with EntityName ...
bool LogRecordResources() const
Get whether meshes and material files are recorded.
void SetPlugin(const sdf::Plugin &_plugin) const
Set the SDF plugin information.
void SetEntityName(const std::string &_entityName)
Set the name of the entity which should receive this plugin. The name is used in conjuction with _ent...
const std::list< PluginInfo > & Plugins() const
Get all the plugins that should be loaded.
const std::string & RenderEngineServer() const
Render engine plugin library to load.
const std::string & EntityName() const
Get the name of the entity which should receive this plugin. The name is used in conjuction with _ent...
const sdf::ElementPtr & Sdf() const
Plugin XML elements associated with this plugin.
void SetSeed(unsigned int _seed)
Set the random seed.
Component< std::string, class NameTag, serializers::StringSerializer > Name
This component holds an entity's name. The component has no concept of scoped names nor does it care ...
Definition: gz/sim/components/Name.hh:37
bool UseLogRecord() const
Get whether the server is recording states.
bool UseDistributedSimulation() const
Get whether the server is using the distributed sim system.
Information about a plugin that should be loaded by the server.
Definition: gz/sim/ServerConfig.hh:71
void SetNetworkRole(const std::string &_role)
Set the network role, which is one of [primary, secondary]. If primary is used, then make sure to als...
std::string SdfString() const
Get the SDF String that has been set. An empty string will be returned if an SDF string has not been ...
std::optional< double > UpdateRate() const
Get the update rate in Hertz.
SourceType
Type of SDF source.
Definition: gz/sim/ServerConfig.hh:48
const std::string & Name() const
Name of the interface within the plugin library to load.
std::optional< sdf::Root > & SdfRoot() const
Get the SDF Root DOM object.