Proposal: asyncronous backends
- From: dave <davidr sucs org>
- To: dashboard <dashboard-hackers gnome org>
- Subject: Proposal: asyncronous backends
- Date: Fri, 05 Mar 2004 13:23:48 +0000
Hi all,
While looking at ways to get weather info via a webservice, I noticed
that while a backend is busy (e.g. waiting for a webservice reply), the
dashboard remains locked up. This really sucks.
So, I suggest that backends get a callback mechanism so that if they
have anything to do that might take a while, they can launch a new
thread and call this function when they're done to report new / changed
results.
I've coded something up which works nicely with the weather backend and
requires only very minor changes to the dashboard/backend bits. See
attached.
With this approach, backends get a GuiMatchNotifyDelegate which they can
then call from a background thread to add a new result or to update an
existing one.
dave
--- cvs/dashboard/engine/dashboard.cs 2004-03-04 08:07:29.000000000 +0000
+++ dashboard/engine/dashboard.cs 2004-03-05 13:20:07.113082032 +0000
@@ -92,6 +92,8 @@
string [] files = Directory.GetFiles (backends_dir, "*.dll");
+ GuiMatchNotifyDelegate callback = new GuiMatchNotifyDelegate(this.BackendCallback);
+
foreach (string file in files) {
try {
@@ -105,6 +107,7 @@
Console.WriteLine ("Loading backend: " + file);
Backend backend = (Backend) Activator.CreateInstance (a.GetType (attr.FactoryClass));
+ backend.UpdateResultCallback = callback; // FIXME: possibly stick this in a constructor somewhere?
ThreadPool.QueueUserWorkItem (new WaitCallback (this.LaunchBackend), backend);
} catch {
@@ -158,7 +161,7 @@
if (attr == null)
continue;
- Console.WriteLine ("Loading render: " + file);
+ Console.WriteLine ("Loading renderer: " + file);
MatchRenderer renderer = (MatchRenderer) Activator.CreateInstance (a.GetType (attr.FactoryClass));
ThreadPool.QueueUserWorkItem (new WaitCallback (this.LaunchRenderer), renderer);
@@ -193,6 +196,16 @@
}
}
+ // called by backends to update results or add new ones
+ public void BackendCallback (BackendResult result) {
+ lock (this.ems) {
+ if (result != null)
+ this.ems.AddBackendResult (result);
+
+ this.window.Display (this.ems);
+ }
+ }
+
//
// Notify the GUI to update
//
--- cvs/dashboard/engine/Backend.cs 2004-02-20 13:03:22.000000000 +0000
+++ dashboard/engine/Backend.cs 2004-03-05 10:44:04.006616416 +0000
@@ -23,6 +23,8 @@
// sent to it.
public abstract bool Startup ();
+ public GuiMatchNotifyDelegate UpdateResultCallback;
+
public IList SubscribedClueTypes = null;
protected void SubscribeToClues (params string[] clue_types_supported)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]