mod emulator;
mod exchange;
mod ops;
mod plan;
mod run;
#[cfg(test)]
mod tests;
use exchange::*;
use ops::*;
use run::*;
pub use exchange::{Exchange, Failure, Transcript};
pub use ops::{
BACKUP_MARGIN, BACKUP_NO_ROOM, BACKUP_VARIABLE, Op, REPLACE_VARIABLE, SCREEN_VARIABLE,
TEXT_VARIABLE, Target, may_serve, store_bytes, trim_fetched,
};
pub use run::{STOPPED, Transfer};
use std::collections::VecDeque;
use kermit_proto::time::Duration;
use kermit_proto::{Client, Command, Config, Event, OutgoingFile};
use saturnus_core::io::Key;
use saturnus_core::{Machine, Model};
use saturnus_objects::transfer::{self as tfile, is_plain_name};
use saturnus_objects::{
Flags, Graphic, ObjectType, UserMemory, Variable, charset, cmdline, prolog,
};
use crate::typing::{Job, Verb};
use crate::wire::{
FINISH_SETTLE, IDLE_WAIT, Line, MIN_WAIT, RETRIES, SERVER_CAP, TIMEOUT, Wire, WireStep, cycles,
};
pub const MAX_FILE_BYTES: usize = 512 * 1024;
pub(super) const STABLE_MS: u64 = 300;
pub(super) const IDLE_CAP_MS: u64 = 10_000;
pub(super) const ON_HOLD_MS: u64 = 100;
pub(super) const PROBE_TIMEOUT: Duration = Duration::from_secs(5);
pub(super) const PROBE_RETRIES: u32 = 1;
pub(super) const PROBE_CAP_MS: u64 = 15_000;
pub(super) const ASK_TIMEOUT: Duration = Duration::from_secs(2);
pub(super) const ASK_CAP_MS: u64 = 6_000;
pub(super) const END_ROUNDS: usize = 2;
pub(super) const DROP_GAP_MS: u64 = 100;
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TransferResult {
pub emulated_ms: f64,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub size: Option<usize>,
pub keys: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub server: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub error: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub free: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub needed: Option<f64>,
}
#[derive(Clone, Debug)]
pub(super) enum Step {
Type(String),
TypeCleanup(String),
WaitNak,
Host { text: String, cleanup: bool },
Send { name: String, data: Vec<u8> },
Get { name: String, text: bool },
Free { needed: f64, refusal: String },
Unarchive,
Push { text: String },
Compile { text: String },
Finish,
Settle,
DropTo(usize),
Algebraic,
CancelLine,
Ask { end: bool },
EndServer,
}
impl Step {
pub(super) fn cleanup(&self) -> bool {
match self {
Step::Host { cleanup, .. } => *cleanup,
Step::Finish
| Step::Settle
| Step::DropTo(_)
| Step::Algebraic
| Step::CancelLine
| Step::Unarchive
| Step::TypeCleanup(_)
| Step::EndServer => true,
_ => false,
}
}
pub(super) fn after_server(&self) -> bool {
matches!(self, Step::Algebraic | Step::DropTo(_))
}
}