Rust code formatting improvements
parent
3e9e4208ce
commit
bd908181ec
|
@ -6,7 +6,7 @@ use std::sync::Arc;
|
|||
|
||||
fn fibonacci(input: u32) -> usize {
|
||||
if input <= 1 {
|
||||
return input as usize
|
||||
return input as usize;
|
||||
}
|
||||
let mut i = 0;
|
||||
let mut sum = 0;
|
||||
|
|
|
@ -16,17 +16,20 @@ pub struct COption<T> {
|
|||
some: bool,
|
||||
}
|
||||
|
||||
impl<T> From<Option<T>> for COption<T> where T: Default {
|
||||
fn from(t: Option<T>) -> COption <T> {
|
||||
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
|
||||
some: true,
|
||||
}
|
||||
} else {
|
||||
COption {
|
||||
data: T::default(),
|
||||
some: false
|
||||
some: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +39,7 @@ impl<T> From<Option<T>> for COption<T> where T: Default {
|
|||
#[repr(C)]
|
||||
pub enum SortOrder {
|
||||
Ascending = 0,
|
||||
Descending = 1
|
||||
Descending = 1,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
|
@ -47,7 +50,7 @@ pub struct QModelIndex {
|
|||
|
||||
pub struct FibonacciQObject {}
|
||||
|
||||
#[derive (Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct FibonacciEmitter {
|
||||
qobject: Arc<Mutex<*const FibonacciQObject>>,
|
||||
input_changed: fn(*const FibonacciQObject),
|
||||
|
@ -83,10 +86,11 @@ pub trait FibonacciTrait {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fibonacci_new(fibonacci: *mut FibonacciQObject,
|
||||
input_changed: fn(*const FibonacciQObject),
|
||||
result_changed: fn(*const FibonacciQObject))
|
||||
-> *mut Fibonacci {
|
||||
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,
|
||||
|
@ -118,7 +122,7 @@ pub unsafe extern "C" fn fibonacci_result_get(ptr: *const Fibonacci) -> u64 {
|
|||
|
||||
pub struct FibonacciListQObject {}
|
||||
|
||||
#[derive (Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct FibonacciListEmitter {
|
||||
qobject: Arc<Mutex<*const FibonacciListQObject>>,
|
||||
new_data_ready: fn(*const FibonacciListQObject),
|
||||
|
@ -177,27 +181,26 @@ 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 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 {
|
||||
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,
|
||||
|
@ -234,7 +237,11 @@ 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) {
|
||||
pub unsafe extern "C" fn fibonacci_list_sort(
|
||||
ptr: *mut FibonacciList,
|
||||
column: u8,
|
||||
order: SortOrder,
|
||||
) {
|
||||
(&mut *ptr).sort(column, order)
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ use std::collections::HashMap;
|
|||
pub struct DirEntry {
|
||||
name: OsString,
|
||||
metadata: Option<Metadata>,
|
||||
path: Option<PathBuf>
|
||||
path: Option<PathBuf>,
|
||||
}
|
||||
|
||||
type Incoming<T> = Arc<Mutex<HashMap<usize, Vec<T>>>>;
|
||||
|
@ -22,11 +22,11 @@ impl Item for DirEntry {
|
|||
DirEntry {
|
||||
name: OsString::from(name),
|
||||
metadata: metadata(name).ok(),
|
||||
path: None
|
||||
path: None,
|
||||
}
|
||||
}
|
||||
fn can_fetch_more(&self) -> bool {
|
||||
self.metadata.as_ref().map_or(false, |m|m.is_dir())
|
||||
self.metadata.as_ref().map_or(false, |m| m.is_dir())
|
||||
}
|
||||
fn file_name(&self) -> String {
|
||||
self.name.to_string_lossy().to_string()
|
||||
|
@ -41,11 +41,9 @@ impl Item for DirEntry {
|
|||
0
|
||||
}
|
||||
fn file_size(&self) -> Option<u64> {
|
||||
self.metadata.as_ref().map(|m|m.len())
|
||||
self.metadata.as_ref().map(|m| m.len())
|
||||
}
|
||||
fn retrieve(id: usize, parents: Vec<&DirEntry>,
|
||||
q: Incoming<Self>,
|
||||
emit: TreeEmitter) {
|
||||
fn retrieve(id: usize, parents: Vec<&DirEntry>, q: Incoming<Self>, emit: TreeEmitter) {
|
||||
let mut v = Vec::new();
|
||||
let path: PathBuf = parents.into_iter().map(|e| &e.name).collect();
|
||||
thread::spawn(move || {
|
||||
|
@ -54,7 +52,7 @@ impl Item for DirEntry {
|
|||
let de = DirEntry {
|
||||
name: i.file_name(),
|
||||
metadata: i.metadata().ok(),
|
||||
path: Some(i.path())
|
||||
path: Some(i.path()),
|
||||
};
|
||||
v.push(de);
|
||||
}
|
||||
|
@ -74,7 +72,7 @@ impl Default for DirEntry {
|
|||
DirEntry {
|
||||
name: OsString::new(),
|
||||
metadata: None,
|
||||
path: None
|
||||
path: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -107,7 +105,10 @@ pub struct RGeneralItemModel<T: Item> {
|
|||
incoming: Incoming<T>,
|
||||
}
|
||||
|
||||
impl<T: Item> RGeneralItemModel<T> where T: Sync + Send {
|
||||
impl<T: Item> RGeneralItemModel<T>
|
||||
where
|
||||
T: Sync + Send,
|
||||
{
|
||||
fn reset(&mut self) {
|
||||
self.model.begin_reset_model();
|
||||
self.entries.clear();
|
||||
|
@ -150,8 +151,11 @@ impl<T: Item> RGeneralItemModel<T> where T: Sync + Send {
|
|||
new_entries.push(e);
|
||||
}
|
||||
if new_entries.len() > 0 {
|
||||
self.model.begin_insert_rows(Some(id), 0,
|
||||
(new_entries.len() - 1));
|
||||
self.model.begin_insert_rows(
|
||||
Some(id),
|
||||
0,
|
||||
(new_entries.len() - 1),
|
||||
);
|
||||
}
|
||||
}
|
||||
self.entries[id].children = Some(children);
|
||||
|
@ -173,14 +177,17 @@ impl<T: Item> RGeneralItemModel<T> where T: Sync + Send {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Item> TreeTrait for RGeneralItemModel<T> where T: Sync + Send {
|
||||
impl<T: Item> TreeTrait for RGeneralItemModel<T>
|
||||
where
|
||||
T: Sync + Send,
|
||||
{
|
||||
fn create(emit: TreeEmitter, model: TreeUniformTree) -> Self {
|
||||
let mut tree = RGeneralItemModel {
|
||||
emit: emit,
|
||||
model: model,
|
||||
entries: Vec::new(),
|
||||
path: None,
|
||||
incoming: Arc::new(Mutex::new(HashMap::new()))
|
||||
incoming: Arc::new(Mutex::new(HashMap::new())),
|
||||
};
|
||||
tree.reset();
|
||||
tree
|
||||
|
|
|
@ -16,17 +16,20 @@ pub struct COption<T> {
|
|||
some: bool,
|
||||
}
|
||||
|
||||
impl<T> From<Option<T>> for COption<T> where T: Default {
|
||||
fn from(t: Option<T>) -> COption <T> {
|
||||
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
|
||||
some: true,
|
||||
}
|
||||
} else {
|
||||
COption {
|
||||
data: T::default(),
|
||||
some: false
|
||||
some: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +91,7 @@ impl<'a> From<&'a Vec<u8>> for QByteArray {
|
|||
#[repr(C)]
|
||||
pub enum SortOrder {
|
||||
Ascending = 0,
|
||||
Descending = 1
|
||||
Descending = 1,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
|
@ -99,7 +102,7 @@ pub struct QModelIndex {
|
|||
|
||||
pub struct TreeQObject {}
|
||||
|
||||
#[derive (Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct TreeEmitter {
|
||||
qobject: Arc<Mutex<*const TreeQObject>>,
|
||||
path_changed: fn(*const TreeQObject),
|
||||
|
@ -121,7 +124,7 @@ impl TreeEmitter {
|
|||
pub fn new_data_ready(&self, item: Option<usize>) {
|
||||
let ptr = *self.qobject.lock().unwrap();
|
||||
if !ptr.is_null() {
|
||||
(self.new_data_ready)(ptr, item.unwrap_or(13), item.is_some());
|
||||
(self.new_data_ready)(ptr, item.unwrap_or(13), item.is_some());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -167,7 +170,9 @@ pub trait TreeTrait {
|
|||
fn get_path(&self) -> Option<String>;
|
||||
fn set_path(&mut self, value: Option<String>);
|
||||
fn row_count(&self, Option<usize>) -> usize;
|
||||
fn can_fetch_more(&self, Option<usize>) -> bool { false }
|
||||
fn can_fetch_more(&self, Option<usize>) -> bool {
|
||||
false
|
||||
}
|
||||
fn fetch_more(&mut self, Option<usize>) {}
|
||||
fn sort(&mut self, u8, SortOrder) {}
|
||||
fn index(&self, item: Option<usize>, row: usize) -> usize;
|
||||
|
@ -182,21 +187,18 @@ pub trait TreeTrait {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn tree_new(tree: *mut TreeQObject,
|
||||
path_changed: fn(*const TreeQObject),
|
||||
new_data_ready: fn(*const TreeQObject, item: usize, valid: bool),
|
||||
data_changed: fn(*const TreeQObject, usize, usize),
|
||||
begin_reset_model: fn(*const TreeQObject),
|
||||
end_reset_model: fn(*const TreeQObject),
|
||||
begin_insert_rows: fn(*const TreeQObject, item: usize, valid: bool,
|
||||
usize,
|
||||
usize),
|
||||
end_insert_rows: fn(*const TreeQObject),
|
||||
begin_remove_rows: fn(*const TreeQObject, item: usize, valid: bool,
|
||||
usize,
|
||||
usize),
|
||||
end_remove_rows: fn(*const TreeQObject))
|
||||
-> *mut Tree {
|
||||
pub extern "C" fn tree_new(
|
||||
tree: *mut TreeQObject,
|
||||
path_changed: fn(*const TreeQObject),
|
||||
new_data_ready: fn(*const TreeQObject, item: usize, valid: bool),
|
||||
data_changed: fn(*const TreeQObject, usize, usize),
|
||||
begin_reset_model: fn(*const TreeQObject),
|
||||
end_reset_model: fn(*const TreeQObject),
|
||||
begin_insert_rows: fn(*const TreeQObject, item: usize, valid: bool, usize, usize),
|
||||
end_insert_rows: fn(*const TreeQObject),
|
||||
begin_remove_rows: fn(*const TreeQObject, item: usize, valid: bool, usize, usize),
|
||||
end_remove_rows: fn(*const TreeQObject),
|
||||
) -> *mut Tree {
|
||||
let tree_emit = TreeEmitter {
|
||||
qobject: Arc::new(Mutex::new(tree)),
|
||||
path_changed: path_changed,
|
||||
|
@ -222,9 +224,11 @@ pub unsafe extern "C" fn tree_free(ptr: *mut Tree) {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tree_path_get(ptr: *const Tree,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, QString)) {
|
||||
pub unsafe extern "C" fn tree_path_get(
|
||||
ptr: *const Tree,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, QString),
|
||||
) {
|
||||
let data = (&*ptr).get_path();
|
||||
if let Some(data) = data {
|
||||
set(p, QString::from(&data));
|
||||
|
@ -241,7 +245,11 @@ pub unsafe extern "C" fn tree_path_set_none(ptr: *mut Tree) {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tree_row_count(ptr: *const Tree, item: usize, valid: bool) -> c_int {
|
||||
pub unsafe extern "C" fn tree_row_count(
|
||||
ptr: *const Tree,
|
||||
item: usize,
|
||||
valid: bool,
|
||||
) -> c_int {
|
||||
if valid {
|
||||
(&*ptr).row_count(Some(item)) as c_int
|
||||
} else {
|
||||
|
@ -249,7 +257,11 @@ pub unsafe extern "C" fn tree_row_count(ptr: *const Tree, item: usize, valid: bo
|
|||
}
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tree_can_fetch_more(ptr: *const Tree, item: usize, valid: bool) -> bool {
|
||||
pub unsafe extern "C" fn tree_can_fetch_more(
|
||||
ptr: *const Tree,
|
||||
item: usize,
|
||||
valid: bool,
|
||||
) -> bool {
|
||||
if valid {
|
||||
(&*ptr).can_fetch_more(Some(item))
|
||||
} else {
|
||||
|
@ -265,11 +277,20 @@ pub unsafe extern "C" fn tree_fetch_more(ptr: *mut Tree, item: usize, valid: boo
|
|||
}
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tree_sort(ptr: *mut Tree, column: u8, order: SortOrder) {
|
||||
pub unsafe extern "C" fn tree_sort(
|
||||
ptr: *mut Tree,
|
||||
column: u8,
|
||||
order: SortOrder
|
||||
) {
|
||||
(&mut *ptr).sort(column, order)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tree_index(ptr: *const Tree, item: usize, valid: bool, row: c_int) -> usize {
|
||||
pub unsafe extern "C" fn tree_index(
|
||||
ptr: *const Tree,
|
||||
item: usize,
|
||||
valid: bool,
|
||||
row: c_int,
|
||||
) -> usize {
|
||||
if !valid {
|
||||
(&*ptr).index(None, row as usize)
|
||||
} else {
|
||||
|
@ -279,9 +300,15 @@ pub unsafe extern "C" fn tree_index(ptr: *const Tree, item: usize, valid: bool,
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tree_parent(ptr: *const Tree, index: usize) -> QModelIndex {
|
||||
if let Some(parent) = (&*ptr).parent(index) {
|
||||
QModelIndex{row: (&*ptr).row(parent) as c_int, internal_id: parent}
|
||||
QModelIndex {
|
||||
row: (&*ptr).row(parent) as c_int,
|
||||
internal_id: parent,
|
||||
}
|
||||
} else {
|
||||
QModelIndex{row: -1, internal_id: 0}
|
||||
QModelIndex {
|
||||
row: -1,
|
||||
internal_id: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
#[no_mangle]
|
||||
|
@ -290,25 +317,31 @@ pub unsafe extern "C" fn tree_row(ptr: *const Tree, item: usize) -> c_int {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tree_data_file_icon(ptr: *const Tree, item: usize,
|
||||
d: *mut c_void,
|
||||
set: fn(*mut c_void, QByteArray)) {
|
||||
pub unsafe extern "C" fn tree_data_file_icon(
|
||||
ptr: *const Tree, item: usize,
|
||||
d: *mut c_void,
|
||||
set: fn(*mut c_void, QByteArray),
|
||||
) {
|
||||
let data = (&*ptr).file_icon(item);
|
||||
set(d, QByteArray::from(&data));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tree_data_file_name(ptr: *const Tree, item: usize,
|
||||
d: *mut c_void,
|
||||
set: fn(*mut c_void, QString)) {
|
||||
pub unsafe extern "C" fn tree_data_file_name(
|
||||
ptr: *const Tree, item: usize,
|
||||
d: *mut c_void,
|
||||
set: fn(*mut c_void, QString),
|
||||
) {
|
||||
let data = (&*ptr).file_name(item);
|
||||
set(d, QString::from(&data));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tree_data_file_path(ptr: *const Tree, item: usize,
|
||||
d: *mut c_void,
|
||||
set: fn(*mut c_void, QString)) {
|
||||
pub unsafe extern "C" fn tree_data_file_path(
|
||||
ptr: *const Tree, item: usize,
|
||||
d: *mut c_void,
|
||||
set: fn(*mut c_void, QString),
|
||||
) {
|
||||
let data = (&*ptr).file_path(item);
|
||||
if let Some(data) = data {
|
||||
set(d, QString::from(&data));
|
||||
|
|
|
@ -8,14 +8,14 @@ use std::{thread, time};
|
|||
struct ProcessItem {
|
||||
row: usize,
|
||||
tasks: Vec<pid_t>,
|
||||
process: Process
|
||||
process: Process,
|
||||
}
|
||||
|
||||
#[derive (Default)]
|
||||
#[derive(Default)]
|
||||
struct ProcessTree {
|
||||
top: Vec<pid_t>,
|
||||
processes: HashMap<pid_t, ProcessItem>,
|
||||
cpusum: f32
|
||||
cpusum: f32,
|
||||
}
|
||||
|
||||
pub struct Processes {
|
||||
|
@ -23,10 +23,10 @@ pub struct Processes {
|
|||
model: ProcessesUniformTree,
|
||||
p: ProcessTree,
|
||||
incoming: Arc<Mutex<Option<ProcessTree>>>,
|
||||
active: bool
|
||||
active: bool,
|
||||
}
|
||||
|
||||
fn check_process_hierarchy(parent: Option<pid_t>, processes: &HashMap<pid_t,Process>) {
|
||||
fn check_process_hierarchy(parent: Option<pid_t>, processes: &HashMap<pid_t, Process>) {
|
||||
for (pid, process) in processes {
|
||||
assert_eq!(process.pid, *pid);
|
||||
if !parent.is_none() {
|
||||
|
@ -36,15 +36,20 @@ fn check_process_hierarchy(parent: Option<pid_t>, processes: &HashMap<pid_t,Proc
|
|||
}
|
||||
}
|
||||
|
||||
fn collect_processes(tasks: &HashMap<pid_t,Process>,
|
||||
mut processes: &mut HashMap<pid_t, ProcessItem>) -> f32 {
|
||||
fn collect_processes(
|
||||
tasks: &HashMap<pid_t, Process>,
|
||||
mut processes: &mut HashMap<pid_t, ProcessItem>,
|
||||
) -> f32 {
|
||||
let mut cpusum = 0.0;
|
||||
for process in tasks.values() {
|
||||
processes.insert(process.pid, ProcessItem {
|
||||
row: 0,
|
||||
tasks: Vec::new(),
|
||||
process: process.clone()
|
||||
});
|
||||
processes.insert(
|
||||
process.pid,
|
||||
ProcessItem {
|
||||
row: 0,
|
||||
tasks: Vec::new(),
|
||||
process: process.clone(),
|
||||
},
|
||||
);
|
||||
let s = collect_processes(&process.tasks, &mut processes);
|
||||
cpusum += process.cpu_usage + s;
|
||||
}
|
||||
|
@ -118,8 +123,11 @@ impl Processes {
|
|||
}
|
||||
}
|
||||
|
||||
fn move_process(pid: pid_t, amap: &mut HashMap<pid_t, ProcessItem>,
|
||||
bmap: &mut HashMap<pid_t, ProcessItem>) {
|
||||
fn move_process(
|
||||
pid: pid_t,
|
||||
amap: &mut HashMap<pid_t, ProcessItem>,
|
||||
bmap: &mut HashMap<pid_t, ProcessItem>,
|
||||
) {
|
||||
if let Some(e) = bmap.remove(&pid) {
|
||||
amap.insert(pid, e);
|
||||
let ts = amap[&pid].tasks.clone();
|
||||
|
@ -129,11 +137,19 @@ fn move_process(pid: pid_t, amap: &mut HashMap<pid_t, ProcessItem>,
|
|||
}
|
||||
}
|
||||
|
||||
fn remove_row(model: &ProcessesUniformTree, parent: pid_t, row: usize,
|
||||
map: &mut HashMap<pid_t, ProcessItem>) {
|
||||
fn remove_row(
|
||||
model: &ProcessesUniformTree,
|
||||
parent: pid_t,
|
||||
row: usize,
|
||||
map: &mut HashMap<pid_t, ProcessItem>,
|
||||
) {
|
||||
let pid = map[&parent].tasks[row];
|
||||
println!("removing {} '{}' {}", pid, map[&pid].process.exe,
|
||||
map[&pid].process.cmd.join(" "));
|
||||
println!(
|
||||
"removing {} '{}' {}",
|
||||
pid,
|
||||
map[&pid].process.exe,
|
||||
map[&pid].process.cmd.join(" ")
|
||||
);
|
||||
model.begin_remove_rows(Some(parent as usize), row, row);
|
||||
map.remove(&pid);
|
||||
let len = {
|
||||
|
@ -148,11 +164,20 @@ fn remove_row(model: &ProcessesUniformTree, parent: pid_t, row: usize,
|
|||
model.end_remove_rows();
|
||||
}
|
||||
|
||||
fn insert_row(model: &ProcessesUniformTree, parent: pid_t, row: usize,
|
||||
map: &mut HashMap<pid_t, ProcessItem>, pid: pid_t,
|
||||
source: &mut HashMap<pid_t, ProcessItem>) {
|
||||
println!("adding {} '{}' {}", pid, source[&pid].process.exe,
|
||||
source[&pid].process.cmd.join(" "));
|
||||
fn insert_row(
|
||||
model: &ProcessesUniformTree,
|
||||
parent: pid_t,
|
||||
row: usize,
|
||||
map: &mut HashMap<pid_t, ProcessItem>,
|
||||
pid: pid_t,
|
||||
source: &mut HashMap<pid_t, ProcessItem>,
|
||||
) {
|
||||
println!(
|
||||
"adding {} '{}' {}",
|
||||
pid,
|
||||
source[&pid].process.exe,
|
||||
source[&pid].process.cmd.join(" ")
|
||||
);
|
||||
model.begin_insert_rows(Some(parent as usize), row, row);
|
||||
move_process(pid, map, source);
|
||||
let len = {
|
||||
|
@ -167,8 +192,7 @@ fn insert_row(model: &ProcessesUniformTree, parent: pid_t, row: usize,
|
|||
model.end_insert_rows();
|
||||
}
|
||||
|
||||
fn sync_row(model: &ProcessesUniformTree, pid: pid_t,
|
||||
a: &mut Process, b: &Process) -> f32 {
|
||||
fn sync_row(model: &ProcessesUniformTree, pid: pid_t, a: &mut Process, b: &Process) -> f32 {
|
||||
let mut changed = false;
|
||||
if a.name != b.name {
|
||||
a.name.clone_from(&b.name);
|
||||
|
@ -196,9 +220,12 @@ fn sync_row(model: &ProcessesUniformTree, pid: pid_t,
|
|||
b.cpu_usage
|
||||
}
|
||||
|
||||
fn sync_tree(model: &ProcessesUniformTree, parent: pid_t,
|
||||
amap: &mut HashMap<pid_t, ProcessItem>,
|
||||
bmap: &mut HashMap<pid_t, ProcessItem>) -> f32 {
|
||||
fn sync_tree(
|
||||
model: &ProcessesUniformTree,
|
||||
parent: pid_t,
|
||||
amap: &mut HashMap<pid_t, ProcessItem>,
|
||||
bmap: &mut HashMap<pid_t, ProcessItem>,
|
||||
) -> f32 {
|
||||
let mut a = 0;
|
||||
let mut b = 0;
|
||||
let mut alen = amap[&parent].tasks.len();
|
||||
|
@ -208,19 +235,24 @@ fn sync_tree(model: &ProcessesUniformTree, parent: pid_t,
|
|||
while a < alen && b < blen {
|
||||
let apid = amap[&parent].tasks[a];
|
||||
let bpid = bmap[&parent].tasks[b];
|
||||
if apid < bpid { // a process has disappeared
|
||||
if apid < bpid {
|
||||
// a process has disappeared
|
||||
remove_row(model, parent, a, amap);
|
||||
alen -= 1;
|
||||
} else if apid > bpid { // a process has appeared
|
||||
} else if apid > bpid {
|
||||
// a process has appeared
|
||||
insert_row(model, parent, a, amap, bpid, bmap);
|
||||
cpu_total += amap[&bpid].process.cpu_usage;
|
||||
a += 1;
|
||||
alen += 1;
|
||||
b += 1;
|
||||
} else {
|
||||
cpu_total += sync_row(model, apid,
|
||||
&mut amap.get_mut(&apid).unwrap().process,
|
||||
&bmap[&apid].process);
|
||||
cpu_total += sync_row(
|
||||
model,
|
||||
apid,
|
||||
&mut amap.get_mut(&apid).unwrap().process,
|
||||
&bmap[&apid].process,
|
||||
);
|
||||
cpu_total += sync_tree(model, apid, amap, bmap);
|
||||
a += 1;
|
||||
b += 1;
|
||||
|
@ -237,7 +269,7 @@ fn sync_tree(model: &ProcessesUniformTree, parent: pid_t,
|
|||
remove_row(model, parent, a, amap);
|
||||
alen -= 1;
|
||||
}
|
||||
if cpu_total != bmap[&parent].process.cpu_usage {
|
||||
if cpu_total != bmap[&parent].process.cpu_usage {
|
||||
amap.get_mut(&parent).unwrap().process.cpu_usage = cpu_total;
|
||||
model.data_changed(parent as usize, parent as usize);
|
||||
}
|
||||
|
@ -252,7 +284,7 @@ impl ProcessesTrait for Processes {
|
|||
model: model,
|
||||
p: ProcessTree::default(),
|
||||
incoming: Arc::new(Mutex::new(None)),
|
||||
active: true
|
||||
active: true,
|
||||
};
|
||||
update_thread(emit, p.incoming.clone());
|
||||
p
|
||||
|
@ -305,8 +337,7 @@ impl ProcessesTrait for Processes {
|
|||
} else {
|
||||
let top = self.p.top.clone();
|
||||
for pid in top {
|
||||
sync_tree(&self.model, pid, &mut self.p.processes,
|
||||
&mut new.processes);
|
||||
sync_tree(&self.model, pid, &mut self.p.processes, &mut new.processes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,17 +16,20 @@ pub struct COption<T> {
|
|||
some: bool,
|
||||
}
|
||||
|
||||
impl<T> From<Option<T>> for COption<T> where T: Default {
|
||||
fn from(t: Option<T>) -> COption <T> {
|
||||
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
|
||||
some: true,
|
||||
}
|
||||
} else {
|
||||
COption {
|
||||
data: T::default(),
|
||||
some: false
|
||||
some: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +68,7 @@ impl<'a> From<&'a String> for QString {
|
|||
#[repr(C)]
|
||||
pub enum SortOrder {
|
||||
Ascending = 0,
|
||||
Descending = 1
|
||||
Descending = 1,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
|
@ -76,7 +79,7 @@ pub struct QModelIndex {
|
|||
|
||||
pub struct ProcessesQObject {}
|
||||
|
||||
#[derive (Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct ProcessesEmitter {
|
||||
qobject: Arc<Mutex<*const ProcessesQObject>>,
|
||||
active_changed: fn(*const ProcessesQObject),
|
||||
|
@ -98,7 +101,7 @@ impl ProcessesEmitter {
|
|||
pub fn new_data_ready(&self, item: Option<usize>) {
|
||||
let ptr = *self.qobject.lock().unwrap();
|
||||
if !ptr.is_null() {
|
||||
(self.new_data_ready)(ptr, item.unwrap_or(13), item.is_some());
|
||||
(self.new_data_ready)(ptr, item.unwrap_or(13), item.is_some());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -144,7 +147,9 @@ pub trait ProcessesTrait {
|
|||
fn get_active(&self) -> bool;
|
||||
fn set_active(&mut self, value: bool);
|
||||
fn row_count(&self, Option<usize>) -> usize;
|
||||
fn can_fetch_more(&self, Option<usize>) -> bool { false }
|
||||
fn can_fetch_more(&self, Option<usize>) -> bool {
|
||||
false
|
||||
}
|
||||
fn fetch_more(&mut self, Option<usize>) {}
|
||||
fn sort(&mut self, u8, SortOrder) {}
|
||||
fn index(&self, item: Option<usize>, row: usize) -> usize;
|
||||
|
@ -160,21 +165,18 @@ pub trait ProcessesTrait {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn processes_new(processes: *mut ProcessesQObject,
|
||||
active_changed: fn(*const ProcessesQObject),
|
||||
new_data_ready: fn(*const ProcessesQObject, item: usize, valid: bool),
|
||||
data_changed: fn(*const ProcessesQObject, usize, usize),
|
||||
begin_reset_model: fn(*const ProcessesQObject),
|
||||
end_reset_model: fn(*const ProcessesQObject),
|
||||
begin_insert_rows: fn(*const ProcessesQObject, item: usize, valid: bool,
|
||||
usize,
|
||||
usize),
|
||||
end_insert_rows: fn(*const ProcessesQObject),
|
||||
begin_remove_rows: fn(*const ProcessesQObject, item: usize, valid: bool,
|
||||
usize,
|
||||
usize),
|
||||
end_remove_rows: fn(*const ProcessesQObject))
|
||||
-> *mut Processes {
|
||||
pub extern "C" fn processes_new(
|
||||
processes: *mut ProcessesQObject,
|
||||
active_changed: fn(*const ProcessesQObject),
|
||||
new_data_ready: fn(*const ProcessesQObject, item: usize, valid: bool),
|
||||
data_changed: fn(*const ProcessesQObject, usize, usize),
|
||||
begin_reset_model: fn(*const ProcessesQObject),
|
||||
end_reset_model: fn(*const ProcessesQObject),
|
||||
begin_insert_rows: fn(*const ProcessesQObject, item: usize, valid: bool, usize, usize),
|
||||
end_insert_rows: fn(*const ProcessesQObject),
|
||||
begin_remove_rows: fn(*const ProcessesQObject, item: usize, valid: bool, usize, usize),
|
||||
end_remove_rows: fn(*const ProcessesQObject),
|
||||
) -> *mut Processes {
|
||||
let processes_emit = ProcessesEmitter {
|
||||
qobject: Arc::new(Mutex::new(processes)),
|
||||
active_changed: active_changed,
|
||||
|
@ -210,7 +212,11 @@ pub unsafe extern "C" fn processes_active_set(ptr: *mut Processes, v: bool) {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn processes_row_count(ptr: *const Processes, item: usize, valid: bool) -> c_int {
|
||||
pub unsafe extern "C" fn processes_row_count(
|
||||
ptr: *const Processes,
|
||||
item: usize,
|
||||
valid: bool,
|
||||
) -> c_int {
|
||||
if valid {
|
||||
(&*ptr).row_count(Some(item)) as c_int
|
||||
} else {
|
||||
|
@ -218,7 +224,11 @@ pub unsafe extern "C" fn processes_row_count(ptr: *const Processes, item: usize,
|
|||
}
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn processes_can_fetch_more(ptr: *const Processes, item: usize, valid: bool) -> bool {
|
||||
pub unsafe extern "C" fn processes_can_fetch_more(
|
||||
ptr: *const Processes,
|
||||
item: usize,
|
||||
valid: bool,
|
||||
) -> bool {
|
||||
if valid {
|
||||
(&*ptr).can_fetch_more(Some(item))
|
||||
} else {
|
||||
|
@ -234,11 +244,20 @@ pub unsafe extern "C" fn processes_fetch_more(ptr: *mut Processes, item: usize,
|
|||
}
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn processes_sort(ptr: *mut Processes, column: u8, order: SortOrder) {
|
||||
pub unsafe extern "C" fn processes_sort(
|
||||
ptr: *mut Processes,
|
||||
column: u8,
|
||||
order: SortOrder
|
||||
) {
|
||||
(&mut *ptr).sort(column, order)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn processes_index(ptr: *const Processes, item: usize, valid: bool, row: c_int) -> usize {
|
||||
pub unsafe extern "C" fn processes_index(
|
||||
ptr: *const Processes,
|
||||
item: usize,
|
||||
valid: bool,
|
||||
row: c_int,
|
||||
) -> usize {
|
||||
if !valid {
|
||||
(&*ptr).index(None, row as usize)
|
||||
} else {
|
||||
|
@ -248,9 +267,15 @@ pub unsafe extern "C" fn processes_index(ptr: *const Processes, item: usize, val
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn processes_parent(ptr: *const Processes, index: usize) -> QModelIndex {
|
||||
if let Some(parent) = (&*ptr).parent(index) {
|
||||
QModelIndex{row: (&*ptr).row(parent) as c_int, internal_id: parent}
|
||||
QModelIndex {
|
||||
row: (&*ptr).row(parent) as c_int,
|
||||
internal_id: parent,
|
||||
}
|
||||
} else {
|
||||
QModelIndex{row: -1, internal_id: 0}
|
||||
QModelIndex {
|
||||
row: -1,
|
||||
internal_id: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
#[no_mangle]
|
||||
|
@ -259,9 +284,11 @@ pub unsafe extern "C" fn processes_row(ptr: *const Processes, item: usize) -> c_
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn processes_data_cmd(ptr: *const Processes, item: usize,
|
||||
d: *mut c_void,
|
||||
set: fn(*mut c_void, QString)) {
|
||||
pub unsafe extern "C" fn processes_data_cmd(
|
||||
ptr: *const Processes, item: usize,
|
||||
d: *mut c_void,
|
||||
set: fn(*mut c_void, QString),
|
||||
) {
|
||||
let data = (&*ptr).cmd(item);
|
||||
set(d, QString::from(&data));
|
||||
}
|
||||
|
@ -282,9 +309,11 @@ pub unsafe extern "C" fn processes_data_memory(ptr: *const Processes, item: usiz
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn processes_data_name(ptr: *const Processes, item: usize,
|
||||
d: *mut c_void,
|
||||
set: fn(*mut c_void, QString)) {
|
||||
pub unsafe extern "C" fn processes_data_name(
|
||||
ptr: *const Processes, item: usize,
|
||||
d: *mut c_void,
|
||||
set: fn(*mut c_void, QString),
|
||||
) {
|
||||
let data = (&*ptr).name(item);
|
||||
set(d, QString::from(&data));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use time_series_interface::*;
|
||||
|
||||
#[derive (Default, Clone)]
|
||||
#[derive(Default, Clone)]
|
||||
struct TimeSeriesItem {
|
||||
input: u32,
|
||||
result: u32,
|
||||
|
@ -17,12 +17,12 @@ impl TimeSeriesTrait for TimeSeries {
|
|||
let mut series = TimeSeries {
|
||||
emit: emit,
|
||||
model: model,
|
||||
list: Vec::new()
|
||||
list: Vec::new(),
|
||||
};
|
||||
for i in 0..100 {
|
||||
series.list.push(TimeSeriesItem {
|
||||
input: i,
|
||||
result: 2 * i
|
||||
result: 2 * i,
|
||||
});
|
||||
}
|
||||
series
|
||||
|
|
|
@ -16,17 +16,20 @@ pub struct COption<T> {
|
|||
some: bool,
|
||||
}
|
||||
|
||||
impl<T> From<Option<T>> for COption<T> where T: Default {
|
||||
fn from(t: Option<T>) -> COption <T> {
|
||||
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
|
||||
some: true,
|
||||
}
|
||||
} else {
|
||||
COption {
|
||||
data: T::default(),
|
||||
some: false
|
||||
some: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +39,7 @@ impl<T> From<Option<T>> for COption<T> where T: Default {
|
|||
#[repr(C)]
|
||||
pub enum SortOrder {
|
||||
Ascending = 0,
|
||||
Descending = 1
|
||||
Descending = 1,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
|
@ -47,7 +50,7 @@ pub struct QModelIndex {
|
|||
|
||||
pub struct TimeSeriesQObject {}
|
||||
|
||||
#[derive (Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct TimeSeriesEmitter {
|
||||
qobject: Arc<Mutex<*const TimeSeriesQObject>>,
|
||||
new_data_ready: fn(*const TimeSeriesQObject),
|
||||
|
@ -106,7 +109,9 @@ pub trait TimeSeriesTrait {
|
|||
fn create(emit: TimeSeriesEmitter, model: TimeSeriesList) -> Self;
|
||||
fn emit(&self) -> &TimeSeriesEmitter;
|
||||
fn row_count(&self) -> usize;
|
||||
fn can_fetch_more(&self) -> bool { false }
|
||||
fn can_fetch_more(&self) -> bool {
|
||||
false
|
||||
}
|
||||
fn fetch_more(&mut self) {}
|
||||
fn sort(&mut self, u8, SortOrder) {}
|
||||
fn input(&self, item: usize) -> u32;
|
||||
|
@ -116,20 +121,17 @@ pub trait TimeSeriesTrait {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn time_series_new(time_series: *mut TimeSeriesQObject,
|
||||
new_data_ready: fn(*const TimeSeriesQObject),
|
||||
data_changed: fn(*const TimeSeriesQObject, usize, usize),
|
||||
begin_reset_model: fn(*const TimeSeriesQObject),
|
||||
end_reset_model: fn(*const TimeSeriesQObject),
|
||||
begin_insert_rows: fn(*const TimeSeriesQObject,
|
||||
usize,
|
||||
usize),
|
||||
end_insert_rows: fn(*const TimeSeriesQObject),
|
||||
begin_remove_rows: fn(*const TimeSeriesQObject,
|
||||
usize,
|
||||
usize),
|
||||
end_remove_rows: fn(*const TimeSeriesQObject))
|
||||
-> *mut TimeSeries {
|
||||
pub extern "C" fn time_series_new(
|
||||
time_series: *mut TimeSeriesQObject,
|
||||
new_data_ready: fn(*const TimeSeriesQObject),
|
||||
data_changed: fn(*const TimeSeriesQObject, usize, usize),
|
||||
begin_reset_model: fn(*const TimeSeriesQObject),
|
||||
end_reset_model: fn(*const TimeSeriesQObject),
|
||||
begin_insert_rows: fn(*const TimeSeriesQObject, usize, usize),
|
||||
end_insert_rows: fn(*const TimeSeriesQObject),
|
||||
begin_remove_rows: fn(*const TimeSeriesQObject, usize, usize),
|
||||
end_remove_rows: fn(*const TimeSeriesQObject),
|
||||
) -> *mut TimeSeries {
|
||||
let time_series_emit = TimeSeriesEmitter {
|
||||
qobject: Arc::new(Mutex::new(time_series)),
|
||||
new_data_ready: new_data_ready,
|
||||
|
@ -166,7 +168,11 @@ 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: u8, order: SortOrder) {
|
||||
pub unsafe extern "C" fn time_series_sort(
|
||||
ptr: *mut TimeSeries,
|
||||
column: u8,
|
||||
order: SortOrder,
|
||||
) {
|
||||
(&mut *ptr).sort(column, order)
|
||||
}
|
||||
|
||||
|
@ -176,7 +182,10 @@ pub unsafe extern "C" fn time_series_data_input(ptr: *const TimeSeries, row: c_i
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn time_series_set_data_input(ptr: *mut TimeSeries, row: c_int, v: u32) -> bool {
|
||||
pub unsafe extern "C" fn time_series_set_data_input(
|
||||
ptr: *mut TimeSeries, row: c_int,
|
||||
v: u32,
|
||||
) -> bool {
|
||||
(&mut *ptr).set_input(row as usize, v)
|
||||
}
|
||||
|
||||
|
@ -186,6 +195,9 @@ pub unsafe extern "C" fn time_series_data_result(ptr: *const TimeSeries, row: c_
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn time_series_set_data_result(ptr: *mut TimeSeries, row: c_int, v: u32) -> bool {
|
||||
pub unsafe extern "C" fn time_series_set_data_result(
|
||||
ptr: *mut TimeSeries, row: c_int,
|
||||
v: u32,
|
||||
) -> bool {
|
||||
(&mut *ptr).set_result(row as usize, v)
|
||||
}
|
||||
|
|
140
src/rust.cpp
140
src/rust.cpp
|
@ -29,21 +29,21 @@ QString rustTypeInit(const T& p)
|
|||
}
|
||||
|
||||
void rConstructorArgsDecl(QTextStream& r, const QString& name, const Object& o, const Configuration& conf) {
|
||||
r << QString("%2: *mut %1QObject").arg(o.name, name);
|
||||
r << QString(" %2: *mut %1QObject").arg(o.name, name);
|
||||
for (const Property& p: o.properties) {
|
||||
if (p.type.type == BindingType::Object) {
|
||||
r << QString(", ");
|
||||
r << QString(",\n");
|
||||
rConstructorArgsDecl(r, p.name, conf.findObject(p.type.name), conf);
|
||||
} else {
|
||||
r << QString(",\n %2_changed: fn(*const %1QObject)")
|
||||
r << QString(",\n %2_changed: fn(*const %1QObject)")
|
||||
.arg(o.name, snakeCase(p.name));
|
||||
}
|
||||
}
|
||||
if (o.type == ObjectType::List) {
|
||||
r << QString(",\n new_data_ready: fn(*const %1QObject)")
|
||||
r << QString(",\n new_data_ready: fn(*const %1QObject)")
|
||||
.arg(o.name);
|
||||
} else if (o.type == ObjectType::UniformTree) {
|
||||
r << QString(",\n new_data_ready: fn(*const %1QObject, item: usize, valid: bool)")
|
||||
r << QString(",\n new_data_ready: fn(*const %1QObject, item: usize, valid: bool)")
|
||||
.arg(o.name);
|
||||
}
|
||||
if (o.type != ObjectType::Object) {
|
||||
|
@ -52,17 +52,13 @@ void rConstructorArgsDecl(QTextStream& r, const QString& name, const Object& o,
|
|||
indexDecl = " item: usize, valid: bool,";
|
||||
}
|
||||
r << QString(R"(,
|
||||
data_changed: fn(*const %1QObject, usize, usize),
|
||||
begin_reset_model: fn(*const %1QObject),
|
||||
end_reset_model: fn(*const %1QObject),
|
||||
begin_insert_rows: fn(*const %1QObject,%2
|
||||
usize,
|
||||
usize),
|
||||
end_insert_rows: fn(*const %1QObject),
|
||||
begin_remove_rows: fn(*const %1QObject,%2
|
||||
usize,
|
||||
usize),
|
||||
end_remove_rows: fn(*const %1QObject))").arg(o.name, indexDecl);
|
||||
data_changed: fn(*const %1QObject, usize, usize),
|
||||
begin_reset_model: fn(*const %1QObject),
|
||||
end_reset_model: fn(*const %1QObject),
|
||||
begin_insert_rows: fn(*const %1QObject,%2 usize, usize),
|
||||
end_insert_rows: fn(*const %1QObject),
|
||||
begin_remove_rows: fn(*const %1QObject,%2 usize, usize),
|
||||
end_remove_rows: fn(*const %1QObject))").arg(o.name, indexDecl);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,7 +110,7 @@ void writeRustInterfaceObject(QTextStream& r, const Object& o, const Configurati
|
|||
r << QString(R"(
|
||||
pub struct %1QObject {}
|
||||
|
||||
#[derive (Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct %1Emitter {
|
||||
qobject: Arc<Mutex<*const %1QObject>>,
|
||||
)").arg(o.name);
|
||||
|
@ -165,7 +161,7 @@ impl %1Emitter {
|
|||
r << R"( pub fn new_data_ready(&self, item: Option<usize>) {
|
||||
let ptr = *self.qobject.lock().unwrap();
|
||||
if !ptr.is_null() {
|
||||
(self.new_data_ready)(ptr, item.unwrap_or(13), item.is_some());
|
||||
(self.new_data_ready)(ptr, item.unwrap_or(13), item.is_some());
|
||||
}
|
||||
}
|
||||
)";
|
||||
|
@ -247,13 +243,17 @@ pub trait %1Trait {
|
|||
}
|
||||
if (o.type == ObjectType::List) {
|
||||
r << R"( fn row_count(&self) -> usize;
|
||||
fn can_fetch_more(&self) -> bool { false }
|
||||
fn can_fetch_more(&self) -> bool {
|
||||
false
|
||||
}
|
||||
fn fetch_more(&mut self) {}
|
||||
fn sort(&mut self, u8, SortOrder) {}
|
||||
)";
|
||||
} else if (o.type == ObjectType::UniformTree) {
|
||||
r << R"( fn row_count(&self, Option<usize>) -> usize;
|
||||
fn can_fetch_more(&self, Option<usize>) -> bool { false }
|
||||
fn can_fetch_more(&self, Option<usize>) -> bool {
|
||||
false
|
||||
}
|
||||
fn fetch_more(&mut self, Option<usize>) {}
|
||||
fn sort(&mut self, u8, SortOrder) {}
|
||||
fn index(&self, item: Option<usize>, row: usize) -> usize;
|
||||
|
@ -275,9 +275,10 @@ pub trait %1Trait {
|
|||
r << QString(R"(}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn %1_new()").arg(lcname);
|
||||
pub extern "C" fn %1_new(
|
||||
)").arg(lcname);
|
||||
rConstructorArgsDecl(r, lcname, o, conf);
|
||||
r << QString(")\n -> *mut %1 {\n").arg(o.name);
|
||||
r << QString(",\n) -> *mut %1 {\n").arg(o.name);
|
||||
rConstructorArgs(r, lcname, o, conf);
|
||||
r << QString(R"( Box::into_raw(Box::new(d_%2))
|
||||
}
|
||||
|
@ -301,9 +302,11 @@ pub unsafe extern "C" fn %2_get(ptr: *mut %1) -> *mut %4 {
|
|||
} else if (p.type.isComplex() && !p.optional) {
|
||||
r << QString(R"(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn %2_get(ptr: *const %1,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, %4)) {
|
||||
pub unsafe extern "C" fn %2_get(
|
||||
ptr: *const %1,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, %4),
|
||||
) {
|
||||
let data = (&*ptr).get_%3();
|
||||
set(p, %4::from(&data));
|
||||
}
|
||||
|
@ -320,9 +323,11 @@ pub unsafe extern "C" fn %2_set(ptr: *mut %1, v: %4) {
|
|||
} else if (p.type.isComplex()) {
|
||||
r << QString(R"(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn %2_get(ptr: *const %1,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, %4)) {
|
||||
pub unsafe extern "C" fn %2_get(
|
||||
ptr: *const %1,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, %4),
|
||||
) {
|
||||
let data = (&*ptr).get_%3();
|
||||
if let Some(data) = data {
|
||||
set(p, %4::from(&data));
|
||||
|
@ -374,14 +379,22 @@ pub unsafe extern "C" fn %2_fetch_more(ptr: *mut %1) {
|
|||
(&mut *ptr).fetch_more()
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn %2_sort(ptr: *mut %1, column: u8, order: SortOrder) {
|
||||
pub unsafe extern "C" fn %2_sort(
|
||||
ptr: *mut %1,
|
||||
column: u8,
|
||||
order: SortOrder,
|
||||
) {
|
||||
(&mut *ptr).sort(column, order)
|
||||
}
|
||||
)").arg(o.name, lcname);
|
||||
} else if (o.type == ObjectType::UniformTree) {
|
||||
r << QString(R"(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn %2_row_count(ptr: *const %1, item: usize, valid: bool) -> c_int {
|
||||
pub unsafe extern "C" fn %2_row_count(
|
||||
ptr: *const %1,
|
||||
item: usize,
|
||||
valid: bool,
|
||||
) -> c_int {
|
||||
if valid {
|
||||
(&*ptr).row_count(Some(item)) as c_int
|
||||
} else {
|
||||
|
@ -389,7 +402,11 @@ pub unsafe extern "C" fn %2_row_count(ptr: *const %1, item: usize, valid: bool)
|
|||
}
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn %2_can_fetch_more(ptr: *const %1, item: usize, valid: bool) -> bool {
|
||||
pub unsafe extern "C" fn %2_can_fetch_more(
|
||||
ptr: *const %1,
|
||||
item: usize,
|
||||
valid: bool,
|
||||
) -> bool {
|
||||
if valid {
|
||||
(&*ptr).can_fetch_more(Some(item))
|
||||
} else {
|
||||
|
@ -405,11 +422,20 @@ pub unsafe extern "C" fn %2_fetch_more(ptr: *mut %1, item: usize, valid: bool) {
|
|||
}
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn %2_sort(ptr: *mut %1, column: u8, order: SortOrder) {
|
||||
pub unsafe extern "C" fn %2_sort(
|
||||
ptr: *mut %1,
|
||||
column: u8,
|
||||
order: SortOrder
|
||||
) {
|
||||
(&mut *ptr).sort(column, order)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn %2_index(ptr: *const %1, item: usize, valid: bool, row: c_int) -> usize {
|
||||
pub unsafe extern "C" fn %2_index(
|
||||
ptr: *const %1,
|
||||
item: usize,
|
||||
valid: bool,
|
||||
row: c_int,
|
||||
) -> usize {
|
||||
if !valid {
|
||||
(&*ptr).index(None, row as usize)
|
||||
} else {
|
||||
|
@ -419,9 +445,15 @@ pub unsafe extern "C" fn %2_index(ptr: *const %1, item: usize, valid: bool, row:
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn %2_parent(ptr: *const %1, index: usize) -> QModelIndex {
|
||||
if let Some(parent) = (&*ptr).parent(index) {
|
||||
QModelIndex{row: (&*ptr).row(parent) as c_int, internal_id: parent}
|
||||
QModelIndex {
|
||||
row: (&*ptr).row(parent) as c_int,
|
||||
internal_id: parent,
|
||||
}
|
||||
} else {
|
||||
QModelIndex{row: -1, internal_id: 0}
|
||||
QModelIndex {
|
||||
row: -1,
|
||||
internal_id: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
#[no_mangle]
|
||||
|
@ -441,9 +473,11 @@ pub unsafe extern "C" fn %2_row(ptr: *const %1, item: usize) -> c_int {
|
|||
if (ip.type.isComplex() && !ip.optional) {
|
||||
r << QString(R"(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn %2_data_%3(ptr: *const %1%5,
|
||||
d: *mut c_void,
|
||||
set: fn(*mut c_void, %4)) {
|
||||
pub unsafe extern "C" fn %2_data_%3(
|
||||
ptr: *const %1%5,
|
||||
d: *mut c_void,
|
||||
set: fn(*mut c_void, %4),
|
||||
) {
|
||||
let data = (&*ptr).%3(%6);
|
||||
set(d, %4::from(&data));
|
||||
}
|
||||
|
@ -451,9 +485,11 @@ pub unsafe extern "C" fn %2_data_%3(ptr: *const %1%5,
|
|||
} else if (ip.type.isComplex()) {
|
||||
r << QString(R"(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn %2_data_%3(ptr: *const %1%5,
|
||||
d: *mut c_void,
|
||||
set: fn(*mut c_void, %4)) {
|
||||
pub unsafe extern "C" fn %2_data_%3(
|
||||
ptr: *const %1%5,
|
||||
d: *mut c_void,
|
||||
set: fn(*mut c_void, %4),
|
||||
) {
|
||||
let data = (&*ptr).%3(%6);
|
||||
if let Some(data) = data {
|
||||
set(d, %4::from(&data));
|
||||
|
@ -480,7 +516,10 @@ pub unsafe extern "C" fn %2_data_%3(ptr: *const %1%5) -> %4 {
|
|||
}
|
||||
r << QString(R"(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn %2_set_data_%3(ptr: *mut %1%4, v: %6) -> bool {
|
||||
pub unsafe extern "C" fn %2_set_data_%3(
|
||||
ptr: *mut %1%4,
|
||||
v: %6,
|
||||
) -> bool {
|
||||
(&mut *ptr).set_%3(%5, %7)
|
||||
}
|
||||
)").arg(o.name, lcname, snakeCase(ip.name), indexDecl, index, type, val);
|
||||
|
@ -535,17 +574,20 @@ pub struct COption<T> {
|
|||
some: bool,
|
||||
}
|
||||
|
||||
impl<T> From<Option<T>> for COption<T> where T: Default {
|
||||
fn from(t: Option<T>) -> COption <T> {
|
||||
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
|
||||
some: true,
|
||||
}
|
||||
} else {
|
||||
COption {
|
||||
data: T::default(),
|
||||
some: false
|
||||
some: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -616,7 +658,7 @@ impl<'a> From<&'a Vec<u8>> for QByteArray {
|
|||
#[repr(C)]
|
||||
pub enum SortOrder {
|
||||
Ascending = 0,
|
||||
Descending = 1
|
||||
Descending = 1,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
|
@ -653,7 +695,7 @@ use %1::*;
|
|||
void writeRustImplementationObject(QTextStream& r, const Object& o) {
|
||||
const QString lcname(snakeCase(o.name));
|
||||
if (o.type != ObjectType::Object) {
|
||||
r << "#[derive (Default, Clone)]\n";
|
||||
r << "#[derive(Default, Clone)]\n";
|
||||
r << QString("struct %1Item {\n").arg(o.name);
|
||||
for (auto ip: o.itemProperties) {
|
||||
const QString lc(snakeCase(ip.name));
|
||||
|
@ -732,7 +774,7 @@ void writeRustImplementationObject(QTextStream& r, const Object& o) {
|
|||
self.%1 = value;
|
||||
self.emit.%1_changed();
|
||||
}
|
||||
)").arg(lc, rustType(p));
|
||||
)").arg(lc, rustType(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#![allow(dead_code)]
|
||||
use interface::*;
|
||||
|
||||
#[derive (Default, Clone)]
|
||||
#[derive(Default, Clone)]
|
||||
struct PersonsItem {
|
||||
user_name: String,
|
||||
}
|
||||
|
|
|
@ -16,17 +16,20 @@ pub struct COption<T> {
|
|||
some: bool,
|
||||
}
|
||||
|
||||
impl<T> From<Option<T>> for COption<T> where T: Default {
|
||||
fn from(t: Option<T>) -> COption <T> {
|
||||
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
|
||||
some: true,
|
||||
}
|
||||
} else {
|
||||
COption {
|
||||
data: T::default(),
|
||||
some: false
|
||||
some: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +68,7 @@ impl<'a> From<&'a String> for QString {
|
|||
#[repr(C)]
|
||||
pub enum SortOrder {
|
||||
Ascending = 0,
|
||||
Descending = 1
|
||||
Descending = 1,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
|
@ -76,7 +79,7 @@ pub struct QModelIndex {
|
|||
|
||||
pub struct PersonsQObject {}
|
||||
|
||||
#[derive (Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct PersonsEmitter {
|
||||
qobject: Arc<Mutex<*const PersonsQObject>>,
|
||||
new_data_ready: fn(*const PersonsQObject),
|
||||
|
@ -135,7 +138,9 @@ pub trait PersonsTrait {
|
|||
fn create(emit: PersonsEmitter, model: PersonsList) -> Self;
|
||||
fn emit(&self) -> &PersonsEmitter;
|
||||
fn row_count(&self) -> usize;
|
||||
fn can_fetch_more(&self) -> bool { false }
|
||||
fn can_fetch_more(&self) -> bool {
|
||||
false
|
||||
}
|
||||
fn fetch_more(&mut self) {}
|
||||
fn sort(&mut self, u8, SortOrder) {}
|
||||
fn user_name(&self, item: usize) -> String;
|
||||
|
@ -143,20 +148,17 @@ pub trait PersonsTrait {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn persons_new(persons: *mut PersonsQObject,
|
||||
new_data_ready: fn(*const PersonsQObject),
|
||||
data_changed: fn(*const PersonsQObject, usize, usize),
|
||||
begin_reset_model: fn(*const PersonsQObject),
|
||||
end_reset_model: fn(*const PersonsQObject),
|
||||
begin_insert_rows: fn(*const PersonsQObject,
|
||||
usize,
|
||||
usize),
|
||||
end_insert_rows: fn(*const PersonsQObject),
|
||||
begin_remove_rows: fn(*const PersonsQObject,
|
||||
usize,
|
||||
usize),
|
||||
end_remove_rows: fn(*const PersonsQObject))
|
||||
-> *mut Persons {
|
||||
pub extern "C" fn persons_new(
|
||||
persons: *mut PersonsQObject,
|
||||
new_data_ready: fn(*const PersonsQObject),
|
||||
data_changed: fn(*const PersonsQObject, usize, usize),
|
||||
begin_reset_model: fn(*const PersonsQObject),
|
||||
end_reset_model: fn(*const PersonsQObject),
|
||||
begin_insert_rows: fn(*const PersonsQObject, usize, usize),
|
||||
end_insert_rows: fn(*const PersonsQObject),
|
||||
begin_remove_rows: fn(*const PersonsQObject, usize, usize),
|
||||
end_remove_rows: fn(*const PersonsQObject),
|
||||
) -> *mut Persons {
|
||||
let persons_emit = PersonsEmitter {
|
||||
qobject: Arc::new(Mutex::new(persons)),
|
||||
new_data_ready: new_data_ready,
|
||||
|
@ -193,19 +195,28 @@ pub unsafe extern "C" fn persons_fetch_more(ptr: *mut Persons) {
|
|||
(&mut *ptr).fetch_more()
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn persons_sort(ptr: *mut Persons, column: u8, order: SortOrder) {
|
||||
pub unsafe extern "C" fn persons_sort(
|
||||
ptr: *mut Persons,
|
||||
column: u8,
|
||||
order: SortOrder,
|
||||
) {
|
||||
(&mut *ptr).sort(column, order)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn persons_data_user_name(ptr: *const Persons, row: c_int,
|
||||
d: *mut c_void,
|
||||
set: fn(*mut c_void, QString)) {
|
||||
pub unsafe extern "C" fn persons_data_user_name(
|
||||
ptr: *const Persons, row: c_int,
|
||||
d: *mut c_void,
|
||||
set: fn(*mut c_void, QString),
|
||||
) {
|
||||
let data = (&*ptr).user_name(row as usize);
|
||||
set(d, QString::from(&data));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn persons_set_data_user_name(ptr: *mut Persons, row: c_int, v: QStringIn) -> bool {
|
||||
pub unsafe extern "C" fn persons_set_data_user_name(
|
||||
ptr: *mut Persons, row: c_int,
|
||||
v: QStringIn,
|
||||
) -> bool {
|
||||
(&mut *ptr).set_user_name(row as usize, v.convert())
|
||||
}
|
||||
|
|
|
@ -25,5 +25,5 @@ impl PersonTrait for Person {
|
|||
self.user_name = value;
|
||||
self.emit.user_name_changed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ impl<'a> From<&'a String> for QString {
|
|||
|
||||
pub struct PersonQObject {}
|
||||
|
||||
#[derive (Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct PersonEmitter {
|
||||
qobject: Arc<Mutex<*const PersonQObject>>,
|
||||
user_name_changed: fn(*const PersonQObject),
|
||||
|
@ -68,9 +68,10 @@ pub trait PersonTrait {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn person_new(person: *mut PersonQObject,
|
||||
user_name_changed: fn(*const PersonQObject))
|
||||
-> *mut Person {
|
||||
pub extern "C" fn person_new(
|
||||
person: *mut PersonQObject,
|
||||
user_name_changed: fn(*const PersonQObject),
|
||||
) -> *mut Person {
|
||||
let person_emit = PersonEmitter {
|
||||
qobject: Arc::new(Mutex::new(person)),
|
||||
user_name_changed: user_name_changed,
|
||||
|
@ -85,9 +86,11 @@ pub unsafe extern "C" fn person_free(ptr: *mut Person) {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn person_user_name_get(ptr: *const Person,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, QString)) {
|
||||
pub unsafe extern "C" fn person_user_name_get(
|
||||
ptr: *const Person,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, QString),
|
||||
) {
|
||||
let data = (&*ptr).get_user_name();
|
||||
set(p, QString::from(&data));
|
||||
}
|
||||
|
|
|
@ -39,54 +39,54 @@ impl ObjectTrait for Object {
|
|||
self.boolean = value;
|
||||
self.emit.boolean_changed();
|
||||
}
|
||||
fn get_bytearray(&self) -> Vec<u8> {
|
||||
fn get_bytearray(&self) -> Vec<u8> {
|
||||
self.bytearray.clone()
|
||||
}
|
||||
fn set_bytearray(&mut self, value: Vec<u8>) {
|
||||
self.bytearray = value;
|
||||
self.emit.bytearray_changed();
|
||||
}
|
||||
fn get_integer(&self) -> i32 {
|
||||
fn get_integer(&self) -> i32 {
|
||||
self.integer
|
||||
}
|
||||
fn set_integer(&mut self, value: i32) {
|
||||
self.integer = value;
|
||||
self.emit.integer_changed();
|
||||
}
|
||||
fn get_optional_bytearray(&self) -> Option<Vec<u8>> {
|
||||
fn get_optional_bytearray(&self) -> Option<Vec<u8>> {
|
||||
self.optional_bytearray.clone()
|
||||
}
|
||||
fn set_optional_bytearray(&mut self, value: Option<Vec<u8>>) {
|
||||
self.optional_bytearray = value;
|
||||
self.emit.optional_bytearray_changed();
|
||||
}
|
||||
fn get_optional_string(&self) -> Option<String> {
|
||||
fn get_optional_string(&self) -> Option<String> {
|
||||
self.optional_string.clone()
|
||||
}
|
||||
fn set_optional_string(&mut self, value: Option<String>) {
|
||||
self.optional_string = value;
|
||||
self.emit.optional_string_changed();
|
||||
}
|
||||
fn get_string(&self) -> String {
|
||||
fn get_string(&self) -> String {
|
||||
self.string.clone()
|
||||
}
|
||||
fn set_string(&mut self, value: String) {
|
||||
self.string = value;
|
||||
self.emit.string_changed();
|
||||
}
|
||||
fn get_u64(&self) -> u64 {
|
||||
fn get_u64(&self) -> u64 {
|
||||
self.u64
|
||||
}
|
||||
fn set_u64(&mut self, value: u64) {
|
||||
self.u64 = value;
|
||||
self.emit.u64_changed();
|
||||
}
|
||||
fn get_uinteger(&self) -> u32 {
|
||||
fn get_uinteger(&self) -> u32 {
|
||||
self.uinteger
|
||||
}
|
||||
fn set_uinteger(&mut self, value: u32) {
|
||||
self.uinteger = value;
|
||||
self.emit.uinteger_changed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,17 +16,20 @@ pub struct COption<T> {
|
|||
some: bool,
|
||||
}
|
||||
|
||||
impl<T> From<Option<T>> for COption<T> where T: Default {
|
||||
fn from(t: Option<T>) -> COption <T> {
|
||||
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
|
||||
some: true,
|
||||
}
|
||||
} else {
|
||||
COption {
|
||||
data: T::default(),
|
||||
some: false
|
||||
some: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +89,7 @@ impl<'a> From<&'a Vec<u8>> for QByteArray {
|
|||
|
||||
pub struct ObjectQObject {}
|
||||
|
||||
#[derive (Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct ObjectEmitter {
|
||||
qobject: Arc<Mutex<*const ObjectQObject>>,
|
||||
boolean_changed: fn(*const ObjectQObject),
|
||||
|
@ -177,16 +180,17 @@ pub trait ObjectTrait {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn object_new(object: *mut ObjectQObject,
|
||||
boolean_changed: fn(*const ObjectQObject),
|
||||
bytearray_changed: fn(*const ObjectQObject),
|
||||
integer_changed: fn(*const ObjectQObject),
|
||||
optional_bytearray_changed: fn(*const ObjectQObject),
|
||||
optional_string_changed: fn(*const ObjectQObject),
|
||||
string_changed: fn(*const ObjectQObject),
|
||||
u64_changed: fn(*const ObjectQObject),
|
||||
uinteger_changed: fn(*const ObjectQObject))
|
||||
-> *mut Object {
|
||||
pub extern "C" fn object_new(
|
||||
object: *mut ObjectQObject,
|
||||
boolean_changed: fn(*const ObjectQObject),
|
||||
bytearray_changed: fn(*const ObjectQObject),
|
||||
integer_changed: fn(*const ObjectQObject),
|
||||
optional_bytearray_changed: fn(*const ObjectQObject),
|
||||
optional_string_changed: fn(*const ObjectQObject),
|
||||
string_changed: fn(*const ObjectQObject),
|
||||
u64_changed: fn(*const ObjectQObject),
|
||||
uinteger_changed: fn(*const ObjectQObject),
|
||||
) -> *mut Object {
|
||||
let object_emit = ObjectEmitter {
|
||||
qobject: Arc::new(Mutex::new(object)),
|
||||
boolean_changed: boolean_changed,
|
||||
|
@ -218,9 +222,11 @@ pub unsafe extern "C" fn object_boolean_set(ptr: *mut Object, v: bool) {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn object_bytearray_get(ptr: *const Object,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, QByteArray)) {
|
||||
pub unsafe extern "C" fn object_bytearray_get(
|
||||
ptr: *const Object,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, QByteArray),
|
||||
) {
|
||||
let data = (&*ptr).get_bytearray();
|
||||
set(p, QByteArray::from(&data));
|
||||
}
|
||||
|
@ -241,9 +247,11 @@ pub unsafe extern "C" fn object_integer_set(ptr: *mut Object, v: i32) {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn object_optional_bytearray_get(ptr: *const Object,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, QByteArray)) {
|
||||
pub unsafe extern "C" fn object_optional_bytearray_get(
|
||||
ptr: *const Object,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, QByteArray),
|
||||
) {
|
||||
let data = (&*ptr).get_optional_bytearray();
|
||||
if let Some(data) = data {
|
||||
set(p, QByteArray::from(&data));
|
||||
|
@ -260,9 +268,11 @@ pub unsafe extern "C" fn object_optional_bytearray_set_none(ptr: *mut Object) {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn object_optional_string_get(ptr: *const Object,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, QString)) {
|
||||
pub unsafe extern "C" fn object_optional_string_get(
|
||||
ptr: *const Object,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, QString),
|
||||
) {
|
||||
let data = (&*ptr).get_optional_string();
|
||||
if let Some(data) = data {
|
||||
set(p, QString::from(&data));
|
||||
|
@ -279,9 +289,11 @@ pub unsafe extern "C" fn object_optional_string_set_none(ptr: *mut Object) {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn object_string_get(ptr: *const Object,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, QString)) {
|
||||
pub unsafe extern "C" fn object_string_get(
|
||||
ptr: *const Object,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, QString),
|
||||
) {
|
||||
let data = (&*ptr).get_string();
|
||||
set(p, QString::from(&data));
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ impl InnerObjectTrait for InnerObject {
|
|||
self.description = value;
|
||||
self.emit.description_changed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Person {
|
||||
emit: PersonEmitter,
|
||||
|
|
|
@ -40,7 +40,7 @@ impl<'a> From<&'a String> for QString {
|
|||
|
||||
pub struct GroupQObject {}
|
||||
|
||||
#[derive (Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct GroupEmitter {
|
||||
qobject: Arc<Mutex<*const GroupQObject>>,
|
||||
}
|
||||
|
@ -62,9 +62,12 @@ pub trait GroupTrait {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn group_new(group: *mut GroupQObject, person: *mut PersonQObject, object: *mut InnerObjectQObject,
|
||||
description_changed: fn(*const InnerObjectQObject))
|
||||
-> *mut Group {
|
||||
pub extern "C" fn group_new(
|
||||
group: *mut GroupQObject,
|
||||
person: *mut PersonQObject,
|
||||
object: *mut InnerObjectQObject,
|
||||
description_changed: fn(*const InnerObjectQObject),
|
||||
) -> *mut Group {
|
||||
let object_emit = InnerObjectEmitter {
|
||||
qobject: Arc::new(Mutex::new(object)),
|
||||
description_changed: description_changed,
|
||||
|
@ -95,7 +98,7 @@ pub unsafe extern "C" fn group_person_get(ptr: *mut Group) -> *mut Person {
|
|||
|
||||
pub struct InnerObjectQObject {}
|
||||
|
||||
#[derive (Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct InnerObjectEmitter {
|
||||
qobject: Arc<Mutex<*const InnerObjectQObject>>,
|
||||
description_changed: fn(*const InnerObjectQObject),
|
||||
|
@ -123,9 +126,10 @@ pub trait InnerObjectTrait {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn inner_object_new(inner_object: *mut InnerObjectQObject,
|
||||
description_changed: fn(*const InnerObjectQObject))
|
||||
-> *mut InnerObject {
|
||||
pub extern "C" fn inner_object_new(
|
||||
inner_object: *mut InnerObjectQObject,
|
||||
description_changed: fn(*const InnerObjectQObject),
|
||||
) -> *mut InnerObject {
|
||||
let inner_object_emit = InnerObjectEmitter {
|
||||
qobject: Arc::new(Mutex::new(inner_object)),
|
||||
description_changed: description_changed,
|
||||
|
@ -140,9 +144,11 @@ pub unsafe extern "C" fn inner_object_free(ptr: *mut InnerObject) {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn inner_object_description_get(ptr: *const InnerObject,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, QString)) {
|
||||
pub unsafe extern "C" fn inner_object_description_get(
|
||||
ptr: *const InnerObject,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, QString),
|
||||
) {
|
||||
let data = (&*ptr).get_description();
|
||||
set(p, QString::from(&data));
|
||||
}
|
||||
|
@ -154,7 +160,7 @@ pub unsafe extern "C" fn inner_object_description_set(ptr: *mut InnerObject, v:
|
|||
|
||||
pub struct PersonQObject {}
|
||||
|
||||
#[derive (Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct PersonEmitter {
|
||||
qobject: Arc<Mutex<*const PersonQObject>>,
|
||||
}
|
||||
|
@ -176,9 +182,11 @@ pub trait PersonTrait {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn person_new(person: *mut PersonQObject, object: *mut InnerObjectQObject,
|
||||
description_changed: fn(*const InnerObjectQObject))
|
||||
-> *mut Person {
|
||||
pub extern "C" fn person_new(
|
||||
person: *mut PersonQObject,
|
||||
object: *mut InnerObjectQObject,
|
||||
description_changed: fn(*const InnerObjectQObject),
|
||||
) -> *mut Person {
|
||||
let object_emit = InnerObjectEmitter {
|
||||
qobject: Arc::new(Mutex::new(object)),
|
||||
description_changed: description_changed,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#![allow(dead_code)]
|
||||
use interface::*;
|
||||
|
||||
#[derive (Default, Clone)]
|
||||
#[derive(Default, Clone)]
|
||||
struct PersonsItem {
|
||||
user_name: String,
|
||||
}
|
||||
|
|
|
@ -16,17 +16,20 @@ pub struct COption<T> {
|
|||
some: bool,
|
||||
}
|
||||
|
||||
impl<T> From<Option<T>> for COption<T> where T: Default {
|
||||
fn from(t: Option<T>) -> COption <T> {
|
||||
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
|
||||
some: true,
|
||||
}
|
||||
} else {
|
||||
COption {
|
||||
data: T::default(),
|
||||
some: false
|
||||
some: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +68,7 @@ impl<'a> From<&'a String> for QString {
|
|||
#[repr(C)]
|
||||
pub enum SortOrder {
|
||||
Ascending = 0,
|
||||
Descending = 1
|
||||
Descending = 1,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
|
@ -76,7 +79,7 @@ pub struct QModelIndex {
|
|||
|
||||
pub struct PersonsQObject {}
|
||||
|
||||
#[derive (Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct PersonsEmitter {
|
||||
qobject: Arc<Mutex<*const PersonsQObject>>,
|
||||
new_data_ready: fn(*const PersonsQObject, item: usize, valid: bool),
|
||||
|
@ -91,7 +94,7 @@ impl PersonsEmitter {
|
|||
pub fn new_data_ready(&self, item: Option<usize>) {
|
||||
let ptr = *self.qobject.lock().unwrap();
|
||||
if !ptr.is_null() {
|
||||
(self.new_data_ready)(ptr, item.unwrap_or(13), item.is_some());
|
||||
(self.new_data_ready)(ptr, item.unwrap_or(13), item.is_some());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +138,9 @@ pub trait PersonsTrait {
|
|||
fn create(emit: PersonsEmitter, model: PersonsUniformTree) -> Self;
|
||||
fn emit(&self) -> &PersonsEmitter;
|
||||
fn row_count(&self, Option<usize>) -> usize;
|
||||
fn can_fetch_more(&self, Option<usize>) -> bool { false }
|
||||
fn can_fetch_more(&self, Option<usize>) -> bool {
|
||||
false
|
||||
}
|
||||
fn fetch_more(&mut self, Option<usize>) {}
|
||||
fn sort(&mut self, u8, SortOrder) {}
|
||||
fn index(&self, item: Option<usize>, row: usize) -> usize;
|
||||
|
@ -146,20 +151,17 @@ pub trait PersonsTrait {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn persons_new(persons: *mut PersonsQObject,
|
||||
new_data_ready: fn(*const PersonsQObject, item: usize, valid: bool),
|
||||
data_changed: fn(*const PersonsQObject, usize, usize),
|
||||
begin_reset_model: fn(*const PersonsQObject),
|
||||
end_reset_model: fn(*const PersonsQObject),
|
||||
begin_insert_rows: fn(*const PersonsQObject, item: usize, valid: bool,
|
||||
usize,
|
||||
usize),
|
||||
end_insert_rows: fn(*const PersonsQObject),
|
||||
begin_remove_rows: fn(*const PersonsQObject, item: usize, valid: bool,
|
||||
usize,
|
||||
usize),
|
||||
end_remove_rows: fn(*const PersonsQObject))
|
||||
-> *mut Persons {
|
||||
pub extern "C" fn persons_new(
|
||||
persons: *mut PersonsQObject,
|
||||
new_data_ready: fn(*const PersonsQObject, item: usize, valid: bool),
|
||||
data_changed: fn(*const PersonsQObject, usize, usize),
|
||||
begin_reset_model: fn(*const PersonsQObject),
|
||||
end_reset_model: fn(*const PersonsQObject),
|
||||
begin_insert_rows: fn(*const PersonsQObject, item: usize, valid: bool, usize, usize),
|
||||
end_insert_rows: fn(*const PersonsQObject),
|
||||
begin_remove_rows: fn(*const PersonsQObject, item: usize, valid: bool, usize, usize),
|
||||
end_remove_rows: fn(*const PersonsQObject),
|
||||
) -> *mut Persons {
|
||||
let persons_emit = PersonsEmitter {
|
||||
qobject: Arc::new(Mutex::new(persons)),
|
||||
new_data_ready: new_data_ready,
|
||||
|
@ -184,7 +186,11 @@ pub unsafe extern "C" fn persons_free(ptr: *mut Persons) {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn persons_row_count(ptr: *const Persons, item: usize, valid: bool) -> c_int {
|
||||
pub unsafe extern "C" fn persons_row_count(
|
||||
ptr: *const Persons,
|
||||
item: usize,
|
||||
valid: bool,
|
||||
) -> c_int {
|
||||
if valid {
|
||||
(&*ptr).row_count(Some(item)) as c_int
|
||||
} else {
|
||||
|
@ -192,7 +198,11 @@ pub unsafe extern "C" fn persons_row_count(ptr: *const Persons, item: usize, val
|
|||
}
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn persons_can_fetch_more(ptr: *const Persons, item: usize, valid: bool) -> bool {
|
||||
pub unsafe extern "C" fn persons_can_fetch_more(
|
||||
ptr: *const Persons,
|
||||
item: usize,
|
||||
valid: bool,
|
||||
) -> bool {
|
||||
if valid {
|
||||
(&*ptr).can_fetch_more(Some(item))
|
||||
} else {
|
||||
|
@ -208,11 +218,20 @@ pub unsafe extern "C" fn persons_fetch_more(ptr: *mut Persons, item: usize, vali
|
|||
}
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn persons_sort(ptr: *mut Persons, column: u8, order: SortOrder) {
|
||||
pub unsafe extern "C" fn persons_sort(
|
||||
ptr: *mut Persons,
|
||||
column: u8,
|
||||
order: SortOrder
|
||||
) {
|
||||
(&mut *ptr).sort(column, order)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn persons_index(ptr: *const Persons, item: usize, valid: bool, row: c_int) -> usize {
|
||||
pub unsafe extern "C" fn persons_index(
|
||||
ptr: *const Persons,
|
||||
item: usize,
|
||||
valid: bool,
|
||||
row: c_int,
|
||||
) -> usize {
|
||||
if !valid {
|
||||
(&*ptr).index(None, row as usize)
|
||||
} else {
|
||||
|
@ -222,9 +241,15 @@ pub unsafe extern "C" fn persons_index(ptr: *const Persons, item: usize, valid:
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn persons_parent(ptr: *const Persons, index: usize) -> QModelIndex {
|
||||
if let Some(parent) = (&*ptr).parent(index) {
|
||||
QModelIndex{row: (&*ptr).row(parent) as c_int, internal_id: parent}
|
||||
QModelIndex {
|
||||
row: (&*ptr).row(parent) as c_int,
|
||||
internal_id: parent,
|
||||
}
|
||||
} else {
|
||||
QModelIndex{row: -1, internal_id: 0}
|
||||
QModelIndex {
|
||||
row: -1,
|
||||
internal_id: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
#[no_mangle]
|
||||
|
@ -233,14 +258,19 @@ pub unsafe extern "C" fn persons_row(ptr: *const Persons, item: usize) -> c_int
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn persons_data_user_name(ptr: *const Persons, item: usize,
|
||||
d: *mut c_void,
|
||||
set: fn(*mut c_void, QString)) {
|
||||
pub unsafe extern "C" fn persons_data_user_name(
|
||||
ptr: *const Persons, item: usize,
|
||||
d: *mut c_void,
|
||||
set: fn(*mut c_void, QString),
|
||||
) {
|
||||
let data = (&*ptr).user_name(item);
|
||||
set(d, QString::from(&data));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn persons_set_data_user_name(ptr: *mut Persons, item: usize, v: QStringIn) -> bool {
|
||||
pub unsafe extern "C" fn persons_set_data_user_name(
|
||||
ptr: *mut Persons, item: usize,
|
||||
v: QStringIn,
|
||||
) -> bool {
|
||||
(&mut *ptr).set_user_name(item, v.convert())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue