Skip to content

feat: C ABI expansion to the full engine surface (p6-s1) (#35) - #87

Merged
JArmandoAnaya merged 1 commit into
mainfrom
feat/p6-s1-capi-expansion
Aug 1, 2026
Merged

JArmandoAnaya merged 1 commit into
mainfrom
feat/p6-s1-capi-expansion

Conversation

@JArmandoAnaya

Copy link
Copy Markdown
Contributor

Everything the C++ engine exposes is now reachable from C.

New entry points

Symbol What it gives C
scn_abi_version(), SCN_ABI_VERSION ABI version as major*10000+minor, so a host that dlopen()s the library can refuse an incompatible major before calling anything
scn_engine_load_xml_file / _string load an OpenSCENARIO XML document and initialize, in one call
scn_engine_entity_count / _entity_id_at enumerate entities without knowing their names, in ascending id order
scn_engine_element_state / _element_transition storyboard-element lifecycle by path, with scn_element_state / scn_element_transition enums
scn_engine_set_traffic_signal_state publish a signal's state from the host side
scn_engine_get_time, scn_engine_initialized simulation time and lifecycle

Diagnostics from a one-call load

The frontend's findings and init's findings belong in one list, in the order
they happened — from C there is one call, so there should be one place to look.
init() clears the list, so the load's findings are prepended afterwards.
DiagnosticSink::prepend is the one deviation from "insertion order is report
order", and it exists to restore that order rather than break it.

A loaded scenario also becomes the builder scenario, so the entity metadata
accessors read it exactly as they read one built through scn_engine_add_*, and
a re-init after close works the same way.

Kernel additions

Engine::entity_ids() (ascending — reusing the std::map the determinism
contract already requires), Engine::set_traffic_signal_state(),
Engine::prepend_diagnostics(), and DiagnosticSink::take/prepend. All bound
in Python, with a python/examples/host_queries.py that walks the same surface
and now runs in CI.

capi/ links scena::frontend-xml — PRIVATE, like scena::core: no frontend or
kernel type appears in capi.h.

Tests

  • capi/tests/c_consumer.c — a pure-C (C11, no C++ anywhere) embedding that
    loads a scenario, enumerates entities, watches an element, publishes a signal
    and steps. Compiled and run as a ctest case, so the header being parseable by
    a C compiler is checked on macOS, Linux and Windows and is not mistaken for the
    library being callable. That is the sprint's exit criterion.
  • capi_test.cpp grows 8 cases: ABI version, load from string / bad string /
    missing file, entity enumeration (including the borrowed-string lifetime, which
    the test demonstrates rather than assumes), element state and transition,
    host signal publication, simulation time, and a null-argument sweep over
    every new entry point with each pointer nulled in turn.

919 → 929 gtest, 166 → 167 pytest. Docs: a new
C API guide page covering versioning, the one-call
load, enumeration, element paths, signals and the borrowed-string rule.

Local: 929/929 gtest, 167/167 pytest, pure-C consumer green, detmath guard,
coverage-matrix checker and clang-format green.

Closes #35

Everything the C++ engine exposes is now reachable from C.

New: scn_abi_version() + SCN_ABI_VERSION (major*10000+minor, so a host that
dlopen()s the library can refuse an incompatible major before calling
anything); scn_engine_load_xml_file/_string, which load an OpenSCENARIO XML
document AND initialize in one call; entity enumeration
(scn_engine_entity_count / _entity_id_at, ascending id order so an index
names the same entity everywhere); storyboard-element state and transition
by path; host-side traffic-signal publication;
scn_engine_get_time / _initialized.

Loading puts the frontend's findings and init's findings in one list, in
the order they happened. init() clears the list, so the load's findings are
prepended after it — DiagnosticSink::prepend is the one deviation from
'insertion order is report order', and it exists to restore that order
rather than break it. A loaded scenario also becomes the builder scenario,
so the entity metadata accessors read it exactly as they read one built
through scn_engine_add_*.

Kernel additions behind it: Engine::entity_ids() (ascending, reusing the
std::map the determinism contract already requires),
Engine::set_traffic_signal_state(), Engine::prepend_diagnostics(), and
DiagnosticSink::take/prepend. All bound in Python with a host_queries.py
example.

capi/ now links scena::frontend-xml — PRIVATE, like scena::core: no
frontend or kernel type appears in capi.h.

Tests: capi/tests/c_consumer.c is a pure-C (C11) embedding compiled and RUN
as a ctest case, which is what keeps the header C-clean on all three
platforms; capi_test.cpp grows 8 cases including a null-argument sweep over
every new entry point. 929 gtest + 167 pytest. Docs: a new C API guide page.

Closes #35
@JArmandoAnaya
JArmandoAnaya merged commit 548c194 into main Aug 1, 2026
9 checks passed
@JArmandoAnaya
JArmandoAnaya deleted the feat/p6-s1-capi-expansion branch August 1, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[p6-s1] C ABI expansion to the full engine surface

1 participant