[Monodevelop-patches-list] r1808 - in trunk/MonoDevelop: build/AddIns src/Main/Base src/Main/Base/Gui/Pads/ClassScout src/Main/Base/Services src/Main/Base/Services/DispatchService
commit-watcher at mono-cvs.ximian.com
commit-watcher at mono-cvs.ximian.com
Wed Jun 23 00:47:32 EDT 2004
Author: tberman
Date: 2004-06-23 00:47:32 -0400 (Wed, 23 Jun 2004)
New Revision: 1808
Added:
trunk/MonoDevelop/src/Main/Base/Services/DispatchService/
trunk/MonoDevelop/src/Main/Base/Services/DispatchService/DispatchService.cs
Modified:
trunk/MonoDevelop/build/AddIns/SharpDevelopCore.addin.xml
trunk/MonoDevelop/src/Main/Base/ChangeLog
trunk/MonoDevelop/src/Main/Base/Gui/Pads/ClassScout/ClassScout.cs
trunk/MonoDevelop/src/Main/Base/Makefile.am
Log:
new dispatch service stuff, the ClassScout is using the Gui part, so that is tested, the background thread stuff has yet to be tested.
Modified: trunk/MonoDevelop/build/AddIns/SharpDevelopCore.addin.xml
===================================================================
--- trunk/MonoDevelop/build/AddIns/SharpDevelopCore.addin.xml 2004-06-23 01:47:17 UTC (rev 1807)
+++ trunk/MonoDevelop/build/AddIns/SharpDevelopCore.addin.xml 2004-06-23 04:47:32 UTC (rev 1808)
@@ -32,6 +32,8 @@
<Extension path = "/Workspace/Services">
<Class id = "MonodocService"
class = "MonoDevelop.Services.MonodocService"/>
+ <Class id = "DispatchService"
+ class = "MonoDevelop.Services.DispatchService"/>
<Class id = "SystemAssemblyService"
class = "MonoDevelop.Services.SystemAssemblyService"/>
<Class id = "ProjectService"
Modified: trunk/MonoDevelop/src/Main/Base/ChangeLog
===================================================================
--- trunk/MonoDevelop/src/Main/Base/ChangeLog 2004-06-23 01:47:17 UTC (rev 1807)
+++ trunk/MonoDevelop/src/Main/Base/ChangeLog 2004-06-23 04:47:32 UTC (rev 1808)
@@ -1,3 +1,13 @@
+2004-06-23 Todd Berman <tberman at off.net>
+
+ * Gui/Pads/ClassScout/ClassScout.cs: use DispatchService instead of
+ IdleWork stuff.
+ * Services/DispatchService/DispatchService.cs: new service, used to
+ pass messages to the gui, or a background thread. The gui stuff has
+ been tested by the ClassScout above, the background thread dispatching
+ has yet to be tested.
+ * Makefile.am: Add DispatchService.cs
+
2004-06-21 John Luke <jluke at cfl.rr.com>
* Gui/Dialogs/OptionPanels/ProjectOptions/CompileFileProjectOptions.cs:
Modified: trunk/MonoDevelop/src/Main/Base/Gui/Pads/ClassScout/ClassScout.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Gui/Pads/ClassScout/ClassScout.cs 2004-06-23 01:47:17 UTC (rev 1807)
+++ trunk/MonoDevelop/src/Main/Base/Gui/Pads/ClassScout/ClassScout.cs 2004-06-23 04:47:32 UTC (rev 1808)
@@ -147,21 +147,16 @@
Nodes.Clear();
}
- void AddIdle (IdleStateHandler cb, object data)
- {
- GLib.Idle.Add (new GLib.IdleHandler (new IdleWork (cb, data).Run));
- }
-
void OnClassInformationChanged(object sender, ClassInformationEventArgs e)
{
- AddIdle (new IdleStateHandler(ChangeClassInfo), e);
+ DispatchService dispatcher = (DispatchService)ServiceManager.Services.GetService (typeof (DispatchService));
+ dispatcher.GuiDispatch (new MessageHandler (ChangeClassInfo), e);
}
- bool ChangeClassInfo (object e)
+ void ChangeClassInfo (object e)
{
ClassInformationEventArgs ce = (ClassInformationEventArgs) e;
ChangeClassInformation (Nodes, ce);
- return false;
}
private void OnNodeActivated(object sender, Gtk.RowActivatedArgs args)
@@ -380,30 +375,4 @@
EndUpdate();
}
}
-
- public delegate bool IdleStateHandler (object state);
-
- class IdleWork
- {
- object _data;
- IdleStateHandler _cb;
-
- public IdleWork (IdleStateHandler cb, object data)
- {
- _data = data;
- _cb = cb;
- }
-
- public bool Run ()
- {
- try {
- return _cb (_data);
- }
- catch (Exception e) {
- Console.WriteLine ("Caught an exception in IdleWork.Run: " + e.ToString ());
- }
- return false;
- }
- }
}
-
Modified: trunk/MonoDevelop/src/Main/Base/Makefile.am
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Makefile.am 2004-06-23 01:47:17 UTC (rev 1807)
+++ trunk/MonoDevelop/src/Main/Base/Makefile.am 2004-06-23 04:47:32 UTC (rev 1808)
@@ -220,6 +220,7 @@
./Services/MonodocService.cs \
./Services/IDebuggerService.cs \
./Services/SystemAssemblyService.cs \
+./Services/DispatchService/DispatchService.cs \
./Internal/Undo/IUndoableOperation.cs \
./Internal/Undo/UndoStack.cs \
./Internal/Undo/UndoQueue.cs \
Added: trunk/MonoDevelop/src/Main/Base/Services/DispatchService/DispatchService.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Services/DispatchService/DispatchService.cs 2004-06-23 01:47:17 UTC (rev 1807)
+++ trunk/MonoDevelop/src/Main/Base/Services/DispatchService/DispatchService.cs 2004-06-23 04:47:32 UTC (rev 1808)
@@ -0,0 +1,106 @@
+using System;
+using System.Threading;
+using System.Collections;
+
+using MonoDevelop.Services;
+using MonoDevelop.Core.Services;
+
+namespace MonoDevelop.Services
+{
+ public class DispatchService : AbstractService
+ {
+ ArrayList arrBackgroundQueue;
+ ArrayList arrGuiQueue;
+ Thread thrBackground;
+ uint iIdle = 0;
+
+ public override void InitializeService ()
+ {
+ arrBackgroundQueue = new ArrayList ();
+ arrGuiQueue = new ArrayList ();
+ thrBackground = new Thread (new ThreadStart (backgroundDispatcher));
+ thrBackground.IsBackground = true;
+ thrBackground.Priority = ThreadPriority.Lowest;
+ thrBackground.Start ();
+ }
+
+ public void GuiDispatch (MessageHandler cb, object state)
+ {
+ arrGuiQueue.Add (new MessageContainer (cb, state));
+ if (iIdle == 0) {
+ iIdle = GLib.Idle.Add (new GLib.IdleHandler (guiDispatcher));
+ /* This code is required because for some
+ * reason the idle handler is run once
+ * before being set, so you get a idle
+ * handler that isnt running, but our code
+ * thinks that it is.
+ */
+ if (arrGuiQueue.Count == 0 && iIdle != 0)
+ iIdle = 0;
+ }
+ }
+
+ public void BackgroundDispatch (MessageHandler cb, object state)
+ {
+ arrBackgroundQueue.Add (new MessageContainer (cb, state));
+ //thrBackground.Resume ();
+ }
+
+ private bool guiDispatcher ()
+ {
+ if (arrGuiQueue.Count == 0) {
+ iIdle = 0;
+ return false;
+ }
+ MessageContainer msg = null;
+ lock (arrGuiQueue) {
+ msg = (MessageContainer)arrGuiQueue[0];
+ arrGuiQueue.RemoveAt (0);
+ }
+ if (msg != null)
+ msg.Run ();
+ if (arrGuiQueue.Count == 0) {
+ iIdle = 0;
+ return false;
+ }
+ return true;
+ }
+
+ private void backgroundDispatcher ()
+ {
+ while (true) {
+ if (arrBackgroundQueue.Count == 0) {
+ Thread.Sleep (500);
+ //thrBackground.Suspend ();
+ continue;
+ }
+ MessageContainer msg = null;
+ lock (arrBackgroundQueue) {
+ msg = (MessageContainer)arrBackgroundQueue[0];
+ arrBackgroundQueue.RemoveAt (0);
+ }
+ if (msg != null)
+ msg.Run ();
+ }
+ }
+ }
+
+ public delegate void MessageHandler (object state);
+
+ class MessageContainer
+ {
+ object data;
+ MessageHandler callback;
+
+ public MessageContainer (MessageHandler cb, object state)
+ {
+ data = state;
+ callback = cb;
+ }
+
+ public void Run ()
+ {
+ callback (data);
+ }
+ }
+}
More information about the Monodevelop-patches-list
mailing list