Procházet zdrojové kódy

app/netdebug: add back GetSignals, GetSlots, GetMethods and GetMethod calls

darkfi před 1 týdnem
rodič
revize
3c4e92d4c9
4 změnil soubory, kde provedl 44 přidání a 49 odebrání
  1. 10 10
      bin/app/gui/print_tree.py
  2. 8 8
      bin/app/pydrk/api.py
  3. 19 31
      bin/app/src/net.rs
  4. 7 0
      bin/app/src/scene.rs

+ 10 - 10
bin/app/gui/print_tree.py

@@ -84,17 +84,17 @@ def print_node_info(parent_path, depth, indent):
         if prop.depends:
             print(f"{ws}    depends: {prop.depends}")
 
-    #for sig in api.get_signals(parent_id):
-    #    print(f"{ws}~{sig}")
-    #    for slot_id, slot in api.get_slots(parent_id, sig):
-    #        print(f"{ws}- '{slot}' ({slot_id})")
+    for sig in api.get_signals(parent_path):
+        print(f"{ws}~{sig}")
+        for slot_id, slot in api.get_slots(parent_path, sig):
+            print(f"{ws}- '{slot}' ({slot_id})")
 
-    #for method_name in api.get_methods(parent_id):
-    #    args, results = api.get_method(parent_id, method_name)
+    for method_name in api.get_methods(parent_path):
+        args, results = api.get_method(parent_path, method_name)
 
-    #    args = [f"{name}: " + PropertyType.to_str(typ) for (name, _, typ) in args]
-    #    results = [f"{name}: " + PropertyType.to_str(typ) for (name, _, typ) in results]
+        args = [f"{name}: " + PropertyType.to_str(typ) for (name, _, typ) in args]
+        results = [f"{name}: " + PropertyType.to_str(typ) for (name, _, typ) in results]
 
-    #    method_str = f"{method_name}(" + ", ".join(args) + ") -> (" + ", ".join(results) + ")"
-    #    print(f"{ws}{method_str}")
+        method_str = f"{method_name}(" + ", ".join(args) + ") -> (" + ", ".join(results) + ")"
+        print(f"{ws}{method_str}")
 

+ 8 - 8
bin/app/pydrk/api.py

@@ -638,9 +638,9 @@ class Api:
             expr.encode_expr(req, sexpr)
         self._make_request(Command.SET_PROPERTY_VALUE, req)
 
-    def get_signals(self, node_id):
+    def get_signals(self, node_path):
         req = bytearray()
-        serial.write_u32(req, node_id)
+        serial.encode_str(req, node_path)
         cur = self._make_request(Command.GET_SIGNALS, req)
         sigs_len = serial.decode_varint(cur)
         sigs = []
@@ -677,9 +677,9 @@ class Api:
             return None
         return serial.read_u32(cur)
 
-    def get_slots(self, node_id, sig_name):
+    def get_slots(self, node_path, sig_name):
         req = bytearray()
-        serial.write_u32(req, node_id)
+        serial.encode_str(req, node_path)
         serial.encode_str(req, sig_name)
         cur = self._make_request(Command.GET_SLOTS, req)
 
@@ -691,9 +691,9 @@ class Api:
         slots = serial.decode_arr(cur, read_slot)
         return slots
 
-    def get_methods(self, node_id):
+    def get_methods(self, node_path):
         req = bytearray()
-        serial.write_u32(req, node_id)
+        serial.encode_str(req, node_path)
         cur = self._make_request(Command.GET_METHODS, req)
 
         def read_method(cur):
@@ -703,9 +703,9 @@ class Api:
         methods = serial.decode_arr(cur, read_method)
         return methods
 
-    def get_method(self, node_id, method_name):
+    def get_method(self, node_path, method_name):
         req = bytearray()
-        serial.write_u32(req, node_id)
+        serial.encode_str(req, node_path)
         serial.encode_str(req, method_name)
         cur = self._make_request(Command.GET_METHOD, req)
 

+ 19 - 31
bin/app/src/net.rs

