Gazebo Sim

API Reference

7.9.0
gz/sim/comms/MsgManager.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 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 
18 #ifndef GZ_SIM_MSGMANAGER_HH_
19 #define GZ_SIM_MSGMANAGER_HH_
20 
21 #include <deque>
22 #include <memory>
23 #include <string>
24 #include <unordered_map>
25 
26 #include <gz/msgs/dataframe.pb.h>
27 #include <gz/msgs/stringmsg_v.pb.h>
28 #include <gz/transport/Node.hh>
29 #include <gz/utils/ImplPtr.hh>
30 #include "gz/sim/config.hh"
31 #include "gz/sim/Entity.hh"
32 #include "gz/sim/System.hh"
33 
34 namespace gz
35 {
36 namespace msgs
37 {
38  // Forward declarations.
39  class Dataframe;
40 }
41 namespace sim
42 {
43 // Inline bracket to help doxygen filtering.
44 inline namespace GZ_SIM_VERSION_NAMESPACE {
45 namespace comms
46 {
47 
50 
53 using SubscriptionHandler =
55 
58 {
61 
64 
67 
70 
73 };
74 
78 
80 class GZ_SIM_VISIBLE MsgManager
81 {
83  public: MsgManager();
84 
93  public: bool AddSubscriber(const std::string &_address,
94  const std::string &_modelName,
95  const std::string &_topic);
96 
100  public: void AddInbound(const std::string &_address,
101  const msgs::DataframeSharedPtr &_msg);
102 
106  public: void AddOutbound(const std::string &_address,
107  const msgs::DataframeSharedPtr &_msg);
108 
113  public: bool RemoveSubscriber(const std::string &_address,
114  const std::string &_topic);
115 
120  public: bool RemoveInbound(const std::string &_address,
121  const msgs::DataframeSharedPtr &_msg);
122 
127  public: bool RemoveOutbound(const std::string &_address,
128  const msgs::DataframeSharedPtr &_msg);
129 
132  public: void DeliverMsgs();
133 
137  public: const Registry &DataConst() const;
138 
142  public: Registry &Data();
143 
147  public: Registry Copy() const;
148 
151  public: void Set(const Registry &_newContent);
152 
154  GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
155 };
156 }
157 }
158 }
159 }
160 
161 #endif