zeitgeist team mailing list archive
-
zeitgeist team
-
Mailing list archive
-
Message #03889
[Branch ~zeitgeist/zeitgeist/bluebird] Rev 218: Implement extension hooks.
------------------------------------------------------------
revno: 218
committer: Siegfried-Angel Gevatter Pujals <siegfried@xxxxxxxxxxxx>
branch nick: bluebird
timestamp: Fri 2011-09-02 19:46:22 +0200
message:
Implement extension hooks.
modified:
src/engine.vala
src/extension-collection.vala
src/extension.vala
test/direct/Makefile.am
--
lp:~zeitgeist/zeitgeist/bluebird
https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird
Your team Zeitgeist Framework Team is subscribed to branch lp:~zeitgeist/zeitgeist/bluebird.
To unsubscribe from this branch go to https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird/+edit-subscription
=== modified file 'src/engine.vala'
--- src/engine.vala 2011-09-02 16:38:41 +0000
+++ src/engine.vala 2011-09-02 17:46:22 +0000
@@ -137,6 +137,9 @@
{
results.set(i++, events.lookup (id));
}
+
+ extension_collection.call_post_get_events (results, sender);
+
return results;
}
@@ -532,13 +535,16 @@
public uint32[] insert_events (GenericArray<Event> events,
BusName? sender=null) throws EngineError
{
+ extension_collection.call_pre_insert_events (events, sender);
uint32[] event_ids = new uint32[events.length];
database.begin_transaction ();
for (int i = 0; i < events.length; ++i)
{
- event_ids[i] = insert_event (events[i], sender);
+ if (events[i] != null)
+ event_ids[i] = insert_event (events[i], sender);
}
database.end_transaction ();
+ extension_collection.call_post_insert_events (events, sender);
return event_ids;
}
@@ -551,9 +557,6 @@
event.id = ++last_id;
- // FIXME: call pre_insert extension hooks
- // if afterwards event == null, return and ignore the event
-
// FIXME: store the payload
// payload_id = store_payload (event);
@@ -695,9 +698,10 @@
return event.id;
}
- public TimeRange? delete_events (uint32[] event_ids, BusName sender)
+ public TimeRange? delete_events (uint32[] event_ids, BusName? sender)
{
- // FIXME: extensions pre_delete
+ event_ids = extension_collection.call_pre_delete_events (
+ event_ids, sender);
TimeRange? time_range = database.get_time_range_for_event_ids (
event_ids);
@@ -718,6 +722,8 @@
message ("Deleted %d (out of %d) events.".printf (
db.changes(), event_ids.length));
+ extension_collection.call_post_delete_events (event_ids, sender);
+
return time_range;
}
=== modified file 'src/extension-collection.vala'
--- src/extension-collection.vala 2011-09-02 16:11:42 +0000
+++ src/extension-collection.vala 2011-09-02 17:46:22 +0000
@@ -104,6 +104,61 @@
return result;
}
+
+ public void call_pre_insert_events (GenericArray<Event?> events,
+ BusName? sender)
+ {
+ int num_events = events.length;
+ for (int i = 0; i < extensions.length; ++i)
+ {
+ extensions[i].pre_insert_events (events, sender);
+ }
+ assert (num_events == events.length);
+ }
+
+ public void call_post_insert_events (GenericArray<Event?> events,
+ BusName? sender)
+ {
+ int num_events = events.length;
+ for (int i = 0; i < extensions.length; ++i)
+ {
+ extensions[i].post_insert_events (events, sender);
+ }
+ assert (num_events == events.length);
+ }
+
+ public void call_post_get_events (GenericArray<Event?> events,
+ BusName? sender)
+ {
+ int num_events = events.length;
+ for (int i = 0; i < extensions.length; ++i)
+ {
+ extensions[i].post_get_events (events, sender);
+ }
+ assert (num_events == events.length);
+ }
+
+ public unowned uint32[] call_pre_delete_events (uint32[] event_ids,
+ BusName? sender)
+ {
+ for (int i = 0; i < extensions.length; ++i)
+ {
+ uint32[]? filtered_ids = extensions[i].pre_delete_events (
+ event_ids, sender);
+ if (filtered_ids != null)
+ event_ids = filtered_ids;
+ }
+ return event_ids;
+ }
+
+ public void call_post_delete_events (uint32[] event_ids,
+ BusName? sender)
+ {
+ for (int i = 0; i < extensions.length; ++i)
+ {
+ extensions[i].post_delete_events (event_ids, sender);
+ }
+ }
}
#if BUILTIN_EXTENSIONS
=== modified file 'src/extension.vala'
--- src/extension.vala 2011-09-02 16:11:42 +0000
+++ src/extension.vala 2011-09-02 17:46:22 +0000
@@ -52,59 +52,77 @@
* log. The returned event is progressively passed through all
* extensions before the final result is inserted.
*
- * To block an event completely simply return null.
+ * To block an event completely simply replace it with NULL.
* The event may also be modified or completely substituted for
* another event.
*
- * The default implementation of this method simply returns the
- * event as is.
- *
- * @param event: A Event instance
- * @param sender: The D-Bus bus name of the client
- * @returns: The filtered event instance to insert into the log
+ * @param events: A GenericArray of Event instances
+ * @param sender: The D-Bus bus name of the client or NULL
*/
- public virtual GenericArray<Event?> pre_insert_events (
- GenericArray<Event?> events, BusName sender)
+ public virtual void pre_insert_events (GenericArray<Event?> events,
+ BusName? sender)
{
- return events;
}
/**
* Hook applied to all events after they are inserted into the log.
*
- * @param event: A Event instance
- * @param sender: The D-Bus bus name of the client
- * @returns: Nothing
+ * The inserted events will have been updated to include their new
+ * ID.
+ *
+ * @param events: A GenericArray of Event instances
+ * @param sender: The D-Bus bus name of the client or NULL
*/
public virtual void post_insert_events (GenericArray<Event?> events,
- BusName sender)
+ BusName? sender)
{
}
/**
- * Hook applied after events have been deleted from the log.
- *
- * @param ids: A list of event ids for the events that has been deleted
- * @param sender: The unique DBus name for the client triggering the delete
- * @returns: Nothing
+ * Hook applied to all events before they are returned to a client
+ * (as a result of a GetEvents or FindEvents call).
+ *
+ * The events returned from this method are progressively passed
+ * through all extensions before the final result is returned to
+ * the client.
+ *
+ * To prevent an event from being returned replace it with NULL.
+ * The event may also be changed in place or fully substituted for
+ * another event.
+ *
+ * @param events: A GenericArray of Event instances
+ * @param sender: The D-Bus bus name of the client or NULL
*/
- public virtual void post_delete_events (uint32[] ids, BusName sender)
- {
- }
+ public virtual void post_get_events (GenericArray<Event?> events,
+ BusName? sender)
+ {
+ }
/**
* Hook applied before events are deleted from the log.
*
- * @param ids: A list of event ids for the events requested to be deleted
- * @param sender: The unique DBus name for the client triggering the delete
- * @returns: The filtered list of event ids which should be deleted or
- * null to specify no change.
+ * @param ids: A list with the IDs of the events whose deletion
+ * is being requested
+ * @param sender: The unique DBus name for the client triggering
+ * the delete, or NULL
+ * @return: The filtered list of event IDs which should be deleted,
+ * or NULL to specify no change
*/
public virtual uint32[]? pre_delete_events (uint32[] ids,
- BusName sender)
+ BusName? sender)
{
return null;
}
+
+ /**
+ * Hook applied after events have been deleted from the log.
+ *
+ * @param ids: A list with the IDs of the events that have been deleted
+ * @param sender: The unique DBus name for the client triggering the delete
+ */
+ public virtual void post_delete_events (uint32[] ids, BusName? sender)
+ {
+ }
}
[CCode (has_target = false)]
=== modified file 'test/direct/Makefile.am'
--- test/direct/Makefile.am 2011-08-26 10:43:01 +0000
+++ test/direct/Makefile.am 2011-09-02 17:46:22 +0000
@@ -17,14 +17,15 @@
SRC_FILES = \
$(top_srcdir)/src/engine.vala \
$(top_srcdir)/src/utils.vala \
+ $(top_srcdir)/src/errors.vala \
$(top_srcdir)/src/notify.vala \
$(top_srcdir)/src/table-lookup.vala \
$(top_srcdir)/src/datamodel.vala \
$(top_srcdir)/src/where-clause.vala \
$(top_srcdir)/src/remote.vala \
- $(top_srcdir)/src/errors.vala \
$(top_srcdir)/src/sql-schema.vala \
$(top_srcdir)/src/extension.vala \
+ $(top_srcdir)/src/extension-collection.vala \
$(top_srcdir)/src/sql.vala \
$(top_srcdir)/src/ontology.vala \
$(top_srcdir)/src/ontology-uris.vala \