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