1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//
// Copyright (C) 2024 - 2025 Automated Design Corp. All Rights Reserved.
//
// IPC Module for CommandMessage-based communication between autocore-server
// and external modules. Provides a unified interface for both internal and
// external module development.
//
//! # 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
//!
//! ```ignore
//! 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;
//! }
//! ```
// Core message types - CommandMessage is the primary type
pub use ;
// Legacy types (deprecated) - kept for backward compatibility during transition
pub use ;
// Wire format and control types
pub use ;
// Handler trait
pub use ;
// Transport layer
pub use ;
// Client (for external modules)
pub use ;
// Server (for autocore-server)
pub use ;
// Routing
pub use ;
// CLI argument parsing
pub use ModuleArgs;
// Errors
pub use IpcError;
// Command definitions
pub use ;