archivist_lib/logs/servers/
log_settings.rsuse crate::logs::error::LogsError;
use crate::logs::repository::LogsRepository;
use fidl::endpoints::{ControlHandle, DiscoverableProtocolMarker};
use futures::StreamExt;
use std::sync::Arc;
use tracing::warn;
use {fidl_fuchsia_diagnostics as fdiagnostics, fuchsia_async as fasync};
pub struct LogSettingsServer {
logs_repo: Arc<LogsRepository>,
scope: fasync::Scope,
}
impl LogSettingsServer {
pub fn new(logs_repo: Arc<LogsRepository>, scope: fasync::Scope) -> Self {
Self { logs_repo, scope }
}
pub fn spawn(&self, stream: fdiagnostics::LogSettingsRequestStream) {
let logs_repo = Arc::clone(&self.logs_repo);
self.scope.spawn(async move {
if let Err(e) = Self::handle_requests(logs_repo, stream).await {
warn!("error handling Log requests: {}", e);
}
});
}
pub async fn handle_requests(
logs_repo: Arc<LogsRepository>,
mut stream: fdiagnostics::LogSettingsRequestStream,
) -> Result<(), LogsError> {
let connection_id = logs_repo.new_interest_connection();
while let Some(request) = stream.next().await {
let request = request.map_err(|source| LogsError::HandlingRequests {
protocol: fdiagnostics::LogSettingsMarker::PROTOCOL_NAME,
source,
})?;
match request {
fdiagnostics::LogSettingsRequest::RegisterInterest { control_handle, .. } => {
warn!("fuchsia.diagnostics/LogSettings.RegisterInterest is not supported; closing the channel");
control_handle.shutdown();
}
fdiagnostics::LogSettingsRequest::SetInterest { selectors, responder } => {
logs_repo.update_logs_interest(connection_id, selectors);
responder.send().ok();
}
}
}
logs_repo.finish_interest_connection(connection_id);
Ok(())
}
}