Add u64 as bindings type
parent
e69b8396bd
commit
106c7ae468
|
@ -7,23 +7,15 @@
|
|||
"typesModule": "types"
|
||||
},
|
||||
"objects": [{
|
||||
"name": "Person",
|
||||
"name": "Fibonacci",
|
||||
"type": "Object",
|
||||
"properties": [{
|
||||
"name": "userName",
|
||||
"type": "QString",
|
||||
"name": "input",
|
||||
"type": "uint",
|
||||
"write": true
|
||||
}, {
|
||||
"name": "age",
|
||||
"type": "int"
|
||||
}, {
|
||||
"name": "active",
|
||||
"type": "bool",
|
||||
"write": true
|
||||
}, {
|
||||
"name": "icon",
|
||||
"type": "QByteArray",
|
||||
"write": true
|
||||
"name": "result",
|
||||
"type": "uint64_t"
|
||||
}]
|
||||
}, {
|
||||
"name": "Directory",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use interface::*;
|
||||
use types::*;
|
||||
use std::fs::*;
|
||||
use libc::{c_int, c_ulonglong};
|
||||
use libc::{c_int};
|
||||
use std::fs::read_dir;
|
||||
use std::path::PathBuf;
|
||||
use std::ffi::OsString;
|
||||
|
@ -246,7 +246,7 @@ impl<T: Item> TreeTrait for RGeneralItemModel<T> {
|
|||
.map(|entry| entry.data.file_type())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
fn file_size(&self, row: c_int, parent: usize) -> c_ulonglong {
|
||||
fn file_size(&self, row: c_int, parent: usize) -> u64 {
|
||||
self.get(row, parent)
|
||||
.map(|entry| entry.data.file_size())
|
||||
.unwrap_or_default()
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#![allow(unknown_lints)]
|
||||
#![allow(mutex_atomic, needless_pass_by_value)]
|
||||
#![allow(unused_imports)]
|
||||
use libc::{c_int, c_uint, c_ulonglong, c_void};
|
||||
use libc::{c_int, c_uint, c_void};
|
||||
use types::*;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::ptr::null;
|
||||
|
@ -83,7 +83,7 @@ pub trait TreeTrait {
|
|||
fn file_path(&self, row: c_int, parent: usize) -> String;
|
||||
fn file_permissions(&self, row: c_int, parent: usize) -> c_int;
|
||||
fn file_type(&self, row: c_int, parent: usize) -> c_int;
|
||||
fn file_size(&self, row: c_int, parent: usize) -> c_ulonglong;
|
||||
fn file_size(&self, row: c_int, parent: usize) -> u64;
|
||||
fn index(&self, row: c_int, parent: usize) -> usize;
|
||||
fn parent(&self, parent: usize) -> QModelIndex;
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ pub unsafe extern "C" fn tree_data_file_type(ptr: *const Tree, row: c_int, paren
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tree_data_file_size(ptr: *const Tree, row: c_int, parent: usize) -> c_ulonglong {
|
||||
pub unsafe extern "C" fn tree_data_file_size(ptr: *const Tree, row: c_int, parent: usize) -> u64 {
|
||||
(&*ptr).file_size(row, parent)
|
||||
}
|
||||
|
||||
|
|
|
@ -6,50 +6,32 @@ use libc::c_uint;
|
|||
use types::*;
|
||||
use testinterface::*;
|
||||
|
||||
pub struct Person {
|
||||
emit: PersonEmitter,
|
||||
user_name: String,
|
||||
age: c_int,
|
||||
active: bool,
|
||||
icon: Vec<u8>,
|
||||
pub struct Fibonacci {
|
||||
emit: FibonacciEmitter,
|
||||
input: c_uint,
|
||||
result: u64,
|
||||
}
|
||||
|
||||
impl PersonTrait for Person {
|
||||
fn create(emit: PersonEmitter) -> Person {
|
||||
Person {
|
||||
impl FibonacciTrait for Fibonacci {
|
||||
fn create(emit: FibonacciEmitter) -> Fibonacci {
|
||||
Fibonacci {
|
||||
emit: emit,
|
||||
user_name: String::new(),
|
||||
age: 0,
|
||||
active: true,
|
||||
icon: Vec::new(),
|
||||
input: 0,
|
||||
result: 0,
|
||||
}
|
||||
}
|
||||
fn emit(&self) -> &PersonEmitter {
|
||||
fn emit(&self) -> &FibonacciEmitter {
|
||||
&self.emit
|
||||
}
|
||||
fn get_user_name(&self) -> String {
|
||||
self.user_name.clone()
|
||||
fn get_input(&self) -> c_uint {
|
||||
self.input
|
||||
}
|
||||
fn set_user_name(&mut self, value: String) {
|
||||
self.user_name = value;
|
||||
self.emit.user_name_changed();
|
||||
fn set_input(&mut self, value: c_uint) {
|
||||
self.input = value;
|
||||
self.emit.input_changed();
|
||||
}
|
||||
fn get_age(&self) -> c_int {
|
||||
self.age
|
||||
}
|
||||
fn get_active(&self) -> bool {
|
||||
self.active
|
||||
}
|
||||
fn set_active(&mut self, value: bool) {
|
||||
self.active = value;
|
||||
self.emit.active_changed();
|
||||
}
|
||||
fn get_icon(&self) -> Vec<u8> {
|
||||
self.icon.clone()
|
||||
}
|
||||
fn set_icon(&mut self, value: Vec<u8>) {
|
||||
self.icon = value;
|
||||
self.emit.icon_changed();
|
||||
fn get_result(&self) -> u64 {
|
||||
self.result
|
||||
}
|
||||
}
|
||||
pub struct Directory {
|
||||
|
|
|
@ -2,130 +2,82 @@
|
|||
#![allow(unknown_lints)]
|
||||
#![allow(mutex_atomic, needless_pass_by_value)]
|
||||
#![allow(unused_imports)]
|
||||
use libc::{c_int, c_uint, c_ulonglong, c_void};
|
||||
use libc::{c_int, c_uint, c_void};
|
||||
use types::*;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::ptr::null;
|
||||
|
||||
use testimplementation::*;
|
||||
|
||||
pub struct PersonQObject {}
|
||||
pub struct FibonacciQObject {}
|
||||
|
||||
#[derive (Clone)]
|
||||
pub struct PersonEmitter {
|
||||
qobject: Arc<Mutex<*const PersonQObject>>,
|
||||
user_name_changed: fn(*const PersonQObject),
|
||||
age_changed: fn(*const PersonQObject),
|
||||
active_changed: fn(*const PersonQObject),
|
||||
icon_changed: fn(*const PersonQObject),
|
||||
pub struct FibonacciEmitter {
|
||||
qobject: Arc<Mutex<*const FibonacciQObject>>,
|
||||
input_changed: fn(*const FibonacciQObject),
|
||||
result_changed: fn(*const FibonacciQObject),
|
||||
}
|
||||
|
||||
unsafe impl Send for PersonEmitter {}
|
||||
unsafe impl Send for FibonacciEmitter {}
|
||||
|
||||
impl PersonEmitter {
|
||||
impl FibonacciEmitter {
|
||||
fn clear(&self) {
|
||||
*self.qobject.lock().unwrap() = null();
|
||||
}
|
||||
pub fn user_name_changed(&self) {
|
||||
pub fn input_changed(&self) {
|
||||
let ptr = *self.qobject.lock().unwrap();
|
||||
if !ptr.is_null() {
|
||||
(self.user_name_changed)(ptr);
|
||||
(self.input_changed)(ptr);
|
||||
}
|
||||
}
|
||||
pub fn age_changed(&self) {
|
||||
pub fn result_changed(&self) {
|
||||
let ptr = *self.qobject.lock().unwrap();
|
||||
if !ptr.is_null() {
|
||||
(self.age_changed)(ptr);
|
||||
}
|
||||
}
|
||||
pub fn active_changed(&self) {
|
||||
let ptr = *self.qobject.lock().unwrap();
|
||||
if !ptr.is_null() {
|
||||
(self.active_changed)(ptr);
|
||||
}
|
||||
}
|
||||
pub fn icon_changed(&self) {
|
||||
let ptr = *self.qobject.lock().unwrap();
|
||||
if !ptr.is_null() {
|
||||
(self.icon_changed)(ptr);
|
||||
(self.result_changed)(ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait PersonTrait {
|
||||
fn create(emit: PersonEmitter) -> Self;
|
||||
fn emit(&self) -> &PersonEmitter;
|
||||
fn get_user_name(&self) -> String;
|
||||
fn set_user_name(&mut self, value: String);
|
||||
fn get_age(&self) -> c_int;
|
||||
fn get_active(&self) -> bool;
|
||||
fn set_active(&mut self, value: bool);
|
||||
fn get_icon(&self) -> Vec<u8>;
|
||||
fn set_icon(&mut self, value: Vec<u8>);
|
||||
pub trait FibonacciTrait {
|
||||
fn create(emit: FibonacciEmitter) -> Self;
|
||||
fn emit(&self) -> &FibonacciEmitter;
|
||||
fn get_input(&self) -> c_uint;
|
||||
fn set_input(&mut self, value: c_uint);
|
||||
fn get_result(&self) -> u64;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn person_new(qobject: *const PersonQObject,
|
||||
user_name_changed: fn(*const PersonQObject),
|
||||
age_changed: fn(*const PersonQObject),
|
||||
active_changed: fn(*const PersonQObject),
|
||||
icon_changed: fn(*const PersonQObject))
|
||||
-> *mut Person {
|
||||
let emit = PersonEmitter {
|
||||
pub extern "C" fn fibonacci_new(qobject: *const FibonacciQObject,
|
||||
input_changed: fn(*const FibonacciQObject),
|
||||
result_changed: fn(*const FibonacciQObject))
|
||||
-> *mut Fibonacci {
|
||||
let emit = FibonacciEmitter {
|
||||
qobject: Arc::new(Mutex::new(qobject)),
|
||||
user_name_changed: user_name_changed,
|
||||
age_changed: age_changed,
|
||||
active_changed: active_changed,
|
||||
icon_changed: icon_changed,
|
||||
input_changed: input_changed,
|
||||
result_changed: result_changed,
|
||||
};
|
||||
let d = Person::create(emit);
|
||||
let d = Fibonacci::create(emit);
|
||||
Box::into_raw(Box::new(d))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn person_free(ptr: *mut Person) {
|
||||
pub unsafe extern "C" fn fibonacci_free(ptr: *mut Fibonacci) {
|
||||
Box::from_raw(ptr).emit().clear();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
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));
|
||||
pub unsafe extern "C" fn fibonacci_input_get(ptr: *const Fibonacci) -> c_uint {
|
||||
(&*ptr).get_input()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn person_user_name_set(ptr: *mut Person, v: QStringIn) {
|
||||
(&mut *ptr).set_user_name(v.convert());
|
||||
pub unsafe extern "C" fn fibonacci_input_set(ptr: *mut Fibonacci, v: c_uint) {
|
||||
(&mut *ptr).set_input(v);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn person_age_get(ptr: *const Person) -> c_int {
|
||||
(&*ptr).get_age()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn person_active_get(ptr: *const Person) -> bool {
|
||||
(&*ptr).get_active()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn person_active_set(ptr: *mut Person, v: bool) {
|
||||
(&mut *ptr).set_active(v);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn person_icon_get(ptr: *const Person,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, QByteArray)) {
|
||||
let data = (&*ptr).get_icon();
|
||||
set(p, QByteArray::from(&data));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn person_icon_set(ptr: *mut Person, v: QByteArray) {
|
||||
(&mut *ptr).set_icon(v.convert());
|
||||
pub unsafe extern "C" fn fibonacci_result_get(ptr: *const Fibonacci) -> u64 {
|
||||
(&*ptr).get_result()
|
||||
}
|
||||
|
||||
pub struct DirectoryQObject {}
|
||||
|
|
|
@ -43,15 +43,11 @@ void set_qbytearray(QByteArray* v, qbytearray_t* val) {
|
|||
}
|
||||
|
||||
extern "C" {
|
||||
Person::Private* person_new(Person*, void (*)(Person*), void (*)(Person*), void (*)(Person*), void (*)(Person*));
|
||||
void person_free(Person::Private*);
|
||||
void person_user_name_get(const Person::Private*, QString*, qstring_set);
|
||||
void person_user_name_set(Person::Private*, qstring_t);
|
||||
int person_age_get(const Person::Private*);
|
||||
bool person_active_get(const Person::Private*);
|
||||
void person_active_set(Person::Private*, bool);
|
||||
void person_icon_get(const Person::Private*, QByteArray*, qbytearray_set);
|
||||
void person_icon_set(Person::Private*, qbytearray_t);
|
||||
Fibonacci::Private* fibonacci_new(Fibonacci*, void (*)(Fibonacci*), void (*)(Fibonacci*));
|
||||
void fibonacci_free(Fibonacci::Private*);
|
||||
uint fibonacci_input_get(const Fibonacci::Private*);
|
||||
void fibonacci_input_set(Fibonacci::Private*, uint);
|
||||
uint64_t fibonacci_result_get(const Fibonacci::Private*);
|
||||
Directory::Private* directory_new(Directory*, void (*)(Directory*),
|
||||
void (*)(const Directory*),
|
||||
void (*)(Directory*),
|
||||
|
@ -75,45 +71,25 @@ extern "C" {
|
|||
void test_tree_path_get(const TestTree::Private*, QString*, qstring_set);
|
||||
void test_tree_path_set(TestTree::Private*, qstring_t);
|
||||
};
|
||||
Person::Person(QObject *parent):
|
||||
Fibonacci::Fibonacci(QObject *parent):
|
||||
QObject(parent),
|
||||
d(person_new(this,
|
||||
[](Person* o) { emit o->userNameChanged(); },
|
||||
[](Person* o) { emit o->ageChanged(); },
|
||||
[](Person* o) { emit o->activeChanged(); },
|
||||
[](Person* o) { emit o->iconChanged(); })) {}
|
||||
d(fibonacci_new(this,
|
||||
[](Fibonacci* o) { emit o->inputChanged(); },
|
||||
[](Fibonacci* o) { emit o->resultChanged(); })) {}
|
||||
|
||||
Person::~Person() {
|
||||
person_free(d);
|
||||
Fibonacci::~Fibonacci() {
|
||||
fibonacci_free(d);
|
||||
}
|
||||
QString Person::userName() const
|
||||
uint Fibonacci::input() const
|
||||
{
|
||||
QString v;
|
||||
person_user_name_get(d, &v, set_qstring);
|
||||
return v;
|
||||
return fibonacci_input_get(d);
|
||||
}
|
||||
void Person::setUserName(const QString& v) {
|
||||
person_user_name_set(d, v);
|
||||
void Fibonacci::setInput(uint v) {
|
||||
fibonacci_input_set(d, v);
|
||||
}
|
||||
int Person::age() const
|
||||
uint64_t Fibonacci::result() const
|
||||
{
|
||||
return person_age_get(d);
|
||||
}
|
||||
bool Person::active() const
|
||||
{
|
||||
return person_active_get(d);
|
||||
}
|
||||
void Person::setActive(bool v) {
|
||||
person_active_set(d, v);
|
||||
}
|
||||
QByteArray Person::icon() const
|
||||
{
|
||||
QByteArray v;
|
||||
person_icon_get(d, &v, set_qbytearray);
|
||||
return v;
|
||||
}
|
||||
void Person::setIcon(const QByteArray& v) {
|
||||
person_icon_set(d, v);
|
||||
return fibonacci_result_get(d);
|
||||
}
|
||||
Directory::Directory(QObject *parent):
|
||||
QAbstractItemModel(parent),
|
||||
|
|
|
@ -5,37 +5,27 @@
|
|||
#include <QObject>
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
class Person : public QObject
|
||||
class Fibonacci : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
class Private;
|
||||
private:
|
||||
Private * const d;
|
||||
Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged FINAL)
|
||||
Q_PROPERTY(int age READ age NOTIFY ageChanged FINAL)
|
||||
Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged FINAL)
|
||||
Q_PROPERTY(QByteArray icon READ icon WRITE setIcon NOTIFY iconChanged FINAL)
|
||||
Q_PROPERTY(uint input READ input WRITE setInput NOTIFY inputChanged FINAL)
|
||||
Q_PROPERTY(uint64_t result READ result NOTIFY resultChanged FINAL)
|
||||
public:
|
||||
explicit Person(QObject *parent = nullptr);
|
||||
~Person();
|
||||
QString userName() const;
|
||||
void setUserName(const QString& v);
|
||||
int age() const;
|
||||
bool active() const;
|
||||
void setActive(bool v);
|
||||
QByteArray icon() const;
|
||||
void setIcon(const QByteArray& v);
|
||||
explicit Fibonacci(QObject *parent = nullptr);
|
||||
~Fibonacci();
|
||||
uint input() const;
|
||||
void setInput(uint v);
|
||||
uint64_t result() const;
|
||||
signals:
|
||||
void userNameChanged();
|
||||
void ageChanged();
|
||||
void activeChanged();
|
||||
void iconChanged();
|
||||
void inputChanged();
|
||||
void resultChanged();
|
||||
private:
|
||||
QString m_userName;
|
||||
int m_age;
|
||||
bool m_active;
|
||||
QByteArray m_icon;
|
||||
uint m_input;
|
||||
uint64_t m_result;
|
||||
};
|
||||
|
||||
class Directory : public QAbstractItemModel
|
||||
|
|
|
@ -105,7 +105,7 @@ extern "C" {
|
|||
void tree_data_file_path(const Tree::Private*, int, quintptr, QString*, qstring_set);
|
||||
int tree_data_file_permissions(const Tree::Private*, int, quintptr);
|
||||
int tree_data_file_type(const Tree::Private*, int, quintptr);
|
||||
qulonglong tree_data_file_size(const Tree::Private*, int, quintptr);
|
||||
uint64_t tree_data_file_size(const Tree::Private*, int, quintptr);
|
||||
void tree_sort(Tree::Private*, int column, Qt::SortOrder order = Qt::AscendingOrder);
|
||||
|
||||
int tree_row_count(const Tree::Private*, int, quintptr);
|
||||
|
@ -201,7 +201,7 @@ QVariant Tree::data(const QModelIndex &index, int role) const
|
|||
v.setValue<int>(tree_data_file_type(d, index.row(), index.internalId()));
|
||||
break;
|
||||
case Qt::UserRole + 5:
|
||||
v.setValue<qulonglong>(tree_data_file_size(d, index.row(), index.internalId()));
|
||||
v.setValue<uint64_t>(tree_data_file_size(d, index.row(), index.internalId()));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -230,7 +230,7 @@ QVariant Tree::data(const QModelIndex &index, int role) const
|
|||
case 4:
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
v.setValue<qulonglong>(tree_data_file_size(d, index.row(), index.internalId()));
|
||||
v.setValue<uint64_t>(tree_data_file_size(d, index.row(), index.internalId()));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -52,7 +52,7 @@ int main (int argc, char *argv[])
|
|||
aboutData.processCommandLine(&parser);
|
||||
|
||||
qmlRegisterType<Directory>("rust", 1, 0, "Directory");
|
||||
qmlRegisterType<Person>("rust", 1, 0, "Person");
|
||||
qmlRegisterType<Fibonacci>("rust", 1, 0, "Fibonacci");
|
||||
|
||||
Tree model;
|
||||
model.setPath("/");
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
}, {
|
||||
"name": "fileSize",
|
||||
"value": "Qt::UserRole + 5",
|
||||
"type": "ulonglong"
|
||||
"type": "uint64_t"
|
||||
}],
|
||||
[{
|
||||
"name": "filePath",
|
||||
|
@ -62,7 +62,7 @@
|
|||
[{
|
||||
"name": "fileSize",
|
||||
"value": "Qt::DisplayRole",
|
||||
"type": "ulonglong"
|
||||
"type": "uint64_t"
|
||||
}]
|
||||
]
|
||||
}]
|
||||
|
|
2
dev
2
dev
|
@ -1,3 +1,3 @@
|
|||
#!/usr/bin/bash
|
||||
rm -rf __nix_qt5__/
|
||||
nix-shell -p qtcreator cmake ninja gcc rustc cargo qt5.full extra-cmake-modules kdeFrameworks.kwidgetsaddons kdeFrameworks.kcoreaddons kdeFrameworks.ki18n appstream cmakeCurses
|
||||
nix-shell -p qtcreator cmake ninja gcc rustc cargo qt5.full extra-cmake-modules kdeFrameworks.kwidgetsaddons kdeFrameworks.kcoreaddons kdeFrameworks.ki18n appstream cmakeCurses kdeFrameworks.ktexteditor
|
||||
|
|
|
@ -67,10 +67,10 @@ const QMap<BindingType, BindingTypeProperties>& bindingTypeProperties() {
|
|||
.rustTypeInit = "0"
|
||||
});
|
||||
f.insert(BindingType::ULongLong, {
|
||||
.name = "ulonglong",
|
||||
.cppSetType = "qulonglong",
|
||||
.cSetType = "qulonglong",
|
||||
.rustType = "c_ulonglong",
|
||||
.name = "uint64_t",
|
||||
.cppSetType = "uint64_t",
|
||||
.cSetType = "uint64_t",
|
||||
.rustType = "u64",
|
||||
.rustTypeInit = "0"
|
||||
});
|
||||
f.insert(BindingType::QString, {
|
||||
|
@ -132,7 +132,10 @@ BindingTypeProperties parseBindingType(const QString& value) {
|
|||
}
|
||||
}
|
||||
err << QCoreApplication::translate("main",
|
||||
"'%1' is not a supported type.\n").arg(value);
|
||||
"'%1' is not a supported type. Try one of\n").arg(value);
|
||||
for (auto i: bindingTypeProperties()) {
|
||||
err << " " << i.name << "\n";
|
||||
}
|
||||
err.flush();
|
||||
exit(1);
|
||||
}
|
||||
|
@ -1089,7 +1092,7 @@ void writeRustInterface(const Configuration& conf) {
|
|||
#![allow(unknown_lints)]
|
||||
#![allow(mutex_atomic, needless_pass_by_value)]
|
||||
#![allow(unused_imports)]
|
||||
use libc::{c_int, c_uint, c_ulonglong, c_void};
|
||||
use libc::{c_int, c_uint, c_void};
|
||||
use types::*;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::ptr::null;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#![allow(unknown_lints)]
|
||||
#![allow(mutex_atomic, needless_pass_by_value)]
|
||||
#![allow(unused_imports)]
|
||||
use libc::{c_int, c_uint, c_ulonglong, c_void};
|
||||
use libc::{c_int, c_uint, c_void};
|
||||
use types::*;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::ptr::null;
|
||||
|
|
|
@ -74,3 +74,9 @@ impl QModelIndex {
|
|||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub enum SortOrder {
|
||||
Ascending = 0,
|
||||
Descending = 1
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ pub struct Object {
|
|||
boolean: bool,
|
||||
integer: c_int,
|
||||
uinteger: c_uint,
|
||||
u64: u64,
|
||||
string: String,
|
||||
bytearray: Vec<u8>,
|
||||
}
|
||||
|
@ -22,6 +23,7 @@ impl ObjectTrait for Object {
|
|||
boolean: true,
|
||||
integer: 0,
|
||||
uinteger: 0,
|
||||
u64: 0,
|
||||
string: String::new(),
|
||||
bytearray: Vec::new(),
|
||||
}
|
||||
|
@ -50,6 +52,13 @@ impl ObjectTrait for Object {
|
|||
self.uinteger = value;
|
||||
self.emit.uinteger_changed();
|
||||
}
|
||||
fn get_u64(&self) -> u64 {
|
||||
self.u64
|
||||
}
|
||||
fn set_u64(&mut self, value: u64) {
|
||||
self.u64 = value;
|
||||
self.emit.u64_changed();
|
||||
}
|
||||
fn get_string(&self) -> String {
|
||||
self.string.clone()
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#![allow(unknown_lints)]
|
||||
#![allow(mutex_atomic, needless_pass_by_value)]
|
||||
#![allow(unused_imports)]
|
||||
use libc::{c_int, c_uint, c_ulonglong, c_void};
|
||||
use libc::{c_int, c_uint, c_void};
|
||||
use types::*;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::ptr::null;
|
||||
|
@ -17,6 +17,7 @@ pub struct ObjectEmitter {
|
|||
boolean_changed: fn(*const ObjectQObject),
|
||||
integer_changed: fn(*const ObjectQObject),
|
||||
uinteger_changed: fn(*const ObjectQObject),
|
||||
u64_changed: fn(*const ObjectQObject),
|
||||
string_changed: fn(*const ObjectQObject),
|
||||
bytearray_changed: fn(*const ObjectQObject),
|
||||
}
|
||||
|
@ -45,6 +46,12 @@ impl ObjectEmitter {
|
|||
(self.uinteger_changed)(ptr);
|
||||
}
|
||||
}
|
||||
pub fn u64_changed(&self) {
|
||||
let ptr = *self.qobject.lock().unwrap();
|
||||
if !ptr.is_null() {
|
||||
(self.u64_changed)(ptr);
|
||||
}
|
||||
}
|
||||
pub fn string_changed(&self) {
|
||||
let ptr = *self.qobject.lock().unwrap();
|
||||
if !ptr.is_null() {
|
||||
|
@ -68,6 +75,8 @@ pub trait ObjectTrait {
|
|||
fn set_integer(&mut self, value: c_int);
|
||||
fn get_uinteger(&self) -> c_uint;
|
||||
fn set_uinteger(&mut self, value: c_uint);
|
||||
fn get_u64(&self) -> u64;
|
||||
fn set_u64(&mut self, value: u64);
|
||||
fn get_string(&self) -> String;
|
||||
fn set_string(&mut self, value: String);
|
||||
fn get_bytearray(&self) -> Vec<u8>;
|
||||
|
@ -79,6 +88,7 @@ pub extern "C" fn object_new(qobject: *const ObjectQObject,
|
|||
boolean_changed: fn(*const ObjectQObject),
|
||||
integer_changed: fn(*const ObjectQObject),
|
||||
uinteger_changed: fn(*const ObjectQObject),
|
||||
u64_changed: fn(*const ObjectQObject),
|
||||
string_changed: fn(*const ObjectQObject),
|
||||
bytearray_changed: fn(*const ObjectQObject))
|
||||
-> *mut Object {
|
||||
|
@ -87,6 +97,7 @@ pub extern "C" fn object_new(qobject: *const ObjectQObject,
|
|||
boolean_changed: boolean_changed,
|
||||
integer_changed: integer_changed,
|
||||
uinteger_changed: uinteger_changed,
|
||||
u64_changed: u64_changed,
|
||||
string_changed: string_changed,
|
||||
bytearray_changed: bytearray_changed,
|
||||
};
|
||||
|
@ -129,6 +140,16 @@ pub unsafe extern "C" fn object_uinteger_set(ptr: *mut Object, v: c_uint) {
|
|||
(&mut *ptr).set_uinteger(v);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn object_u64_get(ptr: *const Object) -> u64 {
|
||||
(&*ptr).get_u64()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn object_u64_set(ptr: *mut Object, v: u64) {
|
||||
(&mut *ptr).set_u64(v);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn object_string_get(ptr: *const Object,
|
||||
p: *mut c_void,
|
||||
|
|
|
@ -74,3 +74,9 @@ impl QModelIndex {
|
|||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub enum SortOrder {
|
||||
Ascending = 0,
|
||||
Descending = 1
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ private slots:
|
|||
void testBool();
|
||||
void testInteger();
|
||||
void testUinteger();
|
||||
void testUint64();
|
||||
void testString();
|
||||
void testByteArray();
|
||||
};
|
||||
|
@ -65,6 +66,18 @@ void TestRustObjectTypes::testUinteger()
|
|||
&Object::uinteger, &Object::uintegerChanged);
|
||||
}
|
||||
|
||||
void TestRustObjectTypes::testUint64()
|
||||
{
|
||||
testSetter(0, &Object::setU64,
|
||||
&Object::u64, &Object::u64Changed);
|
||||
testSetter(1, &Object::setU64,
|
||||
&Object::u64, &Object::u64Changed);
|
||||
testSetter(std::numeric_limits<uint>::min(), &Object::setU64,
|
||||
&Object::u64, &Object::u64Changed);
|
||||
testSetter(std::numeric_limits<uint>::max(), &Object::setU64,
|
||||
&Object::u64, &Object::u64Changed);
|
||||
}
|
||||
|
||||
void TestRustObjectTypes::testString()
|
||||
{
|
||||
testSetter(QString(), &Object::setString,
|
||||
|
|
|
@ -21,6 +21,10 @@
|
|||
"name": "uinteger",
|
||||
"type": "uint",
|
||||
"write": true
|
||||
}, {
|
||||
"name": "u64",
|
||||
"type": "uint64_t",
|
||||
"write": true
|
||||
}, {
|
||||
"name": "string",
|
||||
"type": "QString",
|
||||
|
|
|
@ -43,7 +43,7 @@ void set_qbytearray(QByteArray* v, qbytearray_t* val) {
|
|||
}
|
||||
|
||||
extern "C" {
|
||||
Object::Private* object_new(Object*, void (*)(Object*), void (*)(Object*), void (*)(Object*), void (*)(Object*), void (*)(Object*));
|
||||
Object::Private* object_new(Object*, void (*)(Object*), void (*)(Object*), void (*)(Object*), void (*)(Object*), void (*)(Object*), void (*)(Object*));
|
||||
void object_free(Object::Private*);
|
||||
bool object_boolean_get(const Object::Private*);
|
||||
void object_boolean_set(Object::Private*, bool);
|
||||
|
@ -51,6 +51,8 @@ extern "C" {
|
|||
void object_integer_set(Object::Private*, int);
|
||||
uint object_uinteger_get(const Object::Private*);
|
||||
void object_uinteger_set(Object::Private*, uint);
|
||||
uint64_t object_u64_get(const Object::Private*);
|
||||
void object_u64_set(Object::Private*, uint64_t);
|
||||
void object_string_get(const Object::Private*, QString*, qstring_set);
|
||||
void object_string_set(Object::Private*, qstring_t);
|
||||
void object_bytearray_get(const Object::Private*, QByteArray*, qbytearray_set);
|
||||
|
@ -62,6 +64,7 @@ Object::Object(QObject *parent):
|
|||
[](Object* o) { emit o->booleanChanged(); },
|
||||
[](Object* o) { emit o->integerChanged(); },
|
||||
[](Object* o) { emit o->uintegerChanged(); },
|
||||
[](Object* o) { emit o->u64Changed(); },
|
||||
[](Object* o) { emit o->stringChanged(); },
|
||||
[](Object* o) { emit o->bytearrayChanged(); })) {}
|
||||
|
||||
|
@ -89,6 +92,13 @@ uint Object::uinteger() const
|
|||
void Object::setUinteger(uint v) {
|
||||
object_uinteger_set(d, v);
|
||||
}
|
||||
uint64_t Object::u64() const
|
||||
{
|
||||
return object_u64_get(d);
|
||||
}
|
||||
void Object::setU64(uint64_t v) {
|
||||
object_u64_set(d, v);
|
||||
}
|
||||
QString Object::string() const
|
||||
{
|
||||
QString v;
|
||||
|
|
|
@ -15,6 +15,7 @@ private:
|
|||
Q_PROPERTY(bool boolean READ boolean WRITE setBoolean NOTIFY booleanChanged FINAL)
|
||||
Q_PROPERTY(int integer READ integer WRITE setInteger NOTIFY integerChanged FINAL)
|
||||
Q_PROPERTY(uint uinteger READ uinteger WRITE setUinteger NOTIFY uintegerChanged FINAL)
|
||||
Q_PROPERTY(uint64_t u64 READ u64 WRITE setU64 NOTIFY u64Changed FINAL)
|
||||
Q_PROPERTY(QString string READ string WRITE setString NOTIFY stringChanged FINAL)
|
||||
Q_PROPERTY(QByteArray bytearray READ bytearray WRITE setBytearray NOTIFY bytearrayChanged FINAL)
|
||||
public:
|
||||
|
@ -26,6 +27,8 @@ public:
|
|||
void setInteger(int v);
|
||||
uint uinteger() const;
|
||||
void setUinteger(uint v);
|
||||
uint64_t u64() const;
|
||||
void setU64(uint64_t v);
|
||||
QString string() const;
|
||||
void setString(const QString& v);
|
||||
QByteArray bytearray() const;
|
||||
|
@ -34,12 +37,14 @@ signals:
|
|||
void booleanChanged();
|
||||
void integerChanged();
|
||||
void uintegerChanged();
|
||||
void u64Changed();
|
||||
void stringChanged();
|
||||
void bytearrayChanged();
|
||||
private:
|
||||
bool m_boolean;
|
||||
int m_integer;
|
||||
uint m_uinteger;
|
||||
uint64_t m_u64;
|
||||
QString m_string;
|
||||
QByteArray m_bytearray;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue