stateset_embedded/
print_stations.rs1use stateset_core::{
4 CreatePrintStation, EnqueuePrintJob, PairStationResult, PrintJob, PrintJobFilter, PrintJobId,
5 PrintStation, PrintStationId, Result,
6};
7use stateset_db::{Database, DatabaseCapability};
8use std::sync::Arc;
9
10pub struct PrintStations {
12 db: Arc<dyn Database>,
13}
14
15impl std::fmt::Debug for PrintStations {
16 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17 f.debug_struct("PrintStations").finish_non_exhaustive()
18 }
19}
20
21impl PrintStations {
22 pub(crate) fn new(db: Arc<dyn Database>) -> Self {
23 Self { db }
24 }
25
26 #[must_use]
28 pub fn is_supported(&self) -> bool {
29 self.db.supports_capability(DatabaseCapability::PrintStations)
30 }
31
32 fn ensure(&self) -> Result<()> {
33 self.db.ensure_capability(DatabaseCapability::PrintStations)
34 }
35
36 pub fn pair(&self, input: CreatePrintStation) -> Result<PairStationResult> {
38 self.ensure()?;
39 self.db.print_stations().pair(input)
40 }
41
42 pub fn list_stations(&self) -> Result<Vec<PrintStation>> {
44 self.ensure()?;
45 self.db.print_stations().list_stations()
46 }
47
48 pub fn get_station(&self, id: PrintStationId) -> Result<Option<PrintStation>> {
50 self.ensure()?;
51 self.db.print_stations().get_station(id)
52 }
53
54 pub fn revoke_station(&self, id: PrintStationId) -> Result<PrintStation> {
56 self.ensure()?;
57 self.db.print_stations().revoke_station(id)
58 }
59
60 pub fn enqueue_job(
62 &self,
63 station_id: PrintStationId,
64 input: EnqueuePrintJob,
65 ) -> Result<PrintJob> {
66 self.ensure()?;
67 self.db.print_stations().enqueue_job(station_id, input)
68 }
69
70 pub fn next_job(&self, station_id: PrintStationId) -> Result<Option<PrintJob>> {
72 self.ensure()?;
73 self.db.print_stations().next_job(station_id)
74 }
75
76 pub fn complete_job(&self, job_id: PrintJobId, success: bool) -> Result<PrintJob> {
78 self.ensure()?;
79 self.db.print_stations().complete_job(job_id, success)
80 }
81
82 pub fn list_jobs(
84 &self,
85 station_id: PrintStationId,
86 filter: PrintJobFilter,
87 ) -> Result<Vec<PrintJob>> {
88 self.ensure()?;
89 self.db.print_stations().list_jobs(station_id, filter)
90 }
91}