opendaq 0.1.1

Safe Rust bindings for openDAQ, the open-source data acquisition SDK
Documentation
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
// Generated by tools/generate_bindings.py -- do not edit by hand.

// Mechanical output: lint findings here are the generator's business.
#![allow(clippy::all, unused_imports, rustdoc::bare_urls)]

use crate::error::{check, Error, Result};
use crate::object::{BaseObject, Interface, Ref};
use crate::sys;
use crate::value::{Complex, Ratio, Value};
use crate::generated::*;
use std::ffi::c_char;

/// Wrapper over the openDAQ `daqLastMessageLoggerSinkPrivate` interface.
#[repr(transparent)]
#[derive(Clone, Debug)]
pub struct LastMessageLoggerSinkPrivate(pub(crate) BaseObject);

impl std::ops::Deref for LastMessageLoggerSinkPrivate {
    type Target = BaseObject;
    fn deref(&self) -> &BaseObject { &self.0 }
}
impl crate::sealed::Sealed for LastMessageLoggerSinkPrivate {}
unsafe impl Interface for LastMessageLoggerSinkPrivate {
    const NAME: &'static str = "daqLastMessageLoggerSinkPrivate";
    fn interface_id() -> Option<crate::IntfID> {
        let mut id = crate::IntfID { Data1: 0, Data2: 0, Data3: 0, Data4: 0 };
        unsafe { (crate::sys::api().daqLastMessageLoggerSinkPrivate_getInterfaceId)(&mut id) };
        Some(id)
    }
    unsafe fn from_raw(ptr: *mut std::ffi::c_void) -> Option<Self> {
        Ref::from_owned(ptr).map(Self::__from_ref)
    }
    fn as_base_object(&self) -> &BaseObject { &self.0 }
}
impl LastMessageLoggerSinkPrivate {
    #[doc(hidden)]
    pub(crate) fn __from_ref(r: Ref) -> Self { LastMessageLoggerSinkPrivate(BaseObject(r)) }
}
impl std::fmt::Display for LastMessageLoggerSinkPrivate {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        std::fmt::Display::fmt(self.as_base_object(), f)
    }
}
impl From<&LastMessageLoggerSinkPrivate> for Value {
    fn from(value: &LastMessageLoggerSinkPrivate) -> Value { Value::Object(value.to_base_object()) }
}
impl From<LastMessageLoggerSinkPrivate> for Value {
    fn from(value: LastMessageLoggerSinkPrivate) -> Value { Value::Object(value.to_base_object()) }
}
impl crate::value::FromDaqOwned for LastMessageLoggerSinkPrivate {
    unsafe fn from_daq_owned(ptr: *mut std::ffi::c_void, op: &'static str) -> Result<Self> {
        crate::value::cast_owned(ptr, op)
    }
}

/// Logs messages produced by a specific part of openDAC SDK. The messages are written into the ILoggerSink "Logger Sinks" associated with the Logger Component object.
/// The set of associated sinks is initialized on the Logger Component object creation and cannot be
/// changed after.
/// Logger Component allows to set up a threshold log severity level, so the messages with lower level
/// will not be registered.
/// Additionally, it provides the ability to trigger writing out messages stored in temporary buffers or
/// set up the minimum severity level of messages to be written out automatically,
/// see `flushOnLevel` method.
/// Wrapper over the openDAQ `daqLoggerComponent` interface.
#[repr(transparent)]
#[derive(Clone, Debug)]
pub struct LoggerComponent(pub(crate) BaseObject);

impl std::ops::Deref for LoggerComponent {
    type Target = BaseObject;
    fn deref(&self) -> &BaseObject { &self.0 }
}
impl crate::sealed::Sealed for LoggerComponent {}
unsafe impl Interface for LoggerComponent {
    const NAME: &'static str = "daqLoggerComponent";
    fn interface_id() -> Option<crate::IntfID> {
        let mut id = crate::IntfID { Data1: 0, Data2: 0, Data3: 0, Data4: 0 };
        unsafe { (crate::sys::api().daqLoggerComponent_getInterfaceId)(&mut id) };
        Some(id)
    }
    unsafe fn from_raw(ptr: *mut std::ffi::c_void) -> Option<Self> {
        Ref::from_owned(ptr).map(Self::__from_ref)
    }
    fn as_base_object(&self) -> &BaseObject { &self.0 }
}
impl LoggerComponent {
    #[doc(hidden)]
    pub(crate) fn __from_ref(r: Ref) -> Self { LoggerComponent(BaseObject(r)) }
}
impl std::fmt::Display for LoggerComponent {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        std::fmt::Display::fmt(self.as_base_object(), f)
    }
}
impl From<&LoggerComponent> for Value {
    fn from(value: &LoggerComponent) -> Value { Value::Object(value.to_base_object()) }
}
impl From<LoggerComponent> for Value {
    fn from(value: LoggerComponent) -> Value { Value::Object(value.to_base_object()) }
}
impl crate::value::FromDaqOwned for LoggerComponent {
    unsafe fn from_daq_owned(ptr: *mut std::ffi::c_void, op: &'static str) -> Result<Self> {
        crate::value::cast_owned(ptr, op)
    }
}

