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