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 register(registry: &ActorRegistry) -> String {
53 let name = registry.new_name::<Self>();
54 let actor = Self {
55 name: name.clone(),
56 _configuration: HashMap::new(),
57 };
58 registry.register::<Self>(actor);
59 name
60 }
61}
62
63impl ActorEncode<ActorMsg> for ThreadConfigurationActor {
64 fn encode(&self, _: &ActorRegistry) -> ActorMsg {
65 ActorMsg { actor: self.name() }
66 }
67}