aboutsummaryrefslogtreecommitdiffstats
path: root/prototypes/connections/module-save.h
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-09-25 15:49:48 +0100
committereunhhu <[email protected]>2026-09-25 15:49:48 +0100
commit18675f3e45fa0896efd777bf66ad0ec4c8157d36 (patch)
tree058a22fc929e974cef70cc1ddbd5dc54f56bf55c /prototypes/connections/module-save.h
parent49c29a1255e1ad3f7fde6c64910c7d2c38edad78 (diff)
downloadpure-18675f3e45fa0896efd777bf66ad0ec4c8157d36.tar.gz
pure-18675f3e45fa0896efd777bf66ad0ec4c8157d36.zip
Keep app states in the tree store
When the data host keeps states (PureData.state and .save, implemented by pure_tree_data), every state of an app lives in the store: a text state's draft is its stored value, a list mirrors each change into a stored draft (record header, then items), and numbers, cursors and indices are stored together by name. An app starts from what is stored, moves list fields by name when a record changed, resets cursors and indices that no longer fit, and refuses damaged stored values. Each key, text and message event publishes the states it changed together with the message's document in one store commit, or fails and leaves memory and store as they were. Frame changes go with the next event or pure_app_save. pure-run takes --store PATH. Tests run the same random events on an app in memory and on a stored app that restarts every few events and require equal states after every step; kill a process at every commit stage of an event that changes a number, a text and a list; and check frames, message atomicity and migration by restart and by replacement. A stored event costs about 10.6 ms more on the Pi's SD card, mostly two fsyncs.
Diffstat (limited to 'prototypes/connections/module-save.h')
-rw-r--r--prototypes/connections/module-save.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/prototypes/connections/module-save.h b/prototypes/connections/module-save.h
new file mode 100644
index 0000000..90e0701
--- /dev/null
+++ b/prototypes/connections/module-save.h
@@ -0,0 +1,30 @@
+#ifndef PURE_MODULE_SAVE_H
+#define PURE_MODULE_SAVE_H
+#include "module.h"
+
+/* App states a data host keeps (docs/design/008-module-format.md), internal
+ * to the module executor. Each text state is a stored draft, each list state
+ * a stored draft its list mirrors, and numbers, cursors and indices are one
+ * stored value by name. A save publishes what changed, all or nothing. */
+
+bool pure_save_enabled(const PureApp *);
+/* A text state of m: its stored value, or its initial constant when none. */
+PureResult pure_save_open_text(PureApp *, const PureModule *m, uint32_t state, PureDraft **out, PureVersion *saved);
+/* A list state of m: its stored items, fields moved by name when the stored
+ * record differs from m's. */
+PureResult pure_save_open_list(PureApp *, const PureModule *m, uint32_t state, PureList **out, PureDraft **draft,
+ PureVersion *saved);
+/* Open the stored numbers, cursors and indices of m and, with load, put each
+ * stored one of the same name and kind that still fits into values. */
+PureResult pure_save_open_values(PureApp *, const PureModule *m, double *values, bool load);
+/* Store a list whose record changed in its draft, header and items anew. */
+PureResult pure_save_rewrite_list(const PureModule *m, uint32_t state, PureList *list, PureDraft *draft);
+/* Publish every state changed since the last save (values are the pending
+ * numbers), with document when not NULL; revision is the document's. */
+PureResult pure_save_commit(PureApp *, const double *values, void *document, int64_t *revision);
+
+/* A list with record's fields, taking from `from` each field of the same name
+ * and kind and giving the others their defaults (module.c). */
+PureResult pure_list_migrate(PureList **out, const PureList *from, const char *const *names,
+ const uint8_t *text, unsigned count, const PureModule *m, uint32_t record);
+#endif