Add ASL index state API stubs

This commit is contained in:
Carl Niklas Rydberg 2026-01-17 12:45:13 +01:00
parent a91ab91e39
commit 0d810affb0
2 changed files with 94 additions and 0 deletions

View file

@ -25,6 +25,14 @@ typedef enum {
AMDUAT_ASL_STORE_ERR_IO = 4 AMDUAT_ASL_STORE_ERR_IO = 4
} amduat_asl_store_error_t; } amduat_asl_store_error_t;
typedef uint64_t amduat_asl_snapshot_id_t;
typedef uint64_t amduat_asl_log_position_t;
typedef struct {
amduat_asl_snapshot_id_t snapshot_id;
amduat_asl_log_position_t log_position;
} amduat_asl_index_state_t;
typedef struct { typedef struct {
amduat_asl_store_error_t (*put)(void *ctx, amduat_asl_store_error_t (*put)(void *ctx,
amduat_artifact_t artifact, amduat_artifact_t artifact,
@ -32,6 +40,15 @@ typedef struct {
amduat_asl_store_error_t (*get)(void *ctx, amduat_asl_store_error_t (*get)(void *ctx,
amduat_reference_t ref, amduat_reference_t ref,
amduat_artifact_t *out_artifact); amduat_artifact_t *out_artifact);
amduat_asl_store_error_t (*put_indexed)(void *ctx,
amduat_artifact_t artifact,
amduat_reference_t *out_ref,
amduat_asl_index_state_t *out_state);
amduat_asl_store_error_t (*get_indexed)(void *ctx,
amduat_reference_t ref,
amduat_asl_index_state_t state,
amduat_artifact_t *out_artifact);
bool (*current_state)(void *ctx, amduat_asl_index_state_t *out_state);
amduat_asl_store_error_t (*validate_config)( amduat_asl_store_error_t (*validate_config)(
void *ctx, void *ctx,
amduat_asl_store_config_t config); amduat_asl_store_config_t config);
@ -43,6 +60,9 @@ static inline void amduat_asl_store_ops_init(amduat_asl_store_ops_t *ops) {
} }
ops->put = NULL; ops->put = NULL;
ops->get = NULL; ops->get = NULL;
ops->put_indexed = NULL;
ops->get_indexed = NULL;
ops->current_state = NULL;
ops->validate_config = NULL; ops->validate_config = NULL;
} }
@ -65,6 +85,21 @@ amduat_asl_store_error_t amduat_asl_store_get(amduat_asl_store_t *store,
amduat_reference_t ref, amduat_reference_t ref,
amduat_artifact_t *out_artifact); amduat_artifact_t *out_artifact);
amduat_asl_store_error_t amduat_asl_store_put_indexed(
amduat_asl_store_t *store,
amduat_artifact_t artifact,
amduat_reference_t *out_ref,
amduat_asl_index_state_t *out_state);
amduat_asl_store_error_t amduat_asl_store_get_indexed(
amduat_asl_store_t *store,
amduat_reference_t ref,
amduat_asl_index_state_t state,
amduat_artifact_t *out_artifact);
bool amduat_asl_index_current_state(amduat_asl_store_t *store,
amduat_asl_index_state_t *out_state);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif

View file

@ -60,3 +60,62 @@ amduat_asl_store_error_t amduat_asl_store_get(amduat_asl_store_t *store,
} }
return store->ops.get(store->ctx, ref, out_artifact); return store->ops.get(store->ctx, ref, out_artifact);
} }
amduat_asl_store_error_t amduat_asl_store_put_indexed(
amduat_asl_store_t *store,
amduat_artifact_t artifact,
amduat_reference_t *out_ref,
amduat_asl_index_state_t *out_state) {
amduat_asl_store_error_t cfg_err;
amduat_asl_store_error_t store_err;
if (store == NULL || store->ops.put_indexed == NULL) {
return AMDUAT_ASL_STORE_ERR_UNSUPPORTED;
}
cfg_err = amduat_asl_store_validate_config(store);
if (cfg_err != AMDUAT_ASL_STORE_OK) {
return cfg_err;
}
store_err = store->ops.put_indexed(store->ctx, artifact, out_ref, out_state);
if (store_err != AMDUAT_ASL_STORE_OK) {
return store_err;
}
if (out_ref != NULL && out_ref->hash_id != store->config.hash_id) {
return AMDUAT_ASL_STORE_ERR_INTEGRITY;
}
return AMDUAT_ASL_STORE_OK;
}
amduat_asl_store_error_t amduat_asl_store_get_indexed(
amduat_asl_store_t *store,
amduat_reference_t ref,
amduat_asl_index_state_t state,
amduat_artifact_t *out_artifact) {
amduat_asl_store_error_t cfg_err;
if (store == NULL || store->ops.get_indexed == NULL) {
return AMDUAT_ASL_STORE_ERR_UNSUPPORTED;
}
if (ref.hash_id != store->config.hash_id) {
return AMDUAT_ASL_STORE_ERR_UNSUPPORTED;
}
cfg_err = amduat_asl_store_validate_config(store);
if (cfg_err != AMDUAT_ASL_STORE_OK) {
return cfg_err;
}
return store->ops.get_indexed(store->ctx, ref, state, out_artifact);
}
bool amduat_asl_index_current_state(amduat_asl_store_t *store,
amduat_asl_index_state_t *out_state) {
amduat_asl_store_error_t cfg_err;
if (store == NULL || store->ops.current_state == NULL) {
return false;
}
cfg_err = amduat_asl_store_validate_config(store);
if (cfg_err != AMDUAT_ASL_STORE_OK) {
return false;
}
return store->ops.current_state(store->ctx, out_state);
}