Trying to come up with the structure
This commit is contained in:
26
engine/src/audio_engine/jack_ab.rs
Normal file
26
engine/src/audio_engine/jack_ab.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use crate::audio_engine::AudioBackend;
|
||||
|
||||
pub(crate) struct JackAudioBackend {
|
||||
pub(crate) name: String,
|
||||
pub(crate) running: bool,
|
||||
}
|
||||
|
||||
impl JackAudioBackend {
|
||||
pub(crate) fn new(name: String, running: bool) -> Self {
|
||||
Self { name, running }
|
||||
}
|
||||
}
|
||||
|
||||
impl AudioBackend for JackAudioBackend {
|
||||
fn start_client(&self) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn init_client(&self) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn discover(&self) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
mod jack;
|
||||
mod coreaudio;
|
||||
#[cfg(feature = "jack")]
|
||||
pub(crate) mod jack_ab;
|
||||
|
||||
trait AudioBackend {
|
||||
pub(crate) trait AudioBackend {
|
||||
// Start a audio backend client
|
||||
// It should be executed either on the startup,
|
||||
// or when the audio backend is switched
|
||||
fn start_client();
|
||||
fn start_client(&self);
|
||||
// Initialization of the client should happen
|
||||
// when a project is opened.
|
||||
fn init_client();
|
||||
fn init_client(&self);
|
||||
fn discover(&self);
|
||||
}
|
||||
|
||||
9
engine/src/control_pane/dummy.rs
Normal file
9
engine/src/control_pane/dummy.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
use crate::control_pane::ControlPane;
|
||||
|
||||
struct Dummy {}
|
||||
|
||||
impl ControlPane for Dummy {
|
||||
async fn start_server(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
76
engine/src/control_pane/grpc/mod.rs
Normal file
76
engine/src/control_pane/grpc/mod.rs
Normal 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))
|
||||
}
|
||||
}
|
||||
6
engine/src/control_pane/mod.rs
Normal file
6
engine/src/control_pane/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
pub(crate) mod dummy;
|
||||
pub(crate) mod grpc;
|
||||
|
||||
pub(crate) trait ControlPane {
|
||||
async fn start_server(&self) -> Result<(), Box<dyn std::error::Error>>;
|
||||
}
|
||||
@@ -1,58 +1,29 @@
|
||||
mod audio_engine;
|
||||
pub(crate) mod audio_engine;
|
||||
pub(crate) mod control_pane;
|
||||
|
||||
use crate::control_pane::ControlPane;
|
||||
use clap::Parser;
|
||||
use lib::termix::audio_backend::{Backend, BackendList, FILE_DESCRIPTOR_SET, audio_backend_server::{AudioBackend, AudioBackendServer}};
|
||||
use tonic::{Request, Response, Result, Status, transport::Server};
|
||||
use log::{debug, error, log_enabled, info, Level};
|
||||
use tonic_reflection::server::v1::{ReflectionService, ServerReflection};
|
||||
|
||||
/// Simple program to greet a person
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
struct Args {
|
||||
#[arg(long, default_value_t = 50051)]
|
||||
grpc_port: i32,
|
||||
#[arg(long, default_value_t = true)]
|
||||
grpc_enable_reflections: bool,
|
||||
}
|
||||
|
||||
#[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") {
|
||||
response.backends.push(Backend{ name: "jack".to_string() });
|
||||
}
|
||||
Ok(Response::new(response))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
env_logger::init();
|
||||
let args = Args::parse();
|
||||
// start_grpc_server()
|
||||
info!("starting the grpc server on port {}", args.grpc_port);
|
||||
let reflections = tonic_reflection::server::Builder::configure().register_encoded_file_descriptor_set(FILE_DESCRIPTOR_SET).build_v1().unwrap();
|
||||
let addr = "[::1]:50051".parse()?;
|
||||
let greeter = TermixAudioBackend::default();
|
||||
|
||||
Server::builder()
|
||||
.add_service(AudioBackendServer::new(greeter))
|
||||
.add_service(reflections)
|
||||
.serve(addr)
|
||||
.await?;
|
||||
let grpc_control_pane = control_pane::grpc::Grpc {
|
||||
port: args.grpc_port,
|
||||
enable_reflections: args.grpc_enable_reflections,
|
||||
};
|
||||
grpc_control_pane.start_server().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user