Skip to main content

egui_pop_api/bus/
job_rows.rs

1//! An application's rows in the jobs list, on the bus (ADR 0029): its
2//! **row sources** ([`egui_pop_model::job_rows`]).
3//!
4//! A source is declared, and its rows replaced, by asking
5//! `pop.jobs.rows` ([`JobRowsSet`], a [`JobRowsAsk`]: the source's id,
6//! title, owner and every row it has now); it goes, its rows with it, by
7//! asking `pop.jobs.source.drop` ([`JobSourceDrop`]). The jobs plugin's
8//! listener ([`SOURCES`]) keeps them for the list; both may be asked from
9//! any thread on the bus the application holds. A plugin disconnected
10//! takes the sources it owns with it.
11
12use bus_contract::{Point, PointId, PointKind};
13use egui_pop_model::job_rows::JobRow;
14use serde::{Deserialize, Serialize};
15
16/// A source's rows, asked: the source, its title (the filter's label),
17/// who asks, and every row it has now (the set replaces the last one).
18#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
19#[non_exhaustive]
20pub struct JobRowsAsk {
21    pub source: String,
22    pub title: String,
23    /// Who asks: a plugin's id, a module's.
24    pub owner: String,
25    pub rows: Vec<JobRow>,
26}
27
28impl JobRowsAsk {
29    pub fn new(
30        source: impl Into<String>,
31        title: impl Into<String>,
32        owner: impl Into<String>,
33        rows: Vec<JobRow>,
34    ) -> Self {
35        Self {
36            source: source.into(),
37            title: title.into(),
38            owner: owner.into(),
39            rows,
40        }
41    }
42}
43
44/// A source taken away: which, and who asks.
45#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
46#[non_exhaustive]
47pub struct JobSourceAsk {
48    pub source: String,
49    pub owner: String,
50}
51
52impl JobSourceAsk {
53    pub fn new(source: impl Into<String>, owner: impl Into<String>) -> Self {
54        Self {
55            source: source.into(),
56            owner: owner.into(),
57        }
58    }
59}
60
61/// A source's rows are asked (`pop.jobs.rows`); its listeners say what
62/// they did, one line each, in the value.
63#[derive(Debug)]
64pub struct JobRowsSet;
65impl Point for JobRowsSet {
66    const KIND: PointKind = PointKind::Request;
67    const ID: PointId = PointId::new("pop.jobs.rows");
68    type Input = JobRowsAsk;
69    type Value = Vec<String>;
70}
71
72/// A source is taken away (`pop.jobs.source.drop`).
73#[derive(Debug)]
74pub struct JobSourceDrop;
75impl Point for JobSourceDrop {
76    const KIND: PointKind = PointKind::Request;
77    const ID: PointId = PointId::new("pop.jobs.source.drop");
78    type Input = JobSourceAsk;
79    type Value = Vec<String>;
80}
81
82/// The row source points, in the order [`super::order_dump`] prints them.
83pub const JOB_ROW_POINTS: [&str; 2] = [JobRowsSet::ID.as_str(), JobSourceDrop::ID.as_str()];
84
85/// The jobs plugin's listener of the row source points: keeps each
86/// source's rows for the list.
87pub const SOURCES: &str = "pop.jobs.sources";