Thumbnail file hits. Based on a patch from D Bera
[beagle.git] / beagled / QueryExecutor.cs
blob692ea32f61aa789cfee82ea75c325adf110464e9
1 //
2 // QueryExecutor.cs
3 //
4 // Copyright (C) 2005 Novell, Inc.
5 //
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a
9 // copy of this software and associated documentation files (the "Software"),
10 // to deal in the Software without restriction, including without limitation
11 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 // and/or sell copies of the Software, and to permit persons to whom the
13 // Software is furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 // DEALINGS IN THE SOFTWARE.
27 using System;
28 using System.Collections;
29 using System.Xml.Serialization;
31 using Beagle.Util;
33 namespace Beagle.Daemon {
35 [RequestMessage (typeof (Query))]
36 public class QueryExecutor : RequestMessageExecutor {
38 private Query query;
39 private QueryResult result;
41 private void DisconnectResult ()
43 this.result.HitsAddedEvent -= OnResultHitsAdded;
44 this.result.HitsSubtractedEvent -= OnResultHitsSubtracted;
45 this.result.FinishedEvent -= OnResultFinished;
46 this.result.CancelledEvent -= OnResultCancelled;
48 this.result.Cancel ();
49 this.result.Dispose ();
52 private void AttachResult ()
54 this.result.HitsAddedEvent += OnResultHitsAdded;
55 this.result.HitsSubtractedEvent += OnResultHitsSubtracted;
56 this.result.FinishedEvent += OnResultFinished;
57 this.result.CancelledEvent += OnResultCancelled;
60 public void OnResultHitsAdded (QueryResult result, ICollection some_hits)
62 HitsAddedResponse response = new HitsAddedResponse (some_hits);
64 this.SendAsyncResponse (response);
67 public void OnResultHitsSubtracted (QueryResult result, ICollection some_uris)
69 HitsSubtractedResponse response = new HitsSubtractedResponse (some_uris);
71 this.SendAsyncResponse (response);
74 public void OnResultFinished (QueryResult result)
76 this.SendAsyncResponse (new FinishedResponse ());
79 public void OnResultCancelled (QueryResult result)
81 this.SendAsyncResponse (new CancelledResponse ());
84 private void OnQueryDriverChanged (Queryable queryable, IQueryableChangeData change_data)
86 if (this.result != null)
87 QueryDriver.DoOneQuery (queryable, this.query, this.result, change_data);
90 public override ResponseMessage Execute (RequestMessage req)
92 this.query = (Query) req;
94 this.result = new QueryResult ();
95 AttachResult ();
97 QueryDriver.ChangedEvent += OnQueryDriverChanged;
98 QueryDriver.DoQuery (query,
99 this.result,
100 new RequestMessageExecutor.AsyncResponse (this.SendAsyncResponse));
102 // Don't send a response; we'll be sending them async
103 return null;
106 public override void Cleanup ()
108 DisconnectResult ();