tc_replica_get_task

This commit is contained in:
Dustin J. Mitchell 2022-01-26 02:15:52 +00:00
parent f3b73ca0e4
commit e1c348b96e
4 changed files with 107 additions and 24 deletions

View file

@ -27,6 +27,7 @@ where
F: FnOnce(&mut Replica) -> anyhow::Result<T>,
{
let rep: &'a mut TCReplica = rep_ref(rep);
rep.error = None;
match f(&mut rep.inner) {
Ok(v) => v,
Err(e) => {
@ -83,7 +84,26 @@ pub extern "C" fn tc_replica_new_on_disk<'a>(
// TODO: tc_replica_all_tasks
// TODO: tc_replica_all_task_uuids
// TODO: tc_replica_working_set
// TODO: tc_replica_get_task
/// Get an existing task by its UUID.
///
/// Returns NULL when the task does not exist, and on error. Consult tc_replica_error
/// to distinguish the two conditions.
#[no_mangle]
pub extern "C" fn tc_replica_get_task(rep: *mut TCReplica, uuid: TCUuid) -> *mut TCTask {
wrap(
rep,
|rep| {
let uuid: Uuid = uuid.into();
if let Some(task) = rep.get_task(uuid)? {
Ok(TCTask::as_ptr(task))
} else {
Ok(std::ptr::null_mut())
}
},
std::ptr::null_mut(),
)
}
/// Create a new task. The task must not already exist.
///

View file

@ -84,6 +84,14 @@ struct TCReplica *tc_replica_new_in_memory(void);
*/
struct TCReplica *tc_replica_new_on_disk(struct TCString *path, struct TCString **error_out);
/**
* Get an existing task by its UUID.
*
* Returns NULL when the task does not exist, and on error. Consult tc_replica_error
* to distinguish the two conditions.
*/
struct TCTask *tc_replica_get_task(struct TCReplica *rep, struct TCUuid uuid);
/**
* Create a new task. The task must not already exist.
*