Gazebo Sim

API Reference

10.1.1
Server.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_SERVER_HH_
18#define GZ_SIM_SERVER_HH_
19
20#include <cstdint>
21#include <memory>
22#include <optional>
23#include <string>
24#include <gz/sim/config.hh>
26#include <gz/sim/Export.hh>
29#include <sdf/Element.hh>
30#include <sdf/Plugin.hh>
31
32namespace gz
33{
34 namespace sim
35 {
36 // Inline bracket to help doxygen filtering.
37 inline namespace GZ_SIM_VERSION_NAMESPACE {
38 // Forware declarations
39 class ServerPrivate;
40
116 class GZ_SIM_VISIBLE Server
117 {
119 public: enum class Status {
124 EXITED,
127 STOPPED,
129 RUNNING
130 };
131
136 public: explicit Server(const ServerConfig &_config = ServerConfig());
137
139 public: ~Server();
140
147 public: void SetUpdatePeriod(
148 const std::chrono::steady_clock::duration &_updatePeriod,
149 const unsigned int _worldIndex = 0);
150
166 public: bool Run(const bool _blocking = false,
167 const uint64_t _iterations = 0,
168 const bool _paused = true);
169
177 public: bool RunOnce(const bool _paused = true);
178
184 public: bool Running() const;
185
194 public: std::optional<bool> Running(const unsigned int _worldIndex) const;
195
203 public: bool SetPaused(const bool _paused,
204 const unsigned int _worldIndex = 0) const;
205
212 public: std::optional<bool> Paused(
213 const unsigned int _worldIndex = 0) const;
214
219 public: std::optional<uint64_t> IterationCount(
220 const unsigned int _worldIndex = 0) const;
221
225 public: std::optional<size_t> EntityCount(
226 const unsigned int _worldIndex = 0) const;
227
231 public: std::optional<size_t> SystemCount(
232 const unsigned int _worldIndex = 0) const;
233
240 public: std::optional<bool> AddSystem(
241 const SystemPluginPtr &_system,
242 const unsigned int _worldIndex = 0);
243
254 public: std::optional<bool> AddSystem(
255 const SystemPluginPtr &_system,
256 std::optional<Entity> _entity,
257 std::optional<std::shared_ptr<const sdf::Element>> _sdf,
258 const unsigned int _worldIndex = 0);
259
269 public: std::optional<bool> AddSystem(
270 const sdf::Plugin &_plugin,
271 std::optional<Entity> _entity,
272 const unsigned int _worldIndex = 0);
273
280 public: std::optional<bool> AddSystem(
281 const std::shared_ptr<System> &_system,
282 const unsigned int _worldIndex = 0);
283
294 public: std::optional<bool> AddSystem(
295 const std::shared_ptr<System> &_system,
296 std::optional<Entity> _entity,
297 std::optional<std::shared_ptr<const sdf::Element>> _sdf,
298 const unsigned int _worldIndex = 0);
299
308 public: std::optional<Entity> EntityByName(const std::string &_name,
309 const unsigned int _worldIndex = 0) const;
310
317 public: bool HasEntity(const std::string &_name,
318 const unsigned int _worldIndex = 0) const;
319
333 public: bool RequestRemoveEntity(const std::string &_name,
334 bool _recursive = true,
335 const unsigned int _worldIndex = 0);
336
348 public: bool RequestRemoveEntity(const Entity _entity,
349 bool _recursive = true,
350 const unsigned int _worldIndex = 0);
351
353 public: void Stop();
354
356 public: void ResetAll();
360 public: bool Reset(const std::size_t _runnerId);
361
364 public: Status GetStatus() const;
365
367 private: std::unique_ptr<ServerPrivate> dataPtr;
368 };
369 }
370 }
371}
372
373#endif