Trying to come up with the structure
Some checks failed
ci/woodpecker/push/code_tests Pipeline failed
ci/woodpecker/push/pre_commit_test Pipeline was successful

This commit is contained in:
Nikolai Rodionov
2025-12-01 14:35:28 +01:00
parent dcb6d7b0ea
commit af97801d31
10 changed files with 138 additions and 48 deletions

View File

@@ -0,0 +1,76 @@
use lib::termix::audio_backend::{
self, Backend, BackendList, FILE_DESCRIPTOR_SET,
audio_backend_server::{AudioBackend, AudioBackendServer},
};
use log::info;
use tonic::{Response, transport::Server};
use tonic_reflection::server;
use crate::control_pane::ControlPane;
#[cfg(feature = "jack") ]
use crate::audio_engine::jack_ab::JackAudioBackend;
pub(crate) struct Grpc {
pub(crate) port: i32,
pub(crate) enable_reflections: bool,
}
impl ControlPane for Grpc {
async fn start_server(&self) -> Result<(), Box<dyn std::error::Error>> {
info!("starting the grpc server on port {}", self.port);
// TODO: Use the port from self
let addr = "[::1]:50051".parse()?;
let mut server = Server::builder();
let audio_backend_reflections = server::Builder::configure()
.register_encoded_file_descriptor_set(FILE_DESCRIPTOR_SET)
.build_v1()
.unwrap();
let audio_backend = TermixAudioBackend::default();
server
.add_service(audio_backend_reflections)
.add_service(AudioBackendServer::new(audio_backend))
.serve(addr)
.await?;
Ok(())
}
}
#[derive(Debug, Default)]
pub struct TermixAudioBackend {}
#[tonic::async_trait]
impl AudioBackend for TermixAudioBackend {
async fn start_client(
&self,
requesa: tonic::Request<()>,
) -> std::result::Result<tonic::Response<()>, tonic::Status> {
info!("starting the audio backend client");
todo!()
}
async fn init_connection(
&self,
request: tonic::Request<()>,
) -> std::result::Result<tonic::Response<()>, tonic::Status> {
info!("initializing the connection to the audio backend");
todo!()
}
async fn get_available_backends(
&self,
request: tonic::Request<()>,
) -> Result<Response<BackendList>, tonic::Status> {
info!("discovering available backends");
let mut response = BackendList::default();
if cfg!(feature = "jack") {
let jack = JackAudioBackend{ name: "jack".to_string(), running: todo!() };
response.backends.push(Backend {
name: "jack".to_string(),
});
}
Ok(Response::new(response))
}
}