1use crate::api::Api;
2use std::ffi::{c_void, CString};
3use tm_sys::ffi::{
4 tm_log_type_TM_LOG_TYPE_DEBUG, tm_log_type_TM_LOG_TYPE_ERROR, tm_log_type_TM_LOG_TYPE_INFO,
5 tm_logger_api, TM_LOGGER_API_NAME,
6};
7
8#[derive(Copy, Clone)]
9pub struct LogApi {
10 api: *mut tm_logger_api,
11}
12
13unsafe impl Send for LogApi {}
14unsafe impl Sync for LogApi {}
15
16impl Api for LogApi {
17 type CType = *mut tm_logger_api;
18 const NAME: &'static [u8] = TM_LOGGER_API_NAME;
19
20 #[inline]
21 fn new(api: *mut c_void) -> Self {
22 Self {
23 api: api as Self::CType,
24 }
25 }
26}
27
28impl LogApi {
29 #[inline]
30 pub fn info(&self, message: &str) {
31 let message = CString::new(message).unwrap();
32 unsafe {
33 (*self.api).print.unwrap()(
34 tm_log_type_TM_LOG_TYPE_INFO,
35 message.as_ptr() as *const ::std::os::raw::c_char,
36 )
37 };
38 }
39
40 #[inline]
41 pub fn debug(&self, message: &str) {
42 let message = CString::new(message).unwrap();
43 unsafe {
44 (*self.api).print.unwrap()(
45 tm_log_type_TM_LOG_TYPE_DEBUG,
46 message.as_ptr() as *const ::std::os::raw::c_char,
47 )
48 };
49 }
50
51 #[inline]
52 pub fn error(&self, message: &str) {
53 let message = CString::new(message).unwrap();
54 unsafe {
55 (*self.api).print.unwrap()(
56 tm_log_type_TM_LOG_TYPE_ERROR,
57 message.as_ptr() as *const ::std::os::raw::c_char,
58 )
59 };
60 }
61}