Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions rclpy/rclpy/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,24 @@ def get_service_names_and_types_by_node(
return _rclpy.rclpy_get_service_names_and_types_by_node(
capsule, node_name, node_namespace)

def get_client_names_and_types_by_node(
self,
node_name: str,
node_namespace: str
) -> List[Tuple[str, List[str]]]:
"""
Get a list of discovered service client topics for a remote node.

:param node_name: Name of a remote node to get service clients for.
:param node_namespace: Namespace of the remode node.
:return: List of tuples.
The fist element of each tuple is the service client name and the second element is a list of
service client types.
"""
with self.handle as capsule:
return _rclpy.rclpy_get_client_names_and_types_by_node(
capsule, node_name, node_namespace)

def get_topic_names_and_types(self, no_demangle: bool = False) -> List[Tuple[str, List[str]]]:
"""
Get a list topic names and types for the node.
Expand Down
53 changes: 53 additions & 0 deletions rclpy/src/rclpy/_rclpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -3153,6 +3153,54 @@ rclpy_get_service_names_and_types_by_node(PyObject * Py_UNUSED(self), PyObject *
return pyservice_names_and_types;
}

/// Get a list of service client names and types associated with the given node name.
/**
* Raises ValueError if pynode is not a node capsule
* Raises RuntimeError if there is an rcl error
*
* \param[in] pynode Capsule pointing to the node
* \param[in] node_name of a remote node to get publishers for
* \return Python list of tuples.
* The first element of each tuple is the service name (string) and the second element
* is a list of service types (list of strings).
*/
static PyObject *
rclpy_get_client_names_and_types_by_node(PyObject * Py_UNUSED(self), PyObject * args)
{
PyObject * pynode;
char * node_name;
char * node_namespace;

if (!PyArg_ParseTuple(args, "Oss", &pynode, &node_name, &node_namespace)) {
return NULL;
}

rcl_node_t * node = (rcl_node_t *)PyCapsule_GetPointer(pynode, "rcl_node_t");
if (!node) {
return NULL;
}

rcl_names_and_types_t client_names_and_types = rcl_get_zero_initialized_names_and_types();
rcl_allocator_t allocator = rcl_get_default_allocator();
rcl_ret_t ret =
rcl_get_client_names_and_types_by_node(node, &allocator, node_name, node_namespace,
&client_names_and_types);
if (ret != RCL_RET_OK) {
PyErr_Format(PyExc_RuntimeError,
"Failed to get_client_names_and_types: %s", rcl_get_error_string().str);
rcl_reset_error();
return NULL;
}

PyObject * pyclient_names_and_types = rclpy_convert_to_py_names_and_types(
&client_names_and_types);
if (!rclpy_names_and_types_fini(&client_names_and_types)) {
Py_XDECREF(pyclient_names_and_types);
return NULL;
}
return pyclient_names_and_types;
}

/// Get a list of topic names and types having at least one subscription from the given node name.
/**
* Raises ValueError if pynode is not a node capsule
Expand Down Expand Up @@ -4812,6 +4860,11 @@ static PyMethodDef rclpy_methods[] = {
METH_VARARGS,
"Get service list of specified node from graph API."
},
{
"rclpy_get_client_names_and_types_by_node", rclpy_get_client_names_and_types_by_node,
METH_VARARGS,
"Get a service client list of a specified node from graph API."
},
{
"rclpy_get_topic_names_and_types", rclpy_get_topic_names_and_types, METH_VARARGS,
"Get topic list from graph API."
Expand Down