/// Wrapper over the openDAQ `daqLoggerSink` interface.
#[repr(transparent)]
#[derive(Clone, Debug)]
pub struct LoggerSink(pub(crate) BaseObject);

impl std::ops::Deref for LoggerSink {
    type Target = BaseObject;
    fn deref(&self) -> &BaseObject { &self.0 }
}
impl crate::sealed::Sealed for LoggerSink {}
unsafe impl Interface for LoggerSink {
    const NAME: &'static str = "daqLoggerSink";
    fn interface_id() -> Option<crate::IntfID> { None }
    unsafe fn from_raw(ptr: *mut std::ffi::c_void) -> Option<Self> {
        Ref::from_owned(ptr).map(Self::__from_ref)
    }
    fn as_base_object(&self) -> &BaseObject { &self.0 }
}
impl LoggerSink {
    #[doc(hidden)]
    pub(crate) fn __from_ref(r: Ref) -> Self { LoggerSink(BaseObject(r)) }
}
impl std::fmt::Display for LoggerSink {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        std::fmt::Display::fmt(self.as_base_object(), f)
    }
}
impl From<&LoggerSink> for Value {
    fn from(value: &LoggerSink) -> Value { Value::Object(value.to_base_object()) }
}
impl From<LoggerSink> for Value {
    fn from(value: LoggerSink) -> Value { Value::Object(value.to_base_object()) }
}
impl crate::value::FromDaqOwned for LoggerSink {
    unsafe fn from_daq_owned(ptr: *mut std::ffi::c_void, op: &'static str) -> Result<Self> {
        crate::value::cast_owned(ptr, op)
    }
}

/// Container for messages queue and backing threads used for asynchronous logging.
/// Wrapper over the openDAQ `daqLoggerThreadPool` interface.
#[repr(transparent)]
#[derive(Clone, Debug)]
pub struct LoggerThreadPool(pub(crate) BaseObject);

impl std::ops::Deref for LoggerThreadPool {
    type Target = BaseObject;
    fn deref(&self) -> &BaseObject { &self.0 }
}
impl crate::sealed::Sealed for LoggerThreadPool {}
unsafe impl Interface for LoggerThreadPool {
    const NAME: &'static str = "daqLoggerThreadPool";
    fn interface_id() -> Option<crate::IntfID> {
        let mut id = crate::IntfID { Data1: 0, Data2: 0, Data3: 0, Data4: 0 };
        unsafe { (crate::sys::api().daqLoggerThreadPool_getInterfaceId)(&mut id) };
        Some(id)
    }
    unsafe fn from_raw(ptr: *mut std::ffi::c_void) -> Option<Self> {
        Ref::from_owned(ptr).map(Self::__from_ref)
    }
    fn as_base_object(&self) -> &BaseObject { &self.0 }
}
impl LoggerThreadPool {
    #[doc(hidden)]
    pub(crate) fn __from_ref(r: Ref) -> Self { LoggerThreadPool(BaseObject(r)) }
}
impl std::fmt::Display for LoggerThreadPool {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        std::fmt::Display::fmt(self.as_base_object(), f)
    }
}
impl From<&LoggerThreadPool> for Value {
    fn from(value: &LoggerThreadPool) -> Value { Value::Object(value.to_base_object()) }
}
impl From<LoggerThreadPool> for Value {
    fn from(value: LoggerThreadPool) -> Value { Value::Object(value.to_base_object()) }
}
impl crate::value::FromDaqOwned for LoggerThreadPool {
    unsafe fn from_daq_owned(ptr: *mut std::ffi::c_void, op: &'static str) -> Result<Self> {
        crate::value::cast_owned(ptr, op)
    }
}

