qualia_app_contract/
adapter.rs1use crate::descriptor::Availability;
4use crate::error::ContractError;
5use crate::gesture::{GestureCancel, GestureCommit, GestureSession, GestureUpdate};
6use crate::id::{CommandId, DecimalU64};
7use crate::request::{AppSessionDescriptor, CommandReceipt, CommandRequest, JobDescriptor};
8use crate::target::CommandTarget;
9
10pub trait AppAdapter: Send + Sync {
15 fn describe(&self) -> Result<AppSessionDescriptor, ContractError>;
17
18 fn open(&mut self, _document_id: &str, _open_mode: &str) -> Result<DecimalU64, ContractError> {
20 Ok(DecimalU64(0))
21 }
22
23 fn availability(&self, _target: &CommandTarget, _command_id: &CommandId) -> Availability {
25 Availability::Available
26 }
27
28 fn inspect(&self, _target: &CommandTarget) -> Result<serde_json::Value, ContractError> {
30 Ok(serde_json::Value::Null)
31 }
32
33 fn execute(&mut self, request: &CommandRequest) -> Result<CommandReceipt, ContractError>;
35
36 fn begin_gesture(&mut self, _session: &GestureSession) -> Result<(), ContractError> {
38 Err(ContractError::GesturesUnsupported("gestures unsupported".into()))
39 }
40
41 fn update_gesture(&mut self, _update: &GestureUpdate) -> Result<(), ContractError> {
43 Err(ContractError::GesturesUnsupported("gestures unsupported".into()))
44 }
45
46 fn commit_gesture(&mut self, _commit: &GestureCommit) -> Result<CommandReceipt, ContractError> {
48 Err(ContractError::GesturesUnsupported("gestures unsupported".into()))
49 }
50
51 fn cancel_gesture(&mut self, _cancel: &GestureCancel) -> Result<(), ContractError> {
53 Err(ContractError::GesturesUnsupported("gestures unsupported".into()))
54 }
55
56 fn snapshot(&self) -> Result<Vec<u8>, ContractError> {
58 Ok(Vec::new())
59 }
60
61 fn restore(&mut self, _snapshot_bytes: &[u8]) -> Result<(), ContractError> {
63 Ok(())
64 }
65
66 fn poll_job(&self, job_id: &str) -> Result<JobDescriptor, ContractError> {
68 Err(ContractError::InvalidIdentifier(format!("job {job_id} not found")))
69 }
70
71 fn cancel_job(&mut self, _job_id: &str) -> Result<(), ContractError> {
73 Ok(())
74 }
75
76 fn close(&mut self) -> Result<(), ContractError> {
78 Ok(())
79 }
80}