taiga_plugin_api/daemon/mod.rs
1//! Daemon infrastructure for plugin development
2//!
3//! This module provides utilities for creating daemon-based plugins with IPC communication.
4//! It offers three levels of abstraction:
5//!
6//! 1. **Low-level utilities** (`socket`, `ipc`) - Direct control over sockets and IPC
7//! 2. **Mid-level client helper** (`client`) - Automatic retry-with-autospawn pattern
8//! 3. **High-level traits** (`traits`) - Structured daemon framework
9//!
10//! # Example: Using the client helper
11//!
12//! ```rust,ignore
13//! use taiga_plugin_api::daemon::{
14//! client::{DaemonClientConfig, send_command_with_autospawn},
15//! ipc::DaemonSpawnConfig,
16//! };
17//! use serde::{Serialize, Deserialize};
18//!
19//! #[derive(Serialize)]
20//! struct MyCommand { action: String }
21//!
22//! #[derive(Deserialize)]
23//! struct MyResponse { result: String }
24//!
25//! async fn send_command() -> Result<MyResponse, PluginError> {
26//! let config = DaemonClientConfig::new(
27//! "/tmp/my-plugin.sock",
28//! DaemonSpawnConfig::new("my-plugin", "daemon"),
29//! );
30//!
31//! let cmd = MyCommand { action: "test".into() };
32//! send_command_with_autospawn(&config, &cmd).await
33//! }
34//! ```
35//!
36//! # Example: Using the daemon framework
37//!
38//! ```rust,ignore
39//! use taiga_plugin_api::daemon::traits::{DaemonHandler, DaemonConfig, HandleResult, run_daemon_loop};
40//! use async_trait::async_trait;
41//!
42//! struct MyDaemon { counter: u32 }
43//!
44//! #[async_trait]
45//! impl DaemonHandler for MyDaemon {
46//! type Command = MyCommand;
47//! type Response = MyResponse;
48//!
49//! async fn handle_command(&mut self, cmd: Self::Command) -> HandleResult<Self::Response> {
50//! HandleResult::response(MyResponse::Ok)
51//! }
52//! }
53//!
54//! // Run the daemon:
55//! run_daemon_loop(DaemonConfig::new("/tmp/my.sock"), MyDaemon { counter: 0 }).await?;
56//! ```
57
58pub mod socket;
59pub mod ipc;
60pub mod client;
61pub mod traits;
62
63// Re-export commonly used types
64pub use socket::{create_listener, connect, cleanup_socket};
65pub use ipc::{send_message, receive_message, spawn_daemon_process, DaemonSpawnConfig};
66pub use client::{send_command_with_autospawn, DaemonClientConfig};
67pub use traits::{DaemonHandler, DaemonConfig, HandleResult, run_daemon_loop};