From: Oleksandr Grytsov
Add getting vsnd list amd info API
Signed-off-by: Oleksandr Grytsov
---
tools/libxl/libxl.h | 10 ++
tools/libxl/libxl_types.idl | 19 +++
tools/libxl/libxl_utils.h | 3 +
tools/libxl/libxl_vsnd.c| 359 +++-
4 files changed, 388 insertions(+), 3 deletions(-)
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index 7200d49..acb73ce 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -1927,6 +1927,16 @@ int libxl_device_vsnd_destroy(libxl_ctx *ctx, uint32_t
domid,
const libxl_asyncop_how *ao_how)
LIBXL_EXTERNAL_CALLERS_ONLY;
+libxl_device_vsnd *libxl_device_vsnd_list(libxl_ctx *ctx,
+ uint32_t domid, int *num)
+ LIBXL_EXTERNAL_CALLERS_ONLY;
+void libxl_device_vsnd_list_free(libxl_device_vsnd* list, int num)
+ LIBXL_EXTERNAL_CALLERS_ONLY;
+int libxl_device_vsnd_getinfo(libxl_ctx *ctx, uint32_t domid,
+ libxl_device_vsnd *vsnd,
+ libxl_vsndinfo *vsndlinfo)
+ LIBXL_EXTERNAL_CALLERS_ONLY;
+
/* Keyboard */
int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb,
const libxl_asyncop_how *ao_how)
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index fb3e5e8..cd0c06f 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -988,6 +988,25 @@ libxl_vdisplinfo = Struct("vdisplinfo", [
("connectors", Array(libxl_connectorinfo, "num_connectors"))
], dir=DIR_OUT)
+libxl_streaminfo = Struct("streaminfo", [
+("req_evtch", integer),
+("req_rref", integer)
+])
+
+libxl_pcminfo = Struct("pcminfo", [
+("streams", Array(libxl_streaminfo, "num_vsnd_streams"))
+])
+
+libxl_vsndinfo = Struct("vsndinfo", [
+("backend", string),
+("backend_id", uint32),
+("frontend", string),
+("frontend_id", uint32),
+("devid", libxl_devid),
+("state", integer),
+("pcms", Array(libxl_pcminfo, "num_vsnd_pcms"))
+])
+
# NUMA node characteristics: size and free are how much memory it has, and how
# much of it is free, respectively. dists is an array of distances from this
# node to each other node.
diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h
index 9e743dc..5455752 100644
--- a/tools/libxl/libxl_utils.h
+++ b/tools/libxl/libxl_utils.h
@@ -82,6 +82,9 @@ int libxl_devid_to_device_usbctrl(libxl_ctx *ctx, uint32_t
domid,
int libxl_devid_to_device_vdispl(libxl_ctx *ctx, uint32_t domid,
int devid, libxl_device_vdispl *vdispl);
+int libxl_devid_to_device_vsnd(libxl_ctx *ctx, uint32_t domid,
+ int devid, libxl_device_vsnd *vsnd);
+
int libxl_ctrlport_to_device_usbdev(libxl_ctx *ctx, uint32_t domid,
int ctrl, int port,
libxl_device_usbdev *usbdev);
diff --git a/tools/libxl/libxl_vsnd.c b/tools/libxl/libxl_vsnd.c
index 26885f9..0e7b29c 100644
--- a/tools/libxl/libxl_vsnd.c
+++ b/tools/libxl/libxl_vsnd.c
@@ -37,20 +37,239 @@ static int libxl__device_from_vsnd(libxl__gc *gc, uint32_t
domid,
return 0;
}
+static int libxl__sample_rates_from_string(libxl__gc *gc, const char *str,
+ libxl_vsnd_params *params)
+{
+char *tmp = libxl__strdup(gc, str);
+
+params->num_sample_rates = 0;
+params->sample_rates = NULL;
+
+char *p = strtok(tmp, " ,");
+
+while (p != NULL) {
+params->sample_rates = realloc(params->sample_rates,
+ sizeof(*params->sample_rates) *
+ (params->num_sample_rates + 1));
+params->sample_rates[params->num_sample_rates++] = strtoul(p, NULL, 0);
+p = strtok(NULL, " ,");
+}
+
+return 0;
+}
+
+static int libxl__sample_formats_from_string(libxl__gc *gc, const char *str,
+ libxl_vsnd_params *params)
+{
+int rc;
+char *tmp = libxl__strdup(gc, str);
+
+params->num_sample_formats = 0;
+params->sample_formats = NULL;
+
+char *p = strtok(tmp, " ,");
+
+while (p != NULL) {
+params->sample_formats = realloc(params->sample_formats,
+ sizeof(*params->sample_formats) *
+ (params->num_sample_formats + 1));
+
+libxl_vsnd_pcm_format format;
+
+rc = libxl_vsnd_pcm_format_from_string(p, &format);
+if (rc) return rc;
+
+params->sample_formats[params->num_sample_formats++] = format;
+p = strtok(NULL, " ,");
+}
+
+return 0;
+}
+
+static int libxl__params_from_xenstore(libxl__gc *gc, const char *path,
+