Skip to main content

ghpascon_rust/devices/printer/sato/
ws4.rs

1use std::collections::HashMap;
2use std::ops::Deref;
3
4use serde_json::Value;
5
6use super::config::SatoConfig;
7use super::sato::SatoPrinter;
8use super::transport::SharedEventHandler;
9
10pub struct SatoWs4Printer(pub SatoPrinter);
11
12impl Deref for SatoWs4Printer {
13    type Target = SatoPrinter;
14    fn deref(&self) -> &Self::Target {
15        &self.0
16    }
17}
18
19impl Clone for SatoWs4Printer {
20    fn clone(&self) -> Self {
21        Self(self.0.clone())
22    }
23}
24
25impl SatoWs4Printer {
26    pub fn new(config: SatoConfig) -> Self {
27        Self(SatoPrinter::new(config))
28    }
29
30    pub fn from_map(data: HashMap<String, Value>) -> Self {
31        Self(SatoPrinter::from_map(data))
32    }
33
34    pub fn is_connected(&self) -> bool {
35        self.0.is_connected()
36    }
37
38    pub fn can_print(&self) -> bool {
39        self.0.can_print()
40    }
41
42    pub fn pending_print_jobs(&self) -> usize {
43        self.0.pending_print_jobs()
44    }
45
46    pub fn connect_instruction(&self) -> String {
47        self.0.connect_instruction()
48    }
49
50    pub fn to_map(&self) -> HashMap<String, Value> {
51        self.0.to_map()
52    }
53
54    pub fn set_event_handler(&mut self, handler: SharedEventHandler) {
55        self.0.set_event_handler(handler)
56    }
57
58    pub async fn print(&self, zpl: &str) -> Result<String, String> {
59        self.0.print(zpl).await
60    }
61}
62
63impl Default for SatoWs4Printer {
64    fn default() -> Self {
65        let mut config = SatoConfig::default();
66        config.ip = "192.168.1.102".to_string();
67        config.name = "SATO_WS4".to_string();
68        Self::new(config)
69    }
70}