Merge lp:~3v1n0/bamf/libbamf-matcher-dispose into lp:bamf/0.4

Proposed by Marco Trevisan (Treviño) on 2012-04-24
Status: Merged
Approved by: Michal Hruby on 2012-04-24
Approved revision: 459
Merged at revision: 459
Proposed branch: lp:~3v1n0/bamf/libbamf-matcher-dispose
Merge into: lp:bamf/0.4
Diff against target: 80 lines (+52/-1)
1 file modified
lib/libbamf/bamf-matcher.c (+52/-1)
To merge this branch: bzr merge lp:~3v1n0/bamf/libbamf-matcher-dispose
Reviewer Review Type Date Requested Status
Michal Hruby (community) 2012-04-24 Approve on 2012-04-24
Review via email: mp+103294@code.launchpad.net

Commit message

libbamf, BamfMatcher: added finalize and dispose functions to disconnect to proxy when destructed

Description of the change

libbamf matcher proxy was never destroyed and its signals disconnected when the matcher was destructed (even if it's designed to use a singleton, it could happen).

This should be somewhat related to this: http://go.3v1n0.net/JUVh7K

To post a comment you must log in.
Michal Hruby (mhr3) wrote :

Looks fine, it's pretty strange that bamf_matcher_get_default returns an owned reference, but it has its benefits.

review: Approve
Marco Trevisan (Treviño) (3v1n0) wrote :

Yes, I agree... But I didn't want to change this, since I've used this assumption in unity everywhere.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/libbamf/bamf-matcher.c'
2--- lib/libbamf/bamf-matcher.c 2012-02-28 15:04:38 +0000
3+++ lib/libbamf/bamf-matcher.c 2012-04-24 14:19:32 +0000
4@@ -67,17 +67,28 @@
5 {
6 DBusGConnection *connection;
7 DBusGProxy *proxy;
8- GList *views;
9 };
10
11 static BamfMatcher * default_matcher = NULL;
12
13+static void bamf_matcher_dispose (GObject *object);
14+
15+static void
16+bamf_matcher_finalize (GObject *object)
17+{
18+ default_matcher = NULL;
19+
20+ G_OBJECT_CLASS (bamf_matcher_parent_class)->finalize (object);
21+}
22+
23 static void
24 bamf_matcher_class_init (BamfMatcherClass *klass)
25 {
26 GObjectClass *obj_class = G_OBJECT_CLASS (klass);
27
28 g_type_class_add_private (obj_class, sizeof (BamfMatcherPrivate));
29+ obj_class->dispose = bamf_matcher_dispose;
30+ obj_class->finalize = bamf_matcher_finalize;
31
32 matcher_signals [VIEW_OPENED] =
33 g_signal_new ("view-opened",
34@@ -283,6 +294,46 @@
35 self, NULL);
36 }
37
38+static void
39+bamf_matcher_dispose (GObject *object)
40+{
41+ BamfMatcher *self = BAMF_MATCHER (object);
42+ BamfMatcherPrivate *priv = self->priv;
43+
44+ if (priv->proxy)
45+ {
46+ dbus_g_proxy_disconnect_signal (priv->proxy,
47+ "ViewOpened",
48+ (GCallback) bamf_matcher_on_view_opened,
49+ self);
50+
51+ dbus_g_proxy_disconnect_signal (priv->proxy,
52+ "ViewClosed",
53+ (GCallback) bamf_matcher_on_view_closed,
54+ self);
55+
56+ dbus_g_proxy_disconnect_signal (priv->proxy,
57+ "ActiveApplicationChanged",
58+ (GCallback) bamf_matcher_on_active_application_changed,
59+ self);
60+
61+ dbus_g_proxy_disconnect_signal (priv->proxy,
62+ "ActiveWindowChanged",
63+ (GCallback) bamf_matcher_on_active_window_changed,
64+ self);
65+
66+ dbus_g_proxy_disconnect_signal (priv->proxy,
67+ "StackingOrderChanged",
68+ (GCallback) bamf_matcher_on_stacking_order_changed,
69+ self);
70+
71+ g_object_unref (priv->proxy);
72+ priv->proxy = NULL;
73+ }
74+
75+ G_OBJECT_CLASS (bamf_matcher_parent_class)->dispose (object);
76+}
77+
78 /*
79 * Private Methods
80 */

Subscribers

People subscribed via source and target branches