summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libzeitgeist/Makefile.am1
-rw-r--r--libzeitgeist/log.vala142
-rw-r--r--libzeitgeist/monitor.vala68
-rw-r--r--libzeitgeist/remote.vala20
-rw-r--r--src/zeitgeist-daemon.vala19
5 files changed, 230 insertions, 20 deletions
diff --git a/libzeitgeist/Makefile.am b/libzeitgeist/Makefile.am
index c3063cc3..92c67af9 100644
--- a/libzeitgeist/Makefile.am
+++ b/libzeitgeist/Makefile.am
@@ -19,6 +19,7 @@ libzeitgeist_la_SOURCES = \
datamodel.vala \
log.vala \
mimetype.vala \
+ monitor.vala \
ontology-uris.vala \
ontology.vala \
remote.vala \
diff --git a/libzeitgeist/log.vala b/libzeitgeist/log.vala
index e82363c0..933eae15 100644
--- a/libzeitgeist/log.vala
+++ b/libzeitgeist/log.vala
@@ -24,14 +24,31 @@
namespace Zeitgeist
{
+/**
+ * SECTION:zeitgeist-log
+ * @short_description: Primary access point for talking to the Zeitgeist daemon
+ * @include: zeitgeist.h
+ *
+ * #ZeitgeistLog encapsulates the low level access to the Zeitgeist daemon.
+ * You can use it to manage the log by inserting and deleting entries as well
+ * as do queries on the logged data.
+ *
+ * It's important to realize that the #ZeitgeistLog class does not expose
+ * any API that does synchronous communications with the message bus -
+ * everything is asynchronous. To ease development some of the methods have
+ * variants that are "fire and forget" ignoring the normal return value, so
+ * that callbacks does not have to be set up.
+ */
public class Log : Object
{
private static Log default_instance;
private RemoteLog proxy;
- private Variant engine_version;
+ private Variant? engine_version;
private SList<QueuedMethod> method_dispatch_queue;
+ public bool is_connected { get; private set; default = false; }
+
private class QueuedMethod
{
@@ -41,20 +58,28 @@ public class Log : Object
{
queued_method = callback;
}
+
}
public Log ()
{
+ warning ("hi! requesting proxy...");
Bus.get_proxy<RemoteLog> (BusType.SESSION, Utils.ENGINE_DBUS_NAME,
Utils.ENGINE_DBUS_PATH, 0, null, (obj, res) =>
{
+ warning ("ok! proxy acquired!");
try
{
proxy = Bus.get_proxy.end (res);
+ engine_version = proxy.version;
+ warn_if_fail (engine_version.get_type_string () == "(iii)");
+
process_queued_methods ();
proxy.notify["g-name-owner"].connect (name_owner_changed);
+
+ is_connected = true;
}
catch (IOError err)
{
@@ -82,12 +107,15 @@ public class Log : Object
private void name_owner_changed (ParamSpec pspec)
{
string? name_owner = null; // .get_name_owner ();
+ this.is_connected = name_owner != null;
- if (name_owner != null)
+ if (is_connected)
{
// Reinstate all active monitors
// Update our cached version property
+ engine_version = proxy.version;
+ warn_if_fail (engine_version.get_type_string () == "(iii)");
}
}
@@ -96,10 +124,64 @@ public class Log : Object
return;
if (method_dispatch_queue == null)
method_dispatch_queue = new SList<QueuedMethod> ();
- method_dispatch_queue.append (new QueuedMethod (callback));
+ method_dispatch_queue.prepend (new QueuedMethod (callback));
yield;
}
+ /*
+ public async void insert_events (Cancellable? cancellable=null, ...)
+ throws Error
+ {
+ var lalala = va_list ();
+ // FIXME: variadic async functions are broken! This generates:
+ // static gboolean zeitgeist_log_insert_events_co (ZeitgeistLogInsertEventsData* _data_) {
+ // ...
+ // va_start (_data_->lalala, cancellable);
+ // ...
+ // }
+ yield insert_events_valist (cancellable, lalala);
+ }
+
+ public async void insert_events_valist (Cancellable? cancellable=null,
+ va_list events) throws Error
+ {
+ Event event = events.arg ();
+ }
+ */
+
+ /*
+ public async void insert_events_no_reply (...) throws Error
+ {
+ }
+ */
+
+ public async void insert_events_from_ptrarray (GenericArray<Event> events,
+ Cancellable? cancellable=null) throws Error
+ {
+ yield wait_for_proxy (insert_events_from_ptrarray.callback);
+ yield proxy.insert_events (Events.to_variant (events), cancellable);
+ }
+
+ public async void find_events (
+ TimeRange time_range,
+ GenericArray<Event> event_templates,
+ StorageState storage_state,
+ uint32 num_events,
+ ResultType result_type,
+ Cancellable? cancellable=null) throws Error
+ {
+ }
+
+ public async void find_event_ids (
+ TimeRange time_range,
+ GenericArray<Event> event_templates,
+ StorageState storage_state,
+ uint32 num_events,
+ ResultType result_type,
+ Cancellable? cancellable=null) throws Error
+ {
+ }
+
public async GenericArray<Event> get_events (uint32[] event_ids,
Cancellable? cancellable=null) throws Error
{
@@ -108,6 +190,60 @@ public class Log : Object
return Events.from_variant (result);
}
+ public async void find_related_uris (
+ TimeRange time_range,
+ GenericArray<Event> event_templates,
+ GenericArray<Event> result_event_templates,
+ StorageState storage_state,
+ uint32 num_events,
+ ResultType result_type,
+ Cancellable? cancellable=null) throws Error
+ {
+ }
+
+ public async void delete_events (uint32[] event_ids,
+ Cancellable? cancellable=null) throws Error
+ {
+ yield wait_for_proxy (delete_events.callback);
+ yield proxy.delete_events (event_ids, cancellable);
+ }
+
+ public async void quit (Cancellable? cancellable=null) throws Error
+ {
+ yield wait_for_proxy (quit.callback);
+ yield proxy.quit (cancellable);
+ }
+
+ public async void install_monitor (Monitor monitor) throws Error
+ {
+ }
+
+ public async void remove_monitor (Monitor monitor) throws Error
+ {
+ }
+
+ /**
+ * zeitgeist_log_get_version:
+ * @self: A #ZeitgeistLog instance
+ * @major: (out): Location for the major version
+ * @minor: (out): Location for the minor version
+ * @micro: (out): Location for the micro version
+ *
+ * Gets version of currently running Zeitgeist daemon.
+ *
+ * This method will return the version of Zeitgeist daemon this instance is
+ * connected to. If you call this method right after zeitgeist_log_new(),
+ * only zeros will be returned, a valid version number will only be returned
+ * once this instance successfully connected to the Zeitgeist daemon - ie.
+ * the value of the "is-connected" property must be TRUE (you can connect
+ * to the "notify::is-connected" signal otherwise).
+ */
+ public void get_version (out int major, out int minor, out int micro) {
+ major = minor = micro = 0;
+ if (engine_version != null)
+ engine_version.get ("(iii)", &major, &minor, &micro);
+ }
+
}
}
diff --git a/libzeitgeist/monitor.vala b/libzeitgeist/monitor.vala
new file mode 100644
index 00000000..d9605b33
--- /dev/null
+++ b/libzeitgeist/monitor.vala
@@ -0,0 +1,68 @@
+/*
+ * Copyright © 2012 Canonical Ltd.
+ * By Siegfried-A. Gevatter <siegfried.gevatter@collabora.co.uk>
+ *
+ * Based upon a C implementation (© 2010-2012 Canonical Ltd) by:
+ * Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
+ * Michal Hruby <michal.hruby@canonical.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Zeitgeist
+{
+
+public class Monitor : Object
+{
+
+ private static int monitor_counter = 0;
+
+ private TimeRange time_range;
+ private GenericArray<Event> templates;
+
+ // Client side D-Bus path the monitor lives under
+ private string monitor_path;
+
+ public signal void events_inserted (TimeRange time_range,
+ GenericArray<Event> events);
+ public signal void events_deleted (TimeRange time_range,
+ GenericArray<uint32> event_ids);
+
+ public Monitor (TimeRange time_range, GenericArray<Event> event_templates)
+ {
+ this.time_range = time_range;
+ this.templates = event_templates;
+ this.monitor_path = "/org/gnome/zeitgeist/monitor/%i".printf (
+ monitor_counter++);
+ }
+
+ public TimeRange get_time_range ()
+ {
+ return time_range;
+ }
+
+ public GenericArray<Event> get_templates ()
+ {
+ return templates;
+ }
+
+ public string get_path ()
+ {
+ return "FIXME";
+ }
+
+}
+
+}
diff --git a/libzeitgeist/remote.vala b/libzeitgeist/remote.vala
index a53bc450..c1b5f849 100644
--- a/libzeitgeist/remote.vala
+++ b/libzeitgeist/remote.vala
@@ -33,12 +33,13 @@ namespace Zeitgeist
{
[DBus (signature = "(xx)")]
- public abstract Variant delete_events (
+ public async abstract Variant delete_events (
uint32[] event_ids,
+ Cancellable? cancellable=null,
BusName? sender=null
) throws Error;
- public abstract uint32[] find_event_ids (
+ public async abstract uint32[] find_event_ids (
[DBus (signature = "(xx)")] Variant time_range,
[DBus (signature = "a(asaasay)")] Variant event_templates,
uint storage_state, uint num_events, uint result_type,
@@ -46,14 +47,14 @@ namespace Zeitgeist
) throws Error;
[DBus (signature = "a(asaasay)")]
- public abstract Variant find_events (
+ public async abstract Variant find_events (
[DBus (signature = "(xx)")] Variant time_range,
[DBus (signature = "a(asaasay)")] Variant event_templates,
uint storage_state, uint num_events, uint result_type,
BusName? sender=null
) throws Error;
- public abstract string[] find_related_uris (
+ public async abstract string[] find_related_uris (
[DBus (signature = "(xx)")] Variant time_range,
[DBus (signature = "a(asaasay)")] Variant event_templates,
[DBus (signature = "a(asaasay)")] Variant result_event_templates,
@@ -68,24 +69,27 @@ namespace Zeitgeist
BusName? sender=null
) throws Error;
- public abstract uint32[] insert_events (
+ public async abstract uint32[] insert_events (
[DBus (signature = "a(asaasay)")] Variant events,
+ Cancellable? cancellable=null,
BusName? sender=null
) throws Error;
- public abstract void install_monitor (
+ public async abstract void install_monitor (
ObjectPath monitor_path,
[DBus (signature = "(xx)")] Variant time_range,
[DBus (signature = "a(asaasay)")] Variant event_templates,
BusName? owner=null
) throws Error;
- public abstract void remove_monitor (
+ public async abstract void remove_monitor (
ObjectPath monitor_path,
BusName? owner=null
) throws Error;
- public abstract void quit () throws Error;
+ public async abstract void quit (
+ Cancellable? cancellable=null
+ ) throws Error;
[DBus (name = "extensions")]
public abstract string[] extensions { owned get; }
diff --git a/src/zeitgeist-daemon.vala b/src/zeitgeist-daemon.vala
index 156fd89c..c5471bed 100644
--- a/src/zeitgeist-daemon.vala
+++ b/src/zeitgeist-daemon.vala
@@ -140,7 +140,7 @@ namespace Zeitgeist
return Events.to_variant_with_limit (events);
}
- public string[] find_related_uris (Variant time_range,
+ public async string[] find_related_uris (Variant time_range,
Variant event_templates,
Variant result_event_templates,
uint storage_state, uint num_events, uint result_type,
@@ -153,7 +153,7 @@ namespace Zeitgeist
storage_state, num_events, result_type);
}
- public uint32[] find_event_ids (Variant time_range,
+ public async uint32[] find_event_ids (Variant time_range,
Variant event_templates,
uint storage_state, uint num_events, uint result_type,
BusName? sender=null) throws Error
@@ -164,7 +164,7 @@ namespace Zeitgeist
storage_state, num_events, result_type, sender);
}
- public Variant find_events (Variant time_range,
+ public async Variant find_events (Variant time_range,
Variant event_templates,
uint storage_state, uint num_events, uint result_type,
BusName? sender=null) throws Error
@@ -178,8 +178,9 @@ namespace Zeitgeist
return Events.to_variant_with_limit (events);
}
- public uint32[] insert_events (
+ public async uint32[] insert_events (
Variant vevents,
+ Cancellable? cancellable=null,
BusName? sender=null) throws Error
{
var events = Events.from_variant (vevents);
@@ -204,8 +205,8 @@ namespace Zeitgeist
return event_ids;
}
- public Variant delete_events (uint32[] event_ids, BusName? sender=null)
- throws Error
+ public async Variant delete_events (uint32[] event_ids,
+ Cancellable? cancellable=null, BusName? sender=null) throws Error
{
TimeRange? time_range = engine.delete_events (event_ids, sender);
if (time_range != null)
@@ -221,7 +222,7 @@ namespace Zeitgeist
return time_range.to_variant ();
}
- public void quit () throws Error
+ public async void quit (Cancellable? cancellable=null) throws Error
{
do_quit ();
}
@@ -232,7 +233,7 @@ namespace Zeitgeist
mainloop.quit ();
}
- public void install_monitor (ObjectPath monitor_path,
+ public async void install_monitor (ObjectPath monitor_path,
Variant time_range,
Variant event_templates,
BusName? owner=null) throws Error
@@ -243,7 +244,7 @@ namespace Zeitgeist
Events.from_variant (event_templates));
}
- public void remove_monitor (ObjectPath monitor_path, BusName? owner=null)
+ public async void remove_monitor (ObjectPath monitor_path, BusName? owner=null)
throws Error
{
assert (owner != null);