in usb_monitor_pkg/usb_monitor_pkg/usb_monitor_node.py [0:0]
def usb_mount_point_manager_cb(self, req, res):
"""Callback for the usb_mount_point_manager service. Executes increment/decrement
actions for the mount point node name passed.
Args:
req (USBMountPointManagerSrv.Request): Request object with node_name(str)
identifying the mount point and the
action(int) flag.
res (USBMountPointManagerSrv.Response): Response object with error(int) flag
to indicate if the service call was
successful.
Returns:
USBMountPointManagerSrv.Response: Response object with error(int) flag to
indicate if the service call was successful.
"""
node_name = req.node_name
action = req.action
res.error = 0
self.get_logger().info(f"USB mount point manager callback: {node_name} {action}")
if node_name in self.mount_point_map:
if action == 0:
self.mount_point_map[node_name].ref_dec()
elif action == 1:
self.mount_point_map[node_name].ref_inc()
else:
res.error = 1
self.get_logger().error(f"Incorrect action value: {action}")
else:
res.error = 1
self.get_logger().error(f"Node name not found: {node_name}")
return res