@@ -7,12 +7,13 @@ use std::sync::LazyLock;
77
88use dlopen2:: wrapper:: { Container , WrapperApi } ;
99
10- use crate :: errors:: LVInteropError ;
10+ use crate :: errors:: { LVInteropError , MgError } ;
1111use crate :: {
1212 errors:: { InternalError , Result } ,
1313 memory:: MagicCookie ,
1414 types:: LVStatusCode ,
1515} ;
16+ use crate :: memory:: UPtr ;
1617
1718/// The path to the LabVIEW runtime library.
1819/// Set as const, so we can swap this for different platforms if required.
@@ -44,7 +45,7 @@ pub(crate) type UHandleValue = usize;
4445/// Represents as UPtr passed by value. Can't use the generic
4546/// version from the memory module else since the functions
4647/// aren't generic.
47- pub ( crate ) type UPtrValue = usize ;
48+ pub ( crate ) type UPtrValue = * mut c_void ;
4849
4950static SYNC_API : LazyLock < Result < Container < SyncApi > > > = LazyLock :: new ( load_container) ;
5051
@@ -68,6 +69,19 @@ pub fn memory_api() -> Result<&'static Container<MemoryApi>> {
6869 MEMORY_API . as_ref ( ) . map_err ( |e| e. clone ( ) )
6970}
7071
72+ static COOKIE_API : LazyLock < Result < Container < CookieApi > > > = LazyLock :: new ( || {
73+ let result = load_container :: < CookieApi > ( ) ;
74+
75+ if let Err ( e) = & result {
76+ eprintln ! ( "Failed to load LabVIEW Cookie API: {e}" ) ;
77+ }
78+ result
79+ } ) ;
80+
81+ pub fn cookie_api ( ) -> Result < & ' static Container < CookieApi > > {
82+ COOKIE_API . as_ref ( ) . map_err ( |e| e. clone ( ) )
83+ }
84+
7185/// The LabVIEW synchronisation features are part of the Support Manager API.
7286///
7387/// The [official documentation](https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/properties-and-methods/lv-manager/support-manager-functions.html) for the Support Manager can be found (last verified 2024-jul-09) on the webpage of National Instruments.
@@ -140,6 +154,34 @@ pub struct MemoryApi {
140154 /// `DSNewHClr` is an alternative that also initialized the memory to zero.
141155 #[ dlopen2_name = "DSNewHandle" ]
142156 new_handle : unsafe extern "C" fn ( size : usize ) -> * mut * mut std:: ffi:: c_void ,
157+
158+ /// UPtr DSNewPtr(size);
159+ ///
160+ /// Creates a new pointer to a non-relocatable block of memory of the specified size.
161+ ///
162+ /// ```C
163+ /// UPtr DSNewPtr(size_t size);
164+ /// ```
165+ ///
166+ /// - `size`: `size_t`, Size, in bytes, of the pointer you want to create.
167+ ///
168+ /// Return Value
169+ ///
170+ /// A pointer to a block of size bytes. If an error occurs, this function returns NULL.
171+ #[ dlopen2_name = "DSNewPtr" ]
172+ new_ptr : unsafe extern "C" fn ( size : usize ) -> UPtrValue ,
173+
174+ /// Release the memory referenced by the specified pointer.
175+ ///
176+ /// ```C
177+ /// MgErr DsDisposePtr(p)
178+ /// ```
179+ ///
180+ /// - `p`: `UPtr` Pointer you wish to dispose of.
181+ ///
182+ /// Returns `MgErr`: Either `noErr` or `mZoneErr`.
183+ #[ dlopen2_name = "DSDisposePtr" ]
184+ dispose_ptr : unsafe extern "C" fn ( p : UPtrValue ) -> LVStatusCode ,
143185
144186 /// Copies the data referenced by the handle hsrc into the handle pointed to by ph or a new handle if ph points to NULL.
145187 ///
@@ -244,3 +286,38 @@ pub struct MemoryApi {
244286 total_new_size : usize ,
245287 ) -> LVStatusCode ,
246288}
289+
290+ pub type CookieJar = * mut * mut std:: ffi:: c_void ;
291+ pub struct CookieInfo ;
292+ pub type Bool32 = i32 ;
293+ // Cleanup modes enum
294+ #[ repr( i32 ) ]
295+ enum CleanupMode {
296+ CleanRemove = 0 ,
297+ CleanExit = 1 ,
298+ CleanOnIdle = 2 ,
299+ CleanAfterReset = 3 ,
300+ CleanOnIdleIfNotTop = 4 ,
301+ CleanAfterResetIfNotTop = 5 ,
302+ }
303+ type CleanupProcPtr = extern "C" fn ( usize ) -> i32 ;
304+
305+ #[ derive( WrapperApi ) ]
306+ pub struct CookieApi {
307+ #[ dlopen2_name = "MCNewBigJar" ]
308+ new_big_jar : unsafe extern "C" fn ( item_size : i32 ) -> CookieJar ,
309+ #[ dlopen2_name = "MCDisposeJar" ]
310+ dispose_jar : unsafe extern "C" fn ( jar : CookieJar ) -> MgError ,
311+ #[ dlopen2_name = "MCNewCookie" ]
312+ new_cookie : unsafe extern "C" fn ( jar : CookieJar , info : UPtrValue ) -> MagicCookie ,
313+ #[ dlopen2_name = "MCDisposeCookie" ]
314+ dispose_cookie : unsafe extern "C" fn ( jar : CookieJar , cookie : MagicCookie , info : UPtrValue ) -> LVStatusCode ,
315+ #[ dlopen2_name = "MCGetCookieInfo" ]
316+ get_cookie_info : unsafe extern "C" fn ( jar : CookieJar , cookie : MagicCookie , info : UPtrValue ) -> LVStatusCode ,
317+ #[ dlopen2_name = "MCGetCookieInfoPtr" ]
318+ get_cookie_info_ptr : unsafe extern "C" fn ( jar : CookieJar , cookie : MagicCookie , info : * mut UPtrValue ) -> LVStatusCode ,
319+ #[ dlopen2_name = "MCIsACookie" ]
320+ is_a_cookie : unsafe extern "C" fn ( jar : CookieJar , cookie : MagicCookie ) -> Bool32 ,
321+ #[ dlopen2_name = "RTSetCleanupProc" ]
322+ rt_set_cleanup_proc : unsafe extern "C" fn ( proc : CleanupProcPtr , data_uptr : UPtrValue , cleanup_mode : CleanupMode ) -> LVStatusCode ,
323+ }
0 commit comments