Gazebo Sim

API Reference

7.9.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_SIM_SERVERCONFIG_HH_
18 #define GZ_SIM_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 gz
33 {
34  namespace sim
35  {
36  // Inline bracket to help doxygen filtering.
37  inline namespace GZ_SIM_VERSION_NAMESPACE {
38  // Forward declarations.
39  class ServerConfigPrivate;
40 
45  class GZ_SIM_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 GZ_SIM_VISIBLE PluginInfo
72  {
74  public: PluginInfo();
75 
77  public: ~PluginInfo();
78 
91  public: GZ_DEPRECATED(7) PluginInfo(const std::string &_entityName,
92  const std::string &_entityType,
93  const std::string &_filename,
94  const std::string &_name,
95  const sdf::ElementPtr &_sdf);
96 
105  public: PluginInfo(const std::string &_entityName,
106  const std::string &_entityType,
107  const sdf::Plugin &_plugin);
108 
111  public: PluginInfo(const PluginInfo &_info);
112 
116  public: PluginInfo &operator=(const PluginInfo &_info);
117 
122  public: const std::string &EntityName() const;
123 
128  public: void SetEntityName(const std::string &_entityName);
129 
134  public: const std::string &EntityType() const;
135 
140  public: void SetEntityType(const std::string &_entityType);
141 
145  public: const std::string GZ_DEPRECATED(7) & Filename() const;
146 
152  public: void GZ_DEPRECATED(7) SetFilename(const std::string &_filename);
153 
158  public: const std::string GZ_DEPRECATED(7) & Name() const;
159 
164  public: void GZ_DEPRECATED(7) SetName(const std::string &_name);
165 
169  public: const sdf::ElementPtr GZ_DEPRECATED(7) & Sdf() const;
170 
174  public: void GZ_DEPRECATED(7) SetSdf(const sdf::ElementPtr &_sdf);
175 
178  public: const sdf::Plugin &Plugin() const;
179 
182  public: sdf::Plugin &Plugin();
183 
186  public: void SetPlugin(const sdf::Plugin &_plugin) const;
187 
190  };
191 
193  public: ServerConfig();
194 
197  public: ServerConfig(const ServerConfig &_config);
198 
200  public: ~ServerConfig();
201 
209  public: bool SetSdfFile(const std::string &_file);
210 
214  public: std::string SdfFile() const;
215 
222  public: bool SetSdfString(const std::string &_sdfString);
223 
227  public: std::string SdfString() const;
228 
233  public: void SetSdfRoot(const sdf::Root &_root) const;
234 
238  public: std::optional<sdf::Root> &SdfRoot() const;
239 
242  public: void SetUpdateRate(const double &_hz);
243 
247  public: std::optional<double> UpdateRate() const;
248 
252  public: void SetInitialSimTime(const double &_initialSimTime) const;
253 
256  public: double InitialSimTime() const;
257 
260  public: bool UseLevels() const;
261 
264  public: void SetUseLevels(const bool _levels);
265 
270  public: bool UseDistributedSimulation() const;
271 
278  public: void SetNetworkSecondaries(unsigned int _secondaries);
279 
284  public: unsigned int NetworkSecondaries() const;
285 
293  public: void SetNetworkRole(const std::string &_role);
294 
300  public: std::string NetworkRole() const;
301 
304  public: bool UseLogRecord() const;
305 
308  public: void SetUseLogRecord(const bool _record);
309 
312  public: const std::string LogRecordPath() const;
313 
316  public: void SetLogRecordPath(const std::string &_recordPath);
317 
320  public: std::chrono::steady_clock::duration LogRecordPeriod() const;
321 
324  public: void SetLogRecordPeriod(
325  const std::chrono::steady_clock::duration &_period);
326 
329  public: void AddLogRecordTopic(const std::string &_topic);
330 
333  public: void ClearLogRecordTopics();
334 
338  public: const std::vector<std::string> &LogRecordTopics() const;
339 
342  public: const std::string LogPlaybackPath() const;
343 
346  public: void SetLogPlaybackPath(const std::string &_playbackPath);
347 
350  public: bool LogRecordResources() const;
351 
354  public: void SetLogRecordResources(bool _recordResources);
355 
358  public: std::string LogRecordCompressPath() const;
359 
362  public: void SetLogRecordCompressPath(const std::string &_path);
363 
366  public: unsigned int Seed() const;
367 
370  public: void SetSeed(unsigned int _seed);
371 
375  public: std::optional<std::chrono::steady_clock::duration>
376  UpdatePeriod() const;
377 
383  public: const std::string &ResourceCache() const;
384 
390  public: void SetResourceCache(const std::string &_path);
391 
394  public: const std::string &PhysicsEngine() const;
395 
398  public: void SetPhysicsEngine(const std::string &_physicsEngine);
399 
402  public: const std::string &RenderEngineServer() const;
403 
406  public: const std::string &RenderEngineGui() const;
407 
410  public: void SetHeadlessRendering(const bool _headless);
411 
414  public: bool HeadlessRendering() const;
415 
418  public: void SetRenderEngineServer(
419  const std::string &_renderEngineServer);
420 
423  public: void SetRenderEngineGui(const std::string &_renderEngineGui);
424 
428  public: void AddPlugin(const PluginInfo &_info);
429 
432  public: void AddPlugins(const std::list<PluginInfo> &_plugins);
433 
441  public: PluginInfo LogRecordPlugin() const;
442 
446  public: PluginInfo LogPlaybackPlugin() const;
447 
451  public: const std::list<PluginInfo> &Plugins() const;
452 
456  public: ServerConfig &operator=(const ServerConfig &_cfg);
457 
464  Timestamp() const;
465 
468  public: SourceType Source() const;
469 
471  private: std::unique_ptr<ServerConfigPrivate> dataPtr;
472  };
473 
478  GZ_SIM_VISIBLE
479  parsePluginsFromFile(const std::string &_fname);
480 
485  GZ_SIM_VISIBLE
486  parsePluginsFromString(const std::string &_str);
487 
504  //
507  //
510  GZ_SIM_VISIBLE
511  loadPluginInfo(bool _isPlayback = false);
512  }
513  }
514 }
515 
516 #endif