OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
openswmm_checkpoint.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: Apache-2.0 */
2
11
12#ifndef OPENSWMM_CHECKPOINT_H
13#define OPENSWMM_CHECKPOINT_H
14#include "openswmm_engine.h"
15#include <stddef.h>
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20/* Native backend support, not GUI activation or a session-builder certificate. */
21#define SWMM_CHECKPOINT_INSPECTION (1UL << 0)
22#define SWMM_CHECKPOINT_RESTORE (1UL << 1)
23#define SWMM_CHECKPOINT_SAVE_NEW (1UL << 2)
24#define SWMM_CHECKPOINT_BINARY_PROFILE (1UL << 3)
25#define SWMM_CHECKPOINT_SURFACE_PROFILE (1UL << 4)
26#define SWMM_CHECKPOINT_SOURCE_STREAM (1UL << 5)
27#define SWMM_CHECKPOINT_FILE_PROFILE (1UL << 6)
28#define SWMM_CHECKPOINT_BUNDLE_EXPORT (1UL << 7)
29#define SWMM_CHECKPOINT_SESSION_BUILDER (1UL << 8)
30
31/* Cheap attachment/lifecycle hints; full compatibility remains validated by
32 * inspect/restore/save. An ordinary initialized engine is not attached. */
33#define SWMM_CHECKPOINT_SESSION_ATTACHED (1UL << 0)
34#define SWMM_CHECKPOINT_SESSION_BOUNDARY (1UL << 1)
35#define SWMM_CHECKPOINT_SESSION_FRESH (1UL << 2)
36#define SWMM_CHECKPOINT_SESSION_MANAGED (1UL << 3)
37
38#define SWMM_CHECKPOINT_OUTPUT_NONE 0
39#define SWMM_CHECKPOINT_OUTPUT_BINARY 1
40#define SWMM_CHECKPOINT_OUTPUT_MESH 2
41#define SWMM_CHECKPOINT_OUTPUT_COMBINED 3
42#define SWMM_CHECKPOINT_OUTPUT_FILES 4
43
54
55/* Explicit native-input profile, called in OPENED before ordinary initialize.
56 * Initializes, prepares output, starts and attaches at the initial boundary.
57 * Engine owns source arrays/graphs, stage and journal through close/destruction.
58 * Reviewed spatial ownership requires the current authoring preview token.
59 * Mesh sessions require the qualified CPU aquifer/common-source profile.
60 * Qualified matched mesh transport supports first-order or RK2 advancement,
61 * numerical/binary/mesh/combined output, and the documented ground profiles.
62 * Native LEGACY pollutant networks without catchments, LIDs, treatment, native
63 * heat/age or reactions can retain quality with first-order shared mesh exchange
64 * or an independent RK2 mesh. Shared RK2 network exchange remains refused.
65 * Other external/live forcing, physics and plugin recovery combinations retain
66 * their separate profile guards.
67 * Ordinary initialize keeps its existing ownership guard. No callbacks allowed.
68 * Preflight refusal preserves OPENED; failure after initialization closes the
69 * engine. Partial fresh outputs may remain; caller owns its private workspace.
70 * Every output/journal must have a separate fresh protected destination. */
71/* Profiles without binary output must open with out=NULL. Profiles without
72 * mesh output must open without OUTPUT_FILE. For a mesh profile, set the
73 * absolute fresh SWMM_FILE_OUTPUT_2D slot before this call; the managed builder
74 * binds the built-in writer to that slot (including an OPENED path edit). */
93 const SWMM_CheckpointSessionOptions* options);
94
96
108SWMM_ENGINE_API int swmm_checkpoint_capabilities(SWMM_Engine engine, unsigned long* flags);
120SWMM_ENGINE_API int swmm_checkpoint_session_status(SWMM_Engine engine, unsigned long* flags);
121
122/* All engine calls are synchronous and require exclusive access to the handle
123 * on its owning thread. Inspect/restore require a matching, explicitly prepared
124 * fresh supported checkpoint session, including source/driver/output ownership.
125 * These functions do not prepare that session or enable authored R4 processing.
126 * Inspection validates and discards private copies without adopting/publishing
127 * state. It may require substantial IO and cannot be interrupted. Publication
128 * eligibility is checked again by restore, not certified by inspection.
129 *
130 * Success creates a new immutable snapshot, valid after engine close/destroy.
131 * Failure preserves *snapshot. Caller owns every successful returned snapshot;
132 * replacing its variable does not destroy a prior snapshot. */
149SWMM_ENGINE_API int swmm_checkpoint_inspect(SWMM_Engine engine, const char* path,
150 SWMM_CheckpointInspection* snapshot);
151
152/* Schema 1: raw engine calendar dates and seconds; optional fields are null;
153 * uint64 counts/bytes/sequences are decimal strings. Driver update -1 means
154 * exhausted; equality with engine_seconds means due now. This is metadata,
155 * not a checkpoint format, timezone conversion or proof of adapter availability.
156 *
157 * NULL utf8 with zero capacity queries required bytes INCLUDING terminating NUL.
158 * Short capacity returns BADPARAM, sets required and writes no buffer bytes.
159 * Invalid arguments preserve required. Success writes the complete document.
160 * Snapshot access requires a live returned handle, not concurrent destruction. */
180 size_t capacity, size_t* required);
190
191/* Save only at an accepted boundary. Atomically refuses an existing or
192 * concurrently created destination, including symlinks/directories. Retains
193 * successful companions; never cleans up older checkpoints. A recording/save
194 * error does not imply rollback of previously accepted physics. */
209SWMM_ENGINE_API int swmm_checkpoint_save(SWMM_Engine engine, const char* new_path);
224SWMM_ENGINE_API int swmm_checkpoint_restore(SWMM_Engine engine, const char* path);
225/* Transport of an existing file-backed checkpoint to a new exclusive folder.
226 * Does not certify model/provider compatibility; external inputs remain needed. */
240SWMM_ENGINE_API int swmm_checkpoint_export_bundle(const char* path, const char* new_folder);
241
242/* Specific diagnostic of the last checkpoint operation on THIS thread.
243 * Getter/destroy do not clear it; next operation overwrites it. Copy before
244 * leaving the thread. It is independent of simulation error state and remains
245 * available after engine destruction. Long diagnostics may be truncated.
246 * Validation refusals use IO; unprepared/busy/not-fresh/unsupported use LIFECYCLE;
247 * bad pointers/path encoding use BADPARAM/BADHANDLE. Exceptions never escape. */
259
260#ifdef __cplusplus
261}
262#endif
263#endif
#define SWMM_ENGINE_API
Definition openswmm_2d.h:62
void * SWMM_Engine
Opaque handle to an OpenSWMM Engine instance.
Definition openswmm_callbacks.h:55
SWMM_ENGINE_API int swmm_checkpoint_session_status(SWMM_Engine engine, unsigned long *flags)
Read the current checkpoint attachment and boundary hints.
Definition openswmm_checkpoint_impl.cpp:143
SWMM_ENGINE_API void swmm_checkpoint_inspection_destroy(SWMM_CheckpointInspection snapshot)
Release an inspection snapshot independently of engine lifetime.
Definition openswmm_checkpoint_impl.cpp:216
SWMM_ENGINE_API int swmm_checkpoint_inspect(SWMM_Engine engine, const char *path, SWMM_CheckpointInspection *snapshot)
Validate a checkpoint against a fresh session and return independent metadata.
Definition openswmm_checkpoint_impl.cpp:181
SWMM_ENGINE_API const char * swmm_checkpoint_last_error_msg(void)
Borrow the diagnostic from the last checkpoint operation on this thread.
Definition openswmm_checkpoint_impl.cpp:257
void * SWMM_CheckpointInspection
Definition openswmm_checkpoint.h:95
SWMM_ENGINE_API int swmm_checkpoint_save(SWMM_Engine engine, const char *new_path)
Publish a new checkpoint exclusively at an accepted session boundary.
Definition openswmm_checkpoint_impl.cpp:219
SWMM_ENGINE_API int swmm_checkpoint_export_bundle(const char *path, const char *new_folder)
Package an existing file-backed checkpoint in a new exclusive directory.
Definition openswmm_checkpoint_impl.cpp:242
SWMM_ENGINE_API int swmm_checkpoint_restore(SWMM_Engine engine, const char *path)
Restore a compatible checkpoint into an explicitly prepared fresh session.
Definition openswmm_checkpoint_impl.cpp:232
SWMM_ENGINE_API 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.
Definition openswmm_checkpoint_impl.cpp:199
SWMM_ENGINE_API int swmm_checkpoint_capabilities(SWMM_Engine engine, unsigned long *flags)
Query checkpoint features compiled into this backend.
Definition openswmm_checkpoint_impl.cpp:121
SWMM_ENGINE_API int swmm_checkpoint_start_session(SWMM_Engine engine, const SWMM_CheckpointSessionOptions *options)
Initialize and attach a managed checkpoint session at its initial boundary.
Definition openswmm_checkpoint_impl.cpp:153
OpenSWMM Engine — primary transparent C API (master header).
Definition openswmm_checkpoint.h:44
int output
Definition openswmm_checkpoint.h:47
unsigned long schema_version
Definition openswmm_checkpoint.h:46
const char * ownership_token
Definition openswmm_checkpoint.h:52
int detailed_source_intervals
Definition openswmm_checkpoint.h:50
const char * source_history
Definition openswmm_checkpoint.h:49
size_t struct_size
Definition openswmm_checkpoint.h:45