gz_transport_sys/
lib.rs

1#![doc = include_str!("../README.md")]
2
3use std::os::raw::{c_char, c_uint, c_void};
4
5/// wrap `gz::transport::Node`
6#[repr(C)]
7pub struct Node {
8    _private: [u8; 0],
9}
10
11/// wrap `gz::transport::Node::Publisher`
12#[repr(C)]
13pub struct Publisher {
14    _private: [u8; 0],
15}
16
17/// wrap `std::string`
18#[repr(C)]
19pub struct String {
20    _private: [u8; 0],
21}
22
23/// warp `std::vector<std::string>`
24#[repr(C)]
25pub struct StringVec {
26    _private: [u8; 0],
27}
28
29pub type SubscriberCallback =
30    unsafe extern "C" fn(*const c_char, usize, *const c_char, *mut c_void);
31
32extern "C" {
33    // Node
34    pub fn nodeCreate(partition: *const c_char) -> *mut Node;
35    pub fn nodeDestroy(node: &mut *mut Node);
36
37    // Topic
38    pub fn nodeTopicList(node: &Node) -> *mut StringVec;
39
40    // Topci Pub
41    pub fn nodeAdvertisedTopics(node: &Node) -> *mut StringVec;
42    pub fn nodeAdvertise(
43        node: &mut Node,
44        topic: *const c_char,
45        topic_type: *const c_char,
46    ) -> *mut Publisher;
47    pub fn publisherPublish(
48        publisher: &mut Publisher,
49        data: *const c_char,
50        data_len: usize,
51    ) -> bool;
52    pub fn publisherDestroy(publisher: &mut *mut Publisher);
53
54    // Topic Sub
55    pub fn nodeSubscribedTopics(node: &Node) -> *mut StringVec;
56    pub fn nodeSubscribe(
57        node: &mut Node,
58        topic: *const c_char,
59        callback: SubscriberCallback,
60        user_data: *mut c_void,
61    ) -> bool;
62    pub fn nodeUnsubscribe(node: &mut Node, topic: *const c_char) -> bool;
63
64    // Service
65    pub fn nodeServiceList(node: &Node) -> *mut StringVec;
66
67    // Service Client
68    pub fn nodeRequest(
69        node: &mut Node,
70        topic: *const c_char,
71        req: *const c_char,
72        req_len: usize,
73        reqtype: *const c_char,
74        restype: *const c_char,
75        timeout: c_uint,
76        res: &mut String,
77        result: &mut bool,
78    ) -> bool;
79
80    pub fn stringCreate() -> *mut String;
81    pub fn stringLength(string: &String) -> usize;
82    pub fn stringGet(string: &String) -> *const c_char;
83    pub fn stringDestroy(string: &mut *mut String);
84
85    pub fn stringVecCreate() -> *mut StringVec;
86    pub fn stringVecSize(stringVec: &StringVec) -> usize;
87    pub fn stringVecAt(stringVec: &StringVec, index: usize) -> *const c_char;
88    pub fn stringVecDestroy(stringVec: &mut *mut StringVec);
89
90    pub fn waitForShutdown();
91}