Skip to content

Latest commit

 

History

History
99 lines (71 loc) · 3.44 KB

File metadata and controls

99 lines (71 loc) · 3.44 KB

EventBus Delivery Notes

English | 简体中文

Delivered Files

Core files:

  • eventbus.hpp: single-header EventBus implementation.
  • simple_test.cpp: basic behavior and key-semantics tests.
  • test_full.cpp: complete behavior, statistics, conditional publishing, and thread-safety examples.
  • test_complex_types.cpp: complex payload-type tests.
  • example_simple.cpp: application-style usage examples.

Build and run support:

  • CMakeLists.txt: CMake targets and CTest tests.
  • build.bat: Windows build script.
  • demo.bat: demonstration script.

Documentation:

  • ../README.md: complete usage and API reference.
  • QUICK_START.md: quick-start guide.
  • PROJECT_SUMMARY.md: current technical implementation summary.
  • DELIVERY_NOTES.md: these delivery notes.

Current API Highlights

eventbus::EventBus bus;

auto id = bus.subscribe("event", [](const std::string& value) {
    std::cout << value << "\n";
});

auto result = bus.publish("event", "payload");

(void)bus.unsubscribe("event", id);

EventBus does not serialize subscription callbacks. Applications are responsible for synchronizing shared state inside their callbacks.

Stateless callbacks, or callbacks with internal synchronization, can be subscribed directly:

bus.subscribe("fast", [](int value) {
    (void)value;
});

The same callback may be invoked concurrently by multiple publishing threads.

Verified Capabilities

  • Thread-safe subscription, publishing, and unsubscription from multiple threads.
  • Concurrent callback execution by default, with no callback-level execution lock.
  • publish() returns a PublishResult.
  • Callback exceptions are counted as failures.
  • Type mismatches are counted.
  • const char* to std::string / std::string_view conversion.
  • std::string to std::string_view conversion.
  • Complex STL types and custom payload types.
  • Unsubscription waits for callbacks already in progress to finish.

Build Validation

Recommended validation command:

cmake -S . -B build
cmake --build build --config Debug
ctest --test-dir build -C Debug --output-on-failure --timeout 30

Additional compilation checks used:

g++ -std=c++17 -Wall -Wextra -Wpedantic -I. -c simple_test.cpp -o build/simple_test_gcc.o
g++ -std=c++17 -Wall -Wextra -Wpedantic -I. -c test_full.cpp -o build/test_full_gcc.o
g++ -std=c++17 -Wall -Wextra -Wpedantic -I. -c test_complex_types.cpp -o build/test_complex_types_gcc.o

Integration Considerations

  • Include only eventbus.hpp.
  • Callbacks must return void.
  • Callbacks cannot use non-const lvalue-reference parameters.
  • publish() is synchronous; it is not an asynchronous post operation.
  • Large payloads are copied or moved into the dispatch tuple. Prefer std::shared_ptr<const T> or a const T* with an explicit lifetime.
  • Bind member-function callbacks with a lambda and ensure the object's lifetime covers the subscription.
  • unsubscribe(), unsubscribe_all(), and clear() may wait for callbacks in progress. Evaluate their latency impact before calling them on latency-sensitive threads.

Current Limitations

  • The event-name API still uses const std::string&.
  • Hot paths still incur std::any type-erasure and argument-packing costs.
  • The current version does not provide an asynchronous executor, task queue, or backpressure.
  • No production benchmark report is included. Measure performance with a dedicated benchmark on the target platform.