def recursive_create_objects(self, topic_name, idx, parent): rospy.logdebug("reached parent object creation! current parent: " + str(parent)) hierachy = topic_name.split('/') rospy.logdebug("Current hierachy: " + str(hierachy)) if len(hierachy) == 0 or len(hierachy) == 1: return parent for name in hierachy: rospy.logdebug("current name: " + str(name)) if name != '': try: nodewithsamename = self.server.find_action_node_with_same_name(name, idx) if nodewithsamename is not None: rospy.logdebug("Found node with same name, is now new parent") return self.recursive_create_objects(ros_server.nextname(hierachy, hierachy.index(name)), idx, nodewithsamename) else: # if for some reason 2 services with exactly same name are created use hack>: add random int, prob to hit two # same ints 1/10000, should be sufficient newparent = parent.add_object( ua.NodeId(name, parent.nodeid.NamespaceIndex, ua.NodeIdType.String), ua.QualifiedName(name, parent.nodeid.NamespaceIndex)) return self.recursive_create_objects(ros_server.nextname(hierachy, hierachy.index(name)), idx, newparent) # thrown when node with parent name is not existent in server except IndexError, UaError: newparent = parent.add_object( ua.NodeId(name + str(random.randint(0, 10000)), parent.nodeid.NamespaceIndex, ua.NodeIdType.String), ua.QualifiedName(name, parent.nodeid.NamespaceIndex)) return self.recursive_create_objects(ros_server.nextname(hierachy, hierachy.index(name)), idx, newparent)
def recursive_create_objects(self, name, idx, parent): hierachy = name.split('/') if len(hierachy) == 0 or len(hierachy) == 1: return parent for name in hierachy: if name != '': try: nodewithsamename = self.server.find_service_node_with_same_name( name, idx) rospy.logdebug("nodewithsamename for name: " + str(name) + " is : " + str(nodewithsamename)) if nodewithsamename is not None: rospy.logdebug("recursive call for same name for: " + name) return self.recursive_create_objects( ros_server.nextname(hierachy, hierachy.index(name)), idx, nodewithsamename) else: newparent = parent.add_object( ua.NodeId(name, parent.nodeid.NamespaceIndex, ua.NodeIdType.String), ua.QualifiedName(name, parent.nodeid.NamespaceIndex)) return self.recursive_create_objects( ros_server.nextname(hierachy, hierachy.index(name)), idx, newparent) except IndexError, common.uaerrors.UaError: newparent = parent.add_object( ua.NodeId(name + str(random.randint(0, 10000)), parent.nodeid.NamespaceIndex, ua.NodeIdType.String), ua.QualifiedName(name, parent.nodeid.NamespaceIndex)) return self.recursive_create_objects( ros_server.nextname(hierachy, hierachy.index(name)), idx, newparent)