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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
// 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;
/// Represents a collection of ILoggerComponent "Logger Components" with multiple
/// ILoggerSink "Logger Sinks" and a single ILoggerThreadPool "Logger Thread Pool"
/// shared between components.
/// Logger is used to create, manage and maintain Logger Components associated with different parts of
/// the openDAQ SDK. The Logger provides methods, allowing for components to be added and removed dynamically.
/// The components added within the same Logger object should have unique names. Each newly added
/// component inherits threshold log severity level from the Logger. Then this level can be changed
/// independently per component. The set of sinks is initialized on the Logger object creation
/// and cannot be changed after.
/// Additionally, Logger provides the ability to manage flushing policies for the added components,
/// see `flushOnLevel` method.
/// Wrapper over the openDAQ `daqLogger` interface.
#[repr(transparent)]
#[derive(Clone, Debug)]
pub struct Logger(pub(crate) BaseObject);
impl std::ops::Deref for Logger {
type Target = BaseObject;
fn deref(&self) -> &BaseObject { &self.0 }
}
impl crate::sealed::Sealed for Logger {}
unsafe impl Interface for Logger {
const NAME: &'static str = "daqLogger";
fn interface_id() -> Option<crate::IntfID> {
let mut id = crate::IntfID { Data1: 0, Data2: 0, Data3: 0, Data4: 0 };
unsafe { (crate::sys::api().daqLogger_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 Logger {
#[doc(hidden)]
pub(crate) fn __from_ref(r: Ref) -> Self { Logger(BaseObject(r)) }
}
impl std::fmt::Display for Logger {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.as_base_object(), f)
}
}
impl From<&Logger> for Value {
fn from(value: &Logger) -> Value { Value::Object(value.to_base_object()) }
}
impl From<Logger> for Value {
fn from(value: Logger) -> Value { Value::Object(value.to_base_object()) }
}
impl crate::value::FromDaqOwned for Logger {
unsafe fn from_daq_owned(ptr: *mut std::ffi::c_void, op: &'static str) -> Result<Self> {
crate::value::cast_owned(ptr, op)
}
}
/// Loads all available modules in a implementation-defined manner. User can also side-load custom modules via `addModule` call.
/// Wrapper over the openDAQ `daqModuleManager` interface.
#[repr(transparent)]
#[derive(Clone, Debug)]
pub struct ModuleManager(pub(crate) BaseObject);
impl std::ops::Deref for ModuleManager {
type Target = BaseObject;
fn deref(&self) -> &BaseObject { &self.0 }
}
impl crate::sealed::Sealed for ModuleManager {}
unsafe impl Interface for ModuleManager {
const NAME: &'static str = "daqModuleManager";
fn interface_id() -> Option<crate::IntfID> {
let mut id = crate::IntfID { Data1: 0, Data2: 0, Data3: 0, Data4: 0 };
unsafe { (crate::sys::api().daqModuleManager_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 ModuleManager {
#[doc(hidden)]
pub(crate) fn __from_ref(r: Ref) -> Self { ModuleManager(BaseObject(r)) }
}
impl std::fmt::Display for ModuleManager {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.as_base_object(), f)
}
}
impl From<&ModuleManager> for Value {
fn from(value: &ModuleManager) -> Value { Value::Object(value.to_base_object()) }
}
impl From<ModuleManager> for Value {
fn from(value: ModuleManager) -> Value { Value::Object(value.to_base_object()) }
}
impl crate::value::FromDaqOwned for ModuleManager {
unsafe fn from_daq_owned(ptr: *mut std::ffi::c_void, op: &'static str) -> Result<Self> {
crate::value::cast_owned(ptr, op)
}
}
/// A thread-pool scheduler that supports scheduling one-off functions as well as dependency graphs.
/// Wrapper over the openDAQ `daqScheduler` interface.
#[repr(transparent)]
#[derive(Clone, Debug)]
pub struct Scheduler(pub(crate) BaseObject);
impl std::ops::Deref for Scheduler {
type Target = BaseObject;
fn deref(&self) -> &BaseObject { &self.0 }
}
impl crate::sealed::Sealed for Scheduler {}
unsafe impl Interface for Scheduler {
const NAME: &'static str = "daqScheduler";
fn interface_id() -> Option<crate::IntfID> {
let mut id = crate::IntfID { Data1: 0, Data2: 0, Data3: 0, Data4: 0 };
unsafe { (crate::sys::api().daqScheduler_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 Scheduler {
#[doc(hidden)]
pub(crate) fn __from_ref(r: Ref) -> Self { Scheduler(BaseObject(r)) }
}
impl std::fmt::Display for Scheduler {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.as_base_object(), f)
}
}
impl From<&Scheduler> for Value {
fn from(value: &Scheduler) -> Value { Value::Object(value.to_base_object()) }
}
impl From<Scheduler> for Value {
fn from(value: Scheduler) -> Value { Value::Object(value.to_base_object()) }
}
impl crate::value::FromDaqOwned for Scheduler {
unsafe fn from_daq_owned(ptr: *mut std::ffi::c_void, op: &'static str) -> Result<Self> {
crate::value::cast_owned(ptr, op)
}
}
impl Logger {
/// Creates a component with a given name and adds it to the Logger object.
///
/// # Parameters
/// - `name`: The component's name.
///
/// # Returns
/// - `component`: Added component.
///
/// # Errors
/// - `OPENDAQ_ERR_INVALIDPARAMETER`: if `name` is empty string.
///
/// Calls the openDAQ C function `daqLogger_addComponent()`.
pub fn add_component(&self, name: &str) -> Result<Option<LoggerComponent>> {
let __name = crate::marshal::make_string(name)?;
let mut __component: *mut sys::daqLoggerComponent = std::ptr::null_mut();
let __code = unsafe { (crate::sys::api().daqLogger_addComponent)(self.as_raw() as *mut _, __name.as_ptr() as *mut _, &mut __component) };
check(__code, "daqLogger_addComponent")?;
Ok(unsafe { crate::marshal::take_object::<LoggerComponent>(__component as *mut _) })
}
/// Calls the openDAQ C function `daqLogger_createLogger()`.
pub fn new(sinks: impl Into<Value>, level: LogLevel) -> Result<Logger> {
let __sinks = crate::value::to_daq(&sinks.into())?;
let mut __obj: *mut sys::daqLogger = std::ptr::null_mut();
let __code = unsafe { (crate::sys::api().daqLogger_createLogger)(&mut __obj, crate::value::opt_ref_ptr(&__sinks) as *mut _, level as u32) };
check(__code, "daqLogger_createLogger")?;
Ok(unsafe { crate::marshal::require_object::<Logger>(__obj as *mut _, "daqLogger_createLogger") }?)
}
/// Triggers writing out the messages stored in temporary buffers for added components and sinks associated with the Logger object.
///
/// Calls the openDAQ C function `daqLogger_flush()`.
pub fn flush(&self) -> Result<()> {
let __code = unsafe { (crate::sys::api().daqLogger_flush)(self.as_raw() as *mut _) };
check(__code, "daqLogger_flush")?;
Ok(())
}
/// Sets the minimum severity level of messages to be automatically flushed by components of Logger object.
///
/// # Parameters
/// - `level`: The log severity level.
///
/// Calls the openDAQ C function `daqLogger_flushOnLevel()`.
pub fn flush_on_level(&self, level: LogLevel) -> Result<()> {
let __code = unsafe { (crate::sys::api().daqLogger_flushOnLevel)(self.as_raw() as *mut _, level as u32) };
check(__code, "daqLogger_flushOnLevel")?;
Ok(())
}
/// Gets an added component by name.
///
/// # Parameters
/// - `name`: The component's name.
///
/// # Returns
/// - `component`: The logger component with the name equal to ``name`.`
///
/// # Errors
/// - `OPENDAQ_ERR_NOTFOUND`: if a component with the specified `name` was not added.
///
/// Calls the openDAQ C function `daqLogger_getComponent()`.
pub fn component(&self, name: &str) -> Result<Option<LoggerComponent>> {
let __name = crate::marshal::make_string(name)?;
let mut __component: *mut sys::daqLoggerComponent = std::ptr::null_mut();
let __code = unsafe { (crate::sys::api().daqLogger_getComponent)(self.as_raw() as *mut _, __name.as_ptr() as *mut _, &mut __component) };
check(__code, "daqLogger_getComponent")?;
Ok(unsafe { crate::marshal::take_object::<LoggerComponent>(__component as *mut _) })
}
/// Gets a list of added components.
///
/// # Returns
/// - `components`: The list of added components.
///
/// Calls the openDAQ C function `daqLogger_getComponents()`.
pub fn components(&self) -> Result<Vec<LoggerComponent>> {
let mut __components: *mut sys::daqList = std::ptr::null_mut();
let __code = unsafe { (crate::sys::api().daqLogger_getComponents)(self.as_raw() as *mut _, &mut __components) };
check(__code, "daqLogger_getComponents")?;
Ok(unsafe { crate::marshal::take_list::<LoggerComponent>(__components as *mut _, "daqLogger_getComponents") }?)
}
/// Gets the default log severity level.
///
/// # Returns
/// - `level`: The log severity level.
///
/// Calls the openDAQ C function `daqLogger_getLevel()`.
pub fn level(&self) -> Result<LogLevel> {
let mut __level: u32 = 0;
let __code = unsafe { (crate::sys::api().daqLogger_getLevel)(self.as_raw() as *mut _, &mut __level) };
check(__code, "daqLogger_getLevel")?;
Ok(crate::marshal::enum_out(LogLevel::from_raw(__level), "daqLogger_getLevel")?)
}
/// Gets an added component by name or creates a new one with a given name and adds it to the Logger object.
///
/// # Parameters
/// - `name`: The component's name.
///
/// # Returns
/// - `component`: The logger component with the name equal to ``name`.`
///
/// # Errors
/// - `OPENDAQ_ERR_INVALIDPARAMETER`: if `name` is empty string.
///
/// Calls the openDAQ C function `daqLogger_getOrAddComponent()`.
pub fn or_add_component(&self, name: &str) -> Result<Option<LoggerComponent>> {
let __name = crate::marshal::make_string(name)?;
let mut __component: *mut sys::daqLoggerComponent = std::ptr::null_mut();
let __code = unsafe { (crate::sys::api().daqLogger_getOrAddComponent)(self.as_raw() as *mut _, __name.as_ptr() as *mut _, &mut __component) };
check(__code, "daqLogger_getOrAddComponent")?;
Ok(unsafe { crate::marshal::take_object::<LoggerComponent>(__component as *mut _) })
}
/// Removes the component with a given name from the Logger object.
///
/// # Parameters
/// - `name`: The component's name.
///
/// # Errors
/// - `OPENDAQ_ERR_NOTFOUND`: if a component with the specified `name` was not added.
///
/// Calls the openDAQ C function `daqLogger_removeComponent()`.
pub fn remove_component(&self, name: &str) -> Result<()> {
let __name = crate::marshal::make_string(name)?;
let __code = unsafe { (crate::sys::api().daqLogger_removeComponent)(self.as_raw() as *mut _, __name.as_ptr() as *mut _) };
check(__code, "daqLogger_removeComponent")?;
Ok(())
}
/// Sets the default log severity level.
///
/// # Parameters
/// - `level`: The log severity level.
///
/// Calls the openDAQ C function `daqLogger_setLevel()`.
pub fn set_level(&self, level: LogLevel) -> Result<()> {
let __code = unsafe { (crate::sys::api().daqLogger_setLevel)(self.as_raw() as *mut _, level as u32) };
check(__code, "daqLogger_setLevel")?;
Ok(())
}
}
impl ModuleManager {
/// Side-load a custom module in run-time from memory that was not found by default.
///
/// # Parameters
/// - `module`: The module to add.
///
/// # Errors
/// - `OPENDAQ_ERR_DUPLICATEITEM`: When an identical `module` was already added.
///
/// Calls the openDAQ C function `daqModuleManager_addModule()`.
pub fn add_module(&self, module: &Module) -> Result<()> {
let __code = unsafe { (crate::sys::api().daqModuleManager_addModule)(self.as_raw() as *mut _, module.as_raw() as *mut _) };
check(__code, "daqModuleManager_addModule")?;
Ok(())
}
/// Calls the openDAQ C function `daqModuleManager_createModuleManager()`.
pub fn new(path: &str) -> Result<ModuleManager> {
let __path = crate::marshal::make_string(path)?;
let mut __obj: *mut sys::daqModuleManager = std::ptr::null_mut();
let __code = unsafe { (crate::sys::api().daqModuleManager_createModuleManager)(&mut __obj, __path.as_ptr() as *mut _) };
check(__code, "daqModuleManager_createModuleManager")?;
Ok(unsafe { crate::marshal::require_object::<ModuleManager>(__obj as *mut _, "daqModuleManager_createModuleManager") }?)
}
/// Calls the openDAQ C function `daqModuleManager_createModuleManagerMultiplePaths()`.
pub fn multiple_paths(paths: impl Into<Value>) -> Result<ModuleManager> {
let __paths = crate::value::to_daq(&paths.into())?;
let mut __obj: *mut sys::daqModuleManager = std::ptr::null_mut();
let __code = unsafe { (crate::sys::api().daqModuleManager_createModuleManagerMultiplePaths)(&mut __obj, crate::value::opt_ref_ptr(&__paths) as *mut _) };
check(__code, "daqModuleManager_createModuleManagerMultiplePaths")?;
Ok(unsafe { crate::marshal::require_object::<ModuleManager>(__obj as *mut _, "daqModuleManager_createModuleManagerMultiplePaths") }?)
}
/// Retrieves all modules known to the manager. Whether they were found or side-loaded.
///
/// # Returns
/// - `modules`: A list of known modules.
///
/// Calls the openDAQ C function `daqModuleManager_getModules()`.
pub fn modules(&self) -> Result<Vec<Module>> {
let mut __modules: *mut sys::daqList = std::ptr::null_mut();
let __code = unsafe { (crate::sys::api().daqModuleManager_getModules)(self.as_raw() as *mut _, &mut __modules) };
check(__code, "daqModuleManager_getModules")?;
Ok(unsafe { crate::marshal::take_list::<Module>(__modules as *mut _, "daqModuleManager_getModules") }?)
}
/// Returns a dictionary of module IDs and the respective public keys of their vendors.
///
/// # Returns
/// - `vendor_keys`: key (IString) - module ID, value (IString) - public vendor key Used to identify which authenticator/certificate was used to authenticate the module.
///
/// Calls the openDAQ C function `daqModuleManager_getVendorKeys()`.
pub fn vendor_keys(&self) -> Result<std::collections::HashMap<String, String>> {
let mut __vendor_keys: *mut sys::daqDict = std::ptr::null_mut();
let __code = unsafe { (crate::sys::api().daqModuleManager_getVendorKeys)(self.as_raw() as *mut _, &mut __vendor_keys) };
check(__code, "daqModuleManager_getVendorKeys")?;
Ok(unsafe { crate::marshal::take_dict::<String, String>(__vendor_keys as *mut _, "daqModuleManager_getVendorKeys") }?)
}
/// Loads and adds a single module from the given absolute file system path.
///
/// # Parameters
/// - `path`: The absolute path to the module file.
///
/// # Returns
/// - `module`: The resulting loaded and added module object. This function should be used only after the default modules have been loaded using `loadModules`. The specified path must exist and reference a file with the proper extension.
///
/// Calls the openDAQ C function `daqModuleManager_loadModule()`.
pub fn load_module(&self, path: &str) -> Result<Option<Module>> {
let __path = crate::marshal::make_string(path)?;
let mut __module: *mut sys::daqModule = std::ptr::null_mut();
let __code = unsafe { (crate::sys::api().daqModuleManager_loadModule)(self.as_raw() as *mut _, __path.as_ptr() as *mut _, &mut __module) };
check(__code, "daqModuleManager_loadModule")?;
Ok(unsafe { crate::marshal::take_object::<Module>(__module as *mut _) })
}
/// Loads all modules from the directory path specified during manager construction. The Context is passed to all loaded modules for internal use.
///
/// # Parameters
/// - `context`: The Context containing the Logger, Scheduler, Property Object Class Manager and Module Manager
///
/// Calls the openDAQ C function `daqModuleManager_loadModules()`.
pub fn load_modules(&self, context: &Context) -> Result<()> {
let __code = unsafe { (crate::sys::api().daqModuleManager_loadModules)(self.as_raw() as *mut _, context.as_raw() as *mut _) };
check(__code, "daqModuleManager_loadModules")?;
Ok(())
}
/// Toggle whether this module manager will only load modules that can be authenticated.
///
/// # Parameters
/// - `authenticated_only`: true - only authenticated modules are loaded, false - all modules are loaded
///
/// Calls the openDAQ C function `daqModuleManager_setAuthenticatedOnly()`.
pub fn set_authenticated_only(&self, authenticated_only: bool) -> Result<()> {
let __code = unsafe { (crate::sys::api().daqModuleManager_setAuthenticatedOnly)(self.as_raw() as *mut _, u8::from(authenticated_only)) };
check(__code, "daqModuleManager_setAuthenticatedOnly")?;
Ok(())
}
/// Imports the module authenticator.
///
/// # Parameters
/// - `authenticator`: A custom authenticator used to verify the signature/checksum of the modules.
///
/// Calls the openDAQ C function `daqModuleManager_setModuleAuthenticator()`.
pub fn set_module_authenticator(&self, authenticator: &ModuleAuthenticator) -> Result<()> {
let __code = unsafe { (crate::sys::api().daqModuleManager_setModuleAuthenticator)(self.as_raw() as *mut _, authenticator.as_raw() as *mut _) };
check(__code, "daqModuleManager_setModuleAuthenticator")?;
Ok(())
}
}
impl Scheduler {
/// Calls the openDAQ C function `daqScheduler_createScheduler()`.
pub fn new(logger: &Logger, num_workers: usize) -> Result<Scheduler> {
let mut __obj: *mut sys::daqScheduler = std::ptr::null_mut();
let __code = unsafe { (crate::sys::api().daqScheduler_createScheduler)(&mut __obj, logger.as_raw() as *mut _, num_workers) };
check(__code, "daqScheduler_createScheduler")?;
Ok(unsafe { crate::marshal::require_object::<Scheduler>(__obj as *mut _, "daqScheduler_createScheduler") }?)
}
/// Calls the openDAQ C function `daqScheduler_createSchedulerWithMainLoop()`.
pub fn with_main_loop(logger: &Logger, num_workers: usize, use_main_loop: bool) -> Result<Scheduler> {
let mut __obj: *mut sys::daqScheduler = std::ptr::null_mut();
let __code = unsafe { (crate::sys::api().daqScheduler_createSchedulerWithMainLoop)(&mut __obj, logger.as_raw() as *mut _, num_workers, u8::from(use_main_loop)) };
check(__code, "daqScheduler_createSchedulerWithMainLoop")?;
Ok(unsafe { crate::marshal::require_object::<Scheduler>(__obj as *mut _, "daqScheduler_createSchedulerWithMainLoop") }?)
}
/// Checks if the main loop is currently set.
///
/// # Returns
/// - `is_set`: Returns `true` if the main loop is set and running. This method does not gauarantee that the main loop is currently running, only that it has been set up.
///
/// Calls the openDAQ C function `daqScheduler_isMainLoopSet()`.
pub fn is_main_loop_set(&self) -> Result<bool> {
let mut __is_set: u8 = 0;
let __code = unsafe { (crate::sys::api().daqScheduler_isMainLoopSet)(self.as_raw() as *mut _, &mut __is_set) };
check(__code, "daqScheduler_isMainLoopSet")?;
Ok(__is_set != 0)
}
/// Returns whether more than one worker thread is used.
///
/// # Returns
/// - `multi_threaded`: Returns `true` if more that one worker thread is used by the scheduler.
///
/// Calls the openDAQ C function `daqScheduler_isMultiThreaded()`.
pub fn is_multi_threaded(&self) -> Result<bool> {
let mut __multi_threaded: u8 = 0;
let __code = unsafe { (crate::sys::api().daqScheduler_isMultiThreaded)(self.as_raw() as *mut _, &mut __multi_threaded) };
check(__code, "daqScheduler_isMultiThreaded")?;
Ok(__multi_threaded != 0)
}
/// Starts and blocks the main event loop, executing scheduled tasks.
///
/// # Parameters
/// - `loop_time`: The maximum time to block the loop, in milliseconds. This method runs the main loop, processing all enqueued work (including repetitive tasks) until stopMainLoop is called. Typically executed on the main thread or in a dedicated loop thread.
///
/// Calls the openDAQ C function `daqScheduler_runMainLoop()`.
pub fn run_main_loop(&self) -> Result<()> {
let __code = unsafe { (crate::sys::api().daqScheduler_runMainLoop)(self.as_raw() as *mut _, 1) };
check(__code, "daqScheduler_runMainLoop")?;
Ok(())
}
/// Starts and blocks the main event loop, executing scheduled tasks.
///
/// # Parameters
/// - `loop_time`: The maximum time to block the loop, in milliseconds. This method runs the main loop, processing all enqueued work (including repetitive tasks) until stopMainLoop is called. Typically executed on the main thread or in a dedicated loop thread.
///
/// Calls the openDAQ C function `daqScheduler_runMainLoop()`.
pub fn run_main_loop_with(&self, loop_time: usize) -> Result<()> {
let __code = unsafe { (crate::sys::api().daqScheduler_runMainLoop)(self.as_raw() as *mut _, loop_time) };
check(__code, "daqScheduler_runMainLoop")?;
Ok(())
}
/// Executes a single iteration of the main loop, processing scheduled tasks.
/// This non-blocking method runs one iteration of the main loop, executing one-time tasks
/// and advancing any repetitive tasks. Intended for cases where the main loop is polled manually,
/// such as in GUI frameworks or embedded systems.
///
/// Calls the openDAQ C function `daqScheduler_runMainLoopIteration()`.
pub fn run_main_loop_iteration(&self) -> Result<()> {
let __code = unsafe { (crate::sys::api().daqScheduler_runMainLoopIteration)(self.as_raw() as *mut _) };
check(__code, "daqScheduler_runMainLoopIteration")?;
Ok(())
}
/// Schedules the specified `work` function to run on the thread-pool. The call does not block but immediately returns an `awaitable` that represents the asynchronous execution. It can be waited upon and queried for status and result.
///
/// # Parameters
/// - `function`: The function to schedule for execution.
///
/// # Returns
/// - `awaitable`: The object representing the state and result of the execution.
///
/// # Errors
/// - `OPENDAQ_ERR_SCHEDULER_STOPPED`: when the scheduler already stopped and is not accepting any more work.
///
/// Calls the openDAQ C function `daqScheduler_scheduleFunction()`.
pub fn schedule_function(&self, function: &FunctionObject) -> Result<Option<Awaitable>> {
let mut __awaitable: *mut sys::daqAwaitable = std::ptr::null_mut();
let __code = unsafe { (crate::sys::api().daqScheduler_scheduleFunction)(self.as_raw() as *mut _, function.as_raw() as *mut _, &mut __awaitable) };
check(__code, "daqScheduler_scheduleFunction")?;
Ok(unsafe { crate::marshal::take_object::<Awaitable>(__awaitable as *mut _) })
}
/// Schedules the specified dependency `graph` to run on the thread-pool. The call does not block but immediately returns an `awaitable` that represents the asynchronous execution. It can be waited upon and queried for status and result. \<b\>Any exceptions that occur during the graph execution are silently ignored.\</b\>
///
/// # Parameters
/// - `graph`: The dependency graph (acyclic directed graph) to schedule.
///
/// # Returns
/// - `awaitable`: The object representing the state and result of the execution.
///
/// # Errors
/// - `OPENDAQ_ERR_SCHEDULER_STOPPED`: when the scheduler already stopped and is not accepting any more work.
///
/// Calls the openDAQ C function `daqScheduler_scheduleGraph()`.
pub fn schedule_graph(&self, graph: &TaskGraph) -> Result<Option<Awaitable>> {
let mut __awaitable: *mut sys::daqAwaitable = std::ptr::null_mut();
let __code = unsafe { (crate::sys::api().daqScheduler_scheduleGraph)(self.as_raw() as *mut _, graph.as_raw() as *mut _, &mut __awaitable) };
check(__code, "daqScheduler_scheduleGraph")?;
Ok(unsafe { crate::marshal::take_object::<Awaitable>(__awaitable as *mut _) })
}
/// Schedules the specified work callback to run on the thread-pool. The call does not block.
///
/// # Parameters
/// - `work`: The function to schedule for execution.
///
/// # Errors
/// - `OPENDAQ_ERR_SCHEDULER_STOPPED`: when the scheduler already stopped and is not accepting any more work. Work is a lightweight callback that returns no value and accepts no procedure. It has less overhead than function. The function does not return awaitable object.
///
/// Calls the openDAQ C function `daqScheduler_scheduleWork()`.
pub fn schedule_work(&self, work: &Work) -> Result<()> {
let __code = unsafe { (crate::sys::api().daqScheduler_scheduleWork)(self.as_raw() as *mut _, work.as_raw() as *mut _) };
check(__code, "daqScheduler_scheduleWork")?;
Ok(())
}
/// Schedules a task to be executed by the main loop.
/// The provided work object is queued for execution during a call to either
/// runMainLoop or runMainLoopIteration. This mechanism is commonly used
/// to marshal tasks from background threads to the main loop thread.
///
/// # Parameters
/// - `work`: A lightweight, non-blocking task object to be scheduled.
///
/// Calls the openDAQ C function `daqScheduler_scheduleWorkOnMainLoop()`.
pub fn schedule_work_on_main_loop(&self, work: &Work) -> Result<()> {
let __code = unsafe { (crate::sys::api().daqScheduler_scheduleWorkOnMainLoop)(self.as_raw() as *mut _, work.as_raw() as *mut _) };
check(__code, "daqScheduler_scheduleWorkOnMainLoop")?;
Ok(())
}
/// Cancels all outstanding work and waits for the remaining to complete. After this point the scheduler does not allow any new work or graphs for scheduling.
///
/// Calls the openDAQ C function `daqScheduler_stop()`.
pub fn stop(&self) -> Result<()> {
let __code = unsafe { (crate::sys::api().daqScheduler_stop)(self.as_raw() as *mut _) };
check(__code, "daqScheduler_stop")?;
Ok(())
}
/// Signals the main loop to stop processing and return from runMainLoop.
/// This method unblocks the loop and requests graceful shutdown. It is typically called
/// from another thread or in response to an application shutdown signal.
/// Has no effect if the loop is not currently running.
///
/// Calls the openDAQ C function `daqScheduler_stopMainLoop()`.
pub fn stop_main_loop(&self) -> Result<()> {
let __code = unsafe { (crate::sys::api().daqScheduler_stopMainLoop)(self.as_raw() as *mut _) };
check(__code, "daqScheduler_stopMainLoop")?;
Ok(())
}
/// Waits fo all current scheduled work and tasks to complete.
///
/// Calls the openDAQ C function `daqScheduler_waitAll()`.
pub fn wait_all(&self) -> Result<()> {
let __code = unsafe { (crate::sys::api().daqScheduler_waitAll)(self.as_raw() as *mut _) };
check(__code, "daqScheduler_waitAll")?;
Ok(())
}
}