-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use weak_ptr to avoid circular dependency in panther_battery package #310
Conversation
…os2-fix-circular-dependency
WalkthroughThe recent updates to the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- panther_battery/include/panther_battery/battery_publisher.hpp (1 hunks)
- panther_battery/src/battery_publisher.cpp (5 hunks)
- panther_battery/src/dual_battery_publisher.cpp (2 hunks)
- panther_battery/src/single_battery_publisher.cpp (2 hunks)
Additional comments not posted (13)
panther_battery/include/panther_battery/battery_publisher.hpp (3)
52-53
: Removedconst
qualifiers fromTimeoutReached
andBatteryStatusLogger
.This change aligns with the PR's objective to modify method signatures for better flexibility in method usage.
57-59
: IntroducedGetLogger
andGetClock
methods.These methods provide centralized access to logging and clock functionalities, improving code maintainability and reducing redundancy.
60-60
: Changednode_
fromSharedPtr
toWeakPtr
.This change helps avoid circular dependencies and potential memory leaks, aligning with modern C++ best practices for smart pointer usage.
panther_battery/src/single_battery_publisher.cpp (3)
38-39
: Updated publisher initialization to usenode->
instead ofnode_->
.This change reflects the updated pointer type (
WeakPtr
) and ensures that the object is accessed correctly.
44-44
: Updated to useGetClock()
for obtaining the current time.Using
GetClock()
centralizes clock access, enhancing code consistency and maintainability.Also applies to: 50-50
66-66
: UtilizedGetLogger()
andGetClock()
in logging function.This usage promotes consistency and reduces direct dependency on the node object, aligning with the changes made in the class definition.
panther_battery/src/battery_publisher.cpp (4)
32-33
: Updated parameter declaration and subscription creation to usenode->
.Reflects the change to
WeakPtr
, ensuring that the node is accessed correctly.Also applies to: 38-38
50-53
: Updated to useGetClock()
andGetLogger()
in thePublish
method.Enhances consistency and maintainability by centralizing access to logging and clock functionalities.
68-70
: UpdatedTimeoutReached
andBatteryStatusLogger
to useGetClock()
andGetLogger()
.These changes are consistent with the objective of reducing direct dependencies on the node object and improving code maintainability.
Also applies to: 74-97
125-139
: ImplementedGetLogger()
andGetClock()
methods.These methods provide a safe way to access the node's logger and clock, handling the possibility of the node being expired.
panther_battery/src/dual_battery_publisher.cpp (3)
41-43
: Updated publisher initialization to usenode->
instead ofnode_->
.This change reflects the updated pointer type (
WeakPtr
) and ensures that the object is accessed correctly.
48-48
: Updated to useGetClock()
for obtaining the current time.Using
GetClock()
centralizes clock access, enhancing code consistency and maintainability.Also applies to: 55-55
74-78
: UtilizedGetLogger()
andGetClock()
in logging function.This usage promotes consistency and reduces direct dependency on the node object, aligning with the changes made in the class definition.
rclcpp::Logger GetLogger(); | ||
rclcpp::Clock::SharedPtr GetClock(); | ||
|
||
rclcpp::Node::WeakPtr node_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add info to do not forget why is that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small suggestion rest is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- panther_battery/include/panther_battery/battery_publisher.hpp (1 hunks)
- panther_battery/src/battery_publisher.cpp (5 hunks)
Files skipped from review as they are similar to previous changes (2)
- panther_battery/include/panther_battery/battery_publisher.hpp
- panther_battery/src/battery_publisher.cpp
Summary by CodeRabbit
New Features
Refactor
Bug Fixes