Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: Add ReadAlias and SetAlias implementation #146

Merged
merged 2 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions client/src/dbus/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ pub enum ServiceError {
/// ZBus specific error.
ZBus(zbus::Error),
/// Collection/Item is locked.
IsLocked,
IsLocked(String),
/// Session does not exist.
NoSession,
NoSession(String),
/// Collection/Item does not exist.
NoSuchObject,
NoSuchObject(String),
warusadura marked this conversation as resolved.
Show resolved Hide resolved
}

/// DBus backend specific errors.
Expand Down
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());
}
}

warusadura marked this conversation as resolved.
Show resolved Hide resolved
tracing::info!("Collection with alias {} does not exist.", 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