use pinweaver_storage_api::{
util::{DeserializeExact, ForwardTipcSerialize},
StorageInterface, StorageRequest, StorageResponse,
}; use std::sync::{Arc, Mutex, MutexGuard}; use tipc::{Handle, TipcError, UnbufferedService, MAX_MSG_HANDLES}; use trusty_std::alloc::FallibleVec; use trusty_sys::Error;
type Response = DeserializeExact<StorageResponse>; const MAX_MESSAGE_SIZE: usize = <Response as tipc::Deserialize>::MAX_SERIALIZED_SIZE;
/// The service that initializes the given `StorageClient` upon connection. /// /// This is a tipc server: the storage daemon running in Android connects to /// this service, acting as a tipc client. The connection remains open while /// the main service sends commands to the storage daemon through the /// `StorageClient`. pub(crate) struct StorageClientService {
client: Arc<StorageClient>,
}
#[derive(Default)] pub(crate) struct StorageClient { /// Initialized by the [`StorageClientService`].
server_handle: Mutex<Option<Handle>>,
}
impl StorageClient { /// Locks the mutex or returns an error. fn lock(&self) -> tipc::Result<MutexGuard<'_, Option<Handle>>> { self.server_handle.lock().map_err(|_| TipcError::SystemError(Error::BadState))
}
/// Sets the server handle for this storage client. /// /// Clones the handle to send messages, if a storage daemon hasn't already connected. pubfn set_server_handle(&self, handle: &Handle) -> tipc::Result<()> { match &mut *self.lock()? {
Some(_) => Err(TipcError::SystemError(Error::AlreadyExists)),
server_handle @ None => {
*server_handle = Some(handle.try_clone()?);
Ok(())
}
}
}
/// Clears the current server handle for this storage client. /// /// Ignores whether there is currently a handle set. pubfn clear_server_handle(&self) { iflet Ok(mut handle) = self.lock() {
*handle = None;
}
}
}
impl StorageInterface for StorageClient { type Error = tipc::TipcError;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.