summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManish Sinha <manishsinha@ubuntu.com>2011-04-28 02:48:43 +0530
committerManish Sinha <manishsinha@ubuntu.com>2011-04-28 02:48:43 +0530
commitea21549b356564734b6eef804e06c5a42a52ccab (patch)
tree67240ccf84fa4a5a4fd6d71b261831df6a3554b2
parent571761081788f6ca34d2a17d1833341bf70f7f05 (diff)
Updated the blacklist API. Updated IBlacklist and BlacklistClient and added necessary delegates
-rw-r--r--Zeitgeist/BlacklistClient.cs89
-rw-r--r--Zeitgeist/Client/IBlacklist.cs42
-rw-r--r--Zeitgeist/Delegates.cs22
3 files changed, 136 insertions, 17 deletions
diff --git a/Zeitgeist/BlacklistClient.cs b/Zeitgeist/BlacklistClient.cs
index 475564b..74dbeb6 100644
--- a/Zeitgeist/BlacklistClient.cs
+++ b/Zeitgeist/BlacklistClient.cs
@@ -47,39 +47,104 @@ namespace Zeitgeist
public BlacklistClient()
{
srcInterface = ZsUtils.GetDBusObject<IBlacklist>(objectPath);
+
+ // Connect the Template Added event
+ srcInterface.TemplateAdded += delegate(string blacklistId, RawEvent addedTemplate) {
+ if(TemplateAdded != null)
+ TemplateAdded(blacklistId, RawEvent.FromRaw(addedTemplate));
+ };
+
+ // Connect the Template Removed event
+ srcInterface.TemplateRemoved += delegate(string blacklistId, RawEvent removedTemplate) {
+ if(TemplateRemoved != null)
+ TemplateRemoved(blacklistId, RawEvent.FromRaw(removedTemplate));
+ };
}
/// <summary>
/// Get the current blacklist templates.
/// </summary>
/// <returns>
- /// A list of <see cref="T:System.Collection.Generic.List{Zeitgeist.Datamodel.Event>"/> Blacklist Event templates
+ /// A dictionary of string as key and <see cref="T:System.Collection.Generic.List{Zeitgeist.Datamodel.Event>"/> as the Blacklist template
/// </returns>
- public List<Event> GetBlacklist()
+ public Dictionary<string, Event> GetTemplates()
{
- RawEvent[] rawBlackLists = srcInterface.GetBlacklist();
- return ZsUtils.FromRawEventList(rawBlackLists);
+ Dictionary<string, RawEvent> rawBlackLists = srcInterface.GetTemplates();
+ Dictionary<string, Event> eventList = new Dictionary<string, Event>();
+
+ foreach(KeyValuePair<string, RawEvent> pair in rawBlackLists)
+ {
+ eventList.Add(pair.Key, RawEvent.FromRaw(pair.Value));
+ }
+
+ return eventList;
}
/// <summary>
- /// Set the blacklist to event_templates.
+ /// Add a blacklist template to the engine to stop the matching events to be inserted.
+ /// If the event was inserted successfully then TemplateAdded event is raised
/// </summary>
- /// Events matching any these templates will be blocked from insertion into the log.
- /// It is still possible to find and look up events matching the blacklist which was inserted before the blacklist banned them.
+ /// <param name="blacklistId">
+ /// The id of the blacklist template of the type <see cref="System.String"/>
+ /// </param>
+ /// <param name="eventTemplate">
+ /// The actual event template of type <see cref="Event"/>
+ /// </param>
/// <remarks>
+ /// The event template provided is used to match the event to be inserted. The Properties
+ /// not set are treated as wildcards. Timestamp is not taken under consideration
/// </remarks>
- /// <param name="eventTemplates">
- /// A List of <see cref="T:System.Collection.Generic.List{Zeitgeist.Datamodel.Event>"/> Event templates
+ public void AddTemplate(string blacklistId, Event eventTemplate)
+ {
+ srcInterface.AddTemplate(blacklistId, RawEvent.FromEvent(eventTemplate));
+ }
+
+ /// <summary>
+ /// Removes the blacklist from the engine if found.
+ /// If the blacklist template was found and is removed then TemplateRemoved event is raised
+ /// </summary>
+ /// <param name="blacklistId">
+ /// The blacklist template id for the template <see cref="System.String"/>
/// </param>
- public void SetBlacklist(List<Event> eventTemplates)
+ /// <remarks>
+ /// If the blacklist does not exist. No event is raised
+ /// </remarks>
+ public void RemoveTemplate(string blacklistId)
{
- List<RawEvent> events = ZsUtils.ToRawEventList(eventTemplates);
- srcInterface.SetBlacklist(events.ToArray());
+ srcInterface.RemoveTemplate(blacklistId);
}
+ /// <summary>
+ /// Raised when a blacklist template is added
+ /// </summary>
+ /// <summary>
+ /// When a new blacklist template is added to the engine, then this event is raised.
+ /// The delegate <see cref="Zeitgeist.BlacklistTemplateAddedHandler"/> is used for handle the events.
+ /// This handler has two argument:
+ /// 'blacklistId' of type <see cref="string"/> and
+ /// 'addedTemplate' of type <see cref="Zeitgeist.Datamodel.Event"/>
+ /// </summary>
+ event BlacklistTemplateAddedHandler TemplateAdded;
+
+ /// <summary>
+ /// Raised when a blacklist template is removed
+ /// </summary>
+ /// <summary>
+ /// When a new blacklist template is removed to the engine, then this event is raised.
+ /// The delegate <see cref="Zeitgeist.BlacklistTemplateRemovedHandler"/> is used for handle the events.
+ /// This handler has two argument:
+ /// 'blacklistId' of type <see cref="string"/> and
+ /// 'removedTemplate' of type <see cref="Zeitgeist.Datamodel.Event"/>
+ /// </summary>
+ event BlacklistTemplateRemovedHandler TemplateRemoved;
+
+ #region Private Fields
+
private IBlacklist srcInterface;
private static string objectPath = "/org/gnome/zeitgeist/blacklist";
+
+ #endregion
}
}
diff --git a/Zeitgeist/Client/IBlacklist.cs b/Zeitgeist/Client/IBlacklist.cs
index d96f10f..d8f6541 100644
--- a/Zeitgeist/Client/IBlacklist.cs
+++ b/Zeitgeist/Client/IBlacklist.cs
@@ -24,6 +24,7 @@
using System;
using Zeitgeist.Datamodel;
using Zeitgeist;
+using System.Collections.Generic;
namespace Zeitgeist.Client
{
@@ -39,9 +40,10 @@ namespace Zeitgeist.Client
/// Get the current blacklist templates.
/// </summary>
/// <returns>
- /// A list of Blacklist RawEvent <see cref="T:System.Collection.Generic.List{Zeitgeist.Datamodel.RawEvent>"/> templates
+ /// A dictionary of Blacklist Id as <see cref="string"/> and
+ /// Blacklist RawEvent <see cref="T:System.Collection.Generic.List{Zeitgeist.Datamodel.RawEvent>"/> templates
/// </returns>
- RawEvent[] GetBlacklist();
+ Dictionary<string, RawEvent> GetTemplates();
/// <summary>
/// Set the blacklist to event_templates.
@@ -50,10 +52,40 @@ namespace Zeitgeist.Client
/// Events matching any these templates will be blocked from insertion into the log.
/// It is still possible to find and look up events matching the blacklist which was inserted before the blacklist banned them.
/// </remarks>
- /// <param name="event_templates">
- /// A List of RawEvent <see cref="T:System.Collection.Generic.List{Zeitgeist.Datamodel.RawEvent>"/> templates
+ /// <param name="event_template">
+ /// The <see cref="Zeitgeist.Datamodel.RawEvent"/> representing the template
/// </param>
- void SetBlacklist(RawEvent[] event_templates);
+ void AddTemplate(string blacklist_id, RawEvent event_template);
+
+ /// <summary>
+ /// Remove a blacklist
+ /// </summary>
+ /// <param name="blacklist_id">
+ /// A <see cref="System.String"/> which represents the blacklist id of the blacklist template
+ /// </param>
+ void RemoveTemplate(string blacklist_id);
+
+ /// <summary>
+ /// Raised when a blacklist template is added
+ /// </summary>
+ /// <summary>
+ /// When a new blacklist template is added to the engine, then this event is raised.
+ /// The delegate <see cref="Zeitgeist.Client.RawBlacklistTemplateAddedHandler"/> is used for handle the events.
+ /// </summary>
+ event RawBlacklistTemplateAddedHandler TemplateAdded;
+
+ /// <summary>
+ /// Raised when a blacklist template is removed
+ /// </summary>
+ /// <summary>
+ /// When a new blacklist template is removed to the engine, then this event is raised.
+ /// The delegate <see cref="Zeitgeist.Client.RawBlacklistTemplateRemovedHandler"/> is used for handle the events.
+ /// </summary>
+ event RawBlacklistTemplateRemovedHandler TemplateRemoved;
}
+
+ internal delegate void RawBlacklistTemplateAddedHandler(string blacklistId, RawEvent addedTemplate);
+
+ internal delegate void RawBlacklistTemplateRemovedHandler(string blacklistId, RawEvent removedTemplate);
}
diff --git a/Zeitgeist/Delegates.cs b/Zeitgeist/Delegates.cs
index ba83c91..b13bc30 100644
--- a/Zeitgeist/Delegates.cs
+++ b/Zeitgeist/Delegates.cs
@@ -52,5 +52,27 @@ namespace Zeitgeist
/// The registered data-source of type <see cref="Zeitgeist.Datamodel.DataSource"/>
/// </param>
public delegate void DataSourceRegisteredHandler(DataSource datasource);
+
+ /// <summary>
+ /// This delegate handler for the event related to Blacklist Template addition
+ /// </summary>
+ /// <param name="blacklistId">
+ /// The blacklist ID of type <see cref="string"/>
+ /// </param>
+ /// <param name="addedTemplate">
+ /// The blacklist template added
+ /// </param>
+ public delegate void BlacklistTemplateAddedHandler(string blacklistId, Event addedTemplate);
+
+ /// <summary>
+ /// This delegate handler for the event related to Blacklist Template deletion
+ /// </summary>
+ /// <param name="blacklistId">
+ /// The blacklist ID of type <see cref="string"/>
+ /// </param>
+ /// <param name="removedTemplate">
+ /// The blacklist template removed
+ /// </param>
+ public delegate void BlacklistTemplateRemovedHandler(string blacklistId, Event removedTemplate);
}