Skip to content

Add heap-free mw::com skeleton and proxy examples#692

Open
jorgecasal wants to merge 21 commits into
eclipse-score:mainfrom
etas-contrib:jorgecasal/heap-free-examples
Open

Add heap-free mw::com skeleton and proxy examples#692
jorgecasal wants to merge 21 commits into
eclipse-score:mainfrom
etas-contrib:jorgecasal/heap-free-examples

Conversation

@jorgecasal

@jorgecasal jorgecasal commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

This pull request adds examples that show how to use the mw::com provider (skeleton) and consumer (proxy) sides without allocating on the heap during the operational phase.

The examples are integrated into the mw::com tutorial as chapter 12, under score/mw/com/doc/tutorial/chapter_12/. They are registered in the tutorial build and documentation (score/mw/com/doc/tutorial/BUILD and README.rst), so they render as part of the existing tutorial.

Structure

Chapter 12 contains four self-contained scenarios. Each scenario has its own sources, config, logging config, and build file so it can be built and run on its own:

  • event_send_receive: provider sends events, consumer receives them.
  • event_field_update: provider updates a field, consumer reads it.
  • start_find_service: consumer finds a service, then uses it.
  • bidirectional_discovery: two applications (application_a / application_b) that both provide and consume.

Each scenario splits the two sides into provider and consumer (the bidirectional scenario uses application_a / application_b). A shared service interface lives in common/service_interface.h.

A small helper in heap_check/heap_check.h verifies that no heap allocation happens once the operational phase begins. It overrides operator new/delete and aborts on any allocation after the init/operational boundary.

Known limitation

The async receive handler cannot yet run without the heap, because the provider side allocates when a consumer registers a receive handler. This is a known framework limit (see the TODO in scoped_event_receive_handler.h). The examples use polling instead.

jorgecasal added 13 commits July 2, 2026 17:02
Add four example binaries demonstrating heap-free usage of the
score::mw::com API for ASIL-B/FFI components:

- event_send_receive/skeleton: zero-copy event send via SHM ring buffer
- event_send_receive/proxy: service discovery and subscription
- event_field_update/skeleton: event and field update without heap
- event_field_update/proxy: polling receive for events and fields

Each example uses a two-phase model where all allocating API calls
(Create, OfferService, Subscribe, FindService) happen during init,
and the operational phase uses only shared-memory-backed operations
(Allocate, Send, GetNewSamples, Update). A lightweight operator new
override in heap_check.h aborts on any heap allocation after
forbid_heap() is called, verifying the constraint at runtime.
Rename examples:: namespace to sensor:: across all heap-free example
sources and update include guard to follow path-based convention.
Add tags = ["lint"] to validate_json_schema_test targets.
Remove redundant comments that restate what the code already says.
Deduplicate BUILD and .cpp header summaries — .cpp is now canonical.
Add "Run alongside the skeleton" note to proxy file headers.
Replace SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE with the idiomatic
if (!result.has_value()) { LogError; return EXIT_FAILURE; } pattern for
Result<T> checks, matching the ipc_bridge example. Operational-phase error
returns call allow_heap() before returning so teardown stays valid. Remove
redundant comments already covered by the README.
Both applications concurrently offer their own service and discover the
other via StartFindService without deadlocking. Document as Pair D in the
heap-free README.
Add a skeleton to the start_find_service example so it runs in isolation
like the other heap-free groups, instead of depending on the
event_send_receive skeleton.
…xamples

# Conflicts:
#	module_integration_test/MODULE.bazel.lock
Moves the heap-free mw::com examples from the top-level examples/ tree
into score/mw/com/doc/tutorial/chapter_12/, integrating them as a proper
tutorial chapter with README.rst and BUILD targets.
@jorgecasal jorgecasal force-pushed the jorgecasal/heap-free-examples branch from b264220 to c971ffa Compare July 15, 2026 06:14
Explain why OfferService() must precede Proxy::Create() and forbid_heap():
Proxy::Create() allocates heap and can only succeed after the provider has
offered its service.
Align chapter_12 examples with the sibling tutorial chapters by
replacing init-phase has_value() guards with
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant