Skip to content

Commit aa9af4b

Browse files
author
Charlie Friend
committed
Add remaining checks to cpp-client-telemetry-sys library
1 parent 123779d commit aa9af4b

File tree

2 files changed

+67
-27
lines changed

2 files changed

+67
-27
lines changed

wrappers/rust/cpp-client-telemetry-sys/src/lib.rs

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![allow(non_snake_case)]
44
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
55

6-
use std::ffi::c_void;
6+
use std::ffi::*;
77

88
fn evt_api_call_wrapper(evt_context: Box<evt_context_t>) -> (evt_status_t, Box<evt_context_t>) {
99
let raw_pointer = Box::into_raw(evt_context);
@@ -17,11 +17,13 @@ fn evt_api_call_wrapper(evt_context: Box<evt_context_t>) -> (evt_status_t, Box<e
1717
(result, out_context)
1818
}
1919

20-
fn evt_open(config: *mut c_void) -> Option<evt_handle_t> {
20+
pub fn evt_open(config: CString) -> Option<evt_handle_t> {
21+
let config_bytes = config.to_bytes_with_nul().to_vec();
22+
2123
let context: Box<evt_context_t> = Box::new(evt_context_t {
2224
call: evt_call_t_EVT_OP_OPEN,
2325
handle: 0,
24-
data: config,
26+
data: config_bytes.as_ptr() as *mut c_void,
2527
result: 0,
2628
size: 0,
2729
});
@@ -48,28 +50,41 @@ pub fn evt_close(handle: &evt_handle_t) -> evt_status_t {
4850
result
4951
}
5052

51-
#[cfg(test)]
52-
mod tests {
53-
use super::*;
54-
55-
#[test]
56-
fn test_open_close() {
57-
let config = r#"{
58-
"eventCollectorUri": "http://localhost:64099/OneCollector/track",
59-
"cacheFilePath":"hackathon_storage.db",
60-
"config":{"host": "*"},
61-
"name":"Rust-API-Client-0",
62-
"version":"1.0.0",
63-
"primaryToken":"99999999999999999999999999999999-99999999-9999-9999-9999-999999999999-9999",
64-
"maxTeardownUploadTimeInSec":5,
65-
"hostMode":false,
66-
"traceLevelMask": 4294967295,
67-
"minimumTraceLevel":0,
68-
"sdkmode":0,
69-
"compat": {"customTypePrefix": "compat_event"}
70-
}"#;
71-
72-
let result = evt_open(config.as_ptr() as *mut c_void);
73-
assert_eq!(result, Some(0));
74-
}
53+
pub fn evt_upload(handle: &evt_handle_t) -> evt_status_t {
54+
let context: Box<evt_context_t> = Box::new(evt_context_t {
55+
call: evt_call_t_EVT_OP_UPLOAD,
56+
handle: *handle,
57+
data: std::ptr::null_mut(),
58+
result: 0,
59+
size: 0,
60+
});
61+
62+
evt_api_call_wrapper(context).0
63+
}
64+
65+
pub fn evt_flush(handle: &evt_handle_t) -> evt_status_t {
66+
let context: Box<evt_context_t> = Box::new(evt_context_t {
67+
call: evt_call_t_EVT_OP_FLUSH,
68+
handle: *handle,
69+
data: std::ptr::null_mut(),
70+
result: 0,
71+
size: 0,
72+
});
73+
74+
evt_api_call_wrapper(context).0
75+
}
76+
77+
pub fn evt_log(handle: &evt_handle_t, data: &mut [evt_prop]) -> evt_status_t {
78+
let data_len = data.len() as u32;
79+
let data_pointer = data.as_mut_ptr() as *mut c_void;
80+
81+
let context: Box<evt_context_t> = Box::new(evt_context_t {
82+
call: evt_call_t_EVT_OP_LOG,
83+
handle: *handle,
84+
data: data_pointer,
85+
result: 0,
86+
size: data_len,
87+
});
88+
89+
evt_api_call_wrapper(context).0
7590
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use cpp_client_telemetry_sys::*;
2+
use std::ffi::CString;
3+
4+
#[test]
5+
fn test_open_close() {
6+
// Simple sanity check to ensure the SDK was linked correctly.
7+
let config = r#"{
8+
"eventCollectorUri": "http://localhost:64099/OneCollector/track",
9+
"cacheFilePath":"hackathon_storage.db",
10+
"config":{"host": "*"},
11+
"name":"Rust-API-Client-0",
12+
"version":"1.0.0",
13+
"primaryToken":"99999999999999999999999999999999-99999999-9999-9999-9999-999999999999-9999",
14+
"maxTeardownUploadTimeInSec":5,
15+
"hostMode":false,
16+
"traceLevelMask": 4294967295,
17+
"minimumTraceLevel":0,
18+
"sdkmode":0,
19+
"compat": {"customTypePrefix": "compat_event"}
20+
}"#;
21+
22+
let handle = evt_open(CString::new(config).unwrap()).expect("Failed to get SDK handle");
23+
24+
assert_eq!(evt_close(&handle), 0);
25+
}

0 commit comments

Comments
 (0)