3
* Copyright © 2011 Seif Lotfy <seif@lotfy.com>
4
* Copyright © 2011 Canonical Ltd.
5
* By Michal Hruby <michal.hruby@canonical.com>
7
* This program is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU Lesser General Public License as published by
9
* the Free Software Foundation, either version 2.1 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24
[DBus (name = "org.gnome.zeitgeist.Index")]
25
public interface RemoteSearchEngine: Object
27
[DBus (signature = "a(asaasay)u")]
28
public abstract async Variant search (
30
[DBus (signature = "(xx)")] Variant time_range,
31
[DBus (signature = "a(asaasay)")] Variant filter_templates,
32
uint offset, uint count, uint result_type,
33
[DBus (signature = "a(asaasay)")] out Variant events) throws Error;
36
/* Because of a Vala bug we have to define the proxy interface outside of
37
* [ModuleInit] source */
39
[DBus (name = "org.gnome.zeitgeist.SimpleIndexer")]
40
public interface RemoteSimpleIndexer : Object
42
[DBus (signature = "a(asaasay)u")]
43
public abstract async Variant search (
45
[DBus (signature = "(xx)")] Variant time_range,
46
[DBus (signature = "a(asaasay)")] Variant filter_templates,
47
uint offset, uint count, uint result_type) throws Error;
51
class SearchEngine: Extension, RemoteSearchEngine
54
private RemoteSimpleIndexer siin;
55
private uint registration_id;
66
var connection = Bus.get_sync (BusType.SESSION, null);
67
registration_id = connection.register_object<RemoteSearchEngine> (
68
"/org/gnome/zeitgeist/index/activity", this);
70
// FIXME: shouldn't we delay this to next idle callback?
72
Bus.watch_name_on_connection (connection,
73
"org.gnome.zeitgeist.SimpleIndexer",
74
BusNameWatcherFlags.AUTO_START,
77
if (siin != null) return;
78
conn.get_proxy.begin<RemoteSimpleIndexer> (
79
"org.gnome.zeitgeist.SimpleIndexer",
80
"/org/gnome/zeitgeist/index/activity",
81
0, null, this.proxy_acquired);
87
warning ("%s", err.message);
91
private void proxy_acquired (Object? obj, AsyncResult res)
93
var conn = obj as DBusConnection;
96
siin = conn.get_proxy.end<RemoteSimpleIndexer> (res);
100
warning ("%s", err.message);
104
/* This whole method is one huge workaround for an issue with Vala
105
* enclosing all out/return parameters in a TUPLE variant */
106
public async Variant search (string query_string, Variant time_range,
107
Variant filter_templates, uint offset, uint count, uint result_type,
108
out Variant events) throws Error
110
debug ("Performing search for %s", query_string);
111
if (siin == null || !(siin is DBusProxy))
113
// FIXME: queue until we have the proxy
114
throw new EngineError.DATABASE_ERROR (
115
"Not connected to SimpleIndexer");
117
var timer = new Timer ();
118
DBusProxy proxy = (DBusProxy) siin;
119
var b = new VariantBuilder (new VariantType ("(s(xx)a(asaasay)uuu)"));
120
b.add ("s", query_string);
121
b.add_value (time_range);
122
b.add_value (filter_templates);
125
b.add ("u", result_type);
126
var result = yield proxy.call ("Search", b.end (), 0, -1, null);
127
events = result.get_child_value (0);
128
/* FIXME: this somehow doesn't work :(
129
* but it's fixable in a similar way as this method's signature
132
var result = yield siin.search (query_string, time_range,
133
filter_templates, offset, count, result_type);
135
debug ("Got %u results from indexer (in %f seconds)",
136
(uint) events.n_children (), timer.elapsed ());
137
return result.get_child_value (1);
143
#if BUILTIN_EXTENSIONS
144
public static Type fts_init (TypeModule module)
147
public static Type extension_register (TypeModule module)
150
return typeof (SearchEngine);
154
// vim:expandtab:ts=4:sw=4