11//! Core lifecycle control for the eCAL runtime.
22//!
33//! This module provides safe Rust wrappers around initializing and finalizing
4- //! the eCAL communication system, as well as querying its state.
4+ //! the eCAL communication system, as well as querying its state and version .
55//!
66//! The main entry point is the [`Ecal`] struct which provides:
77//! - [`Ecal::initialize`] to start the middleware
88//! - [`Ecal::finalize`] to shut it down
99//! - [`Ecal::ok`] to query if eCAL is currently running
10+ //! - [`Ecal::is_initialized`] and [`Ecal::is_component_initialized`] for introspection
11+ //! - [`Ecal::version_string`], [`Ecal::version_date_string`] and [`Ecal::version_struct`] for version info
1012//!
1113//! Typically, you will call [`Ecal::initialize`] once at the beginning of your
1214//! application and [`Ecal::finalize`] at shutdown.
1315
14- use std:: ffi:: CString ;
16+ use std:: ffi:: { CStr , CString } ;
1517use crate :: components:: EcalComponents ;
16- use rustecal_sys ;
18+ use crate :: types :: Version ;
1719
18- /// Provides access to the core initialization and finalization functions of eCAL.
20+ /// Provides access to the core initialization, shutdown, and state-checking functions of eCAL.
1921pub struct Ecal ;
2022
2123impl Ecal {
2224 /// Initializes the eCAL runtime system.
2325 ///
24- /// This function must be called before using any publisher or subscriber functionality.
26+ /// This function must be called before using any publisher, subscriber, or service functionality.
2527 ///
2628 /// # Arguments
2729 ///
@@ -48,7 +50,7 @@ impl Ecal {
4850
4951 /// Finalizes and shuts down the eCAL runtime system.
5052 ///
51- /// After calling this function, all publishers and subscribers are invalidated.
53+ /// After calling this function, all publishers, subscribers, and services are invalidated.
5254 pub fn finalize ( ) {
5355 unsafe {
5456 rustecal_sys:: eCAL_Finalize ( ) ;
@@ -65,4 +67,65 @@ impl Ecal {
6567 pub fn ok ( ) -> bool {
6668 unsafe { rustecal_sys:: eCAL_Ok ( ) != 0 }
6769 }
70+
71+ /// Checks if the eCAL system has been initialized.
72+ ///
73+ /// This function checks whether any components of the middleware have been initialized.
74+ ///
75+ /// # Returns
76+ ///
77+ /// `true` if initialization has occurred, `false` otherwise.
78+ pub fn is_initialized ( ) -> bool {
79+ unsafe { rustecal_sys:: eCAL_IsInitialized ( ) != 0 }
80+ }
81+
82+ /// Checks if specific components of eCAL are initialized.
83+ ///
84+ /// This allows querying the status of individual middleware components like pub/sub, monitoring, etc.
85+ ///
86+ /// # Arguments
87+ ///
88+ /// * `components` - Bitmask of components to check.
89+ ///
90+ /// # Returns
91+ ///
92+ /// `true` if the given components are initialized, `false` otherwise.
93+ pub fn is_component_initialized ( components : EcalComponents ) -> bool {
94+ unsafe { rustecal_sys:: eCAL_IsComponentInitialized ( components. bits ( ) ) != 0 }
95+ }
96+
97+ /// Returns the version string of the eCAL runtime.
98+ ///
99+ /// # Returns
100+ ///
101+ /// A static string slice with the full version string, e.g. `"5.11.0"`.
102+ pub fn version_string ( ) -> & ' static str {
103+ unsafe {
104+ CStr :: from_ptr ( rustecal_sys:: eCAL_GetVersionString ( ) )
105+ . to_str ( )
106+ . unwrap_or ( "unknown" )
107+ }
108+ }
109+
110+ /// Returns the build date string of the eCAL runtime.
111+ ///
112+ /// # Returns
113+ ///
114+ /// A static string slice with the build date string, e.g. `"Apr 2025"`.
115+ pub fn version_date_string ( ) -> & ' static str {
116+ unsafe {
117+ CStr :: from_ptr ( rustecal_sys:: eCAL_GetVersionDateString ( ) )
118+ . to_str ( )
119+ . unwrap_or ( "unknown" )
120+ }
121+ }
122+
123+ /// Returns the version of the eCAL runtime as structured integers.
124+ ///
125+ /// # Returns
126+ ///
127+ /// A [`Version`] struct with fields `major`, `minor`, and `patch`.
128+ pub fn version_struct ( ) -> Version {
129+ unsafe { rustecal_sys:: eCAL_GetVersion ( ) . into ( ) }
130+ }
68131}
0 commit comments