Merge lp:~mhr3/libunity/use-owned-models into lp:libunity

Proposed by Michal Hruby on 2012-02-28
Status: Merged
Approved by: Mikkel Kamstrup Erlandsen on 2012-02-28
Approved revision: 124
Merged at revision: 123
Proposed branch: lp:~mhr3/libunity/use-owned-models
Merge into: lp:libunity
Diff against target: 62 lines (+24/-6)
2 files modified
configure.ac (+1/-1)
src/unity-lens-private.vala (+23/-5)
To merge this branch: bzr merge lp:~mhr3/libunity/use-owned-models
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) 2012-02-28 Approve on 2012-02-28
Review via email: mp+94975@code.launchpad.net

Description of the change

Switches the lenses to use leader-writable-only models.

This should prevent the crashes in lenses we are seeing from time to time.

The change in libunity is minor, current tests still pass and tests in dee make sure this works as expected. UNBLOCK

To post a comment you must log in.
lp:~mhr3/libunity/use-owned-models updated on 2012-02-28
124. By Michal Hruby on 2012-02-28

Add a few comments explaining the dark magic

Tried to do a lot of restarts of both unity and the apps lens without being able to reproduce the crasher (I could before on a stock system). Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2012-02-24 09:30:13 +0000
3+++ configure.ac 2012-02-28 15:06:17 +0000
4@@ -133,7 +133,7 @@
5 PKG_CHECK_MODULES(GIO2, [gio-2.0 >= $GLIB_REQUIRED ])
6 PKG_CHECK_MODULES(GIO_UNIX2, [gio-unix-2.0])
7 PKG_CHECK_MODULES(GEE, [gee-1.0 >= 0.6.0])
8-PKG_CHECK_MODULES(DEE, [dee-1.0 >= 0.9.0])
9+PKG_CHECK_MODULES(DEE, [dee-1.0 >= 1.0.4])
10 PKG_CHECK_MODULES(DBUSMENU, [dbusmenu-glib-0.4 >= 0.3.93])
11
12 LIBUNITY_CFLAGS="$GLIB2_CFLAGS $GOBJECT2_CFLAGS $GIO2_CFLAGS $GIO_UNIX2_CFLAGS $GEE_CFLAGS $DEE_CFLAGS $DBUSMENU_CFLAGS"
13
14=== modified file 'src/unity-lens-private.vala'
15--- src/unity-lens-private.vala 2012-01-31 18:24:51 +0000
16+++ src/unity-lens-private.vala 2012-02-28 15:06:17 +0000
17@@ -88,22 +88,40 @@
18 * old instances, or Unity itself, from stopping the models we create be the
19 * swarm leaders
20 */
21- uint t = (uint)time_t ();
22- return "com.canonical.Unity.Lens" + "." + _owner.id + ".T%u".printf (t);
23+ TimeVal tv = TimeVal ();
24+ int64 milli = tv.tv_sec;
25+ milli = milli * 1000 + tv.tv_usec / 1000;
26+ return ("com.canonical.Unity.Lens.%s.T%" + int64.FORMAT + "").printf (
27+ _owner.id, milli);
28+ }
29+
30+ private Dee.SharedModel create_master_model (string swarm_name)
31+ {
32+ /* Create a peer instance that tries to grab the swarm leadership */
33+ var peer = Object.@new (typeof (Dee.Peer),
34+ "swarm-name", swarm_name,
35+ "swarm-owner", true, null) as Dee.Peer;
36+ /* This will create a SharedModel where only the leader can write to it */
37+ var access_mode = Dee.SharedModelAccessMode.LEADER_WRITABLE;
38+ return Object.@new (typeof (Dee.SharedModel),
39+ "peer", peer,
40+ "back-end", new Dee.SequenceModel (),
41+ "access-mode", access_mode, null) as Dee.SharedModel;
42 }
43
44 private void create_models (string dbus_name)
45 {
46 /* Schema definitions come from the Lens specification */
47- _results_model = new Dee.SharedModel (dbus_name + ".Results");
48+ _results_model = create_master_model (dbus_name + ".Results");
49 _results_model.set_schema ("s", "s", "u", "s", "s", "s", "s");
50
51- _global_results_model = new Dee.SharedModel (dbus_name + ".GlobalResults");
52+ _global_results_model = create_master_model (dbus_name + ".GlobalResults");
53 _global_results_model.set_schema ("s", "s", "u", "s", "s", "s", "s");
54
55- _categories_model = new Dee.SharedModel (dbus_name + ".Categories");
56+ _categories_model = create_master_model (dbus_name + ".Categories");
57 _categories_model.set_schema ("s", "s", "s", "a{sv}");
58
59+ /* Filters are updated by unity, so we can't create a master model */
60 _filters_model = new Dee.SharedModel (dbus_name + ".Filters");
61 _filters_model.set_schema ("s", "s", "s", "s", "a{sv}", "b", "b", "b");
62 }

Subscribers

People subscribed via source and target branches