la_mojo nodes and modules: register for events only when fully built #20

Merged
ClaudeAI merged 1 commits from fix/event-handler-attach-detach into master 50 minutes ago
Collaborator

Summary

Applies the attachEvents() / detachEvents() pattern from #19 to the la_mojo camera nodes and kernel modules. They now receive events only while fully constructed.

Problem

A handler was registered in the basicEventHandler constructor and removed in its destructor:

  • the constructor runs before the derived members exist;
  • the destructor runs after they are destroyed.

When a node or module was created or deleted while la_mojo runs (for example a node or module reload), the event heap could call dispatchEvent() on a half-built or half-destroyed object.

Changes

  • Camera nodes (deviceNodePTZCamControl, deviceNodePresetCamControl, deviceNodeStaticCamControl):
    • both constructors pass basicEventHandler(false) and call attachEvents() at their end;
    • the destructor calls detachEvents() first, before stopService().
  • Kernel modules:
    • kernelModule no longer registers in its constructor;
    • kernelModuleFactory attaches each module right after creating it, before startService(). All la_mojo modules are created there;
    • every module destructor calls detachEvents() first: USB relay, Kafka, FlyHunter, SSDP, ONVIF observer, embed video (both variants), modem manager, Bosch, attention cloud and report backupper.
  • basicEventHeap::moveHandlerTop/Bottom no longer register a handler that is not registered. Otherwise an object could end up registered twice once attachEvents() runs.

Sensor nodes are not event handlers and are unchanged. Handlers are still added at the bottom of the list at almost the same moment, so the dispatch order is unchanged.

Testing

  • la_mojo Debug86: full make -k and link. Only the three live555 files cannot compile in the build container, as before. One of them is kernelModuleEmbedVideo.cpp; its two one-line destructor edits were reviewed by hand.
  • No new warnings.
  • Event heap tests (AddressSanitizer): all pass, including the stress test where handlers using this pattern are created and deleted while events flow.

Notes

  • New modules: a module created outside kernelModuleFactory receives no events until attachEvents() is called on it.
  • Not changed: kernelEventFilterBubble, kernelEventFilterYOLO and the kernel keep the automatic registration. They are not deleted while la_mojo runs, and #19 pauses the heap before shutdown.

Generated with Claude Code

https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16

## Summary Applies the `attachEvents()` / `detachEvents()` pattern from #19 to the la_mojo camera nodes and kernel modules. They now receive events only while fully constructed. ## Problem A handler was registered in the `basicEventHandler` constructor and removed in its destructor: - the constructor runs before the derived members exist; - the destructor runs after they are destroyed. When a node or module was created or deleted while la_mojo runs (for example a node or module reload), the event heap could call `dispatchEvent()` on a half-built or half-destroyed object. ## Changes - **Camera nodes** (`deviceNodePTZCamControl`, `deviceNodePresetCamControl`, `deviceNodeStaticCamControl`): - both constructors pass `basicEventHandler(false)` and call `attachEvents()` at their end; - the destructor calls `detachEvents()` first, before `stopService()`. - **Kernel modules:** - `kernelModule` no longer registers in its constructor; - `kernelModuleFactory` attaches each module right after creating it, before `startService()`. All la_mojo modules are created there; - every module destructor calls `detachEvents()` first: USB relay, Kafka, FlyHunter, SSDP, ONVIF observer, embed video (both variants), modem manager, Bosch, attention cloud and report backupper. - **`basicEventHeap::moveHandlerTop/Bottom`** no longer register a handler that is not registered. Otherwise an object could end up registered twice once `attachEvents()` runs. Sensor nodes are not event handlers and are unchanged. Handlers are still added at the bottom of the list at almost the same moment, so the dispatch order is unchanged. ## Testing - **la_mojo Debug86:** full `make -k` and link. Only the three live555 files cannot compile in the build container, as before. One of them is `kernelModuleEmbedVideo.cpp`; its two one-line destructor edits were reviewed by hand. - **No new warnings.** - **Event heap tests (AddressSanitizer):** all pass, including the stress test where handlers using this pattern are created and deleted while events flow. ## Notes - **New modules:** a module created outside `kernelModuleFactory` receives no events until `attachEvents()` is called on it. - **Not changed:** `kernelEventFilterBubble`, `kernelEventFilterYOLO` and the kernel keep the automatic registration. They are not deleted while la_mojo runs, and #19 pauses the heap before shutdown. Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
ClaudeAI added 1 commit 51 minutes ago
a327104ed7
la_mojo nodes and modules: register for events only when fully built
ClaudeAI merged commit d5e172fc4b into master 50 minutes ago
The pull request has been merged as d5e172fc4b.
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This pull request currently doesn't have any dependencies.

Loading…
There is no content yet.