Repository navigation
feat: C ABI expansion to the full engine surface (p6-s1) (#35) - #87
Merged
Merged
Conversation
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
4 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Everything the C++ engine exposes is now reachable from C.
New entry points
scn_abi_version(),SCN_ABI_VERSIONmajor*10000+minor, so a host thatdlopen()s the library can refuse an incompatible major before calling anythingscn_engine_load_xml_file/_stringscn_engine_entity_count/_entity_id_atscn_engine_element_state/_element_transitionscn_element_state/scn_element_transitionenumsscn_engine_set_traffic_signal_statescn_engine_get_time,scn_engine_initializedDiagnostics from a one-call load
The frontend's findings and
init's findings belong in one list, in the orderthey 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::prependis the one deviation from "insertion order is reportorder", 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_*, anda re-init after
closeworks the same way.Kernel additions
Engine::entity_ids()(ascending — reusing thestd::mapthe determinismcontract already requires),
Engine::set_traffic_signal_state(),Engine::prepend_diagnostics(), andDiagnosticSink::take/prepend. All boundin Python, with a
python/examples/host_queries.pythat walks the same surfaceand now runs in CI.
capi/linksscena::frontend-xml— PRIVATE, likescena::core: no frontend orkernel type appears in
capi.h.Tests
capi/tests/c_consumer.c— a pure-C (C11, no C++ anywhere) embedding thatloads 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.cppgrows 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