Gazebo Msgs

API Reference

10.1.1
DiscoveryType.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2023 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_MSGS_CONVERT_DISCOVERYTYPE_HH_
18#define GZ_MSGS_CONVERT_DISCOVERYTYPE_HH_
19
20// Message Headers
21#include "gz/msgs/discovery.pb.h"
22
23// Data Headers
24#include <string>
25
26namespace gz::msgs {
27// Inline bracket to help doxygen filtering.
28inline namespace GZ_MSGS_VERSION_NAMESPACE {
29
31inline msgs::Discovery::Type ConvertDiscoveryType(const std::string &_str)
32{
33 msgs::Discovery::Type result = msgs::Discovery::UNINITIALIZED;
34
35 if (_str == "UNINITIALIZED")
36 {
37 result = msgs::Discovery::UNINITIALIZED;
38 }
39 else if (_str == "ADVERTISE")
40 {
41 result = msgs::Discovery::ADVERTISE;
42 }
43 else if (_str == "SUBSCRIBE")
44 {
45 result = msgs::Discovery::SUBSCRIBE;
46 }
47 else if (_str == "UNADVERTISE")
48 {
49 result = msgs::Discovery::UNADVERTISE;
50 }
51 else if (_str == "HEARTBEAT")
52 {
53 result = msgs::Discovery::HEARTBEAT;
54 }
55 else if (_str == "BYE")
56 {
57 result = msgs::Discovery::BYE;
58 }
59 else if (_str == "NEW_CONNECTION")
60 {
61 result = msgs::Discovery::NEW_CONNECTION;
62 }
63 else if (_str == "END_CONNECTION")
64 {
65 result = msgs::Discovery::END_CONNECTION;
66 }
67 else if (_str == "SUBSCRIBERS_REQ")
68 {
69 result = msgs::Discovery::SUBSCRIBERS_REQ;
70 }
71 else if (_str == "SUBSCRIBERS_REP")
72 {
73 result = msgs::Discovery::SUBSCRIBERS_REP;
74 }
75 else
76 {
77 std::cerr << "Unrecognized DiscoveryType["
78 << _str
79 << "], returning msgs::Discovery::UNINITIALIZED"
80 << std::endl;
81 }
82 return result;
83}
84
86inline std::string ConvertDiscoveryType(const msgs::Discovery::Type &_type)
87{
88 switch (_type)
89 {
90 default:
91 case msgs::Discovery::UNINITIALIZED:
92 return "UNINITIALIZED";
93 case msgs::Discovery::ADVERTISE:
94 return "ADVERTISE";
95 case msgs::Discovery::SUBSCRIBE:
96 return "SUBSCRIBE";
97 case msgs::Discovery::UNADVERTISE:
98 return "UNADVERTISE";
99 case msgs::Discovery::HEARTBEAT:
100 return "HEARTBEAT";
101 case msgs::Discovery::BYE:
102 return "BYE";
103 case msgs::Discovery::NEW_CONNECTION:
104 return "NEW_CONNECTION";
105 case msgs::Discovery::END_CONNECTION:
106 return "END_CONNECTION";
107 case msgs::Discovery::SUBSCRIBERS_REQ:
108 return "SUBSCRIBERS_REQ";
109 case msgs::Discovery::SUBSCRIBERS_REP:
110 return "SUBSCRIBERS_REP";
111 };
112}
113
114// This is for API compatibility
115inline std::string ToString(const msgs::Discovery::Type &_t)
116{
117 return ConvertDiscoveryType(_t);
118}
119} // namespce
120} // namespace gz::msgs
121
122#endif // GZ_MSGS_CONVERT_DISCOVERYTYPE_HH_