Merge lp:~zeitgeist/zeitgeist/bb-extensions-conf into lp:~zeitgeist/zeitgeist/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
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
Review via email: mp+76902@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :

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!

review: Approve
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
=== modified file 'extensions/blacklist.vala'
--- extensions/blacklist.vala 2011-09-24 16:04:43 +0000
+++ extensions/blacklist.vala 2011-09-25 14:01:24 +0000
@@ -42,6 +42,47 @@
42 [DBus (signature = "s(asassay)")] Variant event_template);42 [DBus (signature = "s(asassay)")] Variant event_template);
43 }43 }
4444
45 namespace BlacklistTemplates
46 {
47 private const string SIG_BLACKLIST = "a{s("+Utils.SIG_EVENT+")}";
48
49 private static HashTable<string, Event> from_variant (
50 Variant templates_variant)
51 {
52 var blacklist = new HashTable<string, Event> (str_hash, str_equal);
53
54 assert (templates_variant.get_type_string () == SIG_BLACKLIST);
55 foreach (Variant template_variant in templates_variant)
56 {
57 VariantIter iter = template_variant.iterator ();
58 string template_id = iter.next_value ().get_string ();
59 // FIXME: throw exception upon error instead of aborting
60 Event template = new Event.from_variant (iter.next_value ());
61 blacklist.insert (template_id, template);
62 }
63
64 return blacklist;
65 }
66
67 public static Variant to_variant (HashTable<string, Event> blacklist)
68 {
69 var vb = new VariantBuilder (new VariantType (SIG_BLACKLIST));
70 {
71 var iter = HashTableIter<string, Event> (blacklist);
72 string template_id;
73 Event event_template;
74 while (iter.next (out template_id, out event_template))
75 {
76 vb.open (new VariantType ("{s("+Utils.SIG_EVENT+")}"));
77 vb.add ("s", template_id);
78 vb.add_value (event_template.to_variant ());
79 vb.close ();
80 }
81 }
82 return vb.end ();
83 }
84 }
85
45 class Blacklist: Extension, RemoteBlacklist86 class Blacklist: Extension, RemoteBlacklist
46 {87 {
47 private HashTable<string, Event> blacklist;88 private HashTable<string, Event> blacklist;
@@ -54,9 +95,13 @@
5495
55 construct96 construct
56 {97 {
57 blacklist = new HashTable<string, Event> (str_hash, str_equal);98 // Restore previous blacklist from database, or create an empty one
5899 Variant? templates = retrieve_config ("blacklist",
59 // FIXME: load blacklist from file100 BlacklistTemplates.SIG_BLACKLIST);
101 if (templates != null)
102 blacklist = BlacklistTemplates.from_variant (templates);
103 else
104 blacklist = new HashTable<string, Event> (str_hash, str_equal);
60105
61 // This will be called after bus is acquired, so it shouldn't block106 // This will be called after bus is acquired, so it shouldn't block
62 try107 try
@@ -71,6 +116,10 @@
71 }116 }
72 }117 }
73118
119 public override string get_name () {
120 return "blacklist";
121 }
122
74 public override void unload ()123 public override void unload ()
75 {124 {
76 try125 try
@@ -92,7 +141,8 @@
92141
93 private void flush ()142 private void flush ()
94 {143 {
95 // FIXME: write to file.144 Variant v = BlacklistTemplates.to_variant (blacklist);
145 store_config ("blacklist", v);
96 }146 }
97147
98 public override void pre_insert_events (GenericArray<Event?> events,148 public override void pre_insert_events (GenericArray<Event?> events,
@@ -130,20 +180,7 @@
130180
131 public Variant get_templates ()181 public Variant get_templates ()
132 {182 {
133 var vb = new VariantBuilder (new VariantType ("a{s("+Utils.SIG_EVENT+")}"));183 return BlacklistTemplates.to_variant (blacklist);
134 {
135 var iter = HashTableIter<string, Event> (blacklist);
136 string template_id;
137 Event event_template;
138 while (iter.next (out template_id, out event_template))
139 {
140 vb.open (new VariantType ("{s("+Utils.SIG_EVENT+")}"));
141 vb.add ("s", template_id);
142 vb.add_value (event_template.to_variant ());
143 vb.close ();
144 }
145 }
146 return vb.end ();
147 }184 }
148185
149 }186 }
150187
=== modified file 'extensions/ds-registry.vala'
--- extensions/ds-registry.vala 2011-09-16 09:15:06 +0000
+++ extensions/ds-registry.vala 2011-09-25 14:01:24 +0000
@@ -140,7 +140,7 @@
140 var connection = Bus.get_sync (BusType.SESSION, null);140 var connection = Bus.get_sync (BusType.SESSION, null);
141 registration_id = connection.register_object<RemoteRegistry> (141 registration_id = connection.register_object<RemoteRegistry> (
142 "/org/gnome/zeitgeist/data_source_registry", this);142 "/org/gnome/zeitgeist/data_source_registry", this);
143 143
144 connection.signal_subscribe ("org.freedesktop.DBus",144 connection.signal_subscribe ("org.freedesktop.DBus",
145 "org.freedesktop.DBus", "NameOwnerChanged",145 "org.freedesktop.DBus", "NameOwnerChanged",
146 "/org/freedesktop/DBus", null, 0,146 "/org/freedesktop/DBus", null, 0,
@@ -199,6 +199,12 @@
199 // gobject.timeout_add(DISK_WRITE_TIMEOUT, self._write_to_disk)199 // gobject.timeout_add(DISK_WRITE_TIMEOUT, self._write_to_disk)
200 }200 }
201201
202
203 public override string get_name ()
204 {
205 return "data-source-registry";
206 }
207
202 public override void unload ()208 public override void unload ()
203 {209 {
204 try210 try
205211
=== modified file 'extensions/histogram.vala'
--- extensions/histogram.vala 2011-09-05 16:19:38 +0000
+++ extensions/histogram.vala 2011-09-25 14:01:24 +0000
@@ -49,6 +49,11 @@
49 }49 }
50 }50 }
5151
52 public override string get_name ()
53 {
54 return "histogram";
55 }
56
52 public override void unload ()57 public override void unload ()
53 {58 {
54 try59 try
5560
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2011-09-15 17:57:10 +0000
+++ src/Makefile.am 2011-09-25 14:01:24 +0000
@@ -32,6 +32,7 @@
32 remote.vala \32 remote.vala \
33 extension.vala \33 extension.vala \
34 extension-collection.vala \34 extension-collection.vala \
35 extension-store.vala \
35 notify.vala \36 notify.vala \
36 sql.vala \37 sql.vala \
37 utils.vala \38 utils.vala \
3839
=== modified file 'src/engine.vala'
--- src/engine.vala 2011-09-19 14:12:03 +0000
+++ src/engine.vala 2011-09-25 14:01:24 +0000
@@ -35,6 +35,7 @@
35{35{
3636
37 public Zeitgeist.SQLite.ZeitgeistDatabase database { get; private set; }37 public Zeitgeist.SQLite.ZeitgeistDatabase database { get; private set; }
38 public ExtensionStore extension_store;
38 private ExtensionCollection extension_collection;39 private ExtensionCollection extension_collection;
39 private unowned Sqlite.Database db;40 private unowned Sqlite.Database db;
4041
@@ -57,6 +58,7 @@
57 mimetypes_table = new TableLookup (database, "mimetype");58 mimetypes_table = new TableLookup (database, "mimetype");
58 actors_table = new TableLookup (database, "actor");59 actors_table = new TableLookup (database, "actor");
5960
61 extension_store = new ExtensionStore (this);
60 extension_collection = new ExtensionCollection (this);62 extension_collection = new ExtensionCollection (this);
61 }63 }
6264
@@ -701,7 +703,7 @@
701 manifestations_table.get_id (event.manifestation));703 manifestations_table.get_id (event.manifestation));
702 retrieval_stmt.bind_int64 (4, actors_table.get_id (event.actor));704 retrieval_stmt.bind_int64 (4, actors_table.get_id (event.actor));
703705
704 if ((rc = retrieval_stmt.step()) != Sqlite.ROW) {706 if ((rc = retrieval_stmt.step ()) != Sqlite.ROW) {
705 warning ("SQL error: %d, %s\n", rc, db.errmsg ());707 warning ("SQL error: %d, %s\n", rc, db.errmsg ());
706 return 0;708 return 0;
707 }709 }
708710
=== added file 'src/extension-store.vala'
--- src/extension-store.vala 1970-01-01 00:00:00 +0000
+++ src/extension-store.vala 2011-09-25 14:01:24 +0000
@@ -0,0 +1,118 @@
1/* extension-store.vala
2 *
3 * Copyright © 2011 Collabora Ltd.
4 * By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 2.1 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21using Zeitgeist;
22
23namespace Zeitgeist
24{
25 public class ExtensionStore : Object
26 {
27
28 private Zeitgeist.SQLite.ZeitgeistDatabase database;
29 private unowned Sqlite.Database db;
30 private Sqlite.Statement storage_stmt;
31 private Sqlite.Statement retrieval_stmt;
32
33 public ExtensionStore (Zeitgeist.Engine engine) {
34 database = engine.database;
35 db = database.database;
36 prepare_queries ();
37 }
38
39 private void prepare_queries ()
40 throws EngineError
41 {
42 int rc;
43 string sql;
44
45 // Prepare storage query
46 sql = """
47 INSERT OR REPLACE INTO extensions_conf (
48 extension, key, value
49 ) VALUES (
50 ?, ?, ?
51 )""";
52 rc = database.database.prepare_v2 (sql, -1, out storage_stmt);
53 database.assert_query_success (rc, "Storage query error");
54
55 // Prepare retrieval query
56 sql = """
57 SELECT value
58 FROM extensions_conf
59 WHERE extension=? AND key=?
60 """;
61 rc = database.database.prepare_v2 (sql, -1, out retrieval_stmt);
62 database.assert_query_success (rc, "Retrieval query error");
63 }
64
65 /**
66 * Store the given Variant under the given (extension, key)
67 * identifier, replacing any previous value.
68 */
69 public void store (string extension, string key, Variant data)
70 {
71 int rc;
72 storage_stmt.reset ();
73 storage_stmt.bind_text (1, extension);
74 storage_stmt.bind_text (2, key);
75 storage_stmt.bind_blob (3, data.get_data (), (int) data.get_size ());
76
77 if ((rc = storage_stmt.step ()) != Sqlite.DONE)
78 warning ("SQL error: %d, %s", rc, db.errmsg ());
79 }
80
81 /**
82 * Retrieve a previously stored value.
83 */
84 public Variant? retrieve(string extension, string key, VariantType format)
85 {
86 retrieval_stmt.reset ();
87 retrieval_stmt.bind_text (1, extension);
88 retrieval_stmt.bind_text (2, key);
89
90 int rc = retrieval_stmt.step ();
91 if (rc != Sqlite.ROW)
92 {
93 if (rc != Sqlite.DONE)
94 warning ("SQL error: %d, %s", rc, db.errmsg ());
95 return null;
96 }
97
98 unowned uchar[] blob;
99 blob = (uchar[]) retrieval_stmt.column_blob (0);
100 blob.length = retrieval_stmt.column_bytes (0);
101
102 Variant? data = null;
103 if (blob != null)
104 {
105 ByteArray byte_array = new ByteArray.sized (blob.length);
106 byte_array.append (blob);
107
108 data = Variant.new_from_data<ByteArray> (format,
109 byte_array.data, false, byte_array);
110 }
111
112 retrieval_stmt.reset ();
113 return data;
114 }
115
116 }
117}
118// vim:expandtab:ts=4:sw=4
0119
=== modified file 'src/extension.vala'
--- src/extension.vala 2011-09-17 10:41:24 +0000
+++ src/extension.vala 2011-09-25 14:01:24 +0000
@@ -2,6 +2,8 @@
2 *2 *
3 * Copyright © 2011 Manish Sinha <manishsinha@ubuntu.com>3 * Copyright © 2011 Manish Sinha <manishsinha@ubuntu.com>
4 * Copyright © 2011 Michal Hruby <michal.mhr@gmail.com>4 * Copyright © 2011 Michal Hruby <michal.mhr@gmail.com>
5 * Copyright © 2011 Collabora Ltd.
6 * By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>
5 *7 *
6 * This program is free software: you can redistribute it and/or modify8 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by9 * it under the terms of the GNU Lesser General Public License as published by
@@ -36,6 +38,8 @@
36 {38 {
37 public unowned Engine engine { get; construct set; }39 public unowned Engine engine { get; construct set; }
3840
41 public abstract string get_name();
42
39 /**43 /**
40 * This method gets called before Zeitgeist stops.44 * This method gets called before Zeitgeist stops.
41 *45 *
@@ -122,6 +126,17 @@
122 public virtual void post_delete_events (uint32[] ids, BusName? sender)126 public virtual void post_delete_events (uint32[] ids, BusName? sender)
123 {127 {
124 }128 }
129
130 protected void store_config (string key, Variant data)
131 {
132 engine.extension_store.store (get_name (), key, data);
133 }
134
135 protected Variant? retrieve_config (string key, string format)
136 {
137 VariantType type = new VariantType(format);
138 return engine.extension_store.retrieve (get_name (), key, type);
139 }
125 }140 }
126141
127 [CCode (has_target = false)]142 [CCode (has_target = false)]

Subscribers

People subscribed via source and target branches