252 lines
6.8 KiB
Rust
252 lines
6.8 KiB
Rust
/* generated by rust_qt_binding_generator */
|
|
#![allow(unknown_lints)]
|
|
#![allow(mutex_atomic, needless_pass_by_value)]
|
|
use libc::{c_int, c_void, uint8_t, uint16_t};
|
|
use std::slice;
|
|
|
|
use std::sync::{Arc, Mutex};
|
|
use std::ptr::null;
|
|
|
|
use fibonacci_implementation::*;
|
|
|
|
|
|
#[repr(C)]
|
|
pub struct COption<T> {
|
|
data: T,
|
|
some: bool,
|
|
}
|
|
|
|
impl<T> From<Option<T>> for COption<T>
|
|
where
|
|
T: Default,
|
|
{
|
|
fn from(t: Option<T>) -> COption<T> {
|
|
if let Some(v) = t {
|
|
COption {
|
|
data: v,
|
|
some: true,
|
|
}
|
|
} else {
|
|
COption {
|
|
data: T::default(),
|
|
some: false,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#[repr(C)]
|
|
pub enum SortOrder {
|
|
Ascending = 0,
|
|
Descending = 1,
|
|
}
|
|
|
|
#[repr(C)]
|
|
pub struct QModelIndex {
|
|
row: c_int,
|
|
internal_id: usize,
|
|
}
|
|
|
|
pub struct FibonacciQObject {}
|
|
|
|
#[derive(Clone)]
|
|
pub struct FibonacciEmitter {
|
|
qobject: Arc<Mutex<*const FibonacciQObject>>,
|
|
input_changed: fn(*const FibonacciQObject),
|
|
result_changed: fn(*const FibonacciQObject),
|
|
}
|
|
|
|
unsafe impl Send for FibonacciEmitter {}
|
|
|
|
impl FibonacciEmitter {
|
|
fn clear(&self) {
|
|
*self.qobject.lock().unwrap() = null();
|
|
}
|
|
pub fn input_changed(&self) {
|
|
let ptr = *self.qobject.lock().unwrap();
|
|
if !ptr.is_null() {
|
|
(self.input_changed)(ptr);
|
|
}
|
|
}
|
|
pub fn result_changed(&self) {
|
|
let ptr = *self.qobject.lock().unwrap();
|
|
if !ptr.is_null() {
|
|
(self.result_changed)(ptr);
|
|
}
|
|
}
|
|
}
|
|
|
|
pub trait FibonacciTrait {
|
|
fn create(emit: FibonacciEmitter) -> Self;
|
|
fn emit(&self) -> &FibonacciEmitter;
|
|
fn input(&self) -> u32;
|
|
fn set_input(&mut self, value: u32);
|
|
fn result(&self) -> u64;
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub extern "C" fn fibonacci_new(
|
|
fibonacci: *mut FibonacciQObject,
|
|
input_changed: fn(*const FibonacciQObject),
|
|
result_changed: fn(*const FibonacciQObject),
|
|
) -> *mut Fibonacci {
|
|
let fibonacci_emit = FibonacciEmitter {
|
|
qobject: Arc::new(Mutex::new(fibonacci)),
|
|
input_changed: input_changed,
|
|
result_changed: result_changed,
|
|
};
|
|
let d_fibonacci = Fibonacci::create(fibonacci_emit);
|
|
Box::into_raw(Box::new(d_fibonacci))
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub unsafe extern "C" fn fibonacci_free(ptr: *mut Fibonacci) {
|
|
Box::from_raw(ptr).emit().clear();
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub unsafe extern "C" fn fibonacci_input_get(ptr: *const Fibonacci) -> u32 {
|
|
(&*ptr).input()
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub unsafe extern "C" fn fibonacci_input_set(ptr: *mut Fibonacci, v: u32) {
|
|
(&mut *ptr).set_input(v);
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub unsafe extern "C" fn fibonacci_result_get(ptr: *const Fibonacci) -> u64 {
|
|
(&*ptr).result()
|
|
}
|
|
|
|
pub struct FibonacciListQObject {}
|
|
|
|
#[derive(Clone)]
|
|
pub struct FibonacciListEmitter {
|
|
qobject: Arc<Mutex<*const FibonacciListQObject>>,
|
|
new_data_ready: fn(*const FibonacciListQObject),
|
|
}
|
|
|
|
unsafe impl Send for FibonacciListEmitter {}
|
|
|
|
impl FibonacciListEmitter {
|
|
fn clear(&self) {
|
|
*self.qobject.lock().unwrap() = null();
|
|
}
|
|
pub fn new_data_ready(&self) {
|
|
let ptr = *self.qobject.lock().unwrap();
|
|
if !ptr.is_null() {
|
|
(self.new_data_ready)(ptr);
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct FibonacciListList {
|
|
qobject: *const FibonacciListQObject,
|
|
data_changed: fn(*const FibonacciListQObject, usize, usize),
|
|
begin_reset_model: fn(*const FibonacciListQObject),
|
|
end_reset_model: fn(*const FibonacciListQObject),
|
|
begin_insert_rows: fn(*const FibonacciListQObject, usize, usize),
|
|
end_insert_rows: fn(*const FibonacciListQObject),
|
|
begin_remove_rows: fn(*const FibonacciListQObject, usize, usize),
|
|
end_remove_rows: fn(*const FibonacciListQObject),
|
|
}
|
|
|
|
impl FibonacciListList {
|
|
pub fn data_changed(&self, first: usize, last: usize) {
|
|
(self.data_changed)(self.qobject, first, last);
|
|
}
|
|
pub fn begin_reset_model(&self) {
|
|
(self.begin_reset_model)(self.qobject);
|
|
}
|
|
pub fn end_reset_model(&self) {
|
|
(self.end_reset_model)(self.qobject);
|
|
}
|
|
pub fn begin_insert_rows(&self, first: usize, last: usize) {
|
|
(self.begin_insert_rows)(self.qobject, first, last);
|
|
}
|
|
pub fn end_insert_rows(&self) {
|
|
(self.end_insert_rows)(self.qobject);
|
|
}
|
|
pub fn begin_remove_rows(&self, first: usize, last: usize) {
|
|
(self.begin_remove_rows)(self.qobject, first, last);
|
|
}
|
|
pub fn end_remove_rows(&self) {
|
|
(self.end_remove_rows)(self.qobject);
|
|
}
|
|
}
|
|
|
|
pub trait FibonacciListTrait {
|
|
fn create(emit: FibonacciListEmitter, model: FibonacciListList) -> Self;
|
|
fn emit(&self) -> &FibonacciListEmitter;
|
|
fn row_count(&self) -> usize;
|
|
fn can_fetch_more(&self) -> bool {
|
|
false
|
|
}
|
|
fn fetch_more(&mut self) {}
|
|
fn sort(&mut self, u8, SortOrder) {}
|
|
fn result(&self, item: usize) -> u64;
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub extern "C" fn fibonacci_list_new(
|
|
fibonacci_list: *mut FibonacciListQObject,
|
|
new_data_ready: fn(*const FibonacciListQObject),
|
|
data_changed: fn(*const FibonacciListQObject, usize, usize),
|
|
begin_reset_model: fn(*const FibonacciListQObject),
|
|
end_reset_model: fn(*const FibonacciListQObject),
|
|
begin_insert_rows: fn(*const FibonacciListQObject, usize, usize),
|
|
end_insert_rows: fn(*const FibonacciListQObject),
|
|
begin_remove_rows: fn(*const FibonacciListQObject, usize, usize),
|
|
end_remove_rows: fn(*const FibonacciListQObject),
|
|
) -> *mut FibonacciList {
|
|
let fibonacci_list_emit = FibonacciListEmitter {
|
|
qobject: Arc::new(Mutex::new(fibonacci_list)),
|
|
new_data_ready: new_data_ready,
|
|
};
|
|
let model = FibonacciListList {
|
|
qobject: fibonacci_list,
|
|
data_changed: data_changed,
|
|
begin_reset_model: begin_reset_model,
|
|
end_reset_model: end_reset_model,
|
|
begin_insert_rows: begin_insert_rows,
|
|
end_insert_rows: end_insert_rows,
|
|
begin_remove_rows: begin_remove_rows,
|
|
end_remove_rows: end_remove_rows,
|
|
};
|
|
let d_fibonacci_list = FibonacciList::create(fibonacci_list_emit, model);
|
|
Box::into_raw(Box::new(d_fibonacci_list))
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub unsafe extern "C" fn fibonacci_list_free(ptr: *mut FibonacciList) {
|
|
Box::from_raw(ptr).emit().clear();
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub unsafe extern "C" fn fibonacci_list_row_count(ptr: *const FibonacciList) -> c_int {
|
|
(&*ptr).row_count() as c_int
|
|
}
|
|
#[no_mangle]
|
|
pub unsafe extern "C" fn fibonacci_list_can_fetch_more(ptr: *const FibonacciList) -> bool {
|
|
(&*ptr).can_fetch_more()
|
|
}
|
|
#[no_mangle]
|
|
pub unsafe extern "C" fn fibonacci_list_fetch_more(ptr: *mut FibonacciList) {
|
|
(&mut *ptr).fetch_more()
|
|
}
|
|
#[no_mangle]
|
|
pub unsafe extern "C" fn fibonacci_list_sort(
|
|
ptr: *mut FibonacciList,
|
|
column: u8,
|
|
order: SortOrder,
|
|
) {
|
|
(&mut *ptr).sort(column, order)
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub unsafe extern "C" fn fibonacci_list_data_result(ptr: *const FibonacciList, row: c_int) -> u64 {
|
|
(&*ptr).result(row as usize).into()
|
|
}
|