devtools/actors/
reflow.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
5//! This actor is used for protocol purposes, it forwards the reflow events to clients.
6
7use serde_json::{Map, Value};
8
9use crate::actor::{Actor, ActorError, ActorRegistry};
10use crate::protocol::ClientRequest;
11use crate::{EmptyReplyMsg, StreamId};
12
13pub struct ReflowActor {
14    name: String,
15}
16
17impl Actor for ReflowActor {
18    fn name(&self) -> String {
19        self.name.clone()
20    }
21
22    /// The reflow actor can handle the following messages:
23    ///
24    /// - `start`: Does nothing yet. This doesn't need a reply like other messages.
25    fn handle_message(
26        &self,
27        request: ClientRequest,
28        _registry: &ActorRegistry,
29        msg_type: &str,
30        _msg: &Map<String, Value>,
31        _id: StreamId,
32    ) -> Result<(), ActorError> {
33        match msg_type {
34            "start" => {
35                // TODO: Create an observer on "reflows" events
36                let msg = EmptyReplyMsg { from: self.name() };
37                request.reply_final(&msg)?
38            },
39            _ => return Err(ActorError::UnrecognizedPacketType),
40        };
41        Ok(())
42    }
43
44    fn cleanup(&self, _id: StreamId) {}
45}
46
47impl ReflowActor {
48    pub fn new(name: String) -> Self {
49        Self { name }
50    }
51}