Skip to content

Commit

Permalink
server: Keep a ref to the connection in ServiceManager
Browse files Browse the repository at this point in the history
This removes the connection attribute from Service.
And add object_server()

Signed-off-by: Dhanuka Warusadura <dhanuka@gnome.org>
  • Loading branch information
warusadura committed Oct 29, 2024
1 parent 6456c60 commit 02f53fa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
5 changes: 1 addition & 4 deletions server/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ pub struct Service {
collections: Arc<Mutex<Vec<OwnedObjectPath>>>,
// Other attributes
manager: Arc<Mutex<ServiceManager>>,
#[allow(unused)]
connection: zbus::Connection,
}

#[zbus::interface(name = "org.freedesktop.Secret.Service")]
Expand Down Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions server/src/service_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<OwnedObjectPath, Arc<Session>>,
}

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()
}
Expand Down

0 comments on commit 02f53fa

Please sign in to comment.