net.rs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2025 Dyne.org foundation
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. use async_lock::Mutex;
  19. use darkfi_serial::{async_trait, deserialize, Decodable, Encodable, SerialDecodable, VarInt};
  20. use std::{io::Cursor, sync::Arc};
  21. use zeromq::{Socket, SocketRecv, SocketSend};
  22. use crate::{
  23. error::{Error, Result},
  24. expr::SExprCode,
  25. gfx::{gfxtag, RenderApi},
  26. prop::{PropertyType, Role},
  27. scene::{SceneNodeId, SceneNodePtr, ScenePath},
  28. ExecutorPtr,
  29. };
  30. #[derive(Debug, SerialDecodable)]
  31. #[repr(u8)]
  32. enum Command {
  33. Hello = 0,
  34. AddNode = 1,
  35. RemoveNode = 9,
  36. RenameNode = 23,
  37. ScanDangling = 24,
  38. LookupNodeId = 12,
  39. AddProperty = 11,
  40. LinkNode = 2,
  41. UnlinkNode = 8,
  42. GetInfo = 19,
  43. GetChildren = 4,
  44. GetParents = 5,
  45. GetProperties = 3,
  46. GetPropertyValue = 6,
  47. SetPropertyValue = 7,
  48. GetSignals = 14,
  49. RegisterSlot = 15,
  50. UnregisterSlot = 16,
  51. LookupSlotId = 17,
  52. GetSlots = 18,
  53. GetMethods = 20,
  54. GetMethod = 21,
  55. CallMethod = 22,
  56. }
  57. // Missing calls todo:
  58. // GetPropLen
  59. // UnsetProperty
  60. // SetPropertyNull
  61. // PropertyPushNull
  62. // PropertyPush
  63. // PropertyIsUnset
  64. pub struct ZeroMQAdapter {
  65. /*
  66. // req-reply commands
  67. req_socket: zmq::Socket,
  68. // We cannot share zmq sockets across threads, and we cannot quickly spawn
  69. // pub sockets due to address reuse errors.
  70. slot_sender: mpsc::SyncSender<(Vec<u8>, Vec<u8>)>,
  71. slot_recvr: Option<mpsc::Receiver<(Vec<u8>, Vec<u8>)>>,
  72. */
  73. sg_root: SceneNodePtr,
  74. render_api: RenderApi,
  75. _ex: ExecutorPtr,
  76. zmq_rep: Mutex<zeromq::RepSocket>,
  77. _zmq_pub: Mutex<zeromq::PubSocket>,
  78. }
  79. impl ZeroMQAdapter {
  80. pub async fn new(sg_root: SceneNodePtr, render_api: RenderApi, ex: ExecutorPtr) -> Arc<Self> {
  81. let mut zmq_rep = zeromq::RepSocket::new();
  82. zmq_rep.bind("tcp://0.0.0.0:9484").await.unwrap();
  83. let mut zmq_pub = zeromq::PubSocket::new();
  84. zmq_pub.bind("tcp://0.0.0.0:9485").await.unwrap();
  85. Arc::new(Self {
  86. sg_root,
  87. render_api,
  88. _ex: ex,
  89. zmq_rep: Mutex::new(zmq_rep),
  90. _zmq_pub: Mutex::new(zmq_pub),
  91. })
  92. }
  93. pub async fn run(self: Arc<Self>) {
  94. loop {
  95. let req = self.zmq_rep.lock().await.recv().await.unwrap();
  96. assert_eq!(req.len(), 2);
  97. let cmd = req.get(0).unwrap().to_vec();
  98. assert_eq!(cmd.len(), 1);
  99. let payload = req.get(1).unwrap().to_vec();
  100. let cmd = deserialize(&cmd).unwrap();
  101. debug!(target: "req", "zmq: {:?} {:?}", cmd, payload);
  102. let self2 = self.clone();
  103. match self2.process_request(cmd, payload).await {
  104. Ok(reply) => {
  105. let mut m = zeromq::ZmqMessage::from(vec![0u8]);
  106. m.push_back(reply.into());
  107. // [errc:1] [reply]
  108. self.zmq_rep.lock().await.send(m).await.unwrap();
  109. }
  110. Err(err) => {
  111. let errc = err as u8;
  112. warn!(target: "req", "errc {}: {}", errc, err);
  113. let mut m = zeromq::ZmqMessage::from(vec![errc]);
  114. m.push_back(vec![].into());
  115. // [errc:1] [reply]
  116. self.zmq_rep.lock().await.send(m).await.unwrap();
  117. }
  118. }
  119. }
  120. }
  121. async fn process_request(self: Arc<Self>, cmd: Command, payload: Vec<u8>) -> Result<Vec<u8>> {
  122. let mut cur = Cursor::new(&payload);
  123. let mut reply = vec![];
  124. match cmd {
  125. Command::Hello => {
  126. debug!(target: "req", "hello()");
  127. assert_eq!(payload.len(), 0);
  128. "hello".encode(&mut reply).unwrap();
  129. }
  130. Command::GetInfo => {
  131. /*
  132. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  133. debug!(target: "req", "{:?}({})", cmd, node_id);
  134. let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
  135. node.name.encode(&mut reply).unwrap();
  136. node.typ.encode(&mut reply).unwrap();
  137. */
  138. }
  139. Command::GetChildren => {
  140. let node_path: ScenePath = String::decode(&mut cur).unwrap().parse()?;
  141. debug!(target: "req", "{cmd:?}({node_path})");
  142. let node = self.sg_root.lookup_node(node_path).ok_or(Error::NodeNotFound)?;
  143. let children: Vec<_> = node
  144. .get_children()
  145. .iter()
  146. .map(|node| (node.name.clone(), node.id, node.typ))
  147. .collect();
  148. children.encode(&mut reply).unwrap();
  149. }
  150. Command::GetParents => {
  151. /*
  152. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  153. debug!(target: "req", "{:?}({})", cmd, node_id);
  154. let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
  155. let parents: Vec<_> = node
  156. .parents
  157. .iter()
  158. .map(|node_inf| (node_inf.name.clone(), node_inf.id, node_inf.typ))
  159. .collect();
  160. parents.encode(&mut reply).unwrap();
  161. */
  162. }
  163. Command::GetProperties => {
  164. let node_path: ScenePath = String::decode(&mut cur).unwrap().parse()?;
  165. debug!(target: "req", "{cmd:?}({node_path})");
  166. let node = self.sg_root.lookup_node(node_path).ok_or(Error::NodeNotFound)?;
  167. VarInt(node.props.len() as u64).encode(&mut reply).unwrap();
  168. for prop in &node.props {
  169. prop.name.encode(&mut reply).unwrap();
  170. prop.typ.encode(&mut reply).unwrap();
  171. prop.subtype.encode(&mut reply).unwrap();
  172. //prop.defaults.encode(&mut reply).unwrap();
  173. prop.ui_name.encode(&mut reply).unwrap();
  174. prop.desc.encode(&mut reply).unwrap();
  175. prop.is_null_allowed.encode(&mut reply).unwrap();
  176. prop.is_expr_allowed.encode(&mut reply).unwrap();
  177. (prop.array_len as u32).encode(&mut reply).unwrap();
  178. prop.min_val.encode(&mut reply).unwrap();
  179. prop.max_val.encode(&mut reply).unwrap();
  180. prop.enum_items.encode(&mut reply).unwrap();
  181. let depends: Vec<_> = prop
  182. .get_depends()
  183. .into_iter()
  184. .map(|d| (d.i as u32, d.local_name))
  185. .collect();
  186. depends.encode(&mut reply).unwrap();
  187. }
  188. }
  189. Command::GetPropertyValue => {
  190. let node_path: ScenePath = String::decode(&mut cur).unwrap().parse()?;
  191. let prop_name = String::decode(&mut cur).unwrap();
  192. debug!(target: "req", "{cmd:?}({node_path}, {prop_name})");
  193. let node = self.sg_root.lookup_node(node_path).ok_or(Error::NodeNotFound)?;
  194. let prop = node.get_property(&prop_name).ok_or(Error::PropertyNotFound)?;
  195. prop.typ.encode(&mut reply).unwrap();
  196. VarInt(prop.get_len() as u64).encode(&mut reply).unwrap();
  197. for i in 0..prop.get_len() {
  198. let val = prop.get_value(i)?;
  199. if val.is_unset() {
  200. 1u8.encode(&mut reply).unwrap();
  201. let default = &prop.defaults[i];
  202. default.encode(&mut reply).unwrap();
  203. } else if val.is_null() {
  204. 2u8.encode(&mut reply).unwrap();
  205. } else if val.is_expr() {
  206. 3u8.encode(&mut reply).unwrap();
  207. } else {
  208. 0u8.encode(&mut reply).unwrap();
  209. val.encode(&mut reply).unwrap();
  210. }
  211. }
  212. }
  213. Command::SetPropertyValue => {
  214. let node_path: ScenePath = String::decode(&mut cur).unwrap().parse()?;
  215. let prop_name = String::decode(&mut cur).unwrap();
  216. let prop_i = u32::decode(&mut cur).unwrap() as usize;
  217. let prop_type = PropertyType::decode(&mut cur).unwrap();
  218. debug!(target: "req", "{cmd:?}({node_path}, {prop_name}, {prop_i}, {prop_type:?})");
  219. let node = self.sg_root.lookup_node(node_path).ok_or(Error::NodeNotFound)?;
  220. let prop = node.get_property(&prop_name).ok_or(Error::PropertyNotFound)?;
  221. let atom =
  222. &mut self.render_api.make_guard(gfxtag!("ZeroMQAdapter::SetPropertyValue"));
  223. match prop_type {
  224. PropertyType::Null => {
  225. prop.set_null(atom, Role::User, prop_i)?;
  226. }
  227. PropertyType::Bool => {
  228. let val = bool::decode(&mut cur).unwrap();
  229. prop.set_bool(atom, Role::User, prop_i, val)?;
  230. }
  231. PropertyType::Uint32 => {
  232. let val = u32::decode(&mut cur).unwrap();
  233. prop.set_u32(atom, Role::User, prop_i, val)?;
  234. }
  235. PropertyType::Float32 => {
  236. let val = f32::decode(&mut cur).unwrap();
  237. prop.set_f32(atom, Role::User, prop_i, val)?;
  238. }
  239. PropertyType::Str => {
  240. let val = String::decode(&mut cur).unwrap();
  241. prop.set_str(atom, Role::User, prop_i, val)?;
  242. }
  243. PropertyType::Enum => {
  244. let val = String::decode(&mut cur).unwrap();
  245. prop.set_enum(atom, Role::User, prop_i, val)?;
  246. }
  247. PropertyType::SceneNodeId => {
  248. let val = SceneNodeId::decode(&mut cur).unwrap();
  249. prop.set_node_id(atom, Role::User, prop_i, val)?;
  250. }
  251. PropertyType::SExpr => {
  252. let val = SExprCode::decode(&mut cur).unwrap();
  253. debug!(target: "req", " received code {:?}", val);
  254. prop.set_expr(atom, Role::User, prop_i, val)?;
  255. }
  256. }
  257. }
  258. Command::AddNode => {
  259. /*
  260. let node_name = String::decode(&mut cur).unwrap();
  261. let node_type = SceneNodeType::decode(&mut cur).unwrap();
  262. debug!(target: "req", "{:?}({}, {:?})", cmd, node_name, node_type);
  263. let node_id = scene_graph.add_node(&node_name, node_type).id;
  264. node_id.encode(&mut reply).unwrap();
  265. */
  266. }
  267. Command::RemoveNode => {
  268. /*
  269. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  270. debug!(target: "req", "{:?}({})", cmd, node_id);
  271. scene_graph.remove_node(node_id)?;
  272. */
  273. }
  274. Command::RenameNode => {
  275. /*
  276. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  277. let node_name = String::decode(&mut cur).unwrap();
  278. debug!(target: "req", "{:?}({}, {})", cmd, node_id, node_name);
  279. scene_graph.rename_node(node_id, node_name)?;
  280. */
  281. }
  282. Command::ScanDangling => {
  283. /*
  284. let dangling = scene_graph.scan_dangling();
  285. dangling.encode(&mut reply).unwrap();
  286. */
  287. }
  288. Command::LookupNodeId => {
  289. /*
  290. let node_path: String = deserialize(&payload).unwrap();
  291. debug!(target: "req", "{:?}({})", cmd, node_path);
  292. let node_id = scene_graph.lookup_node_id(&node_path).ok_or(Error::NodeNotFound)?;
  293. node_id.encode(&mut reply).unwrap();
  294. */
  295. }
  296. Command::AddProperty => {
  297. /*
  298. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  299. let prop_name = String::decode(&mut cur).unwrap();
  300. let prop_type = PropertyType::decode(&mut cur).unwrap();
  301. let prop_subtype = PropertySubType::decode(&mut cur).unwrap();
  302. debug!(target: "req", "{:?}({}, {}, {:?}, {:?}, ...)", cmd, node_id, prop_name, prop_type, prop_subtype);
  303. let mut prop = Property::new(prop_name, prop_type, prop_subtype);
  304. let prop_array_len = u32::decode(&mut cur).unwrap();
  305. prop.set_array_len(prop_array_len as usize);
  306. let prop_defaults_is_some = bool::decode(&mut cur).unwrap();
  307. if prop_defaults_is_some {
  308. let prop_defaults_len = VarInt::decode(&mut cur).unwrap();
  309. match prop_type {
  310. PropertyType::Uint32 => {
  311. let mut prop_defaults = vec![];
  312. for _ in 0..prop_defaults_len.0 {
  313. prop_defaults.push(u32::decode(&mut cur).unwrap());
  314. }
  315. prop.set_defaults_u32(prop_defaults)?;
  316. }
  317. PropertyType::Float32 => {
  318. let mut prop_defaults = vec![];
  319. for _ in 0..prop_defaults_len.0 {
  320. prop_defaults.push(f32::decode(&mut cur).unwrap());
  321. }
  322. prop.set_defaults_f32(prop_defaults)?;
  323. }
  324. PropertyType::Str => {
  325. let mut prop_defaults = vec![];
  326. for _ in 0..prop_defaults_len.0 {
  327. prop_defaults.push(String::decode(&mut cur).unwrap());
  328. }
  329. prop.set_defaults_str(prop_defaults)?;
  330. }
  331. _ => return Err(Error::PropertyWrongType),
  332. }
  333. }
  334. let prop_ui_name = String::decode(&mut cur).unwrap();
  335. let prop_desc = String::decode(&mut cur).unwrap();
  336. let prop_is_null_allowed = bool::decode(&mut cur).unwrap();
  337. let prop_is_expr_allowed = bool::decode(&mut cur).unwrap();
  338. match prop_type {
  339. PropertyType::Uint32 => {
  340. let min_is_some = bool::decode(&mut cur).unwrap();
  341. let min = if min_is_some {
  342. let min = u32::decode(&mut cur).unwrap();
  343. Some(PropertyValue::Uint32(min))
  344. } else {
  345. None
  346. };
  347. let max_is_some = bool::decode(&mut cur).unwrap();
  348. let max = if max_is_some {
  349. let max = u32::decode(&mut cur).unwrap();
  350. Some(PropertyValue::Uint32(max))
  351. } else {
  352. None
  353. };
  354. prop.min_val = min;
  355. prop.max_val = max;
  356. }
  357. PropertyType::Float32 => {
  358. let min_is_some = bool::decode(&mut cur).unwrap();
  359. let min = if min_is_some {
  360. let min = f32::decode(&mut cur).unwrap();
  361. Some(PropertyValue::Float32(min))
  362. } else {
  363. None
  364. };
  365. let max_is_some = bool::decode(&mut cur).unwrap();
  366. let max = if max_is_some {
  367. let max = f32::decode(&mut cur).unwrap();
  368. Some(PropertyValue::Float32(max))
  369. } else {
  370. None
  371. };
  372. prop.min_val = min;
  373. prop.max_val = max;
  374. }
  375. _ => {
  376. let min_is_some = bool::decode(&mut cur).unwrap();
  377. if min_is_some {
  378. return Err(Error::PropertyWrongType)
  379. }
  380. let max_is_some = bool::decode(&mut cur).unwrap();
  381. if max_is_some {
  382. return Err(Error::PropertyWrongType)
  383. }
  384. }
  385. }
  386. let prop_enum_items = Vec::<String>::decode(&mut cur).unwrap();
  387. let node = scene_graph.get_node_mut(node_id).ok_or(Error::NodeNotFound)?;
  388. prop.set_ui_text(prop_ui_name, prop_desc);
  389. prop.is_null_allowed = prop_is_null_allowed;
  390. prop.is_expr_allowed = prop_is_expr_allowed;
  391. if !prop_enum_items.is_empty() {
  392. prop.set_enum_items(prop_enum_items)?;
  393. }
  394. node.add_property(prop)?;
  395. */
  396. }
  397. Command::LinkNode => {
  398. /*
  399. let child_id = SceneNodeId::decode(&mut cur).unwrap();
  400. let parent_id = SceneNodeId::decode(&mut cur).unwrap();
  401. debug!(target: "req", "{:?}({}, {})", cmd, child_id, parent_id);
  402. scene_graph.link(child_id, parent_id)?;
  403. */
  404. }
  405. Command::UnlinkNode => {
  406. /*
  407. let child_id = SceneNodeId::decode(&mut cur).unwrap();
  408. let parent_id = SceneNodeId::decode(&mut cur).unwrap();
  409. debug!(target: "req", "{:?}({}, {})", cmd, child_id, parent_id);
  410. scene_graph.unlink(child_id, parent_id)?;
  411. */
  412. }
  413. Command::GetSignals => {
  414. /*
  415. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  416. debug!(target: "req", "{:?}({})", cmd, node_id);
  417. let node = scene_graph.get_node_mut(node_id).ok_or(Error::NodeNotFound)?;
  418. let mut sigs = vec![];
  419. for sig in &node.sigs {
  420. sigs.push(sig.name.clone());
  421. }
  422. sigs.encode(&mut reply).unwrap();
  423. */
  424. }
  425. Command::RegisterSlot => {
  426. /*
  427. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  428. let sig_name = String::decode(&mut cur).unwrap();
  429. let slot_name = String::decode(&mut cur).unwrap();
  430. let user_data = Vec::<u8>::decode(&mut cur).unwrap();
  431. debug!(target: "req", "{:?}({}, {}, {}, {:?})", cmd, node_id, sig_name, slot_name, user_data);
  432. let node = scene_graph.get_node_mut(node_id).ok_or(Error::NodeNotFound)?;
  433. let (sendr, recvr) = async_channel::unbounded();
  434. let slot = Slot { name: slot_name, notify: sendr };
  435. // This task will auto-die when the slot is unregistered
  436. let self2 = self.clone();
  437. self.ex
  438. .spawn(async move {
  439. loop {
  440. let Ok(signal_data) = recvr.recv().await else {
  441. // Die
  442. break
  443. };
  444. let mut m = zeromq::ZmqMessage::from(signal_data);
  445. m.push_back(user_data.clone().into());
  446. self2.zmq_pub.lock().await.send(m).await.unwrap();
  447. }
  448. })
  449. .detach();
  450. let slot_id = node.register(&sig_name, slot)?;
  451. slot_id.encode(&mut reply).unwrap();
  452. */
  453. }
  454. Command::UnregisterSlot => {
  455. /*
  456. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  457. let sig_name = String::decode(&mut cur).unwrap();
  458. let slot_id = SlotId::decode(&mut cur).unwrap();
  459. debug!(target: "req", "{:?}({}, {}, {})", cmd, node_id, sig_name, slot_id);
  460. let node = scene_graph.get_node_mut(node_id).ok_or(Error::NodeNotFound)?;
  461. node.unregister(&sig_name, slot_id)?;
  462. */
  463. }
  464. Command::LookupSlotId => {
  465. /*
  466. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  467. let sig_name = String::decode(&mut cur).unwrap();
  468. let slot_name = String::decode(&mut cur).unwrap();
  469. debug!(target: "req", "{:?}({}, {}, {})", cmd, node_id, sig_name, slot_name);
  470. let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
  471. let signal = node.get_signal(&sig_name).ok_or(Error::SignalNotFound)?;
  472. let slot_id = signal.lookup_slot_id(&slot_name).ok_or(Error::SlotNotFound)?;
  473. slot_id.encode(&mut reply).unwrap();
  474. */
  475. }
  476. Command::GetSlots => {
  477. /*
  478. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  479. let sig_name = String::decode(&mut cur).unwrap();
  480. debug!(target: "req", "{:?}({}, {})", cmd, node_id, sig_name);
  481. let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
  482. let signal = node.get_signal(&sig_name).ok_or(Error::SignalNotFound)?;
  483. let mut slots = vec![];
  484. for (slot_id, slot) in signal.get_slots() {
  485. slots.push((slot.name.clone(), slot_id));
  486. }
  487. slots.encode(&mut reply).unwrap();
  488. */
  489. }
  490. Command::GetMethods => {
  491. /*
  492. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  493. debug!(target: "req", "{:?}({})", cmd, node_id);
  494. let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
  495. let method_names: Vec<_> = node.methods.iter().map(|m| m.name.clone()).collect();
  496. method_names.encode(&mut reply).unwrap();
  497. */
  498. }
  499. Command::GetMethod => {
  500. /*
  501. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  502. let method_name = String::decode(&mut cur).unwrap();
  503. debug!(target: "req", "{:?}({}, {})", cmd, node_id, method_name);
  504. let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
  505. let method = node.get_method(&method_name).ok_or(Error::MethodNotFound)?;
  506. method.args.encode(&mut reply).unwrap();
  507. method.result.encode(&mut reply).unwrap();
  508. */
  509. }
  510. Command::CallMethod => {
  511. let node_path: ScenePath = String::decode(&mut cur).unwrap().parse()?;
  512. let method_name = String::decode(&mut cur).unwrap();
  513. let arg_data = Vec::<u8>::decode(&mut cur).unwrap();
  514. debug!(target: "req", "{cmd:?}({node_path}, {method_name}, ...)");
  515. let node = self.sg_root.lookup_node(node_path).ok_or(Error::NodeNotFound)?;
  516. let result = node.call_method(&method_name, arg_data).await?;
  517. result.encode(&mut reply).unwrap();
  518. }
  519. }
  520. Ok(reply)
  521. }
  522. }