Commit 27fb2f9c authored by Guido Gunther's avatar Guido Gunther Committed by Guido Gunther
Browse files

torch-manager: Cancel proxy creation on dispose



This makes sure there's no lingering async callbacks.
Signed-off-by: Guido Gunther's avatarGuido Günther <guido.gunther@puri.sm>
parent dc77f9d6
......@@ -12,6 +12,7 @@
#include "torch-manager.h"
#include "shell.h"
#include "util.h"
#include "dbus/upower-torch-dbus.h"
#define BUS_NAME "org.freedesktop.UPower"
......@@ -50,6 +51,7 @@ struct _PhoshTorchManager {
int last_brightness;
PhoshUPowerDBusTorch *proxy;
GCancellable *cancel;
};
G_DEFINE_TYPE (PhoshTorchManager, phosh_torch_manager, PHOSH_TYPE_MANAGER);
......@@ -201,16 +203,17 @@ on_proxy_new_for_bus_finish (GObject *source_object,
PhoshTorchManager *self)
{
g_autoptr (GError) err = NULL;
PhoshUPowerDBusTorch *proxy;
g_return_if_fail (PHOSH_IS_TORCH_MANAGER (self));
self->proxy = phosh_upower_dbus_torch_proxy_new_for_bus_finish (res, &err);
if (!self->proxy) {
g_warning ("Failed to get upower torch proxy: %s", err->message);
goto out;
proxy = phosh_upower_dbus_torch_proxy_new_for_bus_finish (res, &err);
if (!proxy) {
phosh_async_error_warn (err, "Failed to get upower torch proxy");
return;
}
g_return_if_fail (PHOSH_IS_TORCH_MANAGER (self));
self->proxy = proxy;
g_signal_connect_object (self->proxy,
"notify::g-name-owner",
G_CALLBACK (on_name_owner_changed),
......@@ -225,21 +228,22 @@ on_proxy_new_for_bus_finish (GObject *source_object,
on_torch_brightness_changed (self, NULL, self->proxy);
g_debug ("Torch manager initialized");
out:
g_object_unref (self);
}
static void
phosh_torch_manager_idle_init (PhoshManager *self)
phosh_torch_manager_idle_init (PhoshManager *manager)
{
PhoshTorchManager *self = PHOSH_TORCH_MANAGER (manager);
self->cancel = g_cancellable_new ();
phosh_upower_dbus_torch_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,
BUS_NAME,
OBJECT_PATH,
NULL,
self->cancel,
(GAsyncReadyCallback) on_proxy_new_for_bus_finish,
g_object_ref (self));
self);
}
......@@ -248,6 +252,9 @@ phosh_torch_manager_dispose (GObject *object)
{
PhoshTorchManager *self = PHOSH_TORCH_MANAGER(object);
g_cancellable_cancel (self->cancel);
g_clear_object (&self->cancel);
g_clear_object (&self->proxy);
G_OBJECT_CLASS (phosh_torch_manager_parent_class)->dispose (object);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment