75 lines
2.2 KiB
Rust
75 lines
2.2 KiB
Rust
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::{audio_engine::jack_ab::JackAudioBackend, control_pane::ControlPane};
|
|
|
|
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();
|
|
let jack = JackAudioBackend::new();
|
|
if jack.feature_jack {
|
|
response.backends.push(Backend {
|
|
name: "jack".to_string(),
|
|
});
|
|
}
|
|
Ok(Response::new(response))
|
|
}
|
|
}
|