From 96a975696e92ed3228e078ea53fa4ec3864270ce Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Tue, 24 Jan 2023 22:05:05 +0100 Subject: [PATCH] RUST: Expose more things to the C part of lektor for the SQLite connexion --- inc/liblektor-rs/database.h | 10 +++++ src/rust/lektor_db/src/connexion.rs | 5 --- src/rust/lektor_unsafe/src/db.rs | 66 +++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 5 deletions(-) diff --git a/inc/liblektor-rs/database.h b/inc/liblektor-rs/database.h index 34b6ffd5..0660be64 100644 --- a/inc/liblektor-rs/database.h +++ b/inc/liblektor-rs/database.h @@ -7,6 +7,7 @@ extern "C" { #include <stdint.h> +struct lkt_uri; struct lkt_sqlite_connection; typedef struct lkt_sqlite_connection lkt_sqlite_connection; @@ -27,6 +28,15 @@ bool lkt_database_delete_kara_by_local_id(lkt_sqlite_connection *, int64_t); bool lkt_database_get_kara_info(lkt_sqlite_connection *, int64_t, lkt_info_cb, void *restrict); bool lkt_database_get_kara_tags(lkt_sqlite_connection *, int64_t, lkt_info_cb, void *restrict); +bool lkt_database_add_to_history(lkt_sqlite_connection *, int64_t); +bool lkt_database_iter_history(lkt_sqlite_connection *, void (*)(int64_t, void *restrict), + void *restrict); +bool lkt_database_clear_history(lkt_sqlite_connection *); +bool lkt_database_search(lkt_sqlite_connection *, lkt_uri *, void (*)(int64_t, void *restrict), + void *restrict); +bool lkt_database_search_playlist(lkt_sqlite_connection *, const char *, lkt_uri *, + void (*)(int64_t, void *restrict), void *restrict); + #if defined(__cplusplus) } #endif diff --git a/src/rust/lektor_db/src/connexion.rs b/src/rust/lektor_db/src/connexion.rs index 943540e9..a291037e 100644 --- a/src/rust/lektor_db/src/connexion.rs +++ b/src/rust/lektor_db/src/connexion.rs @@ -234,11 +234,6 @@ impl LktDatabaseConnection { todo!() } - /// Search the queue by URIs. We return the local ids. - pub fn search_queue(&mut self, _uri: LktCUri) -> LktDatabaseResult<Vec<i64>> { - todo!() - } - /// Search the given playlist by URIs. We return the local ids. pub fn search_playlist<S: AsRef<str>>( &mut self, diff --git a/src/rust/lektor_unsafe/src/db.rs b/src/rust/lektor_unsafe/src/db.rs index 7ad17c31..1482e3f1 100644 --- a/src/rust/lektor_unsafe/src/db.rs +++ b/src/rust/lektor_unsafe/src/db.rs @@ -120,3 +120,69 @@ pub unsafe extern "C" fn lkt_database_get_kara_tags( ) -> bool { unimplemented!() } + +/// Add the kara to the history. +/// ### Safety +/// The passed db pointer must be created by +/// [`lkt_database_establish_connection`]. +#[no_mangle] +pub unsafe extern "C" fn lkt_database_add_to_history( + db: *mut LktDatabaseConnection, + local_id: i64, +) -> bool { + todo!() +} + +/// Iterate over the history. +/// ### Safety +/// The passed db pointer must be created by +/// [`lkt_database_establish_connection`]. +#[no_mangle] +pub unsafe extern "C" fn lkt_database_iter_history( + db: *mut LktDatabaseConnection, + cb: extern "C" fn(i64, usize, *mut c_void), + user: *mut c_void, +) -> bool { + todo!() +} + +/// Clear the history. +/// ### Safety +/// The passed db pointer must be created by +/// [`lkt_database_establish_connection`]. +#[no_mangle] +pub unsafe extern "C" fn lkt_database_clear_history(db: *mut LktDatabaseConnection) -> bool { + todo!() +} + +/// Search the database. +/// ### Safety +/// The passed db pointer must be created by +/// [`lkt_database_establish_connection`]. The passed uri pointer must be a +/// valid an address to a URI. +#[no_mangle] +pub unsafe extern "C" fn lkt_database_search( + db: *mut LktDatabaseConnection, + uri: LktUriPtr, + cb: extern "C" fn(i64, *mut c_void), + user: *mut c_void, +) -> bool { + todo!() +} + +/// Search the specified playlist in database. +/// ### Safety +/// The passed db pointer must be created by +/// [`lkt_database_establish_connection`]. The passed uri pointer must be a +/// valid an address to a URI. The passed playlist name must be a valid C +/// string (a null terminated string). +#[no_mangle] +pub unsafe extern "C" fn lkt_database_search_playlist( + db: *mut LktDatabaseConnection, + playlist: *mut c_char, + uri: LktUriPtr, + cb: extern "C" fn(i64, *mut c_void), + user: *mut c_void, +) -> bool { + todo!() +} -- GitLab