Gazebo Sim

API Reference

9.0.0
TriggeredPublisher.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 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_SYSTEMS_TRIGGEREDPUBLISHER_HH_
18#define GZ_SIM_SYSTEMS_TRIGGEREDPUBLISHER_HH_
19
20#include <memory>
21#include <string>
22#include <vector>
23#include <mutex>
24#include <gz/transport/Node.hh>
25#include "gz/sim/System.hh"
26
27namespace gz
28{
29namespace sim
30{
31// Inline bracket to help doxygen filtering.
32inline namespace GZ_SIM_VERSION_NAMESPACE {
33namespace systems
34{
35 // Forward declaration
36 class InputMatcher;
37
175 public ISystemConfigure,
176 public ISystemPreUpdate
177 {
179 public: TriggeredPublisher() = default;
180
182 public: ~TriggeredPublisher() override;
183
184 // Documentation inherited
185 public: void Configure(const Entity &_entity,
188 EventManager &_eventMgr) override;
189
190 // Documentation inherited
191 public: void PreUpdate(
192 const gz::sim::UpdateInfo &_info,
193 gz::sim::EntityComponentManager &_ecm) override;
194
196 public: void DoWork();
197
199 private: void CallService(std::size_t pendingSrv);
200
202 private: void PublishMsg(std::size_t pending);
203
207 public: bool MatchInput(const transport::ProtoMsg &_inputMsg);
208
210 private: std::string inputMsgType;
211
213 private: std::string inputTopic;
214
216 private: struct OutputInfo
217 {
219 std::string msgType;
220
222 std::string topic;
223
227
230 };
231
233 private: struct SrvOutputInfo
234 {
236 std::string srvName;
237
239 std::string reqType;
240
242 std::string repType;
243
245 std::string reqMsg;
246
248 int timeout;
249 };
250
253
255 private: std::vector<OutputInfo> outputInfo;
256
258 private: std::vector<SrvOutputInfo> srvOutputInfo;
259
261 private: transport::Node node;
262
264 private: std::size_t serviceCount{0};
265
267 private: std::size_t publishCount{0};
268
270 private: std::mutex publishCountMutex;
271
273 private: std::mutex triggerSrvMutex;
274
276 private: std::condition_variable newMatchSignal;
277
279 private: std::thread workerThread;
280
283 private: std::atomic<bool> done{false};
284
286 private: std::chrono::steady_clock::duration delay{0};
287
290
292 private: std::mutex publishQueueMutex;
293 };
294 }
295}
296}
297}
298
299#endif