mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-04-14 08:50:41 +02:00
Fix compile
This commit is contained in:
commit
ff42e21d33
4 changed files with 105 additions and 26 deletions
|
|
@ -382,11 +382,11 @@ dkp_device_print (const DkpDevice *device)
|
|||
strftime (time_buf, sizeof time_buf, "%c", time_tm);
|
||||
|
||||
g_print (" native-path: %s\n", device->priv->native_path);
|
||||
if (device->priv->vendor != NULL)
|
||||
if (device->priv->vendor != NULL && device->priv->vendor[0] != '\0')
|
||||
g_print (" vendor: %s\n", device->priv->vendor);
|
||||
if (device->priv->model != NULL)
|
||||
if (device->priv->model != NULL && device->priv->model[0] != '\0')
|
||||
g_print (" model: %s\n", device->priv->model);
|
||||
if (device->priv->serial != NULL)
|
||||
if (device->priv->serial != NULL && device->priv->serial[0] != '\0')
|
||||
g_print (" serial: %s\n", device->priv->serial);
|
||||
g_print (" power supply: %s\n", dkp_device_print_bool_to_text (device->priv->power_supply));
|
||||
g_print (" updated: %s (%d seconds ago)\n", time_buf, (int) (time (NULL) - device->priv->update_time));
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ gboolean
|
|||
dkp_daemon_set_lid_is_closed (DkpDaemon *daemon, gboolean lid_is_closed)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
static gboolean initialized = FALSE;
|
||||
|
||||
g_return_val_if_fail (DKP_IS_DAEMON (daemon), FALSE);
|
||||
|
||||
|
|
@ -112,7 +113,16 @@ dkp_daemon_set_lid_is_closed (DkpDaemon *daemon, gboolean lid_is_closed)
|
|||
}
|
||||
|
||||
/* save */
|
||||
g_signal_emit (daemon, signals[CHANGED_SIGNAL], 0);
|
||||
if (!initialized) {
|
||||
/* Do not emit an event on startup. Otherwise, e. g.
|
||||
* gnome-power-manager would pick up a "lid is closed" change
|
||||
* event when dk-p gets D-BUS activated, and thus would
|
||||
* immediately suspend the machine on startup. FD#22574 */
|
||||
egg_debug ("not emitting lid change event for daemon startup");
|
||||
initialized = TRUE;
|
||||
} else {
|
||||
g_signal_emit (daemon, signals[CHANGED_SIGNAL], 0);
|
||||
}
|
||||
daemon->priv->lid_is_closed = lid_is_closed;
|
||||
ret = TRUE;
|
||||
out:
|
||||
|
|
@ -448,7 +458,33 @@ dkp_daemon_get_on_ac_local (DkpDaemon *daemon)
|
|||
}
|
||||
|
||||
/**
|
||||
* gpk_daemon_device_changed:
|
||||
* dkp_daemon_set_pmutils_powersave:
|
||||
*
|
||||
* Uses pm-utils to run scripts in power.d
|
||||
**/
|
||||
static gboolean
|
||||
dkp_daemon_set_pmutils_powersave (DkpDaemon *daemon, gboolean powersave)
|
||||
{
|
||||
gboolean ret;
|
||||
gchar *command;
|
||||
GError *error = NULL;
|
||||
|
||||
/* run script from pm-utils */
|
||||
command = g_strdup_printf ("/usr/sbin/pm-powersave %s", powersave ? "true" : "false");
|
||||
egg_debug ("excuting command: %s", command);
|
||||
ret = g_spawn_command_line_async (command, &error);
|
||||
if (!ret) {
|
||||
egg_warning ("failed to run script: %s", error->message);
|
||||
g_error_free (error);
|
||||
goto out;
|
||||
}
|
||||
out:
|
||||
g_free (command);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_daemon_device_changed:
|
||||
**/
|
||||
static void
|
||||
gpk_daemon_device_changed (DkpDaemon *daemon, GUdevDevice *d, gboolean synthesized)
|
||||
|
|
@ -463,7 +499,7 @@ gpk_daemon_device_changed (DkpDaemon *daemon, GUdevDevice *d, gboolean synthesiz
|
|||
dkp_device_changed (device, d, synthesized);
|
||||
} else {
|
||||
egg_debug ("treating change event as add on %s", dkp_device_get_object_path (device));
|
||||
gpk_daemon_device_add (daemon, d, TRUE);
|
||||
dkp_daemon_device_add (daemon, d, TRUE);
|
||||
}
|
||||
|
||||
/* second, check if the on_battery and low_battery state has changed */
|
||||
|
|
@ -472,6 +508,9 @@ gpk_daemon_device_changed (DkpDaemon *daemon, GUdevDevice *d, gboolean synthesiz
|
|||
daemon->priv->on_battery = ret;
|
||||
egg_debug ("now on_battery = %s", ret ? "yes" : "no");
|
||||
g_signal_emit (daemon, signals[CHANGED_SIGNAL], 0);
|
||||
|
||||
/* set pm-utils power policy */
|
||||
dkp_daemon_set_pmutils_powersave (daemon, daemon->priv->on_battery);
|
||||
}
|
||||
ret = dkp_daemon_get_low_battery_local (daemon);
|
||||
if (ret != daemon->priv->low_battery) {
|
||||
|
|
@ -482,10 +521,10 @@ gpk_daemon_device_changed (DkpDaemon *daemon, GUdevDevice *d, gboolean synthesiz
|
|||
}
|
||||
|
||||
/**
|
||||
* gpk_daemon_device_went_away:
|
||||
* dkp_daemon_device_went_away:
|
||||
**/
|
||||
static void
|
||||
gpk_daemon_device_went_away (gpointer user_data, GObject *_device)
|
||||
dkp_daemon_device_went_away (gpointer user_data, GObject *_device)
|
||||
{
|
||||
DkpDaemon *daemon = DKP_DAEMON (user_data);
|
||||
DkpDevice *device = DKP_DEVICE (_device);
|
||||
|
|
@ -493,7 +532,7 @@ gpk_daemon_device_went_away (gpointer user_data, GObject *_device)
|
|||
}
|
||||
|
||||
/**
|
||||
* gpk_daemon_device_get:
|
||||
* dkp_daemon_device_get:
|
||||
**/
|
||||
static DkpDevice *
|
||||
gpk_daemon_device_get (DkpDaemon *daemon, GUdevDevice *d)
|
||||
|
|
@ -573,7 +612,7 @@ out:
|
|||
}
|
||||
|
||||
/**
|
||||
* gpk_daemon_device_add:
|
||||
* dkp_daemon_device_add:
|
||||
**/
|
||||
static gboolean
|
||||
gpk_daemon_device_add (DkpDaemon *daemon, GUdevDevice *d, gboolean emit_event)
|
||||
|
|
@ -586,11 +625,11 @@ gpk_daemon_device_add (DkpDaemon *daemon, GUdevDevice *d, gboolean emit_event)
|
|||
if (device != NULL) {
|
||||
/* we already have the device; treat as change event */
|
||||
egg_debug ("treating add event as change event on %s", dkp_device_get_object_path (device));
|
||||
gpk_daemon_device_changed (daemon, d, FALSE);
|
||||
dkp_daemon_device_changed (daemon, d, FALSE);
|
||||
} else {
|
||||
|
||||
/* get the right sort of device */
|
||||
device = gpk_daemon_device_get (daemon, d);
|
||||
device = dkp_daemon_device_get (daemon, d);
|
||||
if (device == NULL) {
|
||||
egg_debug ("not adding device %s", g_udev_device_get_sysfs_path (d));
|
||||
ret = FALSE;
|
||||
|
|
@ -599,7 +638,7 @@ gpk_daemon_device_add (DkpDaemon *daemon, GUdevDevice *d, gboolean emit_event)
|
|||
/* only take a weak ref; the device will stay on the bus until
|
||||
* it's unreffed. So if we ref it, it'll never go away.
|
||||
*/
|
||||
g_object_weak_ref (G_OBJECT (device), gpk_daemon_device_went_away, daemon);
|
||||
g_object_weak_ref (G_OBJECT (device), dkp_daemon_device_went_away, daemon);
|
||||
dkp_device_list_insert (daemon->priv->list, d, device);
|
||||
if (emit_event) {
|
||||
g_signal_emit (daemon, signals[DEVICE_ADDED_SIGNAL], 0,
|
||||
|
|
@ -611,7 +650,7 @@ out:
|
|||
}
|
||||
|
||||
/**
|
||||
* gpk_daemon_device_remove:
|
||||
* dkp_daemon_device_remove:
|
||||
**/
|
||||
static void
|
||||
gpk_daemon_device_remove (DkpDaemon *daemon, GUdevDevice *d)
|
||||
|
|
@ -655,10 +694,10 @@ gpk_daemon_uevent_signal_handler_cb (GUdevClient *client, const gchar *action,
|
|||
|
||||
#if 0
|
||||
/**
|
||||
* gpk_daemon_throw_error:
|
||||
* dkp_daemon_throw_error:
|
||||
**/
|
||||
static gboolean
|
||||
gpk_daemon_throw_error (DBusGMethodInvocation *context, int error_code, const char *format, ...)
|
||||
dkp_daemon_throw_error (DBusGMethodInvocation *context, int error_code, const char *format, ...)
|
||||
{
|
||||
GError *error;
|
||||
va_list args;
|
||||
|
|
@ -783,10 +822,10 @@ out:
|
|||
}
|
||||
|
||||
/**
|
||||
* gpk_daemon_register_power_daemon:
|
||||
* dkp_daemon_register_power_daemon:
|
||||
**/
|
||||
static gboolean
|
||||
gpk_daemon_register_power_daemon (DkpDaemon *daemon)
|
||||
dkp_daemon_register_power_daemon (DkpDaemon *daemon)
|
||||
{
|
||||
DBusConnection *connection;
|
||||
DBusError dbus_error;
|
||||
|
|
@ -847,7 +886,7 @@ dkp_daemon_new (void)
|
|||
daemon = DKP_DAEMON (g_object_new (DKP_TYPE_DAEMON, NULL));
|
||||
|
||||
daemon->priv->list = dkp_device_list_new ();
|
||||
if (!gpk_daemon_register_power_daemon (DKP_DAEMON (daemon))) {
|
||||
if (!dkp_daemon_register_power_daemon (DKP_DAEMON (daemon))) {
|
||||
g_object_unref (daemon);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -867,6 +906,9 @@ dkp_daemon_new (void)
|
|||
!dkp_daemon_get_on_ac_local (daemon));
|
||||
daemon->priv->low_battery = dkp_daemon_get_low_battery_local (daemon);
|
||||
|
||||
/* set pm-utils power policy */
|
||||
dkp_daemon_set_pmutils_powersave (daemon, daemon->priv->on_battery);
|
||||
|
||||
return daemon;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -274,6 +274,31 @@ dkp_device_supply_convert_device_technology (const gchar *type)
|
|||
return DKP_DEVICE_TECHNOLOGY_UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_device_supply_get_string:
|
||||
**/
|
||||
static gchar *
|
||||
dkp_device_supply_get_string (const gchar *native_path, const gchar *key)
|
||||
{
|
||||
gchar *value;
|
||||
|
||||
/* get value, and strip to remove spaces */
|
||||
value = g_strstrip (sysfs_get_string (native_path, key));
|
||||
|
||||
/* no value */
|
||||
if (value == NULL)
|
||||
goto out;
|
||||
|
||||
/* empty value */
|
||||
if (value[0] == '\0') {
|
||||
g_free (value);
|
||||
value = NULL;
|
||||
goto out;
|
||||
}
|
||||
out:
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_device_supply_refresh_battery:
|
||||
*
|
||||
|
|
@ -301,6 +326,9 @@ dkp_device_supply_refresh_battery (DkpDeviceSupply *supply)
|
|||
gdouble voltage;
|
||||
guint64 time_to_empty;
|
||||
guint64 time_to_full;
|
||||
gchar *manufacturer;
|
||||
gchar *model_name;
|
||||
gchar *serial_number;
|
||||
|
||||
d = dkp_device_get_d (device);
|
||||
if (d == NULL) {
|
||||
|
|
@ -341,19 +369,28 @@ dkp_device_supply_refresh_battery (DkpDeviceSupply *supply)
|
|||
g_object_set (device, "power-supply", TRUE, NULL);
|
||||
|
||||
/* the ACPI spec is bad at defining battery type constants */
|
||||
technology_native = g_strstrip (sysfs_get_string (native_path, "technology"));
|
||||
technology_native = dkp_device_supply_get_string (native_path, "technology");
|
||||
g_object_set (device, "technology", dkp_device_supply_convert_device_technology (technology_native), NULL);
|
||||
g_free (technology_native);
|
||||
|
||||
/* get values which may be blank */
|
||||
manufacturer = dkp_device_supply_get_string (native_path, "manufacturer");
|
||||
model_name = dkp_device_supply_get_string (native_path, "model_name");
|
||||
serial_number = dkp_device_supply_get_string (native_path, "serial_number");
|
||||
|
||||
g_object_set (device,
|
||||
"vendor", g_strstrip (sysfs_get_string (native_path, "manufacturer")),
|
||||
"model", g_strstrip (sysfs_get_string (native_path, "model_name")),
|
||||
"serial", g_strstrip (sysfs_get_string (native_path, "serial_number")),
|
||||
"vendor", manufacturer,
|
||||
"model", model_name,
|
||||
"serial", serial_number,
|
||||
"is-rechargeable", TRUE, /* assume true for laptops */
|
||||
"has-history", TRUE,
|
||||
"has-statistics", TRUE,
|
||||
NULL);
|
||||
|
||||
g_free (manufacturer);
|
||||
g_free (model_name);
|
||||
g_free (serial_number);
|
||||
|
||||
/* these don't change at runtime */
|
||||
energy_full = sysfs_get_double (native_path, "energy_full") / 1000000.0;
|
||||
energy_full_design = sysfs_get_double (native_path, "energy_full_design") / 1000000.0;
|
||||
|
|
|
|||
|
|
@ -92,10 +92,10 @@ pk_polkit_io_remove_watch (PolKitContext *context, int watch_id)
|
|||
}
|
||||
|
||||
/**
|
||||
* gpk_polkit_dbus_filter:
|
||||
* dkp_polkit_dbus_filter:
|
||||
**/
|
||||
static DBusHandlerResult
|
||||
gpk_polkit_dbus_filter (DBusConnection *connection, DBusMessage *message, void *user_data)
|
||||
dkp_polkit_dbus_filter (DBusConnection *connection, DBusMessage *message, void *user_data)
|
||||
{
|
||||
DkpPolkit *polkit = DKP_POLKIT (user_data);
|
||||
const gchar *interface;
|
||||
|
|
@ -274,7 +274,7 @@ dkp_polkit_init (DkpPolkit *polkit)
|
|||
goto out;
|
||||
}
|
||||
|
||||
if (!dbus_connection_add_filter (connection, gpk_polkit_dbus_filter, polkit, NULL)) {
|
||||
if (!dbus_connection_add_filter (connection, dkp_polkit_dbus_filter, polkit, NULL)) {
|
||||
egg_warning ("Cannot add D-Bus filter: %s: %s", dbus_error.name, dbus_error.message);
|
||||
goto out;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue