summaryrefslogtreecommitdiff
path: root/src/dkp-hid.c
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2008-08-13 08:08:29 +0100
committerRichard Hughes <richard@hughsie.com>2008-08-13 08:08:29 +0100
commit3a468e7521425a347168f44030ac25acbbd7d3ac (patch)
tree20b367bbdbd3e45461f32c11c23b008e8d1f5f7e /src/dkp-hid.c
parenta104eb55192286317288d8fa4f708784e2983956 (diff)
only match on USB HID devices so we don't try to connect to every USB device on the system at startup
Diffstat (limited to 'src/dkp-hid.c')
-rw-r--r--src/dkp-hid.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/dkp-hid.c b/src/dkp-hid.c
index 949bc7d..e154c7f 100644
--- a/src/dkp-hid.c
+++ b/src/dkp-hid.c
@@ -277,6 +277,7 @@ dkp_hid_coldplug (DkpDevice *device)
DevkitDevice *d;
gboolean ret = FALSE;
const gchar *device_file;
+ const gchar *type;
DkpObject *obj = dkp_device_get_obj (device);
/* detect what kind of device we are */
@@ -284,6 +285,13 @@ dkp_hid_coldplug (DkpDevice *device)
if (d == NULL)
dkp_error ("could not get device");
+ /* get the type */
+ type = devkit_device_get_property (d, "ID_BATTERY_TYPE");
+ if (type == NULL || strcmp (type, "ups") != 0) {
+ dkp_debug ("not a UPS device");
+ goto out;
+ }
+
/* get the device file */
device_file = devkit_device_get_device_file (d);
if (device_file == NULL) {
@@ -311,11 +319,16 @@ dkp_hid_coldplug (DkpDevice *device)
obj->power_supply = TRUE;
obj->battery_is_present = TRUE;
+ /* try and get from udev if UPS is being difficult */
+ if (obj->vendor == NULL)
+ obj->vendor = g_strdup (devkit_device_get_property (d, "ID_VENDOR"));
+
/* coldplug everything */
dkp_hid_get_all_data (hid);
/* coldplug */
ret = dkp_hid_refresh (device);
+
out:
return ret;
}
@@ -326,6 +339,7 @@ out:
static gboolean
dkp_hid_refresh (DkpDevice *device)
{
+ gboolean set = FALSE;
gboolean ret = FALSE;
GTimeVal time;
guint i;
@@ -338,14 +352,21 @@ dkp_hid_refresh (DkpDevice *device)
g_get_current_time (&time);
obj->update_time = time.tv_sec;
- /* read any data */
+ /* read any data -- it's okay if there's nothing as we are non-blocking */
rd = read (hid->priv->fd, ev, sizeof (ev));
- if (rd < (int) sizeof (ev[0]))
+ if (rd < (int) sizeof (ev[0])) {
+ ret = TRUE;
goto out;
+ }
/* process each event */
- for (i=0; i < rd / sizeof (ev[0]); i++)
- ret = dkp_hid_set_obj (hid, ev[i].hid, ev[i].value);
+ for (i=0; i < rd / sizeof (ev[0]); i++) {
+ set = dkp_hid_set_obj (hid, ev[i].hid, ev[i].value);
+
+ /* if only takes one match to make refresh a success */
+ if (set)
+ ret = TRUE;
+ }
out:
return ret;
}