first pass at xpc impl
This commit is contained in:
38
kordophoned/src/xpc/agent.rs
Normal file
38
kordophoned/src/xpc/agent.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
use crate::daemon::{events::Event, signals::Signal, DaemonResult};
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::{mpsc, oneshot, Mutex};
|
||||
|
||||
/// XPC IPC agent that forwards daemon events and signals over libxpc.
|
||||
#[derive(Clone)]
|
||||
pub struct XpcAgent {
|
||||
event_sink: mpsc::Sender<Event>,
|
||||
signal_receiver: Arc<Mutex<Option<mpsc::Receiver<Signal>>>>,
|
||||
}
|
||||
|
||||
impl XpcAgent {
|
||||
/// Create a new XPC agent with an event sink and signal receiver.
|
||||
pub fn new(event_sink: mpsc::Sender<Event>, signal_receiver: mpsc::Receiver<Signal>) -> Self {
|
||||
Self {
|
||||
event_sink,
|
||||
signal_receiver: Arc::new(Mutex::new(Some(signal_receiver))),
|
||||
}
|
||||
}
|
||||
|
||||
/// Run the XPC agent: perform a basic GetVersion IPC call to the daemon and print the result.
|
||||
pub async fn run(self) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// Send an event to the daemon and await its reply.
|
||||
pub async fn send_event<T>(
|
||||
&self,
|
||||
make_event: impl FnOnce(crate::daemon::events::Reply<T>) -> Event,
|
||||
) -> DaemonResult<T> {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
self.event_sink
|
||||
.send(make_event(tx))
|
||||
.await
|
||||
.map_err(|_| "Failed to send event")?;
|
||||
rx.await.map_err(|_| "Failed to receive reply".into())
|
||||
}
|
||||
}
|
||||
27
kordophoned/src/xpc/endpoint.rs
Normal file
27
kordophoned/src/xpc/endpoint.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
#![cfg(target_os = "macos")]
|
||||
//! XPC registry for registering handlers and emitting signals.
|
||||
|
||||
/// Registry for XPC message handlers and signal emission.
|
||||
pub struct XpcRegistry;
|
||||
|
||||
impl XpcRegistry {
|
||||
/// Create a new XPC registry for the service.
|
||||
pub fn new() -> Self {
|
||||
XpcRegistry
|
||||
}
|
||||
|
||||
/// Register a handler for incoming messages at a given endpoint.
|
||||
pub fn register_handler<F>(&self, _name: &str, _handler: F)
|
||||
where
|
||||
F: Fn(&[u8]) -> Vec<u8> + Send + Sync + 'static,
|
||||
{
|
||||
// TODO: Implement handler registration over libxpc using SERVICE_NAME
|
||||
let _ = (_name, _handler);
|
||||
}
|
||||
|
||||
/// Send a signal (notification) to connected clients.
|
||||
pub fn send_signal<T: serde::Serialize>(&self, _signal: &str, _data: &T) {
|
||||
// TODO: Serialize and send signal over XPC
|
||||
let _ = (_signal, _data);
|
||||
}
|
||||
}
|
||||
8
kordophoned/src/xpc/interface.rs
Normal file
8
kordophoned/src/xpc/interface.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
#![cfg(target_os = "macos")]
|
||||
//! XPC interface definitions for macOS IPC
|
||||
|
||||
/// Mach service name for the XPC interface (must include trailing NUL).
|
||||
pub const SERVICE_NAME: &str = "net.buzzert.kordophonecd\0";
|
||||
|
||||
/// Method names for the XPC interface (must include trailing NUL).
|
||||
pub const GET_VERSION_METHOD: &str = "GetVersion\0";
|
||||
6
kordophoned/src/xpc/mod.rs
Normal file
6
kordophoned/src/xpc/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
#![cfg(target_os = "macos")]
|
||||
//! macOS XPC IPC interface modules.
|
||||
|
||||
pub mod agent;
|
||||
pub mod endpoint;
|
||||
pub mod interface;
|
||||
Reference in New Issue
Block a user