-
Notifications
You must be signed in to change notification settings - Fork 9
Autoremove EventHandler from parent entity #16
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -64,16 +64,19 @@ public class EventHandlerImpl< | |||||||||
| * @param eventStatusFactory Factory of an event status. | ||||||||||
| * @param callback The callback function that will be called when the event | ||||||||||
| * is triggered. | ||||||||||
| * @param removeCallback Callback that will be called when this object is being disposed. | ||||||||||
| */ | ||||||||||
| public EventHandlerImpl( | ||||||||||
| final WeakReference<ParentT> parentReference, | ||||||||||
| final long handle, | ||||||||||
| final Supplier<T> eventStatusFactory, | ||||||||||
| final Consumer<T> callback) { | ||||||||||
| final Consumer<T> callback, | ||||||||||
| final Consumer<EventHandler> removeCallback) { | ||||||||||
| this.parentReference = parentReference; | ||||||||||
| this.handle = handle; | ||||||||||
| this.eventStatusFactory = eventStatusFactory; | ||||||||||
| this.callback = callback; | ||||||||||
| this.removeCallback = removeCallback; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
|
|
@@ -102,9 +105,11 @@ public final long getHandle() { | |||||||||
| * {@inheritDoc} | ||||||||||
| */ | ||||||||||
| public synchronized final void dispose() { | ||||||||||
| if (this.handle != 0) { | ||||||||||
| nativeDispose(this.handle); | ||||||||||
| if (this.handle == 0) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
| this.removeCallback.accept(this); | ||||||||||
|
||||||||||
| if (node_handle == 0) { | |
| // TODO(esteve): handle this, node is null, but publisher isn't | |
| return; | |
| } |
About:
node.dispose()
pub.publish()
I think that one is UB, as the node has been destroyed and not the publisher (it likely depends on the rmw implementation).
We can leave this PR as-is and I'll have to revisit my approach in ros2-java#110 (with some more unit tests).
👍
Uh oh!
There was an error while loading. Please reload this page.