1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#![doc = include_str!("../README.md")]

use std::os::raw::{c_char, c_uint, c_void};

/// wrap `gz::transport::Node`
#[repr(C)]
pub struct Node {
    _private: [u8; 0],
}

/// wrap `gz::transport::Node::Publisher`
#[repr(C)]
pub struct Publisher {
    _private: [u8; 0],
}

/// wrap `std::string`
#[repr(C)]
pub struct String {
    _private: [u8; 0],
}

/// warp `std::vector<std::string>`
#[repr(C)]
pub struct StringVec {
    _private: [u8; 0],
}

pub type SubscriberCallback =
    unsafe extern "C" fn(*const c_char, usize, *const c_char, *mut c_void);

extern "C" {
    // Node
    pub fn nodeCreate(partition: *const c_char) -> *mut Node;
    pub fn nodeDestroy(node: &mut *mut Node);

    // Topic
    pub fn nodeTopicList(node: &Node) -> *mut StringVec;

    // Topci Pub
    pub fn nodeAdvertisedTopics(node: &Node) -> *mut StringVec;
    pub fn nodeAdvertise(
        node: &mut Node,
        topic: *const c_char,
        topic_type: *const c_char,
    ) -> *mut Publisher;
    pub fn publisherPublish(
        publisher: &mut Publisher,
        data: *const c_char,
        data_len: usize,
    ) -> bool;
    pub fn publisherDestroy(publisher: &mut *mut Publisher);

    // Topic Sub
    pub fn nodeSubscribedTopics(node: &Node) -> *mut StringVec;
    pub fn nodeSubscribe(
        node: &mut Node,
        topic: *const c_char,
        callback: SubscriberCallback,
        user_data: *mut c_void,
    ) -> bool;
    pub fn nodeUnsubscribe(node: &mut Node, topic: *const c_char) -> bool;

    // Service
    pub fn nodeServiceList(node: &Node) -> *mut StringVec;

    // Service Client
    pub fn nodeRequest(
        node: &mut Node,
        topic: *const c_char,
        req: *const c_char,
        req_len: usize,
        reqtype: *const c_char,
        restype: *const c_char,
        timeout: c_uint,
        res: &mut String,
        result: &mut bool,
    ) -> bool;

    pub fn stringCreate() -> *mut String;
    pub fn stringLength(string: &String) -> usize;
    pub fn stringGet(string: &String) -> *const c_char;
    pub fn stringDestroy(string: &mut *mut String);

    pub fn stringVecCreate() -> *mut StringVec;
    pub fn stringVecSize(stringVec: &StringVec) -> usize;
    pub fn stringVecAt(stringVec: &StringVec, index: usize) -> *const c_char;
    pub fn stringVecDestroy(stringVec: &mut *mut StringVec);

    pub fn waitForShutdown();
}