devtools/actors/
process.rs1use serde::Serialize;
10use serde_json::{Map, Value};
11
12use crate::StreamId;
13use crate::actor::{Actor, ActorError, ActorRegistry};
14use crate::actors::root::DescriptorTraits;
15use crate::protocol::ClientRequest;
16
17#[derive(Serialize)]
18struct ListWorkersReply {
19 from: String,
20 workers: Vec<u32>, }
22
23#[derive(Serialize)]
24#[serde(rename_all = "camelCase")]
25pub struct ProcessActorMsg {
26 actor: String,
27 id: u32,
28 is_parent: bool,
29 is_windowless_parent: bool,
30 traits: DescriptorTraits,
31}
32
33pub struct ProcessActor {
34 name: String,
35}
36
37impl Actor for ProcessActor {
38 fn name(&self) -> String {
39 self.name.clone()
40 }
41
42 fn handle_message(
46 &self,
47 request: ClientRequest,
48 _registry: &ActorRegistry,
49 msg_type: &str,
50 _msg: &Map<String, Value>,
51 _id: StreamId,
52 ) -> Result<(), ActorError> {
53 match msg_type {
54 "listWorkers" => {
55 let reply = ListWorkersReply {
56 from: self.name(),
57 workers: vec![],
58 };
59 request.reply_final(&reply)?
60 },
61
62 _ => return Err(ActorError::UnrecognizedPacketType),
63 };
64 Ok(())
65 }
66}
67
68impl ProcessActor {
69 pub fn new(name: String) -> Self {
70 Self { name }
71 }
72
73 pub fn encodable(&self) -> ProcessActorMsg {
74 ProcessActorMsg {
75 actor: self.name(),
76 id: 0,
77 is_parent: true,
78 is_windowless_parent: false,
79 traits: Default::default(),
80 }
81 }
82}