Skip to content

Commit 61e247d

Browse files
author
NICK
committed
fixes for linux system
1 parent 3ebee2e commit 61e247d

File tree

8 files changed

+119
-11
lines changed

8 files changed

+119
-11
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ once_cell = "1.13.0"
1010
widestring = "1.0.2"
1111
native_macro = { path = "./macros" }
1212
derivative = "2.2.0"
13-
lazy_static = "1.4.0"
13+
lazy_static = "1.4.0"
14+
libc = "0.2.126"

macros/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub fn native_object(_args: TokenStream, input: TokenStream) -> TokenStream {
3030

3131
#[allow(non_upper_case_globals)]
3232
static #base_done_vtable_name: IInitDoneBaseVTable<#ident> = IInitDoneBaseVTable {
33+
#[cfg(target_os = "linux")]
34+
offset_linux: 0,
3335
drop: {
3436
unsafe extern "C" fn drop<T: IComponentBase>(_0: &mut T) {
3537

@@ -64,6 +66,8 @@ pub fn native_object(_args: TokenStream, input: TokenStream) -> TokenStream {
6466

6567
#[allow(non_upper_case_globals)]
6668
static #language_ext_vtable_name: ILanguageExtenderBaseVTable<#ident> = ILanguageExtenderBaseVTable {
69+
#[cfg(target_os = "linux")]
70+
offset_linux: 0,
6771
drop: {
6872
unsafe extern "C" fn drop<T: IComponentBase>(_0: &mut T) {
6973

@@ -203,6 +207,8 @@ pub fn native_object(_args: TokenStream, input: TokenStream) -> TokenStream {
203207

204208
#[allow(non_upper_case_globals)]
205209
static #locale_vtable_name: LocaleBaseVTable<#ident> = LocaleBaseVTable {
210+
#[cfg(target_os = "linux")]
211+
offset_linux: 0,
206212
drop: {
207213
unsafe extern "C" fn drop<T: IComponentBase>(_0: &mut T) {
208214

src/component.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use crate::connector::IConnector;
66

77
#[repr(C)]
88
pub struct IInitDoneBaseVTable<T> {
9+
#[cfg(target_os = "linux")]
10+
pub offset_linux: u64,
911
pub drop: unsafe extern "C" fn(&mut T),
1012
pub init: unsafe extern "C" fn(&mut T, *mut c_void) -> bool,
1113
pub set_mem_manager: unsafe extern "C" fn(&mut T, *mut c_void) -> bool,
@@ -15,6 +17,8 @@ pub struct IInitDoneBaseVTable<T> {
1517

1618
#[repr(C)]
1719
pub struct ILanguageExtenderBaseVTable<T> {
20+
#[cfg(target_os = "linux")]
21+
pub offset_linux: u64,
1822
pub drop: unsafe extern "C" fn(&mut T),
1923
pub register_extension_as: unsafe extern "C" fn(&mut T, *mut *const u16) -> bool,
2024
pub get_n_props: unsafe extern "C" fn(&mut T) -> i64,
@@ -36,6 +40,8 @@ pub struct ILanguageExtenderBaseVTable<T> {
3640

3741
#[repr(C)]
3842
pub struct LocaleBaseVTable<T> {
43+
#[cfg(target_os = "linux")]
44+
pub offset_linux: u64,
3945
pub drop: unsafe extern "C" fn(&mut T),
4046
pub set_locale: unsafe extern "C" fn(&mut T, *const u16)
4147
}

src/connector.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::ptr::NonNull;
33
use widestring::U16CStr;
44
use crate::memory::IMemoryManager;
55
use crate::types::Variant;
6+
use crate::info::{AppInfo, IPlatformInfo};
67

78
#[repr(u8)]
89
enum Interface {
@@ -23,6 +24,8 @@ struct IMessageBox {
2324

2425
#[repr(C)]
2526
struct IConnectorVTable {
27+
#[cfg(target_os = "linux")]
28+
pub offset_linux: u64,
2629
_drop: unsafe extern "C" fn(&mut IConnector),
2730
add_error: unsafe extern "C" fn(&mut IConnector, u16, *const u16, *const u16, i64) -> bool,
2831
read: unsafe extern "C" fn(&mut IConnector, *const u16, *const Variant, *mut u64, *const *const u16) -> bool,
@@ -139,4 +142,20 @@ impl IConnector {
139142
Err(())
140143
}
141144
}
145+
146+
#[must_use]
147+
pub fn platform_info(&mut self) -> Result<AppInfo, ()> {
148+
let interface = self.get_interface(Interface::IPlatformInfo);
149+
if interface.is_null() {
150+
return Err(())
151+
}
152+
153+
let interface = unsafe { &mut *(interface as *mut IPlatformInfo) };
154+
let result = unsafe { (interface.vtable.as_mut().get_platform_info)(interface) };
155+
if result.is_null() {
156+
return Err(())
157+
}
158+
159+
Ok(AppInfo::from(unsafe { &*result }))
160+
}
142161
}

src/info.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
use std::ptr::NonNull;
2+
use widestring::U16CStr;
3+
4+
#[repr(C)]
5+
pub(crate) struct PlatformInfoVTable {
6+
pub(crate) get_platform_info: unsafe extern "C" fn(&IPlatformInfo) -> *const AppInfoInner,
7+
}
8+
9+
#[repr(C)]
10+
pub(crate) struct IPlatformInfo {
11+
pub(crate) vtable: NonNull<PlatformInfoVTable>
12+
}
13+
14+
#[repr(i8)]
15+
#[derive(Copy, Clone)]
16+
pub enum AppType {
17+
AppUnknown = -1,
18+
AppThinClient = 0,
19+
AppThickClient = 1,
20+
AppWebClient = 2,
21+
AppServer = 3,
22+
AppExtConn = 4,
23+
AppMobileClient = 5,
24+
AppMobileServer = 6,
25+
}
26+
27+
#[repr(C)]
28+
pub(crate) struct AppInfoInner {
29+
version: *const u16,
30+
user_agent: *const u16,
31+
application: AppType,
32+
}
33+
34+
pub struct AppInfo {
35+
version: String,
36+
user_agent: String,
37+
application: AppType,
38+
}
39+
40+
impl AppInfo {
41+
pub fn version(&self) -> &str {
42+
self.version.as_str()
43+
}
44+
45+
pub fn user_agent(&self) -> &str {
46+
self.user_agent.as_str()
47+
}
48+
49+
pub fn application(&self) -> AppType {
50+
self.application
51+
}
52+
}
53+
54+
impl From<&AppInfoInner> for AppInfo {
55+
fn from(value: &AppInfoInner) -> Self {
56+
AppInfo {
57+
version: {
58+
match value.version.is_null() {
59+
true => String::new(),
60+
false => unsafe { U16CStr::from_ptr_str(value.version).to_string_lossy() }
61+
}
62+
},
63+
user_agent: {
64+
match value.user_agent.is_null() {
65+
true => String::new(),
66+
false => unsafe { U16CStr::from_ptr_str(value.user_agent).to_string_lossy() }
67+
}
68+
},
69+
application: value.application
70+
}
71+
}
72+
}

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
extern crate derivative;
2+
extern crate libc;
23

34
pub use once_cell::sync::OnceCell;
45
pub use derivative::Derivative;
@@ -10,4 +11,5 @@ pub mod component;
1011
pub mod types;
1112
pub mod memory;
1213
pub mod connector;
14+
pub mod info;
1315

src/memory.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use std::ptr::NonNull;
44

55
#[repr(C)]
66
pub struct IMemoryManagerVTable {
7+
#[cfg(target_os = "linux")]
8+
offset_linux: u64,
79
_drop: unsafe extern "C" fn(&mut IMemoryManager),
810
_alloc_memory: unsafe extern "C" fn(&mut IMemoryManager, *mut *const c_void, usize) -> bool,
911
_free_memory: unsafe extern "C" fn(&mut IMemoryManager, *mut *const c_void),

src/types.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use core::ffi::c_char;
1+
use libc::{tm, c_char};
22
use crate::component::IComponentInit;
3-
use crate::memory::IMemoryManager;
43

54
#[allow(non_camel_case_types)]
65
#[repr(u16)]
@@ -59,7 +58,8 @@ pub union VariantUnion {
5958
pvar_val: *const Variant,
6059
pwstr_val: (*const u16, u32),
6160
pstr_val: (*const c_char, u32),
62-
nothing: [u8;34]
61+
tm_val: tm,
62+
//nothing: [u8;34]
6363
}
6464

6565
#[repr(C)]
@@ -312,7 +312,7 @@ macro_rules! variant_from {
312312
impl From<$from> for Variant {
313313
fn from(value: $from) -> Self {
314314
Self {
315-
value: VariantUnion { $field: value},
315+
value: VariantUnion { $field: value.into() },
316316
cb_elements: 0,
317317
vt: $vt
318318
}
@@ -322,12 +322,12 @@ macro_rules! variant_from {
322322
}
323323

324324
variant_from!(bool, b_val, VariableType::VTYPE_BOOL);
325-
variant_from!(u8, ui8val, VariableType::VTYPE_UI1);
326-
variant_from!(u16, ushort_val, VariableType::VTYPE_UI2);
327-
variant_from!(u32, ul_val, VariableType::VTYPE_UI4);
325+
variant_from!(u8, ull_val, VariableType::VTYPE_UI1);
326+
variant_from!(u16, ull_val, VariableType::VTYPE_UI2);
327+
variant_from!(u32, ull_val, VariableType::VTYPE_UI4);
328328
variant_from!(u64, ull_val, VariableType::VTYPE_UI8);
329-
variant_from!(i8, i8val, VariableType::VTYPE_I1);
330-
variant_from!(i16, short_val, VariableType::VTYPE_I2);
331-
variant_from!(i32, l_val, VariableType::VTYPE_I4);
329+
variant_from!(i8, ll_val, VariableType::VTYPE_I1);
330+
variant_from!(i16, ll_val, VariableType::VTYPE_I2);
331+
variant_from!(i32, ll_val, VariableType::VTYPE_I4);
332332
variant_from!(i64, ll_val, VariableType::VTYPE_I8);
333333
variant_from!(f64, dbl_val, VariableType::VTYPE_R8);

0 commit comments

Comments
 (0)