Skip to content

Commit b8173e2

Browse files
authored
Dynamic Subscription (REP-2011 Subset): Stubs for rclcpp (#2165)
* Implement subscription base changes * Add stubbed out classes Signed-off-by: methylDragon <[email protected]>
1 parent 3088b53 commit b8173e2

20 files changed

+902
-73
lines changed

rclcpp/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ set(${PROJECT_NAME}_SRCS
4949
src/rclcpp/detail/rmw_implementation_specific_subscription_payload.cpp
5050
src/rclcpp/detail/utilities.cpp
5151
src/rclcpp/duration.cpp
52+
src/rclcpp/dynamic_typesupport/dynamic_message.cpp
53+
src/rclcpp/dynamic_typesupport/dynamic_message_type.cpp
54+
src/rclcpp/dynamic_typesupport/dynamic_message_type_builder.cpp
55+
src/rclcpp/dynamic_typesupport/dynamic_message_type_support.cpp
56+
src/rclcpp/dynamic_typesupport/dynamic_serialization_support.cpp
5257
src/rclcpp/event.cpp
5358
src/rclcpp/exceptions/exceptions.cpp
5459
src/rclcpp/executable_list.cpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright 2023 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+
#ifndef RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_MESSAGE_HPP_
16+
#define RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_MESSAGE_HPP_
17+
18+
#include <rcl/allocator.h>
19+
#include <rcl/types.h>
20+
#include <rosidl_dynamic_typesupport/types.h>
21+
22+
#include <memory>
23+
#include <string>
24+
25+
#include "rclcpp/dynamic_typesupport/dynamic_message_type.hpp"
26+
#include "rclcpp/dynamic_typesupport/dynamic_serialization_support.hpp"
27+
#include "rclcpp/macros.hpp"
28+
#include "rclcpp/visibility_control.hpp"
29+
30+
namespace rclcpp
31+
{
32+
namespace dynamic_typesupport
33+
{
34+
35+
/// Utility wrapper class for rosidl_dynamic_typesupport_dynamic_data_t
36+
/// STUBBED OUT
37+
class DynamicMessage : public std::enable_shared_from_this<DynamicMessage>
38+
{
39+
public:
40+
RCLCPP_SMART_PTR_ALIASES_ONLY(DynamicMessage)
41+
42+
RCLCPP_PUBLIC
43+
virtual ~DynamicMessage();
44+
45+
protected:
46+
// NOTE(methylDragon):
47+
// This is just here to extend the lifetime of the serialization support
48+
// It isn't actually used by the builder since the builder should compose its own support
49+
//
50+
// ... Though ideally it should be the exact same support as the one stored in the
51+
// DynamicSerializationSupport
52+
DynamicSerializationSupport::SharedPtr serialization_support_;
53+
54+
rosidl_dynamic_typesupport_dynamic_data_t rosidl_dynamic_data_;
55+
bool is_loaned_;
56+
57+
// Used for returning the loaned value, and lifetime management
58+
DynamicMessage::SharedPtr parent_data_;
59+
60+
private:
61+
RCLCPP_DISABLE_COPY(DynamicMessage)
62+
63+
RCLCPP_PUBLIC
64+
DynamicMessage();
65+
};
66+
67+
} // namespace dynamic_typesupport
68+
} // namespace rclcpp
69+
70+
#endif // RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_MESSAGE_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2023 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+
#ifndef RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_MESSAGE_TYPE_HPP_
16+
#define RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_MESSAGE_TYPE_HPP_
17+
18+
#include <rcl/allocator.h>
19+
#include <rosidl_dynamic_typesupport/types.h>
20+
21+
#include <memory>
22+
#include <string>
23+
24+
#include "rclcpp/dynamic_typesupport/dynamic_serialization_support.hpp"
25+
#include "rclcpp/macros.hpp"
26+
#include "rclcpp/visibility_control.hpp"
27+
28+
namespace rclcpp
29+
{
30+
namespace dynamic_typesupport
31+
{
32+
33+
/// Utility wrapper class for `rosidl_dynamic_typesupport_dynamic_type_t`
34+
/// STUBBED OUT
35+
class DynamicMessageType : public std::enable_shared_from_this<DynamicMessageType>
36+
{
37+
public:
38+
RCLCPP_SMART_PTR_ALIASES_ONLY(DynamicMessageType)
39+
40+
RCLCPP_PUBLIC
41+
virtual ~DynamicMessageType();
42+
43+
protected:
44+
// NOTE(methylDragon):
45+
// This is just here to extend the lifetime of the serialization support
46+
// It isn't actually used by the builder since the builder should compose its own support
47+
//
48+
// ... Though ideally it should be the exact same support as the one stored in the
49+
// `DynamicSerializationSupport`
50+
DynamicSerializationSupport::SharedPtr serialization_support_;
51+
52+
rosidl_dynamic_typesupport_dynamic_type_t rosidl_dynamic_type_;
53+
54+
private:
55+
RCLCPP_DISABLE_COPY(DynamicMessageType)
56+
57+
RCLCPP_PUBLIC
58+
DynamicMessageType();
59+
};
60+
61+
} // namespace dynamic_typesupport
62+
} // namespace rclcpp
63+
64+
#endif // RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_MESSAGE_TYPE_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2023 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+
#ifndef RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_MESSAGE_TYPE_BUILDER_HPP_
16+
#define RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_MESSAGE_TYPE_BUILDER_HPP_
17+
18+
#include <rcl/allocator.h>
19+
#include <rosidl_dynamic_typesupport/types.h>
20+
21+
#include <memory>
22+
#include <string>
23+
24+
#include "rclcpp/dynamic_typesupport/dynamic_serialization_support.hpp"
25+
#include "rclcpp/macros.hpp"
26+
#include "rclcpp/visibility_control.hpp"
27+
28+
namespace rclcpp
29+
{
30+
namespace dynamic_typesupport
31+
{
32+
33+
/// Utility wrapper class for `rosidl_dynamic_typesupport_dynamic_type_builder_t *`
34+
/// STUBBED OUT
35+
class DynamicMessageTypeBuilder : public std::enable_shared_from_this<DynamicMessageTypeBuilder>
36+
{
37+
public:
38+
RCLCPP_SMART_PTR_ALIASES_ONLY(DynamicMessageTypeBuilder)
39+
40+
RCLCPP_PUBLIC
41+
virtual ~DynamicMessageTypeBuilder();
42+
43+
protected:
44+
// NOTE(methylDragon):
45+
// This is just here to extend the lifetime of the serialization support
46+
// It isn't actually used by the builder since the builder should compose its own support
47+
//
48+
// ... Though ideally it should be the exact same support as the one stored in the
49+
// `DynamicSerializationSupport`
50+
DynamicSerializationSupport::SharedPtr serialization_support_;
51+
52+
rosidl_dynamic_typesupport_dynamic_type_builder_t rosidl_dynamic_type_builder_;
53+
54+
private:
55+
RCLCPP_DISABLE_COPY(DynamicMessageTypeBuilder)
56+
57+
RCLCPP_PUBLIC
58+
DynamicMessageTypeBuilder();
59+
};
60+
61+
} // namespace dynamic_typesupport
62+
} // namespace rclcpp
63+
64+
65+
#endif // RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_MESSAGE_TYPE_BUILDER_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2023 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+
#ifndef RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_MESSAGE_TYPE_SUPPORT_HPP_
16+
#define RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_MESSAGE_TYPE_SUPPORT_HPP_
17+
18+
#include <rcl/allocator.h>
19+
20+
#include <rosidl_dynamic_typesupport/dynamic_message_type_support_struct.h>
21+
#include <rosidl_dynamic_typesupport/types.h>
22+
#include <rosidl_runtime_c/message_type_support_struct.h>
23+
#include <rosidl_runtime_c/type_description/type_description__struct.h>
24+
25+
#include <memory>
26+
#include <string>
27+
28+
#include "rclcpp/dynamic_typesupport/dynamic_message.hpp"
29+
#include "rclcpp/dynamic_typesupport/dynamic_message_type.hpp"
30+
#include "rclcpp/dynamic_typesupport/dynamic_serialization_support.hpp"
31+
32+
#include "rclcpp/macros.hpp"
33+
#include "rclcpp/visibility_control.hpp"
34+
35+
namespace rclcpp
36+
{
37+
namespace dynamic_typesupport
38+
{
39+
40+
/// Utility wrapper class for `rosidl_message_type_support_t` containing managed
41+
/// STUBBED OUT
42+
class DynamicMessageTypeSupport : public std::enable_shared_from_this<DynamicMessageTypeSupport>
43+
{
44+
public:
45+
RCLCPP_SMART_PTR_ALIASES_ONLY(DynamicMessageTypeSupport)
46+
47+
RCLCPP_PUBLIC
48+
virtual ~DynamicMessageTypeSupport();
49+
50+
protected:
51+
DynamicSerializationSupport::SharedPtr serialization_support_;
52+
DynamicMessageType::SharedPtr dynamic_message_type_;
53+
DynamicMessage::SharedPtr dynamic_message_;
54+
55+
rosidl_message_type_support_t rosidl_message_type_support_;
56+
57+
private:
58+
RCLCPP_DISABLE_COPY(DynamicMessageTypeSupport)
59+
60+
RCLCPP_PUBLIC
61+
DynamicMessageTypeSupport();
62+
};
63+
64+
} // namespace dynamic_typesupport
65+
} // namespace rclcpp
66+
67+
#endif // RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_MESSAGE_TYPE_SUPPORT_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2023 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+
#ifndef RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_SERIALIZATION_SUPPORT_HPP_
16+
#define RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_SERIALIZATION_SUPPORT_HPP_
17+
18+
#include <rcl/allocator.h>
19+
#include <rosidl_dynamic_typesupport/api/serialization_support.h>
20+
#include <rosidl_dynamic_typesupport/types.h>
21+
22+
#include <memory>
23+
#include <string>
24+
25+
#include "rclcpp/macros.hpp"
26+
#include "rclcpp/visibility_control.hpp"
27+
28+
namespace rclcpp
29+
{
30+
namespace dynamic_typesupport
31+
{
32+
33+
/// Utility wrapper class for rosidl_dynamic_typesupport_serialization_support_t
34+
class DynamicSerializationSupport : public std::enable_shared_from_this<DynamicSerializationSupport>
35+
{
36+
public:
37+
RCLCPP_SMART_PTR_ALIASES_ONLY(DynamicSerializationSupport)
38+
39+
RCLCPP_PUBLIC
40+
explicit DynamicSerializationSupport(rcl_allocator_t allocator = rcl_get_default_allocator());
41+
42+
RCLCPP_PUBLIC
43+
DynamicSerializationSupport(
44+
const std::string & serialization_library_name,
45+
rcl_allocator_t allocator = rcl_get_default_allocator());
46+
47+
RCLCPP_PUBLIC
48+
virtual ~DynamicSerializationSupport();
49+
50+
protected:
51+
rosidl_dynamic_typesupport_serialization_support_t rosidl_serialization_support_;
52+
53+
private:
54+
RCLCPP_DISABLE_COPY(DynamicSerializationSupport)
55+
};
56+
57+
} // namespace dynamic_typesupport
58+
} // namespace rclcpp
59+
60+
#endif // RCLCPP__DYNAMIC_TYPESUPPORT__DYNAMIC_SERIALIZATION_SUPPORT_HPP_

rclcpp/include/rclcpp/generic_subscription.hpp

+26-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class GenericSubscription : public rclcpp::SubscriptionBase
8484
options.to_rcl_subscription_options(qos),
8585
options.event_callbacks,
8686
options.use_default_callbacks,
87-
true),
87+
SubscriptionType::SERIALIZED_MESSAGE),
8888
callback_(callback),
8989
ts_lib_(ts_lib)
9090
{}
@@ -123,6 +123,31 @@ class GenericSubscription : public rclcpp::SubscriptionBase
123123
RCLCPP_PUBLIC
124124
void return_serialized_message(std::shared_ptr<rclcpp::SerializedMessage> & message) override;
125125

