## Breaking Change
IIO API redesigned from manual pull+if-forest to callback dispatch.
All modules must update their subscribe() calls to pass handlers.
### Before (OLD API)
```cpp
io->subscribe("input:mouse");
void process(...) {
while (io->hasMessages()) {
auto msg = io->pullMessage();
if (msg.topic == "input:mouse") {
handleMouse(msg);
} else if (msg.topic == "input:keyboard") {
handleKeyboard(msg);
}
}
}
```
### After (NEW API)
```cpp
io->subscribe("input:mouse", [this](const Message& msg) {
handleMouse(msg);
});
void process(...) {
while (io->hasMessages()) {
io->pullAndDispatch(); // Callbacks invoked automatically
}
}
```
## Changes
**Core API (include/grove/IIO.h)**
- Added: `using MessageHandler = std::function<void(const Message&)>`
- Changed: `subscribe()` now requires `MessageHandler` callback parameter
- Changed: `subscribeLowFreq()` now requires `MessageHandler` callback
- Removed: `pullMessage()`
- Added: `pullAndDispatch()` - pulls and auto-dispatches to handlers
**Implementation (src/IntraIO.cpp)**
- Store callbacks in `Subscription.handler`
- `pullAndDispatch()` matches topic against ALL subscriptions (not just first)
- Fixed: Regex pattern compilation supports both wildcards (*) and regex (.*)
- Performance: ~1000 msg/s throughput (unchanged from before)
**Files Updated**
- 31 test/module files migrated to callback API (via parallel agents)
- 8 documentation files updated (DEVELOPER_GUIDE, USER_GUIDE, module READMEs)
## Bugs Fixed During Migration
1. **pullAndDispatch() early return bug**: Was only calling FIRST matching handler
- Fix: Loop through ALL subscriptions, invoke all matching handlers
2. **Regex pattern compilation bug**: Pattern "player:.*" failed to match
- Fix: Detect ".*" in pattern → use as regex, otherwise escape and convert wildcards
## Testing
✅ test_11_io_system: PASSED (IIO pub/sub, pattern matching, batching)
✅ test_threaded_module_system: 6/6 PASSED
✅ test_threaded_stress: 5/5 PASSED (50 modules, 100x reload, concurrent ops)
✅ test_12_datanode: PASSED
✅ 10 TopicTree scenarios: 10/10 PASSED
✅ benchmark_e2e: ~1000 msg/s throughput
Total: 23+ tests passing
## Performance Impact
No performance regression from callback dispatch:
- IIO throughput: ~1000 msg/s (same as before)
- ThreadedModuleSystem: Speedup ~1.0x (barrier pattern expected)
## Migration Guide
For all modules using IIO:
1. Update subscribe() calls to include handler lambda
2. Replace pullMessage() loops with pullAndDispatch()
3. Move topic-specific logic from if-forest into callbacks
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
88 lines
3.1 KiB
C++
88 lines
3.1 KiB
C++
/**
|
|
* IT_015 Minimal: UIModule Input Integration (Minimal Version)
|
|
*
|
|
* This is a minimal test that verifies IIO message publishing works
|
|
* without loading actual modules (to avoid DLL loading issues on Windows)
|
|
*/
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
#include <grove/IntraIOManager.h>
|
|
#include <grove/IntraIO.h>
|
|
#include <grove/JsonDataNode.h>
|
|
#include <iostream>
|
|
|
|
using namespace grove;
|
|
|
|
TEST_CASE("IT_015_Minimal: IIO Message Publishing", "[integration][input][ui][minimal]") {
|
|
std::cout << "\n========================================\n";
|
|
std::cout << "IT_015 Minimal: IIO Test\n";
|
|
std::cout << "========================================\n\n";
|
|
|
|
auto& ioManager = IntraIOManager::getInstance();
|
|
|
|
// Create IIO instances
|
|
auto publisher = ioManager.createInstance("publisher");
|
|
auto subscriber = ioManager.createInstance("subscriber");
|
|
|
|
int mouseMoveCount = 0;
|
|
int mouseButtonCount = 0;
|
|
int keyboardKeyCount = 0;
|
|
|
|
// Subscribe to input events with callbacks
|
|
subscriber->subscribe("input:mouse:move", [&](const Message& msg) {
|
|
mouseMoveCount++;
|
|
int x = msg.data->getInt("x", 0);
|
|
int y = msg.data->getInt("y", 0);
|
|
std::cout << "✅ Received input:mouse:move (" << x << ", " << y << ")\n";
|
|
});
|
|
subscriber->subscribe("input:mouse:button", [&](const Message& msg) {
|
|
mouseButtonCount++;
|
|
std::cout << "✅ Received input:mouse:button\n";
|
|
});
|
|
subscriber->subscribe("input:keyboard:key", [&](const Message& msg) {
|
|
keyboardKeyCount++;
|
|
std::cout << "✅ Received input:keyboard:key\n";
|
|
});
|
|
|
|
// Publish input events
|
|
std::cout << "Publishing input events...\n";
|
|
|
|
// Mouse move
|
|
auto mouseMoveData = std::make_unique<JsonDataNode>("data");
|
|
mouseMoveData->setInt("x", 400);
|
|
mouseMoveData->setInt("y", 300);
|
|
publisher->publish("input:mouse:move", std::move(mouseMoveData));
|
|
|
|
// Mouse button
|
|
auto mouseButtonData = std::make_unique<JsonDataNode>("data");
|
|
mouseButtonData->setInt("button", 0);
|
|
mouseButtonData->setBool("pressed", true);
|
|
mouseButtonData->setInt("x", 100);
|
|
mouseButtonData->setInt("y", 100);
|
|
publisher->publish("input:mouse:button", std::move(mouseButtonData));
|
|
|
|
// Keyboard key
|
|
auto keyData = std::make_unique<JsonDataNode>("data");
|
|
keyData->setInt("scancode", 44); // Space
|
|
keyData->setBool("pressed", true);
|
|
publisher->publish("input:keyboard:key", std::move(keyData));
|
|
|
|
// Dispatch messages to trigger callbacks
|
|
while (subscriber->hasMessages() > 0) {
|
|
subscriber->pullAndDispatch();
|
|
}
|
|
|
|
// Verify
|
|
std::cout << "\nResults:\n";
|
|
std::cout << " - Mouse moves: " << mouseMoveCount << "\n";
|
|
std::cout << " - Mouse buttons: " << mouseButtonCount << "\n";
|
|
std::cout << " - Keyboard keys: " << keyboardKeyCount << "\n";
|
|
|
|
REQUIRE(mouseMoveCount == 1);
|
|
REQUIRE(mouseButtonCount == 1);
|
|
REQUIRE(keyboardKeyCount == 1);
|
|
|
|
std::cout << "\n✅ IT_015_Minimal: Test PASSED\n";
|
|
std::cout << "========================================\n\n";
|
|
}
|