use serde::{Deserialize, Serialize};
use zbus::zvariant::{OwnedObjectPath, OwnedValue, Type, Value};
use crate::{enum_impl_serde_str, enum_impl_str_conv, impl_value_conversions_as_str};
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Type)]
pub enum UnitType {
Service,
Mount,
Swap,
Socket,
Target,
Device,
Automount,
Timer,
Path,
Slice,
Scope,
}
enum_impl_str_conv!(UnitType, {
"service": Service,
"mount": Mount,
"swap": Swap,
"socket": Socket,
"target": Target,
"device": Device,
"automount": Automount,
"timer": Timer,
"path": Path,
"slice": Slice,
"scope": Scope,
});
enum_impl_serde_str!(UnitType);
impl_value_conversions_as_str!(UnitType);
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Type, Serialize, Deserialize)]
pub enum UnitFileFlags {
Runtime,
Force,
Portable,
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Type)]
#[zvariant(signature = "s")]
pub enum Mode {
Replace,
Fail,
Isolate,
IgnoreDependencies,
IgnoreRequirements,
}
enum_impl_str_conv!(Mode, {
"replace": Replace,
"fail": Fail,
"isolate": Isolate,
"ignore-dependencies": IgnoreDependencies,
"ignore-requirements": IgnoreRequirements,
});
enum_impl_serde_str!(Mode);
impl_value_conversions_as_str!(Mode);
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Type)]
#[zvariant(signature = "s")]
pub enum LoadState {
Stub,
Loaded,
NotFound,
BadSetting,
Error,
Merged,
Masked,
}
enum_impl_str_conv!(LoadState, {
"stub": Stub,
"loaded": Loaded,
"not-found": NotFound,
"bad-setting": BadSetting,
"error": Error,
"merged": Merged,
"masked": Masked,
});
enum_impl_serde_str!(LoadState);
impl_value_conversions_as_str!(LoadState);
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Type)]
#[zvariant(signature = "s")]
pub enum ActiveState {
Active,
Reloading,
Inactive,
Failed,
Activating,
Deactivating,
Maintenance,
}
enum_impl_str_conv!(ActiveState, {
"active": Active,
"reloading": Reloading,
"inactive": Inactive,
"failed": Failed,
"activating": Activating,
"deactivating": Deactivating,
"maintenance" : Maintenance,
});
enum_impl_serde_str!(ActiveState);
impl_value_conversions_as_str!(ActiveState);
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Type)]
#[zvariant(signature = "s")]
pub enum UnitFileState {
Enabled,
EnabledRuntime,
Linked,
LinkedRuntime,
Masked,
MaskedRuntime,
Static,
Disabled,
Invalid,
}
enum_impl_str_conv!(UnitFileState, {
"enabled": Enabled,
"enabled-runtime": EnabledRuntime,
"linked": Linked,
"linked-runtime": LinkedRuntime,
"masked": Masked,
"masked-runtime": MaskedRuntime,
"static": Static,
"disabled": Disabled,
"invalid": Invalid,
});
enum_impl_serde_str!(UnitFileState);
impl_value_conversions_as_str!(UnitFileState);
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Type)]
#[zvariant(signature = "s")]
pub enum SubState {
Dead,
Waiting,
Running,
Failed,
Tentative,
Plugged,
Mounting,
MountingDone,
Mounted,
Remounting,
Unmounting,
RemountingSigterm,
RemountingSigkill,
UnmountingSigterm,
UnmountingSigkill,
Cleaning,
Abandoned,
StopSigterm,
StopSigkill,
Condition,
StartPre,
Start,
StartPost,
Exited,
Reload,
Stop,
StopWatchdog,
StopPost,
FinalWatchdog,
FinalSigterm,
FinalSigkill,
AutoRestart,
AutoRestartQueued,
Active,
StartChown,
Listening,
StopPre,
StopPreSigterm,
StopPreSigkill,
Activating,
ActivatingDone,
Deactivating,
DeactivatingSigterm,
DeactivatingSigkill,
Elapsed,
}
enum_impl_str_conv!(SubState, {
"dead": Dead,
"waiting": Waiting,
"running": Running,
"failed": Failed,
"tentative": Tentative,
"plugged": Plugged,
"mounting": Mounting,
"mounting-done": MountingDone,
"mounted": Mounted,
"remounting": Remounting,
"unmounting": Unmounting,
"remounting-sigterm": RemountingSigterm,
"remounting-sigkill": RemountingSigkill,
"unmounting-sigterm": UnmountingSigterm,
"unmounting-sigkill": UnmountingSigkill,
"cleaning": Cleaning,
"abandoned": Abandoned,
"stop-sigterm": StopSigterm,
"stop-sigkill": StopSigkill,
"condition": Condition,
"start-pre": StartPre,
"start": Start,
"start-post": StartPost,
"exited": Exited,
"reload": Reload,
"stop": Stop,
"stop-watchdog": StopWatchdog,
"stop-post": StopPost,
"final-watchdog": FinalWatchdog,
"final-sigterm": FinalSigterm,
"final-sigkill": FinalSigkill,
"auto-restart": AutoRestart,
"auto-restart-queued": AutoRestartQueued,
"active": Active,
"start-chown": StartChown,
"listening": Listening,
"stop-pre": StopPre,
"stop-pre-sigterm": StopPreSigterm,
"stop-pre-sigkill": StopPreSigkill,
"activating": Activating,
"activating-done": ActivatingDone,
"deactivating": Deactivating,
"deactivating-sigterm": DeactivatingSigterm,
"deactivating-sigkill": DeactivatingSigkill,
"elapsed": Elapsed,
});
enum_impl_serde_str!(SubState);
impl_value_conversions_as_str!(SubState);
#[derive(Debug, PartialEq, Eq, Clone, Type, Serialize, Deserialize)]
pub struct Unit {
pub name: String,
pub description: String,
pub load: LoadState,
pub active: ActiveState,
pub sub_state: SubState,
pub followed_unit: String,
pub path: OwnedObjectPath,
pub queued_job: u32,
pub job_type: String,
pub job_path: OwnedObjectPath,
}
#[derive(Debug, PartialEq, Eq, Clone, Type, Serialize, Deserialize)]
pub struct Job {
pub job_id: u32,
pub unit_name: String,
pub job_type: JobType,
pub job_state: JobState,
pub job_path: OwnedObjectPath,
pub unit_path: OwnedObjectPath,
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Type)]
#[zvariant(signature = "s")]
pub enum JobType {
Start,
VerifyActive,
Stop,
Reload,
Restart,
TryRestart,
ReloadOrStart,
}
enum_impl_str_conv!(JobType, {
"start": Start,
"verify-active": VerifyActive,
"stop": Stop,
"reload": Reload,
"restart": Restart,
"try-restart": TryRestart,
"reload-or-start": ReloadOrStart,
});
enum_impl_serde_str!(JobType);
impl_value_conversions_as_str!(JobType);
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Type)]
#[zvariant(signature = "s")]
pub enum JobState {
Waiting,
Running,
}
enum_impl_str_conv!(JobState, {
"waiting": Waiting,
"running": Running,
});
enum_impl_serde_str!(JobState);
impl_value_conversions_as_str!(JobState);
#[derive(Debug, PartialEq, Eq, Clone, Type, Serialize, Deserialize)]
pub struct EnquedJob {
pub job_id: u32,
pub job_path: OwnedObjectPath,
pub unit_name: String,
pub unit_path: OwnedObjectPath,
pub job_type: String,
}
#[derive(Debug, PartialEq, Eq, Clone, Type, Serialize, Deserialize)]
pub struct EnqueJob {
pub job: EnquedJob,
pub affected_jobs: Vec<EnquedJob>,
}
#[derive(Debug, PartialEq, Eq, Clone, Type, Serialize, Deserialize, Value, OwnedValue)]
pub struct KeyValue<K, V>
where
K: Type,
V: Type,
{
pub key: K,
pub value: V,
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Type)]
#[zvariant(signature = "s")]
pub enum ChangeType {
Symlink,
Unlink,
}
enum_impl_str_conv!(ChangeType, {
"symlink": Symlink,
"unlink": Unlink,
});
enum_impl_serde_str!(ChangeType);
impl_value_conversions_as_str!(ChangeType);
#[derive(Debug, PartialEq, Eq, Clone, Type, Serialize, Deserialize)]
pub struct Change {
change_type: ChangeType,
symlink_file: String,
symlink_dest: String,
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Type)]
#[zvariant(signature = "s")]
pub enum PathWatchCondition {
Exists,
ExistsGlob,
Changed,
Modified,
DirectoryNotEmpty,
}
enum_impl_str_conv!(PathWatchCondition, {
"PathExists": Exists,
"PathExistsGlob": ExistsGlob,
"PathChanged": Changed,
"PathModified": Modified,
"PathDirectoryNotEmpty": DirectoryNotEmpty,
});
enum_impl_serde_str!(PathWatchCondition);
impl_value_conversions_as_str!(PathWatchCondition);
#[derive(Debug, PartialEq, Eq, Clone, Type, Serialize, Deserialize, Value, OwnedValue)]
pub struct PathWatch {
pub condition: String,
pub path: String,
}
#[derive(Debug, PartialEq, Eq, Clone, Type, Serialize, Deserialize, Value, OwnedValue)]
pub struct Exec {
pub binary_path: String,
pub arguments: Vec<String>,
pub is_failure: bool,
pub last_start_realtime_us: u64,
pub last_start_monotonic_us: u64,
pub last_exit_realtime_us: u64,
pub last_exit_monotonic_us: u64,
pub pid: u32,
pub last_exit_code: i32,
pub last_status: i32,
}
#[derive(Debug, PartialEq, Eq, Clone, Type, Serialize, Deserialize, Value, OwnedValue)]
pub struct ExecEx {
pub binary_path: String,
pub arguments: Vec<String>,
pub options: Vec<String>,
pub last_start_realtime_us: u64,
pub last_start_monotonic_us: u64,
pub last_exit_realtime_us: u64,
pub last_exit_monotonic_us: u64,
pub pid: u32,
pub last_exit_code: i32,
pub last_status: i32,
}
#[derive(Debug, PartialEq, Eq, Clone, Type, Serialize, Deserialize, Value, OwnedValue)]
pub struct TimerCalendar {
pub base: String,
pub calendar_spec: String,
pub next_elapse_realtime_usec: u64,
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Type)]
#[zvariant(signature = "s")]
pub enum TimerCalendarBase {
OnCalendar,
}
enum_impl_str_conv!(TimerCalendarBase, {
"OnCalendar": OnCalendar,
});
enum_impl_serde_str!(TimerCalendarBase);
impl_value_conversions_as_str!(TimerCalendarBase);
#[derive(Debug, PartialEq, Eq, Clone, Type, Serialize, Deserialize, Value, OwnedValue)]
pub struct TimerMonotonic {
pub base: String,
pub offset_usec: u64,
pub next_elapse_realtime_usec: u64,
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Type)]
#[zvariant(signature = "s")]
pub enum TimerMonotonicBase {
OnActiveUSec,
OnBootUSec,
OnStartupUSec,
OnUnitActiveUSec,
OnUnitInactiveUSec,
}
enum_impl_str_conv!(TimerMonotonicBase, {
"OnActiveUSec": OnActiveUSec,
"OnBootUSec": OnBootUSec,
"OnStartupUSec": OnStartupUSec,
"OnUnitActiveUSec": OnUnitActiveUSec,
"OnUnitInactiveUSec": OnUnitInactiveUSec,
});
enum_impl_serde_str!(TimerMonotonicBase);
impl_value_conversions_as_str!(TimerMonotonicBase);
pub const BIND_MOUNT_RECURSIVE: u64 = 0x4000;
#[derive(Debug, PartialEq, Eq, Clone, Type, Serialize, Deserialize, Value, OwnedValue)]
pub struct BindMount {
pub source: String,
pub destination: String,
pub ignore_non_existing: bool,
pub options: u64,
}
#[derive(Debug, PartialEq, Eq, Clone, Type, Serialize, Deserialize, Value, OwnedValue)]
pub struct Process {
pub cgroup_controller: String,
pub pid: u32,
pub command_line: String,
}
#[derive(Debug, PartialEq, Eq, Clone, Type, Serialize, Deserialize, Value, OwnedValue)]
pub struct DirectorySymlink {
pub target_path: String,
pub symlink_path: String,
pub flags: u64,
}
#[derive(Debug, PartialEq, Eq, Clone, Type, Serialize, Deserialize, Value, OwnedValue)]
pub struct MountImage {
pub image_path: String,
pub mount_point: String,
pub ignore_non_existing: bool,
pub mount_options: Vec<PartitionMountOptions>,
}
#[derive(Debug, PartialEq, Eq, Clone, Type, Serialize, Deserialize, Value, OwnedValue)]
pub struct PartitionMountOptions {
pub partition: String,
pub mount_options: String,
}
#[derive(Debug, PartialEq, Eq, Clone, Type, Serialize, Deserialize, Value, OwnedValue)]
pub struct ExtensionImage {
pub image_path: String,
pub ignore_non_existing: bool,
pub mount_options: Vec<PartitionMountOptions>,
}