forked from ros2/rosbag2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow an arbitrary topic to be recorded (ros2#26)
* ros2GH-52 Extend db schema to include topic meta data - Two table db layout (messages and topics) - Messages table references topics table but without foreign key for improved write performance - Create_topic must be called for every topic prior to storing a message of this topic. - Sqlite_storage caches all known topics - At least for now the type information is stored as a simple string. * ros2GH-54 Make first rcl subscription prototype work * ros2GH-54 find type name from topic * ros2GH-54 Publish messages from database knowing only topic name and pass topic name by terminal * ros2GH-54 Refactoring of typesupport helpers * ros2GH-54 Use c++ typesupport * ros2GH-54 Use cpp typesupport and rclcpp::Node for publisher * ros2GH-54 Add raw subscription and use in rosbag_record * ros2GH-54 Add Rosbag2Node and Rosbag2Publisher classes and use them in Rosbag2::play * ros2GH-54 Rename Rosbag2Publisher to RawPublisher * ros2GH-54 Minor refactoring of Rosbag2Node * ros2GH-54 Extract and test waiting for topic into its own method * ros2GH-54 Fix read integration tests and linters * ros2GH-55 Refactor Rosbag2Node::create_raw_publisher() * ros2GH-54 Add subscription method to rosbag node * ros2GH-54 Keep subscription alive * ros2GH-54: Extract subscription to correct class * ros2GH-55 Change interface of raw_publisher to match subscriber * ros2GH-54 Add test for rosbag node * ros2GH-54 Unfriend rclcpp class * ros2GH-54 Make test more robust * ros2GH-54 Fix build * ros2GH-54 Minor cleanup and documentation * ros2GH-55 Minor refactoring + TODO comment * ros2GH-54 Change dynamic library folder on Windows * ros2GH-54 Fix build * ros2GH-54 Add shutdown to test * ros2GH-55 Add test helpers methods for usage in multiple tests * ros2GH-55 Add new method to read all topics and types in BaseReadInterface and use it in Rosbag2::play * ros2GH-55 Fix gcc and msvc * ros2GH-54 Rename raw to generic in publisher/subscriber * ros2GH-55 Check that topic and associated type in bag file are well defined before playing back messages * ros2GH-54 Prevent unnecessary error message loading storage * ros2GH-54 Fix memory leak * ros2GH-54 stabilize node test * ros2GH-55 Check if database exists when opening storage with READ_ONLY flag * ros2GH-54 Minor cleanup of subscriber * ros2GH-54 Wait a small amount of time to let node discover other nodes * Add logging to false case * ros2GH-54 Catch exceptions and exit cleanly * Use rmw_serialized_message_t and rcutils_char_array_t consistently * ros2GH-4 Refactoring for correctness - pass a few strings as const reference - throw error when no topics could be found * Improve error messages when loading plugins * alphabetical order * type_id -> type
- Loading branch information
1 parent
3f77b33
commit bdd7fd1
Showing
34 changed files
with
1,191 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2018, Bosch Software Innovations GmbH. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "generic_publisher.hpp" | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
namespace rosbag2 | ||
{ | ||
|
||
GenericPublisher::GenericPublisher( | ||
rclcpp::node_interfaces::NodeBaseInterface * node_base, | ||
const std::string & topic, | ||
const rosidl_message_type_support_t & type_support) | ||
: rclcpp::PublisherBase(node_base, topic, type_support, rcl_publisher_get_default_options()) | ||
{} | ||
|
||
void GenericPublisher::publish(std::shared_ptr<rmw_serialized_message_t> message) | ||
{ | ||
auto return_code = rcl_publish_serialized_message( | ||
get_publisher_handle(), message.get()); | ||
|
||
if (return_code != RCL_RET_OK) { | ||
rclcpp::exceptions::throw_from_rcl_error(return_code, "failed to publish serialized message"); | ||
} | ||
} | ||
|
||
} // namespace rosbag2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2018, Bosch Software Innovations GmbH. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef ROSBAG2__GENERIC_PUBLISHER_HPP_ | ||
#define ROSBAG2__GENERIC_PUBLISHER_HPP_ | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "rclcpp/rclcpp.hpp" | ||
|
||
namespace rosbag2 | ||
{ | ||
|
||
class GenericPublisher : public rclcpp::PublisherBase | ||
{ | ||
public: | ||
GenericPublisher( | ||
rclcpp::node_interfaces::NodeBaseInterface * node_base, | ||
const std::string & topic, | ||
const rosidl_message_type_support_t & type_support); | ||
|
||
~GenericPublisher() override = default; | ||
|
||
void publish(std::shared_ptr<rmw_serialized_message_t> message); | ||
}; | ||
|
||
} // namespace rosbag2 | ||
|
||
#endif // ROSBAG2__GENERIC_PUBLISHER_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Copyright 2018, Bosch Software Innovations GmbH. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "generic_subscription.hpp" | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "rclcpp/any_subscription_callback.hpp" | ||
#include "rclcpp/subscription.hpp" | ||
|
||
namespace rosbag2 | ||
{ | ||
|
||
GenericSubscription::GenericSubscription( | ||
std::shared_ptr<rcl_node_t> node_handle, | ||
const rosidl_message_type_support_t & ts, | ||
const std::string & topic_name, | ||
std::function<void(std::shared_ptr<rcutils_char_array_t>)> callback) | ||
: SubscriptionBase( | ||
node_handle, | ||
ts, | ||
topic_name, | ||
rcl_subscription_get_default_options(), | ||
true), | ||
default_allocator_(rcutils_get_default_allocator()), | ||
callback_(callback) | ||
{} | ||
|
||
std::shared_ptr<void> GenericSubscription::create_message() | ||
{ | ||
return create_serialized_message(); | ||
} | ||
|
||
std::shared_ptr<rmw_serialized_message_t> GenericSubscription::create_serialized_message() | ||
{ | ||
return borrow_serialized_message(0); | ||
} | ||
|
||
|
||
void GenericSubscription::handle_message( | ||
std::shared_ptr<void> & message, const rmw_message_info_t & message_info) | ||
{ | ||
(void) message_info; | ||
auto typed_message = std::static_pointer_cast<rcutils_char_array_t>(message); | ||
callback_(typed_message); | ||
} | ||
|
||
void GenericSubscription::return_message(std::shared_ptr<void> & message) | ||
{ | ||
auto typed_message = std::static_pointer_cast<rcutils_char_array_t>(message); | ||
return_serialized_message(typed_message); | ||
} | ||
|
||
void GenericSubscription::return_serialized_message( | ||
std::shared_ptr<rmw_serialized_message_t> & message) | ||
{ | ||
message.reset(); | ||
} | ||
|
||
void GenericSubscription::handle_intra_process_message( | ||
rcl_interfaces::msg::IntraProcessMessage & ipm, | ||
const rmw_message_info_t & message_info) | ||
{ | ||
(void) ipm; | ||
(void) message_info; | ||
throw std::runtime_error("Intra process is not supported"); | ||
} | ||
|
||
const std::shared_ptr<rcl_subscription_t> | ||
GenericSubscription::get_intra_process_subscription_handle() const | ||
{ | ||
return nullptr; | ||
} | ||
|
||
std::shared_ptr<rmw_serialized_message_t> | ||
GenericSubscription::borrow_serialized_message(size_t capacity) | ||
{ | ||
auto message = new rmw_serialized_message_t; | ||
*message = rmw_get_zero_initialized_serialized_message(); | ||
auto init_return = rmw_serialized_message_init(message, capacity, &default_allocator_); | ||
if (init_return != RCL_RET_OK) { | ||
rclcpp::exceptions::throw_from_rcl_error(init_return); | ||
} | ||
|
||
auto serialized_msg = std::shared_ptr<rmw_serialized_message_t>(message, | ||
[](rmw_serialized_message_t * msg) { | ||
auto fini_return = rmw_serialized_message_fini(msg); | ||
delete msg; | ||
if (fini_return != RCL_RET_OK) { | ||
RCUTILS_LOG_ERROR_NAMED( | ||
"rosbag2", | ||
"failed to destroy serialized message: %s", rcl_get_error_string_safe()); | ||
} | ||
}); | ||
|
||
return serialized_msg; | ||
} | ||
|
||
} // namespace rosbag2 |
Oops, something went wrong.