devtools/actors/watcher/
network_parent.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use serde::Serialize;
6use serde_json::{Map, Value};
7
8use crate::actor::{Actor, ActorError, ActorRegistry};
9use crate::protocol::ClientRequest;
10use crate::{EmptyReplyMsg, StreamId};
11
12#[derive(Serialize)]
13pub struct NetworkParentActorMsg {
14    actor: String,
15}
16
17pub struct NetworkParentActor {
18    name: String,
19}
20
21impl Actor for NetworkParentActor {
22    fn name(&self) -> String {
23        self.name.clone()
24    }
25
26    /// The network parent actor can handle the following messages:
27    ///
28    /// - `setSaveRequestAndResponseBodies`: Doesn't do anything yet
29    fn handle_message(
30        &self,
31        request: ClientRequest,
32        _registry: &ActorRegistry,
33        msg_type: &str,
34        _msg: &Map<String, Value>,
35        _id: StreamId,
36    ) -> Result<(), ActorError> {
37        match msg_type {
38            "setSaveRequestAndResponseBodies" => {
39                let msg = EmptyReplyMsg { from: self.name() };
40                request.reply_final(&msg)?
41            },
42            _ => return Err(ActorError::UnrecognizedPacketType),
43        };
44        Ok(())
45    }
46}
47
48impl NetworkParentActor {
49    pub fn new(name: String) -> Self {
50        Self { name }
51    }
52
53    pub fn encodable(&self) -> NetworkParentActorMsg {
54        NetworkParentActorMsg { actor: self.name() }
55    }
56}