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