Merge lp:~rainct/libzeitgeist/log_get_default into lp:libzeitgeist

Proposed by Siegfried Gevatter
Status: Merged
Approved by: Mikkel Kamstrup Erlandsen
Approved revision: 220
Merged at revision: 220
Proposed branch: lp:~rainct/libzeitgeist/log_get_default
Merge into: lp:libzeitgeist
Prerequisite: lp:~rainct/libzeitgeist/776651-doc
Diff against target: 91 lines (+38/-0)
3 files modified
src/zeitgeist-log.c (+26/-0)
src/zeitgeist-log.h (+2/-0)
tests/test-log.c (+10/-0)
To merge this branch: bzr merge lp:~rainct/libzeitgeist/log_get_default
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen Approve
Review via email: mp+91284@code.launchpad.net
To post a comment you must log in.
220. By Siegfried Gevatter

Give stuff the right name, even

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Just perfect!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/zeitgeist-log.c'
2--- src/zeitgeist-log.c 2012-01-30 12:26:04 +0000
3+++ src/zeitgeist-log.c 2012-02-02 15:11:19 +0000
4@@ -120,6 +120,8 @@
5 GAsyncResult *res,
6 gpointer user_data);
7
8+static ZeitgeistLog *zeitgeist_log_singleton = NULL;
9+
10 static void
11 zeitgeist_log_init (ZeitgeistLog *self)
12 {
13@@ -310,6 +312,10 @@
14 * until the connection is ready - at which point you will get a notify signal
15 * on the #ZeitgeistLog:connected property.
16 *
17+ * It isn't recommended to call this function more than once. If you need to
18+ * access #ZeitgeistLog from different parts of your codebase, consider using
19+ * zeitgeist_log_get_default() instead.
20+ *
21 * Returns: A reference to a newly allocated log.
22 */
23 ZeitgeistLog*
24@@ -324,6 +330,26 @@
25 }
26
27 /**
28+ * zeitgeist_log_get_default:
29+ * Get a unique instance of #ZeitgeistLog, that you can share in your
30+ * application without caring about memory management.
31+ *
32+ * See zeitgeist_log_new() for more information.
33+ *
34+ * Returns: (transfer none): A unique #ZeitgeistLog. Do not ref or unref it.
35+ *
36+ * Since: 0.3.14
37+ */
38+ZeitgeistLog*
39+zeitgeist_log_get_default (void)
40+{
41+ if (G_UNLIKELY (!zeitgeist_log_singleton))
42+ zeitgeist_log_singleton = zeitgeist_log_new ();
43+
44+ return zeitgeist_log_singleton;
45+}
46+
47+/**
48 * zeitgeist_log_insert_events:
49 * @self: The log logging the events
50 * @cancellable: To cancel the operation or %NULL
51
52=== modified file 'src/zeitgeist-log.h'
53--- src/zeitgeist-log.h 2011-03-07 14:19:39 +0000
54+++ src/zeitgeist-log.h 2012-02-02 15:11:19 +0000
55@@ -60,6 +60,8 @@
56
57 ZeitgeistLog* zeitgeist_log_new (void);
58
59+ZeitgeistLog* zeitgeist_log_get_default (void);
60+
61 void zeitgeist_log_insert_events (ZeitgeistLog *self,
62 GCancellable *cancellable,
63 GAsyncReadyCallback callback,
64
65=== modified file 'tests/test-log.c'
66--- tests/test-log.c 2010-06-10 08:39:30 +0000
67+++ tests/test-log.c 2012-02-02 15:11:19 +0000
68@@ -198,6 +198,14 @@
69 g_main_loop_run (fix->mainloop);
70 }
71
72+static void
73+test_get_default (Fixture *fix, gconstpointer data) {
74+ ZeitgeistLog *zeitgeist_log1, *zeitgeist_log2;
75+ zeitgeist_log1 = zeitgeist_log_get_default ();
76+ zeitgeist_log2 = zeitgeist_log_get_default ();
77+ g_assert (zeitgeist_log1 == zeitgeist_log2);
78+}
79+
80 int
81 main (int argc,
82 char *argv[])
83@@ -207,6 +215,8 @@
84
85 g_test_add ("/Zeitgeist/Log/InsertGetDelete", Fixture, NULL,
86 setup, test_insert_get_delete, teardown);
87+ g_test_add ("/Zeitgeist/Log/GetDefault", Fixture, NULL,
88+ NULL, test_get_default, NULL);
89
90 return g_test_run();
91 }

Subscribers

People subscribed via source and target branches