Fixed #374055:Only the first "tag" is detected in digikam.
[beagle.git] / bludgeon / EventTracker.cs
blobf42a47c79b6bd85911e1bdc24721bcbb901638d8
2 using System;
3 using System.Collections;
5 using Beagle.Util;
7 namespace Bludgeon {
9 public class EventTracker {
11 private enum EventType {
12 Added,
13 Subtracted
16 private class Event {
17 public EventType Type;
18 public string Uri;
21 object big_lock = new object ();
22 ArrayList expected_events = new ArrayList ();
24 public EventTracker ()
29 ////////////////////////////////////////////////////////
31 public void ExpectingAdded (string uri)
33 lock (big_lock) {
35 // Adding anything always generates a paired
36 // subtracted event.
37 ExpectingSubtracted (uri);
39 Event ev = new Event ();
40 ev.Type = EventType.Added;
41 ev.Uri = uri;
42 expected_events.Add (ev);
44 //Log.Spew ("Expecting Added {0}", uri);
48 public void ExpectingSubtracted (string uri)
50 lock (big_lock) {
51 Event ev = new Event ();
52 ev.Type = EventType.Subtracted;
53 ev.Uri = uri;
54 expected_events.Add (ev);
56 //Log.Spew ("Expecting Subtracted {0}", uri);
60 ////////////////////////////////////////////////////////
62 private void GotEvent (EventType type, string uri)
64 lock (big_lock) {
65 for (int i = 0; i < expected_events.Count; ++i) {
66 Event ev = (Event) expected_events [i];
67 if (ev.Type == type && ev.Uri == uri) {
68 expected_events.RemoveAt (i);
69 return;
72 throw new Exception ("Spurious event " + type + " " + uri);
76 public void GotAddedEvent (string uri)
78 GotEvent (EventType.Added, uri);
81 public void GotSubtractedEvent (string uri)
83 GotEvent (EventType.Subtracted, uri);