Expand description
IPC module for CommandMessage-based communication between autocore-server and external modules. Provides ModuleHandler trait (analogous to AsyncServelet), TCP transport with length-prefix framing, and TopicRouter for message dispatch.
§IPC Module
This module provides infrastructure for CommandMessage-based IPC communication between autocore-server and external modules over TCP sockets.
§Key Components
- [
CommandMessage] - Unified message type for all IPC communication - [
MessageType] - Enum defining the semantic meaning of messages - [
ModuleHandler] - Trait that external modules implement (analogous to AsyncServelet) - [
IpcClient] - Client for external modules to connect to autocore-server - [
IpcServer] - Server-side listener for incoming module connections - [
TopicRouter] - Helper for routing messages to callbacks based on topic patterns
§Example: External Module
ⓘ
use mechutil::ipc::{ModuleHandler, IpcClient, CommandMessage, MessageType};
use async_trait::async_trait;
struct MyModule {
// module state
}
#[async_trait]
impl ModuleHandler for MyModule {
async fn handle_message(&mut self, msg: CommandMessage) -> CommandMessage {
// Process the message and return response
msg.into_response(serde_json::json!({"status": "ok"}))
}
async fn on_initialize(&mut self) -> Result<(), anyhow::Error> {
Ok(())
}
async fn on_finalize(&mut self) -> Result<(), anyhow::Error> {
Ok(())
}
fn domain(&self) -> &str {
"mymodule"
}
}
#[tokio::main]
async fn main() {
let module = MyModule {};
let client = IpcClient::connect("127.0.0.1:9100", module).await.unwrap();
client.run().await;
}Structs§
- Action
Deprecated - Defines an action that can be executed on a servelet.
- Base
Module Handler - A simple base implementation of ModuleHandler that can be extended.
- Broadcast
Sender - A sender for broadcasting messages to the server from any task.
- Command
Message - CommandMessage is the unified message format for all IPC communication.
- Command
Message Result Deprecated - The result portion of a CommandMessage.
- Framed
Stream - A framed TCP stream for IPC communication.
- IpcClient
- IPC Client for external modules.
- IpcClient
Builder - Builder for IpcClient with fluent configuration.
- IpcClient
Config - Configuration for the IPC client.
- IpcMessage
Header - Header for IPC messages, used for framing on the wire.
- IpcServer
- IPC Server that accepts connections from external modules.
- IpcServer
Config - Configuration for the IPC server.
- IpcTransport
- Thread-safe wrapper around FramedStream for concurrent access.
- Module
Args - Parsed command-line arguments common to all external modules.
- Module
Connection - Represents a connected module.
- Module
Registration - Registration message sent by module when connecting to server.
- Route
Context - Context passed to route handlers.
- Route
Match - Result of route matching.
- Split
Transport - Split transport for separate read/write tasks.
- Topic
Router - Router for dispatching messages to handlers based on topic.
- Topic
Router Builder - Builder for TopicRouter with fluent API.
Enums§
- Control
Type - Control message subtypes for initialization, finalization, etc.
- IpcError
- Errors that can occur during IPC operations.
- Message
Type - Message types for IPC communication.
- Server
Event - Events emitted by the server.
Traits§
- Module
Handler - The ModuleHandler trait defines the interface that external modules implement to process IPC messages from autocore-server.
- Module
Handler Ext - Extension trait for ModuleHandler that provides IPC-specific message handling.
- Route
Handler - Trait for route handler functions.
Functions§
- current_
timecode - Get the current timestamp in milliseconds since UNIX epoch
- handle_
module_ connection - Handle a module connection in a dedicated task.
- next_
transaction_ id - Generate a unique transaction ID