Compare commits
124 Commits
use-rcpput
...
2.3.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ceeff0f0f | ||
|
|
6a1b6a3f38 | ||
|
|
47f21dab3d | ||
|
|
8f2809df64 | ||
|
|
a2004f8369 | ||
|
|
6756ccfb50 | ||
|
|
234b5e423b | ||
|
|
3dddfd7d93 | ||
|
|
b132a2b0cd | ||
|
|
a4fd8ceece | ||
|
|
965b4d2c24 | ||
|
|
bea9c5a8f6 | ||
|
|
3497650ee2 | ||
|
|
17847ee90a | ||
|
|
46ec8bb5df | ||
|
|
4cc446d9a2 | ||
|
|
6820dac315 | ||
|
|
29cfc45e81 | ||
|
|
5607c3242d | ||
|
|
c277b4c8bb | ||
|
|
d65bc667fa | ||
|
|
37415670c6 | ||
|
|
1c22d6b2c4 | ||
|
|
9f2f754029 | ||
|
|
0e8450940f | ||
|
|
7266e67683 | ||
|
|
d04ec4bf80 | ||
|
|
e920175dae | ||
|
|
ed7a23731a | ||
|
|
85235938f6 | ||
|
|
f357033ad7 | ||
|
|
bee4b760fb | ||
|
|
8f2f746b41 | ||
|
|
f1c5524164 | ||
|
|
dec7d8a00f | ||
|
|
730e99b742 | ||
|
|
43df9eff37 | ||
|
|
77aae4019e | ||
|
|
504e68bdab | ||
|
|
5e8fff6549 | ||
|
|
1ae8ca41fb | ||
|
|
b3f50460f4 | ||
|
|
17c53a16f0 | ||
|
|
1b9cf547a4 | ||
|
|
a6b9def7ae | ||
|
|
707f9cfa8e | ||
|
|
ec31b29824 | ||
|
|
77a3c06f2b | ||
|
|
7757f6b402 | ||
|
|
80b2f5439b | ||
|
|
bcce051eb2 | ||
|
|
ee7b8ca5f2 | ||
|
|
2078887a2b | ||
|
|
8808f4b287 | ||
|
|
cb6ac99a49 | ||
|
|
8cc331f38c | ||
|
|
6238b4263b | ||
|
|
ddb43bb3ab | ||
|
|
823163e68e | ||
|
|
55b30fc1e2 | ||
|
|
b49295ceee | ||
|
|
f8da934ac9 | ||
|
|
0a4ff4db3d | ||
|
|
94082318c9 | ||
|
|
f000b53095 | ||
|
|
443fc180c7 | ||
|
|
e700d3becd | ||
|
|
5fd6e2340a | ||
|
|
b451425ce6 | ||
|
|
0312defbc5 | ||
|
|
fb76d4b640 | ||
|
|
e20837bf6a | ||
|
|
420eb01a65 | ||
|
|
9f11b1d6a2 | ||
|
|
d2d4c599e0 | ||
|
|
baea732ec9 | ||
|
|
8be1e76fd8 | ||
|
|
b17c73992a | ||
|
|
954cc3d27f | ||
|
|
efef96e657 | ||
|
|
32ef520434 | ||
|
|
61357c49f7 | ||
|
|
41d5f24425 | ||
|
|
48f956a3e3 | ||
|
|
48d3603018 | ||
|
|
3b1319b23d | ||
|
|
04bccb95cb | ||
|
|
60bcee36ab | ||
|
|
f1283ef4b9 | ||
|
|
7d7d4c3b96 | ||
|
|
623e013f48 | ||
|
|
df036bbe03 | ||
|
|
30e9fae395 | ||
|
|
25286ac1c3 | ||
|
|
c21ddaaf8b | ||
|
|
23ef782e02 | ||
|
|
00b4020194 | ||
|
|
823e1dd404 | ||
|
|
f71d3bfda2 | ||
|
|
cf1be86f5c | ||
|
|
4dcb0eda68 | ||
|
|
9c1cbdf6c7 | ||
|
|
6e6dd9cb1a | ||
|
|
45a47c6448 | ||
|
|
6e408b79f3 | ||
|
|
b843c75ef8 | ||
|
|
cb1b32ee15 | ||
|
|
b67fa594f8 | ||
|
|
8bfc8e631f | ||
|
|
75f3d54d57 | ||
|
|
27e59d930a | ||
|
|
ce5de8757d | ||
|
|
6ea67a4e9f | ||
|
|
5f6bf45202 | ||
|
|
dc528ad710 | ||
|
|
26e824c7c0 | ||
|
|
3a3ba55fa2 | ||
|
|
1745db6dcd | ||
|
|
7ed387f862 | ||
|
|
a10ae56629 | ||
|
|
1f000b8d97 | ||
|
|
c14f46e6f3 | ||
|
|
70e1830ecd | ||
|
|
77564eb2ff |
@@ -2,150 +2,129 @@
|
||||
Changelog for package rclcpp
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
5.1.0 (2020-11-02)
|
||||
2.3.1 (2021-04-14)
|
||||
------------------
|
||||
* Deprecate Duration(rcl_duration_value_t) in favor of static Duration::from_nanoseconds(rcl_duration_value_t) (`#1432 <https://github.com/ros2/rclcpp/issues/1432>`_)
|
||||
* Avoid parsing arguments twice in `rclcpp::init_and_remove_ros_arguments` (`#1415 <https://github.com/ros2/rclcpp/issues/1415>`_)
|
||||
* Update quality declaration links (re: `ros2/docs.ros2.org#52 <https://github.com/ros2/docs.ros2.org/issues/52>`_) (`#1616 <https://github.com/ros2/rclcpp/issues/1616>`_)
|
||||
* Fix documented example in create_publisher (`#1558 <https://github.com/ros2/rclcpp/issues/1558>`_) (`#1559 <https://github.com/ros2/rclcpp/issues/1559>`_)
|
||||
* Fix runtime error: reference binding to null pointer of type (`#1547 <https://github.com/ros2/rclcpp/issues/1547>`_) (`#1548 <https://github.com/ros2/rclcpp/issues/1548>`_)
|
||||
* Contributors: Jacob Perron, Simon Honigmann, Tomoya Fujita
|
||||
|
||||
2.3.0 (2020-12-09)
|
||||
------------------
|
||||
* Update QD to QL 1 (`#1480 <https://github.com/ros2/rclcpp/issues/1480>`_)
|
||||
* Add performance tests for parameter transport (`#1470 <https://github.com/ros2/rclcpp/issues/1470>`_)
|
||||
* Add benchmarks for node parameters interface (`#1470 <https://github.com/ros2/rclcpp/issues/1470>`_)
|
||||
* Fix NodeOptions copy constructor (`#1376 <https://github.com/ros2/rclcpp/issues/1376>`_) (`#1451 <https://github.com/ros2/rclcpp/issues/1451>`_)
|
||||
* Avoid reference cycle to fix memory leak (`#1301 <https://github.com/ros2/rclcpp/issues/1301>`_) (`#1450 <https://github.com/ros2/rclcpp/issues/1450>`_)
|
||||
* Bump rclcpp packages to Quality Level 2 (`#1445 <https://github.com/ros2/rclcpp/issues/1445>`_) (`#1446 <https://github.com/ros2/rclcpp/issues/1446>`_)
|
||||
* Added executor benchmark tests (`#1413 <https://github.com/ros2/rclcpp/issues/1413>`_)
|
||||
* Add service and client benchmarks (`#1425 <https://github.com/ros2/rclcpp/issues/1425>`_)
|
||||
* Set CMakeLists to only use default rmw for benchmarks (`#1427 <https://github.com/ros2/rclcpp/issues/1427>`_)
|
||||
* Update tracetools' QL in rclcpp's QD (`#1428 <https://github.com/ros2/rclcpp/issues/1428>`_)
|
||||
* Add missing locking to the rclcpp_action::ServerBase. (`#1421 <https://github.com/ros2/rclcpp/issues/1421>`_)
|
||||
* Initial benchmark tests for rclcpp::init/shutdown create/destroy node (`#1411 <https://github.com/ros2/rclcpp/issues/1411>`_)
|
||||
* Refactor test CMakeLists in prep for benchmarks (`#1422 <https://github.com/ros2/rclcpp/issues/1422>`_)
|
||||
* Add methods in topic and service interface to resolve a name (`#1410 <https://github.com/ros2/rclcpp/issues/1410>`_)
|
||||
* Update deprecated gtest macros (`#1370 <https://github.com/ros2/rclcpp/issues/1370>`_)
|
||||
* Use global namespace for parameter events subscription topic (`#1257 <https://github.com/ros2/rclcpp/issues/1257>`_) (`#1261 <https://github.com/ros2/rclcpp/issues/1261>`_)
|
||||
* Refactor test CMakeLists.txt (`#1422 <https://github.com/ros2/rclcpp/issues/1422>`_) and moving rosidl_generate_interfaces_call (`#1424 <https://github.com/ros2/rclcpp/issues/1424>`_) (`#1437 <https://github.com/ros2/rclcpp/issues/1437>`_)
|
||||
* Update tracetools' QL in rclcpp's QD (`#1428 <https://github.com/ros2/rclcpp/issues/1428>`_) (`#1430 <https://github.com/ros2/rclcpp/issues/1430>`_)
|
||||
* Add coverage statement (`#1367 <https://github.com/ros2/rclcpp/issues/1367>`_)
|
||||
* Update tracetools' QL to 2 in rclcpp's QD (`#1187 <https://github.com/ros2/rclcpp/issues/1187>`_)
|
||||
* Fix reference to rclcpp in its QD (`#1161 <https://github.com/ros2/rclcpp/issues/1161>`_)
|
||||
* Clear members for StaticExecutorEntitiesCollector to avoid shared_ptr dependency (`#1303 <https://github.com/ros2/rclcpp/issues/1303>`_)
|
||||
* Increase test timeouts of slow running tests with rmw_connext_cpp (`#1400 <https://github.com/ros2/rclcpp/issues/1400>`_)
|
||||
* Avoid self dependency that not destoryed (`#1301 <https://github.com/ros2/rclcpp/issues/1301>`_)
|
||||
* Update maintainers (`#1384 <https://github.com/ros2/rclcpp/issues/1384>`_)
|
||||
* Add clock qos to node options (`#1375 <https://github.com/ros2/rclcpp/issues/1375>`_)
|
||||
* Fix NodeOptions copy constructor (`#1376 <https://github.com/ros2/rclcpp/issues/1376>`_)
|
||||
* Make sure to clean the external client/service handle. (`#1296 <https://github.com/ros2/rclcpp/issues/1296>`_)
|
||||
* Increase coverage of WaitSetTemplate (`#1368 <https://github.com/ros2/rclcpp/issues/1368>`_)
|
||||
* Increase coverage of guard_condition.cpp to 100% (`#1369 <https://github.com/ros2/rclcpp/issues/1369>`_)
|
||||
* Add coverage statement (`#1367 <https://github.com/ros2/rclcpp/issues/1367>`_)
|
||||
* Tests for LoanedMessage with mocked loaned message publisher (`#1366 <https://github.com/ros2/rclcpp/issues/1366>`_)
|
||||
* Add unit tests for qos and qos_event files (`#1352 <https://github.com/ros2/rclcpp/issues/1352>`_)
|
||||
* Finish coverage of publisher API (`#1365 <https://github.com/ros2/rclcpp/issues/1365>`_)
|
||||
* Finish API coverage on executors. (`#1364 <https://github.com/ros2/rclcpp/issues/1364>`_)
|
||||
* Finish API coverage on executors (`#1364 <https://github.com/ros2/rclcpp/issues/1364>`_)
|
||||
* Only exchange intra_process waitable if nonnull (`#1317 <https://github.com/ros2/rclcpp/issues/1317>`_)
|
||||
* Add test for ParameterService (`#1355 <https://github.com/ros2/rclcpp/issues/1355>`_)
|
||||
* Add time API coverage tests (`#1347 <https://github.com/ros2/rclcpp/issues/1347>`_)
|
||||
* Add timer coverage tests (`#1363 <https://github.com/ros2/rclcpp/issues/1363>`_)
|
||||
* Add in additional tests for parameter_client.cpp coverage.
|
||||
* Minor fixes to the parameter_service.cpp file.
|
||||
* reset rcl_context shared_ptr after calling rcl_init sucessfully (`#1357 <https://github.com/ros2/rclcpp/issues/1357>`_)
|
||||
* Improved test publisher - zero qos history depth value exception (`#1360 <https://github.com/ros2/rclcpp/issues/1360>`_)
|
||||
* Improve test publisher - zero qos history depth value exception (`#1360 <https://github.com/ros2/rclcpp/issues/1360>`_)
|
||||
* Covered resolve_use_intra_process (`#1359 <https://github.com/ros2/rclcpp/issues/1359>`_)
|
||||
* Improve test_subscription_options (`#1358 <https://github.com/ros2/rclcpp/issues/1358>`_)
|
||||
* Add in more tests for init_options coverage. (`#1353 <https://github.com/ros2/rclcpp/issues/1353>`_)
|
||||
* Add in more tests for init_options coverage (`#1353 <https://github.com/ros2/rclcpp/issues/1353>`_)
|
||||
* Test the remaining node public API (`#1342 <https://github.com/ros2/rclcpp/issues/1342>`_)
|
||||
* Complete coverage of Parameter and ParameterValue API (`#1344 <https://github.com/ros2/rclcpp/issues/1344>`_)
|
||||
* Add in more tests for the utilities. (`#1349 <https://github.com/ros2/rclcpp/issues/1349>`_)
|
||||
* Add in two more tests for expand_topic_or_service_name. (`#1350 <https://github.com/ros2/rclcpp/issues/1350>`_)
|
||||
* Add in more tests for the utilities (`#1349 <https://github.com/ros2/rclcpp/issues/1349>`_)
|
||||
* Add in two more tests for expand_topic_or_service_name (`#1350 <https://github.com/ros2/rclcpp/issues/1350>`_)
|
||||
* Add tests for node_options API (`#1343 <https://github.com/ros2/rclcpp/issues/1343>`_)
|
||||
* Add in more coverage for expand_topic_or_service_name. (`#1346 <https://github.com/ros2/rclcpp/issues/1346>`_)
|
||||
* Test exception in spin_until_future_complete. (`#1345 <https://github.com/ros2/rclcpp/issues/1345>`_)
|
||||
* Add coverage tests graph_listener (`#1330 <https://github.com/ros2/rclcpp/issues/1330>`_)
|
||||
* Add in unit tests for the Executor class.
|
||||
* Allow mimick patching of methods with up to 9 arguments.
|
||||
* Improve the error messages in the Executor class.
|
||||
* Add executor unit tests `#1336 <https://github.com/ros2/rclcpp/issues/1336>`_ (`#1395 <https://github.com/ros2/rclcpp/issues/1395>`_)
|
||||
* Add coverage for client API (`#1329 <https://github.com/ros2/rclcpp/issues/1329>`_)
|
||||
* Increase service coverage (`#1332 <https://github.com/ros2/rclcpp/issues/1332>`_)
|
||||
* Make more of the static entity collector API private.
|
||||
* Const-ify more of the static executor.
|
||||
* Add more tests for the static single threaded executor.
|
||||
* Many more tests for the static_executor_entities_collector.
|
||||
* Get one more line of code coverage in memory_strategy.cpp
|
||||
* Bugfix when adding callback group.
|
||||
* Fix typos in comments.
|
||||
* Remove deprecated executor::FutureReturnCode APIs. (`#1327 <https://github.com/ros2/rclcpp/issues/1327>`_)
|
||||
* Add ostream test for FutureReturnCode (`#1327 <https://github.com/ros2/rclcpp/issues/1327>`_) (`#1393 <https://github.com/ros2/rclcpp/issues/1393>`_)
|
||||
* Increase coverage of publisher/subscription API (`#1325 <https://github.com/ros2/rclcpp/issues/1325>`_)
|
||||
* Not finalize guard condition while destructing SubscriptionIntraProcess (`#1307 <https://github.com/ros2/rclcpp/issues/1307>`_)
|
||||
* Expose qos setting for /rosout (`#1247 <https://github.com/ros2/rclcpp/issues/1247>`_)
|
||||
* Add coverage for missing API (except executors) (`#1326 <https://github.com/ros2/rclcpp/issues/1326>`_)
|
||||
* Include topic name in QoS mismatch warning messages (`#1286 <https://github.com/ros2/rclcpp/issues/1286>`_)
|
||||
* Add coverage tests context functions (`#1321 <https://github.com/ros2/rclcpp/issues/1321>`_)
|
||||
* Increase coverage of node_interfaces, including with mocking rcl errors (`#1322 <https://github.com/ros2/rclcpp/issues/1322>`_)
|
||||
* Contributors: Ada-King, Alejandro Hernández Cordero, Audrow Nash, Barry Xu, Chen Lihui, Chris Lalancette, Christophe Bedard, Ivan Santiago Paunovic, Jorge Perez, Morgan Quigley, brawner
|
||||
|
||||
5.0.0 (2020-09-18)
|
||||
------------------
|
||||
* Make node_graph::count_graph_users() const (`#1320 <https://github.com/ros2/rclcpp/issues/1320>`_)
|
||||
* Add coverage for wait_set_policies (`#1316 <https://github.com/ros2/rclcpp/issues/1316>`_)
|
||||
* Only exchange intra_process waitable if nonnull (`#1317 <https://github.com/ros2/rclcpp/issues/1317>`_)
|
||||
* Check waitable for nullptr during constructor (`#1315 <https://github.com/ros2/rclcpp/issues/1315>`_)
|
||||
* Call vector.erase with end iterator overload (`#1314 <https://github.com/ros2/rclcpp/issues/1314>`_)
|
||||
* Use best effort, keep last, history depth 1 QoS Profile for '/clock' subscriptions (`#1312 <https://github.com/ros2/rclcpp/issues/1312>`_)
|
||||
* Add tests type_support module (`#1308 <https://github.com/ros2/rclcpp/issues/1308>`_)
|
||||
* Replace std_msgs with test_msgs in executors test (`#1310 <https://github.com/ros2/rclcpp/issues/1310>`_)
|
||||
* Add set_level for rclcpp::Logger (`#1284 <https://github.com/ros2/rclcpp/issues/1284>`_)
|
||||
* Remove unused private function (rclcpp::Node and rclcpp_lifecycle::Node) (`#1294 <https://github.com/ros2/rclcpp/issues/1294>`_)
|
||||
* Adding tests basic getters (`#1291 <https://github.com/ros2/rclcpp/issues/1291>`_)
|
||||
* Adding callback groups in executor (`#1218 <https://github.com/ros2/rclcpp/issues/1218>`_)
|
||||
* Refactor Subscription Topic Statistics Tests (`#1281 <https://github.com/ros2/rclcpp/issues/1281>`_)
|
||||
* Add operator!= for duration (`#1236 <https://github.com/ros2/rclcpp/issues/1236>`_)
|
||||
* Fix clock thread issue (`#1266 <https://github.com/ros2/rclcpp/issues/1266>`_) (`#1267 <https://github.com/ros2/rclcpp/issues/1267>`_)
|
||||
* Fix topic stats test, wait for more messages, only check the ones with samples (`#1274 <https://github.com/ros2/rclcpp/issues/1274>`_)
|
||||
* Add get_domain_id method to rclcpp::Context (`#1271 <https://github.com/ros2/rclcpp/issues/1271>`_)
|
||||
* Fixes for unit tests that fail under cyclonedds (`#1270 <https://github.com/ros2/rclcpp/issues/1270>`_)
|
||||
* initialize_logging\_ should be copied (`#1272 <https://github.com/ros2/rclcpp/issues/1272>`_)
|
||||
* Use static_cast instead of C-style cast for instrumentation (`#1263 <https://github.com/ros2/rclcpp/issues/1263>`_)
|
||||
* Make parameter clients use template constructors (`#1249 <https://github.com/ros2/rclcpp/issues/1249>`_)
|
||||
* Ability to configure domain_id via InitOptions. (`#1165 <https://github.com/ros2/rclcpp/issues/1165>`_)
|
||||
* Ability to configure domain_id via InitOptions (`#1165 <https://github.com/ros2/rclcpp/issues/1165>`_)
|
||||
* Simplify and fix allocator memory strategy unit test for connext (`#1252 <https://github.com/ros2/rclcpp/issues/1252>`_)
|
||||
* Use global namespace for parameter events subscription topic (`#1257 <https://github.com/ros2/rclcpp/issues/1257>`_)
|
||||
* Increase timeouts for connext for long tests (`#1253 <https://github.com/ros2/rclcpp/issues/1253>`_)
|
||||
* Adjust test_static_executor_entities_collector for rmw_connext_cpp (`#1251 <https://github.com/ros2/rclcpp/issues/1251>`_)
|
||||
* Fix failing test with Connext since it doesn't wait for discovery (`#1246 <https://github.com/ros2/rclcpp/issues/1246>`_)
|
||||
* Fix node graph test with Connext and CycloneDDS returning actual data (`#1245 <https://github.com/ros2/rclcpp/issues/1245>`_)
|
||||
* Warn about unused result of add_on_set_parameters_callback (`#1238 <https://github.com/ros2/rclcpp/issues/1238>`_)
|
||||
* Unittests for memory strategy files, except allocator_memory_strategy (`#1189 <https://github.com/ros2/rclcpp/issues/1189>`_)
|
||||
* EXPECT_THROW_EQ and ASSERT_THROW_EQ macros for unittests (`#1232 <https://github.com/ros2/rclcpp/issues/1232>`_)
|
||||
* Parameterize test executors for all executor types (`#1222 <https://github.com/ros2/rclcpp/issues/1222>`_) (`#1386 <https://github.com/ros2/rclcpp/issues/1386>`_)
|
||||
* Derive and throw exception in spin_some spin_all for StaticSingleThreadedExecutor (`#1385 <https://github.com/ros2/rclcpp/issues/1385>`_)
|
||||
* Add unit test for static_executor_entities_collector (`#1221 <https://github.com/ros2/rclcpp/issues/1221>`_)
|
||||
* Parameterize test executors for all executor types (`#1222 <https://github.com/ros2/rclcpp/issues/1222>`_)
|
||||
* Unit tests for allocator_memory_strategy.cpp part 2 (`#1198 <https://github.com/ros2/rclcpp/issues/1198>`_)
|
||||
* Unit tests for allocator_memory_strategy.hpp (`#1197 <https://github.com/ros2/rclcpp/issues/1197>`_)
|
||||
* Derive and throw exception in spin_some spin_all for StaticSingleThreadedExecutor (`#1220 <https://github.com/ros2/rclcpp/issues/1220>`_)
|
||||
* Make ring buffer thread-safe (`#1213 <https://github.com/ros2/rclcpp/issues/1213>`_)
|
||||
* Add missing RCLCPP_PUBLIC to ~StaticExecutorEntitiesCollector (`#1227 <https://github.com/ros2/rclcpp/issues/1227>`_)
|
||||
* Document graph functions don't apply remap rules (`#1225 <https://github.com/ros2/rclcpp/issues/1225>`_)
|
||||
* Remove recreation of entities_collector (`#1217 <https://github.com/ros2/rclcpp/issues/1217>`_)
|
||||
* Contributors: Audrow Nash, Chen Lihui, Christophe Bedard, Daisuke Sato, Devin Bonnie, Dirk Thomas, Ivan Santiago Paunovic, Jacob Perron, Jannik Abbenseth, Jorge Perez, Pedro Pena, Shane Loretz, Stephen Brawner, Tomoya Fujita
|
||||
|
||||
4.0.0 (2020-07-09)
|
||||
------------------
|
||||
* Fix rclcpp::NodeOptions::operator= (`#1211 <https://github.com/ros2/rclcpp/issues/1211>`_)
|
||||
* Link against thread library where necessary (`#1210 <https://github.com/ros2/rclcpp/issues/1210>`_)
|
||||
* Unit tests for node interfaces (`#1202 <https://github.com/ros2/rclcpp/issues/1202>`_)
|
||||
* Remove usage of domain id in node options (`#1205 <https://github.com/ros2/rclcpp/issues/1205>`_)
|
||||
* Remove deprecated set_on_parameters_set_callback function (`#1199 <https://github.com/ros2/rclcpp/issues/1199>`_)
|
||||
* Fix conversion of negative durations to messages (`#1188 <https://github.com/ros2/rclcpp/issues/1188>`_)
|
||||
* Fix implementation of NodeOptions::use_global_arguments() (`#1176 <https://github.com/ros2/rclcpp/issues/1176>`_)
|
||||
* Bump to QD to level 3 and fixed links (`#1158 <https://github.com/ros2/rclcpp/issues/1158>`_)
|
||||
* Fix pub/sub count API tests (`#1203 <https://github.com/ros2/rclcpp/issues/1203>`_)
|
||||
* Update tracetools' QL to 2 in rclcpp's QD (`#1187 <https://github.com/ros2/rclcpp/issues/1187>`_)
|
||||
* Fix exception message on rcl_clock_init (`#1182 <https://github.com/ros2/rclcpp/issues/1182>`_)
|
||||
* Throw exception if rcl_timer_init fails (`#1179 <https://github.com/ros2/rclcpp/issues/1179>`_)
|
||||
* Unit tests for some header-only functions/classes (`#1181 <https://github.com/ros2/rclcpp/issues/1181>`_)
|
||||
* Callback should be perfectly-forwarded (`#1183 <https://github.com/ros2/rclcpp/issues/1183>`_)
|
||||
* Add unit tests for logging functionality (`#1184 <https://github.com/ros2/rclcpp/issues/1184>`_)
|
||||
* Add create_publisher include to create_subscription (`#1180 <https://github.com/ros2/rclcpp/issues/1180>`_)
|
||||
* Contributors: Alejandro Hernández Cordero, Christophe Bedard, Claire Wang, Dirk Thomas, Ivan Santiago Paunovic, Johannes Meyer, Michel Hidalgo, Stephen Brawner, tomoya
|
||||
|
||||
3.0.0 (2020-06-18)
|
||||
------------------
|
||||
* Fix rclcpp::NodeOptions::operator= (`#1211 <https://github.com/ros2/rclcpp/issues/1211>`_)
|
||||
* Check period duration in create_wall_timer (`#1178 <https://github.com/ros2/rclcpp/issues/1178>`_)
|
||||
* Fix get_node_time_source_interface() docstring (`#988 <https://github.com/ros2/rclcpp/issues/988>`_)
|
||||
* Add message lost subscription event (`#1164 <https://github.com/ros2/rclcpp/issues/1164>`_)
|
||||
* Add spin_all method to Executor (`#1156 <https://github.com/ros2/rclcpp/issues/1156>`_)
|
||||
* Reorganize test directory and split CMakeLists.txt (`#1173 <https://github.com/ros2/rclcpp/issues/1173>`_)
|
||||
* Throw exception if rcl_timer_init fails (`#1179 <https://github.com/ros2/rclcpp/issues/1179>`_)
|
||||
* Remove finalization of guard_condition from GraphListener::__shutdown() (`#1401 <https://github.com/ros2/rclcpp/issues/1401>`_)
|
||||
* Contributors: Alejandro Hernández Cordero, Chen Lihui, Chris Lalancette, Christophe Bedard, Devin Bonnie, Dirk Thomas, Jacob Perron, Jorge Perez, Louise Poubel, Michel Hidalgo, Scott K Logan, Stephen Brawner, tomoya
|
||||
|
||||
2.2.0 (2020-10-07)
|
||||
------------------
|
||||
* Fix implementation of NodeOptions::use_global_arguments() (`#1176 <https://github.com/ros2/rclcpp/issues/1176>`_) (`#1372 <https://github.com/ros2/rclcpp/issues/1372>`_)
|
||||
* Fix conversion of negative durations to messages (`#1188 <https://github.com/ros2/rclcpp/issues/1188>`_) (`#1371 <https://github.com/ros2/rclcpp/issues/1371>`_)
|
||||
* Call vector.erase with end iterator overload (`#1314 <https://github.com/ros2/rclcpp/issues/1314>`_) (`#1380 <https://github.com/ros2/rclcpp/issues/1380>`_)
|
||||
* Check waitable for nullptr during constructor (`#1315 <https://github.com/ros2/rclcpp/issues/1315>`_) (`#1379 <https://github.com/ros2/rclcpp/issues/1379>`_)
|
||||
* Fix pub/sub count API tests. (`#1203 <https://github.com/ros2/rclcpp/issues/1203>`_) (`#1319 <https://github.com/ros2/rclcpp/issues/1319>`_)
|
||||
* Reorganize test directory and split CMakeLists.txt (`#1173 <https://github.com/ros2/rclcpp/issues/1173>`_) (`#1262 <https://github.com/ros2/rclcpp/issues/1262>`_)
|
||||
* Add operator!= for duration (`#1236 <https://github.com/ros2/rclcpp/issues/1236>`_) (`#1278 <https://github.com/ros2/rclcpp/issues/1278>`_)
|
||||
* Contributors: Ivan Santiago Paunovic, Jacob Perron, Jannik Abbenseth, Johannes Meyer, Michel Hidalgo, Stephen Brawner
|
||||
|
||||
2.1.0 (2020-08-03)
|
||||
------------------
|
||||
* Warn about unused result of add_on_set_parameters_callback (`#1238 <https://github.com/ros2/rclcpp/issues/1238>`_) (`#1244 <https://github.com/ros2/rclcpp/issues/1244>`_)
|
||||
* Add missing RCLCPP_PUBLIC to ~StaticExecutorEntitiesCollector (`#1227 <https://github.com/ros2/rclcpp/issues/1227>`_) (`#1228 <https://github.com/ros2/rclcpp/issues/1228>`_)
|
||||
* Remove recreation of entities_collector (`#1217 <https://github.com/ros2/rclcpp/issues/1217>`_) (`#1224 <https://github.com/ros2/rclcpp/issues/1224>`_)
|
||||
* Contributors: Jacob Perron, brawner
|
||||
|
||||
2.0.2 (2020-07-07)
|
||||
------------------
|
||||
* Link against thread library where necessary (`#1210 <https://github.com/ros2/rclcpp/issues/1210>`_) (`#1214 <https://github.com/ros2/rclcpp/issues/1214>`_)
|
||||
* Fix exception message on rcl_clock_init (`#1182 <https://github.com/ros2/rclcpp/issues/1182>`_) (`#1193 <https://github.com/ros2/rclcpp/issues/1193>`_)
|
||||
* Contributors: Dirk Thomas, tomoya
|
||||
|
||||
2.0.1 (2020-06-23)
|
||||
------------------
|
||||
* Add create_publisher include to create_subscription (`#1180 <https://github.com/ros2/rclcpp/issues/1180>`_) (`#1192 <https://github.com/ros2/rclcpp/issues/1192>`_)
|
||||
* Fix get_node_time_source_interface() docstring (`#988 <https://github.com/ros2/rclcpp/issues/988>`_) (`#1185 <https://github.com/ros2/rclcpp/issues/1185>`_)
|
||||
* Fixed doxygen warnings (`#1163 <https://github.com/ros2/rclcpp/issues/1163>`_) (`#1191 <https://github.com/ros2/rclcpp/issues/1191>`_)
|
||||
* Check if context is valid when looping in spin_some (`#1167 <https://github.com/ros2/rclcpp/issues/1167>`_)
|
||||
* Add check for invalid topic statistics publish period (`#1151 <https://github.com/ros2/rclcpp/issues/1151>`_)
|
||||
* Fix spin_until_future_complete: check spinning value (`#1023 <https://github.com/ros2/rclcpp/issues/1023>`_)
|
||||
* Fix doxygen warnings (`#1163 <https://github.com/ros2/rclcpp/issues/1163>`_)
|
||||
* Fix reference to rclcpp in its Quality declaration (`#1161 <https://github.com/ros2/rclcpp/issues/1161>`_)
|
||||
* Allow spin_until_future_complete to accept any future like object (`#1113 <https://github.com/ros2/rclcpp/issues/1113>`_)
|
||||
* Contributors: Alejandro Hernández Cordero, Christophe Bedard, Devin Bonnie, Dirk Thomas, DongheeYe, Ivan Santiago Paunovic, Jacob Perron, Sarthak Mittal, brawner, tomoya
|
||||
Make Executor::spin_once_impl private before backporting, to avoid API compatibility issues
|
||||
* Add check for invalid topic statistics publish period (`#1151 <https://github.com/ros2/rclcpp/issues/1151>`_) (`#1172 <https://github.com/ros2/rclcpp/issues/1172>`_)
|
||||
* Contributors: Alejandro Hernández Cordero, Devin Bonnie, DongheeYe, Ivan Santiago Paunovic, Jacob Perron, Stephen Brawner
|
||||
|
||||
2.0.0 (2020-06-01)
|
||||
------------------
|
||||
|
||||
@@ -2,15 +2,15 @@ This document is a declaration of software quality for the `rclcpp` package, bas
|
||||
|
||||
# rclcpp Quality Declaration
|
||||
|
||||
The package `rclcpp` claims to be in the **Quality Level 2** category.
|
||||
The package `rclcpp` claims to be in the **Quality Level 1** category when it is used with a **Quality Level 1** middleware.
|
||||
|
||||
Below are the rationales, notes, and caveats for this claim, organized by each requirement listed in the [Package Quality Categories in REP-2004](https://index.ros.org/doc/ros2/Contributing/Developer-Guide/#package-quality-categories) of the ROS2 developer guide.
|
||||
Below are the rationales, notes, and caveats for this claim, organized by each requirement listed in the [Package Quality Categories in REP-2004](https://www.ros.org/reps/rep-2004.html) of the ROS2 developer guide.
|
||||
|
||||
## Version Policy [1]
|
||||
|
||||
### Version Scheme [1.i]
|
||||
|
||||
`rclcpp` uses `semver` according to the recommendation for ROS Core packages in the [ROS 2 Developer Guide](https://index.ros.org/doc/ros2/Contributing/Developer-Guide/#versioning).
|
||||
`rclcpp` uses `semver` according to the recommendation for ROS Core packages in the [ROS 2 Developer Guide](https://docs.ros.org/en/foxy/Contributing/Developer-Guide.html#versioning).
|
||||
|
||||
### Version Stability [1.ii]
|
||||
|
||||
@@ -39,11 +39,11 @@ Headers under the folder `detail` are not considered part of the public API and
|
||||
|
||||
## Change Control Process [2]
|
||||
|
||||
`rclcpp` follows the recommended guidelines for ROS Core packages in the [ROS 2 Developer Guide](https://index.ros.org/doc/ros2/Contributing/Developer-Guide/#change-control-process).
|
||||
`rclcpp` follows the recommended guidelines for ROS Core packages in the [ROS 2 Developer Guide](https://docs.ros.org/en/foxy/Contributing/Developer-Guide.html#change-control-process).
|
||||
|
||||
### Change Requests [2.i]
|
||||
|
||||
All changes will occur through a pull request, check [ROS 2 Developer Guide](https://index.ros.org/doc/ros2/Contributing/Developer-Guide/#change-control-process) for additional information.
|
||||
All changes will occur through a pull request, check [ROS 2 Developer Guide](https://docs.ros.org/en/foxy/Contributing/Developer-Guide.html#change-control-process) for additional information.
|
||||
|
||||
### Contributor Origin [2.ii]
|
||||
|
||||
@@ -51,18 +51,17 @@ This package uses DCO as its confirmation of contributor origin policy. More inf
|
||||
|
||||
### Peer Review Policy [2.iii]
|
||||
|
||||
All pull requests will be peer-reviewed, check [ROS 2 Developer Guide](https://index.ros.org/doc/ros2/Contributing/Developer-Guide/#change-control-process) for additional information.
|
||||
All pull requests will be peer-reviewed, check [ROS 2 Developer Guide](https://docs.ros.org/en/foxy/Contributing/Developer-Guide.html#change-control-process) for additional information.
|
||||
|
||||
### Continuous Integration [2.iv]
|
||||
|
||||
All pull requests must pass CI on all [tier 1 platforms](https://www.ros.org/reps/rep-2000.html#support-tiers)
|
||||
|
||||
Currently nightly results can be seen here:
|
||||
|
||||
* [linux-aarch64_release](https://ci.ros2.org/view/nightly/job/nightly_linux-aarch64_release/lastBuild/testReport/rclcpp/)
|
||||
* [linux_release](https://ci.ros2.org/view/nightly/job/nightly_linux_release/lastBuild/testReport/rclcpp/)
|
||||
* [mac_osx_release](https://ci.ros2.org/view/nightly/job/nightly_osx_release/lastBuild/testReport/rclcpp/)
|
||||
* [windows_release](https://ci.ros2.org/view/nightly/job/nightly_win_rel/lastBuild/testReport/rclcpp/)
|
||||
Though there are no nightly jobs for foxy outside of linux, each change is tested on ci.ros2.org.
|
||||
* [linux-aarch64](https://ci.ros2.org/job/ci_linux-aarch64)
|
||||
* [linux](https://ci.ros2.org/job/ci_linux)
|
||||
* [mac_osx](https://ci.ros2.org/job/ci_osx)
|
||||
* [windows](https://ci.ros2.org/job/ci_windows)
|
||||
|
||||
### Documentation Policy [2.v]
|
||||
|
||||
@@ -72,37 +71,36 @@ All pull requests must resolve related documentation changes before merging.
|
||||
|
||||
### Feature Documentation [3.i]
|
||||
|
||||
`rclcpp` has a [feature list](http://docs.ros2.org/latest/api/rclcpp/) and each item in the list links to the corresponding feature documentation. There is documentation for all of the features, and new features require documentation before being added.
|
||||
`rclcpp` has a [feature list](http://docs.ros2.org/foxy/api/rclcpp/) and each item in the list links to the corresponding feature documentation. There is documentation for all of the features, and new features require documentation before being added.
|
||||
|
||||
### Public API Documentation [3.ii]
|
||||
|
||||
The API is publicly available in its [ROS 2 API documentation](http://docs.ros2.org/latest/api/rclcpp/).
|
||||
The API is publicly available in its [ROS 2 API documentation](http://docs.ros2.org/foxy/api/rclcpp/).
|
||||
|
||||
### License [3.iii]
|
||||
|
||||
The license for `rclcpp` is Apache 2.0, and a summary is in each source file, the type is declared in the [`package.xml`](./package.xml) manifest file, and a full copy of the license is in the [`LICENSE`](../LICENSE) file.
|
||||
|
||||
There is an automated test which runs a linter that ensures each file has a license statement. [Here](http://build.ros2.org/view/Fpr/job/Fpr__rclcpp__ubuntu_focal_amd64/lastSuccessfulBuild/testReport/rclcpp/) can be found a list with the latest results of the various linters being run on the package.
|
||||
There is an automated test which runs a linter that ensures each file has a license statement. [Here](http://build.ros2.org/view/Fpr/job/Fpr__rclcpp__ubuntu_focal_amd64/lastCompletedBuild/testReport/rclcpp/) can be found a list with the latest results of the various linters being run on the package.
|
||||
|
||||
### Copyright Statements [3.iv]
|
||||
|
||||
The copyright holders each provide a statement of copyright in each source code file in `rclcpp`.
|
||||
|
||||
There is an automated test which runs a linter that ensures each file has at least one copyright statement. Latest linter result report can be seen [here](http://build.ros2.org/view/Fpr/job/Fpr__rclcpp__ubuntu_focal_amd64/lastSuccessfulBuild/testReport/rclcpp/copyright/).
|
||||
There is an automated test which runs a linter that ensures each file has at least one copyright statement. Latest linter result report can be seen [here](http://build.ros2.org/view/Fpr/job/Fpr__rclcpp__ubuntu_focal_amd64/lastCompletedBuild/testReport/rclcpp/copyright/).
|
||||
|
||||
## Testing [4]
|
||||
|
||||
### Feature Testing [4.i]
|
||||
|
||||
Each feature in `rclcpp` has corresponding tests which simulate typical usage, and they are located in the [`test`](https://github.com/ros2/rclcpp/tree/master/test) directory.
|
||||
Each feature in `rclcpp` has corresponding tests which simulate typical usage, and they are located in the [`test`](https://github.com/ros2/rclcpp/tree/foxy/test) directory.
|
||||
New features are required to have tests before being added.
|
||||
|
||||
Currently nightly test results can be seen here:
|
||||
|
||||
* [linux-aarch64_release](https://ci.ros2.org/view/nightly/job/nightly_linux-aarch64_release/lastBuild/testReport/rclcpp/)
|
||||
* [linux_release](https://ci.ros2.org/view/nightly/job/nightly_linux_release/lastBuild/testReport/rclcpp/)
|
||||
* [mac_osx_release](https://ci.ros2.org/view/nightly/job/nightly_osx_release/lastBuild/testReport/rclcpp/)
|
||||
* [windows_release](https://ci.ros2.org/view/nightly/job/nightly_win_rel/lastBuild/testReport/rclcpp/)
|
||||
Though there are no nightly jobs for foxy outside of linux, each change is tested on ci.ros2.org.
|
||||
* [linux-aarch64](https://ci.ros2.org/job/ci_linux-aarch64)
|
||||
* [linux](https://ci.ros2.org/job/ci_linux)
|
||||
* [mac_osx](https://ci.ros2.org/job/ci_osx)
|
||||
* [windows](https://ci.ros2.org/job/ci_windows)
|
||||
|
||||
### Public API Testing [4.ii]
|
||||
|
||||
@@ -111,7 +109,7 @@ The tests aim to cover both typical usage and corner cases, but are quantified b
|
||||
|
||||
### Coverage [4.iii]
|
||||
|
||||
`rclcpp` follows the recommendations for ROS Core packages in the [ROS 2 Developer Guide](https://index.ros.org/doc/ros2/Contributing/Developer-Guide/#code-coverage), and opts to use line coverage instead of branch coverage.
|
||||
`rclcpp` follows the recommendations for ROS Core packages in the [ROS 2 Developer Guide](https://docs.ros.org/en/foxy/Contributing/Developer-Guide.html#code-coverage), and opts to use line coverage instead of branch coverage.
|
||||
|
||||
This includes:
|
||||
|
||||
@@ -121,23 +119,27 @@ This includes:
|
||||
|
||||
Changes are required to make a best effort to keep or increase coverage before being accepted, but decreases are allowed if properly justified and accepted by reviewers.
|
||||
|
||||
Current coverage statistics can be viewed [here](https://ci.ros2.org/job/nightly_linux_coverage/lastSuccessfulBuild/cobertura/src_ros2_rclcpp_rclcpp_src_rclcpp/). A description of how coverage statistics are calculated is summarized in this page ["ROS 2 Onboarding Guide"](https://index.ros.org/doc/ros2/Contributing/ROS-2-On-boarding-Guide/#note-on-coverage-runs).
|
||||
Current coverage statistics can be viewed [here](https://ci.ros2.org/job/nightly_linux_foxy_coverage/lastCompletedBuild/cobertura/src_ros2_rclcpp_rclcpp_src_rclcpp/). A description of how coverage statistics are calculated is summarized in this page ["ROS 2 Onboarding Guide"](https://docs.ros.org/en/foxy/Contributing/Developer-Guide.html#note-on-coverage-runs).
|
||||
|
||||
`rclcpp` has a line coverage `>= 95%`, which is calculated over all directories within `rclcpp` with the exception of the `experimental` directory.
|
||||
|
||||
### Performance [4.iv]
|
||||
|
||||
It is not yet defined if this package requires performance testing and how addresses this topic.
|
||||
`rclcpp` follows the recommendations for performance testing of C/C++ code in the [ROS 2 Developer Guide](https://docs.ros.org/en/foxy/Contributing/Developer-Guide.html#performance), and opts to do performance analysis on each release rather than each change.
|
||||
|
||||
The performance tests of `rclcpp` are located in the [test/benchmark directory](https://github.com/ros2/rclcpp/tree/foxy/rclcpp/test/benchmark).
|
||||
|
||||
System level performance benchmarks that cover features of `rclcpp` can be found at:
|
||||
* [Benchmarks](http://build.ros2.org/view/Fci/job/Fci__benchmark_ubuntu_focal_amd64/BenchmarkTable/)
|
||||
* [Performance](http://build.ros2.org/view/Fci/job/Fci__nightly-performance_ubuntu_focal_amd64/lastCompletedBuild/)
|
||||
|
||||
Changes that introduce regressions in performance must be adequately justified in order to be accepted and merged.
|
||||
|
||||
### Linters and Static Analysis [4.v]
|
||||
|
||||
`rclcpp` uses and passes all the ROS2 standard linters and static analysis tools for a C++ package as described in the [ROS 2 Developer Guide](https://index.ros.org/doc/ros2/Contributing/Developer-Guide/#linters-and-static-analysis). Passing implies there are no linter/static errors when testing against CI of supported platforms.
|
||||
`rclcpp` uses and passes all the ROS2 standard linters and static analysis tools for a C++ package as described in the [ROS 2 Developer Guide](https://docs.ros.org/en/foxy/Contributing/Developer-Guide.html#linters-and-static-analysis). Passing implies there are no linter/static errors when testing against CI of supported platforms.
|
||||
|
||||
Currently nightly test results can be seen here:
|
||||
* [linux-aarch64_release](https://ci.ros2.org/view/nightly/job/nightly_linux-aarch64_release/lastBuild/testReport/rclcpp/)
|
||||
* [linux_release](https://ci.ros2.org/view/nightly/job/nightly_linux_release/lastBuild/testReport/rclcpp/)
|
||||
* [mac_osx_release](https://ci.ros2.org/view/nightly/job/nightly_osx_release/lastBuild/testReport/rclcpp/)
|
||||
* [windows_release](https://ci.ros2.org/view/nightly/job/nightly_win_rel/lastBuild/testReport/rclcpp/)
|
||||
Currently nightly test results can be seen [here](http://build.ros2.org/view/Fpr/job/Fpr__rclcpp__ubuntu_focal_amd64/lastCompletedBuild/testReport/rclcpp).
|
||||
|
||||
## Dependencies [5]
|
||||
|
||||
@@ -155,49 +157,49 @@ It also has several test dependencies, which do not affect the resulting quality
|
||||
|
||||
The `libstatistics_collector` package provides lightweight aggregation utilities to collect statistics and measure message metrics.
|
||||
|
||||
It is **Quality Level 2**, see its [Quality Declaration document](https://github.com/ros-tooling/libstatistics_collector/tree/master/QUALITY_DECLARATION.md).
|
||||
It is **Quality Level 1**, see its [Quality Declaration document](https://github.com/ros-tooling/libstatistics_collector/tree/foxy-devel/QUALITY_DECLARATION.md).
|
||||
|
||||
#### `rcl`
|
||||
|
||||
`rcl` a library to support implementation of language specific ROS 2 Client Libraries.
|
||||
|
||||
It is **Quality Level 2**, see its [Quality Declaration document](https://github.com/ros2/rcl/blob/master/rcl/QUALITY_DECLARATION.md).
|
||||
It is **Quality Level 1**, see its [Quality Declaration document](https://github.com/ros2/rcl/blob/foxy/rcl/QUALITY_DECLARATION.md).
|
||||
|
||||
#### `rcl_yaml_param_parser`
|
||||
|
||||
The `rcl_yaml_param_parser` package provides an API that is used to parse YAML configuration files which may be used to configure ROS and specific nodes.
|
||||
|
||||
It is **Quality Level 2**, see its [Quality Declaration document](https://github.com/ros2/rcl/tree/master/rcl_yaml_param_parser/QUALITY_DECLARATION.md).
|
||||
It is **Quality Level 1**, see its [Quality Declaration document](https://github.com/ros2/rcl/tree/foxy/rcl_yaml_param_parser/QUALITY_DECLARATION.md).
|
||||
|
||||
#### `rcpputils`
|
||||
|
||||
The `rcpputils` package provides an API which contains common utilities and data structures useful when programming in C++.
|
||||
|
||||
It is **Quality Level 2**, see its [Quality Declaration document](https://github.com/ros2/rcpputils/blob/master/QUALITY_DECLARATION.md).
|
||||
It is **Quality Level 1**, see its [Quality Declaration document](https://github.com/ros2/rcpputils/blob/foxy/QUALITY_DECLARATION.md).
|
||||
|
||||
#### `rcutils`
|
||||
|
||||
The `rcutils` package provides an API which contains common utilities and data structures useful when programming in C.
|
||||
|
||||
It is **Quality Level 2**, see its [Quality Declaration document](https://github.com/ros2/rcutils/blob/master/QUALITY_DECLARATION.md).
|
||||
It is **Quality Level 1**, see its [Quality Declaration document](https://github.com/ros2/rcutils/blob/foxy/QUALITY_DECLARATION.md).
|
||||
|
||||
#### `rmw`
|
||||
|
||||
`rmw` is the ROS 2 middleware library.
|
||||
|
||||
It is **Quality Level 2**, see its [Quality Declaration document](https://github.com/ros2/rmw/blob/master/rmw/QUALITY_DECLARATION.md).
|
||||
It is **Quality Level 1**, see its [Quality Declaration document](https://github.com/ros2/rmw/blob/foxy/rmw/QUALITY_DECLARATION.md).
|
||||
|
||||
#### `statistics_msgs`
|
||||
|
||||
The `statistics_msgs` package contains ROS 2 message definitions for reporting statistics for topics and system resources.
|
||||
|
||||
It is **Quality Level 2**, see its [Quality Declaration document](https://github.com/ros2/rcl_interfaces/blob/master/statistics_msgs/QUALITY_DECLARATION.md).
|
||||
It is **Quality Level 1**, see its [Quality Declaration document](https://github.com/ros2/rcl_interfaces/blob/foxy/statistics_msgs/QUALITY_DECLARATION.md).
|
||||
|
||||
#### `tracetools`
|
||||
|
||||
The `tracetools` package provides utilities for instrumenting the code in `rclcpp` so that it may be traced for debugging and performance analysis.
|
||||
|
||||
It is **Quality Level 1**, see its [Quality Declaration document](https://gitlab.com/ros-tracing/ros2_tracing/-/blob/master/tracetools/QUALITY_DECLARATION.md).
|
||||
It is **Quality Level 1**, see its [Quality Declaration document](https://gitlab.com/ros-tracing/ros2_tracing/-/blob/foxy/tracetools/QUALITY_DECLARATION.md).
|
||||
|
||||
### Direct Runtime non-ROS Dependency [5.iii]
|
||||
|
||||
@@ -207,11 +209,11 @@ It is **Quality Level 1**, see its [Quality Declaration document](https://gitlab
|
||||
|
||||
`rclcpp` supports all of the tier 1 platforms as described in [REP-2000](https://www.ros.org/reps/rep-2000.html#support-tiers), and tests each change against all of them.
|
||||
|
||||
Currently nightly build status can be seen here:
|
||||
* [linux-aarch64_release](https://ci.ros2.org/view/nightly/job/nightly_linux-aarch64_release/lastBuild/rclcpp/)
|
||||
* [linux_release](https://ci.ros2.org/view/nightly/job/nightly_linux_release/lastBuild/rclcpp/)
|
||||
* [mac_osx_release](https://ci.ros2.org/view/nightly/job/nightly_osx_release/lastBuild/rclcpp/)
|
||||
* [windows_release](https://ci.ros2.org/view/nightly/job/nightly_win_rel/lastBuild/rclcpp/)
|
||||
Though there are no nightly jobs for foxy outside of linux, each change is tested on ci.ros2.org.
|
||||
* [linux-aarch64](https://ci.ros2.org/job/ci_linux-aarch64)
|
||||
* [linux](https://ci.ros2.org/job/ci_linux)
|
||||
* [mac_osx](https://ci.ros2.org/job/ci_osx)
|
||||
* [windows](https://ci.ros2.org/job/ci_windows)
|
||||
|
||||
## Security
|
||||
|
||||
|
||||
@@ -6,4 +6,4 @@ Visit the [rclcpp API documentation](http://docs.ros2.org/latest/api/rclcpp/) fo
|
||||
|
||||
## Quality Declaration
|
||||
|
||||
This package claims to be in the **Quality Level 2** category, see the [Quality Declaration](QUALITY_DECLARATION.md) for more details.
|
||||
This package claims to be in the **Quality Level 1** category, see the [Quality Declaration](QUALITY_DECLARATION.md) for more details.
|
||||
|
||||
@@ -88,7 +88,7 @@ public:
|
||||
std::shared_ptr<typename ServiceT::Request> request,
|
||||
std::shared_ptr<typename ServiceT::Response> response)
|
||||
{
|
||||
TRACEPOINT(callback_start, static_cast<const void *>(this), false);
|
||||
TRACEPOINT(callback_start, (const void *)this, false);
|
||||
if (shared_ptr_callback_ != nullptr) {
|
||||
(void)request_header;
|
||||
shared_ptr_callback_(request, response);
|
||||
@@ -97,7 +97,7 @@ public:
|
||||
} else {
|
||||
throw std::runtime_error("unexpected request without any callback set");
|
||||
}
|
||||
TRACEPOINT(callback_end, static_cast<const void *>(this));
|
||||
TRACEPOINT(callback_end, (const void *)this);
|
||||
}
|
||||
|
||||
void register_callback_for_tracing()
|
||||
@@ -106,12 +106,12 @@ public:
|
||||
if (shared_ptr_callback_) {
|
||||
TRACEPOINT(
|
||||
rclcpp_callback_register,
|
||||
static_cast<const void *>(this),
|
||||
(const void *)this,
|
||||
get_symbol(shared_ptr_callback_));
|
||||
} else if (shared_ptr_with_request_header_callback_) {
|
||||
TRACEPOINT(
|
||||
rclcpp_callback_register,
|
||||
static_cast<const void *>(this),
|
||||
(const void *)this,
|
||||
get_symbol(shared_ptr_with_request_header_callback_));
|
||||
}
|
||||
#endif // TRACETOOLS_DISABLED
|
||||
|
||||
@@ -158,7 +158,7 @@ public:
|
||||
void dispatch(
|
||||
std::shared_ptr<MessageT> message, const rclcpp::MessageInfo & message_info)
|
||||
{
|
||||
TRACEPOINT(callback_start, static_cast<const void *>(this), false);
|
||||
TRACEPOINT(callback_start, (const void *)this, false);
|
||||
if (shared_ptr_callback_) {
|
||||
shared_ptr_callback_(message);
|
||||
} else if (shared_ptr_with_info_callback_) {
|
||||
@@ -178,13 +178,13 @@ public:
|
||||
} else {
|
||||
throw std::runtime_error("unexpected message without any callback set");
|
||||
}
|
||||
TRACEPOINT(callback_end, static_cast<const void *>(this));
|
||||
TRACEPOINT(callback_end, (const void *)this);
|
||||
}
|
||||
|
||||
void dispatch_intra_process(
|
||||
ConstMessageSharedPtr message, const rclcpp::MessageInfo & message_info)
|
||||
{
|
||||
TRACEPOINT(callback_start, static_cast<const void *>(this), true);
|
||||
TRACEPOINT(callback_start, (const void *)this, true);
|
||||
if (const_shared_ptr_callback_) {
|
||||
const_shared_ptr_callback_(message);
|
||||
} else if (const_shared_ptr_with_info_callback_) {
|
||||
@@ -201,13 +201,13 @@ public:
|
||||
throw std::runtime_error("unexpected message without any callback set");
|
||||
}
|
||||
}
|
||||
TRACEPOINT(callback_end, static_cast<const void *>(this));
|
||||
TRACEPOINT(callback_end, (const void *)this);
|
||||
}
|
||||
|
||||
void dispatch_intra_process(
|
||||
MessageUniquePtr message, const rclcpp::MessageInfo & message_info)
|
||||
{
|
||||
TRACEPOINT(callback_start, static_cast<const void *>(this), true);
|
||||
TRACEPOINT(callback_start, (const void *)this, true);
|
||||
if (shared_ptr_callback_) {
|
||||
typename std::shared_ptr<MessageT> shared_message = std::move(message);
|
||||
shared_ptr_callback_(shared_message);
|
||||
@@ -225,7 +225,7 @@ public:
|
||||
} else {
|
||||
throw std::runtime_error("unexpected message without any callback set");
|
||||
}
|
||||
TRACEPOINT(callback_end, static_cast<const void *>(this));
|
||||
TRACEPOINT(callback_end, (const void *)this);
|
||||
}
|
||||
|
||||
bool use_take_shared_method() const
|
||||
@@ -239,22 +239,22 @@ public:
|
||||
if (shared_ptr_callback_) {
|
||||
TRACEPOINT(
|
||||
rclcpp_callback_register,
|
||||
static_cast<const void *>(this),
|
||||
(const void *)this,
|
||||
get_symbol(shared_ptr_callback_));
|
||||
} else if (shared_ptr_with_info_callback_) {
|
||||
TRACEPOINT(
|
||||
rclcpp_callback_register,
|
||||
static_cast<const void *>(this),
|
||||
(const void *)this,
|
||||
get_symbol(shared_ptr_with_info_callback_));
|
||||
} else if (unique_ptr_callback_) {
|
||||
TRACEPOINT(
|
||||
rclcpp_callback_register,
|
||||
static_cast<const void *>(this),
|
||||
(const void *)this,
|
||||
get_symbol(unique_ptr_callback_));
|
||||
} else if (unique_ptr_with_info_callback_) {
|
||||
TRACEPOINT(
|
||||
rclcpp_callback_register,
|
||||
static_cast<const void *>(this),
|
||||
(const void *)this,
|
||||
get_symbol(unique_ptr_with_info_callback_));
|
||||
}
|
||||
#endif // TRACETOOLS_DISABLED
|
||||
|
||||
@@ -56,44 +56,8 @@ class CallbackGroup
|
||||
public:
|
||||
RCLCPP_SMART_PTR_DEFINITIONS(CallbackGroup)
|
||||
|
||||
/// Constructor for CallbackGroup.
|
||||
/**
|
||||
* Callback Groups have a type, either 'Mutually Exclusive' or 'Reentrant'
|
||||
* and when creating one the type must be specified.
|
||||
*
|
||||
* Callbacks in Reentrant Callback Groups must be able to:
|
||||
* - run at the same time as themselves (reentrant)
|
||||
* - run at the same time as other callbacks in their group
|
||||
* - run at the same time as other callbacks in other groups
|
||||
*
|
||||
* Callbacks in Mutually Exclusive Callback Groups:
|
||||
* - will not be run multiple times simultaneously (non-reentrant)
|
||||
* - will not be run at the same time as other callbacks in their group
|
||||
* - but must run at the same time as callbacks in other groups
|
||||
*
|
||||
* Additionally, callback groups have a property which determines whether or
|
||||
* not they are added to an executor with their associated node automatically.
|
||||
* When creating a callback group the automatically_add_to_executor_with_node
|
||||
* argument determines this behavior, and if true it will cause the newly
|
||||
* created callback group to be added to an executor with the node when the
|
||||
* Executor::add_node method is used.
|
||||
* If false, this callback group will not be added automatically and would
|
||||
* have to be added to an executor manually using the
|
||||
* Executor::add_callback_group method.
|
||||
*
|
||||
* Whether the node was added to the executor before creating the callback
|
||||
* group, or after, is irrelevant; the callback group will be automatically
|
||||
* added to the executor in either case.
|
||||
*
|
||||
* \param[in] group_type They type of the callback group.
|
||||
* \param[in] automatically_add_to_executor_with_node a boolean which
|
||||
* determines whether a callback group is automatically added to an executor
|
||||
* with the node with which it is associated.
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
explicit CallbackGroup(
|
||||
CallbackGroupType group_type,
|
||||
bool automatically_add_to_executor_with_node = true);
|
||||
explicit CallbackGroup(CallbackGroupType group_type);
|
||||
|
||||
template<typename Function>
|
||||
rclcpp::SubscriptionBase::SharedPtr
|
||||
@@ -138,31 +102,6 @@ public:
|
||||
const CallbackGroupType &
|
||||
type() const;
|
||||
|
||||
/// Return a reference to the 'associated with executor' atomic boolean.
|
||||
/**
|
||||
* When a callback group is added to an executor this boolean is checked
|
||||
* to ensure it has not already been added to another executor.
|
||||
* If it has not been, then this boolean is set to true to indicate it is
|
||||
* now associated with an executor.
|
||||
*
|
||||
* When the callback group is removed from the executor, this atomic boolean
|
||||
* is set back to false.
|
||||
*
|
||||
* \return the 'associated with executor' atomic boolean
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
std::atomic_bool &
|
||||
get_associated_with_executor_atomic();
|
||||
|
||||
/// Return true if this callback group should be automatically added to an executor by the node.
|
||||
/**
|
||||
* \return boolean true if this callback group should be automatically added
|
||||
* to an executor when the associated node is added, otherwise false.
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
bool
|
||||
automatically_add_to_executor_with_node() const;
|
||||
|
||||
protected:
|
||||
RCLCPP_DISABLE_COPY(CallbackGroup)
|
||||
|
||||
@@ -197,14 +136,12 @@ protected:
|
||||
CallbackGroupType type_;
|
||||
// Mutex to protect the subsequent vectors of pointers.
|
||||
mutable std::mutex mutex_;
|
||||
std::atomic_bool associated_with_executor_;
|
||||
std::vector<rclcpp::SubscriptionBase::WeakPtr> subscription_ptrs_;
|
||||
std::vector<rclcpp::TimerBase::WeakPtr> timer_ptrs_;
|
||||
std::vector<rclcpp::ServiceBase::WeakPtr> service_ptrs_;
|
||||
std::vector<rclcpp::ClientBase::WeakPtr> client_ptrs_;
|
||||
std::vector<rclcpp::Waitable::WeakPtr> waitable_ptrs_;
|
||||
std::atomic_bool can_be_taken_from_;
|
||||
const bool automatically_add_to_executor_with_node_;
|
||||
|
||||
private:
|
||||
template<typename TypeT, typename Function>
|
||||
|
||||
@@ -361,8 +361,7 @@ public:
|
||||
SharedPromiseWithRequest promise = std::make_shared<PromiseWithRequest>();
|
||||
SharedFutureWithRequest future_with_request(promise->get_future());
|
||||
|
||||
auto wrapping_cb = [future_with_request, promise, request,
|
||||
cb = std::forward<CallbackWithRequestType>(cb)](SharedFuture future) {
|
||||
auto wrapping_cb = [future_with_request, promise, request, &cb](SharedFuture future) {
|
||||
auto response = future.get();
|
||||
promise->set_value(std::make_pair(request, response));
|
||||
cb(future_with_request);
|
||||
|
||||
@@ -139,11 +139,6 @@ public:
|
||||
rclcpp::InitOptions
|
||||
get_init_options();
|
||||
|
||||
/// Return actual domain id.
|
||||
RCLCPP_PUBLIC
|
||||
size_t
|
||||
get_domain_id() const;
|
||||
|
||||
/// Return the shutdown reason, or empty string if not shutdown.
|
||||
/**
|
||||
* This function is thread-safe.
|
||||
|
||||
@@ -21,13 +21,6 @@
|
||||
#include "rcl/time.h"
|
||||
#include "rclcpp/visibility_control.hpp"
|
||||
|
||||
// Windows has preprocessor defines for "min" and "max", which can cause
|
||||
// problems when things like std::numeric_limits<int>::max are used. This
|
||||
// macro is used to defeat the macro matching logic and hence workaround the
|
||||
// issue. The idea comes from:
|
||||
// https://stackoverflow.com/questions/11544073/how-do-i-deal-with-the-max-macro-in-windows-h-colliding-with-max-in-std/11550864#11550864
|
||||
#define PREVENT_WINDOWS_MIN_MAX
|
||||
|
||||
namespace rclcpp
|
||||
{
|
||||
class RCLCPP_PUBLIC Duration
|
||||
@@ -45,14 +38,10 @@ public:
|
||||
*/
|
||||
Duration(int32_t seconds, uint32_t nanoseconds);
|
||||
|
||||
/// Construct duration from the specified nanoseconds.
|
||||
[[deprecated(
|
||||
"Use Duration::from_nanoseconds instead or std::chrono_literals. For example:"
|
||||
"rclcpp::Duration::from_nanoseconds(int64_variable);"
|
||||
"rclcpp::Duration(0ns);")]]
|
||||
// This constructor matches any numeric value - ints or floats.
|
||||
explicit Duration(rcl_duration_value_t nanoseconds);
|
||||
|
||||
/// Construct duration from the specified std::chrono::nanoseconds.
|
||||
// This constructor matches std::chrono::nanoseconds.
|
||||
explicit Duration(std::chrono::nanoseconds nanoseconds);
|
||||
|
||||
// This constructor matches any std::chrono value other than nanoseconds
|
||||
@@ -115,7 +104,7 @@ public:
|
||||
*/
|
||||
static
|
||||
Duration
|
||||
max PREVENT_WINDOWS_MIN_MAX();
|
||||
max();
|
||||
|
||||
Duration
|
||||
operator*(double scale) const;
|
||||
@@ -140,10 +129,6 @@ public:
|
||||
static Duration
|
||||
from_seconds(double seconds);
|
||||
|
||||
/// Create a duration object from an integer number representing nanoseconds
|
||||
static Duration
|
||||
from_nanoseconds(rcl_duration_value_t nanoseconds);
|
||||
|
||||
/// Convert Duration into a std::chrono::Duration.
|
||||
template<class DurationT>
|
||||
DurationT
|
||||
@@ -158,8 +143,6 @@ public:
|
||||
|
||||
private:
|
||||
rcl_duration_t rcl_duration_;
|
||||
|
||||
Duration() = default;
|
||||
};
|
||||
|
||||
} // namespace rclcpp
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
@@ -43,10 +42,6 @@
|
||||
namespace rclcpp
|
||||
{
|
||||
|
||||
typedef std::map<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr,
|
||||
std::owner_less<rclcpp::CallbackGroup::WeakPtr>> WeakCallbackGroupsToNodesMap;
|
||||
|
||||
// Forward declaration is used in convenience method signature.
|
||||
class Node;
|
||||
|
||||
@@ -81,118 +76,13 @@ public:
|
||||
virtual void
|
||||
spin() = 0;
|
||||
|
||||
/// Add a callback group to an executor.
|
||||
/**
|
||||
* An executor can have zero or more callback groups which provide work during `spin` functions.
|
||||
* When an executor attempts to add a callback group, the executor checks to see if it is already
|
||||
* associated with another executor, and if it has been, then an exception is thrown.
|
||||
* Otherwise, the callback group is added to the executor.
|
||||
*
|
||||
* Adding a callback group with this method does not associate its node with this executor
|
||||
* in any way
|
||||
*
|
||||
* \param[in] group_ptr a shared ptr that points to a callback group
|
||||
* \param[in] node_ptr a shared pointer that points to a node base interface
|
||||
* \param[in] notify True to trigger the interrupt guard condition during this function. If
|
||||
* the executor is blocked at the rmw layer while waiting for work and it is notified that a new
|
||||
* callback group was added, it will wake up.
|
||||
* \throw std::runtime_error if the callback group is associated to an executor
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
virtual void
|
||||
add_callback_group(
|
||||
rclcpp::CallbackGroup::SharedPtr group_ptr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
|
||||
bool notify = true);
|
||||
|
||||
/// Get callback groups that belong to executor.
|
||||
/**
|
||||
* This function returns a vector of weak pointers that point to callback groups that were
|
||||
* associated with the executor.
|
||||
* The callback groups associated with this executor may have been added with
|
||||
* `add_callback_group`, or added when a node was added to the executor with `add_node`, or
|
||||
* automatically added when it created by a node already associated with this executor and the
|
||||
* automatically_add_to_executor_with_node parameter was true.
|
||||
*
|
||||
* \return a vector of weak pointers that point to callback groups that are associated with
|
||||
* the executor
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
virtual std::vector<rclcpp::CallbackGroup::WeakPtr>
|
||||
get_all_callback_groups();
|
||||
|
||||
/// Get callback groups that belong to executor.
|
||||
/**
|
||||
* This function returns a vector of weak pointers that point to callback groups that were
|
||||
* associated with the executor.
|
||||
* The callback groups associated with this executor have been added with
|
||||
* `add_callback_group`.
|
||||
*
|
||||
* \return a vector of weak pointers that point to callback groups that are associated with
|
||||
* the executor
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
virtual std::vector<rclcpp::CallbackGroup::WeakPtr>
|
||||
get_manually_added_callback_groups();
|
||||
|
||||
/// Get callback groups that belong to executor.
|
||||
/**
|
||||
* This function returns a vector of weak pointers that point to callback groups that were
|
||||
* added from a node that is associated with the executor.
|
||||
* The callback groups are added when a node is added to the executor with `add_node`, or
|
||||
* automatically if they are created in the future by that node and have the
|
||||
* automatically_add_to_executor_with_node argument set to true.
|
||||
*
|
||||
* \return a vector of weak pointers that point to callback groups from a node associated with
|
||||
* the executor
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
virtual std::vector<rclcpp::CallbackGroup::WeakPtr>
|
||||
get_automatically_added_callback_groups_from_nodes();
|
||||
|
||||
/// Remove a callback group from the executor.
|
||||
/**
|
||||
* The callback group is removed from and disassociated with the executor.
|
||||
* If the callback group removed was the last callback group from the node
|
||||
* that is associated with the executor, the interrupt guard condition
|
||||
* is triggered and node's guard condition is removed from the executor.
|
||||
*
|
||||
* This function only removes a callback group that was manually added with
|
||||
* rclcpp::Executor::add_callback_group.
|
||||
* To remove callback groups that were added from a node using
|
||||
* rclcpp::Executor::add_node, use rclcpp::Executor::remove_node instead.
|
||||
*
|
||||
* \param[in] group_ptr Shared pointer to the callback group to be added.
|
||||
* \param[in] notify True to trigger the interrupt guard condition during this function. If
|
||||
* the executor is blocked at the rmw layer while waiting for work and it is notified that a
|
||||
* callback group was removed, it will wake up.
|
||||
* \throw std::runtime_error if node is deleted before callback group
|
||||
* \throw std::runtime_error if the callback group is not associated with the executor
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
virtual void
|
||||
remove_callback_group(
|
||||
rclcpp::CallbackGroup::SharedPtr group_ptr,
|
||||
bool notify = true);
|
||||
|
||||
/// Add a node to the executor.
|
||||
/**
|
||||
* Nodes have associated callback groups, and this method adds any of those callback groups
|
||||
* to this executor which have their automatically_add_to_executor_with_node parameter true.
|
||||
* The node is also associated with the executor so that future callback groups which are
|
||||
* created on the node with the automatically_add_to_executor_with_node parameter set to true
|
||||
* are also automatically associated with this executor.
|
||||
*
|
||||
* Callback groups with the automatically_add_to_executor_with_node parameter set to false must
|
||||
* be manually added to an executor using the rclcpp::Executor::add_callback_group method.
|
||||
*
|
||||
* If a node is already associated with an executor, this method throws an exception.
|
||||
*
|
||||
* An executor can have zero or more nodes which provide work during `spin` functions.
|
||||
* \param[in] node_ptr Shared pointer to the node to be added.
|
||||
* \param[in] notify True to trigger the interrupt guard condition during this function. If
|
||||
* the executor is blocked at the rmw layer while waiting for work and it is notified that a new
|
||||
* node was added, it will wake up.
|
||||
* \throw std::runtime_error if a node is already associated to an executor
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
virtual void
|
||||
@@ -208,19 +98,10 @@ public:
|
||||
|
||||
/// Remove a node from the executor.
|
||||
/**
|
||||
* Any callback groups automatically added when this node was added with
|
||||
* rclcpp::Executor::add_node are automatically removed, and the node is no longer associated
|
||||
* with this executor.
|
||||
*
|
||||
* This also means that future callback groups created by the given node are no longer
|
||||
* automatically added to this executor.
|
||||
*
|
||||
* \param[in] node_ptr Shared pointer to the node to remove.
|
||||
* \param[in] notify True to trigger the interrupt guard condition and wake up the executor.
|
||||
* This is useful if the last node was removed from the executor while the executor was blocked
|
||||
* waiting for work in another thread, because otherwise the executor would never be notified.
|
||||
* \throw std::runtime_error if the node is not associated with an executor.
|
||||
* \throw std::runtime_error if the node is not associated with this executor.
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
virtual void
|
||||
@@ -279,7 +160,7 @@ public:
|
||||
void
|
||||
spin_node_some(std::shared_ptr<rclcpp::Node> node);
|
||||
|
||||
/// Collect work once and execute all available work, optionally within a duration.
|
||||
/// Complete all available queued work without blocking.
|
||||
/**
|
||||
* This function can be overridden. The default implementation is suitable for a
|
||||
* single-threaded model of execution.
|
||||
@@ -294,23 +175,6 @@ public:
|
||||
virtual void
|
||||
spin_some(std::chrono::nanoseconds max_duration = std::chrono::nanoseconds(0));
|
||||
|
||||
/// Collect and execute work repeatedly within a duration or until no more work is available.
|
||||
/**
|
||||
* This function can be overridden. The default implementation is suitable for a
|
||||
* single-threaded model of execution.
|
||||
* Adding subscriptions, timers, services, etc. with blocking callbacks will cause this function
|
||||
* to block (which may have unintended consequences).
|
||||
* If the time that waitables take to be executed is longer than the period on which new waitables
|
||||
* become ready, this method will execute work repeatedly until `max_duration` has elapsed.
|
||||
*
|
||||
* \param[in] max_duration The maximum amount of time to spend executing work. Must be positive.
|
||||
* Note that spin_all() may take longer than this time as it only returns once max_duration has
|
||||
* been exceeded.
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
virtual void
|
||||
spin_all(std::chrono::nanoseconds max_duration);
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
virtual void
|
||||
spin_once(std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
|
||||
@@ -325,10 +189,10 @@ public:
|
||||
* code.
|
||||
* \return The return code, one of `SUCCESS`, `INTERRUPTED`, or `TIMEOUT`.
|
||||
*/
|
||||
template<typename FutureT, typename TimeRepT = int64_t, typename TimeT = std::milli>
|
||||
template<typename ResponseT, typename TimeRepT = int64_t, typename TimeT = std::milli>
|
||||
FutureReturnCode
|
||||
spin_until_future_complete(
|
||||
const FutureT & future,
|
||||
const std::shared_future<ResponseT> & future,
|
||||
std::chrono::duration<TimeRepT, TimeT> timeout = std::chrono::duration<TimeRepT, TimeT>(-1))
|
||||
{
|
||||
// TODO(wjwwood): does not work recursively; can't call spin_node_until_future_complete
|
||||
@@ -406,10 +270,6 @@ protected:
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node,
|
||||
std::chrono::nanoseconds timeout);
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
spin_some_impl(std::chrono::nanoseconds max_duration, bool exhaustive);
|
||||
|
||||
/// Find the next available executable and do the work associated with it.
|
||||
/**
|
||||
* \param[in] any_exec Union structure that can hold any executable type (timer, subscription,
|
||||
@@ -446,79 +306,22 @@ protected:
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr
|
||||
get_node_by_group(
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes,
|
||||
rclcpp::CallbackGroup::SharedPtr group);
|
||||
|
||||
/// Return true if the node has been added to this executor.
|
||||
/**
|
||||
* \param[in] node_ptr a shared pointer that points to a node base interface
|
||||
* \return true if the node is associated with the executor, otherwise false
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
bool
|
||||
has_node(
|
||||
const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes) const;
|
||||
get_node_by_group(rclcpp::CallbackGroup::SharedPtr group);
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
rclcpp::CallbackGroup::SharedPtr
|
||||
get_group_by_timer(rclcpp::TimerBase::SharedPtr timer);
|
||||
|
||||
/// Add a callback group to an executor
|
||||
/**
|
||||
* \see rclcpp::Executor::add_callback_group
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
virtual void
|
||||
add_callback_group_to_map(
|
||||
rclcpp::CallbackGroup::SharedPtr group_ptr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
|
||||
WeakCallbackGroupsToNodesMap & weak_groups_to_nodes,
|
||||
bool notify = true);
|
||||
|
||||
/// Remove a callback group from the executor.
|
||||
/**
|
||||
* \see rclcpp::Executor::remove_callback_group
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
virtual void
|
||||
remove_callback_group_from_map(
|
||||
rclcpp::CallbackGroup::SharedPtr group_ptr,
|
||||
WeakCallbackGroupsToNodesMap & weak_groups_to_nodes,
|
||||
bool notify = true);
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
bool
|
||||
get_next_ready_executable(AnyExecutable & any_executable);
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
bool
|
||||
get_next_ready_executable_from_map(
|
||||
AnyExecutable & any_executable,
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes);
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
bool
|
||||
get_next_executable(
|
||||
AnyExecutable & any_executable,
|
||||
std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
|
||||
|
||||
/// Add all callback groups that can be automatically added from associated nodes.
|
||||
/**
|
||||
* The executor, before collecting entities, verifies if any callback group from
|
||||
* nodes associated with the executor, which is not already associated to an executor,
|
||||
* can be automatically added to this executor.
|
||||
* This takes care of any callback group that has been added to a node but not explicitly added
|
||||
* to the executor.
|
||||
* It is important to note that in order for the callback groups to be automatically added to an
|
||||
* executor through this function, the node of the callback groups needs to have been added
|
||||
* through the `add_node` method.
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
virtual void
|
||||
add_callback_groups_from_nodes_associated_to_executor();
|
||||
|
||||
/// Spinning state, used to prevent multi threaded calls to spin and to cancel blocking spins.
|
||||
std::atomic_bool spinning;
|
||||
|
||||
@@ -539,29 +342,13 @@ protected:
|
||||
|
||||
RCLCPP_DISABLE_COPY(Executor)
|
||||
|
||||
std::list<rclcpp::node_interfaces::NodeBaseInterface::WeakPtr> weak_nodes_;
|
||||
std::list<const rcl_guard_condition_t *> guard_conditions_;
|
||||
|
||||
private:
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
spin_once_impl(std::chrono::nanoseconds timeout);
|
||||
|
||||
typedef std::map<rclcpp::node_interfaces::NodeBaseInterface::WeakPtr,
|
||||
const rcl_guard_condition_t *,
|
||||
std::owner_less<rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>>
|
||||
WeakNodesToGuardConditionsMap;
|
||||
|
||||
/// maps nodes to guard conditions
|
||||
WeakNodesToGuardConditionsMap weak_nodes_to_guard_conditions_;
|
||||
|
||||
/// maps callback groups associated to nodes
|
||||
WeakCallbackGroupsToNodesMap weak_groups_associated_with_executor_to_nodes_;
|
||||
|
||||
/// maps callback groups to nodes associated with executor
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes_associated_with_executor_;
|
||||
|
||||
/// maps all callback groups to nodes
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes_;
|
||||
|
||||
/// nodes that are associated with the executor
|
||||
std::list<rclcpp::node_interfaces::NodeBaseInterface::WeakPtr> weak_nodes_;
|
||||
};
|
||||
|
||||
namespace executor
|
||||
|
||||
@@ -66,12 +66,12 @@ using rclcpp::executors::SingleThreadedExecutor;
|
||||
* If the time spent inside the blocking loop exceeds this timeout, return a `TIMEOUT` return code.
|
||||
* \return The return code, one of `SUCCESS`, `INTERRUPTED`, or `TIMEOUT`.
|
||||
*/
|
||||
template<typename FutureT, typename TimeRepT = int64_t, typename TimeT = std::milli>
|
||||
template<typename ResponseT, typename TimeRepT = int64_t, typename TimeT = std::milli>
|
||||
rclcpp::FutureReturnCode
|
||||
spin_node_until_future_complete(
|
||||
rclcpp::Executor & executor,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
|
||||
const FutureT & future,
|
||||
const std::shared_future<ResponseT> & future,
|
||||
std::chrono::duration<TimeRepT, TimeT> timeout = std::chrono::duration<TimeRepT, TimeT>(-1))
|
||||
{
|
||||
// TODO(wjwwood): does not work recursively; can't call spin_node_until_future_complete
|
||||
@@ -82,13 +82,13 @@ spin_node_until_future_complete(
|
||||
return retcode;
|
||||
}
|
||||
|
||||
template<typename NodeT = rclcpp::Node, typename FutureT, typename TimeRepT = int64_t,
|
||||
template<typename NodeT = rclcpp::Node, typename ResponseT, typename TimeRepT = int64_t,
|
||||
typename TimeT = std::milli>
|
||||
rclcpp::FutureReturnCode
|
||||
spin_node_until_future_complete(
|
||||
rclcpp::Executor & executor,
|
||||
std::shared_ptr<NodeT> node_ptr,
|
||||
const FutureT & future,
|
||||
const std::shared_future<ResponseT> & future,
|
||||
std::chrono::duration<TimeRepT, TimeT> timeout = std::chrono::duration<TimeRepT, TimeT>(-1))
|
||||
{
|
||||
return rclcpp::executors::spin_node_until_future_complete(
|
||||
@@ -104,7 +104,7 @@ template<typename FutureT, typename TimeRepT = int64_t, typename TimeT = std::mi
|
||||
rclcpp::FutureReturnCode
|
||||
spin_until_future_complete(
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
|
||||
const FutureT & future,
|
||||
const std::shared_future<FutureT> & future,
|
||||
std::chrono::duration<TimeRepT, TimeT> timeout = std::chrono::duration<TimeRepT, TimeT>(-1))
|
||||
{
|
||||
rclcpp::executors::SingleThreadedExecutor executor;
|
||||
@@ -116,7 +116,7 @@ template<typename NodeT = rclcpp::Node, typename FutureT, typename TimeRepT = in
|
||||
rclcpp::FutureReturnCode
|
||||
spin_until_future_complete(
|
||||
std::shared_ptr<NodeT> node_ptr,
|
||||
const FutureT & future,
|
||||
const std::shared_future<FutureT> & future,
|
||||
std::chrono::duration<TimeRepT, TimeT> timeout = std::chrono::duration<TimeRepT, TimeT>(-1))
|
||||
{
|
||||
return rclcpp::spin_until_future_complete(node_ptr->get_node_base_interface(), future, timeout);
|
||||
|
||||
@@ -17,9 +17,7 @@
|
||||
|
||||
#include <chrono>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "rcl/guard_condition.h"
|
||||
#include "rcl/wait.h"
|
||||
@@ -34,9 +32,6 @@ namespace rclcpp
|
||||
{
|
||||
namespace executors
|
||||
{
|
||||
typedef std::map<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr,
|
||||
std::owner_less<rclcpp::CallbackGroup::WeakPtr>> WeakCallbackGroupsToNodesMap;
|
||||
|
||||
class StaticExecutorEntitiesCollector final
|
||||
: public rclcpp::Waitable,
|
||||
@@ -64,7 +59,7 @@ public:
|
||||
void
|
||||
init(
|
||||
rcl_wait_set_t * p_wait_set,
|
||||
rclcpp::memory_strategy::MemoryStrategy::SharedPtr memory_strategy,
|
||||
rclcpp::memory_strategy::MemoryStrategy::SharedPtr & memory_strategy,
|
||||
rcl_guard_condition_t * executor_guard_condition);
|
||||
|
||||
/// Finalize StaticExecutorEntitiesCollector to clear resources
|
||||
@@ -76,11 +71,27 @@ public:
|
||||
void
|
||||
execute() override;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
fill_memory_strategy();
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
fill_executable_list();
|
||||
|
||||
/// Function to reallocate space for entities in the wait set.
|
||||
/**
|
||||
* \throws std::runtime_error if wait set couldn't be cleared or resized.
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
prepare_wait_set();
|
||||
|
||||
/// Function to add_handles_to_wait_set and wait for work and
|
||||
/**
|
||||
* block until the wait set is ready or until the timeout has been exceeded.
|
||||
* \throws std::runtime_error if wait set couldn't be cleared or filled.
|
||||
* \throws any rcl errors from rcl_wait, \see rclcpp::exceptions::throw_from_rcl_error()
|
||||
* \throws any rcl errors from rcl_wait, \sa rclcpp::exceptions::throw_from_rcl_error()
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
@@ -97,58 +108,17 @@ public:
|
||||
size_t
|
||||
get_number_of_ready_guard_conditions() override;
|
||||
|
||||
/// Add a callback group to an executor.
|
||||
/**
|
||||
* \see rclcpp::Executor::add_callback_group
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
bool
|
||||
add_callback_group(
|
||||
rclcpp::CallbackGroup::SharedPtr group_ptr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr);
|
||||
|
||||
/// Add a callback group to an executor.
|
||||
/**
|
||||
* \see rclcpp::Executor::add_callback_group
|
||||
* \return boolean whether the node from the callback group is new
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
bool
|
||||
add_callback_group(
|
||||
rclcpp::CallbackGroup::SharedPtr group_ptr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
|
||||
WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
|
||||
|
||||
/// Remove a callback group from the executor.
|
||||
/**
|
||||
* \see rclcpp::Executor::remove_callback_group
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
bool
|
||||
remove_callback_group(
|
||||
rclcpp::CallbackGroup::SharedPtr group_ptr);
|
||||
|
||||
/// Remove a callback group from the executor.
|
||||
/**
|
||||
* \see rclcpp::Executor::remove_callback_group_from_map
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
bool
|
||||
remove_callback_group_from_map(
|
||||
rclcpp::CallbackGroup::SharedPtr group_ptr,
|
||||
WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
|
||||
|
||||
/**
|
||||
* \see rclcpp::Executor::add_node()
|
||||
* \sa rclcpp::Executor::add_node()
|
||||
* \throw std::runtime_error if node was already added
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
bool
|
||||
void
|
||||
add_node(
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr);
|
||||
|
||||
/**
|
||||
* \see rclcpp::Executor::remove_node()
|
||||
* \sa rclcpp::Executor::remove_node()
|
||||
* \throw std::runtime_error if no guard condition is associated with node.
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
@@ -156,26 +126,6 @@ public:
|
||||
remove_node(
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr);
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr>
|
||||
get_all_callback_groups();
|
||||
|
||||
/// Get callback groups that belong to executor.
|
||||
/**
|
||||
* \see rclcpp::Executor::get_manually_added_callback_groups()
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr>
|
||||
get_manually_added_callback_groups();
|
||||
|
||||
/// Get callback groups that belong to executor.
|
||||
/**
|
||||
* \see rclcpp::Executor::get_automatically_added_callback_groups_from_nodes()
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr>
|
||||
get_automatically_added_callback_groups_from_nodes();
|
||||
|
||||
/// Complete all available queued work without blocking.
|
||||
/**
|
||||
* This function checks if after the guard condition was triggered
|
||||
@@ -272,55 +222,12 @@ public:
|
||||
get_waitable(size_t i) {return exec_list_.waitable[i];}
|
||||
|
||||
private:
|
||||
/// Function to reallocate space for entities in the wait set.
|
||||
/**
|
||||
* \throws std::runtime_error if wait set couldn't be cleared or resized.
|
||||
*/
|
||||
void
|
||||
prepare_wait_set();
|
||||
|
||||
void
|
||||
fill_executable_list();
|
||||
|
||||
void
|
||||
fill_memory_strategy();
|
||||
|
||||
/// Return true if the node belongs to the collector
|
||||
/**
|
||||
* \param[in] group_ptr a node base interface shared pointer
|
||||
* \return boolean whether a node belongs the collector
|
||||
*/
|
||||
bool
|
||||
has_node(
|
||||
const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) const;
|
||||
|
||||
/// Add all callback groups that can be automatically added by any executor
|
||||
/// and is not already associated with an executor from nodes
|
||||
/// that are associated with executor
|
||||
/**
|
||||
* \see rclcpp::Executor::add_callback_groups_from_nodes_associated_to_executor()
|
||||
*/
|
||||
void
|
||||
add_callback_groups_from_nodes_associated_to_executor();
|
||||
|
||||
void
|
||||
fill_executable_list_from_map(const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
|
||||
/// Nodes guard conditions which trigger this waitable
|
||||
std::list<const rcl_guard_condition_t *> guard_conditions_;
|
||||
|
||||
/// Memory strategy: an interface for handling user-defined memory allocation strategies.
|
||||
rclcpp::memory_strategy::MemoryStrategy::SharedPtr memory_strategy_;
|
||||
|
||||
// maps callback groups to nodes.
|
||||
WeakCallbackGroupsToNodesMap weak_groups_associated_with_executor_to_nodes_;
|
||||
// maps callback groups to nodes.
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes_associated_with_executor_;
|
||||
|
||||
typedef std::map<rclcpp::node_interfaces::NodeBaseInterface::WeakPtr,
|
||||
const rcl_guard_condition_t *,
|
||||
std::owner_less<rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>>
|
||||
WeakNodesToGuardConditionsMap;
|
||||
WeakNodesToGuardConditionsMap weak_nodes_to_guard_conditions_;
|
||||
|
||||
/// List of weak nodes registered in the static executor
|
||||
std::list<rclcpp::node_interfaces::NodeBaseInterface::WeakPtr> weak_nodes_;
|
||||
|
||||
|
||||
@@ -78,30 +78,15 @@ public:
|
||||
void
|
||||
spin() override;
|
||||
|
||||
/// Add a callback group to an executor.
|
||||
/**
|
||||
* \sa rclcpp::Executor::add_callback_group
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
add_callback_group(
|
||||
rclcpp::CallbackGroup::SharedPtr group_ptr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
|
||||
bool notify = true) override;
|
||||
|
||||
/// Remove callback group from the executor
|
||||
/**
|
||||
* \sa rclcpp::Executor::remove_callback_group
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
remove_callback_group(
|
||||
rclcpp::CallbackGroup::SharedPtr group_ptr,
|
||||
bool notify = true) override;
|
||||
|
||||
/// Add a node to the executor.
|
||||
/**
|
||||
* \sa rclcpp::Executor::add_node
|
||||
* An executor can have zero or more nodes which provide work during `spin` functions.
|
||||
* \param[in] node_ptr Shared pointer to the node to be added.
|
||||
* \param[in] notify True to trigger the interrupt guard condition during this function. If
|
||||
* the executor is blocked at the rmw layer while waiting for work and it is notified that a new
|
||||
* node was added, it will wake up.
|
||||
* \throw std::runtime_error if node was already added or if rcl_trigger_guard_condition
|
||||
* return an error
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
@@ -111,7 +96,8 @@ public:
|
||||
|
||||
/// Convenience function which takes Node and forwards NodeBaseInterface.
|
||||
/**
|
||||
* \sa rclcpp::StaticSingleThreadedExecutor::add_node
|
||||
* \throw std::runtime_error if node was already added or if rcl_trigger_guard_condition
|
||||
* returns an error
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
@@ -119,7 +105,11 @@ public:
|
||||
|
||||
/// Remove a node from the executor.
|
||||
/**
|
||||
* \sa rclcpp::Executor::remove_node
|
||||
* \param[in] node_ptr Shared pointer to the node to remove.
|
||||
* \param[in] notify True to trigger the interrupt guard condition and wake up the executor.
|
||||
* This is useful if the last node was removed from the executor while the executor was blocked
|
||||
* waiting for work in another thread, because otherwise the executor would never be notified.
|
||||
* \throw std::runtime_error if rcl_trigger_guard_condition returns an error
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
@@ -129,32 +119,12 @@ public:
|
||||
|
||||
/// Convenience function which takes Node and forwards NodeBaseInterface.
|
||||
/**
|
||||
* \sa rclcpp::Executor::remove_node
|
||||
* \throw std::runtime_error if rcl_trigger_guard_condition returns an error
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
remove_node(std::shared_ptr<rclcpp::Node> node_ptr, bool notify = true) override;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr>
|
||||
get_all_callback_groups() override;
|
||||
|
||||
/// Get callback groups that belong to executor.
|
||||
/**
|
||||
* \sa rclcpp::Executor::get_manually_added_callback_groups()
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr>
|
||||
get_manually_added_callback_groups() override;
|
||||
|
||||
/// Get callback groups that belong to executor.
|
||||
/**
|
||||
* \sa rclcpp::Executor::get_automatically_added_callback_groups_from_nodes()
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr>
|
||||
get_automatically_added_callback_groups_from_nodes() override;
|
||||
|
||||
/// Spin (blocking) until the future is complete, it times out waiting, or rclcpp is interrupted.
|
||||
/**
|
||||
* \param[in] future The future to wait on. If this function returns SUCCESS, the future can be
|
||||
@@ -173,10 +143,10 @@ public:
|
||||
* exec.add_node(node);
|
||||
* exec.spin_until_future_complete(future);
|
||||
*/
|
||||
template<typename FutureT, typename TimeRepT = int64_t, typename TimeT = std::milli>
|
||||
template<typename ResponseT, typename TimeRepT = int64_t, typename TimeT = std::milli>
|
||||
rclcpp::FutureReturnCode
|
||||
spin_until_future_complete(
|
||||
FutureT & future,
|
||||
std::shared_future<ResponseT> & future,
|
||||
std::chrono::duration<TimeRepT, TimeT> timeout = std::chrono::duration<TimeRepT, TimeT>(-1))
|
||||
{
|
||||
std::future_status status = future.wait_for(std::chrono::seconds(0));
|
||||
@@ -221,38 +191,6 @@ public:
|
||||
return rclcpp::FutureReturnCode::INTERRUPTED;
|
||||
}
|
||||
|
||||
/// Not yet implemented, see https://github.com/ros2/rclcpp/issues/1219 for tracking
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
spin_some(std::chrono::nanoseconds max_duration = std::chrono::nanoseconds(0)) override
|
||||
{
|
||||
(void)max_duration;
|
||||
throw rclcpp::exceptions::UnimplementedError(
|
||||
"spin_some is not implemented for StaticSingleThreadedExecutor, use spin or "
|
||||
"spin_until_future_complete");
|
||||
}
|
||||
|
||||
/// Not yet implemented, see https://github.com/ros2/rclcpp/issues/1219 for tracking
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
spin_all(std::chrono::nanoseconds) override
|
||||
{
|
||||
throw rclcpp::exceptions::UnimplementedError(
|
||||
"spin_all is not implemented for StaticSingleThreadedExecutor, use spin or "
|
||||
"spin_until_future_complete");
|
||||
}
|
||||
|
||||
/// Not yet implemented, see https://github.com/ros2/rclcpp/issues/1219 for tracking
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
spin_once(std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1)) override
|
||||
{
|
||||
(void)timeout;
|
||||
throw rclcpp::exceptions::UnimplementedError(
|
||||
"spin_once is not implemented for StaticSingleThreadedExecutor, use spin or "
|
||||
"spin_until_future_complete");
|
||||
}
|
||||
|
||||
protected:
|
||||
/// Check which executables in ExecutableList struct are ready from wait_set and execute them.
|
||||
/**
|
||||
|
||||
@@ -37,10 +37,6 @@ namespace experimental
|
||||
namespace buffers
|
||||
{
|
||||
|
||||
/// Store elements in a fixed-size, FIFO buffer
|
||||
/**
|
||||
* All public member functions are thread-safe.
|
||||
*/
|
||||
template<typename BufferT>
|
||||
class RingBufferImplementation : public BufferImplementationBase<BufferT>
|
||||
{
|
||||
@@ -59,125 +55,55 @@ public:
|
||||
|
||||
virtual ~RingBufferImplementation() {}
|
||||
|
||||
/// Add a new element to store in the ring buffer
|
||||
/**
|
||||
* This member function is thread-safe.
|
||||
*
|
||||
* \param request the element to be stored in the ring buffer
|
||||
*/
|
||||
void enqueue(BufferT request)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
write_index_ = next_(write_index_);
|
||||
write_index_ = next(write_index_);
|
||||
ring_buffer_[write_index_] = std::move(request);
|
||||
|
||||
if (is_full_()) {
|
||||
read_index_ = next_(read_index_);
|
||||
if (is_full()) {
|
||||
read_index_ = next(read_index_);
|
||||
} else {
|
||||
size_++;
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove the oldest element from ring buffer
|
||||
/**
|
||||
* This member function is thread-safe.
|
||||
*
|
||||
* \return the element that is being removed from the ring buffer
|
||||
*/
|
||||
BufferT dequeue()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
if (!has_data_()) {
|
||||
if (!has_data()) {
|
||||
RCLCPP_ERROR(rclcpp::get_logger("rclcpp"), "Calling dequeue on empty intra-process buffer");
|
||||
throw std::runtime_error("Calling dequeue on empty intra-process buffer");
|
||||
}
|
||||
|
||||
auto request = std::move(ring_buffer_[read_index_]);
|
||||
read_index_ = next_(read_index_);
|
||||
read_index_ = next(read_index_);
|
||||
|
||||
size_--;
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
/// Get the next index value for the ring buffer
|
||||
/**
|
||||
* This member function is thread-safe.
|
||||
*
|
||||
* \param val the current index value
|
||||
* \return the next index value
|
||||
*/
|
||||
inline size_t next(size_t val)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return next_(val);
|
||||
return (val + 1) % capacity_;
|
||||
}
|
||||
|
||||
/// Get if the ring buffer has at least one element stored
|
||||
/**
|
||||
* This member function is thread-safe.
|
||||
*
|
||||
* \return `true` if there is data and `false` otherwise
|
||||
*/
|
||||
inline bool has_data() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return has_data_();
|
||||
return size_ != 0;
|
||||
}
|
||||
|
||||
/// Get if the size of the buffer is equal to its capacity
|
||||
/**
|
||||
* This member function is thread-safe.
|
||||
*
|
||||
* \return `true` if the size of the buffer is equal is capacity
|
||||
* and `false` otherwise
|
||||
*/
|
||||
inline bool is_full() const
|
||||
inline bool is_full()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return is_full_();
|
||||
return size_ == capacity_;
|
||||
}
|
||||
|
||||
void clear() {}
|
||||
|
||||
private:
|
||||
/// Get the next index value for the ring buffer
|
||||
/**
|
||||
* This member function is not thread-safe.
|
||||
*
|
||||
* \param val the current index value
|
||||
* \return the next index value
|
||||
*/
|
||||
inline size_t next_(size_t val)
|
||||
{
|
||||
return (val + 1) % capacity_;
|
||||
}
|
||||
|
||||
/// Get if the ring buffer has at least one element stored
|
||||
/**
|
||||
* This member function is not thread-safe.
|
||||
*
|
||||
* \return `true` if there is data and `false` otherwise
|
||||
*/
|
||||
inline bool has_data_() const
|
||||
{
|
||||
return size_ != 0;
|
||||
}
|
||||
|
||||
/// Get if the size of the buffer is equal to its capacity
|
||||
/**
|
||||
* This member function is not thread-safe.
|
||||
*
|
||||
* \return `true` if the size of the buffer is equal is capacity
|
||||
* and `false` otherwise
|
||||
*/
|
||||
inline bool is_full_() const
|
||||
{
|
||||
return size_ == capacity_;
|
||||
}
|
||||
|
||||
size_t capacity_;
|
||||
|
||||
std::vector<BufferT> ring_buffer_;
|
||||
@@ -186,7 +112,7 @@ private:
|
||||
size_t read_index_;
|
||||
size_t size_;
|
||||
|
||||
mutable std::mutex mutex_;
|
||||
std::mutex mutex_;
|
||||
};
|
||||
|
||||
} // namespace buffers
|
||||
|
||||
@@ -207,7 +207,7 @@ public:
|
||||
sub_ids.take_shared_subscriptions.size() <= 1)
|
||||
{
|
||||
// There is at maximum 1 buffer that does not require ownership.
|
||||
// So this case is equivalent to all the buffers requiring ownership
|
||||
// So we this case is equivalent to all the buffers requiring ownership
|
||||
|
||||
// Merge the two vector of ids into a unique one
|
||||
std::vector<uint64_t> concatenated_vector(sub_ids.take_shared_subscriptions);
|
||||
|
||||
@@ -92,8 +92,8 @@ public:
|
||||
|
||||
TRACEPOINT(
|
||||
rclcpp_subscription_callback_added,
|
||||
static_cast<const void *>(this),
|
||||
static_cast<const void *>(&any_callback_));
|
||||
(const void *)this,
|
||||
(const void *)&any_callback_);
|
||||
// The callback object gets copied, so if registration is done too early/before this point
|
||||
// (e.g. in `AnySubscriptionCallback::set()`), its address won't match any address used later
|
||||
// in subsequent tracepoints.
|
||||
@@ -102,16 +102,6 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
~SubscriptionIntraProcess()
|
||||
{
|
||||
if (rcl_guard_condition_fini(&gc_) != RCL_RET_OK) {
|
||||
RCUTILS_LOG_ERROR_NAMED(
|
||||
"rclcpp",
|
||||
"Failed to destroy guard condition: %s",
|
||||
rcutils_get_error_string().str);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
is_ready(rcl_wait_set_t * wait_set)
|
||||
{
|
||||
|
||||
@@ -42,6 +42,20 @@ RCLCPP_PUBLIC
|
||||
std::string
|
||||
to_string(const FutureReturnCode & future_return_code);
|
||||
|
||||
namespace executor
|
||||
{
|
||||
|
||||
using FutureReturnCode [[deprecated("use rclcpp::FutureReturnCode instead")]] = FutureReturnCode;
|
||||
|
||||
[[deprecated("use rclcpp::to_string(const rclcpp::FutureReturnCode &) instead")]]
|
||||
inline
|
||||
std::string
|
||||
to_string(const rclcpp::FutureReturnCode & future_return_code)
|
||||
{
|
||||
return rclcpp::to_string(future_return_code);
|
||||
}
|
||||
|
||||
} // namespace executor
|
||||
} // namespace rclcpp
|
||||
|
||||
#endif // RCLCPP__FUTURE_RETURN_CODE_HPP_
|
||||
|
||||
@@ -160,12 +160,6 @@ protected:
|
||||
void
|
||||
run_loop();
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
void init_wait_set();
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
void cleanup_wait_set();
|
||||
|
||||
private:
|
||||
RCLCPP_DISABLE_COPY(GraphListener)
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#define RCLCPP__INIT_OPTIONS_HPP_
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include "rcl/init_options.h"
|
||||
#include "rclcpp/visibility_control.hpp"
|
||||
@@ -81,30 +80,11 @@ public:
|
||||
const rcl_init_options_t *
|
||||
get_rcl_init_options() const;
|
||||
|
||||
/// Retrieve default domain id and set.
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
use_default_domain_id();
|
||||
|
||||
/// Set the domain id.
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
set_domain_id(size_t domain_id);
|
||||
|
||||
/// Return domain id.
|
||||
RCLCPP_PUBLIC
|
||||
size_t
|
||||
get_domain_id() const;
|
||||
|
||||
protected:
|
||||
void
|
||||
finalize_init_options();
|
||||
|
||||
private:
|
||||
void
|
||||
finalize_init_options_impl();
|
||||
|
||||
mutable std::mutex init_options_mutex_;
|
||||
std::unique_ptr<rcl_init_options_t> init_options_;
|
||||
bool initialize_logging_{true};
|
||||
};
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "rclcpp/visibility_control.hpp"
|
||||
|
||||
#include "rcl/node.h"
|
||||
#include "rcutils/logging.h"
|
||||
|
||||
/**
|
||||
* \def RCLCPP_LOGGING_ENABLED
|
||||
@@ -77,18 +76,6 @@ get_node_logger(const rcl_node_t * node);
|
||||
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
/// An enum for the type of logger level.
|
||||
enum class Level
|
||||
{
|
||||
Unset = RCUTILS_LOG_SEVERITY_UNSET, ///< The unset log level
|
||||
Debug = RCUTILS_LOG_SEVERITY_DEBUG, ///< The debug log level
|
||||
Info = RCUTILS_LOG_SEVERITY_INFO, ///< The info log level
|
||||
Warn = RCUTILS_LOG_SEVERITY_WARN, ///< The warn log level
|
||||
Error = RCUTILS_LOG_SEVERITY_ERROR, ///< The error log level
|
||||
Fatal = RCUTILS_LOG_SEVERITY_FATAL, ///< The fatal log level
|
||||
};
|
||||
|
||||
private:
|
||||
friend Logger rclcpp::get_logger(const std::string & name);
|
||||
friend ::rclcpp::node_interfaces::NodeLogging;
|
||||
@@ -151,16 +138,6 @@ public:
|
||||
}
|
||||
return Logger(*name_ + "." + suffix);
|
||||
}
|
||||
|
||||
/// Set level for current logger.
|
||||
/**
|
||||
* \param[in] level the logger's level
|
||||
* \throws rclcpp::exceptions::RCLInvalidArgument if level is invalid.
|
||||
* \throws rclcpp::exceptions::RCLError if other error happens.
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
void
|
||||
set_level(Level level);
|
||||
};
|
||||
|
||||
} // namespace rclcpp
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#define RCLCPP__MEMORY_STRATEGY_HPP_
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include "rcl/allocator.h"
|
||||
@@ -43,13 +42,11 @@ class RCLCPP_PUBLIC MemoryStrategy
|
||||
{
|
||||
public:
|
||||
RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(MemoryStrategy)
|
||||
using WeakCallbackGroupsToNodesMap = std::map<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr,
|
||||
std::owner_less<rclcpp::CallbackGroup::WeakPtr>>;
|
||||
using WeakNodeList = std::list<rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>;
|
||||
|
||||
virtual ~MemoryStrategy() = default;
|
||||
|
||||
virtual bool collect_entities(const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
|
||||
virtual bool collect_entities(const WeakNodeList & weak_nodes) = 0;
|
||||
|
||||
virtual size_t number_of_ready_subscriptions() const = 0;
|
||||
virtual size_t number_of_ready_services() const = 0;
|
||||
@@ -71,27 +68,27 @@ public:
|
||||
virtual void
|
||||
get_next_subscription(
|
||||
rclcpp::AnyExecutable & any_exec,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
|
||||
const WeakNodeList & weak_nodes) = 0;
|
||||
|
||||
virtual void
|
||||
get_next_service(
|
||||
rclcpp::AnyExecutable & any_exec,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
|
||||
const WeakNodeList & weak_nodes) = 0;
|
||||
|
||||
virtual void
|
||||
get_next_client(
|
||||
rclcpp::AnyExecutable & any_exec,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
|
||||
const WeakNodeList & weak_nodes) = 0;
|
||||
|
||||
virtual void
|
||||
get_next_timer(
|
||||
rclcpp::AnyExecutable & any_exec,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
|
||||
const WeakNodeList & weak_nodes) = 0;
|
||||
|
||||
virtual void
|
||||
get_next_waitable(
|
||||
rclcpp::AnyExecutable & any_exec,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) = 0;
|
||||
const WeakNodeList & weak_nodes) = 0;
|
||||
|
||||
virtual rcl_allocator_t
|
||||
get_allocator() = 0;
|
||||
@@ -99,52 +96,52 @@ public:
|
||||
static rclcpp::SubscriptionBase::SharedPtr
|
||||
get_subscription_by_handle(
|
||||
std::shared_ptr<const rcl_subscription_t> subscriber_handle,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
|
||||
const WeakNodeList & weak_nodes);
|
||||
|
||||
static rclcpp::ServiceBase::SharedPtr
|
||||
get_service_by_handle(
|
||||
std::shared_ptr<const rcl_service_t> service_handle,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
|
||||
const WeakNodeList & weak_nodes);
|
||||
|
||||
static rclcpp::ClientBase::SharedPtr
|
||||
get_client_by_handle(
|
||||
std::shared_ptr<const rcl_client_t> client_handle,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
|
||||
const WeakNodeList & weak_nodes);
|
||||
|
||||
static rclcpp::TimerBase::SharedPtr
|
||||
get_timer_by_handle(
|
||||
std::shared_ptr<const rcl_timer_t> timer_handle,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
|
||||
const WeakNodeList & weak_nodes);
|
||||
|
||||
static rclcpp::node_interfaces::NodeBaseInterface::SharedPtr
|
||||
get_node_by_group(
|
||||
rclcpp::CallbackGroup::SharedPtr group,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
|
||||
const WeakNodeList & weak_nodes);
|
||||
|
||||
static rclcpp::CallbackGroup::SharedPtr
|
||||
get_group_by_subscription(
|
||||
rclcpp::SubscriptionBase::SharedPtr subscription,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
|
||||
const WeakNodeList & weak_nodes);
|
||||
|
||||
static rclcpp::CallbackGroup::SharedPtr
|
||||
get_group_by_service(
|
||||
rclcpp::ServiceBase::SharedPtr service,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
|
||||
const WeakNodeList & weak_nodes);
|
||||
|
||||
static rclcpp::CallbackGroup::SharedPtr
|
||||
get_group_by_client(
|
||||
rclcpp::ClientBase::SharedPtr client,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
|
||||
const WeakNodeList & weak_nodes);
|
||||
|
||||
static rclcpp::CallbackGroup::SharedPtr
|
||||
get_group_by_timer(
|
||||
rclcpp::TimerBase::SharedPtr timer,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
|
||||
const WeakNodeList & weak_nodes);
|
||||
|
||||
static rclcpp::CallbackGroup::SharedPtr
|
||||
get_group_by_waitable(
|
||||
rclcpp::Waitable::SharedPtr waitable,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes);
|
||||
const WeakNodeList & weak_nodes);
|
||||
};
|
||||
|
||||
} // namespace memory_strategy
|
||||
|
||||
@@ -141,9 +141,7 @@ public:
|
||||
/// Create and return a callback group.
|
||||
RCLCPP_PUBLIC
|
||||
rclcpp::CallbackGroup::SharedPtr
|
||||
create_callback_group(
|
||||
rclcpp::CallbackGroupType group_type,
|
||||
bool automatically_add_to_executor_with_node = true);
|
||||
create_callback_group(rclcpp::CallbackGroupType group_type);
|
||||
|
||||
/// Return the list of callback groups in the node.
|
||||
RCLCPP_PUBLIC
|
||||
@@ -163,7 +161,7 @@ public:
|
||||
* pub = node->create_publisher<MsgT>("chatter", QoS(10)); // implicitly KeepLast
|
||||
* pub = node->create_publisher<MsgT>("chatter", QoS(KeepLast(10)));
|
||||
* pub = node->create_publisher<MsgT>("chatter", QoS(KeepAll()));
|
||||
* pub = node->create_publisher<MsgT>("chatter", QoS(1).best_effort().volatile());
|
||||
* pub = node->create_publisher<MsgT>("chatter", QoS(1).best_effort().durability_volatile());
|
||||
* {
|
||||
* rclcpp::QoS custom_qos(KeepLast(10), rmw_qos_profile_sensor_data);
|
||||
* pub = node->create_publisher<MsgT>("chatter", custom_qos);
|
||||
@@ -847,6 +845,26 @@ public:
|
||||
void
|
||||
remove_on_set_parameters_callback(const OnSetParametersCallbackHandle * const handler);
|
||||
|
||||
/// Register a callback to be called anytime a parameter is about to be changed.
|
||||
/**
|
||||
* \deprecated Use add_on_set_parameters_callback instead.
|
||||
* With this method, only one callback can be set at a time. The callback that was previously
|
||||
* set by this method is returned or `nullptr` if no callback was previously set.
|
||||
*
|
||||
* The callbacks added with `add_on_set_parameters_callback` are stored in a different place.
|
||||
* `remove_on_set_parameters_callback` can't be used with the callbacks registered with this
|
||||
* method. For removing it, use `set_on_parameters_set_callback(nullptr)`.
|
||||
*
|
||||
* \param[in] callback The callback to be called when the value for a
|
||||
* parameter is about to be set.
|
||||
* \return The previous callback that was registered, if there was one,
|
||||
* otherwise nullptr.
|
||||
*/
|
||||
[[deprecated("use add_on_set_parameters_callback(OnParametersSetCallbackType callback) instead")]]
|
||||
RCLCPP_PUBLIC
|
||||
OnParametersSetCallbackType
|
||||
set_on_parameters_set_callback(rclcpp::Node::OnParametersSetCallbackType callback);
|
||||
|
||||
/// Get the fully-qualified names of all available nodes.
|
||||
/**
|
||||
* The fully-qualified name includes the local namespace and name of the node.
|
||||
@@ -887,21 +905,15 @@ public:
|
||||
const std::string & node_name,
|
||||
const std::string & namespace_) const;
|
||||
|
||||
/// Return the number of publishers created for a given topic.
|
||||
/**
|
||||
* \param[in] topic_name the actual topic name used; it will not be automatically remapped.
|
||||
* \return number of publishers that have been created for the given topic.
|
||||
* \throws std::runtime_error if publishers could not be counted
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
size_t
|
||||
count_publishers(const std::string & topic_name) const;
|
||||
|
||||
/// Return the number of subscribers created for a given topic.
|
||||
/// Return the number of subscribers who have created a subscription for a given topic.
|
||||
/**
|
||||
* \param[in] topic_name the actual topic name used; it will not be automatically remapped.
|
||||
* \return number of subscribers that have been created for the given topic.
|
||||
* \throws std::runtime_error if subscribers could not be counted
|
||||
* \param[in] topic_name the topic_name on which to count the subscribers.
|
||||
* \return number of subscribers who have created a subscription for a given topic.
|
||||
* \throws std::runtime_error if publishers could not be counted
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
size_t
|
||||
@@ -922,7 +934,7 @@ public:
|
||||
* A relative or private topic will be expanded using this node's namespace and name.
|
||||
* The queried `topic_name` is not remapped.
|
||||
*
|
||||
* \param[in] topic_name the actual topic name used; it will not be automatically remapped.
|
||||
* \param[in] topic_name the topic_name on which to find the publishers.
|
||||
* \param[in] no_mangle if `true`, `topic_name` needs to be a valid middleware topic name,
|
||||
* otherwise it should be a valid ROS topic name. Defaults to `false`.
|
||||
* \return a list of TopicEndpointInfo representing all the publishers on this topic.
|
||||
@@ -948,7 +960,7 @@ public:
|
||||
* A relative or private topic will be expanded using this node's namespace and name.
|
||||
* The queried `topic_name` is not remapped.
|
||||
*
|
||||
* \param[in] topic_name the actual topic name used; it will not be automatically remapped.
|
||||
* \param[in] topic_name the topic_name on which to find the subscriptions.
|
||||
* \param[in] no_mangle if `true`, `topic_name` needs to be a valid middleware topic name,
|
||||
* otherwise it should be a valid ROS topic name. Defaults to `false`.
|
||||
* \return a list of TopicEndpointInfo representing all the subscriptions on this topic.
|
||||
@@ -1182,6 +1194,10 @@ protected:
|
||||
private:
|
||||
RCLCPP_DISABLE_COPY(Node)
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
bool
|
||||
group_in_node(CallbackGroup::SharedPtr group);
|
||||
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_;
|
||||
rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph_;
|
||||
rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging_;
|
||||
|
||||
@@ -83,9 +83,7 @@ public:
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
rclcpp::CallbackGroup::SharedPtr
|
||||
create_callback_group(
|
||||
rclcpp::CallbackGroupType group_type,
|
||||
bool automatically_add_to_executor_with_node = true) override;
|
||||
create_callback_group(rclcpp::CallbackGroupType group_type) override;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
rclcpp::CallbackGroup::SharedPtr
|
||||
@@ -118,10 +116,6 @@ public:
|
||||
bool
|
||||
get_enable_topic_statistics_default() const override;
|
||||
|
||||
std::string
|
||||
resolve_topic_or_service_name(
|
||||
const std::string & name, bool is_service, bool only_expand = false) const override;
|
||||
|
||||
private:
|
||||
RCLCPP_DISABLE_COPY(NodeBase)
|
||||
|
||||
|
||||
@@ -106,9 +106,7 @@ public:
|
||||
RCLCPP_PUBLIC
|
||||
virtual
|
||||
rclcpp::CallbackGroup::SharedPtr
|
||||
create_callback_group(
|
||||
rclcpp::CallbackGroupType group_type,
|
||||
bool automatically_add_to_executor_with_node = true) = 0;
|
||||
create_callback_group(rclcpp::CallbackGroupType group_type) = 0;
|
||||
|
||||
/// Return the default callback group.
|
||||
RCLCPP_PUBLIC
|
||||
@@ -163,13 +161,6 @@ public:
|
||||
virtual
|
||||
bool
|
||||
get_enable_topic_statistics_default() const = 0;
|
||||
|
||||
/// Expand and remap a given topic or service name.
|
||||
RCLCPP_PUBLIC
|
||||
virtual
|
||||
std::string
|
||||
resolve_topic_or_service_name(
|
||||
const std::string & name, bool is_service, bool only_expand = false) const = 0;
|
||||
};
|
||||
|
||||
} // namespace node_interfaces
|
||||
|
||||
@@ -110,7 +110,7 @@ public:
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
size_t
|
||||
count_graph_users() const override;
|
||||
count_graph_users() override;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
std::vector<rclcpp::TopicEndpointInfo>
|
||||
|
||||
@@ -146,7 +146,6 @@ public:
|
||||
/**
|
||||
* A topic is considered to exist when at least one publisher or subscriber
|
||||
* exists for it, whether they be local or remote to this process.
|
||||
* The returned names are the actual names used and do not have remap rules applied.
|
||||
*
|
||||
* \param[in] no_demangle if true, topic names and types are not demangled
|
||||
*/
|
||||
@@ -160,7 +159,6 @@ public:
|
||||
* A service is considered to exist when at least one service server or
|
||||
* service client exists for it, whether they be local or remote to this
|
||||
* process.
|
||||
* The returned names are the actual names used and do not have remap rules applied.
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
virtual
|
||||
@@ -170,7 +168,6 @@ public:
|
||||
/// Return a map of existing service names to list of service types for a specific node.
|
||||
/**
|
||||
* This function only considers services - not clients.
|
||||
* The returned names are the actual names used and do not have remap rules applied.
|
||||
*
|
||||
* \param[in] node_name name of the node
|
||||
* \param[in] namespace_ namespace of the node
|
||||
@@ -183,36 +180,24 @@ public:
|
||||
const std::string & namespace_) const = 0;
|
||||
|
||||
/// Return a vector of existing node names (string).
|
||||
/*
|
||||
* The returned names are the actual names used and do not have remap rules applied.
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
virtual
|
||||
std::vector<std::string>
|
||||
get_node_names() const = 0;
|
||||
|
||||
/// Return a vector of existing node names and namespaces (pair of string).
|
||||
/*
|
||||
* The returned names are the actual names used and do not have remap rules applied.
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
virtual
|
||||
std::vector<std::pair<std::string, std::string>>
|
||||
get_node_names_and_namespaces() const = 0;
|
||||
|
||||
/// Return the number of publishers that are advertised on a given topic.
|
||||
/*
|
||||
* \param[in] topic_name the actual topic name used; it will not be automatically remapped.
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
virtual
|
||||
size_t
|
||||
count_publishers(const std::string & topic_name) const = 0;
|
||||
|
||||
/// Return the number of subscribers who have created a subscription for a given topic.
|
||||
/*
|
||||
* \param[in] topic_name the actual topic name used; it will not be automatically remapped.
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
virtual
|
||||
size_t
|
||||
@@ -278,11 +263,10 @@ public:
|
||||
RCLCPP_PUBLIC
|
||||
virtual
|
||||
size_t
|
||||
count_graph_users() const = 0;
|
||||
count_graph_users() = 0;
|
||||
|
||||
/// Return the topic endpoint information about publishers on a given topic.
|
||||
/**
|
||||
* \param[in] topic_name the actual topic name used; it will not be automatically remapped.
|
||||
* \sa rclcpp::Node::get_publishers_info_by_topic
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
@@ -292,7 +276,6 @@ public:
|
||||
|
||||
/// Return the topic endpoint information about subscriptions on a given topic.
|
||||
/**
|
||||
* \param[in] topic_name the actual topic name used; it will not be automatically remapped.
|
||||
* \sa rclcpp::Node::get_subscriptions_info_by_topic
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
|
||||
@@ -170,6 +170,11 @@ public:
|
||||
void
|
||||
remove_on_set_parameters_callback(const OnSetParametersCallbackHandle * const handler) override;
|
||||
|
||||
[[deprecated("use add_on_set_parameters_callback(OnParametersSetCallbackType callback) instead")]]
|
||||
RCLCPP_PUBLIC
|
||||
OnParametersSetCallbackType
|
||||
set_on_parameters_set_callback(OnParametersSetCallbackType callback) override;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
const std::map<std::string, rclcpp::ParameterValue> &
|
||||
get_parameter_overrides() const override;
|
||||
|
||||
@@ -191,6 +191,17 @@ public:
|
||||
void
|
||||
remove_on_set_parameters_callback(const OnSetParametersCallbackHandle * const handler) = 0;
|
||||
|
||||
/// Register a callback for when parameters are being set, return an existing one.
|
||||
/**
|
||||
* \deprecated Use add_on_set_parameters_callback instead.
|
||||
* \sa rclcpp::Node::set_on_parameters_set_callback
|
||||
*/
|
||||
[[deprecated("use add_on_set_parameters_callback(OnParametersSetCallbackType callback) instead")]]
|
||||
RCLCPP_PUBLIC
|
||||
virtual
|
||||
OnParametersSetCallbackType
|
||||
set_on_parameters_set_callback(OnParametersSetCallbackType callback) = 0;
|
||||
|
||||
/// Return the initial parameter values used by the NodeParameters to override default values.
|
||||
RCLCPP_PUBLIC
|
||||
virtual
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
#ifndef RCLCPP__NODE_INTERFACES__NODE_SERVICES_HPP_
|
||||
#define RCLCPP__NODE_INTERFACES__NODE_SERVICES_HPP_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "rclcpp/callback_group.hpp"
|
||||
#include "rclcpp/client.hpp"
|
||||
#include "rclcpp/macros.hpp"
|
||||
@@ -55,10 +53,6 @@ public:
|
||||
rclcpp::ServiceBase::SharedPtr service_base_ptr,
|
||||
rclcpp::CallbackGroup::SharedPtr group) override;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
std::string
|
||||
resolve_service_name(const std::string & name, bool only_expand = false) const override;
|
||||
|
||||
private:
|
||||
RCLCPP_DISABLE_COPY(NodeServices)
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
#ifndef RCLCPP__NODE_INTERFACES__NODE_SERVICES_INTERFACE_HPP_
|
||||
#define RCLCPP__NODE_INTERFACES__NODE_SERVICES_INTERFACE_HPP_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "rclcpp/callback_group.hpp"
|
||||
#include "rclcpp/client.hpp"
|
||||
#include "rclcpp/macros.hpp"
|
||||
@@ -51,12 +49,6 @@ public:
|
||||
add_service(
|
||||
rclcpp::ServiceBase::SharedPtr service_base_ptr,
|
||||
rclcpp::CallbackGroup::SharedPtr group) = 0;
|
||||
|
||||
/// Get the remapped and expanded service name given a input name.
|
||||
RCLCPP_PUBLIC
|
||||
virtual
|
||||
std::string
|
||||
resolve_service_name(const std::string & name, bool only_expand = false) const = 0;
|
||||
};
|
||||
|
||||
} // namespace node_interfaces
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include "rclcpp/node_interfaces/node_services_interface.hpp"
|
||||
#include "rclcpp/node_interfaces/node_time_source_interface.hpp"
|
||||
#include "rclcpp/node_interfaces/node_topics_interface.hpp"
|
||||
#include "rclcpp/qos.hpp"
|
||||
#include "rclcpp/time_source.hpp"
|
||||
#include "rclcpp/visibility_control.hpp"
|
||||
|
||||
@@ -47,8 +46,7 @@ public:
|
||||
rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services,
|
||||
rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging,
|
||||
rclcpp::node_interfaces::NodeClockInterface::SharedPtr node_clock,
|
||||
rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_parameters,
|
||||
const rclcpp::QoS & qos = rclcpp::RosoutQoS()
|
||||
rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_parameters
|
||||
);
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
|
||||
@@ -81,10 +81,6 @@ public:
|
||||
rclcpp::node_interfaces::NodeTimersInterface *
|
||||
get_node_timers_interface() const override;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
std::string
|
||||
resolve_topic_name(const std::string & name, bool only_expand = false) const override;
|
||||
|
||||
private:
|
||||
RCLCPP_DISABLE_COPY(NodeTopics)
|
||||
|
||||
|
||||
@@ -86,12 +86,6 @@ public:
|
||||
virtual
|
||||
rclcpp::node_interfaces::NodeTimersInterface *
|
||||
get_node_timers_interface() const = 0;
|
||||
|
||||
/// Get a remapped and expanded topic name given an input name.
|
||||
RCLCPP_PUBLIC
|
||||
virtual
|
||||
std::string
|
||||
resolve_topic_name(const std::string & name, bool only_expand = false) const = 0;
|
||||
};
|
||||
|
||||
} // namespace node_interfaces
|
||||
|
||||
@@ -46,8 +46,6 @@ public:
|
||||
* - enable_topic_statistics = false
|
||||
* - start_parameter_services = true
|
||||
* - start_parameter_event_publisher = true
|
||||
* - clock_qos = rclcpp::ClockQoS()
|
||||
* - rosout_qos = rclcpp::RosoutQoS()
|
||||
* - parameter_event_qos = rclcpp::ParameterEventQoS
|
||||
* - with history setting and depth from rmw_qos_profile_parameter_events
|
||||
* - parameter_event_publisher_options = rclcpp::PublisherOptionsBase
|
||||
@@ -245,19 +243,6 @@ public:
|
||||
NodeOptions &
|
||||
start_parameter_event_publisher(bool start_parameter_event_publisher);
|
||||
|
||||
/// Return a reference to the clock QoS.
|
||||
RCLCPP_PUBLIC
|
||||
const rclcpp::QoS &
|
||||
clock_qos() const;
|
||||
|
||||
/// Set the clock QoS.
|
||||
/**
|
||||
* The QoS settings to be used for the publisher on /clock topic, if enabled.
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
NodeOptions &
|
||||
clock_qos(const rclcpp::QoS & clock_qos);
|
||||
|
||||
/// Return a reference to the parameter_event_qos QoS.
|
||||
RCLCPP_PUBLIC
|
||||
const rclcpp::QoS &
|
||||
@@ -271,19 +256,6 @@ public:
|
||||
NodeOptions &
|
||||
parameter_event_qos(const rclcpp::QoS & parameter_event_qos);
|
||||
|
||||
/// Return a reference to the rosout QoS.
|
||||
RCLCPP_PUBLIC
|
||||
const rclcpp::QoS &
|
||||
rosout_qos() const;
|
||||
|
||||
/// Set the rosout QoS.
|
||||
/**
|
||||
* The QoS settings to be used for the publisher on /rosout topic, if enabled.
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
NodeOptions &
|
||||
rosout_qos(const rclcpp::QoS & rosout_qos);
|
||||
|
||||
/// Return a reference to the parameter_event_publisher_options.
|
||||
RCLCPP_PUBLIC
|
||||
const rclcpp::PublisherOptionsBase &
|
||||
@@ -355,6 +327,11 @@ public:
|
||||
NodeOptions &
|
||||
allocator(rcl_allocator_t allocator);
|
||||
|
||||
protected:
|
||||
/// Retrieve the ROS_DOMAIN_ID environment variable and populate options.
|
||||
size_t
|
||||
get_domain_id_from_env() const;
|
||||
|
||||
private:
|
||||
// This is mutable to allow for a const accessor which lazily creates the node options instance.
|
||||
/// Underlying rcl_node_options structure.
|
||||
@@ -382,14 +359,10 @@ private:
|
||||
|
||||
bool start_parameter_event_publisher_ {true};
|
||||
|
||||
rclcpp::QoS clock_qos_ = rclcpp::ClockQoS();
|
||||
|
||||
rclcpp::QoS parameter_event_qos_ = rclcpp::ParameterEventsQoS(
|
||||
rclcpp::QoSInitialization::from_rmw(rmw_qos_profile_parameter_events)
|
||||
);
|
||||
|
||||
rclcpp::QoS rosout_qos_ = rclcpp::RosoutQoS();
|
||||
|
||||
rclcpp::PublisherOptionsBase parameter_event_publisher_options_ = rclcpp::PublisherOptionsBase();
|
||||
|
||||
bool allow_undeclared_parameters_ {false};
|
||||
|
||||
@@ -73,21 +73,12 @@ public:
|
||||
* \param[in] qos_profile (optional) The rmw qos profile to use to subscribe
|
||||
* \param[in] group (optional) The async parameter client will be added to this callback group.
|
||||
*/
|
||||
template<typename NodeT>
|
||||
RCLCPP_PUBLIC
|
||||
AsyncParametersClient(
|
||||
const std::shared_ptr<NodeT> node,
|
||||
const rclcpp::Node::SharedPtr node,
|
||||
const std::string & remote_node_name = "",
|
||||
const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters,
|
||||
rclcpp::CallbackGroup::SharedPtr group = nullptr)
|
||||
: AsyncParametersClient(
|
||||
node->get_node_base_interface(),
|
||||
node->get_node_topics_interface(),
|
||||
node->get_node_graph_interface(),
|
||||
node->get_node_services_interface(),
|
||||
remote_node_name,
|
||||
qos_profile,
|
||||
group)
|
||||
{}
|
||||
rclcpp::CallbackGroup::SharedPtr group = nullptr);
|
||||
|
||||
/// Constructor
|
||||
/**
|
||||
@@ -96,21 +87,12 @@ public:
|
||||
* \param[in] qos_profile (optional) The rmw qos profile to use to subscribe
|
||||
* \param[in] group (optional) The async parameter client will be added to this callback group.
|
||||
*/
|
||||
template<typename NodeT>
|
||||
RCLCPP_PUBLIC
|
||||
AsyncParametersClient(
|
||||
NodeT * node,
|
||||
rclcpp::Node * node,
|
||||
const std::string & remote_node_name = "",
|
||||
const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters,
|
||||
rclcpp::CallbackGroup::SharedPtr group = nullptr)
|
||||
: AsyncParametersClient(
|
||||
node->get_node_base_interface(),
|
||||
node->get_node_topics_interface(),
|
||||
node->get_node_graph_interface(),
|
||||
node->get_node_services_interface(),
|
||||
remote_node_name,
|
||||
qos_profile,
|
||||
group)
|
||||
{}
|
||||
rclcpp::CallbackGroup::SharedPtr group = nullptr);
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
std::shared_future<std::vector<rclcpp::Parameter>>
|
||||
@@ -255,61 +237,31 @@ class SyncParametersClient
|
||||
public:
|
||||
RCLCPP_SMART_PTR_DEFINITIONS(SyncParametersClient)
|
||||
|
||||
template<typename NodeT>
|
||||
RCLCPP_PUBLIC
|
||||
explicit SyncParametersClient(
|
||||
std::shared_ptr<NodeT> node,
|
||||
rclcpp::Node::SharedPtr node,
|
||||
const std::string & remote_node_name = "",
|
||||
const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters)
|
||||
: SyncParametersClient(
|
||||
std::make_shared<rclcpp::executors::SingleThreadedExecutor>(),
|
||||
node,
|
||||
remote_node_name,
|
||||
qos_profile)
|
||||
{}
|
||||
const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters);
|
||||
|
||||
template<typename NodeT>
|
||||
RCLCPP_PUBLIC
|
||||
SyncParametersClient(
|
||||
rclcpp::Executor::SharedPtr executor,
|
||||
std::shared_ptr<NodeT> node,
|
||||
rclcpp::Node::SharedPtr node,
|
||||
const std::string & remote_node_name = "",
|
||||
const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters)
|
||||
: SyncParametersClient(
|
||||
executor,
|
||||
node->get_node_base_interface(),
|
||||
node->get_node_topics_interface(),
|
||||
node->get_node_graph_interface(),
|
||||
node->get_node_services_interface(),
|
||||
remote_node_name,
|
||||
qos_profile)
|
||||
{}
|
||||
const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters);
|
||||
|
||||
template<typename NodeT>
|
||||
SyncParametersClient(
|
||||
NodeT * node,
|
||||
RCLCPP_PUBLIC
|
||||
explicit SyncParametersClient(
|
||||
rclcpp::Node * node,
|
||||
const std::string & remote_node_name = "",
|
||||
const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters)
|
||||
: SyncParametersClient(
|
||||
std::make_shared<rclcpp::executors::SingleThreadedExecutor>(),
|
||||
node,
|
||||
remote_node_name,
|
||||
qos_profile)
|
||||
{}
|
||||
const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters);
|
||||
|
||||
template<typename NodeT>
|
||||
RCLCPP_PUBLIC
|
||||
SyncParametersClient(
|
||||
rclcpp::Executor::SharedPtr executor,
|
||||
NodeT * node,
|
||||
rclcpp::Node * node,
|
||||
const std::string & remote_node_name = "",
|
||||
const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters)
|
||||
: SyncParametersClient(
|
||||
executor,
|
||||
node->get_node_base_interface(),
|
||||
node->get_node_topics_interface(),
|
||||
node->get_node_graph_interface(),
|
||||
node->get_node_services_interface(),
|
||||
remote_node_name,
|
||||
qos_profile)
|
||||
{}
|
||||
const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters);
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
SyncParametersClient(
|
||||
@@ -319,18 +271,7 @@ public:
|
||||
const rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph_interface,
|
||||
const rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services_interface,
|
||||
const std::string & remote_node_name = "",
|
||||
const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters)
|
||||
: executor_(executor), node_base_interface_(node_base_interface)
|
||||
{
|
||||
async_parameters_client_ =
|
||||
std::make_shared<AsyncParametersClient>(
|
||||
node_base_interface,
|
||||
node_topics_interface,
|
||||
node_graph_interface,
|
||||
node_services_interface,
|
||||
remote_node_name,
|
||||
qos_profile);
|
||||
}
|
||||
const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters);
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
std::vector<rclcpp::Parameter>
|
||||
|
||||
@@ -68,7 +68,7 @@ public:
|
||||
* \param[in] node_base NodeBaseInterface pointer that is used in part of the setup.
|
||||
* \param[in] topic Name of the topic to publish to.
|
||||
* \param[in] qos QoS profile for Subcription.
|
||||
* \param[in] options Options for the subscription.
|
||||
* \param[in] options options for the subscription.
|
||||
*/
|
||||
Publisher(
|
||||
rclcpp::node_interfaces::NodeBaseInterface * node_base,
|
||||
|
||||
@@ -92,12 +92,7 @@ struct PublisherOptionsWithAllocator : public PublisherOptionsBase
|
||||
get_allocator() const
|
||||
{
|
||||
if (!this->allocator) {
|
||||
// TODO(wjwwood): I would like to use the commented line instead, but
|
||||
// cppcheck 1.89 fails with:
|
||||
// Syntax Error: AST broken, binary operator '>' doesn't have two operands.
|
||||
// return std::make_shared<Allocator>();
|
||||
std::shared_ptr<Allocator> tmp(new Allocator());
|
||||
return tmp;
|
||||
return std::make_shared<Allocator>();
|
||||
}
|
||||
return this->allocator;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
#include "rclcpp/duration.hpp"
|
||||
#include "rclcpp/visibility_control.hpp"
|
||||
#include "rcl/logging_rosout.h"
|
||||
#include "rmw/incompatible_qos_events_statuses.h"
|
||||
#include "rmw/qos_profiles.h"
|
||||
#include "rmw/types.h"
|
||||
@@ -163,26 +162,6 @@ bool operator==(const QoS & left, const QoS & right);
|
||||
RCLCPP_PUBLIC
|
||||
bool operator!=(const QoS & left, const QoS & right);
|
||||
|
||||
/**
|
||||
* Clock QoS class
|
||||
* - History: Keep last,
|
||||
* - Depth: 1,
|
||||
* - Reliability: Best effort,
|
||||
* - Durability: Volatile,
|
||||
* - Deadline: Default,
|
||||
* - Lifespan: Default,
|
||||
* - Liveliness: System default,
|
||||
* - Liveliness lease duration: default,
|
||||
* - avoid ros namespace conventions: false
|
||||
*/
|
||||
class RCLCPP_PUBLIC ClockQoS : public QoS
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
ClockQoS(
|
||||
const QoSInitialization & qos_initialization = KeepLast(1));
|
||||
};
|
||||
|
||||
/**
|
||||
* Sensor Data QoS class
|
||||
* - History: Keep last,
|
||||
@@ -271,28 +250,6 @@ public:
|
||||
));
|
||||
};
|
||||
|
||||
/**
|
||||
* Rosout QoS class
|
||||
* - History: Keep last,
|
||||
* - Depth: 1000,
|
||||
* - Reliability: Reliable,
|
||||
* - Durability: TRANSIENT_LOCAL,
|
||||
* - Deadline: Default,
|
||||
* - Lifespan: {10, 0},
|
||||
* - Liveliness: System default,
|
||||
* - Liveliness lease duration: default,
|
||||
* - Avoid ros namespace conventions: false
|
||||
*/
|
||||
class RCLCPP_PUBLIC RosoutQoS : public QoS
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
RosoutQoS(
|
||||
const QoSInitialization & rosout_qos_initialization = (
|
||||
QoSInitialization::from_rmw(rcl_qos_profile_rosout_default)
|
||||
));
|
||||
};
|
||||
|
||||
/**
|
||||
* System defaults QoS class
|
||||
* - History: System default,
|
||||
|
||||
@@ -34,7 +34,6 @@ using QOSDeadlineRequestedInfo = rmw_requested_deadline_missed_status_t;
|
||||
using QOSDeadlineOfferedInfo = rmw_offered_deadline_missed_status_t;
|
||||
using QOSLivelinessChangedInfo = rmw_liveliness_changed_status_t;
|
||||
using QOSLivelinessLostInfo = rmw_liveliness_lost_status_t;
|
||||
using QOSMessageLostInfo = rmw_message_lost_status_t;
|
||||
using QOSOfferedIncompatibleQoSInfo = rmw_offered_qos_incompatible_event_status_t;
|
||||
using QOSRequestedIncompatibleQoSInfo = rmw_requested_qos_incompatible_event_status_t;
|
||||
|
||||
@@ -42,7 +41,6 @@ using QOSDeadlineRequestedCallbackType = std::function<void (QOSDeadlineRequeste
|
||||
using QOSDeadlineOfferedCallbackType = std::function<void (QOSDeadlineOfferedInfo &)>;
|
||||
using QOSLivelinessChangedCallbackType = std::function<void (QOSLivelinessChangedInfo &)>;
|
||||
using QOSLivelinessLostCallbackType = std::function<void (QOSLivelinessLostInfo &)>;
|
||||
using QOSMessageLostCallbackType = std::function<void (QOSMessageLostInfo &)>;
|
||||
using QOSOfferedIncompatibleQoSCallbackType = std::function<void (QOSOfferedIncompatibleQoSInfo &)>;
|
||||
using QOSRequestedIncompatibleQoSCallbackType =
|
||||
std::function<void (QOSRequestedIncompatibleQoSInfo &)>;
|
||||
@@ -61,7 +59,6 @@ struct SubscriptionEventCallbacks
|
||||
QOSDeadlineRequestedCallbackType deadline_callback;
|
||||
QOSLivelinessChangedCallbackType liveliness_callback;
|
||||
QOSRequestedIncompatibleQoSCallbackType incompatible_qos_callback;
|
||||
QOSMessageLostCallbackType message_lost_callback;
|
||||
};
|
||||
|
||||
class UnsupportedEventTypeException : public exceptions::RCLErrorBase, public std::runtime_error
|
||||
|
||||
@@ -223,8 +223,8 @@ public:
|
||||
}
|
||||
TRACEPOINT(
|
||||
rclcpp_service_callback_added,
|
||||
static_cast<const void *>(get_service_handle().get()),
|
||||
static_cast<const void *>(&any_callback_));
|
||||
(const void *)get_service_handle().get(),
|
||||
(const void *)&any_callback_);
|
||||
#ifndef TRACETOOLS_DISABLED
|
||||
any_callback_.register_callback_for_tracing();
|
||||
#endif
|
||||
@@ -258,8 +258,8 @@ public:
|
||||
service_handle_ = service_handle;
|
||||
TRACEPOINT(
|
||||
rclcpp_service_callback_added,
|
||||
static_cast<const void *>(get_service_handle().get()),
|
||||
static_cast<const void *>(&any_callback_));
|
||||
(const void *)get_service_handle().get(),
|
||||
(const void *)&any_callback_);
|
||||
#ifndef TRACETOOLS_DISABLED
|
||||
any_callback_.register_callback_for_tracing();
|
||||
#endif
|
||||
@@ -295,8 +295,8 @@ public:
|
||||
service_handle_->impl = service_handle->impl;
|
||||
TRACEPOINT(
|
||||
rclcpp_service_callback_added,
|
||||
static_cast<const void *>(get_service_handle().get()),
|
||||
static_cast<const void *>(&any_callback_));
|
||||
(const void *)get_service_handle().get(),
|
||||
(const void *)&any_callback_);
|
||||
#ifndef TRACETOOLS_DISABLED
|
||||
any_callback_.register_callback_for_tracing();
|
||||
#endif
|
||||
|
||||
@@ -150,47 +150,48 @@ public:
|
||||
);
|
||||
}
|
||||
|
||||
bool collect_entities(const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) override
|
||||
bool collect_entities(const WeakNodeList & weak_nodes) override
|
||||
{
|
||||
bool has_invalid_weak_groups_or_nodes = false;
|
||||
for (const auto & pair : weak_groups_to_nodes) {
|
||||
auto group = pair.first.lock();
|
||||
auto node = pair.second.lock();
|
||||
if (group == nullptr || node == nullptr) {
|
||||
has_invalid_weak_groups_or_nodes = true;
|
||||
bool has_invalid_weak_nodes = false;
|
||||
for (auto & weak_node : weak_nodes) {
|
||||
auto node = weak_node.lock();
|
||||
if (!node) {
|
||||
has_invalid_weak_nodes = true;
|
||||
continue;
|
||||
}
|
||||
if (!group || !group->can_be_taken_from().load()) {
|
||||
continue;
|
||||
for (auto & weak_group : node->get_callback_groups()) {
|
||||
auto group = weak_group.lock();
|
||||
if (!group || !group->can_be_taken_from().load()) {
|
||||
continue;
|
||||
}
|
||||
group->find_subscription_ptrs_if(
|
||||
[this](const rclcpp::SubscriptionBase::SharedPtr & subscription) {
|
||||
subscription_handles_.push_back(subscription->get_subscription_handle());
|
||||
return false;
|
||||
});
|
||||
group->find_service_ptrs_if(
|
||||
[this](const rclcpp::ServiceBase::SharedPtr & service) {
|
||||
service_handles_.push_back(service->get_service_handle());
|
||||
return false;
|
||||
});
|
||||
group->find_client_ptrs_if(
|
||||
[this](const rclcpp::ClientBase::SharedPtr & client) {
|
||||
client_handles_.push_back(client->get_client_handle());
|
||||
return false;
|
||||
});
|
||||
group->find_timer_ptrs_if(
|
||||
[this](const rclcpp::TimerBase::SharedPtr & timer) {
|
||||
timer_handles_.push_back(timer->get_timer_handle());
|
||||
return false;
|
||||
});
|
||||
group->find_waitable_ptrs_if(
|
||||
[this](const rclcpp::Waitable::SharedPtr & waitable) {
|
||||
waitable_handles_.push_back(waitable);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
group->find_subscription_ptrs_if(
|
||||
[this](const rclcpp::SubscriptionBase::SharedPtr & subscription) {
|
||||
subscription_handles_.push_back(subscription->get_subscription_handle());
|
||||
return false;
|
||||
});
|
||||
group->find_service_ptrs_if(
|
||||
[this](const rclcpp::ServiceBase::SharedPtr & service) {
|
||||
service_handles_.push_back(service->get_service_handle());
|
||||
return false;
|
||||
});
|
||||
group->find_client_ptrs_if(
|
||||
[this](const rclcpp::ClientBase::SharedPtr & client) {
|
||||
client_handles_.push_back(client->get_client_handle());
|
||||
return false;
|
||||
});
|
||||
group->find_timer_ptrs_if(
|
||||
[this](const rclcpp::TimerBase::SharedPtr & timer) {
|
||||
timer_handles_.push_back(timer->get_timer_handle());
|
||||
return false;
|
||||
});
|
||||
group->find_waitable_ptrs_if(
|
||||
[this](const rclcpp::Waitable::SharedPtr & waitable) {
|
||||
waitable_handles_.push_back(waitable);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
return has_invalid_weak_groups_or_nodes;
|
||||
return has_invalid_weak_nodes;
|
||||
}
|
||||
|
||||
void add_waitable_handle(const rclcpp::Waitable::SharedPtr & waitable) override
|
||||
@@ -263,14 +264,14 @@ public:
|
||||
void
|
||||
get_next_subscription(
|
||||
rclcpp::AnyExecutable & any_exec,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) override
|
||||
const WeakNodeList & weak_nodes) override
|
||||
{
|
||||
auto it = subscription_handles_.begin();
|
||||
while (it != subscription_handles_.end()) {
|
||||
auto subscription = get_subscription_by_handle(*it, weak_groups_to_nodes);
|
||||
auto subscription = get_subscription_by_handle(*it, weak_nodes);
|
||||
if (subscription) {
|
||||
// Find the group for this handle and see if it can be serviced
|
||||
auto group = get_group_by_subscription(subscription, weak_groups_to_nodes);
|
||||
auto group = get_group_by_subscription(subscription, weak_nodes);
|
||||
if (!group) {
|
||||
// Group was not found, meaning the subscription is not valid...
|
||||
// Remove it from the ready list and continue looking
|
||||
@@ -286,7 +287,7 @@ public:
|
||||
// Otherwise it is safe to set and return the any_exec
|
||||
any_exec.subscription = subscription;
|
||||
any_exec.callback_group = group;
|
||||
any_exec.node_base = get_node_by_group(group, weak_groups_to_nodes);
|
||||
any_exec.node_base = get_node_by_group(group, weak_nodes);
|
||||
subscription_handles_.erase(it);
|
||||
return;
|
||||
}
|
||||
@@ -298,14 +299,14 @@ public:
|
||||
void
|
||||
get_next_service(
|
||||
rclcpp::AnyExecutable & any_exec,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) override
|
||||
const WeakNodeList & weak_nodes) override
|
||||
{
|
||||
auto it = service_handles_.begin();
|
||||
while (it != service_handles_.end()) {
|
||||
auto service = get_service_by_handle(*it, weak_groups_to_nodes);
|
||||
auto service = get_service_by_handle(*it, weak_nodes);
|
||||
if (service) {
|
||||
// Find the group for this handle and see if it can be serviced
|
||||
auto group = get_group_by_service(service, weak_groups_to_nodes);
|
||||
auto group = get_group_by_service(service, weak_nodes);
|
||||
if (!group) {
|
||||
// Group was not found, meaning the service is not valid...
|
||||
// Remove it from the ready list and continue looking
|
||||
@@ -321,7 +322,7 @@ public:
|
||||
// Otherwise it is safe to set and return the any_exec
|
||||
any_exec.service = service;
|
||||
any_exec.callback_group = group;
|
||||
any_exec.node_base = get_node_by_group(group, weak_groups_to_nodes);
|
||||
any_exec.node_base = get_node_by_group(group, weak_nodes);
|
||||
service_handles_.erase(it);
|
||||
return;
|
||||
}
|
||||
@@ -331,16 +332,14 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
get_next_client(
|
||||
rclcpp::AnyExecutable & any_exec,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) override
|
||||
get_next_client(rclcpp::AnyExecutable & any_exec, const WeakNodeList & weak_nodes) override
|
||||
{
|
||||
auto it = client_handles_.begin();
|
||||
while (it != client_handles_.end()) {
|
||||
auto client = get_client_by_handle(*it, weak_groups_to_nodes);
|
||||
auto client = get_client_by_handle(*it, weak_nodes);
|
||||
if (client) {
|
||||
// Find the group for this handle and see if it can be serviced
|
||||
auto group = get_group_by_client(client, weak_groups_to_nodes);
|
||||
auto group = get_group_by_client(client, weak_nodes);
|
||||
if (!group) {
|
||||
// Group was not found, meaning the service is not valid...
|
||||
// Remove it from the ready list and continue looking
|
||||
@@ -356,7 +355,7 @@ public:
|
||||
// Otherwise it is safe to set and return the any_exec
|
||||
any_exec.client = client;
|
||||
any_exec.callback_group = group;
|
||||
any_exec.node_base = get_node_by_group(group, weak_groups_to_nodes);
|
||||
any_exec.node_base = get_node_by_group(group, weak_nodes);
|
||||
client_handles_.erase(it);
|
||||
return;
|
||||
}
|
||||
@@ -368,14 +367,14 @@ public:
|
||||
void
|
||||
get_next_timer(
|
||||
rclcpp::AnyExecutable & any_exec,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) override
|
||||
const WeakNodeList & weak_nodes) override
|
||||
{
|
||||
auto it = timer_handles_.begin();
|
||||
while (it != timer_handles_.end()) {
|
||||
auto timer = get_timer_by_handle(*it, weak_groups_to_nodes);
|
||||
auto timer = get_timer_by_handle(*it, weak_nodes);
|
||||
if (timer) {
|
||||
// Find the group for this handle and see if it can be serviced
|
||||
auto group = get_group_by_timer(timer, weak_groups_to_nodes);
|
||||
auto group = get_group_by_timer(timer, weak_nodes);
|
||||
if (!group) {
|
||||
// Group was not found, meaning the timer is not valid...
|
||||
// Remove it from the ready list and continue looking
|
||||
@@ -391,7 +390,7 @@ public:
|
||||
// Otherwise it is safe to set and return the any_exec
|
||||
any_exec.timer = timer;
|
||||
any_exec.callback_group = group;
|
||||
any_exec.node_base = get_node_by_group(group, weak_groups_to_nodes);
|
||||
any_exec.node_base = get_node_by_group(group, weak_nodes);
|
||||
timer_handles_.erase(it);
|
||||
return;
|
||||
}
|
||||
@@ -401,16 +400,14 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
get_next_waitable(
|
||||
rclcpp::AnyExecutable & any_exec,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) override
|
||||
get_next_waitable(rclcpp::AnyExecutable & any_exec, const WeakNodeList & weak_nodes) override
|
||||
{
|
||||
auto it = waitable_handles_.begin();
|
||||
while (it != waitable_handles_.end()) {
|
||||
auto waitable = *it;
|
||||
if (waitable) {
|
||||
// Find the group for this handle and see if it can be serviced
|
||||
auto group = get_group_by_waitable(waitable, weak_groups_to_nodes);
|
||||
auto group = get_group_by_waitable(waitable, weak_nodes);
|
||||
if (!group) {
|
||||
// Group was not found, meaning the waitable is not valid...
|
||||
// Remove it from the ready list and continue looking
|
||||
@@ -426,7 +423,7 @@ public:
|
||||
// Otherwise it is safe to set and return the any_exec
|
||||
any_exec.waitable = waitable;
|
||||
any_exec.callback_group = group;
|
||||
any_exec.node_base = get_node_by_group(group, weak_groups_to_nodes);
|
||||
any_exec.node_base = get_node_by_group(group, weak_nodes);
|
||||
waitable_handles_.erase(it);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public:
|
||||
* \param[in] topic_name Name of the topic to subscribe to.
|
||||
* \param[in] qos QoS profile for Subcription.
|
||||
* \param[in] callback User defined callback to call when a message is received.
|
||||
* \param[in] options Options for the subscription.
|
||||
* \param[in] options options for the subscription.
|
||||
* \param[in] message_memory_strategy The memory strategy to be used for managing message memory.
|
||||
* \param[in] subscription_topic_statistics Optional pointer to a topic statistics subcription.
|
||||
* \throws std::invalid_argument if the QoS is uncompatible with intra-process (if one
|
||||
@@ -144,11 +144,6 @@ public:
|
||||
// pass
|
||||
}
|
||||
}
|
||||
if (options.event_callbacks.message_lost_callback) {
|
||||
this->add_event_handler(
|
||||
options.event_callbacks.message_lost_callback,
|
||||
RCL_SUBSCRIPTION_MESSAGE_LOST);
|
||||
}
|
||||
|
||||
// Setup intra process publishing if requested.
|
||||
if (rclcpp::detail::resolve_use_intra_process(options, *node_base)) {
|
||||
@@ -184,8 +179,8 @@ public:
|
||||
resolve_intra_process_buffer_type(options.intra_process_buffer_type, callback));
|
||||
TRACEPOINT(
|
||||
rclcpp_subscription_init,
|
||||
static_cast<const void *>(get_subscription_handle().get()),
|
||||
static_cast<const void *>(subscription_intra_process.get()));
|
||||
(const void *)get_subscription_handle().get(),
|
||||
(const void *)subscription_intra_process.get());
|
||||
|
||||
// Add it to the intra process manager.
|
||||
using rclcpp::experimental::IntraProcessManager;
|
||||
@@ -200,12 +195,12 @@ public:
|
||||
|
||||
TRACEPOINT(
|
||||
rclcpp_subscription_init,
|
||||
static_cast<const void *>(get_subscription_handle().get()),
|
||||
static_cast<const void *>(this));
|
||||
(const void *)get_subscription_handle().get(),
|
||||
(const void *)this);
|
||||
TRACEPOINT(
|
||||
rclcpp_subscription_callback_added,
|
||||
static_cast<const void *>(this),
|
||||
static_cast<const void *>(&any_callback_));
|
||||
(const void *)this,
|
||||
(const void *)&any_callback_);
|
||||
// The callback object gets copied, so if registration is done too early/before this point
|
||||
// (e.g. in `AnySubscriptionCallback::set()`), its address won't match any address used later
|
||||
// in subsequent tracepoints.
|
||||
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
* \param[in] node_base NodeBaseInterface pointer used in parts of the setup.
|
||||
* \param[in] type_support_handle rosidl type support struct, for the Message type of the topic.
|
||||
* \param[in] topic_name Name of the topic to subscribe to.
|
||||
* \param[in] subscription_options Options for the subscription.
|
||||
* \param[in] subscription_options options for the subscription.
|
||||
* \param[in] is_serialized is true if the message will be delivered still serialized
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
|
||||
@@ -101,7 +101,7 @@ struct SubscriptionOptionsWithAllocator : public SubscriptionOptionsBase
|
||||
rcl_subscription_options_t result = rcl_subscription_get_default_options();
|
||||
using AllocatorTraits = std::allocator_traits<Allocator>;
|
||||
using MessageAllocatorT = typename AllocatorTraits::template rebind_alloc<MessageT>;
|
||||
auto message_alloc = std::make_shared<MessageAllocatorT>(*allocator.get());
|
||||
auto message_alloc = std::make_shared<MessageAllocatorT>(*this->get_allocator().get());
|
||||
result.allocator = allocator::get_rcl_allocator<MessageT>(*message_alloc);
|
||||
result.qos = qos.get_rmw_qos_profile();
|
||||
result.rmw_subscription_options.ignore_local_publications = this->ignore_local_publications;
|
||||
|
||||
@@ -23,13 +23,6 @@
|
||||
|
||||
#include "rclcpp/duration.hpp"
|
||||
|
||||
// Windows has preprocessor defines for "min" and "max", which can cause
|
||||
// problems when things like std::numeric_limits<int>::max are used. This
|
||||
// macro is used to defeat the macro matching logic and hence workaround the
|
||||
// issue. The idea comes from:
|
||||
// https://stackoverflow.com/questions/11544073/how-do-i-deal-with-the-max-macro-in-windows-h-colliding-with-max-in-std/11550864#11550864
|
||||
#define PREVENT_WINDOWS_MIN_MAX
|
||||
|
||||
namespace rclcpp
|
||||
{
|
||||
|
||||
@@ -196,7 +189,7 @@ public:
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
static Time
|
||||
max PREVENT_WINDOWS_MIN_MAX();
|
||||
max();
|
||||
|
||||
/// Get the seconds since epoch
|
||||
/**
|
||||
|
||||
@@ -40,19 +40,16 @@ public:
|
||||
* The node will be attached to the time source.
|
||||
*
|
||||
* \param node std::shared pointer to a initialized node
|
||||
* \param qos QoS that will be used when creating a `/clock` subscription.
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
explicit TimeSource(rclcpp::Node::SharedPtr node, const rclcpp::QoS & qos = rclcpp::ClockQoS());
|
||||
explicit TimeSource(rclcpp::Node::SharedPtr node);
|
||||
|
||||
/// Empty constructor
|
||||
/**
|
||||
* An Empty TimeSource class
|
||||
*
|
||||
* \param qos QoS that will be used when creating a `/clock` subscription.
|
||||
*/
|
||||
RCLCPP_PUBLIC
|
||||
explicit TimeSource(const rclcpp::QoS & qos = rclcpp::ClockQoS());
|
||||
TimeSource();
|
||||
|
||||
/// Attack node to the time source.
|
||||
/**
|
||||
@@ -117,14 +114,11 @@ private:
|
||||
// Store (and update on node attach) logger for logging.
|
||||
Logger logger_;
|
||||
|
||||
// QoS of the clock subscription.
|
||||
rclcpp::QoS qos_;
|
||||
|
||||
// The subscription for the clock callback
|
||||
using MessageT = rosgraph_msgs::msg::Clock;
|
||||
using Alloc = std::allocator<void>;
|
||||
using SubscriptionT = rclcpp::Subscription<MessageT, Alloc>;
|
||||
std::shared_ptr<SubscriptionT> clock_subscription_{nullptr};
|
||||
std::shared_ptr<SubscriptionT> clock_subscription_;
|
||||
std::mutex clock_sub_lock_;
|
||||
|
||||
// The clock callback itself
|
||||
@@ -154,6 +148,8 @@ private:
|
||||
void disable_ros_time();
|
||||
|
||||
// Internal helper functions used inside iterators
|
||||
static void enable_ros_time(rclcpp::Clock::SharedPtr clock);
|
||||
static void disable_ros_time(rclcpp::Clock::SharedPtr clock);
|
||||
static void set_clock(
|
||||
const builtin_interfaces::msg::Time::SharedPtr msg,
|
||||
bool set_ros_time_enabled,
|
||||
@@ -161,7 +157,7 @@ private:
|
||||
|
||||
// Local storage of validity of ROS time
|
||||
// This is needed when new clocks are added.
|
||||
bool ros_time_active_{false};
|
||||
bool ros_time_active_;
|
||||
// Last set message to be passed to newly registered clocks
|
||||
rosgraph_msgs::msg::Clock::SharedPtr last_msg_set_;
|
||||
|
||||
@@ -170,7 +166,7 @@ private:
|
||||
// A vector to store references to associated clocks.
|
||||
std::vector<rclcpp::Clock::SharedPtr> associated_clocks_;
|
||||
// A handler for the use_sim_time parameter callback.
|
||||
rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr sim_time_cb_handler_{nullptr};
|
||||
rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr sim_time_cb_handler_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace rclcpp
|
||||
|
||||
@@ -176,11 +176,11 @@ public:
|
||||
{
|
||||
TRACEPOINT(
|
||||
rclcpp_timer_callback_added,
|
||||
static_cast<const void *>(get_timer_handle().get()),
|
||||
static_cast<const void *>(&callback_));
|
||||
(const void *)get_timer_handle().get(),
|
||||
(const void *)&callback_);
|
||||
TRACEPOINT(
|
||||
rclcpp_callback_register,
|
||||
static_cast<const void *>(&callback_),
|
||||
(const void *)&callback_,
|
||||
get_symbol(callback_));
|
||||
}
|
||||
|
||||
@@ -205,9 +205,9 @@ public:
|
||||
if (ret != RCL_RET_OK) {
|
||||
throw std::runtime_error("Failed to notify timer that callback occurred");
|
||||
}
|
||||
TRACEPOINT(callback_start, static_cast<const void *>(&callback_), false);
|
||||
TRACEPOINT(callback_start, (const void *)&callback_, false);
|
||||
execute_callback_delegate<>();
|
||||
TRACEPOINT(callback_end, static_cast<const void *>(&callback_));
|
||||
TRACEPOINT(callback_end, (const void *)&callback_);
|
||||
}
|
||||
|
||||
// void specialization
|
||||
|
||||
@@ -2,13 +2,10 @@
|
||||
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
|
||||
<package format="2">
|
||||
<name>rclcpp</name>
|
||||
<version>5.1.0</version>
|
||||
<version>2.3.1</version>
|
||||
<description>The ROS client library in C++.</description>
|
||||
<maintainer email="ivanpauno@ekumenlabs.com">Ivan Paunovic</maintainer>
|
||||
<maintainer email="mabel@openrobotics.org">Mabel Zhang</maintainer>
|
||||
<maintainer email="william@openrobotics.org">William Woodall</maintainer>
|
||||
<maintainer email="dthomas@osrfoundation.org">Dirk Thomas</maintainer>
|
||||
<license>Apache License 2.0</license>
|
||||
<author email="dthomas@openrobotics.org">Dirk Thomas</author>
|
||||
|
||||
<buildtool_depend>ament_cmake_ros</buildtool_depend>
|
||||
|
||||
|
||||
@@ -19,12 +19,8 @@
|
||||
using rclcpp::CallbackGroup;
|
||||
using rclcpp::CallbackGroupType;
|
||||
|
||||
CallbackGroup::CallbackGroup(
|
||||
CallbackGroupType group_type,
|
||||
bool automatically_add_to_executor_with_node)
|
||||
: type_(group_type), associated_with_executor_(false),
|
||||
can_be_taken_from_(true),
|
||||
automatically_add_to_executor_with_node_(automatically_add_to_executor_with_node)
|
||||
CallbackGroup::CallbackGroup(CallbackGroupType group_type)
|
||||
: type_(group_type), can_be_taken_from_(true)
|
||||
{}
|
||||
|
||||
|
||||
@@ -40,18 +36,6 @@ CallbackGroup::type() const
|
||||
return type_;
|
||||
}
|
||||
|
||||
std::atomic_bool &
|
||||
CallbackGroup::get_associated_with_executor_atomic()
|
||||
{
|
||||
return associated_with_executor_;
|
||||
}
|
||||
|
||||
bool
|
||||
CallbackGroup::automatically_add_to_executor_with_node() const
|
||||
{
|
||||
return automatically_add_to_executor_with_node_;
|
||||
}
|
||||
|
||||
void
|
||||
CallbackGroup::add_subscription(
|
||||
const rclcpp::SubscriptionBase::SharedPtr subscription_ptr)
|
||||
|
||||
@@ -199,17 +199,13 @@ Context::init(
|
||||
throw rclcpp::ContextAlreadyInitialized();
|
||||
}
|
||||
this->clean_up();
|
||||
rcl_context_t * context = new rcl_context_t;
|
||||
if (!context) {
|
||||
throw std::runtime_error("failed to allocate memory for rcl context");
|
||||
}
|
||||
*context = rcl_get_zero_initialized_context();
|
||||
rcl_ret_t ret = rcl_init(argc, argv, init_options.get_rcl_init_options(), context);
|
||||
rcl_context_.reset(new rcl_context_t, __delete_context);
|
||||
*rcl_context_.get() = rcl_get_zero_initialized_context();
|
||||
rcl_ret_t ret = rcl_init(argc, argv, init_options.get_rcl_init_options(), rcl_context_.get());
|
||||
if (RCL_RET_OK != ret) {
|
||||
delete context;
|
||||
rcl_context_.reset();
|
||||
rclcpp::exceptions::throw_from_rcl_error(ret, "failed to initialize rcl");
|
||||
}
|
||||
rcl_context_.reset(context, __delete_context);
|
||||
|
||||
if (init_options.auto_initialize_logging()) {
|
||||
logging_mutex_ = get_global_logging_mutex();
|
||||
@@ -279,17 +275,6 @@ Context::get_init_options()
|
||||
return init_options_;
|
||||
}
|
||||
|
||||
size_t
|
||||
Context::get_domain_id() const
|
||||
{
|
||||
size_t domain_id;
|
||||
rcl_ret_t ret = rcl_context_get_domain_id(rcl_context_.get(), &domain_id);
|
||||
if (RCL_RET_OK != ret) {
|
||||
rclcpp::exceptions::throw_from_rcl_error(ret, "failed to get domain id from context");
|
||||
}
|
||||
return domain_id;
|
||||
}
|
||||
|
||||
std::string
|
||||
Context::shutdown_reason()
|
||||
{
|
||||
|
||||
@@ -37,7 +37,7 @@ Duration::Duration(int32_t seconds, uint32_t nanoseconds)
|
||||
rcl_duration_.nanoseconds += nanoseconds;
|
||||
}
|
||||
|
||||
Duration::Duration(rcl_duration_value_t nanoseconds)
|
||||
Duration::Duration(int64_t nanoseconds)
|
||||
{
|
||||
rcl_duration_.nanoseconds = nanoseconds;
|
||||
}
|
||||
@@ -148,7 +148,7 @@ Duration::operator+(const rclcpp::Duration & rhs) const
|
||||
this->rcl_duration_.nanoseconds,
|
||||
rhs.rcl_duration_.nanoseconds,
|
||||
std::numeric_limits<rcl_duration_value_t>::max());
|
||||
return Duration::from_nanoseconds(
|
||||
return Duration(
|
||||
rcl_duration_.nanoseconds + rhs.rcl_duration_.nanoseconds);
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ Duration::operator-(const rclcpp::Duration & rhs) const
|
||||
rhs.rcl_duration_.nanoseconds,
|
||||
std::numeric_limits<rcl_duration_value_t>::max());
|
||||
|
||||
return Duration::from_nanoseconds(
|
||||
return Duration(
|
||||
rcl_duration_.nanoseconds - rhs.rcl_duration_.nanoseconds);
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ Duration::operator*(double scale) const
|
||||
scale,
|
||||
std::numeric_limits<rcl_duration_value_t>::max());
|
||||
long double scale_ld = static_cast<long double>(scale);
|
||||
return Duration::from_nanoseconds(
|
||||
return Duration(
|
||||
static_cast<rcl_duration_value_t>(
|
||||
static_cast<long double>(rcl_duration_.nanoseconds) * scale_ld));
|
||||
}
|
||||
@@ -249,17 +249,7 @@ Duration::to_rmw_time() const
|
||||
Duration
|
||||
Duration::from_seconds(double seconds)
|
||||
{
|
||||
Duration ret;
|
||||
ret.rcl_duration_.nanoseconds = static_cast<int64_t>(RCL_S_TO_NS(seconds));
|
||||
return ret;
|
||||
}
|
||||
|
||||
Duration
|
||||
Duration::from_nanoseconds(rcl_duration_value_t nanoseconds)
|
||||
{
|
||||
Duration ret;
|
||||
ret.rcl_duration_.nanoseconds = nanoseconds;
|
||||
return ret;
|
||||
return Duration(static_cast<int64_t>(RCL_S_TO_NS(seconds)));
|
||||
}
|
||||
|
||||
} // namespace rclcpp
|
||||
|
||||
@@ -14,26 +14,21 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "rcl/allocator.h"
|
||||
#include "rcl/error_handling.h"
|
||||
|
||||
#include "rclcpp/exceptions.hpp"
|
||||
#include "rclcpp/executor.hpp"
|
||||
#include "rclcpp/memory_strategy.hpp"
|
||||
#include "rclcpp/executors/static_single_threaded_executor.hpp"
|
||||
#include "rclcpp/node.hpp"
|
||||
#include "rclcpp/scope_exit.hpp"
|
||||
#include "rclcpp/utilities.hpp"
|
||||
|
||||
#include "rcutils/logging_macros.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
using rclcpp::exceptions::throw_from_rcl_error;
|
||||
using rclcpp::AnyExecutable;
|
||||
using rclcpp::Executor;
|
||||
@@ -86,33 +81,19 @@ Executor::Executor(const rclcpp::ExecutorOptions & options)
|
||||
|
||||
Executor::~Executor()
|
||||
{
|
||||
// Disassociate all callback groups.
|
||||
for (auto & pair : weak_groups_to_nodes_) {
|
||||
auto group = pair.first.lock();
|
||||
if (group) {
|
||||
std::atomic_bool & has_executor = group->get_associated_with_executor_atomic();
|
||||
// Disassocate all nodes
|
||||
for (auto & weak_node : weak_nodes_) {
|
||||
auto node = weak_node.lock();
|
||||
if (node) {
|
||||
std::atomic_bool & has_executor = node->get_associated_with_executor_atomic();
|
||||
has_executor.store(false);
|
||||
}
|
||||
}
|
||||
// Disassociate all nodes.
|
||||
std::for_each(
|
||||
weak_nodes_.begin(), weak_nodes_.end(), []
|
||||
(rclcpp::node_interfaces::NodeBaseInterface::WeakPtr weak_node_ptr) {
|
||||
auto shared_node_ptr = weak_node_ptr.lock();
|
||||
if (shared_node_ptr) {
|
||||
std::atomic_bool & has_executor = shared_node_ptr->get_associated_with_executor_atomic();
|
||||
has_executor.store(false);
|
||||
}
|
||||
});
|
||||
weak_nodes_.clear();
|
||||
weak_groups_associated_with_executor_to_nodes_.clear();
|
||||
weak_groups_to_nodes_associated_with_executor_.clear();
|
||||
weak_groups_to_nodes_.clear();
|
||||
for (const auto & pair : weak_nodes_to_guard_conditions_) {
|
||||
auto & guard_condition = pair.second;
|
||||
for (auto & guard_condition : guard_conditions_) {
|
||||
memory_strategy_->remove_guard_condition(guard_condition);
|
||||
}
|
||||
weak_nodes_to_guard_conditions_.clear();
|
||||
guard_conditions_.clear();
|
||||
|
||||
// Finalize the wait set.
|
||||
if (rcl_wait_set_fini(&wait_set_) != RCL_RET_OK) {
|
||||
@@ -133,117 +114,6 @@ Executor::~Executor()
|
||||
context_->release_interrupt_guard_condition(&wait_set_, std::nothrow);
|
||||
}
|
||||
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr>
|
||||
Executor::get_all_callback_groups()
|
||||
{
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr> groups;
|
||||
for (const auto & group_node_ptr : weak_groups_associated_with_executor_to_nodes_) {
|
||||
groups.push_back(group_node_ptr.first);
|
||||
}
|
||||
for (auto const & group_node_ptr : weak_groups_to_nodes_associated_with_executor_) {
|
||||
groups.push_back(group_node_ptr.first);
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr>
|
||||
Executor::get_manually_added_callback_groups()
|
||||
{
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr> groups;
|
||||
for (auto const & group_node_ptr : weak_groups_associated_with_executor_to_nodes_) {
|
||||
groups.push_back(group_node_ptr.first);
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr>
|
||||
Executor::get_automatically_added_callback_groups_from_nodes()
|
||||
{
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr> groups;
|
||||
for (auto const & group_node_ptr : weak_groups_to_nodes_associated_with_executor_) {
|
||||
groups.push_back(group_node_ptr.first);
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
void
|
||||
Executor::add_callback_groups_from_nodes_associated_to_executor()
|
||||
{
|
||||
for (auto & weak_node : weak_nodes_) {
|
||||
auto node = weak_node.lock();
|
||||
if (node) {
|
||||
auto group_ptrs = node->get_callback_groups();
|
||||
std::for_each(
|
||||
group_ptrs.begin(), group_ptrs.end(),
|
||||
[this, node](rclcpp::CallbackGroup::WeakPtr group_ptr)
|
||||
{
|
||||
auto shared_group_ptr = group_ptr.lock();
|
||||
if (shared_group_ptr && shared_group_ptr->automatically_add_to_executor_with_node() &&
|
||||
!shared_group_ptr->get_associated_with_executor_atomic().load())
|
||||
{
|
||||
this->add_callback_group_to_map(
|
||||
shared_group_ptr,
|
||||
node,
|
||||
weak_groups_to_nodes_associated_with_executor_,
|
||||
true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Executor::add_callback_group_to_map(
|
||||
rclcpp::CallbackGroup::SharedPtr group_ptr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
|
||||
rclcpp::memory_strategy::MemoryStrategy::WeakCallbackGroupsToNodesMap & weak_groups_to_nodes,
|
||||
bool notify)
|
||||
{
|
||||
// If the callback_group already has an executor
|
||||
std::atomic_bool & has_executor = group_ptr->get_associated_with_executor_atomic();
|
||||
if (has_executor.exchange(true)) {
|
||||
throw std::runtime_error("Callback group has already been added to an executor.");
|
||||
}
|
||||
bool is_new_node = !has_node(node_ptr, weak_groups_to_nodes_associated_with_executor_) &&
|
||||
!has_node(node_ptr, weak_groups_associated_with_executor_to_nodes_);
|
||||
rclcpp::CallbackGroup::WeakPtr weak_group_ptr = group_ptr;
|
||||
auto insert_info =
|
||||
weak_groups_to_nodes.insert(std::make_pair(weak_group_ptr, node_ptr));
|
||||
bool was_inserted = insert_info.second;
|
||||
if (!was_inserted) {
|
||||
throw std::runtime_error("Callback group was already added to executor.");
|
||||
}
|
||||
// Also add to the map that contains all callback groups
|
||||
weak_groups_to_nodes_.insert(std::make_pair(weak_group_ptr, node_ptr));
|
||||
if (is_new_node) {
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr node_weak_ptr(node_ptr);
|
||||
weak_nodes_to_guard_conditions_[node_weak_ptr] = node_ptr->get_notify_guard_condition();
|
||||
if (notify) {
|
||||
// Interrupt waiting to handle new node
|
||||
rcl_ret_t ret = rcl_trigger_guard_condition(&interrupt_guard_condition_);
|
||||
if (ret != RCL_RET_OK) {
|
||||
throw_from_rcl_error(ret, "Failed to trigger guard condition on callback group add");
|
||||
}
|
||||
}
|
||||
// Add the node's notify condition to the guard condition handles
|
||||
std::unique_lock<std::mutex> lock(memory_strategy_mutex_);
|
||||
memory_strategy_->add_guard_condition(node_ptr->get_notify_guard_condition());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Executor::add_callback_group(
|
||||
rclcpp::CallbackGroup::SharedPtr group_ptr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
|
||||
bool notify)
|
||||
{
|
||||
this->add_callback_group_to_map(
|
||||
group_ptr,
|
||||
node_ptr,
|
||||
weak_groups_associated_with_executor_to_nodes_,
|
||||
notify);
|
||||
}
|
||||
|
||||
void
|
||||
Executor::add_node(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify)
|
||||
{
|
||||
@@ -252,68 +122,25 @@ Executor::add_node(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_pt
|
||||
if (has_executor.exchange(true)) {
|
||||
throw std::runtime_error("Node has already been added to an executor.");
|
||||
}
|
||||
for (auto & weak_group : node_ptr->get_callback_groups()) {
|
||||
auto group_ptr = weak_group.lock();
|
||||
if (group_ptr != nullptr && !group_ptr->get_associated_with_executor_atomic().load() &&
|
||||
group_ptr->automatically_add_to_executor_with_node())
|
||||
{
|
||||
this->add_callback_group_to_map(
|
||||
group_ptr,
|
||||
node_ptr,
|
||||
weak_groups_to_nodes_associated_with_executor_,
|
||||
notify);
|
||||
// Check to ensure node not already added
|
||||
for (auto & weak_node : weak_nodes_) {
|
||||
auto node = weak_node.lock();
|
||||
if (node == node_ptr) {
|
||||
// TODO(jacquelinekay): Use a different error here?
|
||||
throw std::runtime_error("Cannot add node to executor, node already added.");
|
||||
}
|
||||
}
|
||||
weak_nodes_.push_back(node_ptr);
|
||||
}
|
||||
|
||||
void
|
||||
Executor::remove_callback_group_from_map(
|
||||
rclcpp::CallbackGroup::SharedPtr group_ptr,
|
||||
rclcpp::memory_strategy::MemoryStrategy::WeakCallbackGroupsToNodesMap & weak_groups_to_nodes,
|
||||
bool notify)
|
||||
{
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr;
|
||||
rclcpp::CallbackGroup::WeakPtr weak_group_ptr = group_ptr;
|
||||
auto iter = weak_groups_to_nodes.find(weak_group_ptr);
|
||||
if (iter != weak_groups_to_nodes.end()) {
|
||||
node_ptr = iter->second.lock();
|
||||
if (node_ptr == nullptr) {
|
||||
throw std::runtime_error("Node must not be deleted before its callback group(s).");
|
||||
guard_conditions_.push_back(node_ptr->get_notify_guard_condition());
|
||||
if (notify) {
|
||||
// Interrupt waiting to handle new node
|
||||
if (rcl_trigger_guard_condition(&interrupt_guard_condition_) != RCL_RET_OK) {
|
||||
throw std::runtime_error(rcl_get_error_string().str);
|
||||
}
|
||||
weak_groups_to_nodes.erase(iter);
|
||||
weak_groups_to_nodes_.erase(group_ptr);
|
||||
std::atomic_bool & has_executor = group_ptr->get_associated_with_executor_atomic();
|
||||
has_executor.store(false);
|
||||
} else {
|
||||
throw std::runtime_error("Callback group needs to be associated with executor.");
|
||||
}
|
||||
// If the node was matched and removed, interrupt waiting.
|
||||
if (!has_node(node_ptr, weak_groups_to_nodes_associated_with_executor_) &&
|
||||
!has_node(node_ptr, weak_groups_associated_with_executor_to_nodes_))
|
||||
{
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr node_weak_ptr(node_ptr);
|
||||
weak_nodes_to_guard_conditions_.erase(node_weak_ptr);
|
||||
if (notify) {
|
||||
rcl_ret_t ret = rcl_trigger_guard_condition(&interrupt_guard_condition_);
|
||||
if (ret != RCL_RET_OK) {
|
||||
throw_from_rcl_error(ret, "Failed to trigger guard condition on callback group remove");
|
||||
}
|
||||
}
|
||||
std::unique_lock<std::mutex> lock(memory_strategy_mutex_);
|
||||
memory_strategy_->remove_guard_condition(node_ptr->get_notify_guard_condition());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Executor::remove_callback_group(
|
||||
rclcpp::CallbackGroup::SharedPtr group_ptr,
|
||||
bool notify)
|
||||
{
|
||||
this->remove_callback_group_from_map(
|
||||
group_ptr,
|
||||
weak_groups_associated_with_executor_to_nodes_,
|
||||
notify);
|
||||
// Add the node's notify condition to the guard condition handles
|
||||
std::unique_lock<std::mutex> lock(memory_strategy_mutex_);
|
||||
memory_strategy_->add_guard_condition(node_ptr->get_notify_guard_condition());
|
||||
}
|
||||
|
||||
void
|
||||
@@ -325,44 +152,34 @@ Executor::add_node(std::shared_ptr<rclcpp::Node> node_ptr, bool notify)
|
||||
void
|
||||
Executor::remove_node(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify)
|
||||
{
|
||||
if (!node_ptr->get_associated_with_executor_atomic().load()) {
|
||||
throw std::runtime_error("Node needs to be associated with an executor.");
|
||||
}
|
||||
|
||||
bool found_node = false;
|
||||
auto node_it = weak_nodes_.begin();
|
||||
while (node_it != weak_nodes_.end()) {
|
||||
bool matched = (node_it->lock() == node_ptr);
|
||||
if (matched) {
|
||||
found_node = true;
|
||||
node_it = weak_nodes_.erase(node_it);
|
||||
} else {
|
||||
++node_it;
|
||||
}
|
||||
}
|
||||
if (!found_node) {
|
||||
throw std::runtime_error("Node needs to be associated with this executor.");
|
||||
}
|
||||
|
||||
for (auto it = weak_groups_to_nodes_associated_with_executor_.begin();
|
||||
it != weak_groups_to_nodes_associated_with_executor_.end(); )
|
||||
bool node_removed = false;
|
||||
{
|
||||
auto weak_node_ptr = it->second;
|
||||
auto shared_node_ptr = weak_node_ptr.lock();
|
||||
auto group_ptr = it->first.lock();
|
||||
|
||||
// Increment iterator before removing in case it's invalidated
|
||||
it++;
|
||||
if (shared_node_ptr == node_ptr) {
|
||||
remove_callback_group_from_map(
|
||||
group_ptr,
|
||||
weak_groups_to_nodes_associated_with_executor_,
|
||||
notify);
|
||||
auto node_it = weak_nodes_.begin();
|
||||
auto gc_it = guard_conditions_.begin();
|
||||
while (node_it != weak_nodes_.end()) {
|
||||
bool matched = (node_it->lock() == node_ptr);
|
||||
if (matched) {
|
||||
node_it = weak_nodes_.erase(node_it);
|
||||
gc_it = guard_conditions_.erase(gc_it);
|
||||
node_removed = true;
|
||||
} else {
|
||||
++node_it;
|
||||
++gc_it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::atomic_bool & has_executor = node_ptr->get_associated_with_executor_atomic();
|
||||
has_executor.store(false);
|
||||
if (notify) {
|
||||
// If the node was matched and removed, interrupt waiting
|
||||
if (node_removed) {
|
||||
if (rcl_trigger_guard_condition(&interrupt_guard_condition_) != RCL_RET_OK) {
|
||||
throw std::runtime_error(rcl_get_error_string().str);
|
||||
}
|
||||
}
|
||||
}
|
||||
std::unique_lock<std::mutex> lock(memory_strategy_mutex_);
|
||||
memory_strategy_->remove_guard_condition(node_ptr->get_notify_guard_condition());
|
||||
}
|
||||
|
||||
void
|
||||
@@ -396,22 +213,15 @@ Executor::spin_node_some(std::shared_ptr<rclcpp::Node> node)
|
||||
this->spin_node_some(node->get_node_base_interface());
|
||||
}
|
||||
|
||||
void Executor::spin_some(std::chrono::nanoseconds max_duration)
|
||||
{
|
||||
return this->spin_some_impl(max_duration, false);
|
||||
}
|
||||
|
||||
void Executor::spin_all(std::chrono::nanoseconds max_duration)
|
||||
{
|
||||
if (max_duration <= 0ns) {
|
||||
throw std::invalid_argument("max_duration must be positive");
|
||||
}
|
||||
return this->spin_some_impl(max_duration, true);
|
||||
}
|
||||
|
||||
void
|
||||
Executor::spin_some_impl(std::chrono::nanoseconds max_duration, bool exhaustive)
|
||||
Executor::spin_some(std::chrono::nanoseconds max_duration)
|
||||
{
|
||||
if (nullptr != dynamic_cast<executors::StaticSingleThreadedExecutor *>(this)) {
|
||||
throw rclcpp::exceptions::UnimplementedError(
|
||||
"spin_some is not implemented for StaticSingleThreadedExecutor, use spin or "
|
||||
"spin_until_future_complete");
|
||||
}
|
||||
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
auto max_duration_not_elapsed = [max_duration, start]() {
|
||||
if (std::chrono::nanoseconds(0) == max_duration) {
|
||||
@@ -429,20 +239,14 @@ Executor::spin_some_impl(std::chrono::nanoseconds max_duration, bool exhaustive)
|
||||
throw std::runtime_error("spin_some() called while already spinning");
|
||||
}
|
||||
RCLCPP_SCOPE_EXIT(this->spinning.store(false); );
|
||||
bool work_available = false;
|
||||
// non-blocking call to pre-load all available work
|
||||
wait_for_work(std::chrono::milliseconds::zero());
|
||||
while (rclcpp::ok(context_) && spinning.load() && max_duration_not_elapsed()) {
|
||||
AnyExecutable any_exec;
|
||||
if (!work_available) {
|
||||
wait_for_work(std::chrono::milliseconds::zero());
|
||||
}
|
||||
if (get_next_ready_executable(any_exec)) {
|
||||
execute_any_executable(any_exec);
|
||||
work_available = true;
|
||||
} else {
|
||||
if (!work_available || !exhaustive) {
|
||||
break;
|
||||
}
|
||||
work_available = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -459,6 +263,11 @@ Executor::spin_once_impl(std::chrono::nanoseconds timeout)
|
||||
void
|
||||
Executor::spin_once(std::chrono::nanoseconds timeout)
|
||||
{
|
||||
if (nullptr != dynamic_cast<executors::StaticSingleThreadedExecutor *>(this)) {
|
||||
throw rclcpp::exceptions::UnimplementedError(
|
||||
"spin_once is not implemented for StaticSingleThreadedExecutor, use spin or "
|
||||
"spin_until_future_complete");
|
||||
}
|
||||
if (spinning.exchange(true)) {
|
||||
throw std::runtime_error("spin_once() called while already spinning");
|
||||
}
|
||||
@@ -657,46 +466,25 @@ Executor::wait_for_work(std::chrono::nanoseconds timeout)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(memory_strategy_mutex_);
|
||||
|
||||
// Check weak_nodes_ to find any callback group that is not owned
|
||||
// by an executor and add it to the list of callbackgroups for
|
||||
// collect entities. Also exchange to false so it is not
|
||||
// allowed to add to another executor
|
||||
add_callback_groups_from_nodes_associated_to_executor();
|
||||
|
||||
// Collect the subscriptions and timers to be waited on
|
||||
memory_strategy_->clear_handles();
|
||||
bool has_invalid_weak_groups_or_nodes =
|
||||
memory_strategy_->collect_entities(weak_groups_to_nodes_);
|
||||
bool has_invalid_weak_nodes = memory_strategy_->collect_entities(weak_nodes_);
|
||||
|
||||
if (has_invalid_weak_groups_or_nodes) {
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr> invalid_group_ptrs;
|
||||
for (auto pair : weak_groups_to_nodes_) {
|
||||
auto weak_group_ptr = pair.first;
|
||||
auto weak_node_ptr = pair.second;
|
||||
if (weak_group_ptr.expired() || weak_node_ptr.expired()) {
|
||||
invalid_group_ptrs.push_back(weak_group_ptr);
|
||||
auto node_guard_pair = weak_nodes_to_guard_conditions_.find(weak_node_ptr);
|
||||
weak_nodes_to_guard_conditions_.erase(weak_node_ptr);
|
||||
memory_strategy_->remove_guard_condition(node_guard_pair->second);
|
||||
// Clean up any invalid nodes, if they were detected
|
||||
if (has_invalid_weak_nodes) {
|
||||
auto node_it = weak_nodes_.begin();
|
||||
auto gc_it = guard_conditions_.begin();
|
||||
while (node_it != weak_nodes_.end()) {
|
||||
if (node_it->expired()) {
|
||||
node_it = weak_nodes_.erase(node_it);
|
||||
memory_strategy_->remove_guard_condition(*gc_it);
|
||||
gc_it = guard_conditions_.erase(gc_it);
|
||||
} else {
|
||||
++node_it;
|
||||
++gc_it;
|
||||
}
|
||||
}
|
||||
std::for_each(
|
||||
invalid_group_ptrs.begin(), invalid_group_ptrs.end(),
|
||||
[this](rclcpp::CallbackGroup::WeakPtr group_ptr) {
|
||||
if (weak_groups_to_nodes_associated_with_executor_.find(group_ptr) !=
|
||||
weak_groups_to_nodes_associated_with_executor_.end())
|
||||
{
|
||||
weak_groups_to_nodes_associated_with_executor_.erase(group_ptr);
|
||||
}
|
||||
if (weak_groups_associated_with_executor_to_nodes_.find(group_ptr) !=
|
||||
weak_groups_associated_with_executor_to_nodes_.end())
|
||||
{
|
||||
weak_groups_associated_with_executor_to_nodes_.erase(group_ptr);
|
||||
}
|
||||
weak_groups_to_nodes_.erase(group_ptr);
|
||||
});
|
||||
}
|
||||
|
||||
// clear wait set
|
||||
rcl_ret_t ret = rcl_wait_set_clear(&wait_set_);
|
||||
if (ret != RCL_RET_OK) {
|
||||
@@ -717,7 +505,6 @@ Executor::wait_for_work(std::chrono::nanoseconds timeout)
|
||||
throw std::runtime_error("Couldn't fill wait set");
|
||||
}
|
||||
}
|
||||
|
||||
rcl_ret_t status =
|
||||
rcl_wait(&wait_set_, std::chrono::duration_cast<std::chrono::nanoseconds>(timeout).count());
|
||||
if (status == RCL_RET_WAIT_SET_EMPTY) {
|
||||
@@ -735,18 +522,22 @@ Executor::wait_for_work(std::chrono::nanoseconds timeout)
|
||||
}
|
||||
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr
|
||||
Executor::get_node_by_group(
|
||||
rclcpp::memory_strategy::MemoryStrategy::WeakCallbackGroupsToNodesMap weak_groups_to_nodes,
|
||||
rclcpp::CallbackGroup::SharedPtr group)
|
||||
Executor::get_node_by_group(rclcpp::CallbackGroup::SharedPtr group)
|
||||
{
|
||||
if (!group) {
|
||||
return nullptr;
|
||||
}
|
||||
rclcpp::CallbackGroup::WeakPtr weak_group_ptr(group);
|
||||
const auto finder = weak_groups_to_nodes.find(weak_group_ptr);
|
||||
if (finder != weak_groups_to_nodes.end()) {
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr = finder->second.lock();
|
||||
return node_ptr;
|
||||
for (auto & weak_node : weak_nodes_) {
|
||||
auto node = weak_node.lock();
|
||||
if (!node) {
|
||||
continue;
|
||||
}
|
||||
for (auto & weak_group : node->get_callback_groups()) {
|
||||
auto callback_group = weak_group.lock();
|
||||
if (callback_group == group) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -754,103 +545,80 @@ Executor::get_node_by_group(
|
||||
rclcpp::CallbackGroup::SharedPtr
|
||||
Executor::get_group_by_timer(rclcpp::TimerBase::SharedPtr timer)
|
||||
{
|
||||
for (const auto & pair : weak_groups_associated_with_executor_to_nodes_) {
|
||||
auto group = pair.first.lock();
|
||||
if (!group) {
|
||||
for (auto & weak_node : weak_nodes_) {
|
||||
auto node = weak_node.lock();
|
||||
if (!node) {
|
||||
continue;
|
||||
}
|
||||
auto timer_ref = group->find_timer_ptrs_if(
|
||||
[timer](const rclcpp::TimerBase::SharedPtr & timer_ptr) -> bool {
|
||||
return timer_ptr == timer;
|
||||
});
|
||||
if (timer_ref) {
|
||||
return group;
|
||||
for (auto & weak_group : node->get_callback_groups()) {
|
||||
auto group = weak_group.lock();
|
||||
if (!group) {
|
||||
continue;
|
||||
}
|
||||
auto timer_ref = group->find_timer_ptrs_if(
|
||||
[timer](const rclcpp::TimerBase::SharedPtr & timer_ptr) -> bool {
|
||||
return timer_ptr == timer;
|
||||
});
|
||||
if (timer_ref) {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto & pair : weak_groups_to_nodes_associated_with_executor_) {
|
||||
auto group = pair.first.lock();
|
||||
if (!group) {
|
||||
continue;
|
||||
}
|
||||
auto timer_ref = group->find_timer_ptrs_if(
|
||||
[timer](const rclcpp::TimerBase::SharedPtr & timer_ptr) -> bool {
|
||||
return timer_ptr == timer;
|
||||
});
|
||||
if (timer_ref) {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
return rclcpp::CallbackGroup::SharedPtr();
|
||||
}
|
||||
|
||||
bool
|
||||
Executor::get_next_ready_executable(AnyExecutable & any_executable)
|
||||
{
|
||||
bool success = get_next_ready_executable_from_map(any_executable, weak_groups_to_nodes_);
|
||||
return success;
|
||||
}
|
||||
|
||||
bool
|
||||
Executor::get_next_ready_executable_from_map(
|
||||
AnyExecutable & any_executable,
|
||||
rclcpp::memory_strategy::MemoryStrategy::WeakCallbackGroupsToNodesMap weak_groups_to_nodes)
|
||||
{
|
||||
bool success = false;
|
||||
// Check the timers to see if there are any that are ready
|
||||
memory_strategy_->get_next_timer(any_executable, weak_groups_to_nodes);
|
||||
memory_strategy_->get_next_timer(any_executable, weak_nodes_);
|
||||
if (any_executable.timer) {
|
||||
success = true;
|
||||
}
|
||||
if (!success) {
|
||||
// Check the subscriptions to see if there are any that are ready
|
||||
memory_strategy_->get_next_subscription(any_executable, weak_groups_to_nodes);
|
||||
memory_strategy_->get_next_subscription(any_executable, weak_nodes_);
|
||||
if (any_executable.subscription) {
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
if (!success) {
|
||||
// Check the services to see if there are any that are ready
|
||||
memory_strategy_->get_next_service(any_executable, weak_groups_to_nodes);
|
||||
memory_strategy_->get_next_service(any_executable, weak_nodes_);
|
||||
if (any_executable.service) {
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
if (!success) {
|
||||
// Check the clients to see if there are any that are ready
|
||||
memory_strategy_->get_next_client(any_executable, weak_groups_to_nodes);
|
||||
memory_strategy_->get_next_client(any_executable, weak_nodes_);
|
||||
if (any_executable.client) {
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
if (!success) {
|
||||
// Check the waitables to see if there are any that are ready
|
||||
memory_strategy_->get_next_waitable(any_executable, weak_groups_to_nodes);
|
||||
memory_strategy_->get_next_waitable(any_executable, weak_nodes_);
|
||||
if (any_executable.waitable) {
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
// At this point any_executable should be valid with either a valid subscription
|
||||
// At this point any_exec should be valid with either a valid subscription
|
||||
// or a valid timer, or it should be a null shared_ptr
|
||||
if (success) {
|
||||
rclcpp::CallbackGroup::WeakPtr weak_group_ptr = any_executable.callback_group;
|
||||
auto iter = weak_groups_to_nodes.find(weak_group_ptr);
|
||||
if (iter == weak_groups_to_nodes.end()) {
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (success) {
|
||||
// If it is valid, check to see if the group is mutually exclusive or
|
||||
// not, then mark it accordingly ..Check if the callback_group belongs to this executor
|
||||
if (any_executable.callback_group && any_executable.callback_group->type() == \
|
||||
CallbackGroupType::MutuallyExclusive)
|
||||
// not, then mark it accordingly
|
||||
using callback_group::CallbackGroupType;
|
||||
if (
|
||||
any_executable.callback_group &&
|
||||
any_executable.callback_group->type() == CallbackGroupType::MutuallyExclusive)
|
||||
{
|
||||
// It should not have been taken otherwise
|
||||
assert(any_executable.callback_group->can_be_taken_from().load());
|
||||
// Set to false to indicate something is being run from this group
|
||||
// This is reset to true either when the any_executable is executed or when the
|
||||
// any_executable is destructued
|
||||
// This is reset to true either when the any_exec is executed or when the
|
||||
// any_exec is destructued
|
||||
any_executable.callback_group->can_be_taken_from().store(false);
|
||||
}
|
||||
}
|
||||
@@ -877,18 +645,3 @@ Executor::get_next_executable(AnyExecutable & any_executable, std::chrono::nanos
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
// Returns true iff the weak_groups_to_nodes map has node_ptr as the value in any of its entry.
|
||||
bool
|
||||
Executor::has_node(
|
||||
const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
|
||||
rclcpp::memory_strategy::MemoryStrategy::WeakCallbackGroupsToNodesMap weak_groups_to_nodes) const
|
||||
{
|
||||
return std::find_if(
|
||||
weak_groups_to_nodes.begin(),
|
||||
weak_groups_to_nodes.end(),
|
||||
[&](const WeakCallbackGroupsToNodesMap::value_type & other) -> bool {
|
||||
auto other_ptr = other.second.lock();
|
||||
return other_ptr == node_ptr;
|
||||
}) != weak_groups_to_nodes.end();
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "rclcpp/memory_strategy.hpp"
|
||||
#include "rclcpp/executors/static_single_threaded_executor.hpp"
|
||||
@@ -28,40 +26,23 @@ using rclcpp::executors::StaticExecutorEntitiesCollector;
|
||||
|
||||
StaticExecutorEntitiesCollector::~StaticExecutorEntitiesCollector()
|
||||
{
|
||||
// Disassociate all callback groups and thus nodes.
|
||||
for (const auto & pair : weak_groups_associated_with_executor_to_nodes_) {
|
||||
auto group = pair.first.lock();
|
||||
if (group) {
|
||||
std::atomic_bool & has_executor = group->get_associated_with_executor_atomic();
|
||||
has_executor.store(false);
|
||||
}
|
||||
}
|
||||
for (const auto & pair : weak_groups_to_nodes_associated_with_executor_) {
|
||||
auto group = pair.first.lock();
|
||||
if (group) {
|
||||
std::atomic_bool & has_executor = group->get_associated_with_executor_atomic();
|
||||
has_executor.store(false);
|
||||
}
|
||||
}
|
||||
// Disassociate all nodes
|
||||
for (const auto & weak_node : weak_nodes_) {
|
||||
for (auto & weak_node : weak_nodes_) {
|
||||
auto node = weak_node.lock();
|
||||
if (node) {
|
||||
std::atomic_bool & has_executor = node->get_associated_with_executor_atomic();
|
||||
has_executor.store(false);
|
||||
}
|
||||
}
|
||||
weak_groups_associated_with_executor_to_nodes_.clear();
|
||||
weak_groups_to_nodes_associated_with_executor_.clear();
|
||||
exec_list_.clear();
|
||||
weak_nodes_.clear();
|
||||
weak_nodes_to_guard_conditions_.clear();
|
||||
guard_conditions_.clear();
|
||||
}
|
||||
|
||||
void
|
||||
StaticExecutorEntitiesCollector::init(
|
||||
rcl_wait_set_t * p_wait_set,
|
||||
rclcpp::memory_strategy::MemoryStrategy::SharedPtr memory_strategy,
|
||||
rclcpp::memory_strategy::MemoryStrategy::SharedPtr & memory_strategy,
|
||||
rcl_guard_condition_t * executor_guard_condition)
|
||||
{
|
||||
// Empty initialize executable list
|
||||
@@ -75,7 +56,8 @@ StaticExecutorEntitiesCollector::init(
|
||||
memory_strategy_ = memory_strategy;
|
||||
|
||||
// Add executor's guard condition
|
||||
memory_strategy_->add_guard_condition(executor_guard_condition);
|
||||
guard_conditions_.push_back(executor_guard_condition);
|
||||
|
||||
// Get memory strategy and executable list. Prepare wait_set_
|
||||
execute();
|
||||
}
|
||||
@@ -102,41 +84,18 @@ void
|
||||
StaticExecutorEntitiesCollector::fill_memory_strategy()
|
||||
{
|
||||
memory_strategy_->clear_handles();
|
||||
bool has_invalid_weak_groups_or_nodes =
|
||||
memory_strategy_->collect_entities(weak_groups_to_nodes_associated_with_executor_);
|
||||
bool has_invalid_weak_nodes = memory_strategy_->collect_entities(weak_nodes_);
|
||||
|
||||
// Clean up any invalid nodes, if they were detected
|
||||
if (has_invalid_weak_groups_or_nodes) {
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr> invalid_group_ptrs;
|
||||
for (const auto & pair : weak_groups_to_nodes_associated_with_executor_) {
|
||||
auto & weak_group_ptr = pair.first;
|
||||
auto & weak_node_ptr = pair.second;
|
||||
if (weak_group_ptr.expired() || weak_node_ptr.expired()) {
|
||||
invalid_group_ptrs.push_back(weak_group_ptr);
|
||||
if (has_invalid_weak_nodes) {
|
||||
auto node_it = weak_nodes_.begin();
|
||||
while (node_it != weak_nodes_.end()) {
|
||||
if (node_it->expired()) {
|
||||
node_it = weak_nodes_.erase(node_it);
|
||||
} else {
|
||||
++node_it;
|
||||
}
|
||||
}
|
||||
std::for_each(
|
||||
invalid_group_ptrs.begin(), invalid_group_ptrs.end(),
|
||||
[this](rclcpp::CallbackGroup::WeakPtr group_ptr) {
|
||||
weak_groups_to_nodes_associated_with_executor_.erase(group_ptr);
|
||||
});
|
||||
}
|
||||
has_invalid_weak_groups_or_nodes =
|
||||
memory_strategy_->collect_entities(weak_groups_associated_with_executor_to_nodes_);
|
||||
// Clean up any invalid nodes, if they were detected
|
||||
if (has_invalid_weak_groups_or_nodes) {
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr> invalid_group_ptrs;
|
||||
for (const auto & pair : weak_groups_associated_with_executor_to_nodes_) {
|
||||
auto & weak_group_ptr = pair.first;
|
||||
const auto & weak_node_ptr = pair.second;
|
||||
if (weak_group_ptr.expired() || weak_node_ptr.expired()) {
|
||||
invalid_group_ptrs.push_back(weak_group_ptr);
|
||||
}
|
||||
}
|
||||
std::for_each(
|
||||
invalid_group_ptrs.begin(), invalid_group_ptrs.end(),
|
||||
[this](rclcpp::CallbackGroup::WeakPtr group_ptr) {
|
||||
weak_groups_associated_with_executor_to_nodes_.erase(group_ptr);
|
||||
});
|
||||
}
|
||||
|
||||
// Add the static executor waitable to the memory strategy
|
||||
@@ -147,59 +106,59 @@ void
|
||||
StaticExecutorEntitiesCollector::fill_executable_list()
|
||||
{
|
||||
exec_list_.clear();
|
||||
add_callback_groups_from_nodes_associated_to_executor();
|
||||
fill_executable_list_from_map(weak_groups_associated_with_executor_to_nodes_);
|
||||
fill_executable_list_from_map(weak_groups_to_nodes_associated_with_executor_);
|
||||
// Add the executor's waitable to the executable list
|
||||
exec_list_.add_waitable(shared_from_this());
|
||||
}
|
||||
void
|
||||
StaticExecutorEntitiesCollector::fill_executable_list_from_map(
|
||||
const rclcpp::memory_strategy::MemoryStrategy::WeakCallbackGroupsToNodesMap &
|
||||
weak_groups_to_nodes)
|
||||
{
|
||||
for (const auto & pair : weak_groups_to_nodes) {
|
||||
auto group = pair.first.lock();
|
||||
auto node = pair.second.lock();
|
||||
if (!node || !group || !group->can_be_taken_from().load()) {
|
||||
|
||||
for (auto & weak_node : weak_nodes_) {
|
||||
auto node = weak_node.lock();
|
||||
if (!node) {
|
||||
continue;
|
||||
}
|
||||
group->find_timer_ptrs_if(
|
||||
[this](const rclcpp::TimerBase::SharedPtr & timer) {
|
||||
if (timer) {
|
||||
exec_list_.add_timer(timer);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
group->find_subscription_ptrs_if(
|
||||
[this](const rclcpp::SubscriptionBase::SharedPtr & subscription) {
|
||||
if (subscription) {
|
||||
exec_list_.add_subscription(subscription);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
group->find_service_ptrs_if(
|
||||
[this](const rclcpp::ServiceBase::SharedPtr & service) {
|
||||
if (service) {
|
||||
exec_list_.add_service(service);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
group->find_client_ptrs_if(
|
||||
[this](const rclcpp::ClientBase::SharedPtr & client) {
|
||||
if (client) {
|
||||
exec_list_.add_client(client);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
group->find_waitable_ptrs_if(
|
||||
[this](const rclcpp::Waitable::SharedPtr & waitable) {
|
||||
if (waitable) {
|
||||
exec_list_.add_waitable(waitable);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
// Check in all the callback groups
|
||||
for (auto & weak_group : node->get_callback_groups()) {
|
||||
auto group = weak_group.lock();
|
||||
if (!group || !group->can_be_taken_from().load()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
group->find_timer_ptrs_if(
|
||||
[this](const rclcpp::TimerBase::SharedPtr & timer) {
|
||||
if (timer) {
|
||||
exec_list_.add_timer(timer);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
group->find_subscription_ptrs_if(
|
||||
[this](const rclcpp::SubscriptionBase::SharedPtr & subscription) {
|
||||
if (subscription) {
|
||||
exec_list_.add_subscription(subscription);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
group->find_service_ptrs_if(
|
||||
[this](const rclcpp::ServiceBase::SharedPtr & service) {
|
||||
if (service) {
|
||||
exec_list_.add_service(service);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
group->find_client_ptrs_if(
|
||||
[this](const rclcpp::ClientBase::SharedPtr & client) {
|
||||
if (client) {
|
||||
exec_list_.add_client(client);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
group->find_waitable_ptrs_if(
|
||||
[this](const rclcpp::Waitable::SharedPtr & waitable) {
|
||||
if (waitable) {
|
||||
exec_list_.add_waitable(waitable);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Add the executor's waitable to the executable list
|
||||
exec_list_.add_waitable(shared_from_this());
|
||||
}
|
||||
|
||||
void
|
||||
@@ -219,14 +178,14 @@ StaticExecutorEntitiesCollector::prepare_wait_set()
|
||||
|
||||
if (RCL_RET_OK != ret) {
|
||||
throw std::runtime_error(
|
||||
std::string("Couldn't resize the wait set: ") + rcl_get_error_string().str);
|
||||
std::string("Couldn't resize the wait set : ") + rcl_get_error_string().str);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
StaticExecutorEntitiesCollector::refresh_wait_set(std::chrono::nanoseconds timeout)
|
||||
{
|
||||
// clear wait set (memset to '0' all wait_set_ entities
|
||||
// clear wait set (memeset to '0' all wait_set_ entities
|
||||
// but keeps the wait_set_ number of entities)
|
||||
if (rcl_wait_set_clear(p_wait_set_) != RCL_RET_OK) {
|
||||
throw std::runtime_error("Couldn't clear wait set");
|
||||
@@ -253,8 +212,7 @@ bool
|
||||
StaticExecutorEntitiesCollector::add_to_wait_set(rcl_wait_set_t * wait_set)
|
||||
{
|
||||
// Add waitable guard conditions (one for each registered node) into the wait set.
|
||||
for (const auto & pair : weak_nodes_to_guard_conditions_) {
|
||||
auto & gc = pair.second;
|
||||
for (const auto & gc : guard_conditions_) {
|
||||
rcl_ret_t ret = rcl_wait_set_add_guard_condition(wait_set, gc, NULL);
|
||||
if (ret != RCL_RET_OK) {
|
||||
throw std::runtime_error("Executor waitable: couldn't add guard condition to wait set");
|
||||
@@ -265,152 +223,55 @@ StaticExecutorEntitiesCollector::add_to_wait_set(rcl_wait_set_t * wait_set)
|
||||
|
||||
size_t StaticExecutorEntitiesCollector::get_number_of_ready_guard_conditions()
|
||||
{
|
||||
return weak_nodes_to_guard_conditions_.size();
|
||||
return guard_conditions_.size();
|
||||
}
|
||||
|
||||
bool
|
||||
void
|
||||
StaticExecutorEntitiesCollector::add_node(
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr)
|
||||
{
|
||||
bool is_new_node = false;
|
||||
// If the node already has an executor
|
||||
std::atomic_bool & has_executor = node_ptr->get_associated_with_executor_atomic();
|
||||
if (has_executor.exchange(true)) {
|
||||
throw std::runtime_error("Node has already been added to an executor.");
|
||||
}
|
||||
for (const auto & weak_group : node_ptr->get_callback_groups()) {
|
||||
auto group_ptr = weak_group.lock();
|
||||
if (group_ptr != nullptr && !group_ptr->get_associated_with_executor_atomic().load() &&
|
||||
group_ptr->automatically_add_to_executor_with_node())
|
||||
{
|
||||
is_new_node = (add_callback_group(
|
||||
group_ptr,
|
||||
node_ptr,
|
||||
weak_groups_to_nodes_associated_with_executor_) ||
|
||||
is_new_node);
|
||||
// Check to ensure node not already added
|
||||
for (auto & weak_node : weak_nodes_) {
|
||||
auto node = weak_node.lock();
|
||||
if (node == node_ptr) {
|
||||
// TODO(jacquelinekay): Use a different error here?
|
||||
throw std::runtime_error("Cannot add node to executor, node already added.");
|
||||
}
|
||||
}
|
||||
|
||||
weak_nodes_.push_back(node_ptr);
|
||||
return is_new_node;
|
||||
}
|
||||
|
||||
bool
|
||||
StaticExecutorEntitiesCollector::add_callback_group(
|
||||
rclcpp::CallbackGroup::SharedPtr group_ptr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
|
||||
rclcpp::memory_strategy::MemoryStrategy::WeakCallbackGroupsToNodesMap & weak_groups_to_nodes)
|
||||
{
|
||||
// If the callback_group already has an executor
|
||||
std::atomic_bool & has_executor = group_ptr->get_associated_with_executor_atomic();
|
||||
if (has_executor.exchange(true)) {
|
||||
throw std::runtime_error("Callback group has already been added to an executor.");
|
||||
}
|
||||
bool is_new_node = !has_node(node_ptr, weak_groups_associated_with_executor_to_nodes_) &&
|
||||
!has_node(node_ptr, weak_groups_to_nodes_associated_with_executor_);
|
||||
rclcpp::CallbackGroup::WeakPtr weak_group_ptr = group_ptr;
|
||||
auto insert_info = weak_groups_to_nodes.insert(
|
||||
std::make_pair(weak_group_ptr, node_ptr));
|
||||
bool was_inserted = insert_info.second;
|
||||
if (!was_inserted) {
|
||||
throw std::runtime_error("Callback group was already added to executor.");
|
||||
}
|
||||
if (is_new_node) {
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr node_weak_ptr(node_ptr);
|
||||
weak_nodes_to_guard_conditions_[node_weak_ptr] = node_ptr->get_notify_guard_condition();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
StaticExecutorEntitiesCollector::add_callback_group(
|
||||
rclcpp::CallbackGroup::SharedPtr group_ptr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr)
|
||||
{
|
||||
return add_callback_group(group_ptr, node_ptr, weak_groups_associated_with_executor_to_nodes_);
|
||||
}
|
||||
|
||||
bool
|
||||
StaticExecutorEntitiesCollector::remove_callback_group(
|
||||
rclcpp::CallbackGroup::SharedPtr group_ptr)
|
||||
{
|
||||
return this->remove_callback_group_from_map(
|
||||
group_ptr,
|
||||
weak_groups_associated_with_executor_to_nodes_);
|
||||
}
|
||||
|
||||
bool
|
||||
StaticExecutorEntitiesCollector::remove_callback_group_from_map(
|
||||
rclcpp::CallbackGroup::SharedPtr group_ptr,
|
||||
rclcpp::memory_strategy::MemoryStrategy::WeakCallbackGroupsToNodesMap & weak_groups_to_nodes)
|
||||
{
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr;
|
||||
rclcpp::CallbackGroup::WeakPtr weak_group_ptr = group_ptr;
|
||||
auto iter = weak_groups_to_nodes.find(weak_group_ptr);
|
||||
if (iter != weak_groups_to_nodes.end()) {
|
||||
node_ptr = iter->second.lock();
|
||||
if (node_ptr == nullptr) {
|
||||
throw std::runtime_error("Node must not be deleted before its callback group(s).");
|
||||
}
|
||||
weak_groups_to_nodes.erase(iter);
|
||||
} else {
|
||||
throw std::runtime_error("Callback group needs to be associated with executor.");
|
||||
}
|
||||
// If the node was matched and removed, interrupt waiting.
|
||||
if (!has_node(node_ptr, weak_groups_associated_with_executor_to_nodes_) &&
|
||||
!has_node(node_ptr, weak_groups_to_nodes_associated_with_executor_))
|
||||
{
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr node_weak_ptr(node_ptr);
|
||||
weak_nodes_to_guard_conditions_.erase(node_weak_ptr);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
guard_conditions_.push_back(node_ptr->get_notify_guard_condition());
|
||||
}
|
||||
|
||||
bool
|
||||
StaticExecutorEntitiesCollector::remove_node(
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr)
|
||||
{
|
||||
if (!node_ptr->get_associated_with_executor_atomic().load()) {
|
||||
return false;
|
||||
}
|
||||
bool node_found = false;
|
||||
auto node_it = weak_nodes_.begin();
|
||||
|
||||
while (node_it != weak_nodes_.end()) {
|
||||
bool matched = (node_it->lock() == node_ptr);
|
||||
if (matched) {
|
||||
weak_nodes_.erase(node_it);
|
||||
node_found = true;
|
||||
break;
|
||||
}
|
||||
++node_it;
|
||||
}
|
||||
if (!node_found) {
|
||||
return false;
|
||||
}
|
||||
std::vector<rclcpp::CallbackGroup::SharedPtr> found_group_ptrs;
|
||||
std::for_each(
|
||||
weak_groups_to_nodes_associated_with_executor_.begin(),
|
||||
weak_groups_to_nodes_associated_with_executor_.end(),
|
||||
[&found_group_ptrs, node_ptr](std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr> key_value_pair) {
|
||||
auto & weak_node_ptr = key_value_pair.second;
|
||||
auto shared_node_ptr = weak_node_ptr.lock();
|
||||
auto group_ptr = key_value_pair.first.lock();
|
||||
if (shared_node_ptr == node_ptr) {
|
||||
found_group_ptrs.push_back(group_ptr);
|
||||
// Find and remove node and its guard condition
|
||||
auto gc_it = std::find(
|
||||
guard_conditions_.begin(),
|
||||
guard_conditions_.end(),
|
||||
node_ptr->get_notify_guard_condition());
|
||||
|
||||
if (gc_it != guard_conditions_.end()) {
|
||||
guard_conditions_.erase(gc_it);
|
||||
weak_nodes_.erase(node_it);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
std::for_each(
|
||||
found_group_ptrs.begin(), found_group_ptrs.end(), [this]
|
||||
(rclcpp::CallbackGroup::SharedPtr group_ptr) {
|
||||
this->remove_callback_group_from_map(
|
||||
group_ptr,
|
||||
weak_groups_to_nodes_associated_with_executor_);
|
||||
});
|
||||
std::atomic_bool & has_executor = node_ptr->get_associated_with_executor_atomic();
|
||||
has_executor.store(false);
|
||||
return true;
|
||||
|
||||
throw std::runtime_error("Didn't find guard condition associated with node.");
|
||||
|
||||
} else {
|
||||
++node_it;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -419,13 +280,13 @@ StaticExecutorEntitiesCollector::is_ready(rcl_wait_set_t * p_wait_set)
|
||||
// Check wait_set guard_conditions for added/removed entities to/from a node
|
||||
for (size_t i = 0; i < p_wait_set->size_of_guard_conditions; ++i) {
|
||||
if (p_wait_set->guard_conditions[i] != NULL) {
|
||||
auto found_guard_condition = std::find_if(
|
||||
weak_nodes_to_guard_conditions_.begin(), weak_nodes_to_guard_conditions_.end(),
|
||||
[&](std::pair<rclcpp::node_interfaces::NodeBaseInterface::WeakPtr,
|
||||
const rcl_guard_condition_t *> pair) -> bool {
|
||||
return pair.second == p_wait_set->guard_conditions[i];
|
||||
});
|
||||
if (found_guard_condition != weak_nodes_to_guard_conditions_.end()) {
|
||||
// Check if the guard condition triggered belongs to a node
|
||||
auto it = std::find(
|
||||
guard_conditions_.begin(), guard_conditions_.end(),
|
||||
p_wait_set->guard_conditions[i]);
|
||||
|
||||
// If it does, we are ready to re-collect entities
|
||||
if (it != guard_conditions_.end()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -433,77 +294,3 @@ StaticExecutorEntitiesCollector::is_ready(rcl_wait_set_t * p_wait_set)
|
||||
// None of the guard conditions triggered belong to a registered node
|
||||
return false;
|
||||
}
|
||||
|
||||
// Returns true iff the weak_groups_to_nodes map has node_ptr as the value in any of its entry.
|
||||
bool
|
||||
StaticExecutorEntitiesCollector::has_node(
|
||||
const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
|
||||
const rclcpp::memory_strategy::MemoryStrategy::WeakCallbackGroupsToNodesMap &
|
||||
weak_groups_to_nodes) const
|
||||
{
|
||||
return std::find_if(
|
||||
weak_groups_to_nodes.begin(),
|
||||
weak_groups_to_nodes.end(),
|
||||
[&](const WeakCallbackGroupsToNodesMap::value_type & other) -> bool {
|
||||
auto other_ptr = other.second.lock();
|
||||
return other_ptr == node_ptr;
|
||||
}) != weak_groups_to_nodes.end();
|
||||
}
|
||||
|
||||
void
|
||||
StaticExecutorEntitiesCollector::add_callback_groups_from_nodes_associated_to_executor()
|
||||
{
|
||||
for (const auto & weak_node : weak_nodes_) {
|
||||
auto node = weak_node.lock();
|
||||
if (node) {
|
||||
auto group_ptrs = node->get_callback_groups();
|
||||
std::for_each(
|
||||
group_ptrs.begin(), group_ptrs.end(),
|
||||
[this, node](rclcpp::CallbackGroup::WeakPtr group_ptr)
|
||||
{
|
||||
auto shared_group_ptr = group_ptr.lock();
|
||||
if (shared_group_ptr && shared_group_ptr->automatically_add_to_executor_with_node() &&
|
||||
!shared_group_ptr->get_associated_with_executor_atomic().load())
|
||||
{
|
||||
add_callback_group(
|
||||
shared_group_ptr,
|
||||
node,
|
||||
weak_groups_to_nodes_associated_with_executor_);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr>
|
||||
StaticExecutorEntitiesCollector::get_all_callback_groups()
|
||||
{
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr> groups;
|
||||
for (const auto & group_node_ptr : weak_groups_associated_with_executor_to_nodes_) {
|
||||
groups.push_back(group_node_ptr.first);
|
||||
}
|
||||
for (const auto & group_node_ptr : weak_groups_to_nodes_associated_with_executor_) {
|
||||
groups.push_back(group_node_ptr.first);
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr>
|
||||
StaticExecutorEntitiesCollector::get_manually_added_callback_groups()
|
||||
{
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr> groups;
|
||||
for (const auto & group_node_ptr : weak_groups_associated_with_executor_to_nodes_) {
|
||||
groups.push_back(group_node_ptr.first);
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr>
|
||||
StaticExecutorEntitiesCollector::get_automatically_added_callback_groups_from_nodes()
|
||||
{
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr> groups;
|
||||
for (const auto & group_node_ptr : weak_groups_to_nodes_associated_with_executor_) {
|
||||
groups.push_back(group_node_ptr.first);
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "rclcpp/executors/static_single_threaded_executor.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "rclcpp/scope_exit.hpp"
|
||||
|
||||
@@ -51,32 +50,24 @@ StaticSingleThreadedExecutor::spin()
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
StaticSingleThreadedExecutor::add_callback_group(
|
||||
rclcpp::CallbackGroup::SharedPtr group_ptr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
|
||||
bool notify)
|
||||
{
|
||||
bool is_new_node = entities_collector_->add_callback_group(group_ptr, node_ptr);
|
||||
if (is_new_node && notify) {
|
||||
// Interrupt waiting to handle new node
|
||||
if (rcl_trigger_guard_condition(&interrupt_guard_condition_) != RCL_RET_OK) {
|
||||
throw std::runtime_error(rcl_get_error_string().str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
StaticSingleThreadedExecutor::add_node(
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify)
|
||||
{
|
||||
bool is_new_node = entities_collector_->add_node(node_ptr);
|
||||
if (is_new_node && notify) {
|
||||
// If the node already has an executor
|
||||
std::atomic_bool & has_executor = node_ptr->get_associated_with_executor_atomic();
|
||||
if (has_executor.exchange(true)) {
|
||||
throw std::runtime_error("Node has already been added to an executor.");
|
||||
}
|
||||
|
||||
if (notify) {
|
||||
// Interrupt waiting to handle new node
|
||||
if (rcl_trigger_guard_condition(&interrupt_guard_condition_) != RCL_RET_OK) {
|
||||
throw std::runtime_error(rcl_get_error_string().str);
|
||||
}
|
||||
}
|
||||
|
||||
entities_collector_->add_node(node_ptr);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -85,51 +76,23 @@ StaticSingleThreadedExecutor::add_node(std::shared_ptr<rclcpp::Node> node_ptr, b
|
||||
this->add_node(node_ptr->get_node_base_interface(), notify);
|
||||
}
|
||||
|
||||
void
|
||||
StaticSingleThreadedExecutor::remove_callback_group(
|
||||
rclcpp::CallbackGroup::SharedPtr group_ptr, bool notify)
|
||||
{
|
||||
bool node_removed = entities_collector_->remove_callback_group(group_ptr);
|
||||
// If the node was matched and removed, interrupt waiting
|
||||
if (node_removed && notify) {
|
||||
if (rcl_trigger_guard_condition(&interrupt_guard_condition_) != RCL_RET_OK) {
|
||||
throw std::runtime_error(rcl_get_error_string().str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
StaticSingleThreadedExecutor::remove_node(
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify)
|
||||
{
|
||||
bool node_removed = entities_collector_->remove_node(node_ptr);
|
||||
if (!node_removed) {
|
||||
throw std::runtime_error("Node needs to be associated with this executor.");
|
||||
}
|
||||
// If the node was matched and removed, interrupt waiting
|
||||
|
||||
if (notify) {
|
||||
if (rcl_trigger_guard_condition(&interrupt_guard_condition_) != RCL_RET_OK) {
|
||||
throw std::runtime_error(rcl_get_error_string().str);
|
||||
// If the node was matched and removed, interrupt waiting
|
||||
if (node_removed) {
|
||||
if (rcl_trigger_guard_condition(&interrupt_guard_condition_) != RCL_RET_OK) {
|
||||
throw std::runtime_error(rcl_get_error_string().str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr>
|
||||
StaticSingleThreadedExecutor::get_all_callback_groups()
|
||||
{
|
||||
return entities_collector_->get_all_callback_groups();
|
||||
}
|
||||
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr>
|
||||
StaticSingleThreadedExecutor::get_manually_added_callback_groups()
|
||||
{
|
||||
return entities_collector_->get_manually_added_callback_groups();
|
||||
}
|
||||
|
||||
std::vector<rclcpp::CallbackGroup::WeakPtr>
|
||||
StaticSingleThreadedExecutor::get_automatically_added_callback_groups_from_nodes()
|
||||
{
|
||||
return entities_collector_->get_automatically_added_callback_groups_from_nodes();
|
||||
std::atomic_bool & has_executor = node_ptr->get_associated_with_executor_atomic();
|
||||
has_executor.store(false);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -62,27 +62,6 @@ GraphListener::~GraphListener()
|
||||
this->shutdown(std::nothrow);
|
||||
}
|
||||
|
||||
void GraphListener::init_wait_set()
|
||||
{
|
||||
auto parent_context = parent_context_.lock();
|
||||
if (!parent_context) {
|
||||
throw std::runtime_error("parent context was destroyed");
|
||||
}
|
||||
rcl_ret_t ret = rcl_wait_set_init(
|
||||
&wait_set_,
|
||||
0, // number_of_subscriptions
|
||||
2, // number_of_guard_conditions
|
||||
0, // number_of_timers
|
||||
0, // number_of_clients
|
||||
0, // number_of_services
|
||||
0, // number_of_events
|
||||
parent_context->get_rcl_context().get(),
|
||||
rcl_get_default_allocator());
|
||||
if (RCL_RET_OK != ret) {
|
||||
throw_from_rcl_error(ret, "failed to initialize wait set");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GraphListener::start_if_not_started()
|
||||
{
|
||||
@@ -92,8 +71,24 @@ GraphListener::start_if_not_started()
|
||||
}
|
||||
if (!is_started_) {
|
||||
// Initialize the wait set before starting.
|
||||
init_wait_set();
|
||||
// Register an on_shutdown hook to shutdown the graph listener.
|
||||
auto parent_context = parent_context_.lock();
|
||||
if (!parent_context) {
|
||||
throw std::runtime_error("parent context was destroyed");
|
||||
}
|
||||
rcl_ret_t ret = rcl_wait_set_init(
|
||||
&wait_set_,
|
||||
0, // number_of_subscriptions
|
||||
2, // number_of_guard_conditions
|
||||
0, // number_of_timers
|
||||
0, // number_of_clients
|
||||
0, // number_of_services
|
||||
0, // number_of_events
|
||||
parent_context->get_rcl_context().get(),
|
||||
rcl_get_default_allocator());
|
||||
if (RCL_RET_OK != ret) {
|
||||
throw_from_rcl_error(ret, "failed to initialize wait set");
|
||||
}
|
||||
// Register an on_shutdown hook to shtudown the graph listener.
|
||||
// This is important to ensure that the wait set is finalized before
|
||||
// destruction of static objects occurs.
|
||||
std::weak_ptr<GraphListener> weak_this = shared_from_this();
|
||||
@@ -355,15 +350,6 @@ GraphListener::remove_node(rclcpp::node_interfaces::NodeGraphInterface * node_gr
|
||||
remove_node_(&node_graph_interfaces_, node_graph);
|
||||
}
|
||||
|
||||
void
|
||||
GraphListener::cleanup_wait_set()
|
||||
{
|
||||
rcl_ret_t ret = rcl_wait_set_fini(&wait_set_);
|
||||
if (RCL_RET_OK != ret) {
|
||||
throw_from_rcl_error(ret, "failed to finalize wait set");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GraphListener::__shutdown(bool should_throw)
|
||||
{
|
||||
@@ -385,22 +371,14 @@ GraphListener::__shutdown(bool should_throw)
|
||||
} else {
|
||||
parent_context_ptr->release_interrupt_guard_condition(&wait_set_, std::nothrow);
|
||||
}
|
||||
} else {
|
||||
ret = rcl_guard_condition_fini(shutdown_guard_condition_);
|
||||
if (RCL_RET_OK != ret) {
|
||||
if (should_throw) {
|
||||
throw_from_rcl_error(ret, "failed to finalize shutdown guard condition");
|
||||
} else {
|
||||
RCLCPP_ERROR(
|
||||
rclcpp::get_logger("rclcpp"),
|
||||
"failed to finalize shutdown guard condition");
|
||||
}
|
||||
}
|
||||
}
|
||||
shutdown_guard_condition_ = nullptr;
|
||||
}
|
||||
if (is_started_) {
|
||||
cleanup_wait_set();
|
||||
ret = rcl_wait_set_fini(&wait_set_);
|
||||
if (RCL_RET_OK != ret) {
|
||||
throw_from_rcl_error(ret, "failed to finalize wait set");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,8 +64,7 @@ InitOptions &
|
||||
InitOptions::operator=(const InitOptions & other)
|
||||
{
|
||||
if (this != &other) {
|
||||
std::lock_guard<std::mutex> init_options_lock(init_options_mutex_);
|
||||
this->finalize_init_options_impl();
|
||||
this->finalize_init_options();
|
||||
rcl_ret_t ret = rcl_init_options_copy(other.get_rcl_init_options(), init_options_.get());
|
||||
if (RCL_RET_OK != ret) {
|
||||
rclcpp::exceptions::throw_from_rcl_error(ret, "failed to copy rcl init options");
|
||||
@@ -83,13 +82,6 @@ InitOptions::~InitOptions()
|
||||
|
||||
void
|
||||
InitOptions::finalize_init_options()
|
||||
{
|
||||
std::lock_guard<std::mutex> init_options_lock(init_options_mutex_);
|
||||
this->finalize_init_options_impl();
|
||||
}
|
||||
|
||||
void
|
||||
InitOptions::finalize_init_options_impl()
|
||||
{
|
||||
if (init_options_) {
|
||||
rcl_ret_t ret = rcl_init_options_fini(init_options_.get());
|
||||
@@ -109,38 +101,4 @@ InitOptions::get_rcl_init_options() const
|
||||
return init_options_.get();
|
||||
}
|
||||
|
||||
void
|
||||
InitOptions::use_default_domain_id()
|
||||
{
|
||||
size_t domain_id = RCL_DEFAULT_DOMAIN_ID;
|
||||
rcl_ret_t ret = rcl_get_default_domain_id(&domain_id);
|
||||
if (RCL_RET_OK != ret) {
|
||||
rclcpp::exceptions::throw_from_rcl_error(ret, "failed to get default domain id");
|
||||
}
|
||||
set_domain_id(domain_id);
|
||||
}
|
||||
|
||||
void
|
||||
InitOptions::set_domain_id(size_t domain_id)
|
||||
{
|
||||
std::lock_guard<std::mutex> init_options_lock(init_options_mutex_);
|
||||
rcl_ret_t ret = rcl_init_options_set_domain_id(init_options_.get(), domain_id);
|
||||
if (RCL_RET_OK != ret) {
|
||||
rclcpp::exceptions::throw_from_rcl_error(ret, "failed to set domain id to rcl init options");
|
||||
}
|
||||
}
|
||||
|
||||
size_t
|
||||
InitOptions::get_domain_id() const
|
||||
{
|
||||
std::lock_guard<std::mutex> init_options_lock(init_options_mutex_);
|
||||
size_t domain_id;
|
||||
rcl_ret_t ret = rcl_init_options_get_domain_id(init_options_.get(), &domain_id);
|
||||
if (RCL_RET_OK != ret) {
|
||||
rclcpp::exceptions::throw_from_rcl_error(ret, "failed to get domain id from rcl init options");
|
||||
}
|
||||
|
||||
return domain_id;
|
||||
}
|
||||
|
||||
} // namespace rclcpp
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "rclcpp/exceptions.hpp"
|
||||
#include "rclcpp/logger.hpp"
|
||||
|
||||
#include "rclcpp/logging.hpp"
|
||||
|
||||
namespace rclcpp
|
||||
@@ -44,22 +44,4 @@ get_node_logger(const rcl_node_t * node)
|
||||
return rclcpp::get_logger(logger_name);
|
||||
}
|
||||
|
||||
void
|
||||
Logger::set_level(Level level)
|
||||
{
|
||||
rcutils_ret_t rcutils_ret = rcutils_logging_set_logger_level(
|
||||
get_name(),
|
||||
static_cast<RCUTILS_LOG_SEVERITY>(level));
|
||||
if (rcutils_ret != RCUTILS_RET_OK) {
|
||||
if (rcutils_ret == RCUTILS_RET_INVALID_ARGUMENT) {
|
||||
exceptions::throw_from_rcl_error(
|
||||
RCL_RET_INVALID_ARGUMENT, "Invalid parameter",
|
||||
rcutils_get_error_state(), rcutils_reset_error);
|
||||
}
|
||||
exceptions::throw_from_rcl_error(
|
||||
RCL_RET_ERROR, "Couldn't set logger level",
|
||||
rcutils_get_error_state(), rcutils_reset_error);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace rclcpp
|
||||
|
||||
@@ -20,19 +20,25 @@ using rclcpp::memory_strategy::MemoryStrategy;
|
||||
rclcpp::SubscriptionBase::SharedPtr
|
||||
MemoryStrategy::get_subscription_by_handle(
|
||||
std::shared_ptr<const rcl_subscription_t> subscriber_handle,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes)
|
||||
const WeakNodeList & weak_nodes)
|
||||
{
|
||||
for (const auto & pair : weak_groups_to_nodes) {
|
||||
auto group = pair.first.lock();
|
||||
if (!group) {
|
||||
for (auto & weak_node : weak_nodes) {
|
||||
auto node = weak_node.lock();
|
||||
if (!node) {
|
||||
continue;
|
||||
}
|
||||
auto match_subscription = group->find_subscription_ptrs_if(
|
||||
[&subscriber_handle](const rclcpp::SubscriptionBase::SharedPtr & subscription) -> bool {
|
||||
return subscription->get_subscription_handle() == subscriber_handle;
|
||||
});
|
||||
if (match_subscription) {
|
||||
return match_subscription;
|
||||
for (auto & weak_group : node->get_callback_groups()) {
|
||||
auto group = weak_group.lock();
|
||||
if (!group) {
|
||||
continue;
|
||||
}
|
||||
auto match_subscription = group->find_subscription_ptrs_if(
|
||||
[&subscriber_handle](const rclcpp::SubscriptionBase::SharedPtr & subscription) -> bool {
|
||||
return subscription->get_subscription_handle() == subscriber_handle;
|
||||
});
|
||||
if (match_subscription) {
|
||||
return match_subscription;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
@@ -41,19 +47,25 @@ MemoryStrategy::get_subscription_by_handle(
|
||||
rclcpp::ServiceBase::SharedPtr
|
||||
MemoryStrategy::get_service_by_handle(
|
||||
std::shared_ptr<const rcl_service_t> service_handle,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes)
|
||||
const WeakNodeList & weak_nodes)
|
||||
{
|
||||
for (const auto & pair : weak_groups_to_nodes) {
|
||||
auto group = pair.first.lock();
|
||||
if (!group) {
|
||||
for (auto & weak_node : weak_nodes) {
|
||||
auto node = weak_node.lock();
|
||||
if (!node) {
|
||||
continue;
|
||||
}
|
||||
auto service_ref = group->find_service_ptrs_if(
|
||||
[&service_handle](const rclcpp::ServiceBase::SharedPtr & service) -> bool {
|
||||
return service->get_service_handle() == service_handle;
|
||||
});
|
||||
if (service_ref) {
|
||||
return service_ref;
|
||||
for (auto & weak_group : node->get_callback_groups()) {
|
||||
auto group = weak_group.lock();
|
||||
if (!group) {
|
||||
continue;
|
||||
}
|
||||
auto service_ref = group->find_service_ptrs_if(
|
||||
[&service_handle](const rclcpp::ServiceBase::SharedPtr & service) -> bool {
|
||||
return service->get_service_handle() == service_handle;
|
||||
});
|
||||
if (service_ref) {
|
||||
return service_ref;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
@@ -62,19 +74,25 @@ MemoryStrategy::get_service_by_handle(
|
||||
rclcpp::ClientBase::SharedPtr
|
||||
MemoryStrategy::get_client_by_handle(
|
||||
std::shared_ptr<const rcl_client_t> client_handle,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes)
|
||||
const WeakNodeList & weak_nodes)
|
||||
{
|
||||
for (const auto & pair : weak_groups_to_nodes) {
|
||||
auto group = pair.first.lock();
|
||||
if (!group) {
|
||||
for (auto & weak_node : weak_nodes) {
|
||||
auto node = weak_node.lock();
|
||||
if (!node) {
|
||||
continue;
|
||||
}
|
||||
auto client_ref = group->find_client_ptrs_if(
|
||||
[&client_handle](const rclcpp::ClientBase::SharedPtr & client) -> bool {
|
||||
return client->get_client_handle() == client_handle;
|
||||
});
|
||||
if (client_ref) {
|
||||
return client_ref;
|
||||
for (auto & weak_group : node->get_callback_groups()) {
|
||||
auto group = weak_group.lock();
|
||||
if (!group) {
|
||||
continue;
|
||||
}
|
||||
auto client_ref = group->find_client_ptrs_if(
|
||||
[&client_handle](const rclcpp::ClientBase::SharedPtr & client) -> bool {
|
||||
return client->get_client_handle() == client_handle;
|
||||
});
|
||||
if (client_ref) {
|
||||
return client_ref;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
@@ -83,19 +101,25 @@ MemoryStrategy::get_client_by_handle(
|
||||
rclcpp::TimerBase::SharedPtr
|
||||
MemoryStrategy::get_timer_by_handle(
|
||||
std::shared_ptr<const rcl_timer_t> timer_handle,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes)
|
||||
const WeakNodeList & weak_nodes)
|
||||
{
|
||||
for (const auto & pair : weak_groups_to_nodes) {
|
||||
auto group = pair.first.lock();
|
||||
if (!group) {
|
||||
for (auto & weak_node : weak_nodes) {
|
||||
auto node = weak_node.lock();
|
||||
if (!node) {
|
||||
continue;
|
||||
}
|
||||
auto timer_ref = group->find_timer_ptrs_if(
|
||||
[&timer_handle](const rclcpp::TimerBase::SharedPtr & timer) -> bool {
|
||||
return timer->get_timer_handle() == timer_handle;
|
||||
});
|
||||
if (timer_ref) {
|
||||
return timer_ref;
|
||||
for (auto & weak_group : node->get_callback_groups()) {
|
||||
auto group = weak_group.lock();
|
||||
if (!group) {
|
||||
continue;
|
||||
}
|
||||
auto timer_ref = group->find_timer_ptrs_if(
|
||||
[&timer_handle](const rclcpp::TimerBase::SharedPtr & timer) -> bool {
|
||||
return timer->get_timer_handle() == timer_handle;
|
||||
});
|
||||
if (timer_ref) {
|
||||
return timer_ref;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
@@ -104,17 +128,22 @@ MemoryStrategy::get_timer_by_handle(
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr
|
||||
MemoryStrategy::get_node_by_group(
|
||||
rclcpp::CallbackGroup::SharedPtr group,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes)
|
||||
const WeakNodeList & weak_nodes)
|
||||
{
|
||||
if (!group) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
rclcpp::CallbackGroup::WeakPtr weak_group_ptr(group);
|
||||
const auto finder = weak_groups_to_nodes.find(weak_group_ptr);
|
||||
if (finder != weak_groups_to_nodes.end()) {
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr = finder->second.lock();
|
||||
return node_ptr;
|
||||
for (auto & weak_node : weak_nodes) {
|
||||
auto node = weak_node.lock();
|
||||
if (!node) {
|
||||
continue;
|
||||
}
|
||||
for (auto & weak_group : node->get_callback_groups()) {
|
||||
auto callback_group = weak_group.lock();
|
||||
if (callback_group == group) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -122,20 +151,25 @@ MemoryStrategy::get_node_by_group(
|
||||
rclcpp::CallbackGroup::SharedPtr
|
||||
MemoryStrategy::get_group_by_subscription(
|
||||
rclcpp::SubscriptionBase::SharedPtr subscription,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes)
|
||||
const WeakNodeList & weak_nodes)
|
||||
{
|
||||
for (const auto & pair : weak_groups_to_nodes) {
|
||||
auto group = pair.first.lock();
|
||||
auto node = pair.second.lock();
|
||||
if (!group || !node) {
|
||||
for (auto & weak_node : weak_nodes) {
|
||||
auto node = weak_node.lock();
|
||||
if (!node) {
|
||||
continue;
|
||||
}
|
||||
auto match_sub = group->find_subscription_ptrs_if(
|
||||
[&subscription](const rclcpp::SubscriptionBase::SharedPtr & sub) -> bool {
|
||||
return sub == subscription;
|
||||
});
|
||||
if (match_sub) {
|
||||
return group;
|
||||
for (auto & weak_group : node->get_callback_groups()) {
|
||||
auto group = weak_group.lock();
|
||||
if (!group) {
|
||||
continue;
|
||||
}
|
||||
auto match_sub = group->find_subscription_ptrs_if(
|
||||
[&subscription](const rclcpp::SubscriptionBase::SharedPtr & sub) -> bool {
|
||||
return sub == subscription;
|
||||
});
|
||||
if (match_sub) {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
@@ -144,20 +178,25 @@ MemoryStrategy::get_group_by_subscription(
|
||||
rclcpp::CallbackGroup::SharedPtr
|
||||
MemoryStrategy::get_group_by_service(
|
||||
rclcpp::ServiceBase::SharedPtr service,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes)
|
||||
const WeakNodeList & weak_nodes)
|
||||
{
|
||||
for (const auto & pair : weak_groups_to_nodes) {
|
||||
auto group = pair.first.lock();
|
||||
auto node = pair.second.lock();
|
||||
if (!group || !node) {
|
||||
for (auto & weak_node : weak_nodes) {
|
||||
auto node = weak_node.lock();
|
||||
if (!node) {
|
||||
continue;
|
||||
}
|
||||
auto service_ref = group->find_service_ptrs_if(
|
||||
[&service](const rclcpp::ServiceBase::SharedPtr & serv) -> bool {
|
||||
return serv == service;
|
||||
});
|
||||
if (service_ref) {
|
||||
return group;
|
||||
for (auto & weak_group : node->get_callback_groups()) {
|
||||
auto group = weak_group.lock();
|
||||
if (!group) {
|
||||
continue;
|
||||
}
|
||||
auto service_ref = group->find_service_ptrs_if(
|
||||
[&service](const rclcpp::ServiceBase::SharedPtr & serv) -> bool {
|
||||
return serv == service;
|
||||
});
|
||||
if (service_ref) {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
@@ -166,20 +205,25 @@ MemoryStrategy::get_group_by_service(
|
||||
rclcpp::CallbackGroup::SharedPtr
|
||||
MemoryStrategy::get_group_by_client(
|
||||
rclcpp::ClientBase::SharedPtr client,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes)
|
||||
const WeakNodeList & weak_nodes)
|
||||
{
|
||||
for (const auto & pair : weak_groups_to_nodes) {
|
||||
auto group = pair.first.lock();
|
||||
auto node = pair.second.lock();
|
||||
if (!group || !node) {
|
||||
for (auto & weak_node : weak_nodes) {
|
||||
auto node = weak_node.lock();
|
||||
if (!node) {
|
||||
continue;
|
||||
}
|
||||
auto client_ref = group->find_client_ptrs_if(
|
||||
[&client](const rclcpp::ClientBase::SharedPtr & cli) -> bool {
|
||||
return cli == client;
|
||||
});
|
||||
if (client_ref) {
|
||||
return group;
|
||||
for (auto & weak_group : node->get_callback_groups()) {
|
||||
auto group = weak_group.lock();
|
||||
if (!group) {
|
||||
continue;
|
||||
}
|
||||
auto client_ref = group->find_client_ptrs_if(
|
||||
[&client](const rclcpp::ClientBase::SharedPtr & cli) -> bool {
|
||||
return cli == client;
|
||||
});
|
||||
if (client_ref) {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
@@ -188,20 +232,25 @@ MemoryStrategy::get_group_by_client(
|
||||
rclcpp::CallbackGroup::SharedPtr
|
||||
MemoryStrategy::get_group_by_timer(
|
||||
rclcpp::TimerBase::SharedPtr timer,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes)
|
||||
const WeakNodeList & weak_nodes)
|
||||
{
|
||||
for (const auto & pair : weak_groups_to_nodes) {
|
||||
auto group = pair.first.lock();
|
||||
auto node = pair.second.lock();
|
||||
if (!group || !node) {
|
||||
for (auto & weak_node : weak_nodes) {
|
||||
auto node = weak_node.lock();
|
||||
if (!node) {
|
||||
continue;
|
||||
}
|
||||
auto timer_ref = group->find_timer_ptrs_if(
|
||||
[&timer](const rclcpp::TimerBase::SharedPtr & time) -> bool {
|
||||
return time == timer;
|
||||
});
|
||||
if (timer_ref) {
|
||||
return group;
|
||||
for (auto & weak_group : node->get_callback_groups()) {
|
||||
auto group = weak_group.lock();
|
||||
if (!group) {
|
||||
continue;
|
||||
}
|
||||
auto timer_ref = group->find_timer_ptrs_if(
|
||||
[&timer](const rclcpp::TimerBase::SharedPtr & time) -> bool {
|
||||
return time == timer;
|
||||
});
|
||||
if (timer_ref) {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
@@ -210,20 +259,25 @@ MemoryStrategy::get_group_by_timer(
|
||||
rclcpp::CallbackGroup::SharedPtr
|
||||
MemoryStrategy::get_group_by_waitable(
|
||||
rclcpp::Waitable::SharedPtr waitable,
|
||||
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes)
|
||||
const WeakNodeList & weak_nodes)
|
||||
{
|
||||
for (const auto & pair : weak_groups_to_nodes) {
|
||||
auto group = pair.first.lock();
|
||||
auto node = pair.second.lock();
|
||||
if (!group || !node) {
|
||||
for (auto & weak_node : weak_nodes) {
|
||||
auto node = weak_node.lock();
|
||||
if (!node) {
|
||||
continue;
|
||||
}
|
||||
auto waitable_ref = group->find_waitable_ptrs_if(
|
||||
[&waitable](const rclcpp::Waitable::SharedPtr & group_waitable) -> bool {
|
||||
return group_waitable == waitable;
|
||||
});
|
||||
if (waitable_ref) {
|
||||
return group;
|
||||
for (auto & weak_group : node->get_callback_groups()) {
|
||||
auto group = weak_group.lock();
|
||||
if (!group) {
|
||||
continue;
|
||||
}
|
||||
auto waitable_ref = group->find_waitable_ptrs_if(
|
||||
[&waitable](const rclcpp::Waitable::SharedPtr & group_waitable) -> bool {
|
||||
return group_waitable == waitable;
|
||||
});
|
||||
if (waitable_ref) {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
||||
@@ -138,8 +138,7 @@ Node::Node(
|
||||
node_services_,
|
||||
node_logging_,
|
||||
node_clock_,
|
||||
node_parameters_,
|
||||
options.clock_qos()
|
||||
node_parameters_
|
||||
)),
|
||||
node_waitables_(new rclcpp::node_interfaces::NodeWaitables(node_base_.get())),
|
||||
node_options_(options),
|
||||
@@ -212,11 +211,15 @@ Node::get_logger() const
|
||||
}
|
||||
|
||||
rclcpp::CallbackGroup::SharedPtr
|
||||
Node::create_callback_group(
|
||||
rclcpp::CallbackGroupType group_type,
|
||||
bool automatically_add_to_executor_with_node)
|
||||
Node::create_callback_group(rclcpp::CallbackGroupType group_type)
|
||||
{
|
||||
return node_base_->create_callback_group(group_type, automatically_add_to_executor_with_node);
|
||||
return node_base_->create_callback_group(group_type);
|
||||
}
|
||||
|
||||
bool
|
||||
Node::group_in_node(rclcpp::CallbackGroup::SharedPtr group)
|
||||
{
|
||||
return node_base_->callback_group_in_node(group);
|
||||
}
|
||||
|
||||
const rclcpp::ParameterValue &
|
||||
@@ -325,6 +328,28 @@ Node::remove_on_set_parameters_callback(const OnSetParametersCallbackHandle * co
|
||||
return node_parameters_->remove_on_set_parameters_callback(callback);
|
||||
}
|
||||
|
||||
// suppress deprecated function warning
|
||||
#if !defined(_WIN32)
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#else // !defined(_WIN32)
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable: 4996)
|
||||
#endif
|
||||
|
||||
rclcpp::Node::OnParametersSetCallbackType
|
||||
Node::set_on_parameters_set_callback(rclcpp::Node::OnParametersSetCallbackType callback)
|
||||
{
|
||||
return node_parameters_->set_on_parameters_set_callback(callback);
|
||||
}
|
||||
|
||||
// remove warning suppression
|
||||
#if !defined(_WIN32)
|
||||
# pragma GCC diagnostic pop
|
||||
#else // !defined(_WIN32)
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
std::vector<std::string>
|
||||
Node::get_node_names() const
|
||||
{
|
||||
|
||||
@@ -216,16 +216,11 @@ NodeBase::get_shared_rcl_node_handle() const
|
||||
}
|
||||
|
||||
rclcpp::CallbackGroup::SharedPtr
|
||||
NodeBase::create_callback_group(
|
||||
rclcpp::CallbackGroupType group_type,
|
||||
bool automatically_add_to_executor_with_node)
|
||||
NodeBase::create_callback_group(rclcpp::CallbackGroupType group_type)
|
||||
{
|
||||
using rclcpp::CallbackGroup;
|
||||
using rclcpp::CallbackGroupType;
|
||||
auto group = CallbackGroup::SharedPtr(
|
||||
new CallbackGroup(
|
||||
group_type,
|
||||
automatically_add_to_executor_with_node));
|
||||
auto group = CallbackGroup::SharedPtr(new CallbackGroup(group_type));
|
||||
callback_groups_.push_back(group);
|
||||
return group;
|
||||
}
|
||||
@@ -288,24 +283,3 @@ NodeBase::get_enable_topic_statistics_default() const
|
||||
{
|
||||
return enable_topic_statistics_default_;
|
||||
}
|
||||
|
||||
std::string
|
||||
NodeBase::resolve_topic_or_service_name(
|
||||
const std::string & name, bool is_service, bool only_expand) const
|
||||
{
|
||||
char * output_cstr = NULL;
|
||||
auto allocator = rcl_get_default_allocator();
|
||||
rcl_ret_t ret = rcl_node_resolve_name(
|
||||
node_handle_.get(),
|
||||
name.c_str(),
|
||||
allocator,
|
||||
is_service,
|
||||
only_expand,
|
||||
&output_cstr);
|
||||
if (RCL_RET_OK != ret) {
|
||||
throw_from_rcl_error(ret, "failed to resolve name", rcl_get_error_state());
|
||||
}
|
||||
std::string output{output_cstr};
|
||||
allocator.deallocate(output_cstr, allocator.state);
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -414,7 +414,7 @@ NodeGraph::wait_for_graph_change(
|
||||
}
|
||||
|
||||
size_t
|
||||
NodeGraph::count_graph_users() const
|
||||
NodeGraph::count_graph_users()
|
||||
{
|
||||
return graph_users_count_.load();
|
||||
}
|
||||
|
||||
@@ -874,6 +874,18 @@ NodeParameters::add_on_set_parameters_callback(OnParametersSetCallbackType callb
|
||||
return handle;
|
||||
}
|
||||
|
||||
NodeParameters::OnParametersSetCallbackType
|
||||
NodeParameters::set_on_parameters_set_callback(OnParametersSetCallbackType callback)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
|
||||
ParameterMutationRecursionGuard guard(parameter_modification_enabled_);
|
||||
|
||||
auto existing_callback = on_parameters_set_callback_;
|
||||
on_parameters_set_callback_ = callback;
|
||||
return existing_callback;
|
||||
}
|
||||
|
||||
const std::map<std::string, rclcpp::ParameterValue> &
|
||||
NodeParameters::get_parameter_overrides() const
|
||||
{
|
||||
|
||||
@@ -78,9 +78,3 @@ NodeServices::add_client(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
NodeServices::resolve_service_name(const std::string & name, bool only_expand) const
|
||||
{
|
||||
return node_base_->resolve_topic_or_service_name(name, true, only_expand);
|
||||
}
|
||||
|
||||
@@ -26,16 +26,14 @@ NodeTimeSource::NodeTimeSource(
|
||||
rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services,
|
||||
rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging,
|
||||
rclcpp::node_interfaces::NodeClockInterface::SharedPtr node_clock,
|
||||
rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_parameters,
|
||||
const rclcpp::QoS & qos)
|
||||
rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_parameters)
|
||||
: node_base_(node_base),
|
||||
node_topics_(node_topics),
|
||||
node_graph_(node_graph),
|
||||
node_services_(node_services),
|
||||
node_logging_(node_logging),
|
||||
node_clock_(node_clock),
|
||||
node_parameters_(node_parameters),
|
||||
time_source_(qos)
|
||||
node_parameters_(node_parameters)
|
||||
{
|
||||
time_source_.attachNode(
|
||||
node_base_,
|
||||
|
||||
@@ -129,9 +129,3 @@ NodeTopics::get_node_timers_interface() const
|
||||
{
|
||||
return node_timers_;
|
||||
}
|
||||
|
||||
std::string
|
||||
NodeTopics::resolve_topic_name(const std::string & name, bool only_expand) const
|
||||
{
|
||||
return node_base_->resolve_topic_or_service_name(name, false, only_expand);
|
||||
}
|
||||
|
||||
@@ -77,9 +77,7 @@ NodeOptions::operator=(const NodeOptions & other)
|
||||
this->enable_topic_statistics_ = other.enable_topic_statistics_;
|
||||
this->start_parameter_services_ = other.start_parameter_services_;
|
||||
this->start_parameter_event_publisher_ = other.start_parameter_event_publisher_;
|
||||
this->clock_qos_ = other.clock_qos_;
|
||||
this->parameter_event_qos_ = other.parameter_event_qos_;
|
||||
this->rosout_qos_ = other.rosout_qos_;
|
||||
this->parameter_event_publisher_options_ = other.parameter_event_publisher_options_;
|
||||
this->allow_undeclared_parameters_ = other.allow_undeclared_parameters_;
|
||||
this->automatically_declare_parameters_from_overrides_ =
|
||||
@@ -98,8 +96,8 @@ NodeOptions::get_rcl_node_options() const
|
||||
*node_options_ = rcl_node_get_default_options();
|
||||
node_options_->allocator = this->allocator_;
|
||||
node_options_->use_global_arguments = this->use_global_arguments_;
|
||||
node_options_->domain_id = this->get_domain_id_from_env();
|
||||
node_options_->enable_rosout = this->enable_rosout_;
|
||||
node_options_->rosout_qos = this->rosout_qos_.get_rmw_qos_profile();
|
||||
|
||||
int c_argc = 0;
|
||||
std::unique_ptr<const char *[]> c_argv;
|
||||
@@ -259,19 +257,6 @@ NodeOptions::start_parameter_event_publisher(bool start_parameter_event_publishe
|
||||
return *this;
|
||||
}
|
||||
|
||||
const rclcpp::QoS &
|
||||
NodeOptions::clock_qos() const
|
||||
{
|
||||
return this->clock_qos_;
|
||||
}
|
||||
|
||||
NodeOptions &
|
||||
NodeOptions::clock_qos(const rclcpp::QoS & clock_qos)
|
||||
{
|
||||
this->clock_qos_ = clock_qos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
const rclcpp::QoS &
|
||||
NodeOptions::parameter_event_qos() const
|
||||
{
|
||||
@@ -285,20 +270,6 @@ NodeOptions::parameter_event_qos(const rclcpp::QoS & parameter_event_qos)
|
||||
return *this;
|
||||
}
|
||||
|
||||
const rclcpp::QoS &
|
||||
NodeOptions::rosout_qos() const
|
||||
{
|
||||
return this->rosout_qos_;
|
||||
}
|
||||
|
||||
NodeOptions &
|
||||
NodeOptions::rosout_qos(const rclcpp::QoS & rosout_qos)
|
||||
{
|
||||
this->node_options_.reset();
|
||||
this->rosout_qos_ = rosout_qos;
|
||||
return *this;
|
||||
}
|
||||
|
||||
const rclcpp::PublisherOptionsBase &
|
||||
NodeOptions::parameter_event_publisher_options() const
|
||||
{
|
||||
@@ -355,4 +326,36 @@ NodeOptions::allocator(rcl_allocator_t allocator)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// TODO(wjwwood): reuse rcutils_get_env() to avoid code duplication.
|
||||
// See also: https://github.com/ros2/rcl/issues/119
|
||||
size_t
|
||||
NodeOptions::get_domain_id_from_env() const
|
||||
{
|
||||
// Determine the domain id based on the options and the ROS_DOMAIN_ID env variable.
|
||||
size_t domain_id = std::numeric_limits<size_t>::max();
|
||||
char * ros_domain_id = nullptr;
|
||||
const char * env_var = "ROS_DOMAIN_ID";
|
||||
#ifndef _WIN32
|
||||
ros_domain_id = getenv(env_var);
|
||||
#else
|
||||
size_t ros_domain_id_size;
|
||||
_dupenv_s(&ros_domain_id, &ros_domain_id_size, env_var);
|
||||
#endif
|
||||
if (ros_domain_id) {
|
||||
uint32_t number = static_cast<uint32_t>(strtoul(ros_domain_id, NULL, 0));
|
||||
if (number == (std::numeric_limits<uint32_t>::max)()) {
|
||||
#ifdef _WIN32
|
||||
// free the ros_domain_id before throwing, if getenv was used on Windows
|
||||
free(ros_domain_id);
|
||||
#endif
|
||||
throw std::runtime_error("failed to interpret ROS_DOMAIN_ID as integral number");
|
||||
}
|
||||
domain_id = static_cast<size_t>(number);
|
||||
#ifdef _WIN32
|
||||
free(ros_domain_id);
|
||||
#endif
|
||||
}
|
||||
return domain_id;
|
||||
}
|
||||
|
||||
} // namespace rclcpp
|
||||
|
||||
@@ -104,6 +104,36 @@ AsyncParametersClient::AsyncParametersClient(
|
||||
node_services_interface->add_client(describe_parameters_base, group);
|
||||
}
|
||||
|
||||
AsyncParametersClient::AsyncParametersClient(
|
||||
const rclcpp::Node::SharedPtr node,
|
||||
const std::string & remote_node_name,
|
||||
const rmw_qos_profile_t & qos_profile,
|
||||
rclcpp::CallbackGroup::SharedPtr group)
|
||||
: AsyncParametersClient(
|
||||
node->get_node_base_interface(),
|
||||
node->get_node_topics_interface(),
|
||||
node->get_node_graph_interface(),
|
||||
node->get_node_services_interface(),
|
||||
remote_node_name,
|
||||
qos_profile,
|
||||
group)
|
||||
{}
|
||||
|
||||
AsyncParametersClient::AsyncParametersClient(
|
||||
rclcpp::Node * node,
|
||||
const std::string & remote_node_name,
|
||||
const rmw_qos_profile_t & qos_profile,
|
||||
rclcpp::CallbackGroup::SharedPtr group)
|
||||
: AsyncParametersClient(
|
||||
node->get_node_base_interface(),
|
||||
node->get_node_topics_interface(),
|
||||
node->get_node_graph_interface(),
|
||||
node->get_node_services_interface(),
|
||||
remote_node_name,
|
||||
qos_profile,
|
||||
group)
|
||||
{}
|
||||
|
||||
std::shared_future<std::vector<rclcpp::Parameter>>
|
||||
AsyncParametersClient::get_parameters(
|
||||
const std::vector<std::string> & names,
|
||||
@@ -312,6 +342,78 @@ AsyncParametersClient::wait_for_service_nanoseconds(std::chrono::nanoseconds tim
|
||||
return true;
|
||||
}
|
||||
|
||||
SyncParametersClient::SyncParametersClient(
|
||||
rclcpp::Node::SharedPtr node,
|
||||
const std::string & remote_node_name,
|
||||
const rmw_qos_profile_t & qos_profile)
|
||||
: SyncParametersClient(
|
||||
std::make_shared<rclcpp::executors::SingleThreadedExecutor>(),
|
||||
node,
|
||||
remote_node_name,
|
||||
qos_profile)
|
||||
{}
|
||||
|
||||
SyncParametersClient::SyncParametersClient(
|
||||
rclcpp::Executor::SharedPtr executor,
|
||||
rclcpp::Node::SharedPtr node,
|
||||
const std::string & remote_node_name,
|
||||
const rmw_qos_profile_t & qos_profile)
|
||||
: SyncParametersClient(
|
||||
executor,
|
||||
node->get_node_base_interface(),
|
||||
node->get_node_topics_interface(),
|
||||
node->get_node_graph_interface(),
|
||||
node->get_node_services_interface(),
|
||||
remote_node_name,
|
||||
qos_profile)
|
||||
{}
|
||||
|
||||
SyncParametersClient::SyncParametersClient(
|
||||
rclcpp::Node * node,
|
||||
const std::string & remote_node_name,
|
||||
const rmw_qos_profile_t & qos_profile)
|
||||
: SyncParametersClient(
|
||||
std::make_shared<rclcpp::executors::SingleThreadedExecutor>(),
|
||||
node,
|
||||
remote_node_name,
|
||||
qos_profile)
|
||||
{}
|
||||
|
||||
SyncParametersClient::SyncParametersClient(
|
||||
rclcpp::Executor::SharedPtr executor,
|
||||
rclcpp::Node * node,
|
||||
const std::string & remote_node_name,
|
||||
const rmw_qos_profile_t & qos_profile)
|
||||
: SyncParametersClient(
|
||||
executor,
|
||||
node->get_node_base_interface(),
|
||||
node->get_node_topics_interface(),
|
||||
node->get_node_graph_interface(),
|
||||
node->get_node_services_interface(),
|
||||
remote_node_name,
|
||||
qos_profile)
|
||||
{}
|
||||
|
||||
SyncParametersClient::SyncParametersClient(
|
||||
rclcpp::Executor::SharedPtr executor,
|
||||
const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_interface,
|
||||
const rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics_interface,
|
||||
const rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph_interface,
|
||||
const rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services_interface,
|
||||
const std::string & remote_node_name,
|
||||
const rmw_qos_profile_t & qos_profile)
|
||||
: executor_(executor), node_base_interface_(node_base_interface)
|
||||
{
|
||||
async_parameters_client_ =
|
||||
std::make_shared<AsyncParametersClient>(
|
||||
node_base_interface,
|
||||
node_topics_interface,
|
||||
node_graph_interface,
|
||||
node_services_interface,
|
||||
remote_node_name,
|
||||
qos_profile);
|
||||
}
|
||||
|
||||
std::vector<rclcpp::Parameter>
|
||||
SyncParametersClient::get_parameters(const std::vector<std::string> & parameter_names)
|
||||
{
|
||||
|
||||
@@ -262,9 +262,7 @@ PublisherBase::default_incompatible_qos_callback(
|
||||
std::string policy_name = qos_policy_name_from_kind(event.last_policy_kind);
|
||||
RCLCPP_WARN(
|
||||
rclcpp::get_logger(rcl_node_get_logger_name(rcl_node_handle_.get())),
|
||||
"New subscription discovered on topic '%s', requesting incompatible QoS. "
|
||||
"New subscription discovered on this topic, requesting incompatible QoS. "
|
||||
"No messages will be sent to it. "
|
||||
"Last incompatible policy: %s",
|
||||
get_topic_name(),
|
||||
policy_name.c_str());
|
||||
"Last incompatible policy: %s", policy_name.c_str());
|
||||
}
|
||||
|
||||
@@ -235,12 +235,6 @@ bool operator!=(const QoS & left, const QoS & right)
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
ClockQoS::ClockQoS(const QoSInitialization & qos_initialization)
|
||||
// Using `rmw_qos_profile_sensor_data` intentionally.
|
||||
// It's best effort and `qos_initialization` is overriding the depth to 1.
|
||||
: QoS(qos_initialization, rmw_qos_profile_sensor_data)
|
||||
{}
|
||||
|
||||
SensorDataQoS::SensorDataQoS(const QoSInitialization & qos_initialization)
|
||||
: QoS(qos_initialization, rmw_qos_profile_sensor_data)
|
||||
{}
|
||||
@@ -257,10 +251,6 @@ ParameterEventsQoS::ParameterEventsQoS(const QoSInitialization & qos_initializat
|
||||
: QoS(qos_initialization, rmw_qos_profile_parameter_events)
|
||||
{}
|
||||
|
||||
RosoutQoS::RosoutQoS(const QoSInitialization & rosout_initialization)
|
||||
: QoS(rosout_initialization, rcl_qos_profile_rosout_default)
|
||||
{}
|
||||
|
||||
SystemDefaultsQoS::SystemDefaultsQoS(const QoSInitialization & qos_initialization)
|
||||
: QoS(qos_initialization, rmw_qos_profile_system_default)
|
||||
{}
|
||||
|
||||
@@ -245,11 +245,9 @@ SubscriptionBase::default_incompatible_qos_callback(
|
||||
std::string policy_name = qos_policy_name_from_kind(event.last_policy_kind);
|
||||
RCLCPP_WARN(
|
||||
rclcpp::get_logger(rcl_node_get_logger_name(node_handle_.get())),
|
||||
"New publisher discovered on topic '%s', offering incompatible QoS. "
|
||||
"New publisher discovered on this topic, offering incompatible QoS. "
|
||||
"No messages will be sent to it. "
|
||||
"Last incompatible policy: %s",
|
||||
get_topic_name(),
|
||||
policy_name.c_str());
|
||||
"Last incompatible policy: %s", policy_name.c_str());
|
||||
}
|
||||
|
||||
bool
|
||||
|
||||
@@ -199,7 +199,7 @@ Time::operator-(const rclcpp::Time & rhs) const
|
||||
throw std::underflow_error("time subtraction leads to int64_t underflow");
|
||||
}
|
||||
|
||||
return Duration::from_nanoseconds(rcl_time_.nanoseconds - rhs.rcl_time_.nanoseconds);
|
||||
return Duration(rcl_time_.nanoseconds - rhs.rcl_time_.nanoseconds);
|
||||
}
|
||||
|
||||
Time
|
||||
|
||||
@@ -33,16 +33,17 @@
|
||||
namespace rclcpp
|
||||
{
|
||||
|
||||
TimeSource::TimeSource(std::shared_ptr<rclcpp::Node> node, const rclcpp::QoS & qos)
|
||||
TimeSource::TimeSource(std::shared_ptr<rclcpp::Node> node)
|
||||
: logger_(rclcpp::get_logger("rclcpp")),
|
||||
qos_(qos)
|
||||
clock_subscription_(nullptr),
|
||||
ros_time_active_(false)
|
||||
{
|
||||
this->attachNode(node);
|
||||
}
|
||||
|
||||
TimeSource::TimeSource(const rclcpp::QoS & qos)
|
||||
TimeSource::TimeSource()
|
||||
: logger_(rclcpp::get_logger("rclcpp")),
|
||||
qos_(qos)
|
||||
ros_time_active_(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -184,21 +185,11 @@ void TimeSource::set_clock(
|
||||
const builtin_interfaces::msg::Time::SharedPtr msg, bool set_ros_time_enabled,
|
||||
std::shared_ptr<rclcpp::Clock> clock)
|
||||
{
|
||||
std::lock_guard<std::mutex> clock_guard(clock->get_clock_mutex());
|
||||
|
||||
// Do change
|
||||
if (!set_ros_time_enabled && clock->ros_time_is_active()) {
|
||||
auto ret = rcl_disable_ros_time_override(clock->get_clock_handle());
|
||||
if (ret != RCL_RET_OK) {
|
||||
rclcpp::exceptions::throw_from_rcl_error(
|
||||
ret, "Failed to disable ros_time_override_status");
|
||||
}
|
||||
disable_ros_time(clock);
|
||||
} else if (set_ros_time_enabled && !clock->ros_time_is_active()) {
|
||||
auto ret = rcl_enable_ros_time_override(clock->get_clock_handle());
|
||||
if (ret != RCL_RET_OK) {
|
||||
rclcpp::exceptions::throw_from_rcl_error(
|
||||
ret, "Failed to enable ros_time_override_status");
|
||||
}
|
||||
enable_ros_time(clock);
|
||||
}
|
||||
|
||||
auto ret = rcl_set_ros_time_override(clock->get_clock_handle(), rclcpp::Time(*msg).nanoseconds());
|
||||
@@ -236,7 +227,7 @@ void TimeSource::create_clock_sub()
|
||||
clock_subscription_ = rclcpp::create_subscription<rosgraph_msgs::msg::Clock>(
|
||||
node_topics_,
|
||||
"/clock",
|
||||
rclcpp::QoS(KeepLast(1)).best_effort(),
|
||||
rclcpp::QoS(QoSInitialization::from_rmw(rmw_qos_profile_default)),
|
||||
std::bind(&TimeSource::clock_cb, this, std::placeholders::_1)
|
||||
);
|
||||
}
|
||||
@@ -282,6 +273,24 @@ void TimeSource::on_parameter_event(const rcl_interfaces::msg::ParameterEvent::S
|
||||
}
|
||||
}
|
||||
|
||||
void TimeSource::enable_ros_time(std::shared_ptr<rclcpp::Clock> clock)
|
||||
{
|
||||
auto ret = rcl_enable_ros_time_override(clock->get_clock_handle());
|
||||
if (ret != RCL_RET_OK) {
|
||||
rclcpp::exceptions::throw_from_rcl_error(
|
||||
ret, "Failed to enable ros_time_override_status");
|
||||
}
|
||||
}
|
||||
|
||||
void TimeSource::disable_ros_time(std::shared_ptr<rclcpp::Clock> clock)
|
||||
{
|
||||
auto ret = rcl_disable_ros_time_override(clock->get_clock_handle());
|
||||
if (ret != RCL_RET_OK) {
|
||||
rclcpp::exceptions::throw_from_rcl_error(
|
||||
ret, "Failed to enable ros_time_override_status");
|
||||
}
|
||||
}
|
||||
|
||||
void TimeSource::enable_ros_time()
|
||||
{
|
||||
if (ros_time_active_) {
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
#include "./signal_handler.hpp"
|
||||
#include "rclcpp/contexts/default_context.hpp"
|
||||
#include "rclcpp/detail/utilities.hpp"
|
||||
#include "rclcpp/exceptions.hpp"
|
||||
|
||||
#include "rcl/error_handling.h"
|
||||
@@ -57,47 +56,6 @@ uninstall_signal_handlers()
|
||||
return SignalHandler::get_global_signal_handler().uninstall();
|
||||
}
|
||||
|
||||
static
|
||||
std::vector<std::string>
|
||||
_remove_ros_arguments(
|
||||
char const * const argv[],
|
||||
const rcl_arguments_t * args,
|
||||
rcl_allocator_t alloc)
|
||||
{
|
||||
rcl_ret_t ret;
|
||||
int nonros_argc = 0;
|
||||
const char ** nonros_argv = NULL;
|
||||
|
||||
ret = rcl_remove_ros_arguments(
|
||||
argv,
|
||||
args,
|
||||
alloc,
|
||||
&nonros_argc,
|
||||
&nonros_argv);
|
||||
|
||||
if (RCL_RET_OK != ret || nonros_argc < 0) {
|
||||
// Not using throw_from_rcl_error, because we may need to append deallocation failures.
|
||||
exceptions::RCLError exc(ret, rcl_get_error_state(), "");
|
||||
rcl_reset_error();
|
||||
if (NULL != nonros_argv) {
|
||||
alloc.deallocate(nonros_argv, alloc.state);
|
||||
}
|
||||
throw exc;
|
||||
}
|
||||
|
||||
std::vector<std::string> return_arguments(static_cast<size_t>(nonros_argc));
|
||||
|
||||
for (size_t ii = 0; ii < static_cast<size_t>(nonros_argc); ++ii) {
|
||||
return_arguments[ii] = std::string(nonros_argv[ii]);
|
||||
}
|
||||
|
||||
if (NULL != nonros_argv) {
|
||||
alloc.deallocate(nonros_argv, alloc.state);
|
||||
}
|
||||
|
||||
return return_arguments;
|
||||
}
|
||||
|
||||
std::vector<std::string>
|
||||
init_and_remove_ros_arguments(
|
||||
int argc,
|
||||
@@ -105,10 +63,7 @@ init_and_remove_ros_arguments(
|
||||
const InitOptions & init_options)
|
||||
{
|
||||
init(argc, argv, init_options);
|
||||
|
||||
using rclcpp::contexts::get_global_default_context;
|
||||
auto rcl_context = get_global_default_context()->get_rcl_context();
|
||||
return _remove_ros_arguments(argv, &(rcl_context->global_arguments), rcl_get_default_allocator());
|
||||
return remove_ros_arguments(argc, argv);
|
||||
}
|
||||
|
||||
std::vector<std::string>
|
||||
@@ -124,17 +79,40 @@ remove_ros_arguments(int argc, char const * const argv[])
|
||||
exceptions::throw_from_rcl_error(ret, "failed to parse arguments");
|
||||
}
|
||||
|
||||
std::vector<std::string> return_arguments;
|
||||
try {
|
||||
return_arguments = _remove_ros_arguments(argv, &parsed_args, alloc);
|
||||
} catch (exceptions::RCLError & exc) {
|
||||
int nonros_argc = 0;
|
||||
const char ** nonros_argv = NULL;
|
||||
|
||||
ret = rcl_remove_ros_arguments(
|
||||
argv,
|
||||
&parsed_args,
|
||||
alloc,
|
||||
&nonros_argc,
|
||||
&nonros_argv);
|
||||
|
||||
if (RCL_RET_OK != ret || nonros_argc < 0) {
|
||||
// Not using throw_from_rcl_error, because we may need to append deallocation failures.
|
||||
exceptions::RCLErrorBase base_exc(ret, rcl_get_error_state());
|
||||
rcl_reset_error();
|
||||
if (NULL != nonros_argv) {
|
||||
alloc.deallocate(nonros_argv, alloc.state);
|
||||
}
|
||||
if (RCL_RET_OK != rcl_arguments_fini(&parsed_args)) {
|
||||
exc.formatted_message += std::string(
|
||||
base_exc.formatted_message += std::string(
|
||||
", failed also to cleanup parsed arguments, leaking memory: ") +
|
||||
rcl_get_error_string().str;
|
||||
rcl_reset_error();
|
||||
}
|
||||
throw exc;
|
||||
throw exceptions::RCLError(base_exc, "");
|
||||
}
|
||||
|
||||
std::vector<std::string> return_arguments(static_cast<size_t>(nonros_argc));
|
||||
|
||||
for (size_t ii = 0; ii < static_cast<size_t>(nonros_argc); ++ii) {
|
||||
return_arguments[ii] = std::string(nonros_argv[ii]);
|
||||
}
|
||||
|
||||
if (NULL != nonros_argv) {
|
||||
alloc.deallocate(nonros_argv, alloc.state);
|
||||
}
|
||||
|
||||
ret = rcl_arguments_fini(&parsed_args);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
find_package(ament_cmake_google_benchmark REQUIRED)
|
||||
find_package(performance_test_fixture REQUIRED)
|
||||
|
||||
# These benchmarks are only being created and run for the default RMW
|
||||
@@ -31,6 +32,11 @@ if(TARGET benchmark_node_parameters_interface)
|
||||
target_link_libraries(benchmark_node_parameters_interface ${PROJECT_NAME})
|
||||
endif()
|
||||
|
||||
ament_add_google_benchmark(benchmark_parameter_client benchmark_parameter_client.cpp)
|
||||
if(TARGET benchmark_parameter_client)
|
||||
target_link_libraries(benchmark_parameter_client ${PROJECT_NAME})
|
||||
endif()
|
||||
|
||||
add_performance_test(benchmark_service benchmark_service.cpp)
|
||||
if(TARGET benchmark_service)
|
||||
target_link_libraries(benchmark_service ${PROJECT_NAME})
|
||||
|
||||
324
rclcpp/test/benchmark/benchmark_parameter_client.cpp
Normal file
324
rclcpp/test/benchmark/benchmark_parameter_client.cpp
Normal file
@@ -0,0 +1,324 @@
|
||||
// Copyright 2020 Open Source Robotics Foundation, Inc.
|
||||
//
|
||||
// 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 <memory>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "benchmark/benchmark.h"
|
||||
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
|
||||
class RemoteNodeTest : public benchmark::Fixture
|
||||
{
|
||||
public:
|
||||
RemoteNodeTest()
|
||||
: remote_node_name("my_remote_node")
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
|
||||
#endif
|
||||
void SetUp(benchmark::State &)
|
||||
{
|
||||
remote_context = std::make_shared<rclcpp::Context>();
|
||||
remote_context->init(0, nullptr, rclcpp::InitOptions().auto_initialize_logging(false));
|
||||
|
||||
rclcpp::ExecutorOptions exec_options;
|
||||
exec_options.context = remote_context;
|
||||
|
||||
remote_executor = std::make_shared<rclcpp::executors::SingleThreadedExecutor>(exec_options);
|
||||
|
||||
remote_node = std::make_shared<rclcpp::Node>(
|
||||
remote_node_name, rclcpp::NodeOptions().context(remote_context));
|
||||
remote_executor->add_node(remote_node);
|
||||
|
||||
remote_thread = std::thread(&rclcpp::executors::SingleThreadedExecutor::spin, remote_executor);
|
||||
}
|
||||
|
||||
void TearDown(benchmark::State &)
|
||||
{
|
||||
remote_executor->cancel();
|
||||
remote_context->shutdown("Test is complete");
|
||||
remote_thread.join();
|
||||
|
||||
remote_node.reset();
|
||||
remote_executor.reset();
|
||||
remote_context.reset();
|
||||
}
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
const std::string remote_node_name;
|
||||
|
||||
protected:
|
||||
rclcpp::Context::SharedPtr remote_context;
|
||||
rclcpp::executors::SingleThreadedExecutor::SharedPtr remote_executor;
|
||||
rclcpp::Node::SharedPtr remote_node;
|
||||
std::thread remote_thread;
|
||||
};
|
||||
|
||||
class ParameterClientTest : public RemoteNodeTest
|
||||
{
|
||||
public:
|
||||
ParameterClientTest()
|
||||
: node_name("my_node"),
|
||||
param_prefix("my_prefix"),
|
||||
param1_name(param_prefix + ".my_param_1"),
|
||||
param2_name(param_prefix + ".my_param_2"),
|
||||
param3_name(param_prefix + ".my_param_3")
|
||||
{
|
||||
}
|
||||
|
||||
void SetUp(benchmark::State & state)
|
||||
{
|
||||
RemoteNodeTest::SetUp(state);
|
||||
|
||||
rclcpp::init(0, nullptr);
|
||||
node = std::make_shared<rclcpp::Node>(node_name);
|
||||
|
||||
remote_node->declare_parameter(
|
||||
param1_name, rclcpp::ParameterValue("param1_value"));
|
||||
remote_node->declare_parameter(
|
||||
param2_name, rclcpp::ParameterValue(std::vector<int> {1, 2, 3}));
|
||||
remote_node->declare_parameter(param3_name);
|
||||
remote_node->undeclare_parameter(param3_name);
|
||||
|
||||
params_client = std::make_shared<rclcpp::SyncParametersClient>(node, remote_node_name);
|
||||
|
||||
if (!params_client->wait_for_service()) {
|
||||
state.SkipWithError("Client failed to become ready");
|
||||
}
|
||||
}
|
||||
|
||||
void TearDown(benchmark::State & state)
|
||||
{
|
||||
RemoteNodeTest::TearDown(state);
|
||||
|
||||
rclcpp::shutdown();
|
||||
node.reset();
|
||||
params_client.reset();
|
||||
}
|
||||
|
||||
const std::string node_name;
|
||||
const std::string param_prefix;
|
||||
const std::string param1_name;
|
||||
const std::string param2_name;
|
||||
const std::string param3_name;
|
||||
|
||||
protected:
|
||||
rclcpp::Node::SharedPtr node;
|
||||
rclcpp::SyncParametersClient::SharedPtr params_client;
|
||||
};
|
||||
|
||||
static bool result_is_successful(rcl_interfaces::msg::SetParametersResult result)
|
||||
{
|
||||
return result.successful;
|
||||
}
|
||||
|
||||
BENCHMARK_F(ParameterClientTest, create_destroy_client)(benchmark::State & state)
|
||||
{
|
||||
for (auto _ : state) {
|
||||
params_client.reset();
|
||||
params_client = std::make_shared<rclcpp::SyncParametersClient>(node, remote_node_name);
|
||||
if (!params_client->wait_for_service()) {
|
||||
state.SkipWithError("Client failed to become ready");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_F(ParameterClientTest, has_parameter_hit)(benchmark::State & state)
|
||||
{
|
||||
for (auto _ : state) {
|
||||
if (!params_client->has_parameter(param1_name)) {
|
||||
state.SkipWithError("Parameter was expected");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_F(ParameterClientTest, has_parameter_miss)(benchmark::State & state)
|
||||
{
|
||||
for (auto _ : state) {
|
||||
if (params_client->has_parameter(param3_name)) {
|
||||
state.SkipWithError("Parameter was not expected");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_F(ParameterClientTest, set_parameters_bool)(benchmark::State & state)
|
||||
{
|
||||
const std::vector<rclcpp::Parameter> param_values1
|
||||
{
|
||||
rclcpp::Parameter(param1_name, true),
|
||||
rclcpp::Parameter(param2_name, false),
|
||||
};
|
||||
const std::vector<rclcpp::Parameter> param_values2
|
||||
{
|
||||
rclcpp::Parameter(param1_name, false),
|
||||
rclcpp::Parameter(param2_name, true),
|
||||
};
|
||||
|
||||
for (auto _ : state) {
|
||||
std::vector<rcl_interfaces::msg::SetParametersResult> results =
|
||||
params_client->set_parameters(param_values2);
|
||||
if (!std::all_of(results.begin(), results.end(), result_is_successful)) {
|
||||
state.SkipWithError("Failed to set one or more parameters");
|
||||
break;
|
||||
}
|
||||
|
||||
results = params_client->set_parameters(param_values1);
|
||||
if (!std::all_of(results.begin(), results.end(), result_is_successful)) {
|
||||
state.SkipWithError("Failed to set one or more parameters");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_F(ParameterClientTest, set_parameters_atomically_bool)(benchmark::State & state)
|
||||
{
|
||||
const std::vector<rclcpp::Parameter> param_values1
|
||||
{
|
||||
rclcpp::Parameter(param1_name, true),
|
||||
rclcpp::Parameter(param2_name, false),
|
||||
};
|
||||
const std::vector<rclcpp::Parameter> param_values2
|
||||
{
|
||||
rclcpp::Parameter(param1_name, false),
|
||||
rclcpp::Parameter(param2_name, true),
|
||||
};
|
||||
|
||||
for (auto _ : state) {
|
||||
rcl_interfaces::msg::SetParametersResult result =
|
||||
params_client->set_parameters_atomically(param_values2);
|
||||
if (!result.successful) {
|
||||
state.SkipWithError(("Failed to set parameters: " + result.reason).c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
result = params_client->set_parameters_atomically(param_values1);
|
||||
if (!result.successful) {
|
||||
state.SkipWithError(("Failed to set parameters: " + result.reason).c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_F(ParameterClientTest, set_parameters_string)(benchmark::State & state)
|
||||
{
|
||||
const std::vector<rclcpp::Parameter> param_values1
|
||||
{
|
||||
rclcpp::Parameter(param1_name, "param 1 value A"),
|
||||
rclcpp::Parameter(param2_name, "param 2 value B"),
|
||||
};
|
||||
const std::vector<rclcpp::Parameter> param_values2
|
||||
{
|
||||
rclcpp::Parameter(param1_name, "param 1 value B"),
|
||||
rclcpp::Parameter(param2_name, "param 2 value A"),
|
||||
};
|
||||
|
||||
for (auto _ : state) {
|
||||
std::vector<rcl_interfaces::msg::SetParametersResult> results =
|
||||
params_client->set_parameters(param_values2);
|
||||
if (!std::all_of(results.begin(), results.end(), result_is_successful)) {
|
||||
state.SkipWithError("Failed to set one or more parameters");
|
||||
break;
|
||||
}
|
||||
|
||||
results = params_client->set_parameters(param_values1);
|
||||
if (!std::all_of(results.begin(), results.end(), result_is_successful)) {
|
||||
state.SkipWithError("Failed to set one or more parameters");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_F(ParameterClientTest, set_parameters_array)(benchmark::State & state)
|
||||
{
|
||||
const std::vector<rclcpp::Parameter> param_values1
|
||||
{
|
||||
rclcpp::Parameter(param1_name, std::vector<int> {0, 1, 2}),
|
||||
rclcpp::Parameter(param2_name, std::vector<int> {3, 4, 5}),
|
||||
};
|
||||
const std::vector<rclcpp::Parameter> param_values2
|
||||
{
|
||||
rclcpp::Parameter(param1_name, std::vector<int> {4, 5, 6}),
|
||||
rclcpp::Parameter(param2_name, std::vector<int> {7, 8, 9}),
|
||||
};
|
||||
|
||||
for (auto _ : state) {
|
||||
std::vector<rcl_interfaces::msg::SetParametersResult> results =
|
||||
params_client->set_parameters(param_values2);
|
||||
if (!std::all_of(results.begin(), results.end(), result_is_successful)) {
|
||||
state.SkipWithError("Failed to set one or more parameters");
|
||||
break;
|
||||
}
|
||||
|
||||
results = params_client->set_parameters(param_values1);
|
||||
if (!std::all_of(results.begin(), results.end(), result_is_successful)) {
|
||||
state.SkipWithError("Failed to set one or more parameters");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_F(ParameterClientTest, get_parameters)(benchmark::State & state)
|
||||
{
|
||||
for (auto _ : state) {
|
||||
std::vector<rclcpp::Parameter> results = params_client->get_parameters({param1_name});
|
||||
if (results.size() != 1 || results[0].get_name() != param1_name) {
|
||||
state.SkipWithError("Got the wrong parameter(s)");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_F(ParameterClientTest, list_parameters_hit)(benchmark::State & state)
|
||||
{
|
||||
const std::vector<std::string> prefixes
|
||||
{
|
||||
param_prefix,
|
||||
};
|
||||
|
||||
for (auto _ : state) {
|
||||
rcl_interfaces::msg::ListParametersResult param_list =
|
||||
params_client->list_parameters(prefixes, 10);
|
||||
if (param_list.names.size() != 2) {
|
||||
state.SkipWithError("Expected parameters");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_F(ParameterClientTest, list_parameters_miss)(benchmark::State & state)
|
||||
{
|
||||
const std::vector<std::string> prefixes
|
||||
{
|
||||
"your_prefix",
|
||||
};
|
||||
|
||||
for (auto _ : state) {
|
||||
rcl_interfaces::msg::ListParametersResult param_list =
|
||||
params_client->list_parameters(prefixes, 10);
|
||||
if (param_list.names.size() != 0) {
|
||||
state.SkipWithError("Expected no parameters");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,15 +97,6 @@ if(TARGET test_create_subscription)
|
||||
"test_msgs"
|
||||
)
|
||||
endif()
|
||||
ament_add_gtest(test_add_callback_groups_to_executor
|
||||
test_add_callback_groups_to_executor.cpp
|
||||
TIMEOUT 120)
|
||||
if(TARGET test_add_callback_groups_to_executor)
|
||||
target_link_libraries(test_add_callback_groups_to_executor ${PROJECT_NAME})
|
||||
ament_target_dependencies(test_add_callback_groups_to_executor
|
||||
"test_msgs"
|
||||
)
|
||||
endif()
|
||||
ament_add_gtest(test_expand_topic_or_service_name test_expand_topic_or_service_name.cpp)
|
||||
if(TARGET test_expand_topic_or_service_name)
|
||||
ament_target_dependencies(test_expand_topic_or_service_name
|
||||
@@ -633,12 +624,6 @@ if(TARGET test_thread_safe_synchronization)
|
||||
target_link_libraries(test_thread_safe_synchronization ${PROJECT_NAME})
|
||||
endif()
|
||||
|
||||
ament_add_gtest(test_rosout_qos test_rosout_qos.cpp)
|
||||
if(TARGET test_rosout_qos)
|
||||
ament_target_dependencies(test_rosout_qos "rcl")
|
||||
target_link_libraries(test_rosout_qos ${PROJECT_NAME})
|
||||
endif()
|
||||
|
||||
ament_add_gtest(test_executor test_executor.cpp
|
||||
APPEND_LIBRARY_DIRS "${append_library_dirs}"
|
||||
TIMEOUT 120)
|
||||
|
||||
@@ -115,9 +115,9 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
// TYPED_TEST_SUITE is deprecated as of gtest 1.9, use TYPED_TEST_SUITE when gtest dependency
|
||||
// TYPED_TEST_CASE is deprecated as of gtest 1.9, use TYPED_TEST_SUITE when gtest dependency
|
||||
// is updated.
|
||||
TYPED_TEST_SUITE(TestExecutors, ExecutorTypes, ExecutorTypeNames);
|
||||
TYPED_TEST_CASE(TestExecutors, ExecutorTypes, ExecutorTypeNames);
|
||||
|
||||
// StaticSingleThreadedExecutor is not included in these tests for now, due to:
|
||||
// https://github.com/ros2/rclcpp/issues/1219
|
||||
@@ -125,7 +125,7 @@ using StandardExecutors =
|
||||
::testing::Types<
|
||||
rclcpp::executors::SingleThreadedExecutor,
|
||||
rclcpp::executors::MultiThreadedExecutor>;
|
||||
TYPED_TEST_SUITE(TestExecutorsStable, StandardExecutors, ExecutorTypeNames);
|
||||
TYPED_TEST_CASE(TestExecutorsStable, StandardExecutors, ExecutorTypeNames);
|
||||
|
||||
// Make sure that executors detach from nodes when destructing
|
||||
TYPED_TEST(TestExecutors, detachOnDestruction) {
|
||||
@@ -241,157 +241,6 @@ TYPED_TEST(TestExecutors, testSpinUntilFutureComplete) {
|
||||
EXPECT_EQ(rclcpp::FutureReturnCode::SUCCESS, ret);
|
||||
}
|
||||
|
||||
// Same test, but uses a shared future.
|
||||
TYPED_TEST(TestExecutors, testSpinUntilSharedFutureComplete) {
|
||||
using ExecutorType = TypeParam;
|
||||
ExecutorType executor;
|
||||
executor.add_node(this->node);
|
||||
|
||||
// test success of an immediately finishing future
|
||||
std::promise<bool> promise;
|
||||
std::future<bool> future = promise.get_future();
|
||||
promise.set_value(true);
|
||||
|
||||
// spin_until_future_complete is expected to exit immediately, but would block up until its
|
||||
// timeout if the future is not checked before spin_once_impl.
|
||||
auto shared_future = future.share();
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
auto ret = executor.spin_until_future_complete(shared_future, 1s);
|
||||
executor.remove_node(this->node, true);
|
||||
|
||||
// Check it didn't reach timeout
|
||||
EXPECT_GT(500ms, (std::chrono::steady_clock::now() - start));
|
||||
EXPECT_EQ(rclcpp::FutureReturnCode::SUCCESS, ret);
|
||||
}
|
||||
|
||||
// For a longer running future that should require several iterations of spin_once
|
||||
TYPED_TEST(TestExecutors, testSpinUntilFutureCompleteNoTimeout) {
|
||||
using ExecutorType = TypeParam;
|
||||
ExecutorType executor;
|
||||
executor.add_node(this->node);
|
||||
|
||||
// This future doesn't immediately terminate, so some work gets performed.
|
||||
std::future<void> future = std::async(
|
||||
std::launch::async,
|
||||
[this]() {
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
while (this->callback_count < 1 && (std::chrono::steady_clock::now() - start) < 1s) {
|
||||
std::this_thread::sleep_for(1ms);
|
||||
}
|
||||
});
|
||||
|
||||
bool spin_exited = false;
|
||||
|
||||
// Timeout set to negative for no timeout.
|
||||
std::thread spinner([&]() {
|
||||
auto ret = executor.spin_until_future_complete(future, -1s);
|
||||
EXPECT_EQ(rclcpp::FutureReturnCode::SUCCESS, ret);
|
||||
executor.remove_node(this->node, true);
|
||||
executor.cancel();
|
||||
spin_exited = true;
|
||||
});
|
||||
|
||||
// Do some work for longer than the future needs.
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
this->publisher->publish(test_msgs::msg::Empty());
|
||||
std::this_thread::sleep_for(1ms);
|
||||
if (spin_exited) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Not testing accuracy, just want to make sure that some work occurred.
|
||||
EXPECT_LT(0, this->callback_count);
|
||||
|
||||
// If this fails, the test will probably crash because spinner goes out of scope while the thread
|
||||
// is active. However, it beats letting this run until the gtest timeout.
|
||||
ASSERT_TRUE(spin_exited);
|
||||
executor.cancel();
|
||||
spinner.join();
|
||||
}
|
||||
|
||||
// Check spin_until_future_complete timeout works as expected
|
||||
TYPED_TEST(TestExecutors, testSpinUntilFutureCompleteWithTimeout) {
|
||||
using ExecutorType = TypeParam;
|
||||
ExecutorType executor;
|
||||
executor.add_node(this->node);
|
||||
|
||||
bool spin_exited = false;
|
||||
|
||||
// Needs to run longer than spin_until_future_complete's timeout.
|
||||
std::future<void> future = std::async(
|
||||
std::launch::async,
|
||||
[&spin_exited]() {
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
while (!spin_exited && (std::chrono::steady_clock::now() - start) < 1s) {
|
||||
std::this_thread::sleep_for(1ms);
|
||||
}
|
||||
});
|
||||
|
||||
// Short timeout
|
||||
std::thread spinner([&]() {
|
||||
auto ret = executor.spin_until_future_complete(future, 1ms);
|
||||
EXPECT_EQ(rclcpp::FutureReturnCode::TIMEOUT, ret);
|
||||
executor.remove_node(this->node, true);
|
||||
spin_exited = true;
|
||||
});
|
||||
|
||||
// Do some work for longer than timeout needs.
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
this->publisher->publish(test_msgs::msg::Empty());
|
||||
std::this_thread::sleep_for(1ms);
|
||||
if (spin_exited) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(spin_exited);
|
||||
spinner.join();
|
||||
}
|
||||
|
||||
// Check spin_until_future_complete can be properly interrupted.
|
||||
TYPED_TEST(TestExecutors, testSpinUntilFutureCompleteInterrupted) {
|
||||
using ExecutorType = TypeParam;
|
||||
ExecutorType executor;
|
||||
executor.add_node(this->node);
|
||||
|
||||
bool spin_exited = false;
|
||||
|
||||
// This needs to block longer than it takes to get to the shutdown call below and for
|
||||
// spin_until_future_complete to return
|
||||
std::future<void> future = std::async(
|
||||
std::launch::async,
|
||||
[&spin_exited]() {
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
while (!spin_exited && (std::chrono::steady_clock::now() - start) < 1s) {
|
||||
std::this_thread::sleep_for(1ms);
|
||||
}
|
||||
});
|
||||
|
||||
// Long timeout
|
||||
std::thread spinner([&spin_exited, &executor, &future]() {
|
||||
auto ret = executor.spin_until_future_complete(future, 1s);
|
||||
EXPECT_EQ(rclcpp::FutureReturnCode::INTERRUPTED, ret);
|
||||
spin_exited = true;
|
||||
});
|
||||
|
||||
// Do some minimal work
|
||||
this->publisher->publish(test_msgs::msg::Empty());
|
||||
std::this_thread::sleep_for(1ms);
|
||||
|
||||
// Force interruption
|
||||
rclcpp::shutdown();
|
||||
|
||||
// Give it time to exit
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
while (!spin_exited && (std::chrono::steady_clock::now() - start) < 1s) {
|
||||
std::this_thread::sleep_for(1ms);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(spin_exited);
|
||||
spinner.join();
|
||||
}
|
||||
|
||||
class TestWaitable : public rclcpp::Waitable
|
||||
{
|
||||
public:
|
||||
@@ -457,46 +306,6 @@ private:
|
||||
rcl_guard_condition_t gc_;
|
||||
};
|
||||
|
||||
TYPED_TEST(TestExecutorsStable, spinAll) {
|
||||
using ExecutorType = TypeParam;
|
||||
ExecutorType executor;
|
||||
auto waitable_interfaces = this->node->get_node_waitables_interface();
|
||||
auto my_waitable = std::make_shared<TestWaitable>();
|
||||
waitable_interfaces->add_waitable(my_waitable, nullptr);
|
||||
executor.add_node(this->node);
|
||||
|
||||
// Long timeout, but should not block test if spin_all works as expected as we cancel the
|
||||
// executor.
|
||||
bool spin_exited = false;
|
||||
std::thread spinner([&spin_exited, &executor, this]() {
|
||||
executor.spin_all(1s);
|
||||
executor.remove_node(this->node, true);
|
||||
spin_exited = true;
|
||||
});
|
||||
|
||||
// Do some work until sufficient calls to the waitable occur
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
while (
|
||||
my_waitable->get_count() <= 1 &&
|
||||
!spin_exited &&
|
||||
(std::chrono::steady_clock::now() - start < 1s))
|
||||
{
|
||||
this->publisher->publish(test_msgs::msg::Empty());
|
||||
std::this_thread::sleep_for(1ms);
|
||||
}
|
||||
|
||||
executor.cancel();
|
||||
start = std::chrono::steady_clock::now();
|
||||
while (!spin_exited && (std::chrono::steady_clock::now() - start) < 1s) {
|
||||
std::this_thread::sleep_for(1ms);
|
||||
}
|
||||
|
||||
EXPECT_LT(1u, my_waitable->get_count());
|
||||
waitable_interfaces->remove_waitable(my_waitable, nullptr);
|
||||
ASSERT_TRUE(spin_exited);
|
||||
spinner.join();
|
||||
}
|
||||
|
||||
TYPED_TEST(TestExecutorsStable, spinSome) {
|
||||
using ExecutorType = TypeParam;
|
||||
ExecutorType executor;
|
||||
|
||||
@@ -14,18 +14,13 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
|
||||
#include "test_msgs/msg/empty.hpp"
|
||||
#include "test_msgs/srv/empty.hpp"
|
||||
|
||||
#include "../../mocking_utils/patch.hpp"
|
||||
#include "../../utils/rclcpp_gtest_macros.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@@ -110,9 +105,7 @@ TEST_F(TestStaticExecutorEntitiesCollector, add_remove_node) {
|
||||
EXPECT_NO_THROW(entities_collector_->add_node(node1->get_node_base_interface()));
|
||||
|
||||
// Check adding second time
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
entities_collector_->add_node(node1->get_node_base_interface()),
|
||||
std::runtime_error("Node has already been added to an executor."));
|
||||
EXPECT_THROW(entities_collector_->add_node(node1->get_node_base_interface()), std::runtime_error);
|
||||
|
||||
auto node2 = std::make_shared<rclcpp::Node>("node2", "ns");
|
||||
EXPECT_FALSE(entities_collector_->remove_node(node2->get_node_base_interface()));
|
||||
@@ -121,10 +114,6 @@ TEST_F(TestStaticExecutorEntitiesCollector, add_remove_node) {
|
||||
EXPECT_TRUE(entities_collector_->remove_node(node1->get_node_base_interface()));
|
||||
EXPECT_FALSE(entities_collector_->remove_node(node1->get_node_base_interface()));
|
||||
EXPECT_TRUE(entities_collector_->remove_node(node2->get_node_base_interface()));
|
||||
|
||||
auto node3 = std::make_shared<rclcpp::Node>("node3", "ns");
|
||||
node3->get_node_base_interface()->get_associated_with_executor_atomic().exchange(true);
|
||||
EXPECT_FALSE(entities_collector_->remove_node(node3->get_node_base_interface()));
|
||||
}
|
||||
|
||||
TEST_F(TestStaticExecutorEntitiesCollector, init_bad_arguments) {
|
||||
@@ -307,316 +296,3 @@ TEST_F(TestStaticExecutorEntitiesCollector, add_remove_node_with_entities) {
|
||||
// Still one for the executor
|
||||
EXPECT_EQ(1u, entities_collector_->get_number_of_waitables());
|
||||
}
|
||||
|
||||
TEST_F(TestStaticExecutorEntitiesCollector, add_callback_group) {
|
||||
auto node = std::make_shared<rclcpp::Node>("node1", "ns");
|
||||
rclcpp::CallbackGroup::SharedPtr cb_group = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
|
||||
entities_collector_->add_callback_group(cb_group, node->get_node_base_interface());
|
||||
ASSERT_EQ(entities_collector_->get_all_callback_groups().size(), 1u);
|
||||
}
|
||||
|
||||
TEST_F(TestStaticExecutorEntitiesCollector, add_callback_group_after_add_node) {
|
||||
auto node = std::make_shared<rclcpp::Node>("node1", "ns");
|
||||
rclcpp::CallbackGroup::SharedPtr cb_group = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
|
||||
entities_collector_->add_node(node->get_node_base_interface());
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
entities_collector_->add_callback_group(cb_group, node->get_node_base_interface()),
|
||||
std::runtime_error("Callback group has already been added to an executor."));
|
||||
}
|
||||
|
||||
TEST_F(TestStaticExecutorEntitiesCollector, add_callback_group_twice) {
|
||||
auto node = std::make_shared<rclcpp::Node>("node1", "ns");
|
||||
rclcpp::CallbackGroup::SharedPtr cb_group = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
|
||||
entities_collector_->add_callback_group(cb_group, node->get_node_base_interface());
|
||||
ASSERT_EQ(entities_collector_->get_all_callback_groups().size(), 1u);
|
||||
cb_group->get_associated_with_executor_atomic().exchange(false);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
entities_collector_->add_callback_group(cb_group, node->get_node_base_interface()),
|
||||
std::runtime_error("Callback group was already added to executor."));
|
||||
}
|
||||
|
||||
TEST_F(TestStaticExecutorEntitiesCollector, prepare_wait_set_rcl_wait_set_clear_error) {
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
entities_collector_->add_node(node->get_node_base_interface());
|
||||
|
||||
rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator();
|
||||
auto shared_context = node->get_node_base_interface()->get_context();
|
||||
rcl_context_t * context = shared_context->get_rcl_context().get();
|
||||
EXPECT_EQ(
|
||||
RCL_RET_OK,
|
||||
rcl_wait_set_init(&wait_set, 100, 100, 100, 100, 100, 100, context, allocator));
|
||||
RCLCPP_SCOPE_EXIT({EXPECT_EQ(RCL_RET_OK, rcl_wait_set_fini(&wait_set));});
|
||||
|
||||
auto memory_strategy = rclcpp::memory_strategies::create_default_strategy();
|
||||
rclcpp::GuardCondition guard_condition(shared_context);
|
||||
rcl_guard_condition_t rcl_guard_condition = guard_condition.get_rcl_guard_condition();
|
||||
|
||||
entities_collector_->init(&wait_set, memory_strategy, &rcl_guard_condition);
|
||||
RCLCPP_SCOPE_EXIT(entities_collector_->fini());
|
||||
|
||||
{
|
||||
auto mock = mocking_utils::patch_and_return("lib:rclcpp", rcl_wait_set_clear, RCL_RET_ERROR);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
entities_collector_->execute(),
|
||||
std::runtime_error("Couldn't clear wait set"));
|
||||
}
|
||||
|
||||
EXPECT_TRUE(entities_collector_->remove_node(node->get_node_base_interface()));
|
||||
}
|
||||
|
||||
TEST_F(TestStaticExecutorEntitiesCollector, prepare_wait_set_rcl_wait_set_resize_error) {
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
entities_collector_->add_node(node->get_node_base_interface());
|
||||
|
||||
rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator();
|
||||
auto shared_context = node->get_node_base_interface()->get_context();
|
||||
rcl_context_t * context = shared_context->get_rcl_context().get();
|
||||
EXPECT_EQ(
|
||||
RCL_RET_OK,
|
||||
rcl_wait_set_init(&wait_set, 100, 100, 100, 100, 100, 100, context, allocator));
|
||||
RCLCPP_SCOPE_EXIT({EXPECT_EQ(RCL_RET_OK, rcl_wait_set_fini(&wait_set));});
|
||||
|
||||
auto memory_strategy = rclcpp::memory_strategies::create_default_strategy();
|
||||
rclcpp::GuardCondition guard_condition(shared_context);
|
||||
rcl_guard_condition_t rcl_guard_condition = guard_condition.get_rcl_guard_condition();
|
||||
|
||||
entities_collector_->init(&wait_set, memory_strategy, &rcl_guard_condition);
|
||||
RCLCPP_SCOPE_EXIT(entities_collector_->fini());
|
||||
|
||||
{
|
||||
auto mock = mocking_utils::patch_and_return("lib:rclcpp", rcl_wait_set_resize, RCL_RET_ERROR);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
entities_collector_->execute(),
|
||||
std::runtime_error("Couldn't resize the wait set: error not set"));
|
||||
}
|
||||
|
||||
EXPECT_TRUE(entities_collector_->remove_node(node->get_node_base_interface()));
|
||||
}
|
||||
|
||||
TEST_F(TestStaticExecutorEntitiesCollector, refresh_wait_set_not_initialized) {
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
entities_collector_->refresh_wait_set(std::chrono::nanoseconds(1000)),
|
||||
std::runtime_error("Couldn't clear wait set"));
|
||||
rcl_reset_error();
|
||||
}
|
||||
|
||||
TEST_F(TestStaticExecutorEntitiesCollector, refresh_wait_set_rcl_wait_failed) {
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
entities_collector_->add_node(node->get_node_base_interface());
|
||||
|
||||
rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator();
|
||||
auto shared_context = node->get_node_base_interface()->get_context();
|
||||
rcl_context_t * context = shared_context->get_rcl_context().get();
|
||||
EXPECT_EQ(
|
||||
RCL_RET_OK,
|
||||
rcl_wait_set_init(&wait_set, 100, 100, 100, 100, 100, 100, context, allocator));
|
||||
RCLCPP_SCOPE_EXIT({EXPECT_EQ(RCL_RET_OK, rcl_wait_set_fini(&wait_set));});
|
||||
|
||||
auto memory_strategy = rclcpp::memory_strategies::create_default_strategy();
|
||||
rclcpp::GuardCondition guard_condition(shared_context);
|
||||
rcl_guard_condition_t rcl_guard_condition = guard_condition.get_rcl_guard_condition();
|
||||
|
||||
entities_collector_->init(&wait_set, memory_strategy, &rcl_guard_condition);
|
||||
RCLCPP_SCOPE_EXIT(entities_collector_->fini());
|
||||
|
||||
{
|
||||
auto mock = mocking_utils::patch_and_return("lib:rclcpp", rcl_wait, RCL_RET_ERROR);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
entities_collector_->refresh_wait_set(std::chrono::nanoseconds(1000)),
|
||||
std::runtime_error("rcl_wait() failed: error not set"));
|
||||
}
|
||||
|
||||
EXPECT_TRUE(entities_collector_->remove_node(node->get_node_base_interface()));
|
||||
}
|
||||
|
||||
TEST_F(TestStaticExecutorEntitiesCollector, refresh_wait_set_add_handles_to_wait_set_failed) {
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
|
||||
// Create 1 of each entity type
|
||||
auto subscription =
|
||||
node->create_subscription<test_msgs::msg::Empty>(
|
||||
"topic", rclcpp::QoS(10), [](test_msgs::msg::Empty::SharedPtr) {});
|
||||
auto timer =
|
||||
node->create_wall_timer(std::chrono::seconds(60), []() {});
|
||||
auto service =
|
||||
node->create_service<test_msgs::srv::Empty>(
|
||||
"service",
|
||||
[](
|
||||
const test_msgs::srv::Empty::Request::SharedPtr,
|
||||
test_msgs::srv::Empty::Response::SharedPtr) {});
|
||||
auto client = node->create_client<test_msgs::srv::Empty>("service");
|
||||
auto waitable = std::make_shared<TestWaitable>();
|
||||
|
||||
node->get_node_waitables_interface()->add_waitable(waitable, nullptr);
|
||||
|
||||
entities_collector_->add_node(node->get_node_base_interface());
|
||||
|
||||
rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator();
|
||||
auto shared_context = node->get_node_base_interface()->get_context();
|
||||
rcl_context_t * context = shared_context->get_rcl_context().get();
|
||||
EXPECT_EQ(
|
||||
RCL_RET_OK,
|
||||
rcl_wait_set_init(&wait_set, 100, 100, 100, 100, 100, 100, context, allocator));
|
||||
RCLCPP_SCOPE_EXIT({EXPECT_EQ(RCL_RET_OK, rcl_wait_set_fini(&wait_set));});
|
||||
|
||||
auto memory_strategy = rclcpp::memory_strategies::create_default_strategy();
|
||||
|
||||
rclcpp::GuardCondition guard_condition(shared_context);
|
||||
rcl_guard_condition_t rcl_guard_condition = guard_condition.get_rcl_guard_condition();
|
||||
|
||||
entities_collector_->init(&wait_set, memory_strategy, &rcl_guard_condition);
|
||||
RCLCPP_SCOPE_EXIT(entities_collector_->fini());
|
||||
|
||||
{
|
||||
auto mock = mocking_utils::patch_and_return(
|
||||
"lib:rclcpp", rcl_wait_set_add_subscription,
|
||||
RCL_RET_ERROR);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
entities_collector_->refresh_wait_set(std::chrono::nanoseconds(1000)),
|
||||
std::runtime_error("Couldn't fill wait set"));
|
||||
}
|
||||
|
||||
entities_collector_->remove_node(node->get_node_base_interface());
|
||||
}
|
||||
|
||||
TEST_F(TestStaticExecutorEntitiesCollector, add_to_wait_set_nullptr) {
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
entities_collector_->add_node(node->get_node_base_interface());
|
||||
|
||||
rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator();
|
||||
auto shared_context = node->get_node_base_interface()->get_context();
|
||||
rcl_context_t * context = shared_context->get_rcl_context().get();
|
||||
EXPECT_EQ(
|
||||
RCL_RET_OK,
|
||||
rcl_wait_set_init(&wait_set, 100, 100, 100, 100, 100, 100, context, allocator));
|
||||
RCLCPP_SCOPE_EXIT({EXPECT_EQ(RCL_RET_OK, rcl_wait_set_fini(&wait_set));});
|
||||
|
||||
auto memory_strategy = rclcpp::memory_strategies::create_default_strategy();
|
||||
rclcpp::GuardCondition guard_condition(shared_context);
|
||||
rcl_guard_condition_t rcl_guard_condition = guard_condition.get_rcl_guard_condition();
|
||||
|
||||
entities_collector_->init(&wait_set, memory_strategy, &rcl_guard_condition);
|
||||
RCLCPP_SCOPE_EXIT(entities_collector_->fini());
|
||||
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
entities_collector_->add_to_wait_set(nullptr),
|
||||
std::runtime_error("Executor waitable: couldn't add guard condition to wait set"));
|
||||
rcl_reset_error();
|
||||
|
||||
EXPECT_TRUE(entities_collector_->remove_node(node->get_node_base_interface()));
|
||||
}
|
||||
|
||||
TEST_F(TestStaticExecutorEntitiesCollector, fill_memory_strategy_invalid_group) {
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
entities_collector_->add_node(node->get_node_base_interface());
|
||||
|
||||
rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator();
|
||||
auto shared_context = node->get_node_base_interface()->get_context();
|
||||
rcl_context_t * context = shared_context->get_rcl_context().get();
|
||||
EXPECT_EQ(
|
||||
RCL_RET_OK,
|
||||
rcl_wait_set_init(&wait_set, 100, 100, 100, 100, 100, 100, context, allocator));
|
||||
RCLCPP_SCOPE_EXIT({EXPECT_EQ(RCL_RET_OK, rcl_wait_set_fini(&wait_set));});
|
||||
|
||||
auto memory_strategy = rclcpp::memory_strategies::create_default_strategy();
|
||||
rclcpp::GuardCondition guard_condition(shared_context);
|
||||
rcl_guard_condition_t rcl_guard_condition = guard_condition.get_rcl_guard_condition();
|
||||
|
||||
rclcpp::CallbackGroup::SharedPtr cb_group = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
|
||||
entities_collector_->add_callback_group(cb_group, node->get_node_base_interface());
|
||||
ASSERT_EQ(entities_collector_->get_all_callback_groups().size(), 2u);
|
||||
|
||||
cb_group.reset();
|
||||
|
||||
entities_collector_->init(&wait_set, memory_strategy, &rcl_guard_condition);
|
||||
RCLCPP_SCOPE_EXIT(entities_collector_->fini());
|
||||
ASSERT_EQ(entities_collector_->get_all_callback_groups().size(), 1u);
|
||||
|
||||
EXPECT_TRUE(entities_collector_->remove_node(node->get_node_base_interface()));
|
||||
}
|
||||
|
||||
TEST_F(TestStaticExecutorEntitiesCollector, remove_callback_group_after_node) {
|
||||
auto node = std::make_shared<rclcpp::Node>("node1", "ns");
|
||||
rclcpp::CallbackGroup::SharedPtr cb_group = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
|
||||
entities_collector_->add_callback_group(cb_group, node->get_node_base_interface());
|
||||
ASSERT_EQ(entities_collector_->get_all_callback_groups().size(), 1u);
|
||||
|
||||
node.reset();
|
||||
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
entities_collector_->remove_callback_group(cb_group),
|
||||
std::runtime_error("Node must not be deleted before its callback group(s)."));
|
||||
}
|
||||
|
||||
TEST_F(TestStaticExecutorEntitiesCollector, remove_callback_group_twice) {
|
||||
auto node = std::make_shared<rclcpp::Node>("node1", "ns");
|
||||
rclcpp::CallbackGroup::SharedPtr cb_group = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
|
||||
entities_collector_->add_callback_group(cb_group, node->get_node_base_interface());
|
||||
ASSERT_EQ(entities_collector_->get_all_callback_groups().size(), 1u);
|
||||
|
||||
entities_collector_->remove_callback_group(cb_group);
|
||||
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
entities_collector_->remove_callback_group(cb_group),
|
||||
std::runtime_error("Callback group needs to be associated with executor."));
|
||||
}
|
||||
|
||||
TEST_F(TestStaticExecutorEntitiesCollector, remove_node_opposite_order) {
|
||||
auto node1 = std::make_shared<rclcpp::Node>("node1", "ns");
|
||||
EXPECT_NO_THROW(entities_collector_->add_node(node1->get_node_base_interface()));
|
||||
|
||||
auto node2 = std::make_shared<rclcpp::Node>("node2", "ns");
|
||||
EXPECT_NO_THROW(entities_collector_->add_node(node2->get_node_base_interface()));
|
||||
|
||||
EXPECT_TRUE(entities_collector_->remove_node(node2->get_node_base_interface()));
|
||||
}
|
||||
|
||||
TEST_F(
|
||||
TestStaticExecutorEntitiesCollector,
|
||||
add_callback_groups_from_nodes_associated_to_executor_add) {
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
rclcpp::CallbackGroup::SharedPtr cb_group = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
|
||||
entities_collector_->add_callback_group(cb_group, node->get_node_base_interface());
|
||||
entities_collector_->add_node(node->get_node_base_interface());
|
||||
|
||||
rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator();
|
||||
auto shared_context = node->get_node_base_interface()->get_context();
|
||||
rcl_context_t * context = shared_context->get_rcl_context().get();
|
||||
EXPECT_EQ(
|
||||
RCL_RET_OK,
|
||||
rcl_wait_set_init(&wait_set, 100, 100, 100, 100, 100, 100, context, allocator));
|
||||
RCLCPP_SCOPE_EXIT({EXPECT_EQ(RCL_RET_OK, rcl_wait_set_fini(&wait_set));});
|
||||
|
||||
auto memory_strategy = rclcpp::memory_strategies::create_default_strategy();
|
||||
rclcpp::GuardCondition guard_condition(shared_context);
|
||||
rcl_guard_condition_t rcl_guard_condition = guard_condition.get_rcl_guard_condition();
|
||||
|
||||
entities_collector_->init(&wait_set, memory_strategy, &rcl_guard_condition);
|
||||
RCLCPP_SCOPE_EXIT(entities_collector_->fini());
|
||||
|
||||
cb_group->get_associated_with_executor_atomic().exchange(false);
|
||||
entities_collector_->execute();
|
||||
|
||||
EXPECT_TRUE(entities_collector_->remove_node(node->get_node_base_interface()));
|
||||
}
|
||||
|
||||
@@ -15,20 +15,13 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "rclcpp/exceptions.hpp"
|
||||
#include "rclcpp/node.hpp"
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
#include "rclcpp/executors.hpp"
|
||||
|
||||
#include "test_msgs/srv/empty.hpp"
|
||||
|
||||
#include "../../mocking_utils/patch.hpp"
|
||||
#include "../../utils/rclcpp_gtest_macros.hpp"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class TestStaticSingleThreadedExecutor : public ::testing::Test
|
||||
@@ -51,102 +44,5 @@ TEST_F(TestStaticSingleThreadedExecutor, check_unimplemented) {
|
||||
executor.add_node(node);
|
||||
|
||||
EXPECT_THROW(executor.spin_some(), rclcpp::exceptions::UnimplementedError);
|
||||
EXPECT_THROW(executor.spin_all(0ns), rclcpp::exceptions::UnimplementedError);
|
||||
EXPECT_THROW(executor.spin_once(0ns), rclcpp::exceptions::UnimplementedError);
|
||||
}
|
||||
|
||||
TEST_F(TestStaticSingleThreadedExecutor, add_callback_group_trigger_guard_failed) {
|
||||
rclcpp::executors::StaticSingleThreadedExecutor executor;
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
rclcpp::CallbackGroup::SharedPtr cb_group = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
|
||||
{
|
||||
auto mock = mocking_utils::patch_and_return(
|
||||
"lib:rclcpp", rcl_trigger_guard_condition, RCL_RET_ERROR);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
executor.add_callback_group(cb_group, node->get_node_base_interface(), true),
|
||||
std::runtime_error("error not set"));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(TestStaticSingleThreadedExecutor, add_node_trigger_guard_failed) {
|
||||
rclcpp::executors::StaticSingleThreadedExecutor executor;
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
|
||||
{
|
||||
auto mock = mocking_utils::patch_and_return(
|
||||
"lib:rclcpp", rcl_trigger_guard_condition, RCL_RET_ERROR);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
executor.add_node(node),
|
||||
std::runtime_error("error not set"));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(TestStaticSingleThreadedExecutor, remove_callback_group_trigger_guard_failed) {
|
||||
rclcpp::executors::StaticSingleThreadedExecutor executor;
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
rclcpp::CallbackGroup::SharedPtr cb_group = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
|
||||
executor.add_callback_group(cb_group, node->get_node_base_interface(), true);
|
||||
|
||||
{
|
||||
auto mock = mocking_utils::patch_and_return(
|
||||
"lib:rclcpp", rcl_trigger_guard_condition, RCL_RET_ERROR);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
executor.remove_callback_group(cb_group, true),
|
||||
std::runtime_error("error not set"));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(TestStaticSingleThreadedExecutor, remove_node_failed) {
|
||||
rclcpp::executors::StaticSingleThreadedExecutor executor;
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
|
||||
{
|
||||
auto mock = mocking_utils::patch_and_return(
|
||||
"lib:rclcpp", rcl_trigger_guard_condition, RCL_RET_ERROR);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
executor.remove_node(node, true),
|
||||
std::runtime_error("Node needs to be associated with this executor."));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(TestStaticSingleThreadedExecutor, remove_node_trigger_guard_failed) {
|
||||
rclcpp::executors::StaticSingleThreadedExecutor executor;
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
|
||||
executor.add_node(node);
|
||||
|
||||
{
|
||||
auto mock = mocking_utils::patch_and_return(
|
||||
"lib:rclcpp", rcl_trigger_guard_condition, RCL_RET_ERROR);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
executor.remove_node(node, true),
|
||||
std::runtime_error("error not set"));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(TestStaticSingleThreadedExecutor, execute_service) {
|
||||
rclcpp::executors::StaticSingleThreadedExecutor executor;
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
executor.add_node(node);
|
||||
|
||||
auto service =
|
||||
node->create_service<test_msgs::srv::Empty>(
|
||||
"service",
|
||||
[](
|
||||
const test_msgs::srv::Empty::Request::SharedPtr,
|
||||
test_msgs::srv::Empty::Response::SharedPtr) {});
|
||||
auto client = node->create_client<test_msgs::srv::Empty>("service");
|
||||
|
||||
std::promise<void> promise;
|
||||
std::future<void> future = promise.get_future();
|
||||
EXPECT_EQ(
|
||||
rclcpp::FutureReturnCode::TIMEOUT,
|
||||
executor.spin_until_future_complete(future, std::chrono::milliseconds(1)));
|
||||
|
||||
executor.remove_node(node);
|
||||
executor.spin_until_future_complete(future, std::chrono::milliseconds(1));
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ TEST_F(TestNodeGraph, construct_from_node)
|
||||
|
||||
// get_graph_event is non-const
|
||||
EXPECT_NE(nullptr, node()->get_node_graph_interface()->get_graph_event());
|
||||
EXPECT_EQ(1u, node_graph()->count_graph_users());
|
||||
EXPECT_EQ(1u, node()->get_node_graph_interface()->count_graph_users());
|
||||
}
|
||||
|
||||
TEST_F(TestNodeGraph, get_topic_names_and_types)
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "rcl/node_options.h"
|
||||
#include "rclcpp/node.hpp"
|
||||
@@ -56,9 +55,7 @@ public:
|
||||
{
|
||||
rclcpp::init(0, nullptr);
|
||||
|
||||
rclcpp::NodeOptions options{};
|
||||
options.arguments(std::vector<std::string>{"-r", "foo:=bar"});
|
||||
node = std::make_shared<rclcpp::Node>("node", "ns", options);
|
||||
node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
|
||||
// This dynamic cast is not necessary for the unittest itself, but instead is used to ensure
|
||||
// the proper type is being tested and covered.
|
||||
@@ -132,13 +129,3 @@ TEST_F(TestNodeService, add_client_rcl_trigger_guard_condition_error)
|
||||
node_services->add_client(client, callback_group),
|
||||
std::runtime_error("Failed to notify wait set on client creation: error not set"));
|
||||
}
|
||||
|
||||
TEST_F(TestNodeService, resolve_service_name)
|
||||
{
|
||||
EXPECT_EQ("/ns/bar", node_services->resolve_service_name("foo", false));
|
||||
EXPECT_EQ("/ns/foo", node_services->resolve_service_name("foo", true));
|
||||
EXPECT_EQ("/foo", node_services->resolve_service_name("/foo", true));
|
||||
EXPECT_THROW(
|
||||
node_services->resolve_service_name("this is not a valid name!~>", true),
|
||||
rclcpp::exceptions::RCLError);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "rcl/node_options.h"
|
||||
#include "rclcpp/node.hpp"
|
||||
@@ -81,9 +80,7 @@ public:
|
||||
void SetUp()
|
||||
{
|
||||
rclcpp::init(0, nullptr);
|
||||
rclcpp::NodeOptions options{};
|
||||
options.arguments(std::vector<std::string>{"-r", "foo:=bar"});
|
||||
node = std::make_shared<rclcpp::Node>("node", "ns", options);
|
||||
node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
|
||||
// This dynamic cast is not necessary for the unittest itself, but instead is used to ensure
|
||||
// the proper type is being tested and covered.
|
||||
@@ -157,13 +154,3 @@ TEST_F(TestNodeTopics, add_subscription_rcl_trigger_guard_condition_error)
|
||||
node_topics->add_subscription(subscription, callback_group),
|
||||
std::runtime_error("failed to notify wait set on subscription creation: error not set"));
|
||||
}
|
||||
|
||||
TEST_F(TestNodeTopics, resolve_topic_name)
|
||||
{
|
||||
EXPECT_EQ("/ns/bar", node_topics->resolve_topic_name("foo", false));
|
||||
EXPECT_EQ("/ns/foo", node_topics->resolve_topic_name("foo", true));
|
||||
EXPECT_EQ("/foo", node_topics->resolve_topic_name("/foo", true));
|
||||
EXPECT_THROW(
|
||||
node_topics->resolve_topic_name("this is not a valid name!~>", true),
|
||||
rclcpp::exceptions::RCLError);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -27,9 +26,7 @@
|
||||
#include "test_msgs/srv/empty.hpp"
|
||||
|
||||
using rclcpp::memory_strategies::allocator_memory_strategy::AllocatorMemoryStrategy;
|
||||
typedef std::map<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr,
|
||||
std::owner_less<rclcpp::CallbackGroup::WeakPtr>> WeakCallbackGroupsToNodesMap;
|
||||
using WeakNodeList = std::list<rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>;
|
||||
|
||||
static bool test_waitable_result = false;
|
||||
|
||||
@@ -191,19 +188,10 @@ protected:
|
||||
std::shared_ptr<rclcpp::Node> node,
|
||||
const RclWaitSetSizes & expected)
|
||||
{
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
auto callback_groups = node->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes,
|
||||
&node](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node->get_node_base_interface()));
|
||||
});
|
||||
allocator_memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
WeakNodeList nodes;
|
||||
nodes.push_back(node->get_node_base_interface());
|
||||
|
||||
allocator_memory_strategy()->collect_entities(nodes);
|
||||
EXPECT_EQ(
|
||||
expected.size_of_subscriptions, allocator_memory_strategy()->number_of_ready_subscriptions());
|
||||
EXPECT_EQ(
|
||||
@@ -224,19 +212,9 @@ protected:
|
||||
std::shared_ptr<rclcpp::Node> node,
|
||||
const RclWaitSetSizes & insufficient_capacities)
|
||||
{
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
auto callback_groups = node->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes,
|
||||
&node](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node->get_node_base_interface()));
|
||||
});
|
||||
allocator_memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
WeakNodeList nodes;
|
||||
nodes.push_back(node->get_node_base_interface());
|
||||
allocator_memory_strategy()->collect_entities(nodes);
|
||||
|
||||
auto context = node->get_node_base_interface()->get_context();
|
||||
rcl_context_t * rcl_context = context->get_rcl_context().get();
|
||||
@@ -303,65 +281,26 @@ protected:
|
||||
::testing::AssertionResult TestGetNextEntity(
|
||||
std::shared_ptr<rclcpp::Node> node_with_entity1,
|
||||
std::shared_ptr<rclcpp::Node> node_with_entity2,
|
||||
std::function<rclcpp::AnyExecutable(WeakCallbackGroupsToNodesMap)> get_next_entity_func)
|
||||
std::function<rclcpp::AnyExecutable(WeakNodeList)> get_next_entity_func)
|
||||
{
|
||||
auto basic_node = create_node_with_disabled_callback_groups("basic_node");
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
auto callback_groups = basic_node->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes,
|
||||
&basic_node](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
basic_node->get_node_base_interface()));
|
||||
});
|
||||
auto callback_groups1 = node_with_entity1->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups1.begin(), callback_groups1.end(),
|
||||
[&weak_groups_to_nodes,
|
||||
&node_with_entity1](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node_with_entity1->get_node_base_interface()));
|
||||
});
|
||||
allocator_memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
WeakNodeList nodes;
|
||||
auto basic_node = std::make_shared<rclcpp::Node>("basic_node", "ns");
|
||||
nodes.push_back(node_with_entity1->get_node_base_interface());
|
||||
nodes.push_back(basic_node->get_node_base_interface());
|
||||
allocator_memory_strategy()->collect_entities(nodes);
|
||||
|
||||
rclcpp::AnyExecutable result = get_next_entity_func(weak_groups_to_nodes);
|
||||
rclcpp::AnyExecutable result = get_next_entity_func(nodes);
|
||||
if (result.node_base != node_with_entity1->get_node_base_interface()) {
|
||||
return ::testing::AssertionFailure() <<
|
||||
"Failed to get expected entity with specified get_next_*() function";
|
||||
}
|
||||
|
||||
WeakNodeList uncollected_nodes;
|
||||
auto basic_node2 = std::make_shared<rclcpp::Node>("basic_node2", "ns");
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_uncollected_nodes;
|
||||
auto callback_groups2 = basic_node2->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups2.begin(), callback_groups2.end(),
|
||||
[&weak_groups_to_uncollected_nodes,
|
||||
&basic_node2](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_uncollected_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
basic_node2->get_node_base_interface()));
|
||||
});
|
||||
auto callback_groups3 = node_with_entity2->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups3.begin(), callback_groups3.end(),
|
||||
[&weak_groups_to_uncollected_nodes,
|
||||
&node_with_entity2](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_uncollected_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node_with_entity2->get_node_base_interface()));
|
||||
});
|
||||
rclcpp::AnyExecutable failed_result = get_next_entity_func(weak_groups_to_uncollected_nodes);
|
||||
uncollected_nodes.push_back(node_with_entity2->get_node_base_interface());
|
||||
uncollected_nodes.push_back(basic_node2->get_node_base_interface());
|
||||
|
||||
rclcpp::AnyExecutable failed_result = get_next_entity_func(uncollected_nodes);
|
||||
if (nullptr != failed_result.node_base) {
|
||||
return ::testing::AssertionFailure() <<
|
||||
"A node was retrieved with the specified get_next_*() function despite"
|
||||
@@ -373,33 +312,16 @@ protected:
|
||||
|
||||
::testing::AssertionResult TestGetNextEntityMutuallyExclusive(
|
||||
std::shared_ptr<rclcpp::Node> node_with_entity,
|
||||
std::function<rclcpp::AnyExecutable(WeakCallbackGroupsToNodesMap)> get_next_entity_func)
|
||||
std::function<rclcpp::AnyExecutable(WeakNodeList)> get_next_entity_func)
|
||||
{
|
||||
WeakNodeList nodes;
|
||||
auto basic_node = std::make_shared<rclcpp::Node>("basic_node", "ns");
|
||||
auto basic_node_base = basic_node->get_node_base_interface();
|
||||
|
||||
auto node_base = node_with_entity->get_node_base_interface();
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
auto callback_groups = basic_node_base->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes, &basic_node_base](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
basic_node_base));
|
||||
});
|
||||
callback_groups = node_base->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes, &node_base](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node_base));
|
||||
});
|
||||
allocator_memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
auto basic_node_base = basic_node->get_node_base_interface();
|
||||
nodes.push_back(node_base);
|
||||
nodes.push_back(basic_node_base);
|
||||
allocator_memory_strategy()->collect_entities(nodes);
|
||||
|
||||
// It's important that these be set after collect_entities() otherwise collect_entities() will
|
||||
// not do anything
|
||||
@@ -409,7 +331,7 @@ protected:
|
||||
callback_group->can_be_taken_from() = false;
|
||||
}
|
||||
|
||||
rclcpp::AnyExecutable result = get_next_entity_func(weak_groups_to_nodes);
|
||||
rclcpp::AnyExecutable result = get_next_entity_func(nodes);
|
||||
|
||||
if (nullptr != result.node_base) {
|
||||
return ::testing::AssertionFailure() <<
|
||||
@@ -436,19 +358,10 @@ private:
|
||||
};
|
||||
|
||||
TEST_F(TestAllocatorMemoryStrategy, construct_destruct) {
|
||||
WeakNodeList nodes;
|
||||
auto basic_node = create_node_with_disabled_callback_groups("basic_node");
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
auto callback_groups = basic_node->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes, &basic_node](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
basic_node->get_node_base_interface()));
|
||||
});
|
||||
allocator_memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
nodes.push_back(basic_node->get_node_base_interface());
|
||||
allocator_memory_strategy()->collect_entities(nodes);
|
||||
EXPECT_EQ(0u, allocator_memory_strategy()->number_of_ready_subscriptions());
|
||||
EXPECT_EQ(0u, allocator_memory_strategy()->number_of_ready_services());
|
||||
EXPECT_EQ(0u, allocator_memory_strategy()->number_of_ready_events());
|
||||
@@ -536,18 +449,9 @@ TEST_F(TestAllocatorMemoryStrategy, number_of_entities_with_timer) {
|
||||
|
||||
TEST_F(TestAllocatorMemoryStrategy, add_handles_to_wait_set_bad_arguments) {
|
||||
auto node = create_node_with_subscription("subscription_node");
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
auto callback_groups = node->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes, &node](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node->get_node_base_interface()));
|
||||
});
|
||||
allocator_memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
WeakNodeList nodes;
|
||||
nodes.push_back(node->get_node_base_interface());
|
||||
allocator_memory_strategy()->collect_entities(nodes);
|
||||
EXPECT_FALSE(allocator_memory_strategy()->add_handles_to_wait_set(nullptr));
|
||||
EXPECT_TRUE(rcl_error_is_set());
|
||||
rcl_reset_error();
|
||||
@@ -624,9 +528,9 @@ TEST_F(TestAllocatorMemoryStrategy, get_next_subscription) {
|
||||
auto node1 = create_node_with_subscription("node1");
|
||||
auto node2 = create_node_with_subscription("node2");
|
||||
|
||||
auto get_next_entity = [this](const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) {
|
||||
auto get_next_entity = [this](const WeakNodeList & nodes) {
|
||||
rclcpp::AnyExecutable result;
|
||||
allocator_memory_strategy()->get_next_subscription(result, weak_groups_to_nodes);
|
||||
allocator_memory_strategy()->get_next_subscription(result, nodes);
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -637,9 +541,9 @@ TEST_F(TestAllocatorMemoryStrategy, get_next_service) {
|
||||
auto node1 = create_node_with_service("node1");
|
||||
auto node2 = create_node_with_service("node2");
|
||||
|
||||
auto get_next_entity = [this](const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) {
|
||||
auto get_next_entity = [this](const WeakNodeList & nodes) {
|
||||
rclcpp::AnyExecutable result;
|
||||
allocator_memory_strategy()->get_next_service(result, weak_groups_to_nodes);
|
||||
allocator_memory_strategy()->get_next_service(result, nodes);
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -650,9 +554,9 @@ TEST_F(TestAllocatorMemoryStrategy, get_next_client) {
|
||||
auto node1 = create_node_with_client("node1");
|
||||
auto node2 = create_node_with_client("node2");
|
||||
|
||||
auto get_next_entity = [this](const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) {
|
||||
auto get_next_entity = [this](const WeakNodeList & nodes) {
|
||||
rclcpp::AnyExecutable result;
|
||||
allocator_memory_strategy()->get_next_client(result, weak_groups_to_nodes);
|
||||
allocator_memory_strategy()->get_next_client(result, nodes);
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -663,9 +567,9 @@ TEST_F(TestAllocatorMemoryStrategy, get_next_timer) {
|
||||
auto node1 = create_node_with_timer("node1");
|
||||
auto node2 = create_node_with_timer("node2");
|
||||
|
||||
auto get_next_entity = [this](const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) {
|
||||
auto get_next_entity = [this](const WeakNodeList & nodes) {
|
||||
rclcpp::AnyExecutable result;
|
||||
allocator_memory_strategy()->get_next_timer(result, weak_groups_to_nodes);
|
||||
allocator_memory_strategy()->get_next_timer(result, nodes);
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -680,9 +584,9 @@ TEST_F(TestAllocatorMemoryStrategy, get_next_waitable) {
|
||||
node1->get_node_waitables_interface()->add_waitable(waitable1, nullptr);
|
||||
node2->get_node_waitables_interface()->add_waitable(waitable2, nullptr);
|
||||
|
||||
auto get_next_entity = [this](const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) {
|
||||
auto get_next_entity = [this](const WeakNodeList & nodes) {
|
||||
rclcpp::AnyExecutable result;
|
||||
allocator_memory_strategy()->get_next_waitable(result, weak_groups_to_nodes);
|
||||
allocator_memory_strategy()->get_next_waitable(result, nodes);
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -692,9 +596,9 @@ TEST_F(TestAllocatorMemoryStrategy, get_next_waitable) {
|
||||
TEST_F(TestAllocatorMemoryStrategy, get_next_subscription_mutually_exclusive) {
|
||||
auto node = create_node_with_subscription("node");
|
||||
|
||||
auto get_next_entity = [this](const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) {
|
||||
auto get_next_entity = [this](const WeakNodeList & nodes) {
|
||||
rclcpp::AnyExecutable result;
|
||||
allocator_memory_strategy()->get_next_subscription(result, weak_groups_to_nodes);
|
||||
allocator_memory_strategy()->get_next_subscription(result, nodes);
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -704,9 +608,9 @@ TEST_F(TestAllocatorMemoryStrategy, get_next_subscription_mutually_exclusive) {
|
||||
TEST_F(TestAllocatorMemoryStrategy, get_next_service_mutually_exclusive) {
|
||||
auto node = create_node_with_service("node");
|
||||
|
||||
auto get_next_entity = [this](const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) {
|
||||
auto get_next_entity = [this](const WeakNodeList & nodes) {
|
||||
rclcpp::AnyExecutable result;
|
||||
allocator_memory_strategy()->get_next_service(result, weak_groups_to_nodes);
|
||||
allocator_memory_strategy()->get_next_service(result, nodes);
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -716,9 +620,9 @@ TEST_F(TestAllocatorMemoryStrategy, get_next_service_mutually_exclusive) {
|
||||
TEST_F(TestAllocatorMemoryStrategy, get_next_client_mutually_exclusive) {
|
||||
auto node = create_node_with_client("node");
|
||||
|
||||
auto get_next_entity = [this](const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) {
|
||||
auto get_next_entity = [this](const WeakNodeList & nodes) {
|
||||
rclcpp::AnyExecutable result;
|
||||
allocator_memory_strategy()->get_next_client(result, weak_groups_to_nodes);
|
||||
allocator_memory_strategy()->get_next_client(result, nodes);
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -728,9 +632,9 @@ TEST_F(TestAllocatorMemoryStrategy, get_next_client_mutually_exclusive) {
|
||||
TEST_F(TestAllocatorMemoryStrategy, get_next_timer_mutually_exclusive) {
|
||||
auto node = create_node_with_timer("node");
|
||||
|
||||
auto get_next_entity = [this](const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) {
|
||||
auto get_next_entity = [this](const WeakNodeList & nodes) {
|
||||
rclcpp::AnyExecutable result;
|
||||
allocator_memory_strategy()->get_next_timer(result, weak_groups_to_nodes);
|
||||
allocator_memory_strategy()->get_next_timer(result, nodes);
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -744,14 +648,13 @@ TEST_F(TestAllocatorMemoryStrategy, get_next_waitable_mutually_exclusive) {
|
||||
node->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
node->get_node_waitables_interface()->add_waitable(waitable, callback_group);
|
||||
|
||||
auto get_next_entity =
|
||||
[this, callback_group](const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) {
|
||||
auto get_next_entity = [this, callback_group](const WeakNodeList & nodes) {
|
||||
// This callback group isn't in the base class' callback_group list, so this needs to be done
|
||||
// before get_next_waitable() is called.
|
||||
callback_group->can_be_taken_from() = false;
|
||||
|
||||
rclcpp::AnyExecutable result;
|
||||
allocator_memory_strategy()->get_next_waitable(result, weak_groups_to_nodes);
|
||||
allocator_memory_strategy()->get_next_waitable(result, nodes);
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -759,8 +662,9 @@ TEST_F(TestAllocatorMemoryStrategy, get_next_waitable_mutually_exclusive) {
|
||||
}
|
||||
|
||||
TEST_F(TestAllocatorMemoryStrategy, get_next_subscription_out_of_scope) {
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
WeakNodeList nodes;
|
||||
auto node = create_node_with_disabled_callback_groups("node");
|
||||
nodes.push_back(node->get_node_base_interface());
|
||||
// Force subscription to go out of scope and cleanup after collecting entities.
|
||||
{
|
||||
rclcpp::SubscriptionOptions subscription_options;
|
||||
@@ -778,28 +682,19 @@ TEST_F(TestAllocatorMemoryStrategy, get_next_subscription_out_of_scope) {
|
||||
test_msgs::msg::Empty, decltype(subscription_callback)>(
|
||||
"topic", qos, std::move(subscription_callback), subscription_options);
|
||||
|
||||
auto callback_groups = node->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes, &node](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node->get_node_base_interface()));
|
||||
});
|
||||
allocator_memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
allocator_memory_strategy()->collect_entities(nodes);
|
||||
}
|
||||
EXPECT_EQ(1u, allocator_memory_strategy()->number_of_ready_subscriptions());
|
||||
|
||||
rclcpp::AnyExecutable result;
|
||||
allocator_memory_strategy()->get_next_subscription(result, weak_groups_to_nodes);
|
||||
allocator_memory_strategy()->get_next_subscription(result, nodes);
|
||||
EXPECT_EQ(nullptr, result.node_base);
|
||||
}
|
||||
|
||||
TEST_F(TestAllocatorMemoryStrategy, get_next_service_out_of_scope) {
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
WeakNodeList nodes;
|
||||
auto node = create_node_with_disabled_callback_groups("node");
|
||||
nodes.push_back(node->get_node_base_interface());
|
||||
// Force service to go out of scope and cleanup after collecting entities.
|
||||
{
|
||||
auto callback_group =
|
||||
@@ -812,38 +707,19 @@ TEST_F(TestAllocatorMemoryStrategy, get_next_service_out_of_scope) {
|
||||
auto service = node->create_service<test_msgs::srv::Empty>(
|
||||
"service", std::move(service_callback), rmw_qos_profile_services_default, callback_group);
|
||||
|
||||
auto callback_groups = node->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes, &node](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node->get_node_base_interface()));
|
||||
});
|
||||
allocator_memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
allocator_memory_strategy()->collect_entities(nodes);
|
||||
}
|
||||
EXPECT_EQ(1u, allocator_memory_strategy()->number_of_ready_services());
|
||||
|
||||
rclcpp::AnyExecutable result;
|
||||
allocator_memory_strategy()->get_next_service(result, weak_groups_to_nodes);
|
||||
allocator_memory_strategy()->get_next_service(result, nodes);
|
||||
EXPECT_EQ(nullptr, result.node_base);
|
||||
}
|
||||
|
||||
TEST_F(TestAllocatorMemoryStrategy, get_next_client_out_of_scope) {
|
||||
WeakNodeList nodes;
|
||||
auto node = create_node_with_disabled_callback_groups("node");
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
auto callback_groups = node->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes, &node](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node->get_node_base_interface()));
|
||||
});
|
||||
nodes.push_back(node->get_node_base_interface());
|
||||
// Force client to go out of scope and cleanup after collecting entities.
|
||||
{
|
||||
auto callback_group =
|
||||
@@ -852,69 +728,49 @@ TEST_F(TestAllocatorMemoryStrategy, get_next_client_out_of_scope) {
|
||||
auto client = node->create_client<test_msgs::srv::Empty>(
|
||||
"service", rmw_qos_profile_services_default, callback_group);
|
||||
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
rclcpp::CallbackGroup::WeakPtr(callback_group),
|
||||
node->get_node_base_interface()));
|
||||
|
||||
allocator_memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
allocator_memory_strategy()->collect_entities(nodes);
|
||||
}
|
||||
EXPECT_EQ(1u, allocator_memory_strategy()->number_of_ready_clients());
|
||||
|
||||
rclcpp::AnyExecutable result;
|
||||
allocator_memory_strategy()->get_next_client(result, weak_groups_to_nodes);
|
||||
allocator_memory_strategy()->get_next_client(result, nodes);
|
||||
EXPECT_EQ(nullptr, result.node_base);
|
||||
}
|
||||
|
||||
TEST_F(TestAllocatorMemoryStrategy, get_next_timer_out_of_scope) {
|
||||
WeakNodeList nodes;
|
||||
auto node = create_node_with_disabled_callback_groups("node");
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
nodes.push_back(node->get_node_base_interface());
|
||||
|
||||
// Force timer to go out of scope and cleanup after collecting entities.
|
||||
{
|
||||
auto callback_group =
|
||||
node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
|
||||
auto timer = node->create_wall_timer(
|
||||
std::chrono::seconds(10), []() {}, callback_group);
|
||||
auto callback_groups = node->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes, &node](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node->get_node_base_interface()));
|
||||
});
|
||||
allocator_memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
|
||||
allocator_memory_strategy()->collect_entities(nodes);
|
||||
}
|
||||
EXPECT_EQ(1u, allocator_memory_strategy()->number_of_ready_timers());
|
||||
|
||||
rclcpp::AnyExecutable result;
|
||||
allocator_memory_strategy()->get_next_timer(result, weak_groups_to_nodes);
|
||||
allocator_memory_strategy()->get_next_timer(result, nodes);
|
||||
EXPECT_EQ(nullptr, result.node_base);
|
||||
}
|
||||
|
||||
TEST_F(TestAllocatorMemoryStrategy, get_next_waitable_out_of_scope) {
|
||||
WeakNodeList nodes;
|
||||
auto node = create_node_with_disabled_callback_groups("node");
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
nodes.push_back(node->get_node_base_interface());
|
||||
|
||||
// Force waitable to go out of scope and cleanup after collecting entities.
|
||||
{
|
||||
auto callback_group =
|
||||
node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
auto callback_groups = node->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes, &node](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node->get_node_base_interface()));
|
||||
});
|
||||
allocator_memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
allocator_memory_strategy()->collect_entities(nodes);
|
||||
auto waitable = std::make_shared<TestWaitable>();
|
||||
node->get_node_waitables_interface()->add_waitable(waitable, callback_group);
|
||||
allocator_memory_strategy()->add_waitable_handle(waitable);
|
||||
@@ -923,6 +779,6 @@ TEST_F(TestAllocatorMemoryStrategy, get_next_waitable_out_of_scope) {
|
||||
EXPECT_EQ(1u, allocator_memory_strategy()->number_of_waitables());
|
||||
|
||||
rclcpp::AnyExecutable result;
|
||||
allocator_memory_strategy()->get_next_waitable(result, weak_groups_to_nodes);
|
||||
allocator_memory_strategy()->get_next_waitable(result, nodes);
|
||||
EXPECT_EQ(nullptr, result.node_base);
|
||||
}
|
||||
|
||||
@@ -1,303 +0,0 @@
|
||||
// Copyright 2020 Open Source Robotics Foundation, Inc.
|
||||
//
|
||||
// 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 <gtest/gtest.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "rclcpp/node.hpp"
|
||||
#include "test_msgs/msg/empty.hpp"
|
||||
#include "test_msgs/msg/empty.h"
|
||||
|
||||
#include "rclcpp/exceptions.hpp"
|
||||
#include "rclcpp/executors.hpp"
|
||||
#include "rclcpp/executor.hpp"
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
|
||||
// Note: This is a long running test with rmw_connext_cpp, if you change this file, please check
|
||||
// that this test can complete fully, or adjust the timeout as necessary.
|
||||
// See https://github.com/ros2/rmw_connext/issues/325 for resolution]
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
template<typename T>
|
||||
class TestAddCallbackGroupsToExecutor : public ::testing::Test
|
||||
{
|
||||
public:
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
rclcpp::init(0, nullptr);
|
||||
}
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
rclcpp::shutdown();
|
||||
}
|
||||
};
|
||||
|
||||
using ExecutorTypes =
|
||||
::testing::Types<
|
||||
rclcpp::executors::SingleThreadedExecutor,
|
||||
rclcpp::executors::MultiThreadedExecutor,
|
||||
rclcpp::executors::StaticSingleThreadedExecutor>;
|
||||
|
||||
class ExecutorTypeNames
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
static std::string GetName(int idx)
|
||||
{
|
||||
(void)idx;
|
||||
if (std::is_same<T, rclcpp::executors::SingleThreadedExecutor>()) {
|
||||
return "SingleThreadedExecutor";
|
||||
}
|
||||
|
||||
if (std::is_same<T, rclcpp::executors::MultiThreadedExecutor>()) {
|
||||
return "MultiThreadedExecutor";
|
||||
}
|
||||
|
||||
if (std::is_same<T, rclcpp::executors::StaticSingleThreadedExecutor>()) {
|
||||
return "StaticSingleThreadedExecutor";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
TYPED_TEST_SUITE(TestAddCallbackGroupsToExecutor, ExecutorTypes, ExecutorTypeNames);
|
||||
|
||||
/*
|
||||
* Test adding callback groups.
|
||||
*/
|
||||
TYPED_TEST(TestAddCallbackGroupsToExecutor, add_callback_groups) {
|
||||
using ExecutorType = TypeParam;
|
||||
auto node = std::make_shared<rclcpp::Node>("my_node", "/ns");
|
||||
auto timer_callback = []() {};
|
||||
rclcpp::CallbackGroup::SharedPtr cb_grp = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
rclcpp::TimerBase::SharedPtr timer_ = node->create_wall_timer(
|
||||
2s, timer_callback, cb_grp);
|
||||
ExecutorType executor;
|
||||
executor.add_callback_group(cb_grp, node->get_node_base_interface());
|
||||
ASSERT_EQ(executor.get_all_callback_groups().size(), 1u);
|
||||
ASSERT_EQ(executor.get_manually_added_callback_groups().size(), 1u);
|
||||
ASSERT_EQ(executor.get_automatically_added_callback_groups_from_nodes().size(), 0u);
|
||||
|
||||
const rclcpp::QoS qos(10);
|
||||
auto options = rclcpp::SubscriptionOptions();
|
||||
auto callback = [](const test_msgs::msg::Empty::SharedPtr) {};
|
||||
rclcpp::CallbackGroup::SharedPtr cb_grp2 = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
options.callback_group = cb_grp2;
|
||||
auto subscription =
|
||||
node->create_subscription<test_msgs::msg::Empty>("topic_name", qos, callback, options);
|
||||
executor.add_callback_group(cb_grp2, node->get_node_base_interface());
|
||||
ASSERT_EQ(executor.get_all_callback_groups().size(), 2u);
|
||||
ASSERT_EQ(executor.get_manually_added_callback_groups().size(), 2u);
|
||||
ASSERT_EQ(executor.get_automatically_added_callback_groups_from_nodes().size(), 0u);
|
||||
|
||||
executor.add_node(node);
|
||||
ASSERT_EQ(executor.get_manually_added_callback_groups().size(), 2u);
|
||||
ASSERT_EQ(executor.get_automatically_added_callback_groups_from_nodes().size(), 1u);
|
||||
|
||||
executor.remove_node(node);
|
||||
ASSERT_EQ(executor.get_manually_added_callback_groups().size(), 2u);
|
||||
ASSERT_EQ(executor.get_automatically_added_callback_groups_from_nodes().size(), 0u);
|
||||
|
||||
executor.remove_callback_group(cb_grp);
|
||||
ASSERT_EQ(executor.get_manually_added_callback_groups().size(), 1u);
|
||||
ASSERT_EQ(executor.get_automatically_added_callback_groups_from_nodes().size(), 0u);
|
||||
|
||||
executor.remove_callback_group(cb_grp2);
|
||||
ASSERT_EQ(executor.get_manually_added_callback_groups().size(), 0u);
|
||||
ASSERT_EQ(executor.get_automatically_added_callback_groups_from_nodes().size(), 0u);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test removing callback groups.
|
||||
*/
|
||||
TYPED_TEST(TestAddCallbackGroupsToExecutor, remove_callback_groups) {
|
||||
using ExecutorType = TypeParam;
|
||||
auto node = std::make_shared<rclcpp::Node>("my_node", "/ns");
|
||||
auto timer_callback = []() {};
|
||||
rclcpp::CallbackGroup::SharedPtr cb_grp = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
rclcpp::TimerBase::SharedPtr timer_ = node->create_wall_timer(
|
||||
2s, timer_callback, cb_grp);
|
||||
ExecutorType executor;
|
||||
executor.add_callback_group(cb_grp, node->get_node_base_interface());
|
||||
const rclcpp::QoS qos(10);
|
||||
auto options = rclcpp::SubscriptionOptions();
|
||||
auto callback = [](const test_msgs::msg::Empty::SharedPtr) {};
|
||||
rclcpp::CallbackGroup::SharedPtr cb_grp2 = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
options.callback_group = cb_grp2;
|
||||
auto subscription =
|
||||
node->create_subscription<test_msgs::msg::Empty>("topic_name", qos, callback, options);
|
||||
executor.add_callback_group(cb_grp2, node->get_node_base_interface());
|
||||
|
||||
executor.remove_callback_group(cb_grp);
|
||||
ASSERT_EQ(executor.get_all_callback_groups().size(), 1u);
|
||||
executor.remove_callback_group(cb_grp2);
|
||||
ASSERT_EQ(executor.get_all_callback_groups().size(), 0u);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test adding duplicate callback groups to executor.
|
||||
*/
|
||||
TYPED_TEST(TestAddCallbackGroupsToExecutor, add_duplicate_callback_groups)
|
||||
{
|
||||
rclcpp::executors::MultiThreadedExecutor executor;
|
||||
auto node = std::make_shared<rclcpp::Node>("my_node", "/ns");
|
||||
auto timer_callback = []() {};
|
||||
rclcpp::CallbackGroup::SharedPtr cb_grp = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
rclcpp::TimerBase::SharedPtr timer_ = node->create_wall_timer(
|
||||
2s, timer_callback, cb_grp);
|
||||
executor.add_callback_group(cb_grp, node->get_node_base_interface());
|
||||
EXPECT_THROW(
|
||||
executor.add_callback_group(cb_grp, node->get_node_base_interface()),
|
||||
std::exception);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test adding callback group after node is added to executor.
|
||||
*/
|
||||
TYPED_TEST(TestAddCallbackGroupsToExecutor, add_callback_groups_after_add_node_to_executor)
|
||||
{
|
||||
rclcpp::executors::MultiThreadedExecutor executor;
|
||||
auto node = std::make_shared<rclcpp::Node>("my_node", "/ns");
|
||||
executor.add_node(node->get_node_base_interface());
|
||||
ASSERT_EQ(executor.get_all_callback_groups().size(), 1u);
|
||||
std::atomic_int timer_count {0};
|
||||
auto timer_callback = [&executor, &timer_count]() {
|
||||
if (timer_count > 0) {
|
||||
ASSERT_EQ(executor.get_all_callback_groups().size(), 3u);
|
||||
executor.cancel();
|
||||
}
|
||||
timer_count++;
|
||||
};
|
||||
rclcpp::CallbackGroup::SharedPtr cb_grp = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
rclcpp::TimerBase::SharedPtr timer_ = node->create_wall_timer(
|
||||
2s, timer_callback, cb_grp);
|
||||
rclcpp::CallbackGroup::SharedPtr cb_grp2 = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive, false);
|
||||
auto timer2_callback = []() {};
|
||||
rclcpp::TimerBase::SharedPtr timer2_ = node->create_wall_timer(
|
||||
2s, timer2_callback, cb_grp2);
|
||||
rclcpp::CallbackGroup::SharedPtr cb_grp3 = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive, true);
|
||||
auto timer3_callback = []() {};
|
||||
rclcpp::TimerBase::SharedPtr timer3_ = node->create_wall_timer(
|
||||
2s, timer3_callback, cb_grp3);
|
||||
executor.spin();
|
||||
}
|
||||
|
||||
/*
|
||||
* Test adding unallowable callback group.
|
||||
*/
|
||||
TYPED_TEST(TestAddCallbackGroupsToExecutor, add_unallowable_callback_groups)
|
||||
{
|
||||
auto node = std::make_shared<rclcpp::Node>("my_node", "/ns");
|
||||
auto timer_callback = []() {};
|
||||
rclcpp::CallbackGroup::SharedPtr cb_grp = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive, false);
|
||||
rclcpp::TimerBase::SharedPtr timer_ = node->create_wall_timer(
|
||||
2s, timer_callback, cb_grp);
|
||||
rclcpp::executors::MultiThreadedExecutor executor;
|
||||
executor.add_callback_group(cb_grp, node->get_node_base_interface());
|
||||
ASSERT_EQ(executor.get_all_callback_groups().size(), 1u);
|
||||
|
||||
const rclcpp::QoS qos(10);
|
||||
auto options = rclcpp::SubscriptionOptions();
|
||||
auto callback = [](const test_msgs::msg::Empty::SharedPtr) {};
|
||||
rclcpp::CallbackGroup::SharedPtr cb_grp2 = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive, false);
|
||||
options.callback_group = cb_grp2;
|
||||
auto subscription =
|
||||
node->create_subscription<test_msgs::msg::Empty>("topic_name", qos, callback, options);
|
||||
executor.add_callback_group(cb_grp2, node->get_node_base_interface());
|
||||
ASSERT_EQ(executor.get_all_callback_groups().size(), 2u);
|
||||
|
||||
auto timer2_callback = []() {};
|
||||
rclcpp::CallbackGroup::SharedPtr cb_grp3 = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive, false);
|
||||
rclcpp::TimerBase::SharedPtr timer2_ = node->create_wall_timer(
|
||||
2s, timer2_callback, cb_grp3);
|
||||
executor.add_node(node->get_node_base_interface());
|
||||
ASSERT_EQ(executor.get_all_callback_groups().size(), 3u);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test callback groups from one node to many executors.
|
||||
*/
|
||||
TYPED_TEST(TestAddCallbackGroupsToExecutor, one_node_many_callback_groups_many_executors)
|
||||
{
|
||||
auto node = std::make_shared<rclcpp::Node>("my_node", "/ns");
|
||||
auto timer_callback = []() {};
|
||||
rclcpp::CallbackGroup::SharedPtr cb_grp = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive, false);
|
||||
rclcpp::TimerBase::SharedPtr timer_ = node->create_wall_timer(
|
||||
2s, timer_callback, cb_grp);
|
||||
rclcpp::executors::MultiThreadedExecutor timer_executor;
|
||||
rclcpp::executors::MultiThreadedExecutor sub_executor;
|
||||
timer_executor.add_callback_group(cb_grp, node->get_node_base_interface());
|
||||
const rclcpp::QoS qos(10);
|
||||
auto options = rclcpp::SubscriptionOptions();
|
||||
auto callback = [](const test_msgs::msg::Empty::SharedPtr) {};
|
||||
rclcpp::CallbackGroup::SharedPtr cb_grp2 = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive, false);
|
||||
options.callback_group = cb_grp2;
|
||||
auto subscription =
|
||||
node->create_subscription<test_msgs::msg::Empty>("topic_name", qos, callback, options);
|
||||
sub_executor.add_callback_group(cb_grp2, node->get_node_base_interface());
|
||||
ASSERT_EQ(sub_executor.get_all_callback_groups().size(), 1u);
|
||||
ASSERT_EQ(timer_executor.get_all_callback_groups().size(), 1u);
|
||||
auto timer2_callback = []() {};
|
||||
rclcpp::CallbackGroup::SharedPtr cb_grp3 = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive, false);
|
||||
rclcpp::TimerBase::SharedPtr timer2 = node->create_wall_timer(
|
||||
2s, timer2_callback, cb_grp3);
|
||||
sub_executor.add_node(node);
|
||||
ASSERT_EQ(sub_executor.get_all_callback_groups().size(), 2u);
|
||||
timer_executor.add_callback_group(cb_grp3, node->get_node_base_interface());
|
||||
ASSERT_EQ(timer_executor.get_all_callback_groups().size(), 2u);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test removing callback group from executor that its not associated with.
|
||||
*/
|
||||
TYPED_TEST(TestAddCallbackGroupsToExecutor, remove_callback_group)
|
||||
{
|
||||
rclcpp::executors::MultiThreadedExecutor executor;
|
||||
auto node = std::make_shared<rclcpp::Node>("my_node", "/ns");
|
||||
auto timer_callback = []() {};
|
||||
rclcpp::CallbackGroup::SharedPtr cb_grp = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
rclcpp::TimerBase::SharedPtr timer_ = node->create_wall_timer(
|
||||
2s, timer_callback, cb_grp);
|
||||
EXPECT_THROW(
|
||||
executor.remove_callback_group(cb_grp),
|
||||
std::exception);
|
||||
executor.add_callback_group(cb_grp, node->get_node_base_interface());
|
||||
EXPECT_NO_THROW(executor.remove_callback_group(cb_grp));
|
||||
EXPECT_THROW(
|
||||
executor.remove_callback_group(cb_grp),
|
||||
std::exception);
|
||||
}
|
||||
@@ -68,7 +68,7 @@ TEST_F(TestDuration, operators) {
|
||||
TEST_F(TestDuration, chrono_overloads) {
|
||||
int64_t ns = 123456789l;
|
||||
auto chrono_ns = std::chrono::nanoseconds(ns);
|
||||
auto d1 = rclcpp::Duration::from_nanoseconds(ns);
|
||||
auto d1 = rclcpp::Duration(ns);
|
||||
auto d2 = rclcpp::Duration(chrono_ns);
|
||||
auto d3 = rclcpp::Duration(123456789ns);
|
||||
EXPECT_EQ(d1, d2);
|
||||
@@ -85,11 +85,11 @@ TEST_F(TestDuration, chrono_overloads) {
|
||||
}
|
||||
|
||||
TEST_F(TestDuration, overflows) {
|
||||
auto max = rclcpp::Duration::from_nanoseconds(std::numeric_limits<rcl_duration_value_t>::max());
|
||||
auto min = rclcpp::Duration::from_nanoseconds(std::numeric_limits<rcl_duration_value_t>::min());
|
||||
rclcpp::Duration max(std::numeric_limits<rcl_duration_value_t>::max());
|
||||
rclcpp::Duration min(std::numeric_limits<rcl_duration_value_t>::min());
|
||||
|
||||
rclcpp::Duration one(1ns);
|
||||
rclcpp::Duration negative_one(-1ns);
|
||||
rclcpp::Duration one(1);
|
||||
rclcpp::Duration negative_one(-1);
|
||||
|
||||
EXPECT_THROW(max + one, std::overflow_error);
|
||||
EXPECT_THROW(min - one, std::underflow_error);
|
||||
@@ -106,7 +106,7 @@ TEST_F(TestDuration, overflows) {
|
||||
}
|
||||
|
||||
TEST_F(TestDuration, negative_duration) {
|
||||
rclcpp::Duration assignable_duration = rclcpp::Duration(0ns) - rclcpp::Duration(5, 0);
|
||||
rclcpp::Duration assignable_duration = rclcpp::Duration(0) - rclcpp::Duration(5, 0);
|
||||
|
||||
{
|
||||
// avoid windows converting a literal number less than -INT_MAX to unsigned int C4146
|
||||
@@ -140,24 +140,22 @@ static const int64_t ONE_SEC_IN_NS = 1000 * 1000 * 1000;
|
||||
static const int64_t ONE_AND_HALF_SEC_IN_NS = 3 * HALF_SEC_IN_NS;
|
||||
|
||||
TEST_F(TestDuration, from_seconds) {
|
||||
EXPECT_EQ(rclcpp::Duration(0ns), rclcpp::Duration::from_seconds(0.0));
|
||||
EXPECT_EQ(rclcpp::Duration(0ns), rclcpp::Duration::from_seconds(0));
|
||||
EXPECT_EQ(rclcpp::Duration(0), rclcpp::Duration::from_seconds(0.0));
|
||||
EXPECT_EQ(rclcpp::Duration(0), rclcpp::Duration::from_seconds(0));
|
||||
EXPECT_EQ(rclcpp::Duration(1, HALF_SEC_IN_NS), rclcpp::Duration::from_seconds(1.5));
|
||||
EXPECT_EQ(
|
||||
rclcpp::Duration::from_nanoseconds(-ONE_AND_HALF_SEC_IN_NS),
|
||||
rclcpp::Duration::from_seconds(-1.5));
|
||||
EXPECT_EQ(rclcpp::Duration(-ONE_AND_HALF_SEC_IN_NS), rclcpp::Duration::from_seconds(-1.5));
|
||||
}
|
||||
|
||||
TEST_F(TestDuration, std_chrono_constructors) {
|
||||
EXPECT_EQ(rclcpp::Duration(0ns), rclcpp::Duration(0.0s));
|
||||
EXPECT_EQ(rclcpp::Duration(0ns), rclcpp::Duration(0s));
|
||||
EXPECT_EQ(rclcpp::Duration(0), rclcpp::Duration(0.0s));
|
||||
EXPECT_EQ(rclcpp::Duration(0), rclcpp::Duration(0s));
|
||||
EXPECT_EQ(rclcpp::Duration(1, HALF_SEC_IN_NS), rclcpp::Duration(1.5s));
|
||||
EXPECT_EQ(rclcpp::Duration(-1, 0), rclcpp::Duration(-1s));
|
||||
}
|
||||
|
||||
TEST_F(TestDuration, conversions) {
|
||||
{
|
||||
auto duration = rclcpp::Duration::from_nanoseconds(HALF_SEC_IN_NS);
|
||||
const rclcpp::Duration duration(HALF_SEC_IN_NS);
|
||||
const auto duration_msg = static_cast<builtin_interfaces::msg::Duration>(duration);
|
||||
EXPECT_EQ(duration_msg.sec, 0);
|
||||
EXPECT_EQ(duration_msg.nanosec, HALF_SEC_IN_NS);
|
||||
@@ -172,7 +170,7 @@ TEST_F(TestDuration, conversions) {
|
||||
}
|
||||
|
||||
{
|
||||
auto duration = rclcpp::Duration::from_nanoseconds(ONE_SEC_IN_NS);
|
||||
const rclcpp::Duration duration(ONE_SEC_IN_NS);
|
||||
const auto duration_msg = static_cast<builtin_interfaces::msg::Duration>(duration);
|
||||
EXPECT_EQ(duration_msg.sec, 1);
|
||||
EXPECT_EQ(duration_msg.nanosec, 0u);
|
||||
@@ -187,7 +185,7 @@ TEST_F(TestDuration, conversions) {
|
||||
}
|
||||
|
||||
{
|
||||
auto duration = rclcpp::Duration::from_nanoseconds(ONE_AND_HALF_SEC_IN_NS);
|
||||
const rclcpp::Duration duration(ONE_AND_HALF_SEC_IN_NS);
|
||||
auto duration_msg = static_cast<builtin_interfaces::msg::Duration>(duration);
|
||||
EXPECT_EQ(duration_msg.sec, 1);
|
||||
EXPECT_EQ(duration_msg.nanosec, HALF_SEC_IN_NS);
|
||||
@@ -202,7 +200,7 @@ TEST_F(TestDuration, conversions) {
|
||||
}
|
||||
|
||||
{
|
||||
auto duration = rclcpp::Duration::from_nanoseconds(-HALF_SEC_IN_NS);
|
||||
rclcpp::Duration duration(-HALF_SEC_IN_NS);
|
||||
auto duration_msg = static_cast<builtin_interfaces::msg::Duration>(duration);
|
||||
EXPECT_EQ(duration_msg.sec, -1);
|
||||
EXPECT_EQ(duration_msg.nanosec, HALF_SEC_IN_NS);
|
||||
@@ -215,7 +213,7 @@ TEST_F(TestDuration, conversions) {
|
||||
}
|
||||
|
||||
{
|
||||
auto duration = rclcpp::Duration::from_nanoseconds(-ONE_SEC_IN_NS);
|
||||
rclcpp::Duration duration(-ONE_SEC_IN_NS);
|
||||
auto duration_msg = static_cast<builtin_interfaces::msg::Duration>(duration);
|
||||
EXPECT_EQ(duration_msg.sec, -1);
|
||||
EXPECT_EQ(duration_msg.nanosec, 0u);
|
||||
@@ -228,7 +226,7 @@ TEST_F(TestDuration, conversions) {
|
||||
}
|
||||
|
||||
{
|
||||
auto duration = rclcpp::Duration::from_nanoseconds(-ONE_AND_HALF_SEC_IN_NS);
|
||||
rclcpp::Duration duration(-ONE_AND_HALF_SEC_IN_NS);
|
||||
auto duration_msg = static_cast<builtin_interfaces::msg::Duration>(duration);
|
||||
EXPECT_EQ(duration_msg.sec, -2);
|
||||
EXPECT_EQ(duration_msg.nanosec, HALF_SEC_IN_NS);
|
||||
@@ -255,10 +253,9 @@ TEST_F(TestDuration, test_some_constructors) {
|
||||
}
|
||||
|
||||
TEST_F(TestDuration, test_some_exceptions) {
|
||||
rclcpp::Duration test_duration(0ns);
|
||||
rclcpp::Duration test_duration(0u);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
test_duration =
|
||||
rclcpp::Duration::from_nanoseconds(INT64_MAX) - rclcpp::Duration(-1ns),
|
||||
test_duration = rclcpp::Duration(INT64_MAX) - rclcpp::Duration(-1),
|
||||
std::overflow_error("duration subtraction leads to int64_t overflow"));
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
test_duration = test_duration * (std::numeric_limits<double>::infinity()),
|
||||
|
||||
@@ -51,12 +51,6 @@ public:
|
||||
return memory_strategy_.get();
|
||||
}
|
||||
|
||||
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr local_get_node_by_group(
|
||||
rclcpp::CallbackGroup::SharedPtr group)
|
||||
{
|
||||
return get_node_by_group(weak_groups_to_nodes_, group);
|
||||
}
|
||||
|
||||
rclcpp::CallbackGroup::SharedPtr local_get_group_by_timer(rclcpp::TimerBase::SharedPtr timer)
|
||||
{
|
||||
return get_group_by_timer(timer);
|
||||
@@ -103,87 +97,6 @@ TEST_F(TestExecutor, constructor_bad_wait_set_init) {
|
||||
std::runtime_error("Failed to create wait set in Executor constructor: error not set"));
|
||||
}
|
||||
|
||||
TEST_F(TestExecutor, add_callback_group_twice) {
|
||||
DummyExecutor dummy;
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
rclcpp::CallbackGroup::SharedPtr cb_group = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
dummy.add_callback_group(cb_group, node->get_node_base_interface(), false);
|
||||
cb_group->get_associated_with_executor_atomic().exchange(false);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
dummy.add_callback_group(cb_group, node->get_node_base_interface(), false),
|
||||
std::runtime_error("Callback group was already added to executor."));
|
||||
}
|
||||
|
||||
TEST_F(TestExecutor, add_callback_group_failed_trigger_guard_condition) {
|
||||
DummyExecutor dummy;
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
rclcpp::CallbackGroup::SharedPtr cb_group = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
|
||||
auto mock = mocking_utils::patch_and_return(
|
||||
"lib:rclcpp", rcl_trigger_guard_condition, RCL_RET_ERROR);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
dummy.add_callback_group(cb_group, node->get_node_base_interface(), true),
|
||||
std::runtime_error("Failed to trigger guard condition on callback group add: error not set"));
|
||||
}
|
||||
|
||||
TEST_F(TestExecutor, remove_callback_group_null_node) {
|
||||
DummyExecutor dummy;
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
rclcpp::CallbackGroup::SharedPtr cb_group = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
|
||||
dummy.add_callback_group(cb_group, node->get_node_base_interface(), true);
|
||||
|
||||
node.reset();
|
||||
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
dummy.remove_callback_group(cb_group, false),
|
||||
std::runtime_error("Node must not be deleted before its callback group(s)."));
|
||||
}
|
||||
|
||||
TEST_F(TestExecutor, remove_callback_group_failed_trigger_guard_condition) {
|
||||
DummyExecutor dummy;
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
rclcpp::CallbackGroup::SharedPtr cb_group = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
|
||||
dummy.add_callback_group(cb_group, node->get_node_base_interface(), true);
|
||||
|
||||
auto mock = mocking_utils::patch_and_return(
|
||||
"lib:rclcpp", rcl_trigger_guard_condition, RCL_RET_ERROR);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
dummy.remove_callback_group(cb_group, true),
|
||||
std::runtime_error(
|
||||
"Failed to trigger guard condition on callback group remove: error not set"));
|
||||
}
|
||||
|
||||
TEST_F(TestExecutor, remove_node_not_associated) {
|
||||
DummyExecutor dummy;
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
rclcpp::CallbackGroup::SharedPtr cb_group = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
dummy.remove_node(node->get_node_base_interface(), false),
|
||||
std::runtime_error("Node needs to be associated with an executor."));
|
||||
}
|
||||
|
||||
TEST_F(TestExecutor, remove_node_associated_with_different_executor) {
|
||||
DummyExecutor dummy1;
|
||||
auto node1 = std::make_shared<rclcpp::Node>("node1", "ns");
|
||||
dummy1.add_node(node1->get_node_base_interface(), false);
|
||||
|
||||
DummyExecutor dummy2;
|
||||
auto node2 = std::make_shared<rclcpp::Node>("node2", "ns");
|
||||
dummy2.add_node(node2->get_node_base_interface(), false);
|
||||
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
dummy2.remove_node(node1->get_node_base_interface(), false),
|
||||
std::runtime_error("Node needs to be associated with this executor."));
|
||||
}
|
||||
|
||||
TEST_F(TestExecutor, spin_node_once_nanoseconds) {
|
||||
DummyExecutor dummy;
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
@@ -212,15 +125,6 @@ TEST_F(TestExecutor, spin_node_some) {
|
||||
EXPECT_TRUE(timer_fired);
|
||||
}
|
||||
|
||||
TEST_F(TestExecutor, spin_all_invalid_duration) {
|
||||
DummyExecutor dummy;
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
dummy.spin_all(std::chrono::nanoseconds(-1)),
|
||||
std::invalid_argument("max_duration must be positive"));
|
||||
}
|
||||
|
||||
TEST_F(TestExecutor, spin_some_in_spin_some) {
|
||||
DummyExecutor dummy;
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
@@ -387,28 +291,6 @@ TEST_F(TestExecutor, spin_some_fail_wait) {
|
||||
std::runtime_error("rcl_wait() failed: error not set"));
|
||||
}
|
||||
|
||||
TEST_F(TestExecutor, get_node_by_group_null_group) {
|
||||
DummyExecutor dummy;
|
||||
ASSERT_EQ(nullptr, dummy.local_get_node_by_group(nullptr));
|
||||
}
|
||||
|
||||
TEST_F(TestExecutor, get_node_by_group) {
|
||||
DummyExecutor dummy;
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
rclcpp::CallbackGroup::SharedPtr cb_group = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
dummy.add_callback_group(cb_group, node->get_node_base_interface(), false);
|
||||
ASSERT_EQ(node->get_node_base_interface().get(), dummy.local_get_node_by_group(cb_group).get());
|
||||
}
|
||||
|
||||
TEST_F(TestExecutor, get_node_by_group_not_found) {
|
||||
DummyExecutor dummy;
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
rclcpp::CallbackGroup::SharedPtr cb_group = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
ASSERT_EQ(nullptr, dummy.local_get_node_by_group(cb_group).get());
|
||||
}
|
||||
|
||||
TEST_F(TestExecutor, get_group_by_timer_nullptr) {
|
||||
DummyExecutor dummy;
|
||||
ASSERT_EQ(nullptr, dummy.local_get_group_by_timer(nullptr));
|
||||
@@ -440,48 +322,6 @@ TEST_F(TestExecutor, get_group_by_timer_with_deleted_group) {
|
||||
ASSERT_EQ(nullptr, dummy.local_get_group_by_timer(timer).get());
|
||||
}
|
||||
|
||||
TEST_F(TestExecutor, get_group_by_timer_add_callback_group) {
|
||||
DummyExecutor dummy;
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
rclcpp::CallbackGroup::SharedPtr cb_group = node->create_callback_group(
|
||||
rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
auto timer =
|
||||
node->create_wall_timer(std::chrono::milliseconds(1), [&]() {}, cb_group);
|
||||
dummy.add_callback_group(cb_group, node->get_node_base_interface(), false);
|
||||
|
||||
ASSERT_EQ(cb_group.get(), dummy.local_get_group_by_timer(timer).get());
|
||||
}
|
||||
|
||||
TEST_F(TestExecutor, spin_until_future_complete_in_spin_until_future_complete) {
|
||||
DummyExecutor dummy;
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
bool spin_until_future_complete_in_spin_until_future_complete = false;
|
||||
auto timer =
|
||||
node->create_wall_timer(
|
||||
std::chrono::milliseconds(1), [&]() {
|
||||
try {
|
||||
std::promise<void> promise;
|
||||
std::future<void> future = promise.get_future();
|
||||
dummy.spin_until_future_complete(future, std::chrono::milliseconds(1));
|
||||
} catch (const std::runtime_error & err) {
|
||||
if (err.what() == std::string(
|
||||
"spin_until_future_complete() called while already spinning"))
|
||||
{
|
||||
spin_until_future_complete_in_spin_until_future_complete = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dummy.add_node(node);
|
||||
// Wait for the wall timer to have expired.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
EXPECT_FALSE(spin_until_future_complete_in_spin_until_future_complete);
|
||||
std::promise<void> promise;
|
||||
std::future<void> future = promise.get_future();
|
||||
dummy.spin_until_future_complete(future, std::chrono::milliseconds(1));
|
||||
EXPECT_TRUE(spin_until_future_complete_in_spin_until_future_complete);
|
||||
}
|
||||
|
||||
TEST_F(TestExecutor, spin_node_once_base_interface) {
|
||||
DummyExecutor dummy;
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
@@ -515,14 +355,3 @@ TEST_F(TestExecutor, spin_node_once_node) {
|
||||
dummy.spin_node_once(node);
|
||||
EXPECT_TRUE(spin_called);
|
||||
}
|
||||
|
||||
TEST_F(TestExecutor, spin_until_future_complete_future_already_complete) {
|
||||
DummyExecutor dummy;
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
std::promise<void> promise;
|
||||
std::future<void> future = promise.get_future();
|
||||
promise.set_value();
|
||||
EXPECT_EQ(
|
||||
rclcpp::FutureReturnCode::SUCCESS,
|
||||
dummy.spin_until_future_complete(future, std::chrono::milliseconds(1)));
|
||||
}
|
||||
|
||||
@@ -36,24 +36,22 @@ TEST_F(TestFindWeakNodes, allocator_strategy_with_weak_nodes) {
|
||||
rclcpp::memory_strategies::allocator_memory_strategy::AllocatorMemoryStrategy<>>();
|
||||
auto existing_node = rclcpp::Node::make_shared("existing_node");
|
||||
auto dead_node = rclcpp::Node::make_shared("dead_node");
|
||||
auto existing_group = existing_node->get_node_base_interface()->get_default_callback_group();
|
||||
auto dead_group = dead_node->get_node_base_interface()->get_default_callback_group();
|
||||
rclcpp::memory_strategy::MemoryStrategy::WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
weak_groups_to_nodes[existing_group] = existing_node->get_node_base_interface();
|
||||
weak_groups_to_nodes[dead_group] = dead_node->get_node_base_interface();
|
||||
rclcpp::memory_strategy::MemoryStrategy::WeakNodeList weak_nodes;
|
||||
weak_nodes.push_back(existing_node->get_node_base_interface());
|
||||
weak_nodes.push_back(dead_node->get_node_base_interface());
|
||||
|
||||
// AND
|
||||
// Delete dead_node, creating a dangling pointer in weak_nodes
|
||||
dead_node.reset();
|
||||
ASSERT_FALSE(weak_groups_to_nodes[existing_group].expired());
|
||||
ASSERT_TRUE(weak_groups_to_nodes[dead_group].expired());
|
||||
ASSERT_FALSE(weak_nodes.front().expired());
|
||||
ASSERT_TRUE(weak_nodes.back().expired());
|
||||
|
||||
// WHEN
|
||||
bool has_invalid_weak_groups_or_nodes = memory_strategy->collect_entities(weak_groups_to_nodes);
|
||||
bool has_invalid_weak_nodes = memory_strategy->collect_entities(weak_nodes);
|
||||
|
||||
// THEN
|
||||
// The result of finding dangling node pointers should be true
|
||||
ASSERT_TRUE(has_invalid_weak_groups_or_nodes);
|
||||
ASSERT_TRUE(has_invalid_weak_nodes);
|
||||
|
||||
// Prevent memory leak due to the order of destruction
|
||||
memory_strategy->clear_handles();
|
||||
@@ -66,20 +64,18 @@ TEST_F(TestFindWeakNodes, allocator_strategy_no_weak_nodes) {
|
||||
rclcpp::memory_strategies::allocator_memory_strategy::AllocatorMemoryStrategy<>>();
|
||||
auto existing_node1 = rclcpp::Node::make_shared("existing_node1");
|
||||
auto existing_node2 = rclcpp::Node::make_shared("existing_node2");
|
||||
auto existing_group1 = existing_node1->get_node_base_interface()->get_default_callback_group();
|
||||
auto existing_group2 = existing_node2->get_node_base_interface()->get_default_callback_group();
|
||||
rclcpp::memory_strategy::MemoryStrategy::WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
weak_groups_to_nodes[existing_group1] = existing_node1->get_node_base_interface();
|
||||
weak_groups_to_nodes[existing_group2] = existing_node2->get_node_base_interface();
|
||||
ASSERT_FALSE(weak_groups_to_nodes[existing_group1].expired());
|
||||
ASSERT_FALSE(weak_groups_to_nodes[existing_group2].expired());
|
||||
rclcpp::memory_strategy::MemoryStrategy::WeakNodeList weak_nodes;
|
||||
weak_nodes.push_back(existing_node1->get_node_base_interface());
|
||||
weak_nodes.push_back(existing_node2->get_node_base_interface());
|
||||
ASSERT_FALSE(weak_nodes.front().expired());
|
||||
ASSERT_FALSE(weak_nodes.back().expired());
|
||||
|
||||
// WHEN
|
||||
bool has_invalid_weak_groups_or_nodes = memory_strategy->collect_entities(weak_groups_to_nodes);
|
||||
bool has_invalid_weak_nodes = memory_strategy->collect_entities(weak_nodes);
|
||||
|
||||
// THEN
|
||||
// The result of finding dangling node pointers should be false
|
||||
ASSERT_FALSE(has_invalid_weak_groups_or_nodes);
|
||||
ASSERT_FALSE(has_invalid_weak_nodes);
|
||||
|
||||
// Prevent memory leak due to the order of destruction
|
||||
memory_strategy->clear_handles();
|
||||
|
||||
@@ -125,14 +125,16 @@ public:
|
||||
this->run();
|
||||
}
|
||||
|
||||
void mock_init_wait_set()
|
||||
void mock_start_thread()
|
||||
{
|
||||
this->init_wait_set();
|
||||
}
|
||||
|
||||
void mock_cleanup_wait_set()
|
||||
{
|
||||
this->cleanup_wait_set();
|
||||
// This function prepares the loop thread to be run, but leave
|
||||
// early with the failure thrown. That way the graph_listener wait_set
|
||||
// is init, without being started
|
||||
auto mock_wait_set_init = mocking_utils::inject_on_return(
|
||||
"lib:rclcpp", rcl_wait_set_init, RCL_RET_ERROR);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
this->start_if_not_started(),
|
||||
std::runtime_error("failed to initialize wait set: error not set"));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -150,7 +152,7 @@ TEST_F(TestGraphListener, error_run_graph_listener_mock_wait_set_clear) {
|
||||
auto global_context = rclcpp::contexts::get_global_default_context();
|
||||
auto graph_listener_test =
|
||||
std::make_shared<TestGraphListenerProtectedMethods>(global_context);
|
||||
graph_listener_test->mock_init_wait_set();
|
||||
graph_listener_test->mock_start_thread();
|
||||
auto mock_wait_set_clear = mocking_utils::patch_and_return(
|
||||
"lib:rclcpp", rcl_wait_set_clear, RCL_RET_ERROR);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
@@ -162,7 +164,7 @@ TEST_F(TestGraphListener, error_run_graph_listener_mock_wait_set_add_guard_condi
|
||||
auto global_context = rclcpp::contexts::get_global_default_context();
|
||||
auto graph_listener_test =
|
||||
std::make_shared<TestGraphListenerProtectedMethods>(global_context);
|
||||
graph_listener_test->mock_init_wait_set();
|
||||
graph_listener_test->mock_start_thread();
|
||||
auto mock_wait_set_clear = mocking_utils::patch_and_return(
|
||||
"lib:rclcpp", rcl_wait_set_add_guard_condition, RCL_RET_ERROR);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
@@ -174,7 +176,7 @@ TEST_F(TestGraphListener, error_run_graph_listener_mock_wait_set_add_guard_condi
|
||||
auto global_context = rclcpp::contexts::get_global_default_context();
|
||||
auto graph_listener_test =
|
||||
std::make_shared<TestGraphListenerProtectedMethods>(global_context);
|
||||
graph_listener_test->mock_init_wait_set();
|
||||
graph_listener_test->mock_start_thread();
|
||||
auto mock = mocking_utils::patch(
|
||||
"lib:rclcpp", rcl_wait_set_add_guard_condition, [](auto, ...) {
|
||||
static int counter = 1;
|
||||
@@ -194,7 +196,7 @@ TEST_F(TestGraphListener, error_run_graph_listener_mock_wait_error) {
|
||||
auto global_context = rclcpp::contexts::get_global_default_context();
|
||||
auto graph_listener_test =
|
||||
std::make_shared<TestGraphListenerProtectedMethods>(global_context);
|
||||
graph_listener_test->mock_init_wait_set();
|
||||
graph_listener_test->mock_start_thread();
|
||||
auto mock_wait_set_clear = mocking_utils::patch_and_return(
|
||||
"lib:rclcpp", rcl_wait, RCL_RET_ERROR);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
@@ -206,7 +208,7 @@ TEST_F(TestGraphListener, error_run_graph_listener_mock_wait_timeout) {
|
||||
auto global_context = rclcpp::contexts::get_global_default_context();
|
||||
auto graph_listener_test =
|
||||
std::make_shared<TestGraphListenerProtectedMethods>(global_context);
|
||||
graph_listener_test->mock_init_wait_set();
|
||||
graph_listener_test->mock_start_thread();
|
||||
auto mock_wait_set_clear = mocking_utils::patch_and_return(
|
||||
"lib:rclcpp", rcl_wait, RCL_RET_TIMEOUT);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
@@ -265,54 +267,27 @@ TEST_F(TestGraphListener, test_errors_graph_listener_add_remove_node) {
|
||||
|
||||
/* Shutdown errors */
|
||||
TEST_F(TestGraphListener, test_graph_listener_shutdown_wait_fini_error_nothrow) {
|
||||
auto global_context = rclcpp::contexts::get_global_default_context();
|
||||
auto graph_listener_test =
|
||||
std::make_shared<TestGraphListenerProtectedMethods>(global_context);
|
||||
|
||||
graph_listener_test->start_if_not_started();
|
||||
|
||||
{
|
||||
auto mock_wait_set_fini = mocking_utils::patch_and_return(
|
||||
"lib:rclcpp", rcl_wait_set_fini, RCL_RET_ERROR);
|
||||
// Exception is logged when using nothrow_t
|
||||
EXPECT_NO_THROW(graph_listener_test->shutdown(std::nothrow_t()));
|
||||
}
|
||||
|
||||
graph_listener_test->mock_cleanup_wait_set();
|
||||
graph_listener()->start_if_not_started();
|
||||
auto mock_wait_set_fini = mocking_utils::inject_on_return(
|
||||
"lib:rclcpp", rcl_wait_set_fini, RCL_RET_ERROR);
|
||||
// Exception is logged when using nothrow_t
|
||||
EXPECT_NO_THROW(graph_listener()->shutdown(std::nothrow_t()));
|
||||
}
|
||||
|
||||
TEST_F(TestGraphListener, test_graph_listener_shutdown_wait_fini_error_throw) {
|
||||
auto global_context = rclcpp::contexts::get_global_default_context();
|
||||
auto graph_listener_test =
|
||||
std::make_shared<TestGraphListenerProtectedMethods>(global_context);
|
||||
|
||||
graph_listener()->start_if_not_started();
|
||||
|
||||
{
|
||||
auto mock_wait_set_fini = mocking_utils::patch_and_return(
|
||||
"lib:rclcpp", rcl_wait_set_fini, RCL_RET_ERROR);
|
||||
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
graph_listener()->shutdown(),
|
||||
std::runtime_error("failed to finalize wait set: error not set"));
|
||||
}
|
||||
|
||||
graph_listener_test->mock_cleanup_wait_set();
|
||||
auto mock_wait_set_fini = mocking_utils::inject_on_return(
|
||||
"lib:rclcpp", rcl_wait_set_fini, RCL_RET_ERROR);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
graph_listener()->shutdown(),
|
||||
std::runtime_error("failed to finalize wait set: error not set"));
|
||||
}
|
||||
|
||||
TEST_F(TestGraphListener, test_graph_listener_shutdown_guard_fini_error_throw) {
|
||||
auto global_context = rclcpp::contexts::get_global_default_context();
|
||||
auto graph_listener_test =
|
||||
std::make_shared<TestGraphListenerProtectedMethods>(global_context);
|
||||
|
||||
graph_listener_test->start_if_not_started();
|
||||
|
||||
auto mock_wait_set_fini = mocking_utils::patch_and_return(
|
||||
graph_listener()->start_if_not_started();
|
||||
auto mock_wait_set_fini = mocking_utils::inject_on_return(
|
||||
"lib:rclcpp", rcl_guard_condition_fini, RCL_RET_ERROR);
|
||||
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
graph_listener_test->shutdown(),
|
||||
graph_listener()->shutdown(),
|
||||
std::runtime_error("failed to finalize interrupt guard condition: error not set"));
|
||||
|
||||
graph_listener_test->mock_cleanup_wait_set();
|
||||
}
|
||||
|
||||
@@ -65,20 +65,6 @@ TEST(TestInitOptions, test_initialize_logging) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(TestInitOptions, test_domain_id) {
|
||||
rcl_allocator_t allocator = rcl_get_default_allocator();
|
||||
auto options = rclcpp::InitOptions(allocator);
|
||||
size_t domain_id = RCL_DEFAULT_DOMAIN_ID;
|
||||
EXPECT_EQ(RCL_RET_OK, rcl_get_default_domain_id(&domain_id));
|
||||
|
||||
options.use_default_domain_id();
|
||||
EXPECT_EQ(domain_id, options.get_domain_id());
|
||||
options.set_domain_id(42);
|
||||
EXPECT_EQ((size_t)42, options.get_domain_id());
|
||||
options.use_default_domain_id();
|
||||
EXPECT_EQ(domain_id, options.get_domain_id());
|
||||
}
|
||||
|
||||
// Required for mocking_utils below
|
||||
MOCKING_UTILS_BOOL_OPERATOR_RETURNS_FALSE(rcutils_allocator_t, ==)
|
||||
MOCKING_UTILS_BOOL_OPERATOR_RETURNS_FALSE(rcutils_allocator_t, !=)
|
||||
@@ -111,30 +97,3 @@ TEST(TestInitOptions, copy_constructor_rcl_init_options_copy_failed) {
|
||||
options2.operator=(options),
|
||||
std::runtime_error("failed to copy rcl init options: error not set"));
|
||||
}
|
||||
|
||||
TEST(TestInitOptions, use_default_domain_id_rcl_get_default_domain_id_failed) {
|
||||
rclcpp::InitOptions options;
|
||||
auto mock = mocking_utils::patch_and_return(
|
||||
"lib:rclcpp", rcl_get_default_domain_id, RCL_RET_ERROR);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
options.use_default_domain_id(),
|
||||
std::runtime_error("failed to get default domain id: error not set"));
|
||||
}
|
||||
|
||||
TEST(TestInitOptions, set_domain_id_rcl_init_options_set_domain_id_failed) {
|
||||
rclcpp::InitOptions options;
|
||||
auto mock = mocking_utils::patch_and_return(
|
||||
"lib:rclcpp", rcl_init_options_set_domain_id, RCL_RET_ERROR);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
options.set_domain_id(0),
|
||||
std::runtime_error("failed to set domain id to rcl init options: error not set"));
|
||||
}
|
||||
|
||||
TEST(TestInitOptions, get_domain_id_rcl_init_options_get_domain_id_failed) {
|
||||
rclcpp::InitOptions options;
|
||||
auto mock = mocking_utils::patch_and_return(
|
||||
"lib:rclcpp", rcl_init_options_get_domain_id, RCL_RET_ERROR);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
options.get_domain_id(),
|
||||
std::runtime_error("failed to get domain id from rcl init options: error not set"));
|
||||
}
|
||||
|
||||
@@ -44,114 +44,6 @@ TEST(TestLogger, get_node_logger) {
|
||||
EXPECT_STREQ(logger.get_name(), "ns.my_node");
|
||||
|
||||
logger = rclcpp::get_node_logger(nullptr);
|
||||
rcl_reset_error();
|
||||
EXPECT_STREQ(logger.get_name(), "rclcpp");
|
||||
rclcpp::shutdown();
|
||||
}
|
||||
|
||||
struct LogEvent
|
||||
{
|
||||
bool console_output_handler_called;
|
||||
std::string message;
|
||||
};
|
||||
LogEvent g_last_log_event;
|
||||
|
||||
TEST(TestLogger, set_level) {
|
||||
ASSERT_EQ(RCUTILS_RET_OK, rcutils_logging_initialize());
|
||||
|
||||
rclcpp::Logger logger = rclcpp::get_logger("test_logger");
|
||||
EXPECT_THROW(
|
||||
{
|
||||
logger.set_level(static_cast<rclcpp::Logger::Level>(99999));
|
||||
}, rclcpp::exceptions::RCLInvalidArgument);
|
||||
|
||||
auto rcutils_logging_console_output_handler = [](
|
||||
const rcutils_log_location_t *,
|
||||
int, const char *, rcutils_time_point_value_t,
|
||||
const char * format, va_list * args) -> void
|
||||
{
|
||||
g_last_log_event.console_output_handler_called = true;
|
||||
char buffer[1024];
|
||||
vsnprintf(buffer, sizeof(buffer), format, *args);
|
||||
g_last_log_event.message = buffer;
|
||||
};
|
||||
|
||||
rcutils_logging_output_handler_t previous_output_handler = rcutils_logging_get_output_handler();
|
||||
rcutils_logging_set_output_handler(rcutils_logging_console_output_handler);
|
||||
|
||||
// default
|
||||
RCLCPP_DEBUG(logger, std::string("message %s"), "debug");
|
||||
EXPECT_FALSE(g_last_log_event.console_output_handler_called);
|
||||
RCLCPP_INFO(logger, std::string("message %s"), "info");
|
||||
EXPECT_TRUE(g_last_log_event.console_output_handler_called);
|
||||
EXPECT_EQ("message info", g_last_log_event.message);
|
||||
|
||||
// unset
|
||||
g_last_log_event.console_output_handler_called = false;
|
||||
logger.set_level(rclcpp::Logger::Level::Unset);
|
||||
RCLCPP_DEBUG(logger, std::string("message %s"), "debug");
|
||||
EXPECT_FALSE(g_last_log_event.console_output_handler_called);
|
||||
RCLCPP_INFO(logger, std::string("message %s"), "info");
|
||||
EXPECT_TRUE(g_last_log_event.console_output_handler_called);
|
||||
EXPECT_EQ("message info", g_last_log_event.message);
|
||||
|
||||
// debug
|
||||
g_last_log_event.console_output_handler_called = false;
|
||||
logger.set_level(rclcpp::Logger::Level::Debug);
|
||||
RCLCPP_DEBUG(logger, std::string("message %s"), "debug");
|
||||
EXPECT_TRUE(g_last_log_event.console_output_handler_called);
|
||||
EXPECT_EQ("message debug", g_last_log_event.message);
|
||||
RCLCPP_INFO(logger, std::string("message %s"), "info");
|
||||
EXPECT_EQ("message info", g_last_log_event.message);
|
||||
|
||||
// info
|
||||
g_last_log_event.console_output_handler_called = false;
|
||||
logger.set_level(rclcpp::Logger::Level::Info);
|
||||
RCLCPP_DEBUG(logger, std::string("message %s"), "debug");
|
||||
EXPECT_FALSE(g_last_log_event.console_output_handler_called);
|
||||
RCLCPP_INFO(logger, std::string("message %s"), "info");
|
||||
EXPECT_TRUE(g_last_log_event.console_output_handler_called);
|
||||
EXPECT_EQ("message info", g_last_log_event.message);
|
||||
|
||||
// warn
|
||||
g_last_log_event.console_output_handler_called = false;
|
||||
logger.set_level(rclcpp::Logger::Level::Warn);
|
||||
RCLCPP_DEBUG(logger, std::string("message %s"), "debug");
|
||||
EXPECT_FALSE(g_last_log_event.console_output_handler_called);
|
||||
RCLCPP_INFO(logger, std::string("message %s"), "info");
|
||||
EXPECT_FALSE(g_last_log_event.console_output_handler_called);
|
||||
RCLCPP_WARN(logger, std::string("message %s"), "warn");
|
||||
EXPECT_TRUE(g_last_log_event.console_output_handler_called);
|
||||
EXPECT_EQ("message warn", g_last_log_event.message);
|
||||
|
||||
// error
|
||||
g_last_log_event.console_output_handler_called = false;
|
||||
logger.set_level(rclcpp::Logger::Level::Error);
|
||||
RCLCPP_DEBUG(logger, std::string("message %s"), "debug");
|
||||
EXPECT_FALSE(g_last_log_event.console_output_handler_called);
|
||||
RCLCPP_INFO(logger, std::string("message %s"), "info");
|
||||
EXPECT_FALSE(g_last_log_event.console_output_handler_called);
|
||||
RCLCPP_WARN(logger, std::string("message %s"), "warn");
|
||||
EXPECT_FALSE(g_last_log_event.console_output_handler_called);
|
||||
RCLCPP_ERROR(logger, std::string("message %s"), "error");
|
||||
EXPECT_TRUE(g_last_log_event.console_output_handler_called);
|
||||
EXPECT_EQ("message error", g_last_log_event.message);
|
||||
|
||||
// fatal
|
||||
g_last_log_event.console_output_handler_called = false;
|
||||
logger.set_level(rclcpp::Logger::Level::Fatal);
|
||||
RCLCPP_DEBUG(logger, std::string("message %s"), "debug");
|
||||
EXPECT_FALSE(g_last_log_event.console_output_handler_called);
|
||||
RCLCPP_INFO(logger, std::string("message %s"), "info");
|
||||
EXPECT_FALSE(g_last_log_event.console_output_handler_called);
|
||||
RCLCPP_WARN(logger, std::string("message %s"), "warn");
|
||||
EXPECT_FALSE(g_last_log_event.console_output_handler_called);
|
||||
RCLCPP_ERROR(logger, std::string("message %s"), "error");
|
||||
EXPECT_FALSE(g_last_log_event.console_output_handler_called);
|
||||
RCLCPP_FATAL(logger, std::string("message %s"), "fatal");
|
||||
EXPECT_TRUE(g_last_log_event.console_output_handler_called);
|
||||
EXPECT_EQ("message fatal", g_last_log_event.message);
|
||||
|
||||
rcutils_logging_set_output_handler(previous_output_handler);
|
||||
EXPECT_EQ(RCUTILS_RET_OK, rcutils_logging_shutdown());
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
@@ -25,9 +24,7 @@
|
||||
#include "test_msgs/srv/empty.hpp"
|
||||
|
||||
using rclcpp::memory_strategy::MemoryStrategy;
|
||||
typedef std::map<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr,
|
||||
std::owner_less<rclcpp::CallbackGroup::WeakPtr>> WeakCallbackGroupsToNodesMap;
|
||||
using WeakNodeList = std::list<rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>;
|
||||
|
||||
/**
|
||||
* Mock Waitable class
|
||||
@@ -78,22 +75,13 @@ TEST_F(TestMemoryStrategy, construct_destruct) {
|
||||
}
|
||||
|
||||
TEST_F(TestMemoryStrategy, get_subscription_by_handle) {
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
WeakNodeList nodes;
|
||||
std::shared_ptr<const rcl_subscription_t> subscription_handle;
|
||||
rclcpp::SubscriptionBase::SharedPtr found_subscription = nullptr;
|
||||
{
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
auto callback_groups = node->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes, &node](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node->get_node_base_interface()));
|
||||
});
|
||||
memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
nodes.push_back(node->get_node_base_interface());
|
||||
memory_strategy()->collect_entities(nodes);
|
||||
{
|
||||
auto callback_group =
|
||||
node->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
@@ -109,38 +97,29 @@ TEST_F(TestMemoryStrategy, get_subscription_by_handle) {
|
||||
|
||||
EXPECT_EQ(
|
||||
subscription,
|
||||
memory_strategy()->get_subscription_by_handle(subscription_handle, weak_groups_to_nodes));
|
||||
memory_strategy()->get_subscription_by_handle(subscription_handle, nodes));
|
||||
} // subscription goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_subscription_by_handle(subscription_handle, weak_groups_to_nodes));
|
||||
memory_strategy()->get_subscription_by_handle(subscription_handle, nodes));
|
||||
} // callback_group goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_subscription_by_handle(subscription_handle, weak_groups_to_nodes));
|
||||
memory_strategy()->get_subscription_by_handle(subscription_handle, nodes));
|
||||
} // Node goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_subscription_by_handle(subscription_handle, weak_groups_to_nodes));
|
||||
memory_strategy()->get_subscription_by_handle(subscription_handle, nodes));
|
||||
}
|
||||
|
||||
TEST_F(TestMemoryStrategy, get_service_by_handle) {
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
WeakNodeList nodes;
|
||||
std::shared_ptr<const rcl_service_t> service_handle;
|
||||
rclcpp::ServiceBase::SharedPtr found_service = nullptr;
|
||||
{
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
auto callback_groups = node->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes, &node](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node->get_node_base_interface()));
|
||||
});
|
||||
memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
nodes.push_back(node->get_node_base_interface());
|
||||
memory_strategy()->collect_entities(nodes);
|
||||
{
|
||||
auto callback_group =
|
||||
node->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
@@ -148,11 +127,7 @@ TEST_F(TestMemoryStrategy, get_service_by_handle) {
|
||||
[](const test_msgs::srv::Empty::Request::SharedPtr,
|
||||
test_msgs::srv::Empty::Response::SharedPtr) {};
|
||||
const rclcpp::QoS qos(10);
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
rclcpp::CallbackGroup::WeakPtr(callback_group),
|
||||
node->get_node_base_interface()));
|
||||
|
||||
{
|
||||
auto service = node->create_service<test_msgs::srv::Empty>(
|
||||
"service", std::move(service_callback),
|
||||
@@ -162,38 +137,29 @@ TEST_F(TestMemoryStrategy, get_service_by_handle) {
|
||||
|
||||
EXPECT_EQ(
|
||||
service,
|
||||
memory_strategy()->get_service_by_handle(service_handle, weak_groups_to_nodes));
|
||||
memory_strategy()->get_service_by_handle(service_handle, nodes));
|
||||
} // service goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_service_by_handle(service_handle, weak_groups_to_nodes));
|
||||
memory_strategy()->get_service_by_handle(service_handle, nodes));
|
||||
} // callback_group goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_service_by_handle(service_handle, weak_groups_to_nodes));
|
||||
memory_strategy()->get_service_by_handle(service_handle, nodes));
|
||||
} // Node goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_service_by_handle(service_handle, weak_groups_to_nodes));
|
||||
memory_strategy()->get_service_by_handle(service_handle, nodes));
|
||||
}
|
||||
|
||||
TEST_F(TestMemoryStrategy, get_client_by_handle) {
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
WeakNodeList nodes;
|
||||
std::shared_ptr<const rcl_client_t> client_handle;
|
||||
rclcpp::ClientBase::SharedPtr found_client = nullptr;
|
||||
{
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
auto callback_groups = node->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes, &node](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node->get_node_base_interface()));
|
||||
});
|
||||
memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
nodes.push_back(node->get_node_base_interface());
|
||||
memory_strategy()->collect_entities(nodes);
|
||||
{
|
||||
auto callback_group =
|
||||
node->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
@@ -202,46 +168,32 @@ TEST_F(TestMemoryStrategy, get_client_by_handle) {
|
||||
"service", rmw_qos_profile_services_default, callback_group);
|
||||
|
||||
client_handle = client->get_client_handle();
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
rclcpp::CallbackGroup::WeakPtr(callback_group),
|
||||
node->get_node_base_interface()));
|
||||
|
||||
EXPECT_EQ(
|
||||
client,
|
||||
memory_strategy()->get_client_by_handle(client_handle, weak_groups_to_nodes));
|
||||
memory_strategy()->get_client_by_handle(client_handle, nodes));
|
||||
} // client goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_client_by_handle(client_handle, weak_groups_to_nodes));
|
||||
memory_strategy()->get_client_by_handle(client_handle, nodes));
|
||||
} // callback_group goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_client_by_handle(client_handle, weak_groups_to_nodes));
|
||||
memory_strategy()->get_client_by_handle(client_handle, nodes));
|
||||
} // Node goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_client_by_handle(client_handle, weak_groups_to_nodes));
|
||||
memory_strategy()->get_client_by_handle(client_handle, nodes));
|
||||
}
|
||||
|
||||
TEST_F(TestMemoryStrategy, get_timer_by_handle) {
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
WeakNodeList nodes;
|
||||
std::shared_ptr<const rcl_timer_t> timer_handle;
|
||||
rclcpp::TimerBase::SharedPtr found_timer = nullptr;
|
||||
{
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
auto callback_groups = node->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes, &node](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node->get_node_base_interface()));
|
||||
});
|
||||
memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
nodes.push_back(node->get_node_base_interface());
|
||||
memory_strategy()->collect_entities(nodes);
|
||||
{
|
||||
auto callback_group =
|
||||
node->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
@@ -249,92 +201,58 @@ TEST_F(TestMemoryStrategy, get_timer_by_handle) {
|
||||
auto timer_callback = []() {};
|
||||
auto timer = node->create_wall_timer(
|
||||
std::chrono::milliseconds(1), timer_callback, callback_group);
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
rclcpp::CallbackGroup::WeakPtr(callback_group),
|
||||
node->get_node_base_interface()));
|
||||
|
||||
timer_handle = timer->get_timer_handle();
|
||||
|
||||
EXPECT_EQ(
|
||||
timer,
|
||||
memory_strategy()->get_timer_by_handle(timer_handle, weak_groups_to_nodes));
|
||||
memory_strategy()->get_timer_by_handle(timer_handle, nodes));
|
||||
} // timer goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_timer_by_handle(timer_handle, weak_groups_to_nodes));
|
||||
memory_strategy()->get_timer_by_handle(timer_handle, nodes));
|
||||
} // callback_group goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_timer_by_handle(timer_handle, weak_groups_to_nodes));
|
||||
memory_strategy()->get_timer_by_handle(timer_handle, nodes));
|
||||
} // Node goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_timer_by_handle(timer_handle, weak_groups_to_nodes));
|
||||
memory_strategy()->get_timer_by_handle(timer_handle, nodes));
|
||||
}
|
||||
|
||||
TEST_F(TestMemoryStrategy, get_node_by_group) {
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
WeakNodeList nodes;
|
||||
rclcpp::CallbackGroup::SharedPtr callback_group = nullptr;
|
||||
{
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
auto node_handle = node->get_node_base_interface();
|
||||
auto callback_groups = node_handle->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes, &node_handle](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node_handle));
|
||||
});
|
||||
memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
nodes.push_back(node_handle);
|
||||
memory_strategy()->collect_entities(nodes);
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_node_by_group(nullptr, weak_groups_to_nodes));
|
||||
memory_strategy()->get_node_by_group(nullptr, nodes));
|
||||
|
||||
callback_group =
|
||||
node->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
|
||||
// Nothing in the weak_groups_to_nodes, so find fails.
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_node_by_group(callback_group, weak_groups_to_nodes));
|
||||
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
rclcpp::CallbackGroup::WeakPtr(callback_group),
|
||||
node->get_node_base_interface()));
|
||||
EXPECT_EQ(
|
||||
node_handle,
|
||||
memory_strategy()->get_node_by_group(callback_group, weak_groups_to_nodes));
|
||||
memory_strategy()->get_node_by_group(callback_group, nodes));
|
||||
} // Node goes out of scope
|
||||
// Callback group still exists, so lookup returns nullptr because node is destroyed.
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_node_by_group(callback_group, weak_groups_to_nodes));
|
||||
memory_strategy()->get_node_by_group(callback_group, nodes));
|
||||
}
|
||||
|
||||
TEST_F(TestMemoryStrategy, get_group_by_subscription) {
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
WeakNodeList nodes;
|
||||
rclcpp::SubscriptionBase::SharedPtr subscription = nullptr;
|
||||
rclcpp::CallbackGroup::SharedPtr callback_group = nullptr;
|
||||
{
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
auto callback_groups = node->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes, &node](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node->get_node_base_interface()));
|
||||
});
|
||||
memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
nodes.push_back(node->get_node_base_interface());
|
||||
memory_strategy()->collect_entities(nodes);
|
||||
{
|
||||
// This group is just used to test that a callback group that is held as a weak pointer
|
||||
// by node, doesn't confuse get_group_by_subscription() when it goes out of scope
|
||||
@@ -355,40 +273,27 @@ TEST_F(TestMemoryStrategy, get_group_by_subscription) {
|
||||
subscription = node->create_subscription<
|
||||
test_msgs::msg::Empty, decltype(subscription_callback)>(
|
||||
"topic", qos, std::move(subscription_callback), subscription_options);
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
rclcpp::CallbackGroup::WeakPtr(callback_group),
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr(node->get_node_base_interface())));
|
||||
|
||||
EXPECT_EQ(
|
||||
callback_group,
|
||||
memory_strategy()->get_group_by_subscription(subscription, weak_groups_to_nodes));
|
||||
memory_strategy()->get_group_by_subscription(subscription, nodes));
|
||||
} // callback_group goes out of scope
|
||||
EXPECT_EQ(
|
||||
callback_group,
|
||||
memory_strategy()->get_group_by_subscription(subscription, weak_groups_to_nodes));
|
||||
memory_strategy()->get_group_by_subscription(subscription, nodes));
|
||||
} // Node goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_group_by_subscription(subscription, weak_groups_to_nodes));
|
||||
memory_strategy()->get_group_by_subscription(subscription, nodes));
|
||||
}
|
||||
|
||||
TEST_F(TestMemoryStrategy, get_group_by_service) {
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
WeakNodeList nodes;
|
||||
rclcpp::ServiceBase::SharedPtr service = nullptr;
|
||||
{
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
auto callback_groups = node->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes, &node](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node->get_node_base_interface()));
|
||||
});
|
||||
memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
nodes.push_back(node->get_node_base_interface());
|
||||
memory_strategy()->collect_entities(nodes);
|
||||
{
|
||||
auto callback_group =
|
||||
node->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
@@ -400,139 +305,96 @@ TEST_F(TestMemoryStrategy, get_group_by_service) {
|
||||
service = node->create_service<test_msgs::srv::Empty>(
|
||||
"service", std::move(service_callback),
|
||||
rmw_qos_profile_services_default, callback_group);
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
rclcpp::CallbackGroup::WeakPtr(callback_group),
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr(node->get_node_base_interface())));
|
||||
|
||||
EXPECT_EQ(
|
||||
callback_group,
|
||||
memory_strategy()->get_group_by_service(service, weak_groups_to_nodes));
|
||||
memory_strategy()->get_group_by_service(service, nodes));
|
||||
} // callback_group goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_group_by_service(service, weak_groups_to_nodes));
|
||||
memory_strategy()->get_group_by_service(service, nodes));
|
||||
} // Node goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_group_by_service(service, weak_groups_to_nodes));
|
||||
memory_strategy()->get_group_by_service(service, nodes));
|
||||
}
|
||||
|
||||
TEST_F(TestMemoryStrategy, get_group_by_client) {
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
WeakNodeList nodes;
|
||||
rclcpp::ClientBase::SharedPtr client = nullptr;
|
||||
{
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
auto callback_groups = node->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes, &node](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node->get_node_base_interface()));
|
||||
});
|
||||
memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
nodes.push_back(node->get_node_base_interface());
|
||||
memory_strategy()->collect_entities(nodes);
|
||||
{
|
||||
auto callback_group =
|
||||
node->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
|
||||
client = node->create_client<test_msgs::srv::Empty>(
|
||||
"service", rmw_qos_profile_services_default, callback_group);
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
rclcpp::CallbackGroup::WeakPtr(callback_group),
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr(node->get_node_base_interface())));
|
||||
|
||||
EXPECT_EQ(
|
||||
callback_group,
|
||||
memory_strategy()->get_group_by_client(client, weak_groups_to_nodes));
|
||||
memory_strategy()->get_group_by_client(client, nodes));
|
||||
} // callback_group goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_group_by_client(client, weak_groups_to_nodes));
|
||||
memory_strategy()->get_group_by_client(client, nodes));
|
||||
} // Node goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_group_by_client(client, weak_groups_to_nodes));
|
||||
memory_strategy()->get_group_by_client(client, nodes));
|
||||
}
|
||||
|
||||
TEST_F(TestMemoryStrategy, get_group_by_timer) {
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
WeakNodeList nodes;
|
||||
rclcpp::TimerBase::SharedPtr timer = nullptr;
|
||||
{
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
auto callback_groups = node->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes, &node](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node->get_node_base_interface()));
|
||||
});
|
||||
memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
nodes.push_back(node->get_node_base_interface());
|
||||
memory_strategy()->collect_entities(nodes);
|
||||
{
|
||||
auto callback_group =
|
||||
node->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
auto timer_callback = []() {};
|
||||
timer = node->create_wall_timer(
|
||||
std::chrono::milliseconds(1), timer_callback, callback_group);
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
rclcpp::CallbackGroup::WeakPtr(callback_group),
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr(node->get_node_base_interface())));
|
||||
|
||||
EXPECT_EQ(
|
||||
callback_group,
|
||||
memory_strategy()->get_group_by_timer(timer, weak_groups_to_nodes));
|
||||
memory_strategy()->get_group_by_timer(timer, nodes));
|
||||
} // callback_group goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_group_by_timer(timer, weak_groups_to_nodes));
|
||||
memory_strategy()->get_group_by_timer(timer, nodes));
|
||||
} // Node goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_group_by_timer(timer, weak_groups_to_nodes));
|
||||
memory_strategy()->get_group_by_timer(timer, nodes));
|
||||
}
|
||||
|
||||
TEST_F(TestMemoryStrategy, get_group_by_waitable) {
|
||||
WeakCallbackGroupsToNodesMap weak_groups_to_nodes;
|
||||
WeakNodeList nodes;
|
||||
rclcpp::Waitable::SharedPtr waitable = nullptr;
|
||||
{
|
||||
auto node = std::make_shared<rclcpp::Node>("node", "ns");
|
||||
auto callback_groups = node->get_node_base_interface()->get_callback_groups();
|
||||
std::for_each(
|
||||
callback_groups.begin(), callback_groups.end(),
|
||||
[&weak_groups_to_nodes, &node](rclcpp::CallbackGroup::WeakPtr weak_group_ptr) {
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
weak_group_ptr,
|
||||
node->get_node_base_interface()));
|
||||
});
|
||||
memory_strategy()->collect_entities(weak_groups_to_nodes);
|
||||
nodes.push_back(node->get_node_base_interface());
|
||||
memory_strategy()->collect_entities(nodes);
|
||||
{
|
||||
waitable = std::make_shared<TestWaitable>();
|
||||
auto callback_group =
|
||||
node->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
|
||||
node->get_node_waitables_interface()->add_waitable(waitable, callback_group);
|
||||
weak_groups_to_nodes.insert(
|
||||
std::pair<rclcpp::CallbackGroup::WeakPtr,
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr>(
|
||||
rclcpp::CallbackGroup::WeakPtr(callback_group),
|
||||
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr(node->get_node_base_interface())));
|
||||
|
||||
EXPECT_EQ(
|
||||
callback_group,
|
||||
memory_strategy()->get_group_by_waitable(waitable, weak_groups_to_nodes));
|
||||
memory_strategy()->get_group_by_waitable(waitable, nodes));
|
||||
} // callback_group goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_group_by_waitable(waitable, weak_groups_to_nodes));
|
||||
memory_strategy()->get_group_by_waitable(waitable, nodes));
|
||||
} // Node goes out of scope
|
||||
EXPECT_EQ(
|
||||
nullptr,
|
||||
memory_strategy()->get_group_by_waitable(waitable, weak_groups_to_nodes));
|
||||
memory_strategy()->get_group_by_waitable(waitable, nodes));
|
||||
}
|
||||
|
||||
@@ -2360,6 +2360,206 @@ TEST_F(TestNode, get_parameter_types_undeclared_parameters_allowed) {
|
||||
}
|
||||
}
|
||||
|
||||
// suppress deprecated function test warnings
|
||||
#if !defined(_WIN32)
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#else // !defined(_WIN32)
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable: 4996)
|
||||
#endif
|
||||
|
||||
// test that it is possible to call get_parameter within the set_callback
|
||||
TEST_F(TestNode, set_on_parameters_set_callback_get_parameter) {
|
||||
auto node = std::make_shared<rclcpp::Node>("test_set_callback_get_parameter_node"_unq);
|
||||
|
||||
int64_t intval = node->declare_parameter("intparam", 42);
|
||||
EXPECT_EQ(intval, 42);
|
||||
double floatval = node->declare_parameter("floatparam", 5.4);
|
||||
EXPECT_EQ(floatval, 5.4);
|
||||
|
||||
double floatout;
|
||||
RCLCPP_SCOPE_EXIT({node->set_on_parameters_set_callback(nullptr);}); // always reset
|
||||
auto on_set_parameters =
|
||||
[&node, &floatout](const std::vector<rclcpp::Parameter> & parameters) {
|
||||
rcl_interfaces::msg::SetParametersResult result;
|
||||
result.successful = true;
|
||||
if (parameters.size() != 1) {
|
||||
result.successful = false;
|
||||
}
|
||||
|
||||
if (parameters[0].get_value<int>() != 40) {
|
||||
result.successful = false;
|
||||
}
|
||||
|
||||
rclcpp::Parameter floatparam = node->get_parameter("floatparam");
|
||||
if (floatparam.get_value<double>() != 5.4) {
|
||||
result.successful = false;
|
||||
}
|
||||
floatout = floatparam.get_value<double>();
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
EXPECT_EQ(node->set_on_parameters_set_callback(on_set_parameters), nullptr);
|
||||
ASSERT_NO_THROW(node->set_parameter({"intparam", 40}));
|
||||
ASSERT_EQ(floatout, 5.4);
|
||||
}
|
||||
|
||||
// test that calling set_parameter inside of a set_callback throws an exception
|
||||
TEST_F(TestNode, set_on_parameters_set_callback_set_parameter) {
|
||||
auto node = std::make_shared<rclcpp::Node>("test_set_callback_set_parameter_node"_unq);
|
||||
|
||||
int64_t intval = node->declare_parameter("intparam", 42);
|
||||
EXPECT_EQ(intval, 42);
|
||||
double floatval = node->declare_parameter("floatparam", 5.4);
|
||||
EXPECT_EQ(floatval, 5.4);
|
||||
|
||||
RCLCPP_SCOPE_EXIT({node->set_on_parameters_set_callback(nullptr);}); // always reset
|
||||
auto on_set_parameters =
|
||||
[&node](const std::vector<rclcpp::Parameter> & parameters) {
|
||||
rcl_interfaces::msg::SetParametersResult result;
|
||||
result.successful = true;
|
||||
if (parameters.size() != 1) {
|
||||
result.successful = false;
|
||||
}
|
||||
|
||||
if (parameters[0].get_value<int>() != 40) {
|
||||
result.successful = false;
|
||||
}
|
||||
|
||||
// This should throw an exception
|
||||
node->set_parameter({"floatparam", 5.6});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
EXPECT_EQ(node->set_on_parameters_set_callback(on_set_parameters), nullptr);
|
||||
EXPECT_THROW(
|
||||
{
|
||||
node->set_parameter(rclcpp::Parameter("intparam", 40));
|
||||
}, rclcpp::exceptions::ParameterModifiedInCallbackException);
|
||||
}
|
||||
|
||||
// test that calling declare_parameter inside of a set_callback throws an exception
|
||||
TEST_F(TestNode, set_on_parameters_set_callback_declare_parameter) {
|
||||
auto node = std::make_shared<rclcpp::Node>("test_set_callback_declare_parameter_node"_unq);
|
||||
|
||||
int64_t intval = node->declare_parameter("intparam", 42);
|
||||
EXPECT_EQ(intval, 42);
|
||||
double floatval = node->declare_parameter("floatparam", 5.4);
|
||||
EXPECT_EQ(floatval, 5.4);
|
||||
|
||||
RCLCPP_SCOPE_EXIT({node->set_on_parameters_set_callback(nullptr);}); // always reset
|
||||
auto on_set_parameters =
|
||||
[&node](const std::vector<rclcpp::Parameter> & parameters) {
|
||||
rcl_interfaces::msg::SetParametersResult result;
|
||||
result.successful = true;
|
||||
if (parameters.size() != 1) {
|
||||
result.successful = false;
|
||||
}
|
||||
|
||||
if (parameters[0].get_value<int>() != 40) {
|
||||
result.successful = false;
|
||||
}
|
||||
|
||||
// This should throw an exception
|
||||
node->declare_parameter("floatparam2", 5.6);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
EXPECT_EQ(node->set_on_parameters_set_callback(on_set_parameters), nullptr);
|
||||
EXPECT_THROW(
|
||||
{
|
||||
node->set_parameter(rclcpp::Parameter("intparam", 40));
|
||||
}, rclcpp::exceptions::ParameterModifiedInCallbackException);
|
||||
}
|
||||
|
||||
// test that calling undeclare_parameter inside a set_callback throws an exception
|
||||
TEST_F(TestNode, set_on_parameters_set_callback_undeclare_parameter) {
|
||||
auto node = std::make_shared<rclcpp::Node>("test_set_callback_undeclare_parameter_node"_unq);
|
||||
|
||||
int64_t intval = node->declare_parameter("intparam", 42);
|
||||
EXPECT_EQ(intval, 42);
|
||||
double floatval = node->declare_parameter("floatparam", 5.4);
|
||||
EXPECT_EQ(floatval, 5.4);
|
||||
|
||||
RCLCPP_SCOPE_EXIT({node->set_on_parameters_set_callback(nullptr);}); // always reset
|
||||
auto on_set_parameters =
|
||||
[&node](const std::vector<rclcpp::Parameter> & parameters) {
|
||||
rcl_interfaces::msg::SetParametersResult result;
|
||||
result.successful = true;
|
||||
if (parameters.size() != 1) {
|
||||
result.successful = false;
|
||||
}
|
||||
|
||||
if (parameters[0].get_value<int>() != 40) {
|
||||
result.successful = false;
|
||||
}
|
||||
|
||||
// This should throw an exception
|
||||
node->undeclare_parameter("floatparam");
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
EXPECT_EQ(node->set_on_parameters_set_callback(on_set_parameters), nullptr);
|
||||
EXPECT_THROW(
|
||||
{
|
||||
node->set_parameter(rclcpp::Parameter("intparam", 40));
|
||||
}, rclcpp::exceptions::ParameterModifiedInCallbackException);
|
||||
}
|
||||
|
||||
// test that calling set_on_parameters_set_callback from a set_callback throws an exception
|
||||
TEST_F(TestNode, set_on_parameters_set_callback_set_on_parameters_set_callback) {
|
||||
auto node = std::make_shared<rclcpp::Node>("test_set_callback_set_callback_node"_unq);
|
||||
|
||||
int64_t intval = node->declare_parameter("intparam", 42);
|
||||
EXPECT_EQ(intval, 42);
|
||||
double floatval = node->declare_parameter("floatparam", 5.4);
|
||||
EXPECT_EQ(floatval, 5.4);
|
||||
|
||||
RCLCPP_SCOPE_EXIT({node->set_on_parameters_set_callback(nullptr);}); // always reset
|
||||
auto on_set_parameters =
|
||||
[&node](const std::vector<rclcpp::Parameter> & parameters) {
|
||||
rcl_interfaces::msg::SetParametersResult result;
|
||||
result.successful = true;
|
||||
if (parameters.size() != 1) {
|
||||
result.successful = false;
|
||||
}
|
||||
|
||||
if (parameters[0].get_value<int>() != 40) {
|
||||
result.successful = false;
|
||||
}
|
||||
|
||||
auto bad_parameters =
|
||||
[](const std::vector<rclcpp::Parameter> & parameters) {
|
||||
(void)parameters;
|
||||
rcl_interfaces::msg::SetParametersResult result;
|
||||
return result;
|
||||
};
|
||||
|
||||
// This should throw an exception
|
||||
node->set_on_parameters_set_callback(bad_parameters);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
EXPECT_EQ(node->set_on_parameters_set_callback(on_set_parameters), nullptr);
|
||||
EXPECT_THROW(
|
||||
{
|
||||
node->set_parameter(rclcpp::Parameter("intparam", 40));
|
||||
}, rclcpp::exceptions::ParameterModifiedInCallbackException);
|
||||
}
|
||||
|
||||
// remove warning suppression
|
||||
#if !defined(_WIN32)
|
||||
# pragma GCC diagnostic pop
|
||||
#else // !defined(_WIN32)
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
void expect_qos_profile_eq(
|
||||
const rmw_qos_profile_t & qos1, const rmw_qos_profile_t & qos2, bool is_publisher)
|
||||
{
|
||||
|
||||
@@ -184,7 +184,7 @@ static std::vector<TestParameters> invalid_qos_profiles()
|
||||
return parameters;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
INSTANTIATE_TEST_CASE_P(
|
||||
TestPublisherThrows, TestPublisherInvalidIntraprocessQos,
|
||||
::testing::ValuesIn(invalid_qos_profiles()),
|
||||
::testing::PrintToStringParamName());
|
||||
|
||||
@@ -192,7 +192,7 @@ using AllTestDescriptions = ::testing::Types<
|
||||
TwoSubscriptionsInTwoContextsWithIntraprocessComm,
|
||||
TwoSubscriptionsInTwoContextsWithoutIntraprocessComm
|
||||
>;
|
||||
TYPED_TEST_SUITE(TestPublisherSubscriptionCount, AllTestDescriptions, PrintTestDescription);
|
||||
TYPED_TEST_CASE(TestPublisherSubscriptionCount, AllTestDescriptions, PrintTestDescription);
|
||||
|
||||
|
||||
using test_msgs::msg::Empty;
|
||||
|
||||
@@ -165,9 +165,6 @@ TEST(TestQoS, DerivedTypes) {
|
||||
rclcpp::ParameterEventsQoS parameter_events_qos;
|
||||
EXPECT_EQ(rmw_qos_profile_parameter_events, parameter_events_qos.get_rmw_qos_profile());
|
||||
|
||||
rclcpp::RosoutQoS rosout_qos;
|
||||
EXPECT_EQ(rcl_qos_profile_rosout_default, rosout_qos.get_rmw_qos_profile());
|
||||
|
||||
rclcpp::SystemDefaultsQoS system_default_qos;
|
||||
const rclcpp::KeepLast expected_initialization(RMW_QOS_POLICY_DEPTH_SYSTEM_DEFAULT);
|
||||
const rclcpp::QoS expected_default(expected_initialization);
|
||||
|
||||
@@ -218,11 +218,11 @@ TEST_F(TestQosEvent, test_default_incompatible_qos_callbacks)
|
||||
EXPECT_EQ("", sub_log_msg);
|
||||
} else {
|
||||
EXPECT_EQ(
|
||||
"New subscription discovered on topic '/ns/test_topic', requesting incompatible QoS. "
|
||||
"New subscription discovered on this topic, requesting incompatible QoS. "
|
||||
"No messages will be sent to it. Last incompatible policy: DURABILITY_QOS_POLICY",
|
||||
pub_log_msg);
|
||||
EXPECT_EQ(
|
||||
"New publisher discovered on topic '/ns/test_topic', offering incompatible QoS. "
|
||||
"New publisher discovered on this topic, offering incompatible QoS. "
|
||||
"No messages will be sent to it. Last incompatible policy: DURABILITY_QOS_POLICY",
|
||||
sub_log_msg);
|
||||
}
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
// Copyright 2020 Open Source Robotics Foundation, Inc.
|
||||
//
|
||||
// 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 <gtest/gtest.h>
|
||||
#include <memory>
|
||||
|
||||
#include "rclcpp/node_options.hpp"
|
||||
#include "rclcpp/qos.hpp"
|
||||
#include "rclcpp/duration.hpp"
|
||||
#include "rcl/logging_rosout.h"
|
||||
#include "rcl/init.h"
|
||||
#include "rmw/types.h"
|
||||
|
||||
bool operator==(
|
||||
const rmw_time_t & lhs,
|
||||
const rmw_time_t & rhs)
|
||||
{
|
||||
return lhs.sec == rhs.sec && lhs.nsec == rhs.nsec;
|
||||
}
|
||||
|
||||
bool operator==(
|
||||
const rmw_qos_profile_t & lhs,
|
||||
const rmw_qos_profile_t & rhs)
|
||||
{
|
||||
return lhs.history == rhs.history &&
|
||||
lhs.depth == rhs.depth &&
|
||||
lhs.reliability == rhs.reliability &&
|
||||
lhs.durability == rhs.durability &&
|
||||
lhs.deadline == rhs.deadline &&
|
||||
lhs.lifespan == rhs.lifespan &&
|
||||
lhs.liveliness == rhs.liveliness &&
|
||||
lhs.liveliness_lease_duration == rhs.liveliness_lease_duration &&
|
||||
lhs.avoid_ros_namespace_conventions == rhs.avoid_ros_namespace_conventions;
|
||||
}
|
||||
|
||||
bool operator!=(
|
||||
const rmw_qos_profile_t & lhs,
|
||||
const rmw_qos_profile_t & rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
/*
|
||||
Test rosout_qos function with default value.
|
||||
*/
|
||||
TEST(TestRosoutQoS, test_rosout_qos_with_default_value) {
|
||||
rclcpp::NodeOptions node_options;
|
||||
rclcpp::QoS rosout_qos_profile = node_options.rosout_qos();
|
||||
rmw_qos_profile_t rmw_qos_profile = rosout_qos_profile.get_rmw_qos_profile();
|
||||
EXPECT_EQ(rcl_qos_profile_rosout_default, rmw_qos_profile);
|
||||
EXPECT_EQ(rcl_qos_profile_rosout_default, node_options.get_rcl_node_options()->rosout_qos);
|
||||
}
|
||||
|
||||
/*
|
||||
Test `rosout_qos` function with custom value.
|
||||
*/
|
||||
TEST(TestRosoutQoS, test_rosout_qos_with_custom_value) {
|
||||
rmw_time_t life_span;
|
||||
life_span.sec = 10;
|
||||
life_span.nsec = 0;
|
||||
auto qos_profile = rclcpp::QoS(rclcpp::KeepLast(1000)).transient_local().lifespan(life_span);
|
||||
auto options = rclcpp::NodeOptions().rosout_qos(qos_profile);
|
||||
rclcpp::QoS rosout_qos = options.rosout_qos();
|
||||
rmw_qos_profile_t rmw_qos_profile = rosout_qos.get_rmw_qos_profile();
|
||||
|
||||
EXPECT_EQ(rmw_qos_profile, qos_profile.get_rmw_qos_profile());
|
||||
EXPECT_EQ(rmw_qos_profile, options.get_rcl_node_options()->rosout_qos);
|
||||
}
|
||||
@@ -506,7 +506,7 @@ static std::vector<TestParameters> invalid_qos_profiles()
|
||||
return parameters;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
INSTANTIATE_TEST_CASE_P(
|
||||
TestSubscriptionThrows, TestSubscriptionInvalidIntraprocessQos,
|
||||
::testing::ValuesIn(invalid_qos_profiles()),
|
||||
::testing::PrintToStringParamName());
|
||||
|
||||
@@ -129,7 +129,7 @@ struct TwoContextsPerTest
|
||||
};
|
||||
|
||||
using AllTestDescriptions = ::testing::Types<OneContextPerTest, TwoContextsPerTest>;
|
||||
TYPED_TEST_SUITE(TestSubscriptionPublisherCount, AllTestDescriptions, PrintTestDescription);
|
||||
TYPED_TEST_CASE(TestSubscriptionPublisherCount, AllTestDescriptions, PrintTestDescription);
|
||||
|
||||
|
||||
using test_msgs::msg::Empty;
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
@@ -31,8 +30,6 @@
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
bool logical_eq(const bool a, const bool b)
|
||||
{
|
||||
return (a && b) || ((!a) && !(b));
|
||||
@@ -224,7 +221,7 @@ TEST_F(TestTime, operators) {
|
||||
EXPECT_EQ(sub, young - old);
|
||||
|
||||
rclcpp::Time young_changed(young);
|
||||
young_changed -= rclcpp::Duration::from_nanoseconds(old.nanoseconds());
|
||||
young_changed -= rclcpp::Duration(old.nanoseconds());
|
||||
EXPECT_EQ(sub.nanoseconds(), young_changed.nanoseconds());
|
||||
|
||||
rclcpp::Time system_time(0, 0, RCL_SYSTEM_TIME);
|
||||
@@ -323,8 +320,8 @@ TEST_F(TestTime, overflow_detectors) {
|
||||
TEST_F(TestTime, overflows) {
|
||||
rclcpp::Time max_time(std::numeric_limits<rcl_time_point_value_t>::max());
|
||||
rclcpp::Time min_time(std::numeric_limits<rcl_time_point_value_t>::min());
|
||||
rclcpp::Duration one(1ns);
|
||||
rclcpp::Duration two(2ns);
|
||||
rclcpp::Duration one(1);
|
||||
rclcpp::Duration two(2);
|
||||
|
||||
// Cross min/max
|
||||
EXPECT_THROW(max_time + one, std::overflow_error);
|
||||
@@ -397,7 +394,7 @@ TEST_F(TestTime, test_assignment_operator_from_builtin_msg_time) {
|
||||
}
|
||||
|
||||
TEST_F(TestTime, test_sum_operator) {
|
||||
const rclcpp::Duration one(1ns);
|
||||
const rclcpp::Duration one(1);
|
||||
const rclcpp::Time test_time(0u);
|
||||
EXPECT_EQ(0u, test_time.nanoseconds());
|
||||
|
||||
@@ -409,41 +406,41 @@ TEST_F(TestTime, test_overflow_underflow_throws) {
|
||||
rclcpp::Time test_time(0u);
|
||||
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
test_time = rclcpp::Time(INT64_MAX) + rclcpp::Duration(1ns),
|
||||
test_time = rclcpp::Time(INT64_MAX) + rclcpp::Duration(1),
|
||||
std::overflow_error("addition leads to int64_t overflow"));
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
test_time = rclcpp::Time(INT64_MIN) + rclcpp::Duration(-1ns),
|
||||
test_time = rclcpp::Time(INT64_MIN) + rclcpp::Duration(-1),
|
||||
std::underflow_error("addition leads to int64_t underflow"));
|
||||
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
test_time = rclcpp::Time(INT64_MAX) - rclcpp::Duration(-1ns),
|
||||
test_time = rclcpp::Time(INT64_MAX) - rclcpp::Duration(-1),
|
||||
std::overflow_error("time subtraction leads to int64_t overflow"));
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
test_time = rclcpp::Time(INT64_MIN) - rclcpp::Duration(1ns),
|
||||
test_time = rclcpp::Time(INT64_MIN) - rclcpp::Duration(1),
|
||||
std::underflow_error("time subtraction leads to int64_t underflow"));
|
||||
|
||||
test_time = rclcpp::Time(INT64_MAX);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
test_time += rclcpp::Duration(1ns),
|
||||
test_time += rclcpp::Duration(1),
|
||||
std::overflow_error("addition leads to int64_t overflow"));
|
||||
test_time = rclcpp::Time(INT64_MIN);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
test_time += rclcpp::Duration(-1ns),
|
||||
test_time += rclcpp::Duration(-1),
|
||||
std::underflow_error("addition leads to int64_t underflow"));
|
||||
|
||||
test_time = rclcpp::Time(INT64_MAX);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
test_time -= rclcpp::Duration(-1ns),
|
||||
test_time -= rclcpp::Duration(-1),
|
||||
std::overflow_error("time subtraction leads to int64_t overflow"));
|
||||
test_time = rclcpp::Time(INT64_MIN);
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
test_time -= rclcpp::Duration(1ns),
|
||||
test_time -= rclcpp::Duration(1),
|
||||
std::underflow_error("time subtraction leads to int64_t underflow"));
|
||||
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
test_time = rclcpp::Duration::from_nanoseconds(INT64_MAX) + rclcpp::Time(1),
|
||||
test_time = rclcpp::Duration(INT64_MAX) + rclcpp::Time(1),
|
||||
std::overflow_error("addition leads to int64_t overflow"));
|
||||
RCLCPP_EXPECT_THROW_EQ(
|
||||
test_time = rclcpp::Duration::from_nanoseconds(INT64_MIN) + rclcpp::Time(-1),
|
||||
test_time = rclcpp::Duration(INT64_MIN) + rclcpp::Time(-1),
|
||||
std::underflow_error("addition leads to int64_t underflow"));
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user