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