# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1224692656 25200
# Node ID 468f398f95b0d521c811f91143b1e5d8809c4a95
# Parent e53b108e82fc54142208dd48a6edd07c2eae0a68
(#2) Add input device support to device_parsing and Virt_Device.
Updates:
-Add a count value for input devcies
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r e53b108e82fc -r 468f398f95b0 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
@@ -43,6 +43,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"
@@ -77,6 +78,12 @@
free(dev->port);
}
+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)
@@ -90,6 +97,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);
@@ -455,6 +464,36 @@
return 0;
}
+static int parse_input_device(xmlNode *node, struct virt_device **vdevs)
+{
+ struct virt_device *vdev = NULL;
+ struct input_device *idev = NULL;
+
+ 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;
+ vdev->id = strdup("input");
+
+ *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;
@@ -490,6 +529,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;
@@ -558,6 +599,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;
@@ -622,6 +665,9 @@
} else if (dev->type == CIM_RES_TYPE_GRAPHICS) {
DUP_FIELD(dev, _dev, dev.graphics.type);
DUP_FIELD(dev, _dev, dev.graphics.port);
+ } else if (dev->type == CIM_RES_TYPE_INPUT) {
+ DUP_FIELD(dev, _dev, dev.input.type);
+ DUP_FIELD(dev, _dev, dev.input.bus);
}
return dev;
@@ -876,6 +922,7 @@
parse_devices(xml, &(*dominfo)->dev_emu, CIM_RES_TYPE_EMU);
parse_devices(xml, &(*dominfo)->dev_graphics, CIM_RES_TYPE_GRAPHICS);
+ 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,
diff -r e53b108e82fc -r 468f398f95b0 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
@@ -64,6 +64,11 @@
char *port;
};
+struct input_device {
+ char *type;
+ char *bus;
+};
+
struct virt_device {
uint16_t type;
union {
@@ -73,6 +78,7 @@
struct vcpu_device vcpu;
struct emu_device emu;
struct graphics_device graphics;
+ struct input_device input;
} dev;
char *id;
};
@@ -115,6 +121,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 e53b108e82fc -r 468f398f95b0 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;
}