mirror of
https://git.proxmox.com/git/proxmox-backup-qemu
synced 2025-10-10 20:27:33 +00:00
use opaque type for handle, use reasonable names
This commit is contained in:
parent
734da1f499
commit
99ebe8c690
27
src/lib.rs
27
src/lib.rs
@ -97,13 +97,11 @@ fn backup_worker_task(mut rx: Receiver<BackupMessage>, host: &str) -> Result<(),
|
|||||||
// The C interface
|
// The C interface
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct BackupHandle {
|
pub struct ProxmoxBackupHandle {}
|
||||||
task: Box<BackupTask>,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn connect() -> *mut BackupHandle {
|
pub unsafe extern "C" fn proxmox_backup_connect() -> *mut ProxmoxBackupHandle {
|
||||||
|
|
||||||
println!("Hello");
|
println!("Hello");
|
||||||
|
|
||||||
@ -111,15 +109,15 @@ pub unsafe extern "C" fn connect() -> *mut BackupHandle {
|
|||||||
Ok(task) => {
|
Ok(task) => {
|
||||||
let tmp = Box::new(task);
|
let tmp = Box::new(task);
|
||||||
let test = Box::into_raw(tmp);
|
let test = Box::into_raw(tmp);
|
||||||
test as * mut BackupHandle
|
test as * mut ProxmoxBackupHandle
|
||||||
}
|
}
|
||||||
Err(err) => std::ptr::null_mut(),
|
Err(err) => std::ptr::null_mut(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn write_data_async(
|
pub unsafe extern "C" fn proxmox_backup_write_data_async(
|
||||||
handle: *mut BackupHandle,
|
handle: *mut ProxmoxBackupHandle,
|
||||||
data: *const u8,
|
data: *const u8,
|
||||||
size: u64,
|
size: u64,
|
||||||
callback: extern "C" fn(*mut libc::c_void),
|
callback: extern "C" fn(*mut libc::c_void),
|
||||||
@ -128,19 +126,22 @@ pub unsafe extern "C" fn write_data_async(
|
|||||||
|
|
||||||
let msg = BackupMessage::WriteData { data, size , callback, callback_data };
|
let msg = BackupMessage::WriteData { data, size , callback, callback_data };
|
||||||
|
|
||||||
let _res = (*handle).task.tx.send(msg); // fixme: log errors
|
let task = handle as * mut BackupTask;
|
||||||
|
|
||||||
|
let _res = (*task).tx.send(msg); // fixme: log errors
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn disconnect(handle: *mut BackupHandle) {
|
pub unsafe extern "C" fn proxmox_backup_disconnect(handle: *mut ProxmoxBackupHandle) {
|
||||||
|
|
||||||
println!("diconnect");
|
println!("diconnect");
|
||||||
|
|
||||||
let mut handle = Box::from_raw(handle);
|
let task = handle as * mut BackupTask;
|
||||||
|
let mut task = Box::from_raw(task); // take ownership
|
||||||
|
|
||||||
let _res = handle.task.tx.send(BackupMessage::End); // fixme: log errors
|
let _res = task.tx.send(BackupMessage::End); // fixme: log errors
|
||||||
|
|
||||||
match handle.task.worker.join() {
|
match task.worker.join() {
|
||||||
Ok(result) => {
|
Ok(result) => {
|
||||||
match result {
|
match result {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
@ -156,6 +157,6 @@ pub unsafe extern "C" fn disconnect(handle: *mut BackupHandle) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//drop(handle);
|
//drop(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user