Implement native plugin cycle hooks for real-time PLC synchronization#53
Conversation
- Add plugin_driver_cycle_start() and plugin_driver_cycle_end() functions - Integrate cycle hooks into PLC scan cycle in plc_state_manager.c - Call cycle_start before PLC logic execution, cycle_end after - Plugins opt-in by implementing cycle_start/cycle_end; opt-out by not implementing - Only active (enabled + running) native plugins are called - Update README.md with comprehensive cycle hooks documentation - Add cycle hook functions to API Reference section Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
Pull request overview
This PR implements real-time synchronization hooks for native plugins by integrating cycle_start() and cycle_end() functions into the PLC scan cycle. These hooks, which were previously loaded but never invoked, now allow native plugins to execute code in lockstep with the PLC's scan cycle while the buffer mutex is held.
Key changes:
- Added
plugin_driver_cycle_start()andplugin_driver_cycle_end()functions that iterate through active native plugins and invoke their registered hooks - Integrated cycle hooks into the PLC scan cycle with
cycle_startcalled before PLC logic execution andcycle_endcalled after - Enhanced documentation with comprehensive guidance on cycle hook usage, timing considerations, and the opt-in/opt-out pattern
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| core/src/plc_app/plc_state_manager.c | Integrated cycle hook calls into the PLC scan cycle thread between mutex lock/unlock operations |
| core/src/drivers/plugin_driver.h | Added function declarations for the new cycle hook driver functions |
| core/src/drivers/plugin_driver.c | Implemented the cycle hook iteration logic with NULL pointer checks and plugin state validation |
| core/src/drivers/README.md | Updated documentation to describe cycle hook usage patterns, real-time considerations, and provided implementation examples |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| ``` | ||
|
|
||
| 3. **Memory Management (Python):** |
There was a problem hiding this comment.
The section numbering is incorrect. This should be section 4, not 3, as section 3 is now 'Native Plugin Cycle Hooks (Real-Time Synchronization)' starting at line 653.
| 3. **Memory Management (Python):** | |
| 4. **Memory Management (Python):** |
There was a problem hiding this comment.
Devin, can you check this please?
There was a problem hiding this comment.
Good catch! I've fixed the section numbering - "Memory Management (Python)" is now correctly numbered as section 4. The fix has been pushed in commit 0c0c9a6.
Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
Implement native plugin cycle hooks for real-time PLC synchronization
Summary
This PR implements the
cycle_start()andcycle_end()hooks for native plugins, allowing them to synchronize with the PLC scan cycle in real-time. Previously, these hooks were loaded viadlsymbut never actually invoked.Key changes:
plugin_driver_cycle_start()andplugin_driver_cycle_end()functions that iterate through all active native plugins and call their registered hooksplc_state_manager.c-cycle_startis called before PLC logic execution,cycle_endafterUpdates since last revision
Review & Testing Checklist for Human
test_plugin.cin examples) that implementscycle_start()andcycle_end(), verify they are called each scan cycleplugin_mutex_takeandplugin_mutex_give)Recommended test plan:
plugins/native/examples/test_plugin.cto add print statements or counters incycle_start()andcycle_end()plugins.confwithtype=1Notes
Link to Devin run: https://app.devin.ai/sessions/7bb7a40970384ea79ffea4adc955a73a
Requested by: Thiago Alves (@thiagoralves)