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 27, 2024
1 parent 999268b commit 7d37184
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
8 changes: 8 additions & 0 deletions server/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,12 @@ impl Collection {
pub fn path(&self) -> &OwnedObjectPath {
&self.path
}

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()
}
}
56 changes: 51 additions & 5 deletions server/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,62 @@ 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 collection.alias().await == name {
tracing::info!(
"Collection: {} found for alias: {}",
collection.path(),
name
);
return Ok(collection.path().clone());
}
}

tracing::info!("Collection: does not exist for alias: {}", name);

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,
)))
}

#[zbus(property, name = "Collections")]
Expand Down

0 comments on commit 7d37184

Please sign in to comment.