diff --git a/inc/liblektor-rs/database.h b/inc/liblektor-rs/database.h index 0660be6472abe46c045a8c13ae2b97ed87502fd0..bb7d3639aafe9a51302dc5c1541197a9e92c2763 100644 --- a/inc/liblektor-rs/database.h +++ b/inc/liblektor-rs/database.h @@ -19,6 +19,13 @@ typedef struct lkt_sqlite_connection lkt_sqlite_connection; */ typedef void (*lkt_info_cb)(const char *, const char *, void *restrict); +/* The callback called on every kara when calling the search or iter functions. + * last parameter of the function is a `void*` passed by the user to the parent + * function. The function can't fail. The passed integer is the local ID of the + * kara. + */ +typedef void (*lkt_search_cb)(int64_t, void *restrict); + lkt_sqlite_connection *lkt_database_establish_connection(const char *); void lkt_database_close_connection(lkt_sqlite_connection *); @@ -29,13 +36,11 @@ bool lkt_database_get_kara_info(lkt_sqlite_connection *, int64_t, lkt_info_cb, v 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_iter_history(lkt_sqlite_connection *, lkt_search_cb, 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); +bool lkt_database_search(lkt_sqlite_connection *, struct lkt_uri *, lkt_search_cb, void *restrict); +bool lkt_database_search_playlist(lkt_sqlite_connection *, const char *, struct lkt_uri *, + lkt_search_cb, void *restrict); #if defined(__cplusplus) } diff --git a/inc/liblektor-rs/queue.h b/inc/liblektor-rs/queue.h new file mode 100644 index 0000000000000000000000000000000000000000..8d32c302341b52f6e6f8442fce195857245754e5 --- /dev/null +++ b/inc/liblektor-rs/queue.h @@ -0,0 +1,44 @@ +#if !defined(LIBLEKTOR_RS_Queue___) +#define LIBLEKTOR_RS_Queue___ + +#if defined(__cplusplus) +extern "C" { +#endif + +#include <stdint.h> +#include <stdlib.h> + +struct lkt_uri; +struct lkt_database_queue; +typedef struct lkt_database_priority { + uint8_t value; +} lkt_database_priority; +typedef struct lkt_database_queue lkt_database_queue; + +/* The callback called on every kara when calling the search or iter functions of + * the queue. last parameter of the function is a `void*` passed by the user to + * the parent function. The function can't fail. The passed integer is the local + * ID of the kara. + */ +typedef void (*lkt_search_cb)(int64_t, void *restrict); + +lkt_database_queue *lkt_database_queue_new(); +void lkt_database_queue_delete(lkt_database_queue *); + +bool lkt_database_queue_current(lkt_database_queue *, int64_t *restrict); +bool lkt_database_queue_add_kara(lkt_database_queue *, int64_t, lkt_database_priority); +bool lkt_database_queue_peek_next(lkt_database_queue *, int64_t *restrict); +bool lkt_database_queue_pop_next(lkt_database_queue *, int64_t *restrict); +bool lkt_database_queue_swap(lkt_database_queue *, size_t, size_t, int64_t[2]); +bool lkt_database_queue_delete_all(lkt_database_queue *, int64_t, size_t *restrict); +bool lkt_database_queue_clear(lkt_database_queue *, lkt_database_priority, size_t *restrict); +bool lkt_database_queue_crop(lkt_database_queue *, size_t *restrict); +bool lkt_database_queue_shuffle(lkt_database_queue *); +bool lkt_database_queue_search(lkt_database_queue *, struct lkt_uri *, lkt_search_cb, + void *restrict); + +#if defined(__cplusplus) +} +#endif + +#endif // LIBLEKTOR_RS_Queue___ diff --git a/src/rust/lektor_db/src/queue.rs b/src/rust/lektor_db/src/queue.rs index a6426b95b5b2ae92c950234e24d1151c09f9ec34..6abba6e0e4f03678fc4e6c9041eba04b4f9da89d 100644 --- a/src/rust/lektor_db/src/queue.rs +++ b/src/rust/lektor_db/src/queue.rs @@ -1,4 +1,5 @@ -use super::*; +use crate::*; +use lektor_c_compat::rs::LktCUri; /// The number of priority levels in the queues. The higher the number, the /// higher the priority. @@ -6,6 +7,7 @@ const LKT_DATABASE_QUEUES_COUNT: usize = 5; /// A type to describe a priority. #[derive(Debug, Default)] +#[repr(C)] pub struct LktDatabasePriority { /// The actual priority. Alaways between `0` and /// [LKT_DATABASE_QUEUES_COUNT], both included. @@ -205,4 +207,10 @@ impl LktQueue { pub fn shuffle(&mut self) -> LktQueueResult<()> { todo!() } + + /// Search the queue by matching the URI. Returns the local id of the + /// matched karas. + pub fn search(&self, _uri: LktCUri) -> LktQueueResult<Vec<i64>> { + todo!() + } } diff --git a/src/rust/lektor_unsafe/src/db.rs b/src/rust/lektor_unsafe/src/db.rs index 1482e3f16317d78db99a9733f1c92e9170308471..fee96aa6a2d0d08bc35e98edb09c6b887dd5fb4e 100644 --- a/src/rust/lektor_unsafe/src/db.rs +++ b/src/rust/lektor_unsafe/src/db.rs @@ -99,10 +99,10 @@ pub unsafe extern "C" fn lkt_database_delete_kara_by_local_id( /// [`lkt_database_establish_connection`]. #[no_mangle] pub unsafe extern "C" fn lkt_database_get_kara_info( - db: *mut LktDatabaseConnection, - local_id: i64, - cb: extern "C" fn(*const c_char, *const c_char, *mut c_void), - user: *mut c_void, + _db: *mut LktDatabaseConnection, + _local_id: i64, + _cb: extern "C" fn(*const c_char, *const c_char, *mut c_void), + _user: *mut c_void, ) -> bool { unimplemented!() } @@ -113,10 +113,10 @@ pub unsafe extern "C" fn lkt_database_get_kara_info( /// [`lkt_database_establish_connection`]. #[no_mangle] pub unsafe extern "C" fn lkt_database_get_kara_tags( - db: *mut LktDatabaseConnection, - local_id: i64, - cb: extern "C" fn(*const c_char, *const c_char, *mut c_void), - user: *mut c_void, + _db: *mut LktDatabaseConnection, + _local_id: i64, + _cb: extern "C" fn(*const c_char, *const c_char, *mut c_void), + _user: *mut c_void, ) -> bool { unimplemented!() } @@ -127,8 +127,8 @@ pub unsafe extern "C" fn lkt_database_get_kara_tags( /// [`lkt_database_establish_connection`]. #[no_mangle] pub unsafe extern "C" fn lkt_database_add_to_history( - db: *mut LktDatabaseConnection, - local_id: i64, + _db: *mut LktDatabaseConnection, + _local_id: i64, ) -> bool { todo!() } @@ -139,9 +139,9 @@ pub unsafe extern "C" fn lkt_database_add_to_history( /// [`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, + _db: *mut LktDatabaseConnection, + _cb: extern "C" fn(i64, *mut c_void), + _user: *mut c_void, ) -> bool { todo!() } @@ -151,7 +151,7 @@ pub unsafe extern "C" fn lkt_database_iter_history( /// 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 { +pub unsafe extern "C" fn lkt_database_clear_history(_db: *mut LktDatabaseConnection) -> bool { todo!() } @@ -162,10 +162,10 @@ pub unsafe extern "C" fn lkt_database_clear_history(db: *mut LktDatabaseConnecti /// 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, + _db: *mut LktDatabaseConnection, + _uri: LktUriPtr, + _cb: extern "C" fn(i64, *mut c_void), + _user: *mut c_void, ) -> bool { todo!() } @@ -178,11 +178,11 @@ pub unsafe extern "C" fn lkt_database_search( /// 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, + _db: *mut LktDatabaseConnection, + _playlist: *mut c_char, + _uri: LktUriPtr, + _cb: extern "C" fn(i64, *mut c_void), + _user: *mut c_void, ) -> bool { todo!() } diff --git a/src/rust/lektor_unsafe/src/lib.rs b/src/rust/lektor_unsafe/src/lib.rs index 7df01add86dfd15231e490be4e9abf2919f5ae26..39a589feeb58b89c2756dc0f928aff87504344ab 100644 --- a/src/rust/lektor_unsafe/src/lib.rs +++ b/src/rust/lektor_unsafe/src/lib.rs @@ -1,10 +1,9 @@ //! Create C functions to calls things defined in the rust language from C code. //! See the headers inside the liblektor-rs folder from the C include directory. -#![allow(unused_variables)] - pub mod db; pub mod loging; +pub mod queue; pub mod repo; pub(crate) use lektor_c_compat::{c::*, *}; diff --git a/src/rust/lektor_unsafe/src/queue.rs b/src/rust/lektor_unsafe/src/queue.rs new file mode 100644 index 0000000000000000000000000000000000000000..55abd86b49b584b8815f6a99da93e558a3795bf7 --- /dev/null +++ b/src/rust/lektor_unsafe/src/queue.rs @@ -0,0 +1,100 @@ +//! An unsafe interface around the rust implementation of the queue to be able +//! to call it from C or C++ code. +//! +//! Be carefull when naming things because those names might collide with things +//! defined in lektor's C code... + +use crate::*; +use lektor_db::queue::{LktDatabasePriority, LktQueue}; + +/// Create a queue. On error log the message and +/// return a [`std::ptr::null_mut`]. +/// ### Safety +/// You must check if the returned pointer is null or not. +#[no_mangle] +pub unsafe extern "C" fn lkt_database_queue_new() -> *mut LktQueue { + todo!() +} + +#[no_mangle] +pub unsafe extern "C" fn lkt_database_queue_delete(_queue: *mut LktQueue) { + todo!() +} + +#[no_mangle] +pub unsafe extern "C" fn lkt_database_queue_current(_queue: *mut LktQueue, _ret: *mut i64) -> bool { + todo!() +} + +#[no_mangle] +pub unsafe extern "C" fn lkt_database_queue_add_kara( + _queue: *mut LktQueue, + _id: i64, + _prio: LktDatabasePriority, +) -> bool { + todo!() +} + +#[no_mangle] +pub unsafe extern "C" fn lkt_database_queue_peek_next( + _queue: *mut LktQueue, + _ret: *mut i64, +) -> bool { + todo!() +} + +#[no_mangle] +pub unsafe extern "C" fn lkt_database_queue_pop_next( + _queue: *mut LktQueue, + _ret: *mut i64, +) -> bool { + todo!() +} + +#[no_mangle] +pub unsafe extern "C" fn lkt_database_queue_swap( + _queue: *mut LktQueue, + _pos1: usize, + _pos2: usize, + _ret: *mut i64, +) -> bool { + todo!() +} + +#[no_mangle] +pub unsafe extern "C" fn lkt_database_queue_delete_all( + _queue: *mut LktQueue, + _id: i64, + _ret: *mut usize, +) -> bool { + todo!() +} + +#[no_mangle] +pub unsafe extern "C" fn lkt_database_queue_clear( + _queue: *mut LktQueue, + _prio: LktDatabasePriority, + _ret: *mut usize, +) -> bool { + todo!() +} + +#[no_mangle] +pub unsafe extern "C" fn lkt_database_queue_crop(_queue: *mut LktQueue, _ret: *mut usize) -> bool { + todo!() +} + +#[no_mangle] +pub unsafe extern "C" fn lkt_database_queue_shuffle(_queue: *mut LktQueue) -> bool { + todo!() +} + +#[no_mangle] +pub unsafe extern "C" fn lkt_database_queue_search( + _queue: *mut LktQueue, + _uri: LktUriPtr, + _cb: extern "C" fn(i64, *mut c_void), + _user: *mut c_void, +) -> bool { + todo!() +} diff --git a/src/rust/lektor_unsafe/src/repo.rs b/src/rust/lektor_unsafe/src/repo.rs index 89346dd98ef9677e48c75192b767660dd64c747e..aae4b8c0ea2e61eb3565bb202f9f7059cdee7441 100644 --- a/src/rust/lektor_unsafe/src/repo.rs +++ b/src/rust/lektor_unsafe/src/repo.rs @@ -12,8 +12,8 @@ extern "C" fn lkt_module_repo_rs_get_struct_size() -> size_t { #[no_mangle] extern "C" fn lkt_module_repo_rs_init( repo: LktModuleRepoRsPtr, - queue: LktQueuePtr, - db: LktDbPtr, + _queue: LktQueuePtr, + _db: LktDbPtr, ) -> i32 { let _repo: &mut LktModuleRepoRs = unsafe { &mut *repo }; 1 @@ -26,21 +26,25 @@ extern "C" fn lkt_module_repo_rs_free(repo: LktModuleRepoRsPtr) -> i32 { } #[no_mangle] -extern "C" fn lkt_module_repo_rs_update(repo: LktModuleRepoRsPtr, uri: LktUriPtr) -> i32 { +extern "C" fn lkt_module_repo_rs_update(repo: LktModuleRepoRsPtr, _uri: LktUriPtr) -> i32 { + let _repo: &mut LktModuleRepoRs = unsafe { &mut *repo }; 1 } #[no_mangle] extern "C" fn lkt_module_repo_rs_dry_update(repo: LktModuleRepoRsPtr) -> i32 { + let _repo: &mut LktModuleRepoRs = unsafe { &mut *repo }; 1 } #[no_mangle] extern "C" fn lkt_module_repo_rs_rescan(repo: LktModuleRepoRsPtr) -> i32 { + let _repo: &mut LktModuleRepoRs = unsafe { &mut *repo }; 1 } #[no_mangle] extern "C" fn lkt_module_repo_rs_import(repo: LktModuleRepoRsPtr) -> i32 { + let _repo: &mut LktModuleRepoRs = unsafe { &mut *repo }; 1 }