diff options
author | Richard Hughes <richard@hughsie.com> | 2009-12-01 08:55:04 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2009-12-01 08:55:04 +0000 |
commit | 99e99256547b828df4dacba347b6136645213412 (patch) | |
tree | dcd0899b25260e47b54a28d4845a036fb9a57a24 | |
parent | 1dbe1c87c5703014f46222c8fe555f81015b85a0 (diff) |
Make some small cleanups in prep for the release
-rw-r--r-- | src/dkp-device.c | 10 | ||||
-rw-r--r-- | src/dkp-main.c | 55 | ||||
-rw-r--r-- | src/linux/dkp-device-supply.c | 17 |
3 files changed, 58 insertions, 24 deletions
diff --git a/src/dkp-device.c b/src/dkp-device.c index b8ab766..563dac9 100644 --- a/src/dkp-device.c +++ b/src/dkp-device.c @@ -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; } diff --git a/src/dkp-main.c b/src/dkp-main.c index 57165c0..7117509 100644 --- a/src/dkp-main.c +++ b/src/dkp-main.c @@ -105,24 +105,49 @@ dkp_main_sigint_handler (gint sig) } /** + * 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: **/ 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); + + /* immediatly exit */ + if (immediate_exit) + g_timeout_add (50, (GSourceFunc) dkp_main_timed_exit_cb, loop); - g_object_unref (qos); - g_object_unref (wakeups); - g_object_unref (daemon); - g_main_loop_unref (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; } diff --git a/src/linux/dkp-device-supply.c b/src/linux/dkp-device-supply.c index e6880e4..c562088 100644 --- a/src/linux/dkp-device-supply.c +++ b/src/linux/dkp-device-supply.c @@ -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; } |