an extensible SetUIInfo2 design
cover an extensible SetUIInfo2 design
Currently, the SetUIInfo method cannot set a refresh rate. Simply adding a refresh_rate argument would break the method signature.
This RFC adds the SetUIInfo2 method and QemuUIInfoTypes property.
* SetUIInfo2 takes a dictionary,
allowing partial updates and adding more keys in the future.
* QemuUIInfoTypes exposes the schema of SetUIInfo2's argument.
This patch is a proof-of-concept and it needs further discussion on:
* public API design (the name and the signature)
* partial update behavior (only updating the recognized fields)
* error handling (ignore the wrong keys or return an error?)
Test results:
* qemu:qtest-x86_64/dbus-display-test passed
* qemu:qtest-x86_64/dbus-vmstate-test passed
* qemu:qtest-x86_64/dbus-vnc-test SKIP
* manually created a virtual machine
and successfully set its refresh rate and resolution via SetUIInfo2
Chengyang Zhu (1):
ui/dbus: add extensible SetUIInfo2 method
ui/dbus-console.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ ui/dbus-display1.xml | 17 ++++++++++++++ 2 files changed, 73 insertions(+)
Signature · 1 line
2.55.0
RFC PATCH 1/1 ui/dbus: add extensible SetUIInfo2 method
Currently, the SetUIInfo method cannot set a refresh rate. Simply adding a refresh_rate argument would break the method signature.
This patch adds:
* An extensible SetUIInfo2 method which takes a dictionary as input.
* A property QemuUIInfoTypes
which exposes the schema of the SetUIInfo2 method's argument.
--- ui/dbus-console.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ ui/dbus-display1.xml | 17 ++++++++++++++ 2 files changed, 73 insertions(+)
ui/dbus-console.c +56 -0
@@ -217,6 +217,40 @@ dbus_console_set_ui_info(DBusDisplayConsole *ddc,return DBUS_METHOD_INVOCATION_HANDLED ; } +static gboolean +dbus_console_set_ui_info2 (DBusDisplayConsole *ddc, +GDBusMethodInvocation *invocation, +GVariant *arg_ui_info) +{ +if (!qemu_console_ui_info_supported (ddc->dcl.con)) { +g_dbus_method_invocation_return_error (invocation, +DBUS_DISPLAY_ERROR , +DBUS_DISPLAY_ERROR_UNSUPPORTED , +"SetUIInfo2 is not supported" ); +return DBUS_METHOD_INVOCATION_HANDLED ; + } + +GVariantDict ui_info_dict; +g_variant_dict_init (&ui_info_dict, arg_ui_info); + +QemuUIInfo info = *qemu_console_get_ui_info (ddc->dcl.con); + +g_variant_dict_lookup (&ui_info_dict,"width_mm" ,"q" , &info.width_mm); +g_variant_dict_lookup (&ui_info_dict,"height_mm" ,"q" , &info.height_mm); +g_variant_dict_lookup (&ui_info_dict,"xoff" ,"i" , &info.xoff); +g_variant_dict_lookup (&ui_info_dict,"yoff" ,"i" , &info.yoff); +g_variant_dict_lookup (&ui_info_dict,"width" ,"u" , &info.width); +g_variant_dict_lookup (&ui_info_dict,"height" ,"u" , &info.height); +g_variant_dict_lookup (&ui_info_dict,"refresh_rate" , +"u" , &info.refresh_rate); + +g_variant_dict_clear (&ui_info_dict); + +qemu_console_set_ui_info (ddc->dcl.con, &info, false); +qemu_dbus_display1_console_complete_set_uiinfo2 (ddc->iface, invocation); +return DBUS_METHOD_INVOCATION_HANDLED ; +} +#ifdef G_OS_WIN32 bool dbus_win32_import_socket(GDBusMethodInvocation *invocation,
@@ -538,6 +572,23 @@ QemuConsole *dbus_display_console_get_qemu_console(DBusDisplayConsole *ddc)return ddc->dcl.con; } +static GVariant *get_qemu_ui_info_types (void ) +{ +GVariantBuilder builder; + +g_variant_builder_init (&builder,G_VARIANT_TYPE ("a{sg}" )); + +g_variant_builder_add (&builder,"{sg}" ,"width_mm" ,"q" ); +g_variant_builder_add (&builder,"{sg}" ,"height_mm" ,"q" ); +g_variant_builder_add (&builder,"{sg}" ,"xoff" ,"i" ); +g_variant_builder_add (&builder,"{sg}" ,"yoff" ,"i" ); +g_variant_builder_add (&builder,"{sg}" ,"width" ,"u" ); +g_variant_builder_add (&builder,"{sg}" ,"height" ,"u" ); +g_variant_builder_add (&builder,"{sg}" ,"refresh_rate" ,"u" ); + +return g_variant_builder_end (&builder); +} +DBusDisplayConsole *dbus_display_console_new (DBusDisplay *display,QemuConsole *con) {
@@ -575,6 +626,7 @@ dbus_display_console_new(DBusDisplay *display, QemuConsole *con)"width" ,qemu_console_get_width (con,0 ),"height" ,qemu_console_get_height (con,0 ),"device-address" , device_addr, +"qemu-uiinfo-types" ,get_qemu_ui_info_types (),"interfaces" , interfaces, NULL); g_object_connect(ddc->iface,
@@ -583,6 +635,10 @@ dbus_display_console_new(DBusDisplay *display, QemuConsole *con)"swapped-signal::handle-set-uiinfo" , dbus_console_set_ui_info, ddc, NULL); +g_object_connect (ddc->iface, +"swapped-signal::handle-set-uiinfo2" , + dbus_console_set_ui_info2, ddc, +NULL );g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (ddc),G_DBUS_INTERFACE_SKELETON (ddc->iface));
ui/dbus-display1.xml +17 -0
@@ -100,6 +100,23 @@ <arg name="height" type="u" direction="in"/> </method> + <!-- + QemuUIInfoTypes: + + A D-Bus dictionary which maps the names of QemuUIInfo members to D-Bus type signatures. + --> + <property name="QemuUIInfoTypes" type="a{sg}" access="read"/> + + <!-- + SetUIInfo2: + @ui_info: the new QemuUIInfo. + + Modify the display settings. + --> + <method name="SetUIInfo2"> + <arg name="ui_info" type="a{sv}" direction="in"/> + </method> + <!-- Label:
Signature · 1 line
2.55.0
Hi Chengyang
Quoted 9 lines · Chengyang Zhu
Currently, the
SetUIInfomethod cannot set a refresh rate. Simply adding arefresh_rateargument would break the method signature.This RFC adds the
SetUIInfo2method andQemuUIInfoTypesproperty.
*SetUIInfo2takes a dictionary,
allowing partial updates and adding more keys in the future.
*QemuUIInfoTypesexposes the schema ofSetUIInfo2's argument.
Quoted 5 lines
This patch is a proof-of-concept and it needs further discussion on:
* public API design (the name and the signature)
* partial update behavior (only updating the recognized fields)
* error handling (ignore the wrong keys or return an error?)
It's an interesting design to use an extensible dict for arguments, but it's not very idiomatic or discoverable by existing tools.
Instead, can we introduce an extra interface org.qemu.Display1.UIInfo with the properties and an Apply() method that applies the staged values?
Quoted 18 lines
Test results:
* qemu:qtest-x86_64/dbus-display-test passed
* qemu:qtest-x86_64/dbus-vmstate-test passed
* qemu:qtest-x86_64/dbus-vnc-test SKIP
* manually created a virtual machine
and successfully set its refresh rate and resolution viaSetUIInfo2Chengyang Zhu (1):
ui/dbus: add extensible SetUIInfo2 methodui/dbus-console.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ ui/dbus-display1.xml | 17 ++++++++++++++ 2 files changed, 73 insertions(+)--
2.55.0