Merge lp:~zeitgeist/zeitgeist/bb-extensions-conf into lp:~zeitgeist/zeitgeist/bluebird
- bb-extensions-conf
- Merge into bluebird
Proposed by
Siegfried Gevatter
Status: | Merged |
---|---|
Merged at revision: | 275 |
Proposed branch: | lp:~zeitgeist/zeitgeist/bb-extensions-conf |
Merge into: | lp:~zeitgeist/zeitgeist/bluebird |
Diff against target: |
357 lines (+204/-20) 7 files modified
extensions/blacklist.vala (+55/-18) extensions/ds-registry.vala (+7/-1) extensions/histogram.vala (+5/-0) src/Makefile.am (+1/-0) src/engine.vala (+3/-1) src/extension-store.vala (+118/-0) src/extension.vala (+15/-0) |
To merge this branch: | bzr merge lp:~zeitgeist/zeitgeist/bb-extensions-conf |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michal Hruby (community) | Approve | ||
Review via email: mp+76902@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Siegfried Gevatter (rainct) wrote : | # |
Great. Thanks for the review.
1) Changed, wasn't quite happy with get_name.
2) I'd rather not, if they really need to do something weird they can add a new function.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'extensions/blacklist.vala' | |||
2 | --- extensions/blacklist.vala 2011-09-24 16:04:43 +0000 | |||
3 | +++ extensions/blacklist.vala 2011-09-25 14:01:24 +0000 | |||
4 | @@ -42,6 +42,47 @@ | |||
5 | 42 | [DBus (signature = "s(asassay)")] Variant event_template); | 42 | [DBus (signature = "s(asassay)")] Variant event_template); |
6 | 43 | } | 43 | } |
7 | 44 | 44 | ||
8 | 45 | namespace BlacklistTemplates | ||
9 | 46 | { | ||
10 | 47 | private const string SIG_BLACKLIST = "a{s("+Utils.SIG_EVENT+")}"; | ||
11 | 48 | |||
12 | 49 | private static HashTable<string, Event> from_variant ( | ||
13 | 50 | Variant templates_variant) | ||
14 | 51 | { | ||
15 | 52 | var blacklist = new HashTable<string, Event> (str_hash, str_equal); | ||
16 | 53 | |||
17 | 54 | assert (templates_variant.get_type_string () == SIG_BLACKLIST); | ||
18 | 55 | foreach (Variant template_variant in templates_variant) | ||
19 | 56 | { | ||
20 | 57 | VariantIter iter = template_variant.iterator (); | ||
21 | 58 | string template_id = iter.next_value ().get_string (); | ||
22 | 59 | // FIXME: throw exception upon error instead of aborting | ||
23 | 60 | Event template = new Event.from_variant (iter.next_value ()); | ||
24 | 61 | blacklist.insert (template_id, template); | ||
25 | 62 | } | ||
26 | 63 | |||
27 | 64 | return blacklist; | ||
28 | 65 | } | ||
29 | 66 | |||
30 | 67 | public static Variant to_variant (HashTable<string, Event> blacklist) | ||
31 | 68 | { | ||
32 | 69 | var vb = new VariantBuilder (new VariantType (SIG_BLACKLIST)); | ||
33 | 70 | { | ||
34 | 71 | var iter = HashTableIter<string, Event> (blacklist); | ||
35 | 72 | string template_id; | ||
36 | 73 | Event event_template; | ||
37 | 74 | while (iter.next (out template_id, out event_template)) | ||
38 | 75 | { | ||
39 | 76 | vb.open (new VariantType ("{s("+Utils.SIG_EVENT+")}")); | ||
40 | 77 | vb.add ("s", template_id); | ||
41 | 78 | vb.add_value (event_template.to_variant ()); | ||
42 | 79 | vb.close (); | ||
43 | 80 | } | ||
44 | 81 | } | ||
45 | 82 | return vb.end (); | ||
46 | 83 | } | ||
47 | 84 | } | ||
48 | 85 | |||
49 | 45 | class Blacklist: Extension, RemoteBlacklist | 86 | class Blacklist: Extension, RemoteBlacklist |
50 | 46 | { | 87 | { |
51 | 47 | private HashTable<string, Event> blacklist; | 88 | private HashTable<string, Event> blacklist; |
52 | @@ -54,9 +95,13 @@ | |||
53 | 54 | 95 | ||
54 | 55 | construct | 96 | construct |
55 | 56 | { | 97 | { |
59 | 57 | blacklist = new HashTable<string, Event> (str_hash, str_equal); | 98 | // Restore previous blacklist from database, or create an empty one |
60 | 58 | 99 | Variant? templates = retrieve_config ("blacklist", | |
61 | 59 | // FIXME: load blacklist from file | 100 | BlacklistTemplates.SIG_BLACKLIST); |
62 | 101 | if (templates != null) | ||
63 | 102 | blacklist = BlacklistTemplates.from_variant (templates); | ||
64 | 103 | else | ||
65 | 104 | blacklist = new HashTable<string, Event> (str_hash, str_equal); | ||
66 | 60 | 105 | ||
67 | 61 | // This will be called after bus is acquired, so it shouldn't block | 106 | // This will be called after bus is acquired, so it shouldn't block |
68 | 62 | try | 107 | try |
69 | @@ -71,6 +116,10 @@ | |||
70 | 71 | } | 116 | } |
71 | 72 | } | 117 | } |
72 | 73 | 118 | ||
73 | 119 | public override string get_name () { | ||
74 | 120 | return "blacklist"; | ||
75 | 121 | } | ||
76 | 122 | |||
77 | 74 | public override void unload () | 123 | public override void unload () |
78 | 75 | { | 124 | { |
79 | 76 | try | 125 | try |
80 | @@ -92,7 +141,8 @@ | |||
81 | 92 | 141 | ||
82 | 93 | private void flush () | 142 | private void flush () |
83 | 94 | { | 143 | { |
85 | 95 | // FIXME: write to file. | 144 | Variant v = BlacklistTemplates.to_variant (blacklist); |
86 | 145 | store_config ("blacklist", v); | ||
87 | 96 | } | 146 | } |
88 | 97 | 147 | ||
89 | 98 | public override void pre_insert_events (GenericArray<Event?> events, | 148 | public override void pre_insert_events (GenericArray<Event?> events, |
90 | @@ -130,20 +180,7 @@ | |||
91 | 130 | 180 | ||
92 | 131 | public Variant get_templates () | 181 | public Variant get_templates () |
93 | 132 | { | 182 | { |
108 | 133 | var vb = new VariantBuilder (new VariantType ("a{s("+Utils.SIG_EVENT+")}")); | 183 | return BlacklistTemplates.to_variant (blacklist); |
95 | 134 | { | ||
96 | 135 | var iter = HashTableIter<string, Event> (blacklist); | ||
97 | 136 | string template_id; | ||
98 | 137 | Event event_template; | ||
99 | 138 | while (iter.next (out template_id, out event_template)) | ||
100 | 139 | { | ||
101 | 140 | vb.open (new VariantType ("{s("+Utils.SIG_EVENT+")}")); | ||
102 | 141 | vb.add ("s", template_id); | ||
103 | 142 | vb.add_value (event_template.to_variant ()); | ||
104 | 143 | vb.close (); | ||
105 | 144 | } | ||
106 | 145 | } | ||
107 | 146 | return vb.end (); | ||
109 | 147 | } | 184 | } |
110 | 148 | 185 | ||
111 | 149 | } | 186 | } |
112 | 150 | 187 | ||
113 | === modified file 'extensions/ds-registry.vala' | |||
114 | --- extensions/ds-registry.vala 2011-09-16 09:15:06 +0000 | |||
115 | +++ extensions/ds-registry.vala 2011-09-25 14:01:24 +0000 | |||
116 | @@ -140,7 +140,7 @@ | |||
117 | 140 | var connection = Bus.get_sync (BusType.SESSION, null); | 140 | var connection = Bus.get_sync (BusType.SESSION, null); |
118 | 141 | registration_id = connection.register_object<RemoteRegistry> ( | 141 | registration_id = connection.register_object<RemoteRegistry> ( |
119 | 142 | "/org/gnome/zeitgeist/data_source_registry", this); | 142 | "/org/gnome/zeitgeist/data_source_registry", this); |
121 | 143 | 143 | ||
122 | 144 | connection.signal_subscribe ("org.freedesktop.DBus", | 144 | connection.signal_subscribe ("org.freedesktop.DBus", |
123 | 145 | "org.freedesktop.DBus", "NameOwnerChanged", | 145 | "org.freedesktop.DBus", "NameOwnerChanged", |
124 | 146 | "/org/freedesktop/DBus", null, 0, | 146 | "/org/freedesktop/DBus", null, 0, |
125 | @@ -199,6 +199,12 @@ | |||
126 | 199 | // gobject.timeout_add(DISK_WRITE_TIMEOUT, self._write_to_disk) | 199 | // gobject.timeout_add(DISK_WRITE_TIMEOUT, self._write_to_disk) |
127 | 200 | } | 200 | } |
128 | 201 | 201 | ||
129 | 202 | |||
130 | 203 | public override string get_name () | ||
131 | 204 | { | ||
132 | 205 | return "data-source-registry"; | ||
133 | 206 | } | ||
134 | 207 | |||
135 | 202 | public override void unload () | 208 | public override void unload () |
136 | 203 | { | 209 | { |
137 | 204 | try | 210 | try |
138 | 205 | 211 | ||
139 | === modified file 'extensions/histogram.vala' | |||
140 | --- extensions/histogram.vala 2011-09-05 16:19:38 +0000 | |||
141 | +++ extensions/histogram.vala 2011-09-25 14:01:24 +0000 | |||
142 | @@ -49,6 +49,11 @@ | |||
143 | 49 | } | 49 | } |
144 | 50 | } | 50 | } |
145 | 51 | 51 | ||
146 | 52 | public override string get_name () | ||
147 | 53 | { | ||
148 | 54 | return "histogram"; | ||
149 | 55 | } | ||
150 | 56 | |||
151 | 52 | public override void unload () | 57 | public override void unload () |
152 | 53 | { | 58 | { |
153 | 54 | try | 59 | try |
154 | 55 | 60 | ||
155 | === modified file 'src/Makefile.am' | |||
156 | --- src/Makefile.am 2011-09-15 17:57:10 +0000 | |||
157 | +++ src/Makefile.am 2011-09-25 14:01:24 +0000 | |||
158 | @@ -32,6 +32,7 @@ | |||
159 | 32 | remote.vala \ | 32 | remote.vala \ |
160 | 33 | extension.vala \ | 33 | extension.vala \ |
161 | 34 | extension-collection.vala \ | 34 | extension-collection.vala \ |
162 | 35 | extension-store.vala \ | ||
163 | 35 | notify.vala \ | 36 | notify.vala \ |
164 | 36 | sql.vala \ | 37 | sql.vala \ |
165 | 37 | utils.vala \ | 38 | utils.vala \ |
166 | 38 | 39 | ||
167 | === modified file 'src/engine.vala' | |||
168 | --- src/engine.vala 2011-09-19 14:12:03 +0000 | |||
169 | +++ src/engine.vala 2011-09-25 14:01:24 +0000 | |||
170 | @@ -35,6 +35,7 @@ | |||
171 | 35 | { | 35 | { |
172 | 36 | 36 | ||
173 | 37 | public Zeitgeist.SQLite.ZeitgeistDatabase database { get; private set; } | 37 | public Zeitgeist.SQLite.ZeitgeistDatabase database { get; private set; } |
174 | 38 | public ExtensionStore extension_store; | ||
175 | 38 | private ExtensionCollection extension_collection; | 39 | private ExtensionCollection extension_collection; |
176 | 39 | private unowned Sqlite.Database db; | 40 | private unowned Sqlite.Database db; |
177 | 40 | 41 | ||
178 | @@ -57,6 +58,7 @@ | |||
179 | 57 | mimetypes_table = new TableLookup (database, "mimetype"); | 58 | mimetypes_table = new TableLookup (database, "mimetype"); |
180 | 58 | actors_table = new TableLookup (database, "actor"); | 59 | actors_table = new TableLookup (database, "actor"); |
181 | 59 | 60 | ||
182 | 61 | extension_store = new ExtensionStore (this); | ||
183 | 60 | extension_collection = new ExtensionCollection (this); | 62 | extension_collection = new ExtensionCollection (this); |
184 | 61 | } | 63 | } |
185 | 62 | 64 | ||
186 | @@ -701,7 +703,7 @@ | |||
187 | 701 | manifestations_table.get_id (event.manifestation)); | 703 | manifestations_table.get_id (event.manifestation)); |
188 | 702 | retrieval_stmt.bind_int64 (4, actors_table.get_id (event.actor)); | 704 | retrieval_stmt.bind_int64 (4, actors_table.get_id (event.actor)); |
189 | 703 | 705 | ||
191 | 704 | if ((rc = retrieval_stmt.step()) != Sqlite.ROW) { | 706 | if ((rc = retrieval_stmt.step ()) != Sqlite.ROW) { |
192 | 705 | warning ("SQL error: %d, %s\n", rc, db.errmsg ()); | 707 | warning ("SQL error: %d, %s\n", rc, db.errmsg ()); |
193 | 706 | return 0; | 708 | return 0; |
194 | 707 | } | 709 | } |
195 | 708 | 710 | ||
196 | === added file 'src/extension-store.vala' | |||
197 | --- src/extension-store.vala 1970-01-01 00:00:00 +0000 | |||
198 | +++ src/extension-store.vala 2011-09-25 14:01:24 +0000 | |||
199 | @@ -0,0 +1,118 @@ | |||
200 | 1 | /* extension-store.vala | ||
201 | 2 | * | ||
202 | 3 | * Copyright © 2011 Collabora Ltd. | ||
203 | 4 | * By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> | ||
204 | 5 | * | ||
205 | 6 | * This program is free software: you can redistribute it and/or modify | ||
206 | 7 | * it under the terms of the GNU Lesser General Public License as published by | ||
207 | 8 | * the Free Software Foundation, either version 2.1 of the License, or | ||
208 | 9 | * (at your option) any later version. | ||
209 | 10 | * | ||
210 | 11 | * This program is distributed in the hope that it will be useful, | ||
211 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
212 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
213 | 14 | * GNU General Public License for more details. | ||
214 | 15 | * | ||
215 | 16 | * You should have received a copy of the GNU Lesser General Public License | ||
216 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
217 | 18 | * | ||
218 | 19 | */ | ||
219 | 20 | |||
220 | 21 | using Zeitgeist; | ||
221 | 22 | |||
222 | 23 | namespace Zeitgeist | ||
223 | 24 | { | ||
224 | 25 | public class ExtensionStore : Object | ||
225 | 26 | { | ||
226 | 27 | |||
227 | 28 | private Zeitgeist.SQLite.ZeitgeistDatabase database; | ||
228 | 29 | private unowned Sqlite.Database db; | ||
229 | 30 | private Sqlite.Statement storage_stmt; | ||
230 | 31 | private Sqlite.Statement retrieval_stmt; | ||
231 | 32 | |||
232 | 33 | public ExtensionStore (Zeitgeist.Engine engine) { | ||
233 | 34 | database = engine.database; | ||
234 | 35 | db = database.database; | ||
235 | 36 | prepare_queries (); | ||
236 | 37 | } | ||
237 | 38 | |||
238 | 39 | private void prepare_queries () | ||
239 | 40 | throws EngineError | ||
240 | 41 | { | ||
241 | 42 | int rc; | ||
242 | 43 | string sql; | ||
243 | 44 | |||
244 | 45 | // Prepare storage query | ||
245 | 46 | sql = """ | ||
246 | 47 | INSERT OR REPLACE INTO extensions_conf ( | ||
247 | 48 | extension, key, value | ||
248 | 49 | ) VALUES ( | ||
249 | 50 | ?, ?, ? | ||
250 | 51 | )"""; | ||
251 | 52 | rc = database.database.prepare_v2 (sql, -1, out storage_stmt); | ||
252 | 53 | database.assert_query_success (rc, "Storage query error"); | ||
253 | 54 | |||
254 | 55 | // Prepare retrieval query | ||
255 | 56 | sql = """ | ||
256 | 57 | SELECT value | ||
257 | 58 | FROM extensions_conf | ||
258 | 59 | WHERE extension=? AND key=? | ||
259 | 60 | """; | ||
260 | 61 | rc = database.database.prepare_v2 (sql, -1, out retrieval_stmt); | ||
261 | 62 | database.assert_query_success (rc, "Retrieval query error"); | ||
262 | 63 | } | ||
263 | 64 | |||
264 | 65 | /** | ||
265 | 66 | * Store the given Variant under the given (extension, key) | ||
266 | 67 | * identifier, replacing any previous value. | ||
267 | 68 | */ | ||
268 | 69 | public void store (string extension, string key, Variant data) | ||
269 | 70 | { | ||
270 | 71 | int rc; | ||
271 | 72 | storage_stmt.reset (); | ||
272 | 73 | storage_stmt.bind_text (1, extension); | ||
273 | 74 | storage_stmt.bind_text (2, key); | ||
274 | 75 | storage_stmt.bind_blob (3, data.get_data (), (int) data.get_size ()); | ||
275 | 76 | |||
276 | 77 | if ((rc = storage_stmt.step ()) != Sqlite.DONE) | ||
277 | 78 | warning ("SQL error: %d, %s", rc, db.errmsg ()); | ||
278 | 79 | } | ||
279 | 80 | |||
280 | 81 | /** | ||
281 | 82 | * Retrieve a previously stored value. | ||
282 | 83 | */ | ||
283 | 84 | public Variant? retrieve(string extension, string key, VariantType format) | ||
284 | 85 | { | ||
285 | 86 | retrieval_stmt.reset (); | ||
286 | 87 | retrieval_stmt.bind_text (1, extension); | ||
287 | 88 | retrieval_stmt.bind_text (2, key); | ||
288 | 89 | |||
289 | 90 | int rc = retrieval_stmt.step (); | ||
290 | 91 | if (rc != Sqlite.ROW) | ||
291 | 92 | { | ||
292 | 93 | if (rc != Sqlite.DONE) | ||
293 | 94 | warning ("SQL error: %d, %s", rc, db.errmsg ()); | ||
294 | 95 | return null; | ||
295 | 96 | } | ||
296 | 97 | |||
297 | 98 | unowned uchar[] blob; | ||
298 | 99 | blob = (uchar[]) retrieval_stmt.column_blob (0); | ||
299 | 100 | blob.length = retrieval_stmt.column_bytes (0); | ||
300 | 101 | |||
301 | 102 | Variant? data = null; | ||
302 | 103 | if (blob != null) | ||
303 | 104 | { | ||
304 | 105 | ByteArray byte_array = new ByteArray.sized (blob.length); | ||
305 | 106 | byte_array.append (blob); | ||
306 | 107 | |||
307 | 108 | data = Variant.new_from_data<ByteArray> (format, | ||
308 | 109 | byte_array.data, false, byte_array); | ||
309 | 110 | } | ||
310 | 111 | |||
311 | 112 | retrieval_stmt.reset (); | ||
312 | 113 | return data; | ||
313 | 114 | } | ||
314 | 115 | |||
315 | 116 | } | ||
316 | 117 | } | ||
317 | 118 | // vim:expandtab:ts=4:sw=4 | ||
318 | 0 | 119 | ||
319 | === modified file 'src/extension.vala' | |||
320 | --- src/extension.vala 2011-09-17 10:41:24 +0000 | |||
321 | +++ src/extension.vala 2011-09-25 14:01:24 +0000 | |||
322 | @@ -2,6 +2,8 @@ | |||
323 | 2 | * | 2 | * |
324 | 3 | * Copyright © 2011 Manish Sinha <manishsinha@ubuntu.com> | 3 | * Copyright © 2011 Manish Sinha <manishsinha@ubuntu.com> |
325 | 4 | * Copyright © 2011 Michal Hruby <michal.mhr@gmail.com> | 4 | * Copyright © 2011 Michal Hruby <michal.mhr@gmail.com> |
326 | 5 | * Copyright © 2011 Collabora Ltd. | ||
327 | 6 | * By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> | ||
328 | 5 | * | 7 | * |
329 | 6 | * This program is free software: you can redistribute it and/or modify | 8 | * This program is free software: you can redistribute it and/or modify |
330 | 7 | * it under the terms of the GNU Lesser General Public License as published by | 9 | * it under the terms of the GNU Lesser General Public License as published by |
331 | @@ -36,6 +38,8 @@ | |||
332 | 36 | { | 38 | { |
333 | 37 | public unowned Engine engine { get; construct set; } | 39 | public unowned Engine engine { get; construct set; } |
334 | 38 | 40 | ||
335 | 41 | public abstract string get_name(); | ||
336 | 42 | |||
337 | 39 | /** | 43 | /** |
338 | 40 | * This method gets called before Zeitgeist stops. | 44 | * This method gets called before Zeitgeist stops. |
339 | 41 | * | 45 | * |
340 | @@ -122,6 +126,17 @@ | |||
341 | 122 | public virtual void post_delete_events (uint32[] ids, BusName? sender) | 126 | public virtual void post_delete_events (uint32[] ids, BusName? sender) |
342 | 123 | { | 127 | { |
343 | 124 | } | 128 | } |
344 | 129 | |||
345 | 130 | protected void store_config (string key, Variant data) | ||
346 | 131 | { | ||
347 | 132 | engine.extension_store.store (get_name (), key, data); | ||
348 | 133 | } | ||
349 | 134 | |||
350 | 135 | protected Variant? retrieve_config (string key, string format) | ||
351 | 136 | { | ||
352 | 137 | VariantType type = new VariantType(format); | ||
353 | 138 | return engine.extension_store.retrieve (get_name (), key, type); | ||
354 | 139 | } | ||
355 | 125 | } | 140 | } |
356 | 126 | 141 | ||
357 | 127 | [CCode (has_target = false)] | 142 | [CCode (has_target = false)] |
1) I'd get rid of the get_name method, we can just use get_type().name()
2) if the extension needed something special, store/retrieve could be virtual
Other than that it looks fine, feel free to merge!