# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1224692656 25200
# Node ID 060658b608bf91bb8495690c693e05d34ac8a028
# Parent 010da4fc9cdcb1452cfb21de6d7c9e18037a10d9
(#3) Add input device support to device_parsing and Virt_Device.
Updates from 2 to 3:
-Set tablet devices to have mouse device type
-Set vdev->id directly using asprintf()
Updates from 1 to 2:
-Add a count value for input devcies
-Change ID value from "input" to "device type:bus type"
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r 010da4fc9cdc -r 060658b608bf libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c Wed Oct 22 09:24:16 2008 -0700
+++ b/libxkutil/device_parsing.c Wed Oct 22 09:24:16 2008 -0700
@@ -44,6 +44,7 @@
#define EMU_XPATH (xmlChar *)"/domain/devices/emulator"
#define MEM_XPATH (xmlChar *)"/domain/memory | /domain/currentMemory"
#define GRAPHICS_XPATH (xmlChar *)"/domain/devices/graphics"
+#define INPUT_XPATH (xmlChar *)"/domain/devices/input"
#define DEFAULT_BRIDGE "xenbr0"
#define DEFAULT_NETWORK "default"
@@ -80,6 +81,12 @@
free(dev->keymap);
}
+static void cleanup_input_device(struct input_device *dev)
+{
+ free(dev->type);
+ free(dev->bus);
+}
+
void cleanup_virt_device(struct virt_device *dev)
{
if (dev == NULL)
@@ -93,6 +100,8 @@
cleanup_emu_device(&dev->dev.emu);
else if (dev->type == CIM_RES_TYPE_GRAPHICS)
cleanup_graphics_device(&dev->dev.graphics);
+ else if (dev->type == CIM_RES_TYPE_INPUT)
+ cleanup_input_device(&dev->dev.input);
free(dev->id);
@@ -467,6 +476,42 @@
return 0;
}
+static int parse_input_device(xmlNode *node, struct virt_device **vdevs)
+{
+ struct virt_device *vdev = NULL;
+ struct input_device *idev = NULL;
+ int ret;
+
+ vdev = calloc(1, sizeof(*vdev));
+ if (vdev == NULL)
+ goto err;
+
+ idev = &(vdev->dev.input);
+
+ idev->type = get_attr_value(node, "type");
+ idev->bus = get_attr_value(node, "bus");
+
+ if ((idev->type == NULL) || (idev->bus == NULL))
+ goto err;
+
+ vdev->type = CIM_RES_TYPE_INPUT;
+
+ ret = asprintf(&vdev->id, "%s:%s", idev->type,
idev->bus);
+ if (ret == -1) {
+ CU_DEBUG("Failed to create input id string");
+ goto err;
+ }
+
+ *vdevs = vdev;
+
+ return 1;
+ err:
+ cleanup_input_device(idev);
+ free(vdev);
+
+ return 0;
+}
+
static bool resize_devlist(struct virt_device **list, int newsize)
{
struct virt_device *_list;
@@ -502,6 +547,8 @@
do_real_parse = parse_mem_device;
else if (type == CIM_RES_TYPE_GRAPHICS)
do_real_parse = parse_graphics_device;
+ else if (type == CIM_RES_TYPE_INPUT)
+ do_real_parse = parse_input_device;
else
goto out;
@@ -570,6 +617,8 @@
xpathstr = MEM_XPATH;
else if (type == CIM_RES_TYPE_GRAPHICS)
xpathstr = GRAPHICS_XPATH;
+ else if (type == CIM_RES_TYPE_INPUT)
+ xpathstr = INPUT_XPATH;
else
goto err1;
@@ -638,6 +687,9 @@
DUP_FIELD(dev, _dev, dev.graphics.port);
DUP_FIELD(dev, _dev, dev.graphics.host);
DUP_FIELD(dev, _dev, dev.graphics.keymap);
+ } else if (dev->type == CIM_RES_TYPE_INPUT) {
+ DUP_FIELD(dev, _dev, dev.input.type);
+ DUP_FIELD(dev, _dev, dev.input.bus);
}
return dev;
@@ -893,6 +945,9 @@
parse_devices(xml, &(*dominfo)->dev_emu, CIM_RES_TYPE_EMU);
parse_devices(xml, &(*dominfo)->dev_graphics, CIM_RES_TYPE_GRAPHICS);
+ (*dominfo)->dev_input_ct = parse_devices(xml,
+ &(*dominfo)->dev_input,
+ CIM_RES_TYPE_INPUT);
(*dominfo)->dev_mem_ct = _get_mem_device(xml, &(*dominfo)->dev_mem);
(*dominfo)->dev_net_ct = parse_devices(xml,
&(*dominfo)->dev_net,
@@ -962,6 +1017,7 @@
cleanup_virt_devices(&dom->dev_net, dom->dev_net_ct);
cleanup_virt_devices(&dom->dev_disk, dom->dev_disk_ct);
cleanup_virt_devices(&dom->dev_vcpu, dom->dev_vcpu_ct);
+ cleanup_virt_devices(&dom->dev_input, dom->dev_input_ct);
free(dom);
diff -r 010da4fc9cdc -r 060658b608bf libxkutil/device_parsing.h
--- a/libxkutil/device_parsing.h Wed Oct 22 09:24:16 2008 -0700
+++ b/libxkutil/device_parsing.h Wed Oct 22 09:24:16 2008 -0700
@@ -69,6 +69,11 @@
char *keymap;
};
+struct input_device {
+ char *type;
+ char *bus;
+};
+
struct virt_device {
uint16_t type;
union {
@@ -78,6 +83,7 @@
struct vcpu_device vcpu;
struct emu_device emu;
struct graphics_device graphics;
+ struct input_device input;
} dev;
char *id;
};
@@ -120,6 +126,9 @@
struct virt_device *dev_graphics;
struct virt_device *dev_emu;
+
+ struct virt_device *dev_input;
+ int dev_input_ct;
struct virt_device *dev_mem;
int dev_mem_ct;
diff -r 010da4fc9cdc -r 060658b608bf src/Virt_Device.c
--- a/src/Virt_Device.c Wed Oct 22 09:24:16 2008 -0700
+++ b/src/Virt_Device.c Wed Oct 22 09:24:16 2008 -0700
@@ -39,6 +39,9 @@
#define CIM_NET_UNKNOWN 0
#define CIM_NET_ETHERNET 2
+
+#define CIM_INPUT_UNKNOWN 2
+#define CIM_INPUT_MOUSE 3
const static CMPIBroker *_BROKER;
const static uint64_t XEN_MEM_BLOCKSIZE = 4096;
@@ -214,6 +217,85 @@
return inst;
}
+int get_input_dev_caption(const char *type,
+ const char *bus,
+ char **cap)
+{
+ int ret;
+ const char *type_str;
+ const char *bus_str;
+
+ if (STREQC(type, "mouse"))
+ type_str = "Mouse";
+ else if (STREQC(type, "tablet"))
+ type_str = "Tablet";
+ else
+ type_str = "Unknown device type";
+
+ if (STREQC(bus, "usb"))
+ bus_str = "USB";
+ else if (STREQC(bus, "ps2"))
+ bus_str = "PS2";
+ else
+ bus_str = "Unknown bus";
+
+ ret = asprintf(cap, "%s %s", bus_str, type_str);
+ if (ret == -1) {
+ CU_DEBUG("Failed to create input id string");
+ return 0;
+ }
+
+ return 1;
+}
+
+static int input_set_attr(CMPIInstance *instance,
+ struct input_device *dev)
+{
+ uint16_t cim_type;
+ char *cap;
+ int rc;
+
+ if ((STREQC(dev->type, "mouse")) || (STREQC(dev->type,
"tablet")))
+ cim_type = CIM_INPUT_MOUSE;
+ else
+ cim_type = CIM_INPUT_UNKNOWN;
+
+ rc = get_input_dev_caption(dev->type, dev->bus, &cap);
+ if (rc != 1) {
+ free(cap);
+ return 0;
+ }
+
+ CMSetProperty(instance, "PointingType",
+ (CMPIValue *)&cim_type, CMPI_uint16);
+
+ CMSetProperty(instance, "Caption", (CMPIValue *)cap, CMPI_chars);
+
+ free(cap);
+
+ return 1;
+}
+
+static CMPIInstance *input_instance(const CMPIBroker *broker,
+ struct input_device *dev,
+ const virDomainPtr dom,
+ const char *ns)
+{
+ CMPIInstance *inst;
+ virConnectPtr conn;
+
+ conn = virDomainGetConnect(dom);
+ inst = get_typed_instance(broker,
+ pfx_from_conn(conn),
+ "PointingDevice",
+ ns);
+
+ if (!input_set_attr(inst, dev))
+ return NULL;
+
+ return inst;
+}
+
static int device_set_devid(CMPIInstance *instance,
struct virt_device *dev,
const virDomainPtr dom)
@@ -358,6 +440,11 @@
&dev->dev.graphics,
dom,
ns);
+ else if (dev->type == CIM_RES_TYPE_INPUT)
+ instance = input_instance(broker,
+ &dev->dev.input,
+ dom,
+ ns);
else
return false;
@@ -392,6 +479,8 @@
return CIM_RES_TYPE_PROC;
else if (strstr(classname, "DisplayController"))
return CIM_RES_TYPE_GRAPHICS;
+ else if (strstr(classname, "PointingDevice"))
+ return CIM_RES_TYPE_INPUT;
else
return CIM_RES_TYPE_UNKNOWN;
}
diff -r 010da4fc9cdc -r 060658b608bf src/Virt_Device.h
--- a/src/Virt_Device.h Wed Oct 22 09:24:16 2008 -0700
+++ b/src/Virt_Device.h Wed Oct 22 09:24:16 2008 -0700
@@ -71,6 +71,10 @@
uint16_t res_type_from_device_classname(const char *classname);
+int get_input_dev_caption(const char *type,
+ const char *bus,
+ char **cap);
+
#endif
/*