ROS 2 rclcpp + rcl - kilted  kilted
ROS 2 C++ Client Library with ROS Client Library
qos_overriding_options.cpp
1 // Copyright 2020 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "rclcpp/qos_overriding_options.hpp"
16 
17 #include <initializer_list>
18 #include <ostream>
19 #include <stdexcept>
20 #include <string>
21 #include <utility>
22 #include <vector>
23 
24 #include "rmw/qos_policy_kind.h"
25 #include "rmw/qos_string_conversions.h"
26 
27 namespace rclcpp
28 {
29 
30 const char *
31 qos_policy_kind_to_cstr(const QosPolicyKind & qpk)
32 {
33  const char * ret = rmw_qos_policy_kind_to_str(static_cast<rmw_qos_policy_kind_t>(qpk));
34  if (!ret) {
35  throw std::invalid_argument{"unknown QoS policy kind"};
36  }
37  return ret;
38 }
39 
40 std::ostream &
41 operator<<(std::ostream & oss, const QosPolicyKind & qpk)
42 {
43  return oss << qos_policy_kind_to_cstr(qpk);
44 }
45 
46 static std::initializer_list<QosPolicyKind> kDefaultPolicies =
47 {QosPolicyKind::History, QosPolicyKind::Depth, QosPolicyKind::Reliability};
48 
50  std::initializer_list<QosPolicyKind> policy_kinds,
51  QosCallback validation_callback,
52  std::string id)
53 : id_{std::move(id)},
54  policy_kinds_{policy_kinds},
55  validation_callback_{std::move(validation_callback)}
56 {}
57 
60  QosCallback validation_callback,
61  std::string id)
62 {
63  return QosOverridingOptions{kDefaultPolicies, validation_callback, id};
64 }
65 
66 const std::string &
67 QosOverridingOptions::get_id() const
68 {
69  return id_;
70 }
71 
72 const std::vector<QosPolicyKind> &
73 QosOverridingOptions::get_policy_kinds() const
74 {
75  return policy_kinds_;
76 }
77 
78 const QosCallback &
79 QosOverridingOptions::get_validation_callback() const
80 {
81  return validation_callback_;
82 }
83 
84 } // namespace rclcpp
Options that are passed in subscription/publisher constructor to specify QoSConfigurability.
RCLCPP_PUBLIC QosOverridingOptions()=default
Default constructor, no overrides allowed.
static RCLCPP_PUBLIC QosOverridingOptions with_default_policies(QosCallback validation_callback=nullptr, std::string id={})
Construct passing a list of QoS policies and a verification callback.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
RCLCPP_PUBLIC std::ostream & operator<<(std::ostream &os, const FutureReturnCode &future_return_code)
Stream operator for FutureReturnCode.