net.rs 24 KB

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