![]() |
OpenSWMM Engine
6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
|
Public C API implementation for simulation checkpoints. More...
#include <openswmm/engine/openswmm_checkpoint.h>#include "SWMMEngine.hpp"#include "CheckpointInspection.hpp"#include "../io/CheckpointDirectory.hpp"#include <algorithm>#include <cstring>#include <exception>#include <memory>#include <new>#include <string_view>Functions | |
| int | swmm_checkpoint_capabilities (SWMM_Engine handle, unsigned long *flags) |
| Query checkpoint features compiled into this backend. | |
| int | swmm_checkpoint_session_status (SWMM_Engine handle, unsigned long *flags) |
| Read the current checkpoint attachment and boundary hints. | |
| int | swmm_checkpoint_start_session (SWMM_Engine handle, const SWMM_CheckpointSessionOptions *options) |
| Initialize and attach a managed checkpoint session at its initial boundary. | |
| int | swmm_checkpoint_inspect (SWMM_Engine handle, const char *path, SWMM_CheckpointInspection *snapshot) |
| Validate a checkpoint against a fresh session and return independent metadata. | |
| int | swmm_checkpoint_inspection_json (SWMM_CheckpointInspection handle, char *out, size_t capacity, size_t *required) |
| Copy inspection metadata as a complete NUL-terminated UTF-8 JSON document. | |
| void | swmm_checkpoint_inspection_destroy (SWMM_CheckpointInspection handle) |
| Release an inspection snapshot independently of engine lifetime. | |
| int | swmm_checkpoint_save (SWMM_Engine handle, const char *path) |
| Publish a new checkpoint exclusively at an accepted session boundary. | |
| int | swmm_checkpoint_restore (SWMM_Engine handle, const char *path) |
| Restore a compatible checkpoint into an explicitly prepared fresh session. | |
| int | swmm_checkpoint_export_bundle (const char *path, const char *folder) |
| Package an existing file-backed checkpoint in a new exclusive directory. | |
| const char * | swmm_checkpoint_last_error_msg (void) |
| Borrow the diagnostic from the last checkpoint operation on this thread. | |
Public C API implementation for simulation checkpoints.
| int swmm_checkpoint_capabilities | ( | SWMM_Engine | engine, |
| unsigned long * | flags ) |
Query checkpoint features compiled into this backend.
Capabilities describe backend support, not compatibility of a particular model or session.
| [in] | engine | Non-null live engine handle; no prepared checkpoint session is required. |
| [out] | flags | Non-null destination for the bitwise OR of supported SWMM_CHECKPOINT_* feature flags. Written only on success. |
| int swmm_checkpoint_export_bundle | ( | const char * | path, |
| const char * | new_folder ) |
Package an existing file-backed checkpoint in a new exclusive directory.
Does not need an engine handle or certify model/provider compatibility. External inputs remain necessary.
| [in] | path | Nonempty NUL-terminated UTF-8 source checkpoint path. |
| [in] | new_folder | Nonempty NUL-terminated UTF-8 destination folder that must not already exist. |
| int swmm_checkpoint_inspect | ( | SWMM_Engine | engine, |
| const char * | path, | ||
| SWMM_CheckpointInspection * | snapshot ) |
Validate a checkpoint against a fresh session and return independent metadata.
Inspection may perform substantial synchronous IO; it cannot be interrupted and does not adopt checkpoint state. The returned snapshot survives engine close/destruction and must be released with swmm_checkpoint_inspection_destroy(). Restore rechecks publication eligibility.
| [in] | engine | Non-null engine attached to a matching, explicitly prepared fresh checkpoint session. |
| [in] | path | Nonempty NUL-terminated UTF-8 checkpoint path, borrowed for the synchronous call. |
| [out] | snapshot | Non-null destination for a newly allocated immutable inspection handle. Preserved on failure; a previous handle is not freed when replaced. |
| void swmm_checkpoint_inspection_destroy | ( | SWMM_CheckpointInspection | snapshot | ) |
Release an inspection snapshot independently of engine lifetime.
Does not clear the thread-local checkpoint diagnostic.
| [in] | snapshot | Snapshot owned by the caller, or NULL for a no-op. Every non-null handle must be destroyed exactly once; do not use it afterward. |
| int swmm_checkpoint_inspection_json | ( | SWMM_CheckpointInspection | snapshot, |
| char * | utf8, | ||
| size_t | capacity, | ||
| size_t * | required ) |
Copy inspection metadata as a complete NUL-terminated UTF-8 JSON document.
Schema 1 uses raw engine calendar dates and seconds, null optional fields and decimal strings for uint64 counts/bytes/sequences. A driver update of -1 means exhausted; equality to engine_seconds means due now. Metadata does not certify adapter availability.
| [in] | snapshot | Live inspection handle returned by swmm_checkpoint_inspect(); do not destroy concurrently. |
| [out] | utf8 | Caller-owned destination of capacity bytes, or NULL with capacity=0 to query the required size. No bytes are written when too small. |
| [in] | capacity | Destination capacity in bytes, including space for the terminating NUL. |
| [out] | required | Non-null destination for required bytes INCLUDING the terminating NUL. Updated for a size query or short buffer; preserved for invalid handle/arguments. |
| const char * swmm_checkpoint_last_error_msg | ( | void | ) |
Borrow the diagnostic from the last checkpoint operation on this thread.
The next checkpoint operation clears/overwrites the diagnostic; this getter and inspection destruction do not. The buffer survives engine destruction, is separate from simulation errors, and may truncate long messages.
| int swmm_checkpoint_restore | ( | SWMM_Engine | engine, |
| const char * | path ) |
Restore a compatible checkpoint into an explicitly prepared fresh session.
Does not prepare the required session. All engine operations require exclusive access on the owning thread; an earlier successful inspection does not bypass restore validation.
| [in] | engine | Non-null engine attached to a matching fresh checkpoint session, including source, driver and output ownership. |
| [in] | path | Nonempty NUL-terminated UTF-8 checkpoint path, borrowed for this synchronous call. |
| int swmm_checkpoint_save | ( | SWMM_Engine | engine, |
| const char * | new_path ) |
Publish a new checkpoint exclusively at an accepted session boundary.
Retains successful companions and older checkpoints. Recording/save failure does not roll back previously accepted physics; the caller owns its private workspace and cleanup.
| [in] | engine | Non-null engine attached at an accepted checkpoint session boundary. |
| [in] | new_path | Nonempty NUL-terminated UTF-8 destination. It must not exist; files, directories, symlinks and concurrent creation are refused. |
| int swmm_checkpoint_session_status | ( | SWMM_Engine | engine, |
| unsigned long * | flags ) |
Read the current checkpoint attachment and boundary hints.
These inexpensive hints do not replace full validation by inspect, save or restore.
| [in] | engine | Non-null live engine handle. |
| [out] | flags | Non-null destination for SWMM_CHECKPOINT_SESSION_* bits; written only on success. |
| int swmm_checkpoint_start_session | ( | SWMM_Engine | engine, |
| const SWMM_CheckpointSessionOptions * | options ) |
Initialize and attach a managed checkpoint session at its initial boundary.
See the profile and fresh-destination requirements above. A preflight refusal preserves OPENED; a failure after initialization closes the engine. Retrieve the operation diagnostic with swmm_checkpoint_last_error_msg().
| [in] | engine | Non-null engine in SWMM_STATE_OPENED; requires exclusive access on its owning thread. |
| [in] | options | Non-null options with struct_size >= sizeof(SWMM_CheckpointSessionOptions), schema_version=1, a SWMM_CHECKPOINT_OUTPUT_* profile and detailed_source_intervals equal to 0 or 1. Strings are borrowed for this synchronous call and copied internally. |