Skip to main content

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