Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
Loading...
Searching...
No Matches
native_dynamic_relational.h
Go to the documentation of this file.
1/**
2 * @file
3 * @brief Declares Pharos-owned native relational runtime helpers for dynamic apps.
4 */
5
6#ifndef PHAROS_NATIVE_DYNAMIC_RELATIONAL_H
7#define PHAROS_NATIVE_DYNAMIC_RELATIONAL_H
8
10
11/**
12 * @brief Carries request-local relational bridge state for one native request.
13 */
14typedef struct {
15 int enabled; /**< Non-zero when relational sync is active for the request. */
16 char *before_signature; /**< File signature captured after export and before request mutation. */
18
19/**
20 * @brief Clears heap-owned fields in a request-local relational sync record.
21 *
22 * @param sync Sync record to clear.
23 */
25
26/**
27 * @brief Returns the configured relational backend when it is recognized.
28 *
29 * @param app_root App root directory.
30 * @param runtime_conf_path Runtime config path.
31 * @return Newly allocated backend string, or NULL when no supported backend is configured.
32 */
33char *native_dynamic_relational_backend_dup(const char *app_root, const char *runtime_conf_path);
34
35/**
36 * @brief Returns the effective sqlite database path for a dynamic app.
37 *
38 * @param app_root App root directory.
39 * @param runtime_conf_path Runtime config path.
40 * @param app_id App identifier used for the default sqlite path.
41 * @return Newly allocated sqlite path, or NULL on failure.
42 */
44 const char *app_root,
45 const char *runtime_conf_path,
46 const char *app_id
47);
48
49/**
50 * @brief Returns whether sqlite runtime prerequisites are satisfied.
51 *
52 * @param app_root App root directory.
53 * @param runtime_conf_path Runtime config path.
54 * @param app_id App identifier used for the default sqlite path.
55 * @return Non-zero when sqlite runtime work can proceed, otherwise 0.
56 */
58 const char *app_root,
59 const char *runtime_conf_path,
60 const char *app_id
61);
62
63/**
64 * @brief Returns whether PostgreSQL runtime prerequisites are satisfied.
65 *
66 * @param app_root App root directory.
67 * @param runtime_conf_path Runtime config path.
68 * @return Non-zero when PostgreSQL runtime work can proceed, otherwise 0.
69 */
71 const char *app_root,
72 const char *runtime_conf_path
73);
74
75/**
76 * @brief Prepares the sqlite schema, seed data, and migration ledger for one dynamic app.
77 *
78 * @param app_root App root directory.
79 * @param runtime_conf_path Runtime config path.
80 * @param app_id App identifier used for the default sqlite path.
81 * @return 0 on success, otherwise a non-zero native status code.
82 */
84 const char *app_root,
85 const char *runtime_conf_path,
86 const char *app_id
87);
88
89/**
90 * @brief Prepares the PostgreSQL schema, seed data, and migration ledger for one dynamic app.
91 *
92 * @param app_root App root directory.
93 * @param runtime_conf_path Runtime config path.
94 * @return 0 on success, otherwise a non-zero native status code.
95 */
97 const char *app_root,
98 const char *runtime_conf_path
99);
100
101/**
102 * @brief Exports canonical runtime state JSON from the configured relational backend.
103 *
104 * @param app_root App root directory.
105 * @param runtime_conf_path Runtime config path.
106 * @param app_id App identifier used for sqlite path resolution.
107 * @return Newly allocated compact JSON string, or NULL on failure.
108 */
110 const char *app_root,
111 const char *runtime_conf_path,
112 const char *app_id
113);
114
115/**
116 * @brief Returns the current audit-event count from the configured relational backend.
117 *
118 * @param app_root App root directory.
119 * @param runtime_conf_path Runtime config path.
120 * @param app_id App identifier used for sqlite path resolution.
121 * @return Newly allocated count text, or NULL on failure.
122 */
124 const char *app_root,
125 const char *runtime_conf_path,
126 const char *app_id
127);
128
129/**
130 * @brief Imports canonical runtime state JSON into the configured relational backend.
131 *
132 * @param app_root App root directory.
133 * @param runtime_conf_path Runtime config path.
134 * @param app_id App identifier used for sqlite path resolution.
135 * @param state_path Canonical state JSON path.
136 * @param expected_audit_count Optional optimistic concurrency guard.
137 * @return 0 on success, otherwise a non-zero native status code.
138 */
140 const char *app_root,
141 const char *runtime_conf_path,
142 const char *app_id,
143 const char *state_path,
144 const char *expected_audit_count
145);
146
147/**
148 * @brief Computes a stable signature for one file path.
149 *
150 * @param path File path to hash.
151 * @return Newly allocated signature text, or NULL on failure.
152 */
154
155/**
156 * @brief Exports relational state into the app state file before request handling when enabled.
157 *
158 * @param app App runtime being served.
159 * @param sync Output sync record to populate.
160 * @return 0 on success, otherwise a non-zero native status code.
161 */
163 const AppRuntime *app,
165);
166
167/**
168 * @brief Imports the app state file back into the relational backend when it changed.
169 *
170 * @param app App runtime being served.
171 * @param sync Request sync record populated by prepare_request_state.
172 * @return 0 on success, otherwise a non-zero native status code.
173 */
175 const AppRuntime *app,
177);
178
179#endif
int native_dynamic_relational_runtime_import_state(const char *app_root, const char *runtime_conf_path, const char *app_id, const char *state_path, const char *expected_audit_count)
Imports canonical runtime state JSON into the configured relational backend.
int native_dynamic_relational_postgresql_runtime_ready(const char *app_root, const char *runtime_conf_path)
Returns whether PostgreSQL runtime prerequisites are satisfied.
char * native_dynamic_relational_file_signature_dup(const char *path)
Computes a stable signature for one file path.
int native_dynamic_relational_postgresql_runtime_prepare(const char *app_root, const char *runtime_conf_path)
Prepares the PostgreSQL schema, seed data, and migration ledger for one dynamic app.
int native_dynamic_relational_sqlite_runtime_prepare(const char *app_root, const char *runtime_conf_path, const char *app_id)
Prepares the sqlite schema, seed data, and migration ledger for one dynamic app.
char * native_dynamic_relational_runtime_audit_count_dup(const char *app_root, const char *runtime_conf_path, const char *app_id)
Returns the current audit-event count from the configured relational backend.
int native_dynamic_relational_sqlite_runtime_ready(const char *app_root, const char *runtime_conf_path, const char *app_id)
Returns whether sqlite runtime prerequisites are satisfied.
void native_dynamic_relational_request_sync_free(NativeDynamicRelationalRequestSync *sync)
Clears heap-owned fields in a request-local relational sync record.
char * native_dynamic_relational_runtime_export_json_dup(const char *app_root, const char *runtime_conf_path, const char *app_id)
Exports canonical runtime state JSON from the configured relational backend.
int native_dynamic_relational_prepare_request_state(const AppRuntime *app, NativeDynamicRelationalRequestSync *sync)
Exports relational state into the app state file before request handling when enabled.
char * native_dynamic_relational_backend_dup(const char *app_root, const char *runtime_conf_path)
Returns the configured relational backend when it is recognized.
int native_dynamic_relational_sync_back_if_changed(const AppRuntime *app, const NativeDynamicRelationalRequestSync *sync)
Imports the app state file back into the relational backend when it changed.
char * native_dynamic_relational_sqlite_path_dup(const char *app_root, const char *runtime_conf_path, const char *app_id)
Returns the effective sqlite database path for a dynamic app.
Defines shared native runtime data structures used across the Pharos C runtime.
Loaded runtime metadata for one Pharos app artifact.
Carries request-local relational bridge state for one native request.