Skip to content

Commit

Permalink
server: Add ReadAlias and SetAlias implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Dhanuka Warusadura <dhanuka@gnome.org>
  • Loading branch information
warusadura committed Oct 25, 2024
1 parent d69da2f commit 6993b47
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 5 deletions.
12 changes: 12 additions & 0 deletions server/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,16 @@ impl Collection {
pub fn path(&self) -> &OwnedObjectPath {
&self.path
}

pub async fn label(&self) -> String {
self.label.lock().await.clone()
}

pub async fn set_alias(&self, alias: &str) {
*self.alias.lock().await = alias.to_owned();
}

pub async fn alias(&self) -> String {
self.alias.lock().await.clone()
}
}
54 changes: 49 additions & 5 deletions server/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,60 @@ impl Service {
}

#[zbus(out_args("collection"))]
pub async fn read_alias(&self, _name: &str) -> Result<ObjectPath, ServiceError> {
todo!()
pub async fn read_alias(
&self,
name: &str,
#[zbus(object_server)] object_server: &zbus::ObjectServer,
) -> Result<OwnedObjectPath, ServiceError> {
let collections = self.collections.lock().await;

for collection in collections.iter() {
let collection_ifce_ref = object_server.interface::<_, Collection>(collection).await?;
let collection = collection_ifce_ref.get_mut().await;

if name == "login" {
// To support login alias lookup
if collection.label().await == name {
return Ok(collection.path().clone());
}
} else if collection.alias().await == name {
return Ok(collection.path().clone());
}
}

Ok(OwnedObjectPath::default())
}

pub async fn set_alias(
&self,
_name: &str,
_collection: ObjectPath<'_>,
name: &str,
collection: OwnedObjectPath,
#[zbus(object_server)] object_server: &zbus::ObjectServer,
) -> Result<(), ServiceError> {
todo!()
let collections = self.collections.lock().await;

for path in collections.iter() {
if path == &collection {
let collection_ifce_ref = object_server.interface::<_, Collection>(path).await?;
let collection = collection_ifce_ref.get_mut().await;

collection.set_alias(name).await;

tracing::info!(
"Collection: {} alias updated to {}.",
collection.path(),
name
);
return Ok(());
}
}

tracing::info!("Collection: {} does not exist.", collection);

Err(ServiceError::NoSuchObject(format!(
"The collection: {} does not exist.",
collection,
)))
}
}

Expand Down

0 comments on commit 6993b47

Please sign in to comment.