devtools/actors/
device.rs1use serde::Serialize;
6use serde_json::{Map, Value};
7
8use crate::StreamId;
9use crate::actor::{Actor, ActorError, ActorRegistry};
10use crate::protocol::{ActorDescription, ClientRequest, Method};
11
12#[derive(Serialize)]
13struct GetDescriptionReply {
14 from: String,
15 value: SystemInfo,
16}
17
18#[derive(Serialize)]
21#[serde(rename_all = "camelCase")]
22struct SystemInfo {
23 apptype: String,
24 version: String,
26 appbuildid: String,
29 platformversion: String,
31 brand_name: String,
33}
34
35include!(concat!(env!("OUT_DIR"), "/build_id.rs"));
36
37pub struct DeviceActor {
38 pub name: String,
39}
40
41impl Actor for DeviceActor {
42 fn name(&self) -> String {
43 self.name.clone()
44 }
45 fn handle_message(
46 &self,
47 request: ClientRequest,
48 _registry: &ActorRegistry,
49 msg_type: &str,
50 _msg: &Map<String, Value>,
51 _id: StreamId,
52 ) -> Result<(), ActorError> {
53 match msg_type {
54 "getDescription" => {
55 let msg = GetDescriptionReply {
56 from: self.name(),
57 value: SystemInfo {
58 apptype: "servo".to_string(),
59 version: env!("CARGO_PKG_VERSION").to_string(),
60 appbuildid: BUILD_ID.to_string(),
61 platformversion: "133.0".to_string(),
62 brand_name: "Servo".to_string(),
63 },
64 };
65 request.reply_final(&msg)?
66 },
67
68 _ => return Err(ActorError::UnrecognizedPacketType),
69 };
70 Ok(())
71 }
72}
73
74impl DeviceActor {
75 pub fn new(name: String) -> DeviceActor {
76 DeviceActor { name }
77 }
78
79 pub fn description() -> ActorDescription {
80 ActorDescription {
81 category: "actor",
82 type_name: "device",
83 methods: vec![Method {
84 name: "getDescription",
85 request: Value::Null,
86 response: Value::Object(
87 vec![(
88 "value".to_owned(),
89 Value::Object(
90 vec![("_retval".to_owned(), Value::String("json".to_owned()))]
91 .into_iter()
92 .collect(),
93 ),
94 )]
95 .into_iter()
96 .collect(),
97 ),
98 }],
99 }
100 }
101}