rust-qt-binding-generator/tests/rust_object_types/src/interface.rs

310 lines
8.4 KiB
Rust
Raw Normal View History

2017-08-12 05:03:11 -07:00
/* generated by rust_qt_binding_generator */
#![allow(unknown_lints)]
#![allow(mutex_atomic, needless_pass_by_value)]
2018-05-01 16:23:06 -07:00
use libc::{c_char, c_ushort, c_int, c_void, uint8_t, uint16_t};
use std::slice;
2018-05-01 16:23:06 -07:00
use std::char::decode_utf16;
2017-08-12 05:03:11 -07:00
use std::sync::{Arc, Mutex};
use std::ptr::null;
use implementation::*;
#[repr(C)]
pub struct COption<T> {
data: T,
some: bool,
}
2017-08-29 11:37:51 -07:00
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,
2017-08-29 11:37:51 -07:00
some: true,
}
} else {
COption {
data: T::default(),
2017-08-29 11:37:51 -07:00
some: false,
}
}
}
}
2018-05-01 16:23:06 -07:00
pub enum QString {}
2018-05-01 16:23:06 -07:00
fn set_string_from_utf16(s: &mut String, str: *const c_ushort, len: c_int) {
let utf16 = unsafe { slice::from_raw_parts(str, len as usize) };
let characters = decode_utf16(utf16.iter().cloned())
.into_iter()
.map(|r| r.unwrap());
s.clear();
s.extend(characters);
}
2018-05-01 16:23:06 -07:00
pub enum QByteArray {}
2017-08-12 05:03:11 -07:00
pub struct ObjectQObject {}
2017-08-29 11:37:51 -07:00
#[derive(Clone)]
2017-08-12 05:03:11 -07:00
pub struct ObjectEmitter {
qobject: Arc<Mutex<*const ObjectQObject>>,
2017-08-12 10:21:35 -07:00
boolean_changed: fn(*const ObjectQObject),
bytearray_changed: fn(*const ObjectQObject),
2017-08-21 15:51:48 -07:00
integer_changed: fn(*const ObjectQObject),
2017-08-18 02:44:37 -07:00
optional_bytearray_changed: fn(*const ObjectQObject),
2017-08-21 15:51:48 -07:00
optional_string_changed: fn(*const ObjectQObject),
string_changed: fn(*const ObjectQObject),
u64_changed: fn(*const ObjectQObject),
uinteger_changed: fn(*const ObjectQObject),
2017-08-12 05:03:11 -07:00
}
unsafe impl Send for ObjectEmitter {}
impl ObjectEmitter {
fn clear(&self) {
*self.qobject.lock().unwrap() = null();
}
2017-08-12 10:21:35 -07:00
pub fn boolean_changed(&self) {
2017-08-12 05:03:11 -07:00
let ptr = *self.qobject.lock().unwrap();
if !ptr.is_null() {
2017-08-12 10:21:35 -07:00
(self.boolean_changed)(ptr);
}
}
2017-08-21 15:51:48 -07:00
pub fn bytearray_changed(&self) {
2017-08-12 10:21:35 -07:00
let ptr = *self.qobject.lock().unwrap();
if !ptr.is_null() {
2017-08-21 15:51:48 -07:00
(self.bytearray_changed)(ptr);
2017-08-12 10:21:35 -07:00
}
}
2017-08-21 15:51:48 -07:00
pub fn integer_changed(&self) {
2017-08-12 10:21:35 -07:00
let ptr = *self.qobject.lock().unwrap();
if !ptr.is_null() {
2017-08-21 15:51:48 -07:00
(self.integer_changed)(ptr);
2017-08-12 10:21:35 -07:00
}
}
2017-08-21 15:51:48 -07:00
pub fn optional_bytearray_changed(&self) {
2017-08-15 23:54:14 -07:00
let ptr = *self.qobject.lock().unwrap();
if !ptr.is_null() {
2017-08-21 15:51:48 -07:00
(self.optional_bytearray_changed)(ptr);
2017-08-15 23:54:14 -07:00
}
}
2017-08-21 15:51:48 -07:00
pub fn optional_string_changed(&self) {
2017-08-12 10:21:35 -07:00
let ptr = *self.qobject.lock().unwrap();
if !ptr.is_null() {
2017-08-21 15:51:48 -07:00
(self.optional_string_changed)(ptr);
2017-08-12 10:21:35 -07:00
}
}
2017-08-21 15:51:48 -07:00
pub fn string_changed(&self) {
2017-08-18 02:44:37 -07:00
let ptr = *self.qobject.lock().unwrap();
if !ptr.is_null() {
2017-08-21 15:51:48 -07:00
(self.string_changed)(ptr);
2017-08-18 02:44:37 -07:00
}
}
2017-08-21 15:51:48 -07:00
pub fn u64_changed(&self) {
2017-08-12 10:21:35 -07:00
let ptr = *self.qobject.lock().unwrap();
if !ptr.is_null() {
2017-08-21 15:51:48 -07:00
(self.u64_changed)(ptr);
2017-08-12 05:03:11 -07:00
}
}
2017-08-21 15:51:48 -07:00
pub fn uinteger_changed(&self) {
2017-08-18 02:44:37 -07:00
let ptr = *self.qobject.lock().unwrap();
if !ptr.is_null() {
2017-08-21 15:51:48 -07:00
(self.uinteger_changed)(ptr);
2017-08-18 02:44:37 -07:00
}
}
2017-08-12 05:03:11 -07:00
}
pub trait ObjectTrait {
fn new(emit: ObjectEmitter) -> Self;
2017-08-12 05:03:11 -07:00
fn emit(&self) -> &ObjectEmitter;
2017-08-31 00:01:14 -07:00
fn boolean(&self) -> bool;
2017-08-12 10:21:35 -07:00
fn set_boolean(&mut self, value: bool);
2017-08-31 00:01:14 -07:00
fn bytearray(&self) -> &[u8];
2017-08-12 10:21:35 -07:00
fn set_bytearray(&mut self, value: Vec<u8>);
2017-08-31 00:01:14 -07:00
fn integer(&self) -> i32;
2017-08-21 15:51:48 -07:00
fn set_integer(&mut self, value: i32);
2017-08-31 00:01:14 -07:00
fn optional_bytearray(&self) -> Option<&[u8]>;
2017-08-18 02:44:37 -07:00
fn set_optional_bytearray(&mut self, value: Option<Vec<u8>>);
2017-08-31 00:01:14 -07:00
fn optional_string(&self) -> Option<&str>;
2017-08-21 15:51:48 -07:00
fn set_optional_string(&mut self, value: Option<String>);
2017-08-31 00:01:14 -07:00
fn string(&self) -> &str;
2017-08-21 15:51:48 -07:00
fn set_string(&mut self, value: String);
2017-08-31 00:01:14 -07:00
fn u64(&self) -> u64;
2017-08-21 15:51:48 -07:00
fn set_u64(&mut self, value: u64);
2017-08-31 00:01:14 -07:00
fn uinteger(&self) -> u32;
2017-08-21 15:51:48 -07:00
fn set_uinteger(&mut self, value: u32);
2017-08-12 05:03:11 -07:00
}
#[no_mangle]
2017-08-29 11:37:51 -07:00
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 {
2017-08-26 10:10:18 -07:00
let object_emit = ObjectEmitter {
qobject: Arc::new(Mutex::new(object)),
2017-08-12 10:21:35 -07:00
boolean_changed: boolean_changed,
bytearray_changed: bytearray_changed,
2017-08-21 15:51:48 -07:00
integer_changed: integer_changed,
2017-08-18 02:44:37 -07:00
optional_bytearray_changed: optional_bytearray_changed,
2017-08-21 15:51:48 -07:00
optional_string_changed: optional_string_changed,
string_changed: string_changed,
u64_changed: u64_changed,
uinteger_changed: uinteger_changed,
2017-08-12 05:03:11 -07:00
};
let d_object = Object::new(object_emit);
2017-08-26 10:10:18 -07:00
Box::into_raw(Box::new(d_object))
2017-08-12 05:03:11 -07:00
}
#[no_mangle]
pub unsafe extern "C" fn object_free(ptr: *mut Object) {
Box::from_raw(ptr).emit().clear();
}
#[no_mangle]
2017-08-12 10:21:35 -07:00
pub unsafe extern "C" fn object_boolean_get(ptr: *const Object) -> bool {
2017-08-31 00:01:14 -07:00
(&*ptr).boolean()
2017-08-12 10:21:35 -07:00
}
#[no_mangle]
pub unsafe extern "C" fn object_boolean_set(ptr: *mut Object, v: bool) {
(&mut *ptr).set_boolean(v);
}
#[no_mangle]
2018-05-01 16:23:06 -07:00
pub extern "C" fn object_bytearray_get(
2017-08-29 11:37:51 -07:00
ptr: *const Object,
p: *mut c_void,
2018-05-01 16:23:06 -07:00
set: fn(*mut c_void, *const c_char, c_int),
2017-08-29 11:37:51 -07:00
) {
2018-05-01 16:23:06 -07:00
let o = unsafe { &*ptr };
let v = o.bytearray();
let s: *const c_char = v.as_ptr() as (*const c_char);
set(p, s, v.len() as c_int);
2017-08-12 10:21:35 -07:00
}
#[no_mangle]
2018-05-01 16:23:06 -07:00
pub extern "C" fn object_bytearray_set(ptr: *mut Object, v: *const c_char, len: c_int) {
let o = unsafe { &mut *ptr };
let v = unsafe { slice::from_raw_parts(v as *const u8, len as usize) };
o.set_bytearray(v.into());
2017-08-12 10:21:35 -07:00
}
#[no_mangle]
2017-08-21 15:51:48 -07:00
pub unsafe extern "C" fn object_integer_get(ptr: *const Object) -> i32 {
2017-08-31 00:01:14 -07:00
(&*ptr).integer()
2017-08-12 10:21:35 -07:00
}
2017-08-15 23:54:14 -07:00
#[no_mangle]
2017-08-21 15:51:48 -07:00
pub unsafe extern "C" fn object_integer_set(ptr: *mut Object, v: i32) {
(&mut *ptr).set_integer(v);
2017-08-15 23:54:14 -07:00
}
#[no_mangle]
2018-05-01 16:23:06 -07:00
pub extern "C" fn object_optional_bytearray_get(
2017-08-29 11:37:51 -07:00
ptr: *const Object,
p: *mut c_void,
2018-05-01 16:23:06 -07:00
set: fn(*mut c_void, *const c_char, c_int),
2017-08-29 11:37:51 -07:00
) {
2018-05-01 16:23:06 -07:00
let o = unsafe { &*ptr };
let v = o.optional_bytearray();
if let Some(v) = v {
let s: *const c_char = v.as_ptr() as (*const c_char);
set(p, s, v.len() as c_int);
2017-08-21 15:51:48 -07:00
}
2017-08-15 23:54:14 -07:00
}
2017-08-12 10:21:35 -07:00
#[no_mangle]
2018-05-01 16:23:06 -07:00
pub extern "C" fn object_optional_bytearray_set(ptr: *mut Object, v: *const c_char, len: c_int) {
let o = unsafe { &mut *ptr };
let v = unsafe { slice::from_raw_parts(v as *const u8, len as usize) };
o.set_optional_bytearray(Some(v.into()));
2017-08-12 10:21:35 -07:00
}
#[no_mangle]
2018-05-01 16:23:06 -07:00
pub extern "C" fn object_optional_bytearray_set_none(ptr: *mut Object) {
let o = unsafe { &mut *ptr };
o.set_optional_bytearray(None);
2017-08-12 10:21:35 -07:00
}
2017-08-18 02:44:37 -07:00
#[no_mangle]
2018-05-01 16:23:06 -07:00
pub extern "C" fn object_optional_string_get(
2017-08-29 11:37:51 -07:00
ptr: *const Object,
p: *mut c_void,
2018-05-01 16:23:06 -07:00
set: fn(*mut c_void, *const c_char, c_int),
2017-08-29 11:37:51 -07:00
) {
2018-05-01 16:23:06 -07:00
let o = unsafe { &*ptr };
let v = o.optional_string();
if let Some(v) = v {
let s: *const c_char = v.as_ptr() as (*const c_char);
set(p, s, v.len() as c_int);
2017-08-18 02:44:37 -07:00
}
}
#[no_mangle]
2018-05-01 16:23:06 -07:00
pub extern "C" fn object_optional_string_set(ptr: *mut Object, v: *const c_ushort, len: c_int) {
let o = unsafe { &mut *ptr };
let mut s = String::new();
set_string_from_utf16(&mut s, v, len);
o.set_optional_string(Some(s));
2017-08-18 02:44:37 -07:00
}
#[no_mangle]
2018-05-01 16:23:06 -07:00
pub extern "C" fn object_optional_string_set_none(ptr: *mut Object) {
let o = unsafe { &mut *ptr };
o.set_optional_string(None);
}
2017-08-18 02:44:37 -07:00
2017-08-12 10:21:35 -07:00
#[no_mangle]
2018-05-01 16:23:06 -07:00
pub extern "C" fn object_string_get(
2017-08-29 11:37:51 -07:00
ptr: *const Object,
p: *mut c_void,
2018-05-01 16:23:06 -07:00
set: fn(*mut c_void, *const c_char, c_int),
2017-08-29 11:37:51 -07:00
) {
2018-05-01 16:23:06 -07:00
let o = unsafe { &*ptr };
let v = o.string();
let s: *const c_char = v.as_ptr() as (*const c_char);
set(p, s, v.len() as c_int);
2017-08-12 05:03:11 -07:00
}
#[no_mangle]
2018-05-01 16:23:06 -07:00
pub extern "C" fn object_string_set(ptr: *mut Object, v: *const c_ushort, len: c_int) {
let o = unsafe { &mut *ptr };
let mut s = String::new();
set_string_from_utf16(&mut s, v, len);
o.set_string(s);
2017-08-12 05:03:11 -07:00
}
2017-08-18 02:44:37 -07:00
#[no_mangle]
2017-08-21 15:51:48 -07:00
pub unsafe extern "C" fn object_u64_get(ptr: *const Object) -> u64 {
2017-08-31 00:01:14 -07:00
(&*ptr).u64()
2017-08-18 02:44:37 -07:00
}
#[no_mangle]
2017-08-21 15:51:48 -07:00
pub unsafe extern "C" fn object_u64_set(ptr: *mut Object, v: u64) {
(&mut *ptr).set_u64(v);
2017-08-18 02:44:37 -07:00
}
2017-08-21 15:51:48 -07:00
#[no_mangle]
2017-08-21 15:51:48 -07:00
pub unsafe extern "C" fn object_uinteger_get(ptr: *const Object) -> u32 {
2017-08-31 00:01:14 -07:00
(&*ptr).uinteger()
2017-08-21 15:51:48 -07:00
}
#[no_mangle]
pub unsafe extern "C" fn object_uinteger_set(ptr: *mut Object, v: u32) {
(&mut *ptr).set_uinteger(v);
}