summaryrefslogtreecommitdiff
path: root/libzeitgeist
diff options
context:
space:
mode:
authorSiegfried-Angel Gevatter Pujals <siegfried@gevatter.com>2012-09-08 19:00:36 +0200
committerSiegfried-Angel Gevatter Pujals <siegfried@gevatter.com>2012-09-08 19:00:36 +0200
commit1543988402a80c1b70652dd73bdb60b756c6bf08 (patch)
treeb573fc37be21432744792ec691994643e470f11b /libzeitgeist
parentd921c1df1b9561e96ae7bf333141431b7d4c303b (diff)
downloadzeitgeist-1543988402a80c1b70652dd73bdb60b756c6bf08.tar.gz
libzeitgeist: add "null event" handling
GetEvents returns null-events when a requested ID doesn't exist. This commit fixes libzeitgeist to properly support this, by changing zeitgeist_log_get_events to return GenericArray<Event?>. https://bugs.freedesktop.org/show_bug.cgi?id=53016
Diffstat (limited to 'libzeitgeist')
-rw-r--r--libzeitgeist/API_CHANGES2
-rw-r--r--libzeitgeist/datamodel.vala27
-rw-r--r--libzeitgeist/log.vala13
3 files changed, 32 insertions, 10 deletions
diff --git a/libzeitgeist/API_CHANGES b/libzeitgeist/API_CHANGES
index 2357895e..e528dc2f 100644
--- a/libzeitgeist/API_CHANGES
+++ b/libzeitgeist/API_CHANGES
@@ -15,6 +15,8 @@ API CHANGES FROM LIBZEITGEIST1:
- introduced zeitgeist_time_range_intersect
- removed time_range_get_{start,end}_iso8601
- changed timestamp_for_now to be timestamp_now
+ - zeitgeist_log_get_events now returns GPtrArray (and works
+ with NULL-events)
Vala:
- stuff is more valaish (eg. properties vs set/get)
diff --git a/libzeitgeist/datamodel.vala b/libzeitgeist/datamodel.vala
index 19d47e36..b6b51246 100644
--- a/libzeitgeist/datamodel.vala
+++ b/libzeitgeist/datamodel.vala
@@ -29,6 +29,7 @@ namespace Zeitgeist
[DBus (name = "org.gnome.zeitgeist.DataModelError")]
public errordomain DataModelError {
INVALID_SIGNATURE,
+ NULL_EVENT,
TOO_MANY_RESULTS
}
@@ -429,6 +430,12 @@ namespace Zeitgeist
Variant payload_variant = iter.next_value ();
var event_props = event_array.n_children ();
+
+ if (event_props == 0)
+ {
+ throw new DataModelError.NULL_EVENT ("This is an empty event.");
+ }
+
assert_sig (event_props >= 5, "Missing event information.");
id = (uint32) uint64.parse (event_array.next_value().get_string ());
var str_timestamp = event_array.next_value().get_string ();
@@ -595,14 +602,26 @@ namespace Zeitgeist
namespace Events
{
- public static GenericArray<Event> from_variant (Variant vevents)
+ public static GenericArray<Event?> from_variant (Variant vevents)
throws DataModelError
{
- GenericArray<Event> events = new GenericArray<Event> ();
+ GenericArray<Event?> events = new GenericArray<Event> ();
assert (vevents.get_type_string () == "a("+Utils.SIG_EVENT+")");
- foreach (Variant event in vevents)
- events.add (new Event.from_variant (event));
+ foreach (Variant vevent in vevents)
+ {
+ Event? event = null;
+ try
+ {
+ event = new Event.from_variant (vevent);
+ }
+ catch (DataModelError err)
+ {
+ if (!(err is DataModelError.NULL_EVENT))
+ throw err;
+ }
+ events.add (event);
+ }
return events;
}
diff --git a/libzeitgeist/log.vala b/libzeitgeist/log.vala
index 47e33114..0460a5f2 100644
--- a/libzeitgeist/log.vala
+++ b/libzeitgeist/log.vala
@@ -154,16 +154,16 @@ public class Log : QueuedProxyWrapper
num_events, result_type, cancellable);
}
- public async ResultSet get_events (
- Array<uint32> event_ids,
- Cancellable? cancellable=null) throws Error
+ public async GenericArray<Event> get_events (
+ Array<uint32> event_ids,
+ Cancellable? cancellable=null) throws Error
{
yield wait_for_proxy ();
uint32[] simple_event_ids = new uint32[event_ids.length];
- for (int i=0; i<event_ids.length; i++)
- simple_event_ids[i] = event_ids.index(i);
+ for (int i = 0; i < event_ids.length; i++)
+ simple_event_ids[i] = event_ids.index (i);
var result = yield proxy.get_events (simple_event_ids, cancellable);
- return new SimpleResultSet (Events.from_variant (result));
+ return Events.from_variant (result);
}
public async string[] find_related_uris (
@@ -218,6 +218,7 @@ public class Log : QueuedProxyWrapper
{
DBusConnection conn = ((DBusProxy) proxy).get_connection ();
+ // FIXME: check exception
uint registration_id = conn.register_object<RemoteMonitor> (
monitor.get_path (), monitor);
monitors.insert (monitor, registration_id);