# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1224692656 25200
# Node ID ec261be2c3eee8a81ea4c4a1e88d8282fb8bce87
# Parent d474e34c81bcc1f730db3ac0f04262cc9f7e538a
(#2) Add input device support to device_parsing and Virt_Device.
Updates:
-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 d474e34c81bc -r ec261be2c3ee 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,47 @@
return 0;
}
+static int parse_input_device(xmlNode *node, struct virt_device **vdevs)
+{
+ struct virt_device *vdev = NULL;
+ struct input_device *idev = NULL;
+ char *id;
+ 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(&id, "%s:%s", idev->type, idev->bus);
+ if (ret == -1) {
+ CU_DEBUG("Failed to create input id string");
+ free(id);
+ goto err;
+ }
+
+ vdev->id = strdup(id);
+ free(id);
+
+ *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 +552,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 +622,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 +692,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 +950,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 +1022,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 d474e34c81bc -r ec261be2c3ee 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 d474e34c81bc -r ec261be2c3ee 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,42 @@
return inst;
}
+static int input_set_attr(CMPIInstance *instance,
+ struct input_device *dev)
+{
+ uint16_t cim_type;
+
+ if (STREQC(dev->type, "mouse"))
+ cim_type = CIM_INPUT_MOUSE;
+ else
+ cim_type = CIM_INPUT_UNKNOWN;
+
+ CMSetProperty(instance, "PointingType",
+ (CMPIValue *)&cim_type, CMPI_uint16);
+
+ 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 +397,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 +436,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;
}