From 614aa5efa27d0a98e5d2ee02c9f494c0a86995e8 Mon Sep 17 00:00:00 2001 From: Lena Date: Thu, 28 Mar 2024 14:41:28 +0100 Subject: [PATCH] use ServiceReference --- ctru-rs/src/services/ac.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/ctru-rs/src/services/ac.rs b/ctru-rs/src/services/ac.rs index 880dc5e..e2a08a5 100644 --- a/ctru-rs/src/services/ac.rs +++ b/ctru-rs/src/services/ac.rs @@ -3,9 +3,14 @@ //! - Connect to a network or slot //! - Get information about a network, such as its SSID or security settings use crate::error::ResultCode; - +use crate::services::ServiceReference; +use std::sync::Mutex; /// Handle to the Automatic Connection (AC) service, that handles Wi-Fi and network settings. -pub struct Ac(()); +pub struct Ac { + _service_handler: ServiceReference, +} + +static AC_ACTIVE: Mutex<()> = Mutex::new(()); impl Ac { /// Initialize a new service handle. @@ -26,10 +31,17 @@ impl Ac { /// ``` #[doc(alias = "acInit")] pub fn new() -> crate::Result { - unsafe { - ResultCode(ctru_sys::acInit())?; - Ok(Ac(())) - } + Ok(Ac { + _service_handler: ServiceReference::new(&AC_ACTIVE, + || { + ResultCode(unsafe { ctru_sys::acInit() })?; + + Ok(()) + }, + || unsafe { + ctru_sys::acExit(); + },)? + }) } /// Waits for an internet connection.