console: add & use qemu_console_lookup_by_device_name
We have two places needing this, and a third one will come shortly. So factor things out into a helper function to reduce code duplication. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Daniel P. Berrange <berrange@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
		
							parent
							
								
									071608b519
								
							
						
					
					
						commit
						f2c1d54c18
					
				@ -378,6 +378,8 @@ void graphic_hw_gl_block(QemuConsole *con, bool block);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
QemuConsole *qemu_console_lookup_by_index(unsigned int index);
 | 
					QemuConsole *qemu_console_lookup_by_index(unsigned int index);
 | 
				
			||||||
QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head);
 | 
					QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head);
 | 
				
			||||||
 | 
					QemuConsole *qemu_console_lookup_by_device_name(const char *device_id,
 | 
				
			||||||
 | 
					                                                uint32_t head, Error **errp);
 | 
				
			||||||
bool qemu_console_is_visible(QemuConsole *con);
 | 
					bool qemu_console_is_visible(QemuConsole *con);
 | 
				
			||||||
bool qemu_console_is_graphic(QemuConsole *con);
 | 
					bool qemu_console_is_graphic(QemuConsole *con);
 | 
				
			||||||
bool qemu_console_is_fixedsize(QemuConsole *con);
 | 
					bool qemu_console_is_fixedsize(QemuConsole *con);
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										23
									
								
								ui/console.c
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								ui/console.c
									
									
									
									
									
								
							@ -1790,6 +1790,29 @@ QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head)
 | 
				
			|||||||
    return NULL;
 | 
					    return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					QemuConsole *qemu_console_lookup_by_device_name(const char *device_id,
 | 
				
			||||||
 | 
					                                                uint32_t head, Error **errp)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    DeviceState *dev;
 | 
				
			||||||
 | 
					    QemuConsole *con;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    dev = qdev_find_recursive(sysbus_get_default(), device_id);
 | 
				
			||||||
 | 
					    if (dev == NULL) {
 | 
				
			||||||
 | 
					        error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
 | 
				
			||||||
 | 
					                  "Device '%s' not found", device_id);
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    con = qemu_console_lookup_by_device(dev, head);
 | 
				
			||||||
 | 
					    if (con == NULL) {
 | 
				
			||||||
 | 
					        error_setg(errp, "Device %s (head %d) is not bound to a QemuConsole",
 | 
				
			||||||
 | 
					                   device_id, head);
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return con;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool qemu_console_is_visible(QemuConsole *con)
 | 
					bool qemu_console_is_visible(QemuConsole *con)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return (con == active_console) || (con->dcls > 0);
 | 
					    return (con == active_console) || (con->dcls > 0);
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										15
									
								
								ui/input.c
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								ui/input.c
									
									
									
									
									
								
							@ -82,19 +82,12 @@ void qemu_input_handler_bind(QemuInputHandlerState *s,
 | 
				
			|||||||
                             const char *device_id, int head,
 | 
					                             const char *device_id, int head,
 | 
				
			||||||
                             Error **errp)
 | 
					                             Error **errp)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    DeviceState *dev;
 | 
					 | 
				
			||||||
    QemuConsole *con;
 | 
					    QemuConsole *con;
 | 
				
			||||||
 | 
					    Error *err = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    dev = qdev_find_recursive(sysbus_get_default(), device_id);
 | 
					    con = qemu_console_lookup_by_device_name(device_id, head, &err);
 | 
				
			||||||
    if (dev == NULL) {
 | 
					    if (err) {
 | 
				
			||||||
        error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
 | 
					        error_propagate(errp, err);
 | 
				
			||||||
                  "Device '%s' not found", device_id);
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    con = qemu_console_lookup_by_device(dev, head);
 | 
					 | 
				
			||||||
    if (con == NULL) {
 | 
					 | 
				
			||||||
        error_setg(errp, "Device %s is not bound to a QemuConsole", device_id);
 | 
					 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										15
									
								
								ui/vnc.c
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								ui/vnc.c
									
									
									
									
									
								
							@ -3732,19 +3732,12 @@ void vnc_display_open(const char *id, Error **errp)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    device_id = qemu_opt_get(opts, "display");
 | 
					    device_id = qemu_opt_get(opts, "display");
 | 
				
			||||||
    if (device_id) {
 | 
					    if (device_id) {
 | 
				
			||||||
        DeviceState *dev;
 | 
					 | 
				
			||||||
        int head = qemu_opt_get_number(opts, "head", 0);
 | 
					        int head = qemu_opt_get_number(opts, "head", 0);
 | 
				
			||||||
 | 
					        Error *err = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        dev = qdev_find_recursive(sysbus_get_default(), device_id);
 | 
					        con = qemu_console_lookup_by_device_name(device_id, head, &err);
 | 
				
			||||||
        if (dev == NULL) {
 | 
					        if (err) {
 | 
				
			||||||
            error_setg(errp, "Device '%s' not found", device_id);
 | 
					            error_propagate(errp, err);
 | 
				
			||||||
            goto fail;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        con = qemu_console_lookup_by_device(dev, head);
 | 
					 | 
				
			||||||
        if (con == NULL) {
 | 
					 | 
				
			||||||
            error_setg(errp, "Device %s is not bound to a QemuConsole",
 | 
					 | 
				
			||||||
                       device_id);
 | 
					 | 
				
			||||||
            goto fail;
 | 
					            goto fail;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user