On 10/28/21 17:54, Daniel P. Berrangé wrote:
> This provides a foundation on which to convert simple HMP commands to
> use QMP. The QMP implementation will generate formatted text targeted
> for human consumption, returning it in the HumanReadableText data type.
>
> The HMP command handler will simply print out the formatted string
> within the HumanReadableText data type. Since this will be an entirely
> formulaic action in the case of HMP commands taking no arguemnts, a
> custom command handler is provided.
>
> Thus instead of registering a 'cmd' callback for the HMP command, a
> 'cmd_info_hrt' callback is provided, which will simply be a pointer
> to the QMP implementation.
>
> Signed-off-by: Daniel P. Berrangé <[email protected]>
> ---
> include/monitor/hmp.h | 3 +++
> include/monitor/monitor.h | 2 ++
> include/qapi/type-helpers.h | 14 ++++++++++++++
> monitor/hmp.c | 31 ++++++++++++++++++++++++++++---
> monitor/misc.c | 18 +++++++++++++++++-
> monitor/monitor-internal.h | 7 +++++++
> qapi/common.json | 11 +++++++++++
> qapi/meson.build | 3 +++
> qapi/qapi-type-helpers.c | 23 +++++++++++++++++++++++
> 9 files changed, 108 insertions(+), 4 deletions(-)
> create mode 100644 include/qapi/type-helpers.h
> create mode 100644 qapi/qapi-type-helpers.c
> diff --git a/monitor/hmp.c b/monitor/hmp.c
> index d50c3124e1..352a4d9c80 100644
> --- a/monitor/hmp.c
> +++ b/monitor/hmp.c
> @@ -1061,6 +1061,31 @@ fail:
> return NULL;
> }
>
> +static void hmp_info_human_readable_text(Monitor *mon,
> + HumanReadableText *(*handler)(Error
> **))
> +{
> + Error *err = NULL;
> + g_autoptr(HumanReadableText) info = handler(&err);
> +
> + if (hmp_handle_error(mon, err)) {
> + return;
> + }
> +
> + monitor_printf(mon, "%s", info->human_readable_text);
> +}
Missing:
-- >8 --
diff --git a/monitor/hmp.c b/monitor/hmp.c
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -35,6 +35,7 @@
#include "qemu/log.h"
#include "qemu/option.h"
#include "qemu/units.h"
+#include "monitor/hmp.h"
#include "sysemu/block-backend.h"
#include "sysemu/runstate.h"
#include "trace.h"
---
to avoid:
monitor/hmp.c: In function ‘hmp_info_human_readable_text’:
monitor/hmp.c:1070:9: error: implicit declaration of function
‘hmp_handle_error’ [-Werror=implicit-function-declaration]
1070 | if (hmp_handle_error(mon, err)) {
| ^~~~~~~~~~~~~~~~
monitor/hmp.c:1070:9: error: nested extern declaration of
‘hmp_handle_error’ [-Werror=nested-externs]
cc1: all warnings being treated as errors