1use facet::Facet;
2
3use crate::{BacktraceId, EntityId, Json, PTime, next_entity_id};
4
5#[derive(Facet)]
8pub struct Entity {
9 pub id: EntityId,
11
12 pub birth: PTime,
14
15 #[facet(skip_unless_truthy)]
18 pub removed_at: Option<PTime>,
19
20 pub backtrace: BacktraceId,
22
23 pub name: String,
25
26 pub body: EntityBody,
28}
29
30impl Entity {
31 pub fn new(backtrace: BacktraceId, name: impl Into<String>, body: EntityBody) -> Entity {
33 Entity {
34 id: next_entity_id(),
35 birth: PTime::now(),
36 removed_at: None,
37 backtrace,
38 name: name.into(),
39 body,
40 }
41 }
42}
43
44crate::define_entity_body! {
46 pub enum EntityBody {
47 Future(FutureEntity),
49 Lock(LockEntity),
50 MpscTx(MpscTxEntity),
51 MpscRx(MpscRxEntity),
52 BroadcastTx(BroadcastTxEntity),
53 BroadcastRx(BroadcastRxEntity),
54 WatchTx(WatchTxEntity),
55 WatchRx(WatchRxEntity),
56 OneshotTx(OneshotTxEntity),
57 OneshotRx(OneshotRxEntity),
58 Semaphore(SemaphoreEntity),
59 Notify(NotifyEntity),
60 OnceCell(OnceCellEntity),
61
62 Command(CommandEntity),
64 FileOp(FileOpEntity),
65
66 NetConnect(NetConnectEntity),
68 NetAccept(NetAcceptEntity),
69 NetRead(NetReadEntity),
70 NetWrite(NetWriteEntity),
71
72 Request(RequestEntity),
74 Response(ResponseEntity),
75
76 Custom(CustomEntity),
78
79 Aether(AetherEntity),
81 }
82}
83
84#[derive(Facet, Default)]
85pub struct FutureEntity {
86 #[facet(skip_unless_truthy)]
90 pub skip_entry_frames: Option<u8>,
91}
92
93#[derive(Facet)]
94pub struct LockEntity {
95 pub kind: LockKind,
97}
98
99#[derive(Facet)]
100#[repr(u8)]
101#[facet(rename_all = "snake_case")]
102pub enum LockKind {
103 Mutex,
104 RwLock,
105 Other,
106}
107
108#[derive(Facet)]
109pub struct MpscTxEntity {
110 pub queue_len: u32,
112 pub capacity: Option<u32>,
114}
115
116#[derive(Facet, Clone, Copy, Debug, PartialEq, Eq)]
117pub struct MpscRxEntity {}
118
119#[derive(Facet)]
120pub struct BroadcastTxEntity {
121 pub capacity: u32,
122}
123
124#[derive(Facet)]
125pub struct BroadcastRxEntity {
126 pub lag: u32,
127}
128
129#[derive(Facet)]
130pub struct WatchTxEntity {
131 pub last_update_at: Option<PTime>,
132}
133
134#[derive(Facet)]
135pub struct WatchRxEntity {}
136
137#[derive(Facet)]
138pub struct OneshotTxEntity {
139 pub sent: bool,
140}
141
142#[derive(Facet, Clone, Copy, Debug, PartialEq, Eq)]
143pub struct OneshotRxEntity {}
144
145#[derive(Facet)]
146pub struct SemaphoreEntity {
147 pub max_permits: u32,
149 pub handed_out_permits: u32,
151}
152
153#[derive(Facet)]
154pub struct NotifyEntity {
155 pub waiter_count: u32,
157}
158
159#[derive(Facet)]
160pub struct OnceCellEntity {
161 pub waiter_count: u32,
163 pub state: OnceCellState,
165}
166
167#[derive(Facet, Clone, Copy, Debug, PartialEq, Eq)]
168#[repr(u8)]
169#[facet(rename_all = "snake_case")]
170pub enum OnceCellState {
171 Empty,
172 Initializing,
173 Initialized,
174}
175
176#[derive(Facet)]
177pub struct CommandEntity {
178 pub program: String,
180 pub args: Vec<String>,
182 pub env: Vec<String>,
184}
185
186#[derive(Facet)]
187pub struct FileOpEntity {
188 pub op: FileOpKind,
190 pub path: String,
192}
193
194#[derive(Facet)]
195#[repr(u8)]
196#[facet(rename_all = "snake_case")]
197pub enum FileOpKind {
198 Open,
199 Read,
200 Write,
201 Sync,
202 Metadata,
203 Remove,
204 Rename,
205 Other,
206}
207
208#[derive(Facet)]
209pub struct NetConnectEntity {
210 pub addr: String,
212}
213
214#[derive(Facet)]
215pub struct NetAcceptEntity {
216 pub addr: String,
218}
219
220#[derive(Facet)]
221pub struct NetReadEntity {
222 pub addr: String,
224}
225
226#[derive(Facet)]
227pub struct NetWriteEntity {
228 pub addr: String,
230}
231
232#[derive(Facet)]
235pub struct RequestEntity {
236 pub service_name: String,
240 pub method_name: String,
244 pub args_json: Json,
248}
249
250#[derive(Facet)]
251pub struct ResponseEntity {
252 pub service_name: String,
254 pub method_name: String,
256 pub status: ResponseStatus,
258}
259
260#[derive(Facet, Clone, Debug, PartialEq, Eq)]
261#[repr(u8)]
262#[facet(rename_all = "snake_case")]
263pub enum ResponseStatus {
264 Pending,
266 Ok(Json),
268 Error(ResponseError),
270 Cancelled,
272}
273
274#[derive(Facet, Clone, Debug, PartialEq, Eq)]
275#[repr(u8)]
276#[facet(rename_all = "snake_case")]
277pub enum ResponseError {
278 Internal(String),
280 UserJson(Json),
282}
283
284#[derive(Facet)]
289pub struct CustomEntity {
290 pub kind: String,
292 pub display_name: String,
294 pub category: String,
296 pub icon: String,
298 pub attrs: Json,
300}
301
302#[derive(Facet)]
308pub struct AetherEntity {
309 pub task_id: String,
311}