use super::worker::WorkerSettings;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
pub enum ExportTransfer {
#[default]
FullData,
FinalPicture,
}
impl ExportTransfer {
#[must_use]
pub const fn index(self) -> i32 {
match self {
Self::FullData => 0,
Self::FinalPicture => 1,
}
}
#[must_use]
pub const fn from_index(index: i32) -> Self {
if index == 1 {
Self::FinalPicture
} else {
Self::FullData
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
pub enum TiltVideoCompute {
Local,
Remote,
#[default]
Both,
}
impl TiltVideoCompute {
#[must_use]
pub const fn index(self) -> i32 {
match self {
Self::Local => 0,
Self::Remote => 1,
Self::Both => 2,
}
}
#[must_use]
pub const fn from_index(index: i32) -> Self {
match index {
0 => Self::Local,
1 => Self::Remote,
_ => Self::Both,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
pub enum LiveTransfer {
#[default]
FullData,
FinalPicture,
}
impl LiveTransfer {
#[must_use]
pub const fn index(self) -> i32 {
match self {
Self::FullData => 0,
Self::FinalPicture => 1,
}
}
#[must_use]
pub const fn from_index(index: i32) -> Self {
if index == 1 {
Self::FinalPicture
} else {
Self::FullData
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(default)]
pub struct RemoteEndpoint {
pub connection: WorkerSettings,
pub export_transfer: ExportTransfer,
pub live_transfer: LiveTransfer,
}
impl RemoteEndpoint {
#[must_use]
pub fn new(connection: WorkerSettings) -> Self {
Self {
connection,
..Self::default()
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LegacyWorkerMigration {
pub kept: Option<String>,
pub dropped: Vec<String>,
}
pub fn migrate_legacy_workers(
legacy: &mut Vec<WorkerSettings>,
remote: &mut Option<RemoteEndpoint>,
) -> Option<LegacyWorkerMigration> {
if legacy.is_empty() {
return None;
}
let mut entries = std::mem::take(legacy).into_iter();
let first = entries.next()?;
let mut dropped: Vec<String> = entries.map(|w| w.address).collect();
let kept = if remote.is_some() {
dropped.insert(0, first.address);
None
} else {
let address = first.address.clone();
*remote = Some(RemoteEndpoint::new(first));
Some(address)
};
if let Some(address) = &kept {
tracing::info!(
"settings: migrated the remote-worker list to a single remote endpoint ({address})"
);
}
if !dropped.is_empty() {
tracing::warn!(
"settings: only one remote endpoint is supported now; dropped {} older \
worker entr{}: {}",
dropped.len(),
if dropped.len() == 1 { "y" } else { "ies" },
dropped.join(", ")
);
}
Some(LegacyWorkerMigration { kept, dropped })
}