rust-qt-binding-generator/demo/rust/src/time_series_interface.rs

150 lines
4.6 KiB
Rust

/* generated by rust_qt_binding_generator */
#![allow(unknown_lints)]
#![allow(mutex_atomic, needless_pass_by_value)]
#![allow(unused_imports)]
use libc::{c_int, c_uint, c_void};
use types::*;
use std::sync::{Arc, Mutex};
use std::ptr::null;
use time_series_implementation::*;
pub struct TimeSeriesQObject {}
#[derive (Clone)]
pub struct TimeSeriesEmitter {
qobject: Arc<Mutex<*const TimeSeriesQObject>>,
new_data_ready: fn(*const TimeSeriesQObject),
}
unsafe impl Send for TimeSeriesEmitter {}
impl TimeSeriesEmitter {
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 TimeSeriesList {
qobject: *const TimeSeriesQObject,
begin_reset_model: fn(*const TimeSeriesQObject),
end_reset_model: fn(*const TimeSeriesQObject),
begin_insert_rows: fn(*const TimeSeriesQObject, c_int, c_int),
end_insert_rows: fn(*const TimeSeriesQObject),
begin_remove_rows: fn(*const TimeSeriesQObject, c_int, c_int),
end_remove_rows: fn(*const TimeSeriesQObject),
}
impl TimeSeriesList {
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: c_int, last: c_int) {
(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: c_int, last: c_int) {
(self.begin_remove_rows)(self.qobject, first, last);
}
pub fn end_remove_rows(&self) {
(self.end_remove_rows)(self.qobject);
}
}
pub trait TimeSeriesTrait {
fn create(emit: TimeSeriesEmitter, model: TimeSeriesList) -> Self;
fn emit(&self) -> &TimeSeriesEmitter;
fn row_count(&self) -> c_int;
fn can_fetch_more(&self) -> bool { false }
fn fetch_more(&mut self) {}
fn sort(&mut self, c_int, SortOrder) {}
fn input(&self, row: c_int) -> u32;
fn set_input(&mut self, row: c_int, u32) -> bool;
fn result(&self, row: c_int) -> u32;
fn set_result(&mut self, row: c_int, u32) -> bool;
}
#[no_mangle]
pub extern "C" fn time_series_new(qobject: *const TimeSeriesQObject,
new_data_ready: fn(*const TimeSeriesQObject),
begin_reset_model: fn(*const TimeSeriesQObject),
end_reset_model: fn(*const TimeSeriesQObject),
begin_insert_rows: fn(*const TimeSeriesQObject,
c_int,
c_int),
end_insert_rows: fn(*const TimeSeriesQObject),
begin_remove_rows: fn(*const TimeSeriesQObject,
c_int,
c_int),
end_remove_rows: fn(*const TimeSeriesQObject))
-> *mut TimeSeries {
let emit = TimeSeriesEmitter {
qobject: Arc::new(Mutex::new(qobject)),
new_data_ready: new_data_ready,
};
let model = TimeSeriesList {
qobject: qobject,
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 = TimeSeries::create(emit, model);
Box::into_raw(Box::new(d))
}
#[no_mangle]
pub unsafe extern "C" fn time_series_free(ptr: *mut TimeSeries) {
Box::from_raw(ptr).emit().clear();
}
#[no_mangle]
pub unsafe extern "C" fn time_series_row_count(ptr: *const TimeSeries) -> c_int {
(&*ptr).row_count()
}
#[no_mangle]
pub unsafe extern "C" fn time_series_can_fetch_more(ptr: *const TimeSeries) -> bool {
(&*ptr).can_fetch_more()
}
#[no_mangle]
pub unsafe extern "C" fn time_series_fetch_more(ptr: *mut TimeSeries) {
(&mut *ptr).fetch_more()
}
#[no_mangle]
pub unsafe extern "C" fn time_series_sort(ptr: *mut TimeSeries, column: c_int, order: SortOrder) {
(&mut *ptr).sort(column, order)
}
#[no_mangle]
pub unsafe extern "C" fn time_series_data_input(ptr: *const TimeSeries, row: c_int) -> u32 {
(&*ptr).input(row).into()
}
#[no_mangle]
pub unsafe extern "C" fn time_series_set_data_input(ptr: *mut TimeSeries, row: c_int, v: u32) -> bool {
(&mut *ptr).set_input(row, v)
}
#[no_mangle]
pub unsafe extern "C" fn time_series_data_result(ptr: *const TimeSeries, row: c_int) -> u32 {
(&*ptr).result(row).into()
}
#[no_mangle]
pub unsafe extern "C" fn time_series_set_data_result(ptr: *mut TimeSeries, row: c_int, v: u32) -> bool {
(&mut *ptr).set_result(row, v)
}