From 02f53fa0cc35245a2ef63d53d4d5091a1808b889 Mon Sep 17 00:00:00 2001 From: Dhanuka Warusadura Date: Tue, 29 Oct 2024 21:59:25 +0530 Subject: [PATCH] server: Keep a ref to the connection in ServiceManager This removes the connection attribute from Service. And add object_server() Signed-off-by: Dhanuka Warusadura --- server/src/service.rs | 5 +---- server/src/service_manager.rs | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/server/src/service.rs b/server/src/service.rs index b9286475..76d58405 100644 --- a/server/src/service.rs +++ b/server/src/service.rs @@ -27,8 +27,6 @@ pub struct Service { collections: Arc>>, // Other attributes manager: Arc>, - #[allow(unused)] - connection: zbus::Connection, } #[zbus::interface(name = "org.freedesktop.Secret.Service")] @@ -206,8 +204,7 @@ impl Service { let object_server = connection.object_server(); let service = Self { collections: Default::default(), - manager: Default::default(), - connection: connection.clone(), + manager: Arc::new(Mutex::new(ServiceManager::new(connection.clone()))), }; object_server diff --git a/server/src/service_manager.rs b/server/src/service_manager.rs index c8fff5fb..c2a0d061 100644 --- a/server/src/service_manager.rs +++ b/server/src/service_manager.rs @@ -2,17 +2,29 @@ use std::{collections::HashMap, sync::Arc}; -use zbus::zvariant::OwnedObjectPath; +use zbus::{zvariant::OwnedObjectPath, Connection}; use crate::session::Session; -#[derive(Debug, Default)] +#[derive(Debug)] pub struct ServiceManager { + connection: Connection, // sessions mapped to their corresponding object path on the bus sessions: HashMap>, } impl ServiceManager { + pub fn new(connection: Connection) -> Self { + Self { + sessions: Default::default(), + connection, + } + } + + pub fn object_server(&self) -> &zbus::ObjectServer { + self.connection.object_server() + } + pub fn n_sessions(&self) -> usize { self.sessions.len() }