Skip to content
Extraits de code Groupes Projets
Valider a40cfa09 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

RUST: Add wrappers for queue functions to call rust stuff from C

parent 96a97569
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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)
}
......
#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___
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!()
}
}
......@@ -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!()
}
//! 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::*, *};
......
//! 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!()
}
......@@ -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
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter