Skip to main content

Module ipc

Module ipc 

Source
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§

ActionDeprecated
Defines an action that can be executed on a servelet.
BaseModuleHandler
A simple base implementation of ModuleHandler that can be extended.
BroadcastSender
A sender for broadcasting messages to the server from any task.
CommandMessage
CommandMessage is the unified message format for all IPC communication.
CommandMessageResultDeprecated
The result portion of a CommandMessage.
FramedStream
A framed TCP stream for IPC communication.
IpcClient
IPC Client for external modules.
IpcClientBuilder
Builder for IpcClient with fluent configuration.
IpcClientConfig
Configuration for the IPC client.
IpcMessageHeader
Header for IPC messages, used for framing on the wire.
IpcServer
IPC Server that accepts connections from external modules.
IpcServerConfig
Configuration for the IPC server.
IpcTransport
Thread-safe wrapper around FramedStream for concurrent access.
ModuleArgs
Parsed command-line arguments common to all external modules.
ModuleConnection
Represents a connected module.
ModuleRegistration
Registration message sent by module when connecting to server.
RouteContext
Context passed to route handlers.
RouteMatch
Result of route matching.
SplitTransport
Split transport for separate read/write tasks.
TopicRouter
Router for dispatching messages to handlers based on topic.
TopicRouterBuilder
Builder for TopicRouter with fluent API.

Enums§

ControlType
Control message subtypes for initialization, finalization, etc.
IpcError
Errors that can occur during IPC operations.
MessageType
Message types for IPC communication.
ServerEvent
Events emitted by the server.

Traits§

ModuleHandler
The ModuleHandler trait defines the interface that external modules implement to process IPC messages from autocore-server.
ModuleHandlerExt
Extension trait for ModuleHandler that provides IPC-specific message handling.
RouteHandler
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