Gazebo Msgs

API Reference

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