endurox_sys/
ffi.rs

1//! Raw FFI биндинги к Enduro/X C API
2
3use libc::{c_char, c_int, c_long, c_void};
4
5// Return codes (from xatmi.h)
6pub const TPFAIL: c_int = 0x00000001;
7pub const TPSUCCESS: c_int = 0x00000002;
8
9// Flags
10pub const TPNOBLOCK: c_long = 0x00000001;
11pub const TPNOTRAN: c_long = 0x00000008;
12pub const TPSIGRSTRT: c_long = 0x00000010;
13pub const TPNOTIME: c_long = 0x00000020;
14
15// Service info structure  - must match C TPSVCINFO layout
16// typedef struct {
17//     char name[XATMI_SERVICE_NAME_LENGTH+1];  // 31 chars
18//     char *data;
19//     long len;
20//     long flags;
21//     int cd;
22//     long appkey;
23//     CLIENTID cltid;  // struct with char clientdata[96]
24//     char fname[XATMI_SERVICE_NAME_LENGTH+1]; // 31 chars
25// } TPSVCINFO;
26#[repr(C)]
27pub struct TpSvcInfoRaw {
28    pub name: [c_char; 32], // XATMI_SERVICE_NAME_LENGTH+1 (31, padded to 32)
29    pub data: *mut c_char,
30    pub len: c_long,
31    pub flags: c_long,
32    pub cd: c_int,
33    pub appkey: c_long,
34    pub cltid: [c_char; 96], // CLIENTID.clientdata[NDRX_MAX_ID_SIZE]
35    pub fname: [c_char; 32], // XATMI_SERVICE_NAME_LENGTH+1 (31, padded to 32)
36}
37
38extern "C" {
39    // Server functions
40    #[cfg(feature = "server")]
41    pub fn ndrx_main(argc: c_int, argv: *mut *mut c_char) -> c_int;
42
43    #[cfg(feature = "server")]
44    pub fn tpadvertise_full(
45        svcname: *const c_char,
46        func: extern "C" fn(*mut TpSvcInfoRaw),
47        funcname: *const c_char,
48    ) -> c_int;
49
50    #[cfg(feature = "server")]
51    pub fn tpreturn(rval: c_int, rcode: c_long, data: *mut c_char, len: c_long, flags: c_long);
52
53    // Client functions
54    #[cfg(feature = "client")]
55    pub fn tpinit(tpinfo: *mut c_void) -> c_int;
56
57    #[cfg(feature = "client")]
58    pub fn tpterm() -> c_int;
59
60    #[cfg(feature = "client")]
61    pub fn tpcall(
62        svc: *const c_char,
63        idata: *mut c_char,
64        ilen: c_long,
65        odata: *mut *mut c_char,
66        olen: *mut c_long,
67        flags: c_long,
68    ) -> c_int;
69
70    #[cfg(feature = "client")]
71    pub fn tpacall(svc: *const c_char, data: *mut c_char, len: c_long, flags: c_long) -> c_int;
72
73    #[cfg(feature = "client")]
74    pub fn tpgetrply(
75        cd: *mut c_int,
76        data: *mut *mut c_char,
77        len: *mut c_long,
78        flags: c_long,
79    ) -> c_int;
80
81    // Buffer management
82    pub fn tpalloc(typ: *const c_char, subtyp: *const c_char, size: c_long) -> *mut c_char;
83    pub fn tprealloc(ptr: *mut c_char, size: c_long) -> *mut c_char;
84    pub fn tpfree(ptr: *mut c_char);
85
86    // Error handling
87    pub fn tpstrerror(err: c_int) -> *const c_char;
88    pub fn _exget_tperrno_addr() -> *const c_int;
89
90    // Logging
91    pub fn tplog(lev: c_int, format: *const c_char, ...);
92    pub fn userlog(format: *const c_char, ...);
93
94    // UBF API
95    #[cfg(feature = "ubf")]
96    pub fn Binit(p_ub: *mut c_char, len: c_long) -> c_int;
97
98    #[cfg(feature = "ubf")]
99    pub fn Badd(p_ub: *mut c_char, bfldid: c_int, buf: *const c_char, len: c_int) -> c_int;
100
101    #[cfg(feature = "ubf")]
102    pub fn Bchg(
103        p_ub: *mut c_char,
104        bfldid: c_int,
105        occ: c_int,
106        buf: *const c_char,
107        len: c_int,
108    ) -> c_int;
109
110    #[cfg(feature = "ubf")]
111    pub fn Bget(
112        p_ub: *mut c_char,
113        bfldid: c_int,
114        occ: c_int,
115        buf: *mut c_char,
116        len: *mut c_int,
117    ) -> c_int;
118
119    #[cfg(feature = "ubf")]
120    pub fn CBget(
121        p_ub: *mut c_char,
122        bfldid: c_int,
123        occ: c_int,
124        buf: *mut c_char,
125        len: *mut c_int,
126        usrtype: c_int,
127    ) -> c_int;
128
129    #[cfg(feature = "ubf")]
130    pub fn Bpres(p_ub: *mut c_char, bfldid: c_int, occ: c_int) -> c_int;
131
132    #[cfg(feature = "ubf")]
133    pub fn Bdel(p_ub: *mut c_char, bfldid: c_int, occ: c_int) -> c_int;
134
135    #[cfg(feature = "ubf")]
136    pub fn Bproj(p_ub: *mut c_char, fldlist: *const c_int) -> c_int;
137
138    #[cfg(feature = "ubf")]
139    pub fn Bfprint(p_ub: *mut c_char, outf: *mut c_void) -> c_int;
140
141    #[cfg(feature = "ubf")]
142    pub fn Bprint(p_ub: *mut c_char) -> c_int;
143
144    #[cfg(feature = "ubf")]
145    pub fn Blen(p_ub: *mut c_char, bfldid: c_int, occ: c_int) -> c_int;
146
147    #[cfg(feature = "ubf")]
148    pub fn Bused(p_ub: *mut c_char) -> c_long;
149
150    #[cfg(feature = "ubf")]
151    pub fn Bunused(p_ub: *mut c_char) -> c_long;
152
153    #[cfg(feature = "ubf")]
154    pub fn Bsizeof(p_ub: *mut c_char) -> c_long;
155
156    #[cfg(feature = "ubf")]
157    pub fn Bfldid(fldname: *const c_char) -> c_int;
158
159    #[cfg(feature = "ubf")]
160    pub fn Bfname(bfldid: c_int) -> *const c_char;
161
162    #[cfg(feature = "ubf")]
163    pub fn Bfldtype(bfldid: c_int) -> c_int;
164
165    #[cfg(feature = "ubf")]
166    pub fn Bnext(
167        p_ub: *mut c_char,
168        bfldid: *mut c_int,
169        occ: *mut c_int,
170        buf: *mut c_char,
171        len: *mut c_int,
172    ) -> c_int;
173}
174
175// UBF field types
176#[cfg(feature = "ubf")]
177pub const BFLD_SHORT: c_int = 0;
178#[cfg(feature = "ubf")]
179pub const BFLD_LONG: c_int = 1;
180#[cfg(feature = "ubf")]
181pub const BFLD_CHAR: c_int = 2;
182#[cfg(feature = "ubf")]
183pub const BFLD_FLOAT: c_int = 3;
184#[cfg(feature = "ubf")]
185pub const BFLD_DOUBLE: c_int = 4;
186#[cfg(feature = "ubf")]
187pub const BFLD_STRING: c_int = 5;
188#[cfg(feature = "ubf")]
189pub const BFLD_CARRAY: c_int = 6;