Skip to main content

smcp_server_core/
lib.rs

1//! SMCP 服务器核心库 / SMCP server core library
2//!
3//! 提供基于 socketioxide + Tokio 的 SMCP 协议服务器实现
4//! Provides SMCP protocol server implementation based on socketioxide + Tokio
5
6pub mod auth;
7pub mod handler;
8pub mod server;
9pub mod session;
10
11// 重新导出主要类型
12pub use auth::{AuthError, AuthenticationProvider, DefaultAuthenticationProvider};
13pub use handler::{HandlerError, ServerState, SmcpHandler};
14pub use server::{SmcpServerBuilder, SmcpServerLayer};
15pub use session::{ClientRole, SessionData, SessionError, SessionManager, SessionStats};
16
17/// SMCP 服务器预lude
18/// SMCP server prelude
19pub mod prelude {
20    pub use crate::auth::*;
21    pub use crate::handler::*;
22    pub use crate::server::*;
23    pub use crate::session::*;
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29
30    #[test]
31    fn test_library_imports() {
32        // 确保所有主要类型都可以正确导入
33        let _builder: SmcpServerBuilder = SmcpServerBuilder::new();
34        let _manager: SessionManager = SessionManager::new();
35    }
36
37    #[test]
38    fn test_smcp_crate_api_is_executed() {
39        let req_id = smcp::ReqId::new();
40        assert!(!req_id.as_str().is_empty());
41
42        let role_json = serde_json::to_string(&smcp::Role::Agent).unwrap();
43        assert_eq!(role_json, "\"agent\"");
44
45        let n = smcp::Notification::EnterOffice(smcp::EnterOfficeNotification {
46            office_id: "office1".to_string(),
47            computer: Some("c1".to_string()),
48            agent: None,
49        });
50        let json = serde_json::to_string(&n).unwrap();
51        let de: smcp::Notification = serde_json::from_str(&json).unwrap();
52        match de {
53            smcp::Notification::EnterOffice(p) => {
54                assert_eq!(p.office_id, "office1");
55                assert_eq!(p.computer.as_deref(), Some("c1"));
56                assert!(p.agent.is_none());
57            }
58            _ => panic!("unexpected notification"),
59        }
60    }
61}