@@ -455,18 +455,14 @@ impl ZeroMQAdapter {
                 */
             }
             Command::GetSignals => {
-                /*
-                let node_id = SceneNodeId::decode(&mut cur).unwrap();
-                debug!(target: "req", "{:?}({})", cmd, node_id);
+                let node_path: ScenePath = String::decode(&mut cur).unwrap().parse()?;
+                debug!(target: "req", "{cmd:?}({node_path})");
 
-                let node = scene_graph.get_node_mut(node_id).ok_or(Error::NodeNotFound)?;
+                let node = self.sg_root.lookup_node(node_path).ok_or(Error::NodeNotFound)?;
 
-                let mut sigs = vec![];
-                for sig in &node.sigs {
-                    sigs.push(sig.name.clone());
-                }
-                sigs.encode(&mut reply).unwrap();
-                */
+                let sigs = node.sigs.read().unwrap();
+                let sig_names: Vec<_> = sigs.iter().map(|sig| sig.name.clone()).collect();
+                sig_names.encode(&mut reply).unwrap();
             }
             Command::RegisterSlot => {
                 /*
@@ -528,44 +524,36 @@ impl ZeroMQAdapter {
                 */
             }
             Command::GetSlots => {
-                /*
-                let node_id = SceneNodeId::decode(&mut cur).unwrap();
+                let node_path: ScenePath = String::decode(&mut cur).unwrap().parse()?;
                 let sig_name = String::decode(&mut cur).unwrap();
-                debug!(target: "req", "{:?}({}, {})", cmd, node_id, sig_name);
+                debug!(target: "req", "{cmd:?}({node_path}, {sig_name})");
 
-                let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
+                let node = self.sg_root.lookup_node(node_path).ok_or(Error::NodeNotFound)?;
                 let signal = node.get_signal(&sig_name).ok_or(Error::SignalNotFound)?;
 
-                let mut slots = vec![];
-                for (slot_id, slot) in signal.get_slots() {
-                    slots.push((slot.name.clone(), slot_id));
-                }
-                slots.encode(&mut reply).unwrap();
-                */
+                let slots = signal.get_slots();
+                let slot_names: Vec<_> =
+                    slots.iter().map(|(slot_id, slot)| (slot.name.clone(), *slot_id)).collect();
+                slot_names.encode(&mut reply).unwrap();
             }
             Command::GetMethods => {
-                /*
-                let node_id = SceneNodeId::decode(&mut cur).unwrap();
-                debug!(target: "req", "{:?}({})", cmd, node_id);
+                let node_path: ScenePath = String::decode(&mut cur).unwrap().parse()?;
+                debug!(target: "req", "{cmd:?}({node_path})");
 
-                let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
+                let node = self.sg_root.lookup_node(node_path).ok_or(Error::NodeNotFound)?;
                 let method_names: Vec<_> = node.methods.iter().map(|m| m.name.clone()).collect();
-
                 method_names.encode(&mut reply).unwrap();
-                */
             }
             Command::GetMethod => {
-                /*
-                let node_id = SceneNodeId::decode(&mut cur).unwrap();
+                let node_path: ScenePath = String::decode(&mut cur).unwrap().parse()?;
                 let method_name = String::decode(&mut cur).unwrap();
-                debug!(target: "req", "{:?}({}, {})", cmd, node_id, method_name);
+                debug!(target: "req", "{:?}({}, {})", cmd, node_path, method_name);
 
-                let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
+                let node = self.sg_root.lookup_node(node_path).ok_or(Error::NodeNotFound)?;
                 let method = node.get_method(&method_name).ok_or(Error::MethodNotFound)?;
 
                 method.args.encode(&mut reply).unwrap();
                 method.result.encode(&mut reply).unwrap();
-                */
             }
             Command::CallMethod => {
                 let node_path: ScenePath = String::decode(&mut cur).unwrap().parse()?;

+ 7 - 0
bin/app/src/scene.rs

@@ -533,6 +533,13 @@ pub struct Signal {
     slots: SyncRwLock<HashMap<SlotId, Slot>>,
 }
 
+impl Signal {
+    pub fn get_slots(&self) -> Vec<(SlotId, Slot)> {
+        let slots = self.slots.read().unwrap();
+        slots.iter().map(|(id, slot)| (*id, slot.clone())).collect()
+    }
+}
+
 #[derive(Clone, Debug)]
 pub struct MethodCall {
     pub data: CallData,