Skip to content

feat(sdk): add on_data_changed hook to toolbox vtable#63

Merged
pabloinigoblasco merged 2 commits into
developmentfrom
feat/toolbox-on-data-changed-hook
Apr 20, 2026
Merged

feat(sdk): add on_data_changed hook to toolbox vtable#63
pabloinigoblasco merged 2 commits into
developmentfrom
feat/toolbox-on-data-changed-hook

Conversation

@pabloinigoblasco
Copy link
Copy Markdown
Collaborator

Summary

Add an optional on_data_changed(void* ctx) hook at the end of PJ_toolbox_vtable_t. Mirrors the existing on_time_changed hook pattern for data-change events.

What

  • ABIPJ_toolbox_vtable_t gains a new slot on_data_changed at the end of the struct (opt-in; host NULL-checks before calling).
  • C++ SDKToolboxPluginBase exposes a virtual onDataChanged() with a no-op default. Subclasses override it to react to newly appended data (e.g. recompute a transform over just the delta).
  • Trampolinetrampoline_on_data_changed catches exceptions across the C ABI boundary.
  • HostToolboxHandle::onDataChanged() forwards through the vtable; safe no-op when the plugin doesn't set the slot.

Opt-in

Plugins that don't override the virtual pay no cost and the host never invokes the slot. Backward compatible with plugins compiled against the prior vtable.

Test plan

  • toolbox_plugin_test covers direct invocation through the ABI, no-op path when not overridden, and correct forwarding from ToolboxHandle.
  • Exception safety case (trampoline catches).
  • Mock toolbox (pj_plugins/examples/mock_toolbox.cpp) gains a onDataChanged counter for testing.

Downstream

An incoming follow-up on pj-official-plugins uses this hook in the Quaternion toolbox to re-apply the RPY transform only over newly appended samples (matching PJ 3.x's reactive behaviour).

Mirrors the on_time_changed SDK hook pattern for data-change events:

- PJ_toolbox_vtable_t gains a new slot on_data_changed(void* ctx) at the end of the struct.
- ToolboxPluginBase exposes a virtual onDataChanged() with a no-op default; subclasses override it to react to appended data (e.g., recompute a transform on only the newly committed points).
- trampoline_on_data_changed catches exceptions across the C ABI boundary.
- Host side: ToolboxHandle.onDataChanged() forwards through the vtable when the slot is set; null-check protects older plugins.

Opt-in: plugins that don't override the virtual pay no cost; the host never calls the slot for them. Tests and mock_toolbox cover the wiring.
Add a notifyDataChanged counter to MockToolbox and extend toolbox_plugin_test.cpp with cases that exercise the new hook through the C ABI: direct invocation, no-op when plugin doesn't override, and correct forwarding from ToolboxHandle.
@pabloinigoblasco pabloinigoblasco merged commit fa66afd into development Apr 20, 2026
2 checks passed
@pabloinigoblasco pabloinigoblasco deleted the feat/toolbox-on-data-changed-hook branch May 4, 2026 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant