use malloc_size_of_derive::MallocSizeOf;
use serde::Serialize;
use serde_json::{Map, Value};
use crate::actor::{Actor, ActorEncode, ActorError, ActorRegistry};
use crate::protocol::ClientRequest;
use crate::{ActorMsg, StreamId};
#[derive(MallocSizeOf)]
pub(crate) struct LayoutInspectorActor {
name: String,
}
#[derive(Serialize)]
pub(crate) struct GetGridsReply {
from: String,
grids: Vec<String>,
}
#[derive(Serialize)]
pub(crate) struct GetCurrentFlexboxReply {
from: String,
flexbox: Option<()>,
}
impl Actor for LayoutInspectorActor {
fn name(&self) -> String {
self.name.clone()
}
fn handle_message(
&self,
request: ClientRequest,
_registry: &ActorRegistry,
msg_type: &str,
_msg: &Map<String, Value>,
_id: StreamId,
) -> Result<(), ActorError> {
match msg_type {
"getGrids" => {
let msg = GetGridsReply {
from: self.name(),
grids: vec![],
};
request.reply_final(&msg)?
},
"getCurrentFlexbox" => {
let msg = GetCurrentFlexboxReply {
from: self.name(),
flexbox: None,
};
request.reply_final(&msg)?
},
_ => return Err(ActorError::UnrecognizedPacketType),
};
Ok(())
}
fn cleanup(&self, _id: StreamId) {}
}
impl LayoutInspectorActor {
pub fn register(registry: &ActorRegistry) -> String {
let name = registry.new_name::<Self>();
let actor = Self { name: name.clone() };
registry.register::<Self>(actor);
name
}
}
impl ActorEncode<ActorMsg> for LayoutInspectorActor {
fn encode(&self, _: &ActorRegistry) -> ActorMsg {
ActorMsg { actor: self.name() }
}
}