summaryrefslogtreecommitdiff
path: root/libdevkit-power
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2008-11-07 12:26:47 +0000
committerRichard Hughes <richard@hughsie.com>2008-11-07 12:26:47 +0000
commiteded5b20fc7b609f846a46c347b25109a40191a5 (patch)
tree75a193f5d0445c27c75d3a696779450299db1978 /libdevkit-power
parentf5ea862a06a43c804fa23f289727132602c851b3 (diff)
feature: all logging for all the other device types too
Diffstat (limited to 'libdevkit-power')
-rw-r--r--libdevkit-power/dkp-object.c73
1 files changed, 39 insertions, 34 deletions
diff --git a/libdevkit-power/dkp-object.c b/libdevkit-power/dkp-object.c
index afbb6b5..fa73504 100644
--- a/libdevkit-power/dkp-object.c
+++ b/libdevkit-power/dkp-object.c
@@ -492,47 +492,52 @@ dkp_object_get_id (DkpObject *obj)
GString *string;
gchar *id = NULL;
- /* only valid for devices supplying the system */
- if (!obj->power_supply)
- return id;
-
- /* only valid for batteries */
- if (obj->type != DKP_DEVICE_TYPE_BATTERY)
- return id;
-
- /* we don't have an ID if we are not present */
- if (!obj->is_present)
- return id;
+ /* line power */
+ if (obj->type == DKP_DEVICE_TYPE_LINE_POWER) {
+ goto out;
+
+ /* batteries */
+ } else if (obj->type == DKP_DEVICE_TYPE_BATTERY) {
+ /* we don't have an ID if we are not present */
+ if (!obj->is_present)
+ goto out;
+
+ string = g_string_new ("");
+
+ /* in an ideal world, model-capacity-serial */
+ if (obj->model != NULL && strlen (obj->model) > 2) {
+ g_string_append (string, obj->model);
+ g_string_append_c (string, '-');
+ }
+ if (obj->energy_full_design > 0) {
+ g_string_append_printf (string, "%i", (guint) obj->energy_full_design);
+ g_string_append_c (string, '-');
+ }
+ if (obj->serial != NULL && strlen (obj->serial) > 2) {
+ g_string_append (string, obj->serial);
+ g_string_append_c (string, '-');
+ }
- string = g_string_new ("");
+ /* make sure we are sane */
+ if (string->len == 0) {
+ /* just use something generic */
+ g_string_append (string, "generic_id");
+ } else {
+ /* remove trailing '-' */
+ g_string_set_size (string, string->len - 1);
+ }
- /* in an ideal world, model-capacity-serial */
- if (obj->model != NULL && strlen (obj->model) > 2) {
- g_string_append (string, obj->model);
- g_string_append_c (string, '-');
- }
- if (obj->energy_full_design > 0) {
- g_string_append_printf (string, "%i", (guint) obj->energy_full_design);
- g_string_append_c (string, '-');
- }
- if (obj->serial != NULL && strlen (obj->serial) > 2) {
- g_string_append (string, obj->serial);
- g_string_append_c (string, '-');
- }
+ /* the id may have invalid chars that need to be replaced */
+ id = g_string_free (string, FALSE);
- /* make sure we are sane */
- if (string->len == 0) {
- /* just use something generic */
- g_string_append (string, "generic_id");
} else {
- /* remove trailing '-' */
- g_string_set_size (string, string->len - 1);
+ /* generic fallback */
+ id = g_strdup_printf ("%s-%s-%s", obj->vendor, obj->model, obj->serial);
}
- /* the id may have invalid chars that need to be replaced */
- id = g_string_free (string, FALSE);
- g_strdelimit (id, "\\\t\"' /", '_');
+ g_strdelimit (id, "\\\t\"?' /", '_');
+out:
return id;
}