net.rs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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. prop::{PropertyAtomicGuard, PropertyType, Role},
  26. scene::{SceneNodeId, SceneNodePtr, ScenePath},
  27. ExecutorPtr,
  28. };
  29. #[derive(Debug, SerialDecodable)]
  30. #[repr(u8)]
  31. enum Command {
  32. Hello = 0,
  33. AddNode = 1,
  34. RemoveNode = 9,
  35. RenameNode = 23,
  36. ScanDangling = 24,
  37. LookupNodeId = 12,
  38. AddProperty = 11,
  39. LinkNode = 2,
  40. UnlinkNode = 8,
  41. GetInfo = 19,
  42. GetChildren = 4,
  43. GetParents = 5,
  44. GetProperties = 3,
  45. GetPropertyValue = 6,
  46. SetPropertyValue = 7,
  47. GetSignals = 14,
  48. RegisterSlot = 15,
  49. UnregisterSlot = 16,
  50. LookupSlotId = 17,
  51. GetSlots = 18,
  52. GetMethods = 20,
  53. GetMethod = 21,
  54. CallMethod = 22,
  55. }
  56. // Missing calls todo:
  57. // GetPropLen
  58. // UnsetProperty
  59. // SetPropertyNull
  60. // PropertyPushNull
  61. // PropertyPush
  62. // PropertyIsUnset
  63. pub struct ZeroMQAdapter {
  64. /*
  65. // req-reply commands
  66. req_socket: zmq::Socket,
  67. // We cannot share zmq sockets across threads, and we cannot quickly spawn
  68. // pub sockets due to address reuse errors.
  69. slot_sender: mpsc::SyncSender<(Vec<u8>, Vec<u8>)>,
  70. slot_recvr: Option<mpsc::Receiver<(Vec<u8>, Vec<u8>)>>,
  71. */
  72. sg_root: SceneNodePtr,
  73. _ex: ExecutorPtr,
  74. zmq_rep: Mutex<zeromq::RepSocket>,
  75. _zmq_pub: Mutex<zeromq::PubSocket>,
  76. }
  77. impl ZeroMQAdapter {
  78. pub async fn new(sg_root: SceneNodePtr, ex: ExecutorPtr) -> Arc<Self> {
  79. let mut zmq_rep = zeromq::RepSocket::new();
  80. zmq_rep.bind("tcp://0.0.0.0:9484").await.unwrap();
  81. let mut zmq_pub = zeromq::PubSocket::new();
  82. zmq_pub.bind("tcp://0.0.0.0:9485").await.unwrap();
  83. Arc::new(Self {
  84. sg_root,
  85. _ex: ex,
  86. zmq_rep: Mutex::new(zmq_rep),
  87. _zmq_pub: Mutex::new(zmq_pub),
  88. })
  89. }
  90. pub async fn run(self: Arc<Self>) {
  91. loop {
  92. let req = self.zmq_rep.lock().await.recv().await.unwrap();
  93. assert_eq!(req.len(), 2);
  94. let cmd = req.get(0).unwrap().to_vec();
  95. assert_eq!(cmd.len(), 1);
  96. let payload = req.get(1).unwrap().to_vec();
  97. let cmd = deserialize(&cmd).unwrap();
  98. debug!(target: "req", "zmq: {:?} {:?}", cmd, payload);
  99. let self2 = self.clone();
  100. match self2.process_request(cmd, payload).await {
  101. Ok(reply) => {
  102. let mut m = zeromq::ZmqMessage::from(vec![0u8]);
  103. m.push_back(reply.into());
  104. // [errc:1] [reply]
  105. self.zmq_rep.lock().await.send(m).await.unwrap();
  106. }
  107. Err(err) => {
  108. let errc = err as u8;
  109. warn!(target: "req", "errc {}: {}", errc, err);
  110. let mut m = zeromq::ZmqMessage::from(vec![errc]);
  111. m.push_back(vec![].into());
  112. // [errc:1] [reply]
  113. self.zmq_rep.lock().await.send(m).await.unwrap();
  114. }
  115. }
  116. }
  117. }
  118. async fn process_request(self: Arc<Self>, cmd: Command, payload: Vec<u8>) -> Result<Vec<u8>> {
  119. let mut cur = Cursor::new(&payload);
  120. let mut reply = vec![];
  121. match cmd {
  122. Command::Hello => {
  123. debug!(target: "req", "hello()");
  124. assert_eq!(payload.len(), 0);
  125. "hello".encode(&mut reply).unwrap();
  126. }
  127. Command::GetInfo => {
  128. /*
  129. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  130. debug!(target: "req", "{:?}({})", cmd, node_id);
  131. let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
  132. node.name.encode(&mut reply).unwrap();
  133. node.typ.encode(&mut reply).unwrap();
  134. */
  135. }
  136. Command::GetChildren => {
  137. let node_path: ScenePath = String::decode(&mut cur).unwrap().parse()?;
  138. debug!(target: "req", "{cmd:?}({node_path})");
  139. let node =
  140. self.sg_root.clone().lookup_node(node_path).ok_or(Error::NodeNotFound)?;
  141. let children: Vec<_> = node
  142. .get_children()
  143. .iter()
  144. .map(|node| (node.name.clone(), node.id, node.typ))
  145. .collect();
  146. children.encode(&mut reply).unwrap();
  147. }
  148. Command::GetParents => {
  149. /*
  150. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  151. debug!(target: "req", "{:?}({})", cmd, node_id);
  152. let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
  153. let parents: Vec<_> = node
  154. .parents
  155. .iter()
  156. .map(|node_inf| (node_inf.name.clone(), node_inf.id, node_inf.typ))
  157. .collect();
  158. parents.encode(&mut reply).unwrap();
  159. */
  160. }
  161. Command::GetProperties => {
  162. let node_path: ScenePath = String::decode(&mut cur).unwrap().parse()?;
  163. debug!(target: "req", "{cmd:?}({node_path})");
  164. let node =
  165. self.sg_root.clone().lookup_node(node_path).ok_or(Error::NodeNotFound)?;
  166. VarInt(node.props.len() as u64).encode(&mut reply).unwrap();
  167. for prop in &node.props {
  168. prop.name.encode(&mut reply).unwrap();
  169. prop.typ.encode(&mut reply).unwrap();
  170. prop.subtype.encode(&mut reply).unwrap();
  171. //prop.defaults.encode(&mut reply).unwrap();
  172. prop.ui_name.encode(&mut reply).unwrap();
  173. prop.desc.encode(&mut reply).unwrap();
  174. prop.is_null_allowed.encode(&mut reply).unwrap();
  175. prop.is_expr_allowed.encode(&mut reply).unwrap();
  176. (prop.array_len as u32).encode(&mut reply).unwrap();
  177. prop.min_val.encode(&mut reply).unwrap();
  178. prop.max_val.encode(&mut reply).unwrap();
  179. prop.enum_items.encode(&mut reply).unwrap();
  180. let depends: Vec<_> = prop
  181. .get_depends()
  182. .into_iter()
  183. .map(|d| (d.i as u32, d.local_name))
  184. .collect();
  185. depends.encode(&mut reply).unwrap();
  186. }
  187. }
  188. Command::GetPropertyValue => {
  189. let node_path: ScenePath = String::decode(&mut cur).unwrap().parse()?;
  190. let prop_name = String::decode(&mut cur).unwrap();
  191. debug!(target: "req", "{cmd:?}({node_path}, {prop_name})");
  192. let node =
  193. self.sg_root.clone().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 =
  220. self.sg_root.clone().lookup_node(node_path).ok_or(Error::NodeNotFound)?;
  221. let prop = node.get_property(&prop_name).ok_or(Error::PropertyNotFound)?;
  222. let atom = &mut PropertyAtomicGuard::new();
  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 =
  516. self.sg_root.clone().lookup_node(node_path).ok_or(Error::NodeNotFound)?;
  517. let result = node.call_method(&method_name, arg_data).await?;
  518. result.encode(&mut reply).unwrap();
  519. }
  520. }
  521. Ok(reply)
  522. }
  523. }