126+
127+
// DYNAMIC TYPE ==================================================================================
128+
RCLCPP_PUBLIC
129+
rclcpp::dynamic_typesupport::DynamicMessageType::SharedPtr get_shared_dynamic_message_type()
130+
override;
131+
132+
RCLCPP_PUBLIC
133+
rclcpp::dynamic_typesupport::DynamicMessage::SharedPtr get_shared_dynamic_message() override;
134+
135+
RCLCPP_PUBLIC
136+
rclcpp::dynamic_typesupport::DynamicSerializationSupport::SharedPtr
137+
get_shared_dynamic_serialization_support() override;
138+
139+
RCLCPP_PUBLIC
140+
rclcpp::dynamic_typesupport::DynamicMessage::SharedPtr create_dynamic_message() override;
141+
142+
RCLCPP_PUBLIC
143+
void return_dynamic_message(
144+
rclcpp::dynamic_typesupport::DynamicMessage::SharedPtr & message) override;
145+
146+
RCLCPP_PUBLIC
147+
void handle_dynamic_message(
148+
const rclcpp::dynamic_typesupport::DynamicMessage::SharedPtr & message,
149+
const rclcpp::MessageInfo & message_info) override;
150+
126151
private:
127152
RCLCPP_DISABLE_COPY(GenericSubscription)
128153

0 commit comments

Comments
 (0)