model.rs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. use async_std::sync::Mutex;
  2. use fxhash::{FxHashMap, FxHashSet};
  3. use serde::{Deserialize, Serialize};
  4. #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Hash)]
  5. pub enum Session {
  6. Inbound,
  7. Outbound,
  8. Manual,
  9. }
  10. #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Hash)]
  11. pub enum SelectableObject {
  12. Node(NodeInfo),
  13. Session(SessionInfo),
  14. Connect(ConnectInfo),
  15. }
  16. pub struct Model {
  17. pub ids: Mutex<FxHashSet<String>>,
  18. pub infos: Mutex<FxHashMap<String, SelectableObject>>,
  19. }
  20. impl Model {
  21. pub fn new(
  22. ids: Mutex<FxHashSet<String>>,
  23. infos: Mutex<FxHashMap<String, SelectableObject>>,
  24. ) -> Model {
  25. Model { ids, infos }
  26. }
  27. }
  28. #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Hash)]
  29. pub struct NodeInfo {
  30. pub node_id: String,
  31. pub node_name: String,
  32. pub children: Vec<SessionInfo>,
  33. }
  34. impl NodeInfo {
  35. pub fn new(node_id: String, node_name: String, children: Vec<SessionInfo>) -> NodeInfo {
  36. NodeInfo { node_id, node_name, children }
  37. }
  38. }
  39. #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Hash)]
  40. pub struct SessionInfo {
  41. pub session_id: String,
  42. pub parent: String,
  43. pub children: Vec<ConnectInfo>,
  44. }
  45. impl SessionInfo {
  46. pub fn new(session_id: String, parent: String, children: Vec<ConnectInfo>) -> SessionInfo {
  47. SessionInfo { session_id, parent, children }
  48. }
  49. }
  50. #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Hash)]
  51. pub struct ConnectInfo {
  52. pub connect_id: String,
  53. pub addr: String,
  54. pub is_empty: bool,
  55. pub last_msg: String,
  56. pub last_status: String,
  57. pub state: String,
  58. pub msg_log: Vec<String>,
  59. pub parent: String,
  60. }
  61. impl ConnectInfo {
  62. pub fn new(
  63. connect_id: String,
  64. addr: String,
  65. is_empty: bool,
  66. last_msg: String,
  67. last_status: String,
  68. state: String,
  69. msg_log: Vec<String>,
  70. parent: String,
  71. ) -> ConnectInfo {
  72. ConnectInfo { connect_id, addr, is_empty, last_msg, last_status, state, msg_log, parent }
  73. }
  74. }