diff options
author | Richard Hughes <richard@hughsie.com> | 2008-11-07 12:26:47 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2008-11-07 12:26:47 +0000 |
commit | eded5b20fc7b609f846a46c347b25109a40191a5 (patch) | |
tree | 75a193f5d0445c27c75d3a696779450299db1978 /src | |
parent | f5ea862a06a43c804fa23f289727132602c851b3 (diff) |
feature: all logging for all the other device types too
Diffstat (limited to 'src')
-rw-r--r-- | src/95-devkit-power-wup.rules | 3 | ||||
-rw-r--r-- | src/dkp-csr.c | 7 | ||||
-rw-r--r-- | src/dkp-device.c | 63 | ||||
-rw-r--r-- | src/dkp-device.h | 5 | ||||
-rw-r--r-- | src/dkp-hid.c | 2 | ||||
-rw-r--r-- | src/dkp-history.c | 9 | ||||
-rw-r--r-- | src/dkp-supply.c | 71 | ||||
-rw-r--r-- | src/dkp-wup.c | 4 |
8 files changed, 70 insertions, 94 deletions
diff --git a/src/95-devkit-power-wup.rules b/src/95-devkit-power-wup.rules index 023503b..90b9f88 100644 --- a/src/95-devkit-power-wup.rules +++ b/src/95-devkit-power-wup.rules @@ -1,6 +1,5 @@ ############################################################################################################## # Watts Up? Pro Devices # -ATTR{idVendor}=="0000", ENV{ID_VENDOR}="Watts Up, Inc." -ATTR{idVendor}=="0403", ATTR{idProduct}=="6001", ATTR{serial}=="A80????G", ENV{ID_PRODUCT}="Watts Up? Pro", ENV{DKP_MONITOR_TYPE}="wup" +ATTR{idVendor}=="0403", ATTR{idProduct}=="6001", ATTR{serial}=="A80????G", ENV{ID_VENDOR}="Watts Up, Inc.", ENV{ID_PRODUCT}="Watts Up? Pro", ENV{DKP_MONITOR_TYPE}="wup" diff --git a/src/dkp-csr.c b/src/dkp-csr.c index 8315ad2..79ffb8a 100644 --- a/src/dkp-csr.c +++ b/src/dkp-csr.c @@ -71,10 +71,10 @@ G_DEFINE_TYPE (DkpCsr, dkp_csr, DKP_TYPE_DEVICE) static gboolean dkp_csr_refresh (DkpDevice *device); /** - * dkp_csr_poll: + * dkp_csr_poll_cb: **/ static gboolean -dkp_csr_poll (DkpCsr *csr) +dkp_csr_poll_cb (DkpCsr *csr) { gboolean ret; DkpDevice *device = DKP_DEVICE (csr); @@ -192,6 +192,7 @@ dkp_csr_coldplug (DkpDevice *device) obj->is_present = TRUE; obj->is_rechargeable = TRUE; obj->state = DKP_DEVICE_STATE_DISCHARGING; + obj->has_history = TRUE; /* coldplug */ ret = dkp_csr_refresh (device); @@ -200,7 +201,7 @@ dkp_csr_coldplug (DkpDevice *device) /* set up a poll */ csr->priv->poll_timer_id = g_timeout_add_seconds (DKP_CSR_REFRESH_TIMEOUT, - (GSourceFunc) dkp_csr_poll, csr); + (GSourceFunc) dkp_csr_poll_cb, csr); out: return ret; diff --git a/src/dkp-device.c b/src/dkp-device.c index 903fbfe..c1ae6e6 100644 --- a/src/dkp-device.c +++ b/src/dkp-device.c @@ -36,11 +36,12 @@ #include "sysfs-utils.h" #include "egg-debug.h" +#include "egg-string.h" #include "egg-obj-list.h" #include "dkp-supply.h" #include "dkp-device.h" -#include "dkp-device.h" +#include "dkp-history.h" #include "dkp-history-obj.h" #include "dkp-stats-obj.h" #include "dkp-marshal.h" @@ -52,6 +53,7 @@ struct DkpDevicePrivate DBusGConnection *system_bus_connection; DBusGProxy *system_bus_proxy; DkpDaemon *daemon; + DkpHistory *history; DevkitDevice *d; DkpObject *obj; gboolean has_ever_refresh; @@ -292,6 +294,7 @@ dkp_device_coldplug (DkpDevice *device, DkpDaemon *daemon, DevkitDevice *d) gboolean ret; const gchar *native_path; DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device); + gchar *id; g_return_val_if_fail (DKP_IS_DEVICE (device), FALSE); @@ -317,6 +320,12 @@ dkp_device_coldplug (DkpDevice *device, DkpDaemon *daemon, DevkitDevice *d) if (!ret) goto out; + /* get the id so we can load the old history */ + id = dkp_object_get_id (device->priv->obj); + if (id != NULL) + dkp_history_set_id (device->priv->history, id); + g_free (id); + out: return ret; } @@ -327,7 +336,6 @@ out: gboolean dkp_device_get_statistics (DkpDevice *device, const gchar *type, DBusGMethodInvocation *context) { - DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device); GError *error; EggObjList *array = NULL; GPtrArray *complex; @@ -336,15 +344,21 @@ dkp_device_get_statistics (DkpDevice *device, const gchar *type, DBusGMethodInvo guint i; g_return_val_if_fail (DKP_IS_DEVICE (device), FALSE); + g_return_val_if_fail (type != NULL, FALSE); /* doesn't even try to support this */ - if (klass->get_stats == NULL) { + if (!device->priv->obj->has_statistics) { error = g_error_new (DKP_DAEMON_ERROR, DKP_DAEMON_ERROR_GENERAL, "device does not support getting stats"); dbus_g_method_return_error (context, error); goto out; } - array = klass->get_stats (device, type); + /* get the correct data */ + if (egg_strequal (type, "charging")) + array = dkp_history_get_profile_data (device->priv->history, TRUE); + else if (egg_strequal (type, "discharging")) + array = dkp_history_get_profile_data (device->priv->history, FALSE); + /* maybe the device doesn't support histories */ if (array == NULL) { error = g_error_new (DKP_DAEMON_ERROR, DKP_DAEMON_ERROR_GENERAL, "device has no statistics"); @@ -382,27 +396,41 @@ out: * dkp_device_get_history: **/ gboolean -dkp_device_get_history (DkpDevice *device, const gchar *type, guint timespan, DBusGMethodInvocation *context) +dkp_device_get_history (DkpDevice *device, const gchar *type_string, guint timespan, DBusGMethodInvocation *context) { - DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device); GError *error; EggObjList *array = NULL; GPtrArray *complex; const DkpHistoryObj *obj; GValue *value; guint i; + DkpHistoryType type = DKP_HISTORY_TYPE_UNKNOWN; g_return_val_if_fail (DKP_IS_DEVICE (device), FALSE); + g_return_val_if_fail (type_string != NULL, FALSE); /* doesn't even try to support this */ - if (klass->get_history == NULL) { + if (!device->priv->obj->has_history) { error = g_error_new (DKP_DAEMON_ERROR, DKP_DAEMON_ERROR_GENERAL, "device does not support getting history"); dbus_g_method_return_error (context, error); goto out; } - array = klass->get_history (device, type, timespan); - /* maybe the device doesn't support histories */ + /* get the correct data */ + if (egg_strequal (type_string, "rate")) + type = DKP_HISTORY_TYPE_RATE; + else if (egg_strequal (type_string, "charge")) + type = DKP_HISTORY_TYPE_CHARGE; + else if (egg_strequal (type_string, "time-full")) + type = DKP_HISTORY_TYPE_TIME_FULL; + else if (egg_strequal (type_string, "time-empty")) + type = DKP_HISTORY_TYPE_TIME_EMPTY; + + /* something recognised */ + if (type != DKP_HISTORY_TYPE_UNKNOWN) + array = dkp_history_get_data (device->priv->history, type, timespan); + + /* maybe the device doesn't have any history */ if (array == NULL) { error = g_error_new (DKP_DAEMON_ERROR, DKP_DAEMON_ERROR_GENERAL, "device has no history"); dbus_g_method_return_error (context, error); @@ -445,11 +473,14 @@ dkp_device_refresh_internal (DkpDevice *device) /* do the refresh */ success = klass->refresh (device); - if (!success) + if (!success) { + egg_warning ("failed to reresh"); goto out; + } /* the first time, print all properties */ if (!device->priv->has_ever_refresh) { + egg_debug ("iniital fillup"); dkp_object_print (obj); device->priv->has_ever_refresh = TRUE; goto out; @@ -459,6 +490,7 @@ dkp_device_refresh_internal (DkpDevice *device) ret = !dkp_object_equal (obj, obj_old); if (ret) dkp_object_diff (obj_old, obj); + out: dkp_object_free (obj_old); return success; @@ -536,8 +568,17 @@ dkp_device_get_d (DkpDevice *device) void dkp_device_emit_changed (DkpDevice *device) { + DkpObject *obj = dkp_device_get_obj (device); + g_return_if_fail (DKP_IS_DEVICE (device)); + /* save new history */ + dkp_history_set_state (device->priv->history, obj->state); + dkp_history_set_charge_data (device->priv->history, obj->percentage); + dkp_history_set_rate_data (device->priv->history, obj->energy_rate); + dkp_history_set_time_full_data (device->priv->history, obj->time_to_full); + dkp_history_set_time_empty_data (device->priv->history, obj->time_to_empty); + egg_debug ("emitting changed on %s", device->priv->obj->native_path); g_signal_emit_by_name (device->priv->daemon, "device-changed", device->priv->object_path, NULL); @@ -616,6 +657,7 @@ dkp_device_init (DkpDevice *device) device->priv->d = NULL; device->priv->has_ever_refresh = FALSE; device->priv->obj = dkp_object_new (); + device->priv->history = dkp_history_new (); device->priv->system_bus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (device->priv->system_bus_connection == NULL) { @@ -639,6 +681,7 @@ dkp_device_finalize (GObject *object) g_return_if_fail (device->priv != NULL); g_object_unref (device->priv->d); g_object_unref (device->priv->daemon); + g_object_unref (device->priv->history); dkp_object_free (device->priv->obj); G_OBJECT_CLASS (dkp_device_parent_class)->finalize (object); diff --git a/src/dkp-device.h b/src/dkp-device.h index 6b90316..d4d1d12 100644 --- a/src/dkp-device.h +++ b/src/dkp-device.h @@ -61,11 +61,6 @@ typedef struct gboolean *on_battery); gboolean (*get_low_battery) (DkpDevice *device, gboolean *low_battery); - EggObjList *(*get_history) (DkpDevice *device, - const gchar *type, - guint timespan); - EggObjList *(*get_stats) (DkpDevice *device, - const gchar *type); } DkpDeviceClass; typedef enum diff --git a/src/dkp-hid.c b/src/dkp-hid.c index 90320fc..64b6869 100644 --- a/src/dkp-hid.c +++ b/src/dkp-hid.c @@ -334,6 +334,8 @@ dkp_hid_coldplug (DkpDevice *device) obj->is_rechargeable = TRUE; obj->power_supply = TRUE; obj->is_present = TRUE; + obj->has_history = TRUE; + obj->has_statistics = TRUE; /* try and get from udev if UPS is being difficult */ if (obj->vendor == NULL) diff --git a/src/dkp-history.c b/src/dkp-history.c index 75fc26c..513a9ad 100644 --- a/src/dkp-history.c +++ b/src/dkp-history.c @@ -179,6 +179,7 @@ dkp_history_copy_array_timespan (const EggObjList *array, guint timespan) /* treat the timespan like a range, and search backwards */ obj = (const DkpHistoryObj *) egg_obj_list_index (array, array->len-1); start = obj->time; + timespan *= 0.95f; for (i=array->len-1; i>0; i--) { obj = (const DkpHistoryObj *) egg_obj_list_index (array, i); if (start - obj->time < timespan) @@ -440,9 +441,10 @@ dkp_history_schedule_save (DkpHistory *history) { gboolean ret; - /* if low power, then don't batch up save requests */ + /* TODO: if low power, then don't batch up save requests */ ret = dkp_history_is_low_power (history); - if (ret) { + if (FALSE && ret) { + egg_warning ("saving directly to disk as low power"); dkp_history_save_data (history); return TRUE; } @@ -706,7 +708,8 @@ dkp_history_finalize (GObject *object) history = DKP_HISTORY (object); /* save */ - dkp_history_save_data (history); + if (history->priv->id != NULL) + dkp_history_save_data (history); g_object_unref (history->priv->data_rate); g_object_unref (history->priv->data_charge); diff --git a/src/dkp-supply.c b/src/dkp-supply.c index 7fb4984..623e34a 100644 --- a/src/dkp-supply.c +++ b/src/dkp-supply.c @@ -39,13 +39,11 @@ #include "dkp-enum.h" #include "dkp-object.h" #include "dkp-supply.h" -#include "dkp-history.h" #define DKP_SUPPLY_REFRESH_TIMEOUT 10L struct DkpSupplyPrivate { - DkpHistory *history; guint poll_timer_id; gboolean has_coldplug_values; gdouble energy_old; @@ -368,13 +366,6 @@ dkp_supply_refresh_battery (DkpSupply *supply) } out: - /* save new history */ - dkp_history_set_state (supply->priv->history, obj->state); - dkp_history_set_charge_data (supply->priv->history, obj->percentage); - dkp_history_set_rate_data (supply->priv->history, obj->energy_rate); - dkp_history_set_time_full_data (supply->priv->history, obj->time_to_full); - dkp_history_set_time_empty_data (supply->priv->history, obj->time_to_empty); - g_free (status); return ret; } @@ -398,57 +389,6 @@ dkp_supply_poll_battery (DkpSupply *supply) } /** - * dkp_supply_get_history: - **/ -static EggObjList * -dkp_supply_get_history (DkpDevice *device, const gchar *type_string, guint timespan) -{ - DkpSupply *supply = DKP_SUPPLY (device); - EggObjList *array = NULL; - DkpHistoryType type = DKP_HISTORY_TYPE_UNKNOWN; - - g_return_val_if_fail (DKP_IS_SUPPLY (supply), FALSE); - g_return_val_if_fail (type_string != NULL, FALSE); - - /* get the correct data */ - if (egg_strequal (type_string, "rate")) - type = DKP_HISTORY_TYPE_RATE; - else if (egg_strequal (type_string, "charge")) - type = DKP_HISTORY_TYPE_CHARGE; - else if (egg_strequal (type_string, "time-full")) - type = DKP_HISTORY_TYPE_TIME_FULL; - else if (egg_strequal (type_string, "time-empty")) - type = DKP_HISTORY_TYPE_TIME_EMPTY; - - /* something recognised */ - if (type != DKP_HISTORY_TYPE_UNKNOWN) - array = dkp_history_get_data (supply->priv->history, type, timespan); - - return array; -} - -/** - * dkp_supply_get_stats: - **/ -static EggObjList * -dkp_supply_get_stats (DkpDevice *device, const gchar *type) -{ - DkpSupply *supply = DKP_SUPPLY (device); - EggObjList *array = NULL; - - g_return_val_if_fail (DKP_IS_SUPPLY (supply), FALSE); - g_return_val_if_fail (type != NULL, FALSE); - - /* get the correct data */ - if (egg_strequal (type, "charging")) - array = dkp_history_get_profile_data (supply->priv->history, TRUE); - else if (egg_strequal (type, "discharging")) - array = dkp_history_get_profile_data (supply->priv->history, FALSE); - - return array; -} - -/** * dkp_supply_coldplug: **/ static gboolean @@ -458,7 +398,6 @@ dkp_supply_coldplug (DkpDevice *device) DevkitDevice *d; const gchar *native_path; DkpObject *obj = dkp_device_get_obj (device); - gchar *id; dkp_supply_reset_values (supply); @@ -481,12 +420,6 @@ dkp_supply_coldplug (DkpDevice *device) /* coldplug values */ dkp_supply_refresh (device); - /* get the id so we can load the old history */ - id = dkp_object_get_id (obj); - if (id != NULL) - dkp_history_set_id (supply->priv->history, id); - g_free (id); - return TRUE; } @@ -538,7 +471,6 @@ static void dkp_supply_init (DkpSupply *supply) { supply->priv = DKP_SUPPLY_GET_PRIVATE (supply); - supply->priv->history = dkp_history_new (); } /** @@ -555,7 +487,6 @@ dkp_supply_finalize (GObject *object) supply = DKP_SUPPLY (object); g_return_if_fail (supply->priv != NULL); - g_object_unref (supply->priv->history); if (supply->priv->poll_timer_id > 0) g_source_remove (supply->priv->poll_timer_id); @@ -576,8 +507,6 @@ dkp_supply_class_init (DkpSupplyClass *klass) device_class->get_low_battery = dkp_supply_get_low_battery; device_class->coldplug = dkp_supply_coldplug; device_class->refresh = dkp_supply_refresh; - device_class->get_history = dkp_supply_get_history; - device_class->get_stats = dkp_supply_get_stats; g_type_class_add_private (klass, sizeof (DkpSupplyPrivate)); } diff --git a/src/dkp-wup.c b/src/dkp-wup.c index a1ccace..519310c 100644 --- a/src/dkp-wup.c +++ b/src/dkp-wup.c @@ -405,6 +405,10 @@ dkp_wup_coldplug (DkpDevice *device) obj->power_supply = FALSE; obj->is_present = FALSE; obj->vendor = g_strdup (devkit_device_get_property (d, "ID_VENDOR")); + obj->model = g_strdup (devkit_device_get_property (d, "ID_PRODUCT")); + obj->serial = g_strstrip (sysfs_get_string (obj->native_path, "serial")); + obj->has_history = TRUE; + obj->state = DKP_DEVICE_STATE_DISCHARGING; /* coldplug */ egg_debug ("coldplug"); |