diff options
author | Manish Sinha <mail@manishsinha.net> | 2010-10-10 01:47:55 +0530 |
---|---|---|
committer | Manish Sinha <mail@manishsinha.net> | 2010-10-10 01:47:55 +0530 |
commit | 9146ec42b3a09e5e0e09a7d035f09da0cc5e0b95 (patch) | |
tree | 14de7183166ae26085a82c21efb478465cf2f3f0 | |
parent | 854bc6ae37d11289c3ddd1ee183f5d77c04b1b50 (diff) |
Added support for Monitor
-rw-r--r-- | .bzrignore | 9 | ||||
-rw-r--r-- | Zeitgeist/Datamodel/Delegates.cs | 10 | ||||
-rw-r--r-- | Zeitgeist/Datamodel/Monitor.cs | 104 | ||||
-rw-r--r-- | Zeitgeist/Zeitgeist.csproj | 5 | ||||
-rw-r--r-- | configure.ac | 1 |
5 files changed, 129 insertions, 0 deletions
@@ -1,3 +1,12 @@ +autom4te.cache +install-sh +missing +aclocal.m4 +configure +config.log +config.status +Makefile +Makefile.in bin/ *.userpr* *pidb diff --git a/Zeitgeist/Datamodel/Delegates.cs b/Zeitgeist/Datamodel/Delegates.cs new file mode 100644 index 0000000..7564196 --- /dev/null +++ b/Zeitgeist/Datamodel/Delegates.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; + +namespace Zeitgeist.Datamodel +{ + public delegate void NotifyInsertHandler(TimeRange range, List<Event> events); + + public delegate void NotifyDeleteHandler(TimeRange range, List<UInt32> eventIds); +} + diff --git a/Zeitgeist/Datamodel/Monitor.cs b/Zeitgeist/Datamodel/Monitor.cs new file mode 100644 index 0000000..6c1ef4f --- /dev/null +++ b/Zeitgeist/Datamodel/Monitor.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using NDesk.DBus; +using GLib; +using System.Threading; +using System.ComponentModel; + +namespace Zeitgeist.Datamodel +{ + [Interface("org.gnome.zeitgeist.Monitor")] + internal interface IMonitor + { + void NotifyInsert(TimeRange range, RawEvent[] events); + + void NotifyDelete(TimeRange range, UInt32[] evendIds); + } + + internal class RawMonitor : IMonitor + { + public RawMonitor(string monitorPath) + { + ObjectPath objPath = new ObjectPath (monitorPath); + Bus.Session.Register (objPath, this); + + loop = new MainLoop(); + worker = new BackgroundWorker(); + + worker.DoWork += delegate(object sender, DoWorkEventArgs e) { + loop.Run(); + }; + + worker.RunWorkerAsync(); + } + + public void NotifyInsert(TimeRange range, RawEvent[] events) + { + List<Event> eventList = ZsUtils.FromRawEventList(events); + + if(Inserted != null) + Inserted(range, eventList); + } + + public void NotifyDelete(TimeRange range, UInt32[] evendIds) + { + List<UInt32> eventIdList = new List<UInt32>(evendIds); + + if(Deleted != null) + Deleted(range, eventIdList); + } + + public event NotifyInsertHandler Inserted; + + public event NotifyDeleteHandler Deleted; + + private BackgroundWorker worker; + + private MainLoop loop; + } + + /// <summary> + /// DBus interface for monitoring the Zeitgeist log for certain types of events. + /// When using the Python bindings monitors are normally instantiated indirectly by calling ZeitgeistClient.install_monitor + /// </summary> + /// <remarks> + /// It is important to understand that the Monitor instance lives on the client side, and expose a + /// DBus service there, and the Zeitgeist engine calls back to the monitor when matching events are registered. + /// </remarks> + public class Monitor + { + /// <summary> + /// Create a new instance of Monitor which can be used for notifying the client that some event has been + /// inserted or deleted which matches the event template + /// </summary> + /// <param name="monitorPath"> + /// The DBus path over which the bus is activated <see cref="System.String"/> + /// </param> + public Monitor(string monitorPath) + { + _monitor = new RawMonitor( monitorPath); + + _monitor.Inserted += delegate(TimeRange event_range, List<Event> events) { + if(Inserted != null) + Inserted(event_range, events); + }; + _monitor.Deleted += delegate(TimeRange event_range, List<uint> eventIds) { + if(Deleted != null) + Deleted(event_range, eventIds); + }; + } + + /// <summary> + /// The event which is fired in the case of an event is inserted which matches the Event Templates + /// </summary> + public event NotifyInsertHandler Inserted; + + /// <summary> + /// The event which is fired in the case of an event is deleted which matches the Event Templates + /// </summary> + public event NotifyDeleteHandler Deleted; + + private RawMonitor _monitor; + } +} + diff --git a/Zeitgeist/Zeitgeist.csproj b/Zeitgeist/Zeitgeist.csproj index df3f39f..9c95821 100644 --- a/Zeitgeist/Zeitgeist.csproj +++ b/Zeitgeist/Zeitgeist.csproj @@ -39,6 +39,9 @@ <Reference Include="NDesk.DBus.GLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f6716e4f9b2ed099"> <Package>ndesk-dbus-glib-1.0</Package> </Reference> + <Reference Include="glib-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f"> + <Package>glib-sharp-2.0</Package> + </Reference> </ItemGroup> <ItemGroup> <Compile Include="Datamodel\Event.cs" /> @@ -58,6 +61,8 @@ <Compile Include="Datamodel\Interpretation.cs" /> <Compile Include="Datamodel\Manifestation.cs" /> <Compile Include="Datamodel\NameUri.cs" /> + <Compile Include="Datamodel\Monitor.cs" /> + <Compile Include="Datamodel\Delegates.cs" /> </ItemGroup> <ItemGroup> <Folder Include="Datamodel\" /> diff --git a/configure.ac b/configure.ac index ff79844..2263b1b 100644 --- a/configure.ac +++ b/configure.ac @@ -43,6 +43,7 @@ AC_SUBST(GACUTIL_FLAGS) dnl package checks, common for all configs PKG_CHECK_MODULES([NDESK_DBUS_10], [ndesk-dbus-1.0]) PKG_CHECK_MODULES([NDESK_DBUS_GLIB_10], [ndesk-dbus-glib-1.0]) +PKG_CHECK_MODULES([GLIB_SHARP_20], [glib-sharp-2.0]) AC_CONFIG_FILES([ Zeitgeist/zeitgeist-sharp.pc |