impl LastMessageLoggerSinkPrivate {
    /// Get the last log message
    ///
    /// # Returns
    /// - `last_message`: The last log message
    ///
    /// Calls the openDAQ C function `daqLastMessageLoggerSinkPrivate_getLastMessage()`.
    pub fn last_message(&self) -> Result<String> {
        let mut __last_message: *mut sys::daqString = std::ptr::null_mut();
        let __code = unsafe { (crate::sys::api().daqLastMessageLoggerSinkPrivate_getLastMessage)(self.as_raw() as *mut _, &mut __last_message) };
        check(__code, "daqLastMessageLoggerSinkPrivate_getLastMessage")?;
        Ok(unsafe { crate::marshal::take_string(__last_message) })
    }

    /// Wait for receiving a new log message
    ///
    /// # Parameters
    /// - `timeout_ms`: The timeout in milliseconds until which wait for a new log message. If timeout set as 0 ms waiting will be skipped.
    ///
    /// # Returns
    /// - `success`: The success will return true if there was a new unread log message before waiting or sink got a new logger message before timeout. False if timeout was reached.
    ///
    /// Calls the openDAQ C function `daqLastMessageLoggerSinkPrivate_waitForMessage()`.
    pub fn wait_for_message(&self, timeout_ms: usize) -> Result<bool> {
        let mut __success: u8 = 0;
        let __code = unsafe { (crate::sys::api().daqLastMessageLoggerSinkPrivate_waitForMessage)(self.as_raw() as *mut _, timeout_ms, &mut __success) };
        check(__code, "daqLastMessageLoggerSinkPrivate_waitForMessage")?;
        Ok(__success != 0)
    }

}

impl LoggerComponent {
    /// Calls the openDAQ C function `daqLoggerComponent_createLoggerComponent()`.
    pub fn new(name: &str, sinks: impl Into<Value>, thread_pool: &LoggerThreadPool, level: LogLevel) -> Result<LoggerComponent> {
        let __name = crate::marshal::make_string(name)?;
        let __sinks = crate::value::to_daq(&sinks.into())?;
        let mut __obj: *mut sys::daqLoggerComponent = std::ptr::null_mut();
        let __code = unsafe { (crate::sys::api().daqLoggerComponent_createLoggerComponent)(&mut __obj, __name.as_ptr() as *mut _, crate::value::opt_ref_ptr(&__sinks) as *mut _, thread_pool.as_raw() as *mut _, level as u32) };
        check(__code, "daqLoggerComponent_createLoggerComponent")?;
        Ok(unsafe { crate::marshal::require_object::<LoggerComponent>(__obj as *mut _, "daqLoggerComponent_createLoggerComponent") }?)
    }

    /// Triggers writing out the messages stored in temporary buffers.
    ///
    /// Calls the openDAQ C function `daqLoggerComponent_flush()`.
    pub fn flush(&self) -> Result<()> {
        let __code = unsafe { (crate::sys::api().daqLoggerComponent_flush)(self.as_raw() as *mut _) };
        check(__code, "daqLoggerComponent_flush")?;
        Ok(())
    }

    /// Sets the minimum severity level of messages to be automatically written to the associated sinks bypassing the temporary buffers.
    ///
    /// # Parameters
    /// - `level`: The severity level of messages.
    ///
    /// Calls the openDAQ C function `daqLoggerComponent_flushOnLevel()`.
    pub fn flush_on_level(&self, level: LogLevel) -> Result<()> {
        let __code = unsafe { (crate::sys::api().daqLoggerComponent_flushOnLevel)(self.as_raw() as *mut _, level as u32) };
        check(__code, "daqLoggerComponent_flushOnLevel")?;
        Ok(())
    }

    /// Gets the minimal severity level of messages to be logged by the component.
    ///
    /// # Returns
    /// - `level`: The log severity level of the component.
    ///
    /// Calls the openDAQ C function `daqLoggerComponent_getLevel()`.
    pub fn level(&self) -> Result<LogLevel> {
        let mut __level: u32 = 0;
        let __code = unsafe { (crate::sys::api().daqLoggerComponent_getLevel)(self.as_raw() as *mut _, &mut __level) };
        check(__code, "daqLoggerComponent_getLevel")?;
        Ok(crate::marshal::enum_out(LogLevel::from_raw(__level), "daqLoggerComponent_getLevel")?)
    }

    /// Gets the name of the component.
    ///
    /// # Returns
    /// - `name`: The name of the component.
    ///
    /// Calls the openDAQ C function `daqLoggerComponent_getName()`.
    pub fn name(&self) -> Result<String> {
        let mut __name: *mut sys::daqString = std::ptr::null_mut();
        let __code = unsafe { (crate::sys::api().daqLoggerComponent_getName)(self.as_raw() as *mut _, &mut __name) };
        check(__code, "daqLoggerComponent_getName")?;
        Ok(unsafe { crate::marshal::take_string(__name) })
    }

    /// Sets the minimal severity level of messages to be logged by the component.
    ///
    /// # Parameters
    /// - `level`: The log severity level of the component.
    ///
    /// Calls the openDAQ C function `daqLoggerComponent_setLevel()`.
    pub fn set_level(&self, level: LogLevel) -> Result<()> {
        let __code = unsafe { (crate::sys::api().daqLoggerComponent_setLevel)(self.as_raw() as *mut _, level as u32) };
        check(__code, "daqLoggerComponent_setLevel")?;
        Ok(())
    }

    /// Sets the custom formatter pattern for the component.
    ///
    /// # Parameters
    /// - `pattern`: The format pattern string.
    ///
    /// Calls the openDAQ C function `daqLoggerComponent_setPattern()`.
    pub fn set_pattern(&self, pattern: &str) -> Result<()> {
        let __pattern = crate::marshal::make_string(pattern)?;
        let __code = unsafe { (crate::sys::api().daqLoggerComponent_setPattern)(self.as_raw() as *mut _, __pattern.as_ptr() as *mut _) };
        check(__code, "daqLoggerComponent_setPattern")?;
        Ok(())
    }

    /// Checks whether the messages with given log severity level will be logged or not.
    ///
    /// # Parameters
    /// - `level`: The severity level of messages.
    ///
    /// # Returns
    /// - `will_log`: True if the messages with `level` will be logged within the component; false otherwise.
    ///
    /// Calls the openDAQ C function `daqLoggerComponent_shouldLog()`.
    pub fn should_log(&self, level: LogLevel) -> Result<bool> {
        let mut __will_log: u8 = 0;
        let __code = unsafe { (crate::sys::api().daqLoggerComponent_shouldLog)(self.as_raw() as *mut _, level as u32, &mut __will_log) };
        check(__code, "daqLoggerComponent_shouldLog")?;
        Ok(__will_log != 0)
    }

}

impl LoggerSink {
    /// Calls the openDAQ C function `daqLoggerSink_createBasicFileLoggerSink()`.
    pub fn basic_file(file_name: &str) -> Result<LoggerSink> {
        let __file_name = crate::marshal::make_string(file_name)?;
        let mut __obj: *mut sys::daqLoggerSink = std::ptr::null_mut();
        let __code = unsafe { (crate::sys::api().daqLoggerSink_createBasicFileLoggerSink)(&mut __obj, __file_name.as_ptr() as *mut _) };
        check(__code, "daqLoggerSink_createBasicFileLoggerSink")?;
        Ok(unsafe { crate::marshal::require_object::<LoggerSink>(__obj as *mut _, "daqLoggerSink_createBasicFileLoggerSink") }?)
    }

    /// Calls the openDAQ C function `daqLoggerSink_createRotatingFileLoggerSink()`.
    pub fn rotating_file(file_name: &str, max_file_byte_size: usize, max_files: usize) -> Result<LoggerSink> {
        let __file_name = crate::marshal::make_string(file_name)?;
        let mut __obj: *mut sys::daqLoggerSink = std::ptr::null_mut();
        let __code = unsafe { (crate::sys::api().daqLoggerSink_createRotatingFileLoggerSink)(&mut __obj, __file_name.as_ptr() as *mut _, max_file_byte_size, max_files) };
        check(__code, "daqLoggerSink_createRotatingFileLoggerSink")?;
        Ok(unsafe { crate::marshal::require_object::<LoggerSink>(__obj as *mut _, "daqLoggerSink_createRotatingFileLoggerSink") }?)
    }

    /// Calls the openDAQ C function `daqLoggerSink_createStdErrLoggerSink()`.
    pub fn std_err() -> Result<LoggerSink> {
        let mut __obj: *mut sys::daqLoggerSink = std::ptr::null_mut();
        let __code = unsafe { (crate::sys::api().daqLoggerSink_createStdErrLoggerSink)(&mut __obj) };
        check(__code, "daqLoggerSink_createStdErrLoggerSink")?;
        Ok(unsafe { crate::marshal::require_object::<LoggerSink>(__obj as *mut _, "daqLoggerSink_createStdErrLoggerSink") }?)
    }

    /// Calls the openDAQ C function `daqLoggerSink_createStdOutLoggerSink()`.
    pub fn std_out() -> Result<LoggerSink> {
        let mut __obj: *mut sys::daqLoggerSink = std::ptr::null_mut();
        let __code = unsafe { (crate::sys::api().daqLoggerSink_createStdOutLoggerSink)(&mut __obj) };
        check(__code, "daqLoggerSink_createStdOutLoggerSink")?;
        Ok(unsafe { crate::marshal::require_object::<LoggerSink>(__obj as *mut _, "daqLoggerSink_createStdOutLoggerSink") }?)
    }

    /// Calls the openDAQ C function `daqLoggerSink_createWinDebugLoggerSink()`.
    pub fn win_debug() -> Result<LoggerSink> {
        let mut __obj: *mut sys::daqLoggerSink = std::ptr::null_mut();
        let __code = unsafe { (crate::sys::api().daqLoggerSink_createWinDebugLoggerSink)(&mut __obj) };
        check(__code, "daqLoggerSink_createWinDebugLoggerSink")?;
        Ok(unsafe { crate::marshal::require_object::<LoggerSink>(__obj as *mut _, "daqLoggerSink_createWinDebugLoggerSink") }?)
    }

    /// Calls the openDAQ C function `daqLoggerSink_flush()`.
    pub fn flush(&self) -> Result<()> {
        let __code = unsafe { (crate::sys::api().daqLoggerSink_flush)(self.as_raw() as *mut _) };
        check(__code, "daqLoggerSink_flush")?;
        Ok(())
    }

    /// Calls the openDAQ C function `daqLoggerSink_getLevel()`.
    pub fn level(&self) -> Result<LogLevel> {
        let mut __level: u32 = 0;
        let __code = unsafe { (crate::sys::api().daqLoggerSink_getLevel)(self.as_raw() as *mut _, &mut __level) };
        check(__code, "daqLoggerSink_getLevel")?;
        Ok(crate::marshal::enum_out(LogLevel::from_raw(__level), "daqLoggerSink_getLevel")?)
    }

    /// Calls the openDAQ C function `daqLoggerSink_setLevel()`.
    pub fn set_level(&self, level: LogLevel) -> Result<()> {
        let __code = unsafe { (crate::sys::api().daqLoggerSink_setLevel)(self.as_raw() as *mut _, level as u32) };
        check(__code, "daqLoggerSink_setLevel")?;
        Ok(())
    }

    /// Calls the openDAQ C function `daqLoggerSink_setPattern()`.
    pub fn set_pattern(&self, pattern: &str) -> Result<()> {
        let __pattern = crate::marshal::make_string(pattern)?;
        let __code = unsafe { (crate::sys::api().daqLoggerSink_setPattern)(self.as_raw() as *mut _, __pattern.as_ptr() as *mut _) };
        check(__code, "daqLoggerSink_setPattern")?;
        Ok(())
    }

    /// Calls the openDAQ C function `daqLoggerSink_shouldLog()`.
    pub fn should_log(&self, level: LogLevel) -> Result<bool> {
        let mut __will_log: u8 = 0;
        let __code = unsafe { (crate::sys::api().daqLoggerSink_shouldLog)(self.as_raw() as *mut _, level as u32, &mut __will_log) };
        check(__code, "daqLoggerSink_shouldLog")?;
        Ok(__will_log != 0)
    }

}

impl LoggerThreadPool {
    /// Calls the openDAQ C function `daqLoggerThreadPool_createLoggerThreadPool()`.
    pub fn new() -> Result<LoggerThreadPool> {
        let mut __obj: *mut sys::daqLoggerThreadPool = std::ptr::null_mut();
        let __code = unsafe { (crate::sys::api().daqLoggerThreadPool_createLoggerThreadPool)(&mut __obj) };
        check(__code, "daqLoggerThreadPool_createLoggerThreadPool")?;
        Ok(unsafe { crate::marshal::require_object::<LoggerThreadPool>(__obj as *mut _, "daqLoggerThreadPool_createLoggerThreadPool") }?)
    }

}