devtools/actors/watcher/
thread_configuration.rs1use std::collections::HashMap;
9
10use malloc_size_of_derive::MallocSizeOf;
11use serde_json::{Map, Value};
12
13use crate::actor::{Actor, ActorEncode, ActorError, ActorRegistry};
14use crate::protocol::ClientRequest;
15use crate::{ActorMsg, EmptyReplyMsg, StreamId};
16
17#[derive(MallocSizeOf)]
18pub(crate) struct ThreadConfigurationActor {
19 name: String,
20 _configuration: HashMap<&'static str, bool>,
21}
22
23impl Actor for ThreadConfigurationActor {
24 fn name(&self) -> String {
25 self.name.clone()
26 }
27
28 fn handle_message(
32 &self,
33 request: ClientRequest,
34 _registry: &ActorRegistry,
35 msg_type: &str,
36 _msg: &Map<String, Value>,
37 _id: StreamId,
38 ) -> Result<(), ActorError> {
39 match msg_type {
40 "updateConfiguration" => {
41 let msg = EmptyReplyMsg { from: self.name() };
43 request.reply_final(&msg)?
44 },
45 _ => return Err(ActorError::UnrecognizedPacketType),
46 };
47 Ok(())
48 }
49}
50
51impl ThreadConfigurationActor {
52 pub fn new(name: String) -> Self {
53 Self {
54 name,
55 _configuration: HashMap::new(),
56 }
57 }
58}
59
60impl ActorEncode<ActorMsg> for ThreadConfigurationActor {
61 fn encode(&self, _: &ActorRegistry) -> ActorMsg {
62 ActorMsg { actor: self.name() }
63 }
64}