mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-05-03 07:48:12 +02:00
Make some small cleanups in prep for the release
This commit is contained in:
parent
1dbe1c87c5
commit
99e9925654
3 changed files with 58 additions and 24 deletions
|
|
@ -85,8 +85,7 @@ struct DkpDevicePrivate
|
|||
|
||||
static gboolean dkp_device_register_device (DkpDevice *device);
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_NATIVE_PATH,
|
||||
PROP_VENDOR,
|
||||
|
|
@ -118,8 +117,7 @@ enum
|
|||
PROP_LAST
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
SIGNAL_CHANGED,
|
||||
SIGNAL_LAST,
|
||||
};
|
||||
|
|
@ -532,7 +530,7 @@ dkp_device_coldplug (DkpDevice *device, DkpDaemon *daemon, GObject *native)
|
|||
gboolean ret;
|
||||
const gchar *native_path;
|
||||
DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device);
|
||||
gchar *id;
|
||||
gchar *id = NULL;
|
||||
|
||||
g_return_val_if_fail (DKP_IS_DEVICE (device), FALSE);
|
||||
|
||||
|
|
@ -579,13 +577,13 @@ dkp_device_coldplug (DkpDevice *device, DkpDaemon *daemon, GObject *native)
|
|||
id = dkp_device_get_id (device);
|
||||
if (id != NULL)
|
||||
dkp_history_set_id (device->priv->history, id);
|
||||
g_free (id);
|
||||
|
||||
out:
|
||||
/* start signals and callbacks */
|
||||
g_object_thaw_notify (G_OBJECT(device));
|
||||
device->priv->during_coldplug = FALSE;
|
||||
egg_debug ("device now not coldplug");
|
||||
g_free (id);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -104,6 +104,18 @@ dkp_main_sigint_handler (gint sig)
|
|||
g_main_loop_quit (loop);
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_main_timed_exit_cb:
|
||||
*
|
||||
* Exits the main loop, which is helpful for valgrinding.
|
||||
**/
|
||||
static gboolean
|
||||
dkp_main_timed_exit_cb (GMainLoop *loop)
|
||||
{
|
||||
g_main_loop_quit (loop);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* main:
|
||||
**/
|
||||
|
|
@ -111,18 +123,31 @@ gint
|
|||
main (gint argc, gchar **argv)
|
||||
{
|
||||
GError *error = NULL;
|
||||
DkpDaemon *daemon;
|
||||
DkpQos *qos;
|
||||
DkpWakeups *wakeups;
|
||||
DkpDaemon *daemon = NULL;
|
||||
DkpQos *qos = NULL;
|
||||
DkpWakeups *wakeups = NULL;
|
||||
GOptionContext *context;
|
||||
DBusGProxy *bus_proxy;
|
||||
DBusGConnection *bus;
|
||||
gboolean ret;
|
||||
gint retval = 1;
|
||||
gboolean timed_exit = FALSE;
|
||||
gboolean immediate_exit = FALSE;
|
||||
|
||||
const GOptionEntry options[] = {
|
||||
{ "timed-exit", '\0', 0, G_OPTION_ARG_NONE, &timed_exit,
|
||||
/* TRANSLATORS: exit after we've started up, used for user profiling */
|
||||
_("Exit after a small delay"), NULL },
|
||||
{ "immediate-exit", '\0', 0, G_OPTION_ARG_NONE, &immediate_exit,
|
||||
/* TRANSLATORS: exit straight away, used for automatic profiling */
|
||||
_("Exit after the engine has loaded"), NULL },
|
||||
{ NULL}
|
||||
};
|
||||
|
||||
g_type_init ();
|
||||
|
||||
context = g_option_context_new ("DeviceKit Power Daemon");
|
||||
g_option_context_add_main_entries (context, options, NULL);
|
||||
g_option_context_add_group (context, egg_debug_get_option_group ());
|
||||
g_option_context_parse (context, &argc, &argv, NULL);
|
||||
g_option_context_free (context);
|
||||
|
|
@ -158,21 +183,33 @@ main (gint argc, gchar **argv)
|
|||
qos = dkp_qos_new ();
|
||||
wakeups = dkp_wakeups_new ();
|
||||
daemon = dkp_daemon_new ();
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
ret = dkp_daemon_startup (daemon);
|
||||
if (!ret) {
|
||||
egg_warning ("Could not startup; bailing out");
|
||||
goto out;
|
||||
}
|
||||
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
g_main_loop_run (loop);
|
||||
/* only timeout and close the mainloop if we have specified it on the command line */
|
||||
if (timed_exit)
|
||||
g_timeout_add_seconds (30, (GSourceFunc) dkp_main_timed_exit_cb, loop);
|
||||
|
||||
g_object_unref (qos);
|
||||
g_object_unref (wakeups);
|
||||
g_object_unref (daemon);
|
||||
g_main_loop_unref (loop);
|
||||
/* immediatly exit */
|
||||
if (immediate_exit)
|
||||
g_timeout_add (50, (GSourceFunc) dkp_main_timed_exit_cb, loop);
|
||||
|
||||
/* wait for input or timeout */
|
||||
g_main_loop_run (loop);
|
||||
retval = 0;
|
||||
out:
|
||||
if (qos != NULL)
|
||||
g_object_unref (qos);
|
||||
if (wakeups != NULL)
|
||||
g_object_unref (wakeups);
|
||||
if (daemon != NULL)
|
||||
g_object_unref (daemon);
|
||||
if (loop != NULL)
|
||||
g_main_loop_unref (loop);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -380,7 +380,7 @@ static gboolean
|
|||
dkp_device_supply_refresh_battery (DkpDeviceSupply *supply)
|
||||
{
|
||||
gchar *status = NULL;
|
||||
gchar *technology_native;
|
||||
gchar *technology_native = NULL;
|
||||
gboolean ret = TRUE;
|
||||
gdouble voltage_design;
|
||||
DkpDeviceState old_state;
|
||||
|
|
@ -398,9 +398,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;
|
||||
gchar *manufacturer = NULL;
|
||||
gchar *model_name = NULL;
|
||||
gchar *serial_number = NULL;
|
||||
gboolean recall_notice;
|
||||
const gchar *recall_vendor = NULL;
|
||||
const gchar *recall_url = NULL;
|
||||
|
|
@ -436,7 +436,6 @@ dkp_device_supply_refresh_battery (DkpDeviceSupply *supply)
|
|||
/* the ACPI spec is bad at defining battery type constants */
|
||||
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");
|
||||
|
|
@ -467,10 +466,6 @@ dkp_device_supply_refresh_battery (DkpDeviceSupply *supply)
|
|||
"recall-url", recall_url,
|
||||
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;
|
||||
|
|
@ -686,6 +681,10 @@ dkp_device_supply_refresh_battery (DkpDeviceSupply *supply)
|
|||
NULL);
|
||||
|
||||
out:
|
||||
g_free (technology_native);
|
||||
g_free (manufacturer);
|
||||
g_free (model_name);
|
||||
g_free (serial_number);
|
||||
g_free (